long do_handle_open(int mountdirfd, struct file_handle __user *ufh, int open_flag) { long retval = 0; struct path path; struct file *file; int fd; retval = handle_to_path(mountdirfd, ufh, &path); if (retval) return retval; fd = get_unused_fd_flags(open_flag); if (fd < 0) { path_put(&path); return fd; } file = file_open_root(path.dentry, path.mnt, "", open_flag); if (IS_ERR(file)) { put_unused_fd(fd); retval = PTR_ERR(file); } else { retval = fd; fsnotify_open(file); fd_install(fd, file); } path_put(&path); return retval; }
int map_write(FSInfo *fs, char *path) { FileHandle *root; FileHandle *bad; if (!map_open_write(path)) return 0; if ((root = file_open_root(fs)) == 0) return 0; walk_dir(root); file_close(root); map_close(); return 1; }
static ssize_t binary_sysctl(const int *name, int nlen, void __user *oldval, size_t oldlen, void __user *newval, size_t newlen) { const struct bin_table *table = NULL; struct vfsmount *mnt; struct file *file; ssize_t result; char *pathname; int flags; pathname = sysctl_getname(name, nlen, &table); result = PTR_ERR(pathname); if (IS_ERR(pathname)) goto out; if (oldval && oldlen && newval && newlen) { flags = O_RDWR; } else if (newval && newlen) { flags = O_WRONLY; } else if (oldval && oldlen) { flags = O_RDONLY; } else { result = 0; goto out_putname; } mnt = current->nsproxy->pid_ns->proc_mnt; file = file_open_root(mnt->mnt_root, mnt, pathname, flags); result = PTR_ERR(file); if (IS_ERR(file)) goto out_putname; result = table->convert(file, oldval, oldlen, newval, newlen); fput(file); out_putname: __putname(pathname); out: return result; }