home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 8.ddi / usr / include / sys / fs / ufs_inode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  10.8 KB  |  370 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ident  "@(#)/usr/include/sys/fs/ufs_inode.h.sl 1.1 4.0 12/08/90 28655 AT&T-USL"
  11.  
  12. #ifndef _SYS_FS_UFS_INODE_H
  13. #define _SYS_FS_UFS_INODE_H
  14.  
  15.  
  16.  
  17. /*
  18.  * The I node is the focus of all local file activity in UNIX.
  19.  * There is a unique inode allocated for each active file,
  20.  * each current directory, each mounted-on file, each mapping,
  21.  * and the root.  An inode is `named' by its dev/inumber pair.
  22.  * Data in icommon is read in from permanent inode on volume.
  23.  */
  24.  
  25. #define EFT_MAGIC 0x90909090    /* magic cookie for EFT */
  26. #define    NDADDR    12        /* direct addresses in inode */
  27. #define    NIADDR    3        /* indirect addresses in inode */
  28.  
  29. struct inode {
  30.     struct    inode *i_chain[2];    /* must be first */
  31.     struct    vnode i_vnode;    /* vnode associated with this inode */
  32.     struct    vnode *i_devvp;    /* vnode for block I/O */
  33.     u_short    i_flag;
  34.     dev_t    i_dev;        /* device where inode resides */
  35.     ino_t    i_number;    /* i number, 1-to-1 with device address */
  36.     off_t    i_diroff;    /* offset in dir, where we found last entry */
  37.     struct    fs *i_fs;    /* file sys associated with this inode */
  38.     struct    dquot *i_dquot;    /* quota structure controlling this file */
  39.     short    i_owner;    /* proc index of process locking inode */
  40.     short    i_count;    /* number of inode locks for i_owner */
  41.     daddr_t    i_nextr;    /* next byte read offset (read-ahead) */
  42.     struct inode  *i_freef;    /* free list forward */
  43.     struct inode **i_freeb;    /* free list back */
  44.     ulong    i_vcode;    /* version code attribute */
  45.     long    i_mapcnt;    /* mappings to file pages */
  46.     int    *i_map;        /* block list for the corresponding file */
  47.  
  48.     int    i_mapsz;    /* kmem_alloc'ed size */
  49.     int    i_oldsz;    /* i_size when you did the allocation */
  50.  
  51.     struct     icommon {
  52.         o_mode_t ic_smode;    /*  0: mode and type of file */
  53.         short    ic_nlink;    /*  2: number of links to file */
  54.         o_uid_t    ic_suid;        /*  4: owner's user id */
  55.         o_gid_t    ic_sgid;        /*  6: owner's group id */
  56.         quad    ic_size;    /*  8: number of bytes in file */
  57. #ifdef _KERNEL
  58.         struct timeval ic_atime;/* 16: time last accessed */
  59.         struct timeval ic_mtime;/* 24: time last modified */
  60.         struct timeval ic_ctime;/* 32: last time inode changed */
  61. #else
  62.         time_t    ic_atime;    /* 16: time last accessed */
  63.         long    ic_atspare;
  64.         time_t    ic_mtime;    /* 24: time last modified */
  65.         long    ic_mtspare;
  66.         time_t    ic_ctime;    /* 32: last time inode changed */
  67.         long    ic_ctspare;
  68. #endif
  69.         daddr_t    ic_db[NDADDR];    /* 40: disk block addresses */
  70.         daddr_t    ic_ib[NIADDR];    /* 88: indirect blocks */
  71.         long    ic_flags;    /* 100: status, currently unused */
  72.         long    ic_blocks;    /* 104: blocks actually held */
  73.         long    ic_gen;        /* 108: generation number */
  74.         mode_t    ic_mode;    /* 112: EFT version of mode*/
  75.         uid_t    ic_uid;        /* 116: EFT version of uid */
  76.         gid_t    ic_gid;        /* 120: EFT version of gid */
  77.         ulong    ic_eftflag;    /* 124: indicate EFT version*/
  78.  
  79.     } i_ic;
  80. };
  81.  
  82. struct dinode {
  83.     union {
  84.         struct    icommon di_icom;
  85.         char    di_size[128];
  86.     } di_un;
  87. };
  88. #define i_mode        i_ic.ic_mode
  89. #define    i_nlink        i_ic.ic_nlink
  90. #define i_uid        i_ic.ic_uid
  91. #define i_gid        i_ic.ic_gid
  92. #define i_smode        i_ic.ic_smode
  93. #define i_suid        i_ic.ic_suid
  94. #define i_sgid        i_ic.ic_sgid
  95. #define i_eftflag    i_ic.ic_eftflag
  96.  
  97. /* ugh! -- must be fixed */
  98. #if defined(vax) || defined(i386)
  99. #define    i_size        i_ic.ic_size.val[0]
  100. #endif
  101. #if defined(mc68000) || defined(sparc) || defined(u3b2) || defined(u3b15)
  102. #define    i_size        i_ic.ic_size.val[1]
  103. #endif
  104. #define    i_db        i_ic.ic_db
  105. #define    i_ib        i_ic.ic_ib
  106.  
  107. #define    i_atime        i_ic.ic_atime
  108. #define    i_mtime        i_ic.ic_mtime
  109. #define    i_ctime        i_ic.ic_ctime
  110.  
  111. #define i_blocks    i_ic.ic_blocks
  112. #define    i_oldrdev    i_ic.ic_db[0]
  113. #define    i_rdev        i_ic.ic_db[1]
  114. #define    i_gen        i_ic.ic_gen
  115. #define    i_forw        i_chain[0]
  116. #define    i_back        i_chain[1]
  117.  
  118. #define di_ic        di_un.di_icom
  119. #define    di_mode        di_ic.ic_mode
  120. #define    di_nlink    di_ic.ic_nlink
  121. #define    di_uid        di_ic.ic_uid
  122. #define    di_gid        di_ic.ic_gid
  123. #define di_smode    di_ic.ic_smode
  124. #define di_suid        di_ic.ic_suid
  125. #define di_sgid        di_ic.ic_sgid
  126. #define di_eftflag    di_ic.ic_eftflag
  127.  
  128. #if defined(vax) || defined(i386)
  129. #define    di_size        di_ic.ic_size.val[0]
  130. #endif
  131. #if defined(mc68000) || defined(sparc) || defined(u3b2) || defined(u3b15)
  132. #define    di_size        di_ic.ic_size.val[1]
  133. #endif
  134. #define    di_db        di_ic.ic_db
  135. #define    di_ib        di_ic.ic_ib
  136.  
  137. #define    di_atime    di_ic.ic_atime
  138. #define    di_mtime    di_ic.ic_mtime
  139. #define    di_ctime    di_ic.ic_ctime
  140.  
  141. #define    di_oldrdev    di_ic.ic_db[0]
  142. #define    di_rdev        di_ic.ic_db[1]
  143. #define    di_blocks    di_ic.ic_blocks
  144. #define    di_gen        di_ic.ic_gen
  145.  
  146. /* flags */
  147. #define    ILOCKED        0x001        /* inode is locked */
  148. #define    IUPD        0x002        /* file has been modified */
  149. #define    IACC        0x004        /* inode access time to be updated */
  150. #define    IMOD        0x008        /* inode has been modified */
  151. #define    IWANT        0x010        /* some process waiting on lock */
  152. #define    ISYNC        0x020        /* do all allocation synchronously */
  153. #define    ICHG        0x040        /* inode has been changed */
  154. #define    ILWAIT        0x080        /* someone waiting on file lock */
  155. #define    IREF        0x100        /* inode is being referenced */
  156. #define    INOACC        0x200        /* no access time update in getpage */
  157. #define    IMODTIME    0x400        /* mod time already set */
  158. #define    IINACTIVE    0x800        /* iinactive in progress */
  159. #define    IRWLOCKED    0x1000        /* inode is rwlocked */
  160.  
  161. /* modes */
  162. #define    IFMT        0170000        /* type of file */
  163. #define    IFIFO        0010000        /* named pipe (fifo) */
  164. #define    IFCHR        0020000        /* character special */
  165. #define    IFDIR        0040000        /* directory */
  166. #define    IFBLK        0060000        /* block special */
  167. #define    IFREG        0100000        /* regular */
  168. #define    IFLNK        0120000        /* symbolic link */
  169. #define    IFSOCK        0140000        /* socket */
  170.  
  171. #define    ISUID        04000        /* set user id on execution */
  172. #define    ISGID        02000        /* set group id on execution */
  173. #define    ISVTX        01000        /* save swapped text even after use */
  174. #define    IREAD        0400        /* read, write, execute permissions */
  175. #define    IWRITE        0200
  176. #define    IEXEC        0100
  177.  
  178.  
  179. #ifdef _KERNEL
  180. struct inode *ufs_inode;        /* the inode table itself */
  181. struct inode *inodeNINODE;        /* the end of the inode table */
  182. extern int ufs_ninode;            /* number of slots in the table */
  183.  
  184. extern struct vnodeops ufs_vnodeops;    /* vnode operations for ufs */
  185.  
  186. extern ino_t dirpref();
  187. extern daddr_t blkpref();
  188.  
  189. /*
  190.  * A struct fbuf is used to get a mapping to part of a file using the
  191.  * segkmap facilities.  After you get a mapping, you can fbrelse() it
  192.  * (giving a seg code to pass back to segmap_release), you can fbwrite()
  193.  * it (causes a synchronous write back using inode mapping information),
  194.  * or you can fbiwrite it (causing indirect synchronous write back to
  195.  * the block number given without using inode mapping information).
  196.  */
  197.  
  198. struct fbuf {
  199.     addr_t    fb_addr;
  200.     u_int    fb_count;
  201. };
  202.  
  203. extern int fbread(/* vp, off, len, rw, fbpp */);
  204. extern void fbzero(/* vp, off, len, fbpp */);
  205. extern int fbwrite(/* fb */);
  206. extern int fbiwrite(/* fb, ip, bn */);
  207. extern void fbrelse(/* fb, rw */);
  208.  
  209. /*
  210.  * Convert between inode pointers and vnode pointers
  211.  */
  212. #define VTOI(VP)    ((struct inode *)(VP)->v_data)
  213. #define ITOV(IP)    ((struct vnode *)&(IP)->i_vnode)
  214.  
  215. #ifdef notneeded
  216. Look at sys/mode.h and os/vnode.c
  217. /*
  218.  * Convert between vnode types and inode formats
  219.  */
  220. extern enum vtype    iftovt_tab[];
  221. extern int        vttoif_tab[];
  222. #define IFTOVT(M)    (iftovt_tab[((M) & IFMT) >> 13])
  223. #define VTTOIF(T)    (vttoif_tab[(int)(T)])
  224.  
  225. #define MAKEIMODE(T, M)    (VTTOIF(T) | (M))
  226. #endif
  227.  
  228. /*
  229.  * Lock and unlock inodes.
  230.  */
  231. #define    IRWLOCK(ip) { \
  232.     while ((ip)->i_flag & IRWLOCKED) { \
  233.         (ip)->i_flag |= IWANT; \
  234.         (void) sleep((caddr_t)(ip), PINOD); \
  235.     } \
  236.     (ip)->i_flag |= IRWLOCKED; \
  237.     if (((ip)->i_vnode.v_flag & VISSWAP) != 0){ \
  238.         curproc->p_swlocks++;    \
  239.         curproc->p_flag |= SSWLOCKS;\
  240.     } \
  241. }
  242.  
  243. #define    IRWUNLOCK(ip) { \
  244.     ASSERT((ip)->i_flag & IRWLOCKED); \
  245.     if (((ip)->i_vnode.v_flag & VISSWAP) != 0) \
  246.         if (--curproc->p_swlocks == 0)  \
  247.             curproc->p_flag &= ~SSWLOCKS; \
  248.     (ip)->i_flag &= ~IRWLOCKED; \
  249.     if ((ip)->i_flag & IWANT) { \
  250.         (ip)->i_flag &= ~IWANT; \
  251.         wakeprocs((caddr_t)(ip), PRMPT); \
  252.     } \
  253. }
  254.  
  255. #define    ILOCK(ip) { \
  256.     while (((ip)->i_flag & ILOCKED) && \
  257.         (ip)->i_owner != curproc->p_slot) { \
  258.         (ip)->i_flag |= IWANT; \
  259.         (void) sleep((caddr_t)(ip), PINOD); \
  260.     } \
  261.     (ip)->i_owner = curproc->p_slot; \
  262.     (ip)->i_count++; \
  263.     (ip)->i_flag |= ILOCKED; \
  264.     if (((ip)->i_vnode.v_flag & VISSWAP) != 0){ \
  265.         curproc->p_swlocks++;    \
  266.         curproc->p_flag |= SSWLOCKS;\
  267.     } \
  268. }
  269.  
  270. #define    IUNLOCK(ip) { \
  271.     if (--(ip)->i_count < 0) \
  272.         panic("IUNLOCK"); \
  273.     if (((ip)->i_vnode.v_flag & VISSWAP) != 0) \
  274.         if (--curproc->p_swlocks == 0)  \
  275.             curproc->p_flag &= ~SSWLOCKS; \
  276.     if ((ip)->i_count == 0) { \
  277.         (ip)->i_flag &= ~ILOCKED; \
  278.         if ((ip)->i_flag & IWANT) { \
  279.             (ip)->i_flag &= ~IWANT; \
  280.             wakeprocs((caddr_t)(ip), PRMPT); \
  281.         } \
  282.     } \
  283. }
  284.  
  285. #define IUPDAT(ip, waitfor) { \
  286.     if (ip->i_flag & (IUPD|IACC|ICHG|IMOD)) \
  287.         ufs_iupdat(ip, waitfor); \
  288. }
  289.  
  290. /*
  291.  * Mark an inode with the current (unique) timestamp.
  292.  */
  293. struct timeval iuniqtime;
  294.  
  295. #define IMARK(ip) { \
  296.     if (hrestime.tv_sec > iuniqtime.tv_sec || \
  297.         hrestime.tv_nsec/1000 > iuniqtime.tv_usec) { \
  298.         iuniqtime.tv_sec = hrestime.tv_sec; \
  299.         iuniqtime.tv_usec = hrestime.tv_nsec/1000; \
  300.     } else { \
  301.         iuniqtime.tv_usec++; \
  302.     } \
  303.     if ((ip)->i_flag & IACC) \
  304.         (ip)->i_atime = iuniqtime; \
  305.     if ((ip)->i_flag & IUPD) { \
  306.         (ip)->i_mtime = iuniqtime; \
  307.         (ip)->i_flag |= IMODTIME; \
  308.     } \
  309.     if ((ip)->i_flag & ICHG) { \
  310.         ip->i_diroff = 0; \
  311.         (ip)->i_ctime = iuniqtime; \
  312.     } \
  313. }
  314.  
  315. #define ITIMES(ip) { \
  316.     if ((ip)->i_flag & (IUPD|IACC|ICHG)) { \
  317.         (ip)->i_flag |= IMOD; \
  318.         IMARK(ip); \
  319.         (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
  320.     } \
  321. }
  322.  
  323. /*
  324.  * Allocate the specified block in the inode
  325.  * and make sure any in-core pages are initialized.
  326.  */
  327. #define    BMAPALLOC(ip, lbn, size) \
  328.     ufs_bmap((ip), (lbn), (daddr_t *)NULL, (daddr_t *)NULL, (size), S_WRITE, 0)
  329.  
  330. #define ESAME    (-1)        /* trying to rename linked files (special) */
  331.  
  332. /*
  333.  * Check that file is owned by current user or user is su.
  334.  */
  335. #define OWNER(CR, IP)    (((CR)->cr_uid == (IP)->i_uid)? 0: (suser(CR)? 0: EPERM))
  336.  
  337. #define    UFS_HOLE    (daddr_t)-1    /* value used when no block allocated */
  338.  
  339. /*
  340.  * enums
  341.  */
  342. enum de_op    { DE_CREATE, DE_MKDIR, DE_LINK, DE_RENAME };    /* direnter ops */
  343. enum dr_op    { DR_REMOVE, DR_RMDIR, DR_RENAME };    /* dirremove ops */
  344.  
  345. /*
  346.  * This overlays the fid structure (see vfs.h)
  347.  */
  348. struct ufid {
  349.     u_short    ufid_len;
  350.     ino_t    ufid_ino;
  351.     long    ufid_gen;
  352. };
  353.  
  354. /*
  355.  * UFS VFS private data.
  356.  */
  357. struct ufsvfs {
  358.     struct vnode    *vfs_root;    /* root vnode */
  359.     struct buf    *vfs_bufp;    /* buffer containing superblock */
  360.     struct vnode    *vfs_devvp;    /* block device vnode */
  361.     struct inode    *vfs_qinod;    /* QUOTA: pointer to quota file */
  362.     u_short        vfs_qflags;    /* QUOTA: filesystem flags */
  363.     u_long        vfs_btimelimit;    /* QUOTA: block time limit */
  364.     u_long        vfs_ftimelimit;    /* QUOTA: file time limit */
  365. };
  366.  
  367. #endif
  368.  
  369. #endif /* _SYS_FS_UFS_INODE_H */
  370.