home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / sys / vfs.h < prev    next >
C/C++ Source or Header  |  1993-10-19  |  6KB  |  173 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software License Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  *
  7.  * HISTORY
  8.  *  7-Jan-93  Mac Gillon (mgillon) at NeXT
  9.  *    Integrate POSIX support
  10.  *
  11.  * 27-Sep-89  Morris Meyer (mmeyer) at NeXT
  12.  *    NFS 4.0 Changes.
  13.  */ 
  14.  
  15. #ifndef VFS_H
  16. #define VFS_H
  17.  
  18. #if !defined(_MAXNAMLEN)
  19. #define _MAXNAMLEN
  20. #define    MAXNAMLEN    255
  21. #endif /* _MAXNAMLEN */
  22.  
  23. /* @(#)vfs.h 2.2 88/05/25 4.0NFSSRC SMI; from vfs.h 2.15 87/01/14 SMI    */
  24.  
  25. /*
  26.  * File system identifier. Should be unique (at least per machine).
  27.  */
  28. typedef struct {
  29.     long val[2];            /* file system id type */
  30. } fsid_t;
  31.  
  32. /*
  33.  * File identifier. Should be unique per filesystem on a single machine.
  34.  */
  35. #define    MAXFIDSZ    16
  36. #define freefid(fidp) \
  37.     kfree((caddr_t)(fidp), sizeof (struct fid) - MAXFIDSZ + (fidp)->fid_len)
  38.  
  39. struct fid {
  40.     u_short        fid_len;        /* length of data in bytes */
  41.     char        fid_data[MAXFIDSZ];    /* data (variable length) */
  42. };
  43.  
  44. /*
  45.  * Structure per mounted file system.
  46.  * Each mounted file system has an array of
  47.  * operations and an instance record.
  48.  * The file systems are put on a singly linked list.
  49.  */
  50. struct vfs {
  51.     struct vfs    *vfs_next;        /* next vfs in vfs list */
  52.     struct vfsops    *vfs_op;        /* operations on vfs */
  53.     struct vnode    *vfs_vnodecovered;    /* vnode we mounted on */
  54.     int        vfs_flag;        /* flags */
  55.     int        vfs_bsize;        /* native block size */
  56.     fsid_t        vfs_fsid;        /* file system id */
  57.     caddr_t     vfs_stats;        /* filesystem statistics */
  58.     char        vfs_name[MAXNAMLEN+1];    /* name if faking dir entry */
  59.     struct vfs    *vfs_nextentry;        /* next fake entry in vnode */ 
  60.     uid_t        vfs_uid;        /* user who mounted this */
  61.     caddr_t        vfs_data;        /* private data */
  62. };
  63.  
  64. /*
  65.  * vfs flags.
  66.  * VFS_MLOCK lock the vfs so that name lookup cannot proceed past the vfs.
  67.  * This keeps the subtree stable during mounts and unmounts.
  68.  */
  69. #define VFS_RDONLY    0x01        /* read only vfs */
  70. #define VFS_MLOCK    0x02        /* lock vfs so that subtree is stable */
  71. #define VFS_MWAIT    0x04        /* someone is waiting for lock */
  72. #define VFS_NOSUID    0x08        /* turn off set-uid on exec */
  73. #if    NeXT
  74. /*
  75.  * For now, just overload NOSUID bit, since we don't want to change
  76.  * mount command, etc.  When this gets its own bit, we'll have to
  77.  * edit sys/mount.h to add M_NODEV and mntent.h to add MNTOPT_NODEV
  78.  * along with hacking all the appropriate programs.
  79.  */
  80. #define VFS_NODEV    VFS_NOSUID    /* no access to blk and char dev */
  81. #endif    NeXT
  82. #define VFS_GRPID    0x10        /* Old BSD group-id on create */
  83. #define VFS_NOSUB    0x20        /* No mounts allowed beneath this fs */
  84. #define VFS_REMOUNT    0x40        /* modify mount otions only */
  85. #define VFS_MULTI    0x80        /* Do multi-component lookup on files */
  86.  
  87. /*
  88.  * Operations supported on virtual file system.
  89.  */
  90. struct vfsops {
  91.     int    (*vfs_mount)();        /* mount file system */
  92.     int    (*vfs_unmount)();    /* unmount file system */
  93.     int    (*vfs_root)();        /* get root vnode */
  94.     int    (*vfs_statfs)();    /* get fs statistics */
  95.     int    (*vfs_sync)();        /* flush fs buffers */
  96.     int    (*vfs_vget)();        /* get vnode from fid */
  97.     int    (*vfs_mountroot)();    /* mount the root filesystem */
  98. #ifndef MACH
  99.     int    (*vfs_swapvp)();    /* return vnode for swap */
  100. #endif  MACH
  101. };
  102.  
  103. #define VFS_MOUNT(VFSP, PATH, DATA) \
  104.                  (*(VFSP)->vfs_op->vfs_mount)(VFSP, PATH, DATA)
  105. #define VFS_UNMOUNT(VFSP)     (*(VFSP)->vfs_op->vfs_unmount)(VFSP)
  106. #define VFS_ROOT(VFSP, VPP)     (*(VFSP)->vfs_op->vfs_root)(VFSP,VPP)
  107. #define VFS_STATFS(VFSP, SBP)     (*(VFSP)->vfs_op->vfs_statfs)(VFSP,SBP)
  108. #define VFS_SYNC(VFSP)         (*(VFSP)->vfs_op->vfs_sync)(VFSP)
  109. #define VFS_VGET(VFSP, VPP, FIDP) (*(VFSP)->vfs_op->vfs_vget)(VFSP, VPP, FIDP)
  110. #define VFS_MOUNTROOT(VFSP, VPP, NM) \
  111.                  (*(VFSP)->vfs_op->vfs_mountroot)(VFSP, VPP, NM)
  112. #ifndef MACH
  113. #define VFS_SWAPVP(VFSP, VPP, NM) (*(VFSP)->vfs_op->vfs_swapvp)(VFSP, VPP, NM)
  114. #endif  MACH
  115.  
  116. /*
  117.  * file system statistics
  118.  */
  119. struct statfs {
  120.     long f_type;            /* type of info, zero for now */
  121.     long f_bsize;            /* fundamental file system block size */
  122.     long f_blocks;            /* total blocks in file system */
  123.     long f_bfree;            /* free block in fs */
  124.     long f_bavail;            /* free blocks avail to non-superuser */
  125.     long f_files;            /* total file nodes in file system */
  126.     long f_ffree;            /* free file nodes in fs */
  127.     fsid_t f_fsid;            /* file system id */
  128.     long f_spare[7];        /* spare for later */
  129. };
  130.  
  131. #ifdef KERNEL
  132. /*
  133.  * Filesystem type switch table
  134.  */
  135. struct vfssw {
  136.     char        *vsw_name;    /* type name string */
  137.     struct vfsops    *vsw_ops;    /* filesystem operations vector */
  138. };
  139.  
  140. /*
  141.  * public operations
  142.  */
  143. extern void    vfs_mountroot();    /* mount the root */
  144. extern int    vfs_add();        /* add a new vfs to mounted vfs list */
  145. extern void    vfs_remove();        /* remove a vfs from mounted vfs list */
  146. extern int    vfs_lock();        /* lock a vfs */
  147. extern void    vfs_unlock();        /* unlock a vfs */
  148. extern struct vfs *getvfs();        /* return vfs given fsid */
  149. extern struct vfssw *getfstype();    /* find default filesystem type */
  150. extern int vfs_getmajor();        /* get major device # for an fs type */
  151. extern void vfs_putmajor();        /* free major device # for an fs type */
  152. extern int vfs_getnum();        /* get device # for an fs type */
  153. extern void vfs_putnum();        /* release device # for an fs type */
  154.  
  155. #define VFS_INIT(VFSP, OP, DATA)    { \
  156.     (VFSP)->vfs_next = (struct vfs *)0; \
  157.     (VFSP)->vfs_op = (OP); \
  158.     (VFSP)->vfs_flag = 0; \
  159.     (VFSP)->vfs_stats = NULL; \
  160.     (VFSP)->vfs_data = (DATA); \
  161.     (VFSP)->vfs_nextentry = (struct vfs *)0; \
  162.     (VFSP)->vfs_uid = u.u_uid; \
  163. }
  164. /*
  165.  * globals
  166.  */
  167. extern struct vfs *rootvfs;        /* ptr to root vfs structure */
  168. extern struct vfssw vfssw[];        /* table of filesystem types */
  169. extern struct vfssw *vfsNVFS;        /* vfs switch table end marker */
  170. #endif
  171.  
  172. #endif /* def VFS_H */
  173.