Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 54484
b: refs/heads/master
c: c2fa1b8
h: refs/heads/master
v: v3
  • Loading branch information
J. Bruce Fields committed Apr 16, 2007
1 parent ca2aa17 commit 6a23d1c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 226a998dbf3c6f9b85f67d08a52c5a2143ed9d88
refs/heads/master: c2fa1b8a6c059dd08a802545fed3badc8df2adc1
61 changes: 36 additions & 25 deletions trunk/fs/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,38 @@ asmlinkage long sys_flock(unsigned int fd, unsigned int cmd)
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.
* This implements the F_GETLK command of fcntl().
*/
Expand Down Expand Up @@ -1645,24 +1677,9 @@ int fcntl_getlk(struct file *filp, struct flock __user *l)

flock.l_type = F_UNLCK;
if (fl != NULL) {
flock.l_pid = fl->fl_pid;
#if BITS_PER_LONG == 32
/*
* Make sure we can represent the posix lock via
* legacy 32bit flock.
*/
error = -EOVERFLOW;
if (fl->fl_start > OFFT_OFFSET_MAX)
goto out;
if ((fl->fl_end != OFFSET_MAX)
&& (fl->fl_end > OFFT_OFFSET_MAX))
error = posix_lock_to_flock(&flock, fl);
if (error)
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;
if (!copy_to_user(l, &flock, sizeof(flock)))
Expand Down Expand Up @@ -1798,14 +1815,8 @@ int fcntl_getlk64(struct file *filp, struct flock64 __user *l)
}

flock.l_type = F_UNLCK;
if (fl != NULL) {
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;
}
if (fl != NULL)
posix_lock_to_flock64(&flock, fl);
error = -EFAULT;
if (!copy_to_user(l, &flock, sizeof(flock)))
error = 0;
Expand Down

0 comments on commit 6a23d1c

Please sign in to comment.