1 /* 2 * Taken from Linux kernel tree (linux/fs/ufs) 3 * linux/include/linux/ufs_fs.h 4 * 5 * Copyright (C) 1996 6 * Adrian Rodriguez (adrian (at) franklins-tower.rutgers.edu) 7 * Laboratory for Computer Science Research Computing Facility 8 * Rutgers, The State University of New Jersey 9 * 10 * Copyright (c) 2013 Raphael S. Carvalho <raphael.scarv (at) gmail.com> 11 * 12 * Clean swab support by Fare <fare (at) tunes.org> 13 * just hope no one is using NNUUXXI on __?64 structure elements 14 * 64-bit clean thanks to Maciej W. Rozycki <macro (at) ds2.pg.gda.pl> 15 * 16 * 4.4BSD (FreeBSD) support added on February 1st 1998 by 17 * Niels Kristian Bech Jensen <nkbj (at) image.dk> partially based 18 * on code by Martin von Loewis <martin (at) mira.isdn.cs.tu-berlin.de>. 19 * 20 * NeXTstep support added on February 5th 1998 by 21 * Niels Kristian Bech Jensen <nkbj (at) image.dk>. 22 * 23 * Write support by Daniel Pirkl <daniel.pirkl (at) email.cz> 24 * 25 * HP/UX hfs filesystem support added by 26 * Martin K. Petersen <mkp (at) mkp.net>, August 1999 27 * 28 * UFS2 (of FreeBSD 5.x) support added by 29 * Niraj Kumar <niraj17 (at) iitbombay.org> , Jan 2004 30 * 31 */ 32 33 #ifndef __LINUX_UFS_FS_H 34 #define __LINUX_UFS_FS_H 35 36 #include <inttypes.h> 37 38 typedef uint64_t __fs64; 39 typedef uint32_t __fs32; 40 typedef uint16_t __fs16; 41 42 #define UFS_BBLOCK 0 43 #define UFS_BBSIZE 8192 44 #define UFS_SBLOCK 8192 45 #define UFS_SBSIZE 8192 46 47 #define UFS_SECTOR_SIZE 512 48 #define UFS_SECTOR_BITS 9 49 #define UFS_MAGIC 0x00011954 50 #define UFS_MAGIC_BW 0x0f242697 51 #define UFS2_MAGIC 0x19540119 52 #define UFS_CIGAM 0x54190100 /* byteswapped MAGIC */ 53 54 /* Copied from FreeBSD */ 55 /* 56 * Each disk drive contains some number of filesystems. 57 * A filesystem consists of a number of cylinder groups. 58 * Each cylinder group has inodes and data. 59 * 60 * A filesystem is described by its super-block, which in turn 61 * describes the cylinder groups. The super-block is critical 62 * data and is replicated in each cylinder group to protect against 63 * catastrophic loss. This is done at `newfs' time and the critical 64 * super-block data does not change, so the copies need not be 65 * referenced further unless disaster strikes. 66 * 67 * For filesystem fs, the offsets of the various blocks of interest 68 * are given in the super block as: 69 * [fs->fs_sblkno] Super-block 70 * [fs->fs_cblkno] Cylinder group block 71 * [fs->fs_iblkno] Inode blocks 72 * [fs->fs_dblkno] Data blocks 73 * The beginning of cylinder group cg in fs, is given by 74 * the ``cgbase(fs, cg)'' macro. 75 * 76 * Depending on the architecture and the media, the superblock may 77 * reside in any one of four places. For tiny media where every block 78 * counts, it is placed at the very front of the partition. Historically, 79 * UFS1 placed it 8K from the front to leave room for the disk label and 80 * a small bootstrap. For UFS2 it got moved to 64K from the front to leave 81 * room for the disk label and a bigger bootstrap, and for really piggy 82 * systems we check at 256K from the front if the first three fail. In 83 * all cases the size of the superblock will be SBLOCKSIZE. All values are 84 * given in byte-offset form, so they do not imply a sector size. The 85 * SBLOCKSEARCH specifies the order in which the locations should be searched. 86 */ 87 #define SBLOCK_FLOPPY 0 88 #define SBLOCK_UFS1 8192 89 #define SBLOCK_UFS2 65536 90 #define SBLOCK_PIGGY 262144 91 #define SBLOCKSIZE 8192 92 #define SBLOCKSEARCH \ 93 { SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 } 94 95 #define UFS_MAXNAMLEN 255 96 #define UFS_MAXMNTLEN 512 97 #define UFS2_MAXMNTLEN 468 98 #define UFS2_MAXVOLLEN 32 99 #define UFS_MAXCSBUFS 31 100 #define UFS_LINK_MAX 32000 101 /* 102 #define UFS2_NOCSPTRS ((128 / sizeof(void *)) - 4) 103 */ 104 #define UFS2_NOCSPTRS 28 105 106 /* 107 * UFS_DIR_PAD defines the directory entries boundaries 108 * (must be a multiple of 4) 109 */ 110 #define UFS_DIR_PAD 4 111 #define UFS_DIR_ROUND (UFS_DIR_PAD - 1) 112 #define UFS_DIR_REC_LEN(name_len) (((name_len) + 1 + 8 + UFS_DIR_ROUND) & ~UFS_DIR_ROUND) 113 114 struct ufs_timeval { 115 __fs32 tv_sec; 116 __fs32 tv_usec; 117 }; 118 119 struct ufs_dir_entry { 120 __fs32 d_ino; /* inode number of this entry */ 121 __fs16 d_reclen; /* length of this entry */ 122 union { 123 __fs16 d_namlen; /* actual length of d_name */ 124 struct { 125 __u8 d_type; /* file type */ 126 __u8 d_namlen; /* length of string in d_name */ 127 } d_44; 128 } d_u; 129 __u8 d_name[UFS_MAXNAMLEN + 1]; /* file name */ 130 }; 131 132 struct ufs_csum { 133 __fs32 cs_ndir; /* number of directories */ 134 __fs32 cs_nbfree; /* number of free blocks */ 135 __fs32 cs_nifree; /* number of free inodes */ 136 __fs32 cs_nffree; /* number of free frags */ 137 }; 138 struct ufs2_csum_total { 139 __fs64 cs_ndir; /* number of directories */ 140 __fs64 cs_nbfree; /* number of free blocks */ 141 __fs64 cs_nifree; /* number of free inodes */ 142 __fs64 cs_nffree; /* number of free frags */ 143 __fs64 cs_numclusters; /* number of free clusters */ 144 __fs64 cs_spare[3]; /* future expansion */ 145 }; 146 147 struct ufs_csum_core { 148 __u64 cs_ndir; /* number of directories */ 149 __u64 cs_nbfree; /* number of free blocks */ 150 __u64 cs_nifree; /* number of free inodes */ 151 __u64 cs_nffree; /* number of free frags */ 152 __u64 cs_numclusters; /* number of free clusters */ 153 }; 154 155 struct ufs_super_block { 156 union { 157 struct { 158 __fs32 fs_link; /* UNUSED */ 159 } fs_42; 160 struct { 161 __fs32 fs_state; /* file system state flag */ 162 } fs_sun; 163 } fs_u0; 164 __fs32 fs_rlink; /* UNUSED */ 165 __fs32 fs_sblkno; /* addr of super-block in filesys */ 166 __fs32 fs_cblkno; /* offset of cyl-block in filesys */ 167 __fs32 fs_iblkno; /* offset of inode-blocks in filesys */ 168 __fs32 fs_dblkno; /* offset of first data after cg */ 169 __fs32 fs_cgoffset; /* cylinder group offset in cylinder */ 170 __fs32 fs_cgmask; /* used to calc mod fs_ntrak */ 171 __fs32 fs_time; /* last time written -- time_t */ 172 __fs32 fs_size; /* number of blocks in fs */ 173 __fs32 fs_dsize; /* number of data blocks in fs */ 174 __fs32 fs_ncg; /* number of cylinder groups */ 175 __fs32 fs_bsize; /* size of basic blocks in fs */ 176 __fs32 fs_fsize; /* size of frag blocks in fs */ 177 __fs32 fs_frag; /* number of frags in a block in fs */ 178 /* these are configuration parameters */ 179 __fs32 fs_minfree; /* minimum percentage of free blocks */ 180 __fs32 fs_rotdelay; /* num of ms for optimal next block */ 181 __fs32 fs_rps; /* disk revolutions per second */ 182 /* these fields can be computed from the others */ 183 __fs32 fs_bmask; /* ``blkoff'' calc of blk offsets */ 184 __fs32 fs_fmask; /* ``fragoff'' calc of frag offsets */ 185 __fs32 fs_bshift; /* ``lblkno'' calc of logical blkno */ 186 __fs32 fs_fshift; /* ``numfrags'' calc number of frags */ 187 /* these are configuration parameters */ 188 __fs32 fs_maxcontig; /* max number of contiguous blks */ 189 __fs32 fs_maxbpg; /* max number of blks per cyl group */ 190 /* these fields can be computed from the others */ 191 __fs32 fs_fragshift; /* block to frag shift */ 192 __fs32 fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 193 __fs32 fs_sbsize; /* actual size of super block */ 194 __fs32 fs_csmask; /* csum block offset */ 195 __fs32 fs_csshift; /* csum block number */ 196 __fs32 fs_nindir; /* value of NINDIR */ 197 __fs32 fs_inopb; /* value of INOPB */ 198 __fs32 fs_nspf; /* value of NSPF */ 199 /* yet another configuration parameter */ 200 __fs32 fs_optim; /* optimization preference, see below */ 201 /* these fields are derived from the hardware */ 202 union { 203 struct { 204 __fs32 fs_npsect; /* # sectors/track including spares */ 205 } fs_sun; 206 struct { 207 __fs32 fs_state; /* file system state time stamp */ 208 } fs_sunx86; 209 } fs_u1; 210 __fs32 fs_interleave; /* hardware sector interleave */ 211 __fs32 fs_trackskew; /* sector 0 skew, per track */ 212 /* a unique id for this filesystem (currently unused and unmaintained) */ 213 /* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */ 214 /* Neither of those fields is used in the Tahoe code right now but */ 215 /* there could be problems if they are. */ 216 __fs32 fs_id[2]; /* file system id */ 217 /* sizes determined by number of cylinder groups and their sizes */ 218 __fs32 fs_csaddr; /* blk addr of cyl grp summary area */ 219 __fs32 fs_cssize; /* size of cyl grp summary area */ 220 __fs32 fs_cgsize; /* cylinder group size */ 221 /* these fields are derived from the hardware */ 222 __fs32 fs_ntrak; /* tracks per cylinder */ 223 __fs32 fs_nsect; /* sectors per track */ 224 __fs32 fs_spc; /* sectors per cylinder */ 225 /* this comes from the disk driver partitioning */ 226 __fs32 fs_ncyl; /* cylinders in file system */ 227 /* these fields can be computed from the others */ 228 __fs32 fs_cpg; /* cylinders per group */ 229 __fs32 fs_ipg; /* inodes per cylinder group */ 230 __fs32 fs_fpg; /* blocks per group * fs_frag */ 231 /* this data must be re-computed after crashes */ 232 struct ufs_csum fs_cstotal; /* cylinder summary information */ 233 /* these fields are cleared at mount time */ 234 __s8 fs_fmod; /* super block modified flag */ 235 __s8 fs_clean; /* file system is clean flag */ 236 __s8 fs_ronly; /* mounted read-only flag */ 237 __s8 fs_flags; 238 union { 239 struct { 240 __s8 fs_fsmnt[UFS_MAXMNTLEN];/* name mounted on */ 241 __fs32 fs_cgrotor; /* last cg searched */ 242 __fs32 fs_csp[UFS_MAXCSBUFS];/*list of fs_cs info buffers */ 243 __fs32 fs_maxcluster; 244 __fs32 fs_cpc; /* cyl per cycle in postbl */ 245 __fs16 fs_opostbl[16][8]; /* old rotation block list head */ 246 } fs_u1; 247 struct { 248 __s8 fs_fsmnt[UFS2_MAXMNTLEN]; /* name mounted on */ 249 __u8 fs_volname[UFS2_MAXVOLLEN]; /* volume name */ 250 __fs64 fs_swuid; /* system-wide uid */ 251 __fs32 fs_pad; /* due to alignment of fs_swuid */ 252 __fs32 fs_cgrotor; /* last cg searched */ 253 __fs32 fs_ocsp[UFS2_NOCSPTRS]; /*list of fs_cs info buffers */ 254 __fs32 fs_contigdirs;/*# of contiguously allocated dirs */ 255 __fs32 fs_csp; /* cg summary info buffer for fs_cs */ 256 __fs32 fs_maxcluster; 257 __fs32 fs_active;/* used by snapshots to track fs */ 258 __fs32 fs_old_cpc; /* cyl per cycle in postbl */ 259 __fs32 fs_maxbsize;/*maximum blocking factor permitted */ 260 __fs64 fs_sparecon64[17];/*old rotation block list head */ 261 __fs64 fs_sblockloc; /* byte offset of standard superblock */ 262 struct ufs2_csum_total fs_cstotal;/*cylinder summary information*/ 263 struct ufs_timeval fs_time; /* last time written */ 264 __fs64 fs_size; /* number of blocks in fs */ 265 __fs64 fs_dsize; /* number of data blocks in fs */ 266 __fs64 fs_csaddr; /* blk addr of cyl grp summary area */ 267 __fs64 fs_pendingblocks;/* blocks in process of being freed */ 268 __fs32 fs_pendinginodes;/*inodes in process of being freed */ 269 } fs_u2; 270 } fs_u11; 271 union { 272 struct { 273 __fs32 fs_sparecon[53];/* reserved for future constants */ 274 __fs32 fs_reclaim; 275 __fs32 fs_sparecon2[1]; 276 __fs32 fs_state; /* file system state time stamp */ 277 __fs32 fs_qbmask[2]; /* ~usb_bmask */ 278 __fs32 fs_qfmask[2]; /* ~usb_fmask */ 279 } fs_sun; 280 struct { 281 __fs32 fs_sparecon[53];/* reserved for future constants */ 282 __fs32 fs_reclaim; 283 __fs32 fs_sparecon2[1]; 284 __fs32 fs_npsect; /* # sectors/track including spares */ 285 __fs32 fs_qbmask[2]; /* ~usb_bmask */ 286 __fs32 fs_qfmask[2]; /* ~usb_fmask */ 287 } fs_sunx86; 288 struct { 289 __fs32 fs_sparecon[50];/* reserved for future constants */ 290 __fs32 fs_contigsumsize;/* size of cluster summary array */ 291 __fs32 fs_maxsymlinklen;/* max length of an internal symlink */ 292 __fs32 fs_inodefmt; /* format of on-disk inodes */ 293 __fs32 fs_maxfilesize[2]; /* max representable file size */ 294 __fs32 fs_qbmask[2]; /* ~usb_bmask */ 295 __fs32 fs_qfmask[2]; /* ~usb_fmask */ 296 __fs32 fs_state; /* file system state time stamp */ 297 } fs_44; 298 } fs_u2; 299 __fs32 fs_postblformat; /* format of positional layout tables */ 300 __fs32 fs_nrpos; /* number of rotational positions */ 301 __fs32 fs_postbloff; /* (__s16) rotation block list head */ 302 __fs32 fs_rotbloff; /* (__u8) blocks for each rotation */ 303 __fs32 fs_magic; /* magic number */ 304 __u8 fs_space[1]; /* list of blocks for each rotation */ 305 }; /*struct ufs_super_block*/ 306 307 #endif 308