lkml.org 
[lkml]   [2000]   [Sep]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [RFC] Imminent death of /proc/locks predicted; film at 11
From

[Matthew Wilcox]
> if fcntl took a 4th argument specifying the length of the buffer, i'd
> recommend a F_GETLKS fcntl. a horrid work around for this would be
> that the first 4 bytes of the buffer pointed to by the third argument
> of the fcntl is the length of the buffer.

Ewwww! You're right, it's horrid. Anyway, I think this one can be
solved in userspace -- as long as you don't need atomicity. Untested
code with no error checking:

#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

void report_locks(int fd, void (*report)(int, struct flock *))
{
off_t start, end;
struct flock f;
struct stat st;

fstat(fd, &st);
start = 0; end = st.st_size;

while (start <= end) {
f.l_type = F_WRLCK;
f.l_whence = L_SET;
f.l_start = start;
f.l_len = end-start;
fcntl (fd, F_GETLK, &f);

if (f.l_type == F_UNLCK) /* region is free for the taking */
break;
report (fd, &f);
start = f.l_start + f.l_len + 1;
}
}

Alan, is this roughly what you want?

Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:39    [W:0.207 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site