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/