Re: [RFC] Imminent death of /proc/locks predicted; film at 11

From: Peter Samuelson (peter@cadcamlab.org)
Date: Sat Sep 30 2000 - 20:23:37 EST


[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/



This archive was generated by hypermail 2b29 : Sat Sep 30 2000 - 21:00:28 EST