mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
take descriptor-related part of close() to file.c
Change-Id: I939d86833db0108094a9552a9e6e41ac1d092d87 Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
998d75d211
commit
85efe69668
3 changed files with 29 additions and 21 deletions
26
fs/file.c
26
fs/file.c
|
@ -544,6 +544,32 @@ void fd_install(unsigned int fd, struct file *file)
|
|||
|
||||
EXPORT_SYMBOL(fd_install);
|
||||
|
||||
/*
|
||||
* The same warnings as for __alloc_fd()/__fd_install() apply here...
|
||||
*/
|
||||
int __close_fd(struct files_struct *files, unsigned fd)
|
||||
{
|
||||
struct file *file;
|
||||
struct fdtable *fdt;
|
||||
|
||||
spin_lock(&files->file_lock);
|
||||
fdt = files_fdtable(files);
|
||||
if (fd >= fdt->max_fds)
|
||||
goto out_unlock;
|
||||
file = fdt->fd[fd];
|
||||
if (!file)
|
||||
goto out_unlock;
|
||||
rcu_assign_pointer(fdt->fd[fd], NULL);
|
||||
__clear_close_on_exec(fd, fdt);
|
||||
__put_unused_fd(files, fd);
|
||||
spin_unlock(&files->file_lock);
|
||||
return filp_close(file, files);
|
||||
|
||||
out_unlock:
|
||||
spin_unlock(&files->file_lock);
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
struct file *fget(unsigned int fd)
|
||||
{
|
||||
struct file *file;
|
||||
|
|
22
fs/open.c
22
fs/open.c
|
@ -1082,23 +1082,7 @@ EXPORT_SYMBOL(filp_close);
|
|||
*/
|
||||
SYSCALL_DEFINE1(close, unsigned int, fd)
|
||||
{
|
||||
struct file * filp;
|
||||
struct files_struct *files = current->files;
|
||||
struct fdtable *fdt;
|
||||
int retval;
|
||||
|
||||
spin_lock(&files->file_lock);
|
||||
fdt = files_fdtable(files);
|
||||
if (fd >= fdt->max_fds)
|
||||
goto out_unlock;
|
||||
filp = fdt->fd[fd];
|
||||
if (!filp)
|
||||
goto out_unlock;
|
||||
rcu_assign_pointer(fdt->fd[fd], NULL);
|
||||
__clear_close_on_exec(fd, fdt);
|
||||
__put_unused_fd(files, fd);
|
||||
spin_unlock(&files->file_lock);
|
||||
retval = filp_close(filp, files);
|
||||
int retval = __close_fd(current->files, fd);
|
||||
|
||||
/* can't restart close syscall because file table entry was cleared */
|
||||
if (unlikely(retval == -ERESTARTSYS ||
|
||||
|
@ -1108,10 +1092,6 @@ SYSCALL_DEFINE1(close, unsigned int, fd)
|
|||
retval = -EINTR;
|
||||
|
||||
return retval;
|
||||
|
||||
out_unlock:
|
||||
spin_unlock(&files->file_lock);
|
||||
return -EBADF;
|
||||
}
|
||||
EXPORT_SYMBOL(sys_close);
|
||||
|
||||
|
|
|
@ -129,6 +129,8 @@ extern int __alloc_fd(struct files_struct *files,
|
|||
unsigned start, unsigned end, unsigned flags);
|
||||
extern void __fd_install(struct files_struct *files,
|
||||
unsigned int fd, struct file *file);
|
||||
extern int __close_fd(struct files_struct *files,
|
||||
unsigned int fd);
|
||||
|
||||
extern struct kmem_cache *files_cachep;
|
||||
|
||||
|
|
Loading…
Reference in a new issue