mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-03-30 11:04:25 +00:00
locks: create posix-to-flock helper functions
Factor out a bit of messy code by creating posix-to-flock counterparts to the existing flock-to-posix helper functions. Cc: Christoph Hellwig <hch@infradead.org> Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
This commit is contained in:
parent
226a998dbf
commit
c2fa1b8a6c
1 changed files with 36 additions and 25 deletions
61
fs/locks.c
61
fs/locks.c
|
@ -1611,6 +1611,38 @@ asmlinkage long sys_flock(unsigned int fd, unsigned int cmd)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl)
|
||||||
|
{
|
||||||
|
flock->l_pid = fl->fl_pid;
|
||||||
|
#if BITS_PER_LONG == 32
|
||||||
|
/*
|
||||||
|
* Make sure we can represent the posix lock via
|
||||||
|
* legacy 32bit flock.
|
||||||
|
*/
|
||||||
|
if (fl->fl_start > OFFT_OFFSET_MAX)
|
||||||
|
return -EOVERFLOW;
|
||||||
|
if (fl->fl_end != OFFSET_MAX && fl->fl_end > OFFT_OFFSET_MAX)
|
||||||
|
return -EOVERFLOW;
|
||||||
|
#endif
|
||||||
|
flock->l_start = fl->fl_start;
|
||||||
|
flock->l_len = fl->fl_end == OFFSET_MAX ? 0 :
|
||||||
|
fl->fl_end - fl->fl_start + 1;
|
||||||
|
flock->l_whence = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if BITS_PER_LONG == 32
|
||||||
|
static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl)
|
||||||
|
{
|
||||||
|
flock->l_pid = fl->fl_pid;
|
||||||
|
flock->l_start = fl->fl_start;
|
||||||
|
flock->l_len = fl->fl_end == OFFSET_MAX ? 0 :
|
||||||
|
fl->fl_end - fl->fl_start + 1;
|
||||||
|
flock->l_whence = 0;
|
||||||
|
flock->l_type = fl->fl_type;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Report the first existing lock that would conflict with l.
|
/* Report the first existing lock that would conflict with l.
|
||||||
* This implements the F_GETLK command of fcntl().
|
* This implements the F_GETLK command of fcntl().
|
||||||
*/
|
*/
|
||||||
|
@ -1645,24 +1677,9 @@ int fcntl_getlk(struct file *filp, struct flock __user *l)
|
||||||
|
|
||||||
flock.l_type = F_UNLCK;
|
flock.l_type = F_UNLCK;
|
||||||
if (fl != NULL) {
|
if (fl != NULL) {
|
||||||
flock.l_pid = fl->fl_pid;
|
error = posix_lock_to_flock(&flock, fl);
|
||||||
#if BITS_PER_LONG == 32
|
if (error)
|
||||||
/*
|
|
||||||
* Make sure we can represent the posix lock via
|
|
||||||
* legacy 32bit flock.
|
|
||||||
*/
|
|
||||||
error = -EOVERFLOW;
|
|
||||||
if (fl->fl_start > OFFT_OFFSET_MAX)
|
|
||||||
goto out;
|
goto out;
|
||||||
if ((fl->fl_end != OFFSET_MAX)
|
|
||||||
&& (fl->fl_end > OFFT_OFFSET_MAX))
|
|
||||||
goto out;
|
|
||||||
#endif
|
|
||||||
flock.l_start = fl->fl_start;
|
|
||||||
flock.l_len = fl->fl_end == OFFSET_MAX ? 0 :
|
|
||||||
fl->fl_end - fl->fl_start + 1;
|
|
||||||
flock.l_whence = 0;
|
|
||||||
flock.l_type = fl->fl_type;
|
|
||||||
}
|
}
|
||||||
error = -EFAULT;
|
error = -EFAULT;
|
||||||
if (!copy_to_user(l, &flock, sizeof(flock)))
|
if (!copy_to_user(l, &flock, sizeof(flock)))
|
||||||
|
@ -1798,14 +1815,8 @@ int fcntl_getlk64(struct file *filp, struct flock64 __user *l)
|
||||||
}
|
}
|
||||||
|
|
||||||
flock.l_type = F_UNLCK;
|
flock.l_type = F_UNLCK;
|
||||||
if (fl != NULL) {
|
if (fl != NULL)
|
||||||
flock.l_pid = fl->fl_pid;
|
posix_lock_to_flock64(&flock, fl);
|
||||||
flock.l_start = fl->fl_start;
|
|
||||||
flock.l_len = fl->fl_end == OFFSET_MAX ? 0 :
|
|
||||||
fl->fl_end - fl->fl_start + 1;
|
|
||||||
flock.l_whence = 0;
|
|
||||||
flock.l_type = fl->fl_type;
|
|
||||||
}
|
|
||||||
error = -EFAULT;
|
error = -EFAULT;
|
||||||
if (!copy_to_user(l, &flock, sizeof(flock)))
|
if (!copy_to_user(l, &flock, sizeof(flock)))
|
||||||
error = 0;
|
error = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue