ext2fs_dinode.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* $OpenBSD: ext2fs_dinode.h,v 1.17 2014/07/31 17:37:52 pelikan Exp $ */
  2. /* $NetBSD: ext2fs_dinode.h,v 1.6 2000/01/26 16:21:33 bouyer Exp $ */
  3. /*
  4. * Copyright (c) 1997 Manuel Bouyer.
  5. * Copyright (c) 1982, 1989, 1993
  6. * The Regents of the University of California. All rights reserved.
  7. * (c) UNIX System Laboratories, Inc.
  8. * All or some portions of this file are derived from material licensed
  9. * to the University of California by American Telephone and Telegraph
  10. * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  11. * the permission of UNIX System Laboratories, Inc.
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. *
  37. * @(#)dinode.h 8.6 (Berkeley) 9/13/94
  38. * Modified for ext2fs by Manuel Bouyer.
  39. */
  40. #include <sys/stat.h>
  41. #include <ufs/ufs/dinode.h> /* for ufsino_t */
  42. /*
  43. * The root inode is the root of the file system. Inode 0 can't be used for
  44. * normal purposes and bad blocks are normally linked to inode 1, thus
  45. * the root inode is 2.
  46. * Inode 3 to 10 are reserved in ext2fs.
  47. */
  48. #define EXT2_ROOTINO ((ufsino_t)2)
  49. #define EXT2_RESIZEINO ((ufsino_t)7)
  50. #define EXT2_FIRSTINO ((ufsino_t)11)
  51. /*
  52. * A dinode contains all the meta-data associated with a UFS file.
  53. * This structure defines the on-disk format of a dinode. Since
  54. * this structure describes an on-disk structure, all its fields
  55. * are defined by types with precise widths.
  56. */
  57. #define NDADDR 12 /* Direct addresses in inode. */
  58. #define NIADDR 3 /* Indirect addresses in inode. */
  59. #define EXT2_MAXSYMLINKLEN ((NDADDR+NIADDR) * sizeof (u_int32_t))
  60. struct ext2fs_dinode {
  61. u_int16_t e2di_mode; /* 0: IFMT, permissions; see below. */
  62. u_int16_t e2di_uid_low; /* 2: owner UID, bits 15:0 */
  63. u_int32_t e2di_size; /* 4: file size (bytes) bits 31:0 */
  64. u_int32_t e2di_atime; /* 8: Access time */
  65. u_int32_t e2di_ctime; /* 12: Change time */
  66. u_int32_t e2di_mtime; /* 16: Modification time */
  67. u_int32_t e2di_dtime; /* 20: Deletion time */
  68. u_int16_t e2di_gid_low; /* 24: Owner GID, lowest bits */
  69. u_int16_t e2di_nlink; /* 26: File link count */
  70. u_int32_t e2di_nblock; /* 28: blocks count */
  71. u_int32_t e2di_flags; /* 32: status flags (chflags) */
  72. u_int32_t e2di_version_lo; /* 36: inode version, bits 31:0 */
  73. u_int32_t e2di_blocks[NDADDR+NIADDR]; /* 40: disk blocks */
  74. u_int32_t e2di_gen; /* 100: generation number */
  75. u_int32_t e2di_facl; /* 104: file ACL, bits 31:0 */
  76. u_int32_t e2di_size_hi; /* 108: file size (bytes), bits 63:32 */
  77. u_int32_t e2di_faddr; /* 112: fragment address (obsolete) */
  78. u_int16_t e2di_nblock_hi; /* 116: blocks count, bits 47:32 */
  79. u_int16_t e2di_facl_hi; /* 118: file ACL, bits 47:32 */
  80. u_int16_t e2di_uid_high; /* 120: owner UID, bits 31:16 */
  81. u_int16_t e2di_gid_high; /* 122: owner GID, bits 31:16 */
  82. u_int16_t e2di_chksum_lo; /* 124: inode checksum, bits 15:0 */
  83. u_int16_t e2di__reserved; /* 126: unused */
  84. u_int16_t e2di_isize; /* 128: size of this inode */
  85. u_int16_t e2di_chksum_hi; /* 130: inode checksum, bits 31:16 */
  86. u_int32_t e2di_x_ctime; /* 132: extra Change time */
  87. u_int32_t e2di_x_mtime; /* 136: extra Modification time */
  88. u_int32_t e2di_x_atime; /* 140: extra Access time */
  89. u_int32_t e2di_crtime; /* 144: Creation (birth) time */
  90. u_int32_t e2di_x_crtime; /* 148: extra Creation (birth) time */
  91. u_int32_t e2di_version_hi; /* 152: inode version, bits 63:31 */
  92. };
  93. #define E2MAXSYMLINKLEN ((NDADDR + NIADDR) * sizeof(u_int32_t))
  94. /* File permissions. */
  95. #define EXT2_IEXEC 0000100 /* Executable. */
  96. #define EXT2_IWRITE 0000200 /* Writeable. */
  97. #define EXT2_IREAD 0000400 /* Readable. */
  98. #define EXT2_ISVTX 0001000 /* Sticky bit. */
  99. #define EXT2_ISGID 0002000 /* Set-gid. */
  100. #define EXT2_ISUID 0004000 /* Set-uid. */
  101. /* File types. */
  102. #define EXT2_IFMT 0170000 /* Mask of file type. */
  103. #define EXT2_IFIFO 0010000 /* Named pipe (fifo). */
  104. #define EXT2_IFCHR 0020000 /* Character device. */
  105. #define EXT2_IFDIR 0040000 /* Directory file. */
  106. #define EXT2_IFBLK 0060000 /* Block device. */
  107. #define EXT2_IFREG 0100000 /* Regular file. */
  108. #define EXT2_IFLNK 0120000 /* Symbolic link. */
  109. #define EXT2_IFSOCK 0140000 /* UNIX domain socket. */
  110. /* file flags */
  111. #define EXT2_SECRM 0x00000001 /* Secure deletion */
  112. #define EXT2_UNRM 0x00000002 /* Undelete */
  113. #define EXT2_COMPR 0x00000004 /* Compress file */
  114. #define EXT2_SYNC 0x00000008 /* Synchronous updates */
  115. #define EXT2_IMMUTABLE 0x00000010 /* Immutable file */
  116. #define EXT2_APPEND 0x00000020 /* writes to file may only append */
  117. #define EXT2_NODUMP 0x00000040 /* do not dump file */
  118. #define EXT2_NOATIME 0x00000080 /* do not update access time */
  119. #define EXT4_INDEX 0x00001000 /* hash-indexed directory */
  120. #define EXT4_JOURNAL_DATA 0x00004000 /* file data should be journaled */
  121. #define EXT4_DIRSYNC 0x00010000 /* all dirent updates done synchronously */
  122. #define EXT4_TOPDIR 0x00020000 /* top of directory hierarchies */
  123. #define EXT4_HUGE_FILE 0x00040000 /* nblocks unit is fsb, not db */
  124. #define EXT4_EXTENTS 0x00080000 /* inode uses extents */
  125. #define EXT4_EOFBLOCKS 0x00400000 /* blocks allocated beyond EOF */
  126. /* Size of on-disk inode. */
  127. #define EXT2_REV0_DINODE_SIZE 128
  128. #define EXT2_DINODE_SIZE(fs) ((fs)->e2fs.e2fs_rev > E2FS_REV0 ? \
  129. (fs)->e2fs.e2fs_inode_size : \
  130. EXT2_REV0_DINODE_SIZE)
  131. /*
  132. * The e2di_blocks fields may be overlaid with other information for
  133. * file types that do not have associated disk storage. Block
  134. * and character devices overlay the first data block with their
  135. * dev_t value. Short symbolic links place their path in the
  136. * di_db area.
  137. */
  138. #define e2di_rdev e2di_blocks[0]
  139. #define e2di_shortlink e2di_blocks
  140. /* e2fs needs byte swapping on big-endian systems */
  141. #if BYTE_ORDER == LITTLE_ENDIAN
  142. # define e2fs_iload(fs, old, new) \
  143. memcpy((new),(old), MIN(EXT2_DINODE_SIZE(fs), sizeof(*new)))
  144. # define e2fs_isave(fs, old, new) \
  145. memcpy((new),(old), MIN(EXT2_DINODE_SIZE(fs), sizeof(*new)))
  146. #else
  147. struct m_ext2fs;
  148. void e2fs_i_bswap(struct m_ext2fs *, struct ext2fs_dinode *, struct ext2fs_dinode *);
  149. # define e2fs_iload(fs, old, new) e2fs_i_bswap((fs), (old), (new))
  150. # define e2fs_isave(fs, old, new) e2fs_i_bswap((fs), (old), (new))
  151. #endif