Skip to content

Commit

Permalink
[PATCH] VFS: change struct file to use struct path
Browse files Browse the repository at this point in the history
This patch changes struct file to use struct path instead of having
independent pointers to struct dentry and struct vfsmount, and converts all
users of f_{dentry,vfsmnt} in fs/ to use f_path.{dentry,mnt}.

Additionally, it adds two #define's to make the transition easier for users of
the f_dentry and f_vfsmnt.

Signed-off-by: Josef "Jeff" Sipek <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Josef "Jeff" Sipek authored and Linus Torvalds committed Dec 8, 2006
1 parent b65d34f commit 0f7fc9e
Show file tree
Hide file tree
Showing 32 changed files with 141 additions and 139 deletions.
8 changes: 4 additions & 4 deletions fs/binfmt_aout.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
N_MAGIC(ex) != QMAGIC && N_MAGIC(ex) != NMAGIC) ||
N_TRSIZE(ex) || N_DRSIZE(ex) ||
i_size_read(bprm->file->f_dentry->d_inode) < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) {
i_size_read(bprm->file->f_path.dentry->d_inode) < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) {
return -ENOEXEC;
}

Expand Down Expand Up @@ -389,7 +389,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
{
printk(KERN_WARNING
"fd_offset is not page aligned. Please convert program: %s\n",
bprm->file->f_dentry->d_name.name);
bprm->file->f_path.dentry->d_name.name);
error_time = jiffies;
}

Expand Down Expand Up @@ -469,7 +469,7 @@ static int load_aout_library(struct file *file)
int retval;
struct exec ex;

inode = file->f_dentry->d_inode;
inode = file->f_path.dentry->d_inode;

retval = -ENOEXEC;
error = kernel_read(file, 0, (char *) &ex, sizeof(ex));
Expand Down Expand Up @@ -506,7 +506,7 @@ static int load_aout_library(struct file *file)
{
printk(KERN_WARNING
"N_TXTOFF is not page aligned. Please convert library: %s\n",
file->f_dentry->d_name.name);
file->f_path.dentry->d_name.name);
error_time = jiffies;
}
down_write(&current->mm->mmap_sem);
Expand Down
2 changes: 1 addition & 1 deletion fs/binfmt_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ static int maydump(struct vm_area_struct *vma)

/* Dump shared memory only if mapped from an anonymous file. */
if (vma->vm_flags & VM_SHARED)
return vma->vm_file->f_dentry->d_inode->i_nlink == 0;
return vma->vm_file->f_path.dentry->d_inode->i_nlink == 0;

/* If it hasn't been written to, don't write it out */
if (!vma->anon_vma)
Expand Down
4 changes: 2 additions & 2 deletions fs/binfmt_elf_fdpic.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,

dynamic_error:
printk("ELF FDPIC %s with invalid DYNAMIC section (inode=%lu)\n",
what, file->f_dentry->d_inode->i_ino);
what, file->f_path.dentry->d_inode->i_ino);
return -ELIBBAD;
}

Expand Down Expand Up @@ -1186,7 +1186,7 @@ static int maydump(struct vm_area_struct *vma)

/* Dump shared memory only if mapped from an anonymous file. */
if (vma->vm_flags & VM_SHARED) {
if (vma->vm_file->f_dentry->d_inode->i_nlink == 0) {
if (vma->vm_file->f_path.dentry->d_inode->i_nlink == 0) {
kdcore("%08lx: %08lx: no (share)", vma->vm_start, vma->vm_flags);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/binfmt_flat.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ static int load_flat_file(struct linux_binprm * bprm,
int ret;

hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */
inode = bprm->file->f_dentry->d_inode;
inode = bprm->file->f_path.dentry->d_inode;

text_len = ntohl(hdr->data_start);
data_len = ntohl(hdr->data_end) - ntohl(hdr->data_start);
Expand Down
10 changes: 5 additions & 5 deletions fs/binfmt_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ static void kill_node(Node *e)
static ssize_t
bm_entry_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos)
{
Node *e = file->f_dentry->d_inode->i_private;
Node *e = file->f_path.dentry->d_inode->i_private;
loff_t pos = *ppos;
ssize_t res;
char *page;
Expand Down Expand Up @@ -576,15 +576,15 @@ static ssize_t bm_entry_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos)
{
struct dentry *root;
Node *e = file->f_dentry->d_inode->i_private;
Node *e = file->f_path.dentry->d_inode->i_private;
int res = parse_command(buffer, count);

switch (res) {
case 1: clear_bit(Enabled, &e->flags);
break;
case 2: set_bit(Enabled, &e->flags);
break;
case 3: root = dget(file->f_vfsmnt->mnt_sb->s_root);
case 3: root = dget(file->f_path.mnt->mnt_sb->s_root);
mutex_lock(&root->d_inode->i_mutex);

kill_node(e);
Expand All @@ -610,7 +610,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
Node *e;
struct inode *inode;
struct dentry *root, *dentry;
struct super_block *sb = file->f_vfsmnt->mnt_sb;
struct super_block *sb = file->f_path.mnt->mnt_sb;
int err = 0;

e = create_entry(buffer, count);
Expand Down Expand Up @@ -699,7 +699,7 @@ static ssize_t bm_status_write(struct file * file, const char __user * buffer,
switch (res) {
case 1: enabled = 0; break;
case 2: enabled = 1; break;
case 3: root = dget(file->f_vfsmnt->mnt_sb->s_root);
case 3: root = dget(file->f_path.mnt->mnt_sb->s_root);
mutex_lock(&root->d_inode->i_mutex);

while (!list_empty(&entries))
Expand Down
4 changes: 2 additions & 2 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static int blkdev_commit_write(struct file *file, struct page *page, unsigned fr

/*
* private llseek:
* for a block special file file->f_dentry->d_inode->i_size is zero
* for a block special file file->f_path.dentry->d_inode->i_size is zero
* so we compute the size by hand (just as in block_read/write above)
*/
static loff_t block_llseek(struct file *file, loff_t offset, int origin)
Expand Down Expand Up @@ -1013,7 +1013,7 @@ static int __blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags,
struct dentry fake_dentry = {};
fake_file.f_mode = mode;
fake_file.f_flags = flags;
fake_file.f_dentry = &fake_dentry;
fake_file.f_path.dentry = &fake_dentry;
fake_dentry.d_inode = bdev->bd_inode;

return do_open(bdev, &fake_file, for_part);
Expand Down
12 changes: 6 additions & 6 deletions fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs __user
file = fget(fd);
if (!file)
goto out;
error = vfs_statfs(file->f_dentry, &tmp);
error = vfs_statfs(file->f_path.dentry, &tmp);
if (!error)
error = put_compat_statfs(buf, &tmp);
fput(file);
Expand Down Expand Up @@ -303,7 +303,7 @@ asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct c
file = fget(fd);
if (!file)
goto out;
error = vfs_statfs(file->f_dentry, &tmp);
error = vfs_statfs(file->f_path.dentry, &tmp);
if (!error)
error = put_compat_statfs64(buf, &tmp);
fput(file);
Expand Down Expand Up @@ -365,7 +365,7 @@ static void compat_ioctl_error(struct file *filp, unsigned int fd,
/* find the name of the device. */
path = (char *)__get_free_page(GFP_KERNEL);
if (path) {
fn = d_path(filp->f_dentry, filp->f_vfsmnt, path, PAGE_SIZE);
fn = d_path(filp->f_path.dentry, filp->f_path.mnt, path, PAGE_SIZE);
if (IS_ERR(fn))
fn = "?";
}
Expand Down Expand Up @@ -416,7 +416,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
case FIBMAP:
case FIGETBSZ:
case FIONREAD:
if (S_ISREG(filp->f_dentry->d_inode->i_mode))
if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
break;
/*FALL THROUGH*/

Expand All @@ -438,7 +438,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
goto found_handler;
}

if (S_ISSOCK(filp->f_dentry->d_inode->i_mode) &&
if (S_ISSOCK(filp->f_path.dentry->d_inode->i_mode) &&
cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
error = siocdevprivate_ioctl(fd, cmd, arg);
} else {
Expand Down Expand Up @@ -1259,7 +1259,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
if (iov != iovstack)
kfree(iov);
if ((ret + (type == READ)) > 0) {
struct dentry *dentry = file->f_dentry;
struct dentry *dentry = file->f_path.dentry;
if (type == READ)
fsnotify_access(dentry);
else
Expand Down
2 changes: 1 addition & 1 deletion fs/compat_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long ar
static int vt_check(struct file *file)
{
struct tty_struct *tty;
struct inode *inode = file->f_dentry->d_inode;
struct inode *inode = file->f_path.dentry->d_inode;

if (file->f_op->ioctl != tty_ioctl)
return -EINVAL;
Expand Down
4 changes: 2 additions & 2 deletions fs/dnotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id)
struct dnotify_struct **prev;
struct inode *inode;

inode = filp->f_dentry->d_inode;
inode = filp->f_path.dentry->d_inode;
if (!S_ISDIR(inode->i_mode))
return;
spin_lock(&inode->i_lock);
Expand Down Expand Up @@ -74,7 +74,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
}
if (!dir_notify_enable)
return -EINVAL;
inode = filp->f_dentry->d_inode;
inode = filp->f_path.dentry->d_inode;
if (!S_ISDIR(inode->i_mode))
return -ENOTDIR;
dn = kmem_cache_alloc(dn_cache, GFP_KERNEL);
Expand Down
4 changes: 2 additions & 2 deletions fs/dquot.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@ static void add_dquot_ref(struct super_block *sb, int type)
file_list_lock();
list_for_each(p, &sb->s_files) {
struct file *filp = list_entry(p, struct file, f_u.fu_list);
struct inode *inode = filp->f_dentry->d_inode;
struct inode *inode = filp->f_path.dentry->d_inode;
if (filp->f_mode & FMODE_WRITE && dqinit_needed(inode, type)) {
struct dentry *dentry = dget(filp->f_dentry);
struct dentry *dentry = dget(filp->f_path.dentry);
file_list_unlock();
sb->dq_op->initialize(inode, type);
dput(dentry);
Expand Down
4 changes: 2 additions & 2 deletions fs/eventpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,8 @@ static int ep_getfd(int *efd, struct inode **einode, struct file **efile,
goto eexit_4;
dentry->d_op = &eventpollfs_dentry_operations;
d_add(dentry, inode);
file->f_vfsmnt = mntget(eventpoll_mnt);
file->f_dentry = dentry;
file->f_path.mnt = mntget(eventpoll_mnt);
file->f_path.dentry = dentry;
file->f_mapping = inode->i_mapping;

file->f_pos = 0;
Expand Down
10 changes: 5 additions & 5 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ EXPORT_SYMBOL(flush_old_exec);
int prepare_binprm(struct linux_binprm *bprm)
{
int mode;
struct inode * inode = bprm->file->f_dentry->d_inode;
struct inode * inode = bprm->file->f_path.dentry->d_inode;
int retval;

mode = inode->i_mode;
Expand All @@ -922,7 +922,7 @@ int prepare_binprm(struct linux_binprm *bprm)
bprm->e_uid = current->euid;
bprm->e_gid = current->egid;

if(!(bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)) {
if(!(bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)) {
/* Set-uid? */
if (mode & S_ISUID) {
current->personality &= ~PER_CLEAR_ON_SETID;
Expand Down Expand Up @@ -1519,10 +1519,10 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
0600);
if (IS_ERR(file))
goto fail_unlock;
inode = file->f_dentry->d_inode;
inode = file->f_path.dentry->d_inode;
if (inode->i_nlink > 1)
goto close_fail; /* multiple links - don't dump */
if (!ispipe && d_unhashed(file->f_dentry))
if (!ispipe && d_unhashed(file->f_path.dentry))
goto close_fail;

/* AK: actually i see no reason to not allow this for named pipes etc.,
Expand All @@ -1533,7 +1533,7 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
goto close_fail;
if (!file->f_op->write)
goto close_fail;
if (!ispipe && do_truncate(file->f_dentry, 0, 0, file) != 0)
if (!ispipe && do_truncate(file->f_path.dentry, 0, 0, file) != 0)
goto close_fail;

retval = binfmt->core_dump(signr, regs, file);
Expand Down
2 changes: 1 addition & 1 deletion fs/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ asmlinkage long sys_dup(unsigned int fildes)

static int setfl(int fd, struct file * filp, unsigned long arg)
{
struct inode * inode = filp->f_dentry->d_inode;
struct inode * inode = filp->f_path.dentry->d_inode;
int error = 0;

/*
Expand Down
10 changes: 5 additions & 5 deletions fs/file_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ EXPORT_SYMBOL(fput);
*/
void fastcall __fput(struct file *file)
{
struct dentry *dentry = file->f_dentry;
struct vfsmount *mnt = file->f_vfsmnt;
struct dentry *dentry = file->f_path.dentry;
struct vfsmount *mnt = file->f_path.mnt;
struct inode *inode = dentry->d_inode;

might_sleep();
Expand All @@ -176,8 +176,8 @@ void fastcall __fput(struct file *file)
put_write_access(inode);
put_pid(file->f_owner.pid);
file_kill(file);
file->f_dentry = NULL;
file->f_vfsmnt = NULL;
file->f_path.dentry = NULL;
file->f_path.mnt = NULL;
file_free(file);
dput(dentry);
mntput(mnt);
Expand Down Expand Up @@ -271,7 +271,7 @@ int fs_may_remount_ro(struct super_block *sb)
file_list_lock();
list_for_each(p, &sb->s_files) {
struct file *file = list_entry(p, struct file, f_u.fu_list);
struct inode *inode = file->f_dentry->d_inode;
struct inode *inode = file->f_path.dentry->d_inode;

/* File with pending delete? */
if (inode->i_nlink == 0)
Expand Down
2 changes: 1 addition & 1 deletion fs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ EXPORT_SYMBOL(touch_atime);

void file_update_time(struct file *file)
{
struct inode *inode = file->f_dentry->d_inode;
struct inode *inode = file->f_path.dentry->d_inode;
struct timespec now;
int sync_it = 0;

Expand Down
6 changes: 3 additions & 3 deletions fs/inotify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ asmlinkage long sys_inotify_init(void)
dev->ih = ih;

filp->f_op = &inotify_fops;
filp->f_vfsmnt = mntget(inotify_mnt);
filp->f_dentry = dget(inotify_mnt->mnt_root);
filp->f_mapping = filp->f_dentry->d_inode->i_mapping;
filp->f_path.mnt = mntget(inotify_mnt);
filp->f_path.dentry = dget(inotify_mnt->mnt_root);
filp->f_mapping = filp->f_path.dentry->d_inode->i_mapping;
filp->f_mode = FMODE_READ;
filp->f_flags = O_RDONLY;
filp->private_data = dev;
Expand Down
14 changes: 7 additions & 7 deletions fs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static long do_ioctl(struct file *filp, unsigned int cmd,
goto out;
} else if (filp->f_op->ioctl) {
lock_kernel();
error = filp->f_op->ioctl(filp->f_dentry->d_inode,
error = filp->f_op->ioctl(filp->f_path.dentry->d_inode,
filp, cmd, arg);
unlock_kernel();
}
Expand All @@ -45,7 +45,7 @@ static int file_ioctl(struct file *filp, unsigned int cmd,
{
int error;
int block;
struct inode * inode = filp->f_dentry->d_inode;
struct inode * inode = filp->f_path.dentry->d_inode;
int __user *p = (int __user *)arg;

switch (cmd) {
Expand Down Expand Up @@ -137,17 +137,17 @@ int vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, unsigned lon
break;

case FIOQSIZE:
if (S_ISDIR(filp->f_dentry->d_inode->i_mode) ||
S_ISREG(filp->f_dentry->d_inode->i_mode) ||
S_ISLNK(filp->f_dentry->d_inode->i_mode)) {
loff_t res = inode_get_bytes(filp->f_dentry->d_inode);
if (S_ISDIR(filp->f_path.dentry->d_inode->i_mode) ||
S_ISREG(filp->f_path.dentry->d_inode->i_mode) ||
S_ISLNK(filp->f_path.dentry->d_inode->i_mode)) {
loff_t res = inode_get_bytes(filp->f_path.dentry->d_inode);
error = copy_to_user((loff_t __user *)arg, &res, sizeof(res)) ? -EFAULT : 0;
}
else
error = -ENOTTY;
break;
default:
if (S_ISREG(filp->f_dentry->d_inode->i_mode))
if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
error = file_ioctl(filp, cmd, arg);
else
error = do_ioctl(filp, cmd, arg);
Expand Down
Loading

0 comments on commit 0f7fc9e

Please sign in to comment.