"Clark C. Evans" wrote:
> When I open a file mounted via cd9660 as O_RDONLY and then flock(fd,LOCK_SH)
> it returns invalid argument; is there a reason why the cd-rom file
> system can't just return success here, make flock a no-op that is always
> successful?  There are many cases where you want general code to use
> shared locks on files opened for reading to make sure that it doesn't
> get changed during the read.  This general code should be useable on
> file systems mounted read only.
> 
> Thoughts?  Is there an easy patch?

FreeBSD implements advisory locking wrong; I've tried to get it
fixed several times, but no one is interested.

It looks like someone started to add suport, but then didn't, and
perpetuated the implementation problem.

Here is a patch which finishes adding add advisory locking support
to isofs (wrong way to do it, but only way to do it without changing
VOP_ADVLOCK semantics).

-- Terry
Index: isofs/cd9660/cd9660_vnops.c
===================================================================
RCS file: /cvs/src/sys/isofs/cd9660/cd9660_vnops.c,v
retrieving revision 1.80
diff -c -r1.80 cd9660_vnops.c
*** isofs/cd9660/cd9660_vnops.c 28 Sep 2002 17:14:52 -0000      1.80
--- isofs/cd9660/cd9660_vnops.c 19 Nov 2002 00:13:27 -0000
***************
*** 53,58 ****
--- 53,59 ----
  #include <sys/dirent.h>
  #include <sys/unistd.h>
  #include <sys/filio.h>
+ #include <sys/lockf.h>
  
  #include <vm/vm.h>
  #include <vm/vnode_pager.h>
***************
*** 64,69 ****
--- 65,71 ----
  
  static int cd9660_setattr(struct vop_setattr_args *);
  static int cd9660_access(struct vop_access_args *);
+ static int cd9660_advlock(struct vop_advlock_args *);
  static int cd9660_getattr(struct vop_getattr_args *);
  static int cd9660_ioctl(struct vop_ioctl_args *);
  static int cd9660_pathconf(struct vop_pathconf_args *);
***************
*** 776,787 ****
--- 778,808 ----
  }
  
  /*
+  * Advisory record locking support
+  */
+ static int
+ cd9660_advlock(ap)
+       struct vop_advlock_args /* {
+               struct vnode *a_vp;
+               caddr_t  a_id;
+               int  a_op;
+               struct flock *a_fl;
+               int  a_flags;
+       } */ *ap;
+ {
+       struct iso_node *ip = VTOI(ap->a_vp);
+ 
+       return (lf_advlock(ap, &(ip->i_lockf), ip->i_size));
+ }
+ 
+ /*
   * Global vfs data structures for cd9660
   */
  vop_t **cd9660_vnodeop_p;
  static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
        { &vop_default_desc,            (vop_t *) vop_defaultop },
        { &vop_access_desc,             (vop_t *) cd9660_access },
+       { &vop_advlock_desc,            (vop_t *) cd9660_advlock },
        { &vop_bmap_desc,               (vop_t *) cd9660_bmap },
        { &vop_cachedlookup_desc,       (vop_t *) cd9660_lookup },
        { &vop_getattr_desc,            (vop_t *) cd9660_getattr },

Reply via email to