inode.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*-
  2. * Copyright (c) 1982, 1989, 1993
  3. * The Regents of the University of California. All rights reserved.
  4. * (c) UNIX System Laboratories, Inc.
  5. * All or some portions of this file are derived from material licensed
  6. * to the University of California by American Telephone and Telegraph
  7. * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  8. * the permission of UNIX System Laboratories, Inc.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * @(#)inode.h 8.9 (Berkeley) 5/14/95
  35. * $FreeBSD$
  36. */
  37. typedef struct ufs2_dinode ufs2_dinode;
  38. typedef struct ufsmount ufsmount;
  39. typedef struct vnode vnode;
  40. /*
  41. * This must agree with the definition in <ufs/ufs/dir.h>.
  42. */
  43. #define doff_t int32_t
  44. /*
  45. * The inode is used to describe each active (or recently active) file in the
  46. * UFS filesystem. It is composed of two types of information. The first part
  47. * is the information that is needed only while the file is active (such as
  48. * the identity of the file and linkage to speed its lookup). The second part
  49. * is the permanent meta-data associated with the file which is read in
  50. * from the permanent dinode from long term storage when the file becomes
  51. * active, and is put back when the file is no longer being used.
  52. *
  53. * An inode may only be changed while holding either the exclusive
  54. * vnode lock or the shared vnode lock and the vnode interlock. We use
  55. * the latter only for "read" and "get" operations that require
  56. * changing i_flag, or a timestamp. This locking protocol allows executing
  57. * those operations without having to upgrade the vnode lock from shared to
  58. * exclusive.
  59. */
  60. struct inode {
  61. // TODO HARVEY Replace when snapshot code re-enabled
  62. //TAILQ_ENTRY(inode) i_nextsnap; /* snapshot file list. */
  63. vnode *i_vnode;/* Vnode associated with this inode. */
  64. ufsmount *i_ump;/* Ufsmount point associated with this inode. */
  65. struct dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
  66. union {
  67. struct dirhash *dirhash; /* Hashing for large directories. */
  68. daddr_t *snapblklist; /* Collect expunged snapshot blocks. */
  69. } i_un;
  70. /*
  71. * The real copy of the on-disk inode.
  72. */
  73. ufs2_dinode *din2; /* UFS2 on-disk dinode. */
  74. ino_t i_number; /* The identity of the inode. */
  75. uint32_t i_flag; /* flags, see below */
  76. int i_effnlink; /* i_nlink when I/O completes */
  77. /*
  78. * Side effects; used during directory lookup.
  79. */
  80. int32_t i_count; /* Size of free slot in directory. */
  81. doff_t i_endoff; /* End of useful stuff in directory. */
  82. doff_t i_diroff; /* Offset in dir, where we found last entry. */
  83. doff_t i_offset; /* Offset of free space in directory. */
  84. int i_nextclustercg; /* last cg searched for cluster */
  85. /*
  86. * Data for extended attribute modification.
  87. */
  88. uint8_t *i_ea_area; /* Pointer to malloced copy of EA area */
  89. unsigned i_ea_len; /* Length of i_ea_area */
  90. int i_ea_error; /* First errno in transaction */
  91. int i_ea_refs; /* Number of users of EA area */
  92. /*
  93. * Copies from the on-disk dinode itself.
  94. */
  95. uint64_t i_size; /* File byte count. */
  96. uint64_t i_gen; /* Generation number. */
  97. uint32_t i_flags; /* Status flags (chflags). */
  98. uint32_t i_uid; /* File owner. */
  99. uint32_t i_gid; /* File group. */
  100. uint16_t i_mode; /* IFMT, permissions; see below. */
  101. int16_t i_nlink; /* File link count. */
  102. };
  103. /*
  104. * These flags are kept in i_flag.
  105. */
  106. #define IN_ACCESS 0x0001 /* Access time update request. */
  107. #define IN_CHANGE 0x0002 /* Inode change time update request. */
  108. #define IN_UPDATE 0x0004 /* Modification time update request. */
  109. #define IN_MODIFIED 0x0008 /* Inode has been modified. */
  110. #define IN_NEEDSYNC 0x0010 /* Inode requires fsync. */
  111. #define IN_LAZYMOD 0x0020 /* Modified, but don't write yet. */
  112. #define IN_LAZYACCESS 0x0040 /* Process IN_ACCESS after the
  113. suspension finished */
  114. #define IN_EA_LOCKED 0x0080
  115. #define IN_EA_LOCKWAIT 0x0100
  116. #define IN_TRUNCATED 0x0200 /* Journaled truncation pending. */
  117. #define IN_UFS2 0x0400 /* UFS2 vs UFS1 */
  118. #define i_dirhash i_un.dirhash
  119. #define i_snapblklist i_un.snapblklist
  120. #define ITOUMP(ip) ((ip)->i_ump)
  121. #define ITODEV(ip) (ITOUMP(ip)->um_dev)
  122. #define ITODEVVP(ip) (ITOUMP(ip)->um_devvp)
  123. #define ITOFS(ip) (ITOUMP(ip)->um_fs)
  124. #define ITOVFS(ip) ((ip)->i_vnode->v_mount)
  125. static inline _Bool
  126. I_IS_UFS2(const struct inode *ip)
  127. {
  128. return ((ip->i_flag & IN_UFS2) != 0);
  129. }
  130. #define SHORTLINK(ip) ((caddr_t)(ip)->i_din2->di_db)
  131. #define IS_SNAPSHOT(ip) ((ip)->i_flags & SF_SNAPSHOT)
  132. /*
  133. * Structure used to pass around logical block paths generated by
  134. * ufs_getlbns and used by truncate and bmap code.
  135. */
  136. typedef struct Indir {
  137. ufs2_daddr_t in_lbn; /* Logical block number. */
  138. int in_off; /* Offset in buffer. */
  139. } Indir;
  140. /* Convert between inode pointers and vnode pointers. */
  141. // TODO HARVEY Just remove these 2 macros
  142. #define VTOI(vp) ((inode *)(vp)->data)
  143. #define ITOV(ip) ((ip)->i_vnode)
  144. /* Determine if soft dependencies are being done */
  145. #define DOINGSOFTDEP(vp) ((vp)->v_mount->mnt_flag & (MNT_SOFTDEP | MNT_SUJ))
  146. #define MOUNTEDSOFTDEP(mp) ((mp)->mnt_flag & (MNT_SOFTDEP | MNT_SUJ))
  147. #define DOINGSUJ(vp) ((vp)->v_mount->mnt_flag & MNT_SUJ)
  148. #define MOUNTEDSUJ(mp) ((mp)->mnt_flag & MNT_SUJ)
  149. /* This overlays the fid structure (see mount.h). */
  150. struct ufid {
  151. uint16_t ufid_len; /* Length of structure. */
  152. uint16_t ufid_pad; /* Force 32-bit alignment. */
  153. uint32_t ufid_ino; /* File number (ino). */
  154. uint32_t ufid_gen; /* Generation number. */
  155. };