* [PATCH 0/8] filesystem related cleanups and fixes @ 2005-08-23 20:22 Miklos Szeredi 2005-08-23 20:24 ` [PATCH 1/8] remove ia_attr_flags Miklos Szeredi 0 siblings, 1 reply; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:22 UTC (permalink / raw) To: akpm; +Cc: linux-kernel Hi Andrew! The following patches are small cleanups and fixes, I hope none of them are too controversial. It's probably safe to apply ;) Miklos ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 1/8] remove ia_attr_flags 2005-08-23 20:22 [PATCH 0/8] filesystem related cleanups and fixes Miklos Szeredi @ 2005-08-23 20:24 ` Miklos Szeredi 2005-08-23 20:26 ` [PATCH 2/8] namei cleanup Miklos Szeredi 2005-08-24 7:32 ` [PATCH 1/8] remove ia_attr_flags Christoph Hellwig 0 siblings, 2 replies; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:24 UTC (permalink / raw) To: akpm; +Cc: linux-kernel Remove unused ia_attr_flags from struct iattr, and related defines. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Index: linux/fs/hostfs/hostfs.h =================================================================== --- linux.orig/fs/hostfs/hostfs.h 2005-08-19 14:13:47.000000000 +0200 +++ linux/fs/hostfs/hostfs.h 2005-08-19 15:01:48.000000000 +0200 @@ -49,7 +49,6 @@ struct hostfs_iattr { struct timespec ia_atime; struct timespec ia_mtime; struct timespec ia_ctime; - unsigned int ia_attr_flags; }; extern int stat_file(const char *path, unsigned long long *inode_out, Index: linux/include/linux/fs.h =================================================================== --- linux.orig/include/linux/fs.h 2005-08-19 14:58:53.000000000 +0200 +++ linux/include/linux/fs.h 2005-08-19 15:01:06.000000000 +0200 @@ -283,19 +283,9 @@ struct iattr { struct timespec ia_atime; struct timespec ia_mtime; struct timespec ia_ctime; - unsigned int ia_attr_flags; }; /* - * This is the inode attributes flag definitions - */ -#define ATTR_FLAG_SYNCRONOUS 1 /* Syncronous write */ -#define ATTR_FLAG_NOATIME 2 /* Don't update atime */ -#define ATTR_FLAG_APPEND 4 /* Append-only file */ -#define ATTR_FLAG_IMMUTABLE 8 /* Immutable file */ -#define ATTR_FLAG_NODIRATIME 16 /* Don't update atime for directory */ - -/* * Includes for diskquotas. */ #include <linux/quota.h> ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 2/8] namei cleanup 2005-08-23 20:24 ` [PATCH 1/8] remove ia_attr_flags Miklos Szeredi @ 2005-08-23 20:26 ` Miklos Szeredi 2005-08-23 20:30 ` [PATCH 3/8] use get_fs_struct() in proc Miklos Szeredi 2005-08-23 20:33 ` [PATCH 2/8] namei cleanup Al Viro 2005-08-24 7:32 ` [PATCH 1/8] remove ia_attr_flags Christoph Hellwig 1 sibling, 2 replies; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:26 UTC (permalink / raw) To: akpm; +Cc: linux-kernel, viro Extract common code into inline functions to make reading easier. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Index: linux/fs/namei.c =================================================================== --- linux.orig/fs/namei.c 2005-08-23 20:25:53.000000000 +0200 +++ linux/fs/namei.c 2005-08-23 21:00:02.000000000 +0200 @@ -525,6 +525,22 @@ static inline int __do_follow_link(struc return error; } +static inline void dput_path(struct path *path, struct nameidata *nd) +{ + dput(path->dentry); + if (path->mnt != nd->mnt) + mntput(path->mnt); +} + +static inline void path_to_nameidata(struct path *path, struct nameidata *nd) +{ + dput(nd->dentry); + if (nd->mnt != path->mnt) + mntput(nd->mnt); + nd->mnt = path->mnt; + nd->dentry = path->dentry; +} + /* * This limits recursive symlink follows to 8, while * limiting consecutive symlinks to 40. @@ -552,9 +568,7 @@ static inline int do_follow_link(struct nd->depth--; return err; loop: - dput(path->dentry); - if (path->mnt != nd->mnt) - mntput(path->mnt); + dput_path(path, nd); path_release(nd); return err; } @@ -813,13 +827,8 @@ static fastcall int __link_path_walk(con err = -ENOTDIR; if (!inode->i_op) break; - } else { - dput(nd->dentry); - if (nd->mnt != next.mnt) - mntput(nd->mnt); - nd->mnt = next.mnt; - nd->dentry = next.dentry; - } + } else + path_to_nameidata(&next, nd); err = -ENOTDIR; if (!inode->i_op->lookup) break; @@ -859,13 +868,8 @@ last_component: if (err) goto return_err; inode = nd->dentry->d_inode; - } else { - dput(nd->dentry); - if (nd->mnt != next.mnt) - mntput(nd->mnt); - nd->mnt = next.mnt; - nd->dentry = next.dentry; - } + } else + path_to_nameidata(&next, nd); err = -ENOENT; if (!inode) break; @@ -901,9 +905,7 @@ return_reval: return_base: return 0; out_dput: - dput(next.dentry); - if (nd->mnt != next.mnt) - mntput(next.mnt); + dput_path(&next, nd); break; } path_release(nd); @@ -1505,11 +1507,7 @@ do_last: if (path.dentry->d_inode->i_op && path.dentry->d_inode->i_op->follow_link) goto do_link; - dput(nd->dentry); - nd->dentry = path.dentry; - if (nd->mnt != path.mnt) - mntput(nd->mnt); - nd->mnt = path.mnt; + path_to_nameidata(&path, nd); error = -EISDIR; if (path.dentry->d_inode && S_ISDIR(path.dentry->d_inode->i_mode)) goto exit; @@ -1520,9 +1518,7 @@ ok: return 0; exit_dput: - dput(path.dentry); - if (nd->mnt != path.mnt) - mntput(path.mnt); + dput_path(&path, nd); exit: path_release(nd); return error; ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 3/8] use get_fs_struct() in proc 2005-08-23 20:26 ` [PATCH 2/8] namei cleanup Miklos Szeredi @ 2005-08-23 20:30 ` Miklos Szeredi 2005-08-23 20:33 ` [PATCH 4/8] fix enum pid_directory_inos in proc/base.c Miklos Szeredi 2005-08-23 20:33 ` [PATCH 2/8] namei cleanup Al Viro 1 sibling, 1 reply; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:30 UTC (permalink / raw) To: akpm; +Cc: linux-kernel This patch cleans up proc_cwd_link() and proc_root_link() by factoring out common code into get_fs_struct(). Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Index: linux/fs/proc/base.c =================================================================== --- linux.orig/fs/proc/base.c 2005-08-19 14:47:20.000000000 +0200 +++ linux/fs/proc/base.c 2005-08-19 14:47:35.000000000 +0200 @@ -298,15 +298,21 @@ static int proc_fd_link(struct inode *in return -ENOENT; } -static int proc_cwd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) +static struct fs_struct *get_fs_struct(struct task_struct *task) { struct fs_struct *fs; - int result = -ENOENT; - task_lock(proc_task(inode)); - fs = proc_task(inode)->fs; + task_lock(task); + fs = task->fs; if(fs) atomic_inc(&fs->count); - task_unlock(proc_task(inode)); + task_unlock(task); + return fs; +} + +static int proc_cwd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) +{ + struct fs_struct *fs = get_fs_struct(proc_task(inode)); + int result = -ENOENT; if (fs) { read_lock(&fs->lock); *mnt = mntget(fs->pwdmnt); @@ -320,13 +326,8 @@ static int proc_cwd_link(struct inode *i static int proc_root_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt) { - struct fs_struct *fs; + struct fs_struct *fs = get_fs_struct(proc_task(inode)); int result = -ENOENT; - task_lock(proc_task(inode)); - fs = proc_task(inode)->fs; - if(fs) - atomic_inc(&fs->count); - task_unlock(proc_task(inode)); if (fs) { read_lock(&fs->lock); *mnt = mntget(fs->rootmnt); ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 4/8] fix enum pid_directory_inos in proc/base.c 2005-08-23 20:30 ` [PATCH 3/8] use get_fs_struct() in proc Miklos Szeredi @ 2005-08-23 20:33 ` Miklos Szeredi 2005-08-23 20:36 ` [PATCH 5/8] remove duplicated code from proc and ptrace Miklos Szeredi 0 siblings, 1 reply; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:33 UTC (permalink / raw) To: akpm; +Cc: linux-kernel This patch fixes wrongly placed elements in the pid_directory_inos enum. Also add comment so this mistake is not repeated. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Index: linux/fs/proc/base.c =================================================================== --- linux.orig/fs/proc/base.c 2005-08-19 14:47:35.000000000 +0200 +++ linux/fs/proc/base.c 2005-08-19 14:47:36.000000000 +0200 @@ -120,7 +120,6 @@ enum pid_directory_inos { #ifdef CONFIG_AUDITSYSCALL PROC_TGID_LOGINUID, #endif - PROC_TGID_FD_DIR, PROC_TGID_OOM_SCORE, PROC_TGID_OOM_ADJUST, PROC_TID_INO, @@ -159,9 +158,11 @@ enum pid_directory_inos { #ifdef CONFIG_AUDITSYSCALL PROC_TID_LOGINUID, #endif - PROC_TID_FD_DIR = 0x8000, /* 0x8000-0xffff */ PROC_TID_OOM_SCORE, PROC_TID_OOM_ADJUST, + + /* Add new entries before this */ + PROC_TID_FD_DIR = 0x8000, /* 0x8000-0xffff */ }; struct pid_entry { ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 5/8] remove duplicated code from proc and ptrace 2005-08-23 20:33 ` [PATCH 4/8] fix enum pid_directory_inos in proc/base.c Miklos Szeredi @ 2005-08-23 20:36 ` Miklos Szeredi 2005-08-23 20:43 ` [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs Miklos Szeredi 0 siblings, 1 reply; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:36 UTC (permalink / raw) To: akpm; +Cc: linux-kernel Extract common code used by ptrace_attach() and may_ptrace_attach() into a separate function. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Index: linux/kernel/ptrace.c =================================================================== --- linux.orig/kernel/ptrace.c 2005-08-19 14:47:20.000000000 +0200 +++ linux/kernel/ptrace.c 2005-08-19 14:47:36.000000000 +0200 @@ -118,6 +118,33 @@ int ptrace_check_attach(struct task_stru return ret; } +static int may_attach(struct task_struct *task) +{ + if (!task->mm) + return -EPERM; + if (((current->uid != task->euid) || + (current->uid != task->suid) || + (current->uid != task->uid) || + (current->gid != task->egid) || + (current->gid != task->sgid) || + (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE)) + return -EPERM; + smp_rmb(); + if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE)) + return -EPERM; + + return security_ptrace(current, task); +} + +int ptrace_may_attach(struct task_struct *task) +{ + int err; + task_lock(task); + err = may_attach(task); + task_unlock(task); + return !err; +} + int ptrace_attach(struct task_struct *task) { int retval; @@ -127,22 +154,10 @@ int ptrace_attach(struct task_struct *ta goto bad; if (task == current) goto bad; - if (!task->mm) - goto bad; - if(((current->uid != task->euid) || - (current->uid != task->suid) || - (current->uid != task->uid) || - (current->gid != task->egid) || - (current->gid != task->sgid) || - (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE)) - goto bad; - smp_rmb(); - if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE)) - goto bad; /* the same process cannot be attached many times */ if (task->ptrace & PT_PTRACED) goto bad; - retval = security_ptrace(current, task); + retval = may_attach(task); if (retval) goto bad; Index: linux/include/linux/ptrace.h =================================================================== --- linux.orig/include/linux/ptrace.h 2005-08-19 14:47:20.000000000 +0200 +++ linux/include/linux/ptrace.h 2005-08-19 14:47:36.000000000 +0200 @@ -90,6 +90,7 @@ extern void __ptrace_link(struct task_st struct task_struct *new_parent); extern void __ptrace_unlink(struct task_struct *child); extern void ptrace_untrace(struct task_struct *child); +extern int ptrace_may_attach(struct task_struct *task); static inline void ptrace_link(struct task_struct *child, struct task_struct *new_parent) Index: linux/fs/proc/base.c =================================================================== --- linux.orig/fs/proc/base.c 2005-08-19 14:47:36.000000000 +0200 +++ linux/fs/proc/base.c 2005-08-19 14:47:36.000000000 +0200 @@ -347,33 +347,6 @@ static int proc_root_link(struct inode * (task->state == TASK_STOPPED || task->state == TASK_TRACED) && \ security_ptrace(current,task) == 0)) -static int may_ptrace_attach(struct task_struct *task) -{ - int retval = 0; - - task_lock(task); - - if (!task->mm) - goto out; - if (((current->uid != task->euid) || - (current->uid != task->suid) || - (current->uid != task->uid) || - (current->gid != task->egid) || - (current->gid != task->sgid) || - (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE)) - goto out; - rmb(); - if (task->mm->dumpable != 1 && !capable(CAP_SYS_PTRACE)) - goto out; - if (security_ptrace(current, task)) - goto out; - - retval = 1; -out: - task_unlock(task); - return retval; -} - static int proc_pid_environ(struct task_struct *task, char * buffer) { int res = 0; @@ -383,7 +356,7 @@ static int proc_pid_environ(struct task_ if (len > PAGE_SIZE) len = PAGE_SIZE; res = access_process_vm(task, mm->env_start, buffer, len, 0); - if (!may_ptrace_attach(task)) + if (!ptrace_may_attach(task)) res = -ESRCH; mmput(mm); } @@ -686,7 +659,7 @@ static ssize_t mem_read(struct file * fi int ret = -ESRCH; struct mm_struct *mm; - if (!MAY_PTRACE(task) || !may_ptrace_attach(task)) + if (!MAY_PTRACE(task) || !ptrace_may_attach(task)) goto out; ret = -ENOMEM; @@ -712,7 +685,7 @@ static ssize_t mem_read(struct file * fi this_len = (count > PAGE_SIZE) ? PAGE_SIZE : count; retval = access_process_vm(task, src, page, this_len, 0); - if (!retval || !MAY_PTRACE(task) || !may_ptrace_attach(task)) { + if (!retval || !MAY_PTRACE(task) || !ptrace_may_attach(task)) { if (!ret) ret = -EIO; break; @@ -750,7 +723,7 @@ static ssize_t mem_write(struct file * f struct task_struct *task = proc_task(file->f_dentry->d_inode); unsigned long dst = *ppos; - if (!MAY_PTRACE(task) || !may_ptrace_attach(task)) + if (!MAY_PTRACE(task) || !ptrace_may_attach(task)) return -ESRCH; page = (char *)__get_free_page(GFP_USER); ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs 2005-08-23 20:36 ` [PATCH 5/8] remove duplicated code from proc and ptrace Miklos Szeredi @ 2005-08-23 20:43 ` Miklos Szeredi 2005-08-23 20:45 ` [PATCH 7/8] cifs_create() fix Miklos Szeredi ` (2 more replies) 0 siblings, 3 replies; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:43 UTC (permalink / raw) To: akpm; +Cc: linux-kernel 64 bit architectures all implement their own compatibility sys_open(), when in fact the difference is simply not forcing the O_LARGEFILE flag. So use the a common function instead. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Index: linux/include/linux/fs.h =================================================================== --- linux.orig/include/linux/fs.h 2005-08-23 21:00:01.000000000 +0200 +++ linux/include/linux/fs.h 2005-08-23 21:00:18.000000000 +0200 @@ -1286,6 +1286,7 @@ static inline int break_lease(struct ino /* fs/open.c */ extern int do_truncate(struct dentry *, loff_t start); +extern long do_sys_open(const char __user *filename, int flags, int mode); extern struct file *filp_open(const char *, int, int); extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); extern int filp_close(struct file *, fl_owner_t id); Index: linux/fs/open.c =================================================================== --- linux.orig/fs/open.c 2005-08-23 20:25:54.000000000 +0200 +++ linux/fs/open.c 2005-08-23 21:00:18.000000000 +0200 @@ -938,16 +938,11 @@ void fastcall fd_install(unsigned int fd EXPORT_SYMBOL(fd_install); -asmlinkage long sys_open(const char __user * filename, int flags, int mode) +long do_sys_open(const char __user *filename, int flags, int mode) { - char * tmp; - int fd; + char *tmp = getname(filename); + int fd = PTR_ERR(tmp); - if (force_o_largefile()) - flags |= O_LARGEFILE; - - tmp = getname(filename); - fd = PTR_ERR(tmp); if (!IS_ERR(tmp)) { fd = get_unused_fd(); if (fd >= 0) { @@ -964,6 +959,14 @@ asmlinkage long sys_open(const char __us } return fd; } + +asmlinkage long sys_open(const char __user *filename, int flags, int mode) +{ + if (force_o_largefile()) + flags |= O_LARGEFILE; + + return do_sys_open(filename, flags, mode); +} EXPORT_SYMBOL_GPL(sys_open); #ifndef __alpha__ Index: linux/arch/x86_64/ia32/sys_ia32.c =================================================================== --- linux.orig/arch/x86_64/ia32/sys_ia32.c 2005-08-23 20:22:33.000000000 +0200 +++ linux/arch/x86_64/ia32/sys_ia32.c 2005-08-23 21:00:19.000000000 +0200 @@ -971,28 +971,7 @@ long sys32_kill(int pid, int sig) asmlinkage long sys32_open(const char __user * filename, int flags, int mode) { - char * tmp; - int fd, error; - - /* don't force O_LARGEFILE */ - tmp = getname(filename); - fd = PTR_ERR(tmp); - if (!IS_ERR(tmp)) { - fd = get_unused_fd(); - if (fd >= 0) { - struct file *f = filp_open(tmp, flags, mode); - error = PTR_ERR(f); - if (IS_ERR(f)) { - put_unused_fd(fd); - fd = error; - } else { - fsnotify_open(f->f_dentry); - fd_install(fd, f); - } - } - putname(tmp); - } - return fd; + return do_sys_open(filename, flags, mode); } extern asmlinkage long Index: linux/arch/ppc64/kernel/sys_ppc32.c =================================================================== --- linux.orig/arch/ppc64/kernel/sys_ppc32.c 2005-08-23 20:22:31.000000000 +0200 +++ linux/arch/ppc64/kernel/sys_ppc32.c 2005-08-23 21:00:19.000000000 +0200 @@ -873,29 +873,7 @@ off_t ppc32_lseek(unsigned int fd, u32 o */ asmlinkage long sys32_open(const char __user * filename, int flags, int mode) { - char * tmp; - int fd, error; - - tmp = getname(filename); - fd = PTR_ERR(tmp); - if (!IS_ERR(tmp)) { - fd = get_unused_fd(); - if (fd >= 0) { - struct file * f = filp_open(tmp, flags, mode); - error = PTR_ERR(f); - if (IS_ERR(f)) - goto out_error; - fd_install(fd, f); - } -out: - putname(tmp); - } - return fd; - -out_error: - put_unused_fd(fd); - fd = error; - goto out; + return do_sys_open(filename, flags, mode); } /* Note: it is necessary to treat bufsiz as an unsigned int, Index: linux/arch/ia64/ia32/sys_ia32.c =================================================================== --- linux.orig/arch/ia64/ia32/sys_ia32.c 2005-06-17 21:48:29.000000000 +0200 +++ linux/arch/ia64/ia32/sys_ia32.c 2005-08-23 21:00:19.000000000 +0200 @@ -2365,29 +2365,7 @@ sys32_brk (unsigned int brk) asmlinkage long sys32_open (const char __user * filename, int flags, int mode) { - char * tmp; - int fd, error; - - tmp = getname(filename); - fd = PTR_ERR(tmp); - if (!IS_ERR(tmp)) { - fd = get_unused_fd(); - if (fd >= 0) { - struct file *f = filp_open(tmp, flags, mode); - error = PTR_ERR(f); - if (IS_ERR(f)) - goto out_error; - fd_install(fd, f); - } -out: - putname(tmp); - } - return fd; - -out_error: - put_unused_fd(fd); - fd = error; - goto out; + return do_sys_open(filename, flags, mode); } /* Structure for ia32 emulation on ia64 */ Index: linux/arch/sparc64/kernel/sys_sparc32.c =================================================================== --- linux.orig/arch/sparc64/kernel/sys_sparc32.c 2005-06-17 21:48:29.000000000 +0200 +++ linux/arch/sparc64/kernel/sys_sparc32.c 2005-08-23 21:00:19.000000000 +0200 @@ -1002,29 +1002,7 @@ asmlinkage long sys32_adjtimex(struct ti asmlinkage long sparc32_open(const char __user *filename, int flags, int mode) { - char * tmp; - int fd, error; - - tmp = getname(filename); - fd = PTR_ERR(tmp); - if (!IS_ERR(tmp)) { - fd = get_unused_fd(); - if (fd >= 0) { - struct file * f = filp_open(tmp, flags, mode); - error = PTR_ERR(f); - if (IS_ERR(f)) - goto out_error; - fd_install(fd, f); - } -out: - putname(tmp); - } - return fd; - -out_error: - put_unused_fd(fd); - fd = error; - goto out; + return do_sys_open(filename, flags, mode); } extern unsigned long do_mremap(unsigned long addr, ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 7/8] cifs_create() fix 2005-08-23 20:43 ` [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs Miklos Szeredi @ 2005-08-23 20:45 ` Miklos Szeredi 2005-08-23 20:47 ` [PATCH 8/8] deprecate open("foo", 3) Miklos Szeredi 2005-08-23 21:44 ` [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs Arnd Bergmann 2005-08-24 7:33 ` Christoph Hellwig 2 siblings, 1 reply; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:45 UTC (permalink / raw) To: akpm; +Cc: linux-kernel, smfrench cifs_create() did totally the wrong thing with nd->intent.open.flags: it interpreted nd->intent.open.flags as the original open flags, not the one transformed for open_namei(). Also it used the intent data even if it was not filled in (if called from sys_mknod()). Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Index: linux/fs/cifs/dir.c =================================================================== --- linux.orig/fs/cifs/dir.c 2005-08-23 11:01:58.000000000 +0200 +++ linux/fs/cifs/dir.c 2005-08-23 11:09:03.000000000 +0200 @@ -145,24 +145,23 @@ cifs_create(struct inode *inode, struct return -ENOMEM; } - if(nd) { - if ((nd->intent.open.flags & O_ACCMODE) == O_RDONLY) - desiredAccess = GENERIC_READ; - else if ((nd->intent.open.flags & O_ACCMODE) == O_WRONLY) { - desiredAccess = GENERIC_WRITE; - write_only = TRUE; - } else if ((nd->intent.open.flags & O_ACCMODE) == O_RDWR) { - /* GENERIC_ALL is too much permission to request */ - /* can cause unnecessary access denied on create */ - /* desiredAccess = GENERIC_ALL; */ - desiredAccess = GENERIC_READ | GENERIC_WRITE; + if(nd && (nd->flags & LOOKUP_OPEN)) { + int oflags = nd->intent.open.flags; + + desiredAccess = 0; + if (oflags & FMODE_READ) + desiredAccess |= GENERIC_READ; + if (oflags & FMODE_WRITE) { + desiredAccess |= GENERIC_WRITE; + if (!(oflags & FMODE_READ)) + write_only = TRUE; } - if((nd->intent.open.flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) + if((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) disposition = FILE_CREATE; - else if((nd->intent.open.flags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC)) + else if((oflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC)) disposition = FILE_OVERWRITE_IF; - else if((nd->intent.open.flags & O_CREAT) == O_CREAT) + else if((oflags & O_CREAT) == O_CREAT) disposition = FILE_OPEN_IF; else { cFYI(1,("Create flag not set in create function")); ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 8/8] deprecate open("foo", 3) 2005-08-23 20:45 ` [PATCH 7/8] cifs_create() fix Miklos Szeredi @ 2005-08-23 20:47 ` Miklos Szeredi 0 siblings, 0 replies; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:47 UTC (permalink / raw) To: akpm; +Cc: linux-kernel Deprecate access mode of '3' in open() as suggested by Linus. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Index: linux/fs/open.c =================================================================== --- linux.orig/fs/open.c 2005-08-23 13:15:49.000000000 +0200 +++ linux/fs/open.c 2005-08-23 13:16:15.000000000 +0200 @@ -756,6 +756,17 @@ struct file *filp_open(const char * file { int namei_flags, error; struct nameidata nd; + static int warned; + + /* + * Access mode of 3 had some old uses, that are probably not + * applicable anymore. For now just warn about deprecation. + * Later it can be changed to return -EINVAL. + */ + if ((flags & O_ACCMODE) == 3 && warned < 5) { + warned++; + printk(KERN_WARNING "Warning: '%s' (pid=%i) uses deprecated open flags, please report!\n", current->comm, current->tgid); + } namei_flags = flags; if ((namei_flags+1) & O_ACCMODE) ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs 2005-08-23 20:43 ` [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs Miklos Szeredi 2005-08-23 20:45 ` [PATCH 7/8] cifs_create() fix Miklos Szeredi @ 2005-08-23 21:44 ` Arnd Bergmann 2005-08-24 8:58 ` Miklos Szeredi 2005-08-24 7:33 ` Christoph Hellwig 2 siblings, 1 reply; 17+ messages in thread From: Arnd Bergmann @ 2005-08-23 21:44 UTC (permalink / raw) To: Miklos Szeredi; +Cc: akpm, linux-kernel On Dinsdag 23 August 2005 22:43, Miklos Szeredi wrote: > 64 bit architectures all implement their own compatibility sys_open(), > when in fact the difference is simply not forcing the O_LARGEFILE > flag. So use the a common function instead. > Index: linux/arch/x86_64/ia32/sys_ia32.c > =================================================================== > --- linux.orig/arch/x86_64/ia32/sys_ia32.c 2005-08-23 20:22:33.000000000 +0200 > +++ linux/arch/x86_64/ia32/sys_ia32.c 2005-08-23 21:00:19.000000000 +0200 > @@ -971,28 +971,7 @@ long sys32_kill(int pid, int sig) > > asmlinkage long sys32_open(const char __user * filename, int flags, int mode) > { > - char * tmp; > - int fd, error; Please don't leave the functions inside of the architecture specific code. The code is common enough to be shared, so just put a new compat_sys_open() function into fs/compat.c. I'm also not sure wether s390, mips and/or parisc need to use the same function instead of the standard sys_open(). Arnd <>< ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs 2005-08-23 21:44 ` [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs Arnd Bergmann @ 2005-08-24 8:58 ` Miklos Szeredi 0 siblings, 0 replies; 17+ messages in thread From: Miklos Szeredi @ 2005-08-24 8:58 UTC (permalink / raw) To: arnd; +Cc: akpm, linux-kernel > Please don't leave the functions inside of the architecture specific code. > The code is common enough to be shared, so just put a new compat_sys_open() > function into fs/compat.c. OK. Done for x86_64, ia64, ppc64. Sparc64 does magic things with sparc32_open(), so I left it as it is. > I'm also not sure wether s390, mips and/or parisc need to use the > same function instead of the standard sys_open(). I have no idea. Andrew, could you please apply this one? Thanks, Miklos --- 64 bit architectures all implement their own compatibility sys_open(), when in fact the difference is simply not forcing the O_LARGEFILE flag. So use the a common function instead. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Index: linux/include/linux/fs.h =================================================================== --- linux.orig/include/linux/fs.h 2005-08-23 14:56:06.000000000 +0200 +++ linux/include/linux/fs.h 2005-08-24 10:27:08.000000000 +0200 @@ -1287,6 +1287,7 @@ static inline int break_lease(struct ino /* fs/open.c */ extern int do_truncate(struct dentry *, loff_t start); +extern long do_sys_open(const char __user *filename, int flags, int mode); extern struct file *filp_open(const char *, int, int); extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); extern int filp_close(struct file *, fl_owner_t id); Index: linux/fs/open.c =================================================================== --- linux.orig/fs/open.c 2005-08-23 14:36:20.000000000 +0200 +++ linux/fs/open.c 2005-08-24 10:30:33.000000000 +0200 @@ -938,16 +938,11 @@ void fastcall fd_install(unsigned int fd EXPORT_SYMBOL(fd_install); -asmlinkage long sys_open(const char __user * filename, int flags, int mode) +long do_sys_open(const char __user *filename, int flags, int mode) { - char * tmp; - int fd; + char *tmp = getname(filename); + int fd = PTR_ERR(tmp); - if (force_o_largefile()) - flags |= O_LARGEFILE; - - tmp = getname(filename); - fd = PTR_ERR(tmp); if (!IS_ERR(tmp)) { fd = get_unused_fd(); if (fd >= 0) { @@ -964,6 +959,14 @@ asmlinkage long sys_open(const char __us } return fd; } + +asmlinkage long sys_open(const char __user *filename, int flags, int mode) +{ + if (force_o_largefile()) + flags |= O_LARGEFILE; + + return do_sys_open(filename, flags, mode); +} EXPORT_SYMBOL_GPL(sys_open); #ifndef __alpha__ Index: linux/arch/x86_64/ia32/sys_ia32.c =================================================================== --- linux.orig/arch/x86_64/ia32/sys_ia32.c 2005-08-23 14:36:20.000000000 +0200 +++ linux/arch/x86_64/ia32/sys_ia32.c 2005-08-24 10:29:50.000000000 +0200 @@ -969,32 +969,6 @@ long sys32_kill(int pid, int sig) return sys_kill(pid, sig); } -asmlinkage long sys32_open(const char __user * filename, int flags, int mode) -{ - char * tmp; - int fd, error; - - /* don't force O_LARGEFILE */ - tmp = getname(filename); - fd = PTR_ERR(tmp); - if (!IS_ERR(tmp)) { - fd = get_unused_fd(); - if (fd >= 0) { - struct file *f = filp_open(tmp, flags, mode); - error = PTR_ERR(f); - if (IS_ERR(f)) { - put_unused_fd(fd); - fd = error; - } else { - fsnotify_open(f->f_dentry); - fd_install(fd, f); - } - } - putname(tmp); - } - return fd; -} - extern asmlinkage long sys_timer_create(clockid_t which_clock, struct sigevent __user *timer_event_spec, Index: linux/arch/ppc64/kernel/sys_ppc32.c =================================================================== --- linux.orig/arch/ppc64/kernel/sys_ppc32.c 2005-08-23 14:36:20.000000000 +0200 +++ linux/arch/ppc64/kernel/sys_ppc32.c 2005-08-24 10:34:59.000000000 +0200 @@ -867,37 +867,6 @@ off_t ppc32_lseek(unsigned int fd, u32 o return sys_lseek(fd, (int)offset, origin); } -/* - * This is just a version for 32-bit applications which does - * not force O_LARGEFILE on. - */ -asmlinkage long sys32_open(const char __user * filename, int flags, int mode) -{ - char * tmp; - int fd, error; - - tmp = getname(filename); - fd = PTR_ERR(tmp); - if (!IS_ERR(tmp)) { - fd = get_unused_fd(); - if (fd >= 0) { - struct file * f = filp_open(tmp, flags, mode); - error = PTR_ERR(f); - if (IS_ERR(f)) - goto out_error; - fd_install(fd, f); - } -out: - putname(tmp); - } - return fd; - -out_error: - put_unused_fd(fd); - fd = error; - goto out; -} - /* Note: it is necessary to treat bufsiz as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) Index: linux/arch/ia64/ia32/sys_ia32.c =================================================================== --- linux.orig/arch/ia64/ia32/sys_ia32.c 2005-08-23 14:36:20.000000000 +0200 +++ linux/arch/ia64/ia32/sys_ia32.c 2005-08-24 10:38:19.000000000 +0200 @@ -2359,37 +2359,6 @@ sys32_brk (unsigned int brk) return ret; } -/* - * Exactly like fs/open.c:sys_open(), except that it doesn't set the O_LARGEFILE flag. - */ -asmlinkage long -sys32_open (const char __user * filename, int flags, int mode) -{ - char * tmp; - int fd, error; - - tmp = getname(filename); - fd = PTR_ERR(tmp); - if (!IS_ERR(tmp)) { - fd = get_unused_fd(); - if (fd >= 0) { - struct file *f = filp_open(tmp, flags, mode); - error = PTR_ERR(f); - if (IS_ERR(f)) - goto out_error; - fd_install(fd, f); - } -out: - putname(tmp); - } - return fd; - -out_error: - put_unused_fd(fd); - fd = error; - goto out; -} - /* Structure for ia32 emulation on ia64 */ struct epoll_event32 { Index: linux/arch/sparc64/kernel/sys_sparc32.c =================================================================== --- linux.orig/arch/sparc64/kernel/sys_sparc32.c 2005-08-23 14:36:20.000000000 +0200 +++ linux/arch/sparc64/kernel/sys_sparc32.c 2005-08-23 14:56:06.000000000 +0200 @@ -1002,29 +1002,7 @@ asmlinkage long sys32_adjtimex(struct ti asmlinkage long sparc32_open(const char __user *filename, int flags, int mode) { - char * tmp; - int fd, error; - - tmp = getname(filename); - fd = PTR_ERR(tmp); - if (!IS_ERR(tmp)) { - fd = get_unused_fd(); - if (fd >= 0) { - struct file * f = filp_open(tmp, flags, mode); - error = PTR_ERR(f); - if (IS_ERR(f)) - goto out_error; - fd_install(fd, f); - } -out: - putname(tmp); - } - return fd; - -out_error: - put_unused_fd(fd); - fd = error; - goto out; + return do_sys_open(filename, flags, mode); } extern unsigned long do_mremap(unsigned long addr, Index: linux/arch/x86_64/ia32/ia32entry.S =================================================================== --- linux.orig/arch/x86_64/ia32/ia32entry.S 2005-08-19 14:14:35.000000000 +0200 +++ linux/arch/x86_64/ia32/ia32entry.S 2005-08-24 10:28:42.000000000 +0200 @@ -298,7 +298,7 @@ ia32_sys_call_table: .quad stub32_fork .quad sys_read .quad sys_write - .quad sys32_open /* 5 */ + .quad compat_sys_open /* 5 */ .quad sys_close .quad sys32_waitpid .quad sys_creat Index: linux/arch/ia64/ia32/ia32_entry.S =================================================================== --- linux.orig/arch/ia64/ia32/ia32_entry.S 2005-06-24 13:21:28.000000000 +0200 +++ linux/arch/ia64/ia32/ia32_entry.S 2005-08-24 10:37:14.000000000 +0200 @@ -215,7 +215,7 @@ ia32_syscall_table: data8 sys32_fork data8 sys_read data8 sys_write - data8 sys32_open /* 5 */ + data8 compat_sys_open /* 5 */ data8 sys_close data8 sys32_waitpid data8 sys_creat Index: linux/arch/ppc64/kernel/misc.S =================================================================== --- linux.orig/arch/ppc64/kernel/misc.S 2005-08-19 14:14:33.000000000 +0200 +++ linux/arch/ppc64/kernel/misc.S 2005-08-24 10:36:11.000000000 +0200 @@ -859,7 +859,7 @@ _GLOBAL(sys_call_table32) .llong .ppc_fork .llong .sys_read .llong .sys_write - .llong .sys32_open /* 5 */ + .llong .compat_sys_open /* 5 */ .llong .sys_close .llong .sys32_waitpid .llong .sys32_creat Index: linux/fs/compat.c =================================================================== --- linux.orig/fs/compat.c 2005-08-24 10:40:44.000000000 +0200 +++ linux/fs/compat.c 2005-08-24 10:56:44.000000000 +0200 @@ -1277,6 +1277,16 @@ out: } /* + * Exactly like fs/open.c:sys_open(), except that it doesn't set the + * O_LARGEFILE flag. + */ +asmlinkage long +compat_sys_open(const char __user *filename, int flags, int mode) +{ + return do_sys_open(filename, flags, mode); +} + +/* * compat_count() counts the number of arguments/envelopes. It is basically * a copy of count() from fs/exec.c, except that it works with 32 bit argv * and envp pointers. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs 2005-08-23 20:43 ` [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs Miklos Szeredi 2005-08-23 20:45 ` [PATCH 7/8] cifs_create() fix Miklos Szeredi 2005-08-23 21:44 ` [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs Arnd Bergmann @ 2005-08-24 7:33 ` Christoph Hellwig 2005-08-24 9:00 ` Miklos Szeredi 2 siblings, 1 reply; 17+ messages in thread From: Christoph Hellwig @ 2005-08-24 7:33 UTC (permalink / raw) To: Miklos Szeredi; +Cc: akpm, linux-kernel On Tue, Aug 23, 2005 at 10:43:35PM +0200, Miklos Szeredi wrote: > 64 bit architectures all implement their own compatibility sys_open(), > when in fact the difference is simply not forcing the O_LARGEFILE > flag. So use the a common function instead. Traditional naming would be just do_open(), but else this looks very nice. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs 2005-08-24 7:33 ` Christoph Hellwig @ 2005-08-24 9:00 ` Miklos Szeredi 2005-08-24 9:05 ` Christoph Hellwig 0 siblings, 1 reply; 17+ messages in thread From: Miklos Szeredi @ 2005-08-24 9:00 UTC (permalink / raw) To: hch; +Cc: akpm, linux-kernel > On Tue, Aug 23, 2005 at 10:43:35PM +0200, Miklos Szeredi wrote: > > 64 bit architectures all implement their own compatibility sys_open(), > > when in fact the difference is simply not forcing the O_LARGEFILE > > flag. So use the a common function instead. > > Traditional naming would be just do_open(), but else this looks very nice. do_open() was my first choice, but it caused a number of clashes. Miklos ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs 2005-08-24 9:00 ` Miklos Szeredi @ 2005-08-24 9:05 ` Christoph Hellwig 0 siblings, 0 replies; 17+ messages in thread From: Christoph Hellwig @ 2005-08-24 9:05 UTC (permalink / raw) To: Miklos Szeredi; +Cc: hch, akpm, linux-kernel On Wed, Aug 24, 2005 at 11:00:07AM +0200, Miklos Szeredi wrote: > > On Tue, Aug 23, 2005 at 10:43:35PM +0200, Miklos Szeredi wrote: > > > 64 bit architectures all implement their own compatibility sys_open(), > > > when in fact the difference is simply not forcing the O_LARGEFILE > > > flag. So use the a common function instead. > > > > Traditional naming would be just do_open(), but else this looks very nice. > > do_open() was my first choice, but it caused a number of clashes. ok, let's leave it the way it is.. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/8] namei cleanup 2005-08-23 20:26 ` [PATCH 2/8] namei cleanup Miklos Szeredi 2005-08-23 20:30 ` [PATCH 3/8] use get_fs_struct() in proc Miklos Szeredi @ 2005-08-23 20:33 ` Al Viro 2005-08-23 20:50 ` Miklos Szeredi 1 sibling, 1 reply; 17+ messages in thread From: Al Viro @ 2005-08-23 20:33 UTC (permalink / raw) To: Miklos Szeredi; +Cc: akpm, linux-kernel On Tue, Aug 23, 2005 at 10:26:53PM +0200, Miklos Szeredi wrote: Bad names, IMO. > +static inline void dput_path(struct path *path, struct nameidata *nd) > +{ > + dput(path->dentry); > + if (path->mnt != nd->mnt) > + mntput(path->mnt); > +} > + > +static inline void path_to_nameidata(struct path *path, struct nameidata *nd) > +{ > + dput(nd->dentry); > + if (nd->mnt != path->mnt) > + mntput(nd->mnt); > + nd->mnt = path->mnt; > + nd->dentry = path->dentry; > +} ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/8] namei cleanup 2005-08-23 20:33 ` [PATCH 2/8] namei cleanup Al Viro @ 2005-08-23 20:50 ` Miklos Szeredi 0 siblings, 0 replies; 17+ messages in thread From: Miklos Szeredi @ 2005-08-23 20:50 UTC (permalink / raw) To: viro; +Cc: akpm, linux-kernel > Bad names, IMO. > You're probably right. Can you suggest better ones? Thanks, Miklos > > +static inline void dput_path(struct path *path, struct nameidata *nd) > > +{ > > + dput(path->dentry); > > + if (path->mnt != nd->mnt) > > + mntput(path->mnt); > > +} > > + > > +static inline void path_to_nameidata(struct path *path, struct nameidata *nd) > > +{ > > + dput(nd->dentry); > > + if (nd->mnt != path->mnt) > > + mntput(nd->mnt); > > + nd->mnt = path->mnt; > > + nd->dentry = path->dentry; > > +} ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/8] remove ia_attr_flags 2005-08-23 20:24 ` [PATCH 1/8] remove ia_attr_flags Miklos Szeredi 2005-08-23 20:26 ` [PATCH 2/8] namei cleanup Miklos Szeredi @ 2005-08-24 7:32 ` Christoph Hellwig 1 sibling, 0 replies; 17+ messages in thread From: Christoph Hellwig @ 2005-08-24 7:32 UTC (permalink / raw) To: Miklos Szeredi; +Cc: akpm, linux-kernel On Tue, Aug 23, 2005 at 10:24:30PM +0200, Miklos Szeredi wrote: > Remove unused ia_attr_flags from struct iattr, and related defines. I had actually planned to make use of this, by adding a common helper for the ext2-style file flags ioctl so all the checking is moved outside the filesystems. OTOH I planned this forever and didn't get ver far, so it's probably okay to remove it - I can put it back when needed. ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2005-08-24 9:05 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-23 20:22 [PATCH 0/8] filesystem related cleanups and fixes Miklos Szeredi
2005-08-23 20:24 ` [PATCH 1/8] remove ia_attr_flags Miklos Szeredi
2005-08-23 20:26 ` [PATCH 2/8] namei cleanup Miklos Szeredi
2005-08-23 20:30 ` [PATCH 3/8] use get_fs_struct() in proc Miklos Szeredi
2005-08-23 20:33 ` [PATCH 4/8] fix enum pid_directory_inos in proc/base.c Miklos Szeredi
2005-08-23 20:36 ` [PATCH 5/8] remove duplicated code from proc and ptrace Miklos Szeredi
2005-08-23 20:43 ` [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs Miklos Szeredi
2005-08-23 20:45 ` [PATCH 7/8] cifs_create() fix Miklos Szeredi
2005-08-23 20:47 ` [PATCH 8/8] deprecate open("foo", 3) Miklos Szeredi
2005-08-23 21:44 ` [PATCH 6/8] remove duplicated sys_open32() code from 64bit archs Arnd Bergmann
2005-08-24 8:58 ` Miklos Szeredi
2005-08-24 7:33 ` Christoph Hellwig
2005-08-24 9:00 ` Miklos Szeredi
2005-08-24 9:05 ` Christoph Hellwig
2005-08-23 20:33 ` [PATCH 2/8] namei cleanup Al Viro
2005-08-23 20:50 ` Miklos Szeredi
2005-08-24 7:32 ` [PATCH 1/8] remove ia_attr_flags Christoph Hellwig
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox