aboutsummaryrefslogtreecommitdiff
path: root/libdiskfs/fsys-getroot.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdiskfs/fsys-getroot.c')
-rw-r--r--libdiskfs/fsys-getroot.c63
1 files changed, 36 insertions, 27 deletions
diff --git a/libdiskfs/fsys-getroot.c b/libdiskfs/fsys-getroot.c
index 2a18810c..e083032e 100644
--- a/libdiskfs/fsys-getroot.c
+++ b/libdiskfs/fsys-getroot.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation
+ Copyright (C) 1993,94,95,96,97,98,2002 Free Software Foundation
This file is part of the GNU Hurd.
@@ -8,7 +8,7 @@ it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-The GNU Hurd is distributed in the hope that it will be useful,
+The GNU Hurd is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@@ -31,22 +31,28 @@ diskfs_S_fsys_getroot (fsys_t controlport,
mach_msg_type_name_t replytype,
mach_port_t dotdot,
uid_t *uids,
- u_int nuids,
+ size_t nuids,
uid_t *gids,
- u_int ngids,
+ size_t ngids,
int flags,
retry_type *retry,
char *retryname,
file_t *returned_port,
mach_msg_type_name_t *returned_port_poly)
{
- struct port_info *pt = ports_lookup_port (diskfs_port_bucket, controlport,
+ struct port_info *pt = ports_lookup_port (diskfs_port_bucket, controlport,
diskfs_control_class);
error_t error = 0;
mode_t type;
struct protid *newpi;
+ struct peropen *newpo;
struct iouser user;
- struct peropen peropen_context = { root_parent: dotdot };
+ struct peropen peropen_context =
+ {
+ root_parent: dotdot,
+ shadow_root_parent: MACH_PORT_NULL,
+ shadow_root: _diskfs_chroot_directory ? diskfs_root_node : NULL /* XXX */
+ };
if (!pt)
return EOPNOTSUPP;
@@ -61,9 +67,9 @@ diskfs_S_fsys_getroot (fsys_t controlport,
rwlock_reader_lock (&diskfs_fsys_lock);
mutex_lock (&diskfs_root_node->lock);
-
+
/* This code is similar (but not the same as) the code in
- dir-pathtrans.c that does the same thing. Perhaps a way should
+ dir-lookup.c that does the same thing. Perhaps a way should
be found to share the logic. */
type = diskfs_root_node->dn_stat.st_mode & S_IFMT;
@@ -73,7 +79,7 @@ diskfs_S_fsys_getroot (fsys_t controlport,
&& !(flags & O_NOTRANS))
{
error = fshelp_fetch_root (&diskfs_root_node->transbox,
- &peropen_context, dotdot, &user, flags,
+ &peropen_context, dotdot, &user, flags,
_diskfs_translator_callback1,
_diskfs_translator_callback2,
retry, retryname, returned_port);
@@ -86,17 +92,17 @@ diskfs_S_fsys_getroot (fsys_t controlport,
*returned_port_poly = MACH_MSG_TYPE_MOVE_SEND;
return error;
}
-
+
/* ENOENT means the translator was removed in the interim. */
error = 0;
}
-
+
if (type == S_IFLNK && !(flags & (O_NOLINK | O_NOTRANS)))
{
/* Handle symlink interpretation */
char pathbuf[diskfs_root_node->dn_stat.st_size + 1];
- int amt;
-
+ size_t amt;
+
if (diskfs_read_symlink_hook)
error = (*diskfs_read_symlink_hook) (diskfs_root_node, pathbuf);
if (!diskfs_read_symlink_hook || error == EINVAL)
@@ -112,7 +118,7 @@ diskfs_S_fsys_getroot (fsys_t controlport,
drop_idvec ();
return error;
}
-
+
if (pathbuf[0] == '/')
{
*retry = FS_RETRY_MAGICAL;
@@ -134,24 +140,24 @@ diskfs_S_fsys_getroot (fsys_t controlport,
}
}
- if ((type == S_IFSOCK || type == S_IFBLK
+ if ((type == S_IFSOCK || type == S_IFBLK
|| type == S_IFCHR || type == S_IFIFO)
&& (flags & (O_READ|O_WRITE|O_EXEC)))
error = EOPNOTSUPP;
-
+
if (!error && (flags & O_READ))
error = fshelp_access (&diskfs_root_node->dn_stat, S_IREAD, &user);
-
+
if (!error && (flags & O_EXEC))
error = fshelp_access (&diskfs_root_node->dn_stat, S_IEXEC, &user);
-
+
if (!error && (flags & (O_WRITE)))
{
if (type == S_IFDIR)
error = EISDIR;
else if (diskfs_check_readonly ())
error = EROFS;
- else
+ else
error = fshelp_access (&diskfs_root_node->dn_stat,
S_IWRITE, &user);
}
@@ -163,7 +169,7 @@ diskfs_S_fsys_getroot (fsys_t controlport,
drop_idvec ();
return error;
}
-
+
if ((flags & O_NOATIME)
&& (fshelp_isowner (&diskfs_root_node->dn_stat, &user)
== EPERM))
@@ -171,22 +177,25 @@ diskfs_S_fsys_getroot (fsys_t controlport,
flags &= ~OPENONLY_STATE_MODES;
- error =
- diskfs_create_protid (diskfs_make_peropen (diskfs_root_node, flags,
- &peropen_context),
- &user, &newpi);
-
- mach_port_deallocate (mach_task_self (), dotdot);
+ error = diskfs_make_peropen (diskfs_root_node, flags,
+ &peropen_context, &newpo);
+ if (! error)
+ {
+ error = diskfs_create_protid (newpo, &user, &newpi);
+ if (error)
+ diskfs_release_peropen (newpo);
+ }
if (! error)
{
+ mach_port_deallocate (mach_task_self (), dotdot);
*retry = FS_RETRY_NORMAL;
*retryname = '\0';
*returned_port = ports_get_right (newpi);
*returned_port_poly = MACH_MSG_TYPE_MAKE_SEND;
ports_port_deref (newpi);
}
-
+
mutex_unlock (&diskfs_root_node->lock);
rwlock_reader_unlock (&diskfs_fsys_lock);