diff options
author | Sergiu Ivanov <unlimitedscolobb@gmail.com> | 2008-10-01 21:08:57 +0300 |
---|---|---|
committer | Sergiu Ivanov <unlimitedscolobb@gmail.com> | 2008-10-01 21:08:57 +0300 |
commit | 7200dac108c4a8981b7f7f5f90757409c3e6d5bf (patch) | |
tree | 4d870907262ca5ced29115c45f838d9f4252a04d | |
parent | 783e451ddefe81ef0c83412569b0a99c415f28d9 (diff) |
Cloned the native implementation of netfs_S_fsys_getroot.
I cloned the native implementation of netfs_S_fsys_getroot,
since we filter translators run on nsmux nodes to see the
translator stacks of the real filesystem nodes.
-rw-r--r-- | nsmux.c | 129 | ||||
-rw-r--r-- | nsmux.h | 19 |
2 files changed, 148 insertions, 0 deletions
@@ -1382,6 +1382,135 @@ netfs_S_dir_lookup return error; }/*netfs_S_dir_lookup*/ /*----------------------------------------------------------------------------*/ +/*Responds to RPC fsys_getroot*/ +error_t +netfs_S_fsys_getroot + ( + mach_port_t cntl, + mach_port_t reply, + mach_msg_type_name_t reply_type, + mach_port_t dotdot, + uid_t *uids, + mach_msg_type_number_t nuids, + uid_t *gids, + mach_msg_type_number_t ngids, + int flags, + retry_type *do_retry, + char *retry_name, + mach_port_t *retry_port, + mach_msg_type_name_t *retry_port_type + ) + { + LOG_MSG("netfs_S_fsys_getroot"); + + struct port_info *pt = ports_lookup_port (netfs_port_bucket, cntl, + netfs_control_class); + struct iouser *cred; + error_t err; + struct protid *newpi; + mode_t type; + struct peropen peropen_context = { root_parent: dotdot }; + + if (!pt) + return EOPNOTSUPP; + ports_port_deref (pt); + + err = iohelp_create_complex_iouser (&cred, uids, nuids, gids, ngids); + if (err) + return err; + + flags &= O_HURD; + + mutex_lock (&netfs_root_node->lock); + err = netfs_validate_stat (netfs_root_node, cred); + if (err) + goto out; + + type = netfs_root_node->nn_stat.st_mode & S_IFMT; + + if (((netfs_root_node->nn_stat.st_mode & S_IPTRANS) + || fshelp_translated (&netfs_root_node->transbox)) + && !(flags & O_NOTRANS)) + { + err = fshelp_fetch_root (&netfs_root_node->transbox, + &peropen_context, dotdot, cred, flags, + _netfs_translator_callback1, + _netfs_translator_callback2, + do_retry, retry_name, retry_port); + if (err != ENOENT) + { + mutex_unlock (&netfs_root_node->lock); + iohelp_free_iouser (cred); + if (!err) + *retry_port_type = MACH_MSG_TYPE_MOVE_SEND; + return err; + } + /* ENOENT means translator has vanished inside fshelp_fetch_root. */ + err = 0; + } + + if (type == S_IFLNK && !(flags & (O_NOLINK | O_NOTRANS))) + { + char pathbuf[netfs_root_node->nn_stat.st_size + 1]; + + err = netfs_attempt_readlink (cred, netfs_root_node, pathbuf); + + if (err) + goto out; + + mutex_unlock (&netfs_root_node->lock); + iohelp_free_iouser (cred); + + if (pathbuf[0] == '/') + { + *do_retry = FS_RETRY_MAGICAL; + *retry_port = MACH_PORT_NULL; + *retry_port_type = MACH_MSG_TYPE_COPY_SEND; + strcpy (retry_name, pathbuf); + mach_port_deallocate (mach_task_self (), dotdot); + return 0; + } + else + { + *do_retry = FS_RETRY_REAUTH; + *retry_port = dotdot; + *retry_port_type = MACH_MSG_TYPE_MOVE_SEND; + strcpy (retry_name, pathbuf); + return 0; + } + } + + if ((type == S_IFSOCK || type == S_IFBLK || type == S_IFCHR + || type == S_IFIFO) && (flags & (O_READ|O_WRITE|O_EXEC))) + { + err = EOPNOTSUPP; + goto out; + } + + err = netfs_check_open_permissions (cred, netfs_root_node, flags, 0); + if (err) + goto out; + + flags &= ~OPENONLY_STATE_MODES; + + newpi = netfs_make_protid (netfs_make_peropen (netfs_root_node, flags, + &peropen_context), + cred); + mach_port_deallocate (mach_task_self (), dotdot); + + *do_retry = FS_RETRY_NORMAL; + *retry_port = ports_get_right (newpi); + *retry_port_type = MACH_MSG_TYPE_MAKE_SEND; + retry_name[0] = '\0'; + ports_port_deref (newpi); + + out: + if (err) + iohelp_free_iouser (cred); + mutex_unlock (&netfs_root_node->lock); + return err; + }/*netfs_S_fsys_getroot*/ +/*----------------------------------------------------------------------------*/ /*Deletes `name` in `dir` for `user`*/ error_t netfs_attempt_unlink @@ -186,6 +186,25 @@ netfs_S_dir_lookup mach_msg_type_number_t * retry_port_type ); /*----------------------------------------------------------------------------*/ +/*Responds to RPC fsys_getroot*/ +error_t +netfs_S_fsys_getroot + ( + mach_port_t cntl, + mach_port_t reply, + mach_msg_type_name_t reply_type, + mach_port_t dotdot, + uid_t *uids, + mach_msg_type_number_t nuids, + uid_t *gids, + mach_msg_type_number_t ngids, + int flags, + retry_type *do_retry, + char *retry_name, + mach_port_t *retry_port, + mach_msg_type_name_t *retry_port_type + ); +/*----------------------------------------------------------------------------*/ /*Deletes `name` in `dir` for `user`*/ error_t netfs_attempt_unlink |