00001 /***************************************************************************************** 00002 Copyright (c) 2002-2004 The UbixOS Project 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are 00006 permitted provided that the following conditions are met: 00007 00008 Redistributions of source code must retain the above copyright notice, this list of 00009 conditions, the following disclaimer and the list of authors. Redistributions in binary 00010 form must reproduce the above copyright notice, this list of conditions, the following 00011 disclaimer and the list of authors in the documentation and/or other materials provided 00012 with the distribution. Neither the name of the UbixOS Project nor the names of its 00013 contributors may be used to endorse or promote products derived from this software 00014 without specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 00026 $Id: ufs_8h-source.html 88 2016-01-12 00:11:29Z reddawg $ 00027 00028 *****************************************************************************************/ 00029 00030 #ifndef _UFS_H 00031 #define _UFS_H 00032 00033 #include <ubixos/types.h> 00034 #include <vfs/vfs.h> 00035 #include <sys/device.h> 00036 00037 00038 #define DT_REG 8 00039 #define MAXNAMLEN 255 00040 #define ROOTINO ((ino_t)2) 00041 #define DT_DIR 4 00042 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 00043 #define DEV_BSIZE (1<<DEV_BSHIFT) 00044 #define SBLOCK_FLOPPY 0 00045 #define SBLOCK_UFS1 8192 00046 #define SBLOCK_UFS2 65536 00047 #define SBLOCK_PIGGY 262144 00048 #define SBLOCKSIZE 8192 00049 #define SBLOCKSEARCH \ 00050 { SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 } 00051 #define FS_UFS1_MAGIC 0x011954 /* UFS1 fast filesystem magic number */ 00052 #define FS_UFS2_MAGIC 0x19540119 /* UFS2 fast filesystem magic number */ 00053 #define MAXMNTLEN 468 00054 #define MAXVOLLEN 32 00055 #define NOCSPTRS ((128 / sizeof(void *)) - 4) 00056 #define FSMAXSNAP 20 00057 #define MAXBSIZE 65536 00058 #define NINDIR(fs) ((fs)->fs_nindir) 00059 00060 /* 00061 * Cylinder group macros to locate things in cylinder groups. 00062 * They calc filesystem addresses of cylinder group data structures. 00063 */ 00064 #define cgbase(fs, c) (((ufs2_daddr_t)(fs)->fs_fpg) * (c)) 00065 #define cgdmin(fs, c) (cgstart(fs, c) + (fs)->fs_dblkno) /* 1st data */ 00066 #define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode blk */ 00067 #define cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno) /* super blk */ 00068 #define cgtod(fs, c) (cgstart(fs, c) + (fs)->fs_cblkno) /* cg block */ 00069 #define cgstart(fs, c) \ 00070 ((fs)->fs_magic == FS_UFS2_MAGIC ? cgbase(fs, c) : \ 00071 (cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask)))) 00072 00073 00074 #define fsbtodb(fs, b) ((daddr_t)(b) << (fs)->fs_fsbtodb) 00075 #define dbtofsb(fs, b) ((b) >> (fs)->fs_fsbtodb) 00076 00077 /* 00078 * Macros for handling inode numbers: 00079 * inode number to filesystem block offset. 00080 * inode number to cylinder group number. 00081 * inode number to filesystem block address. 00082 */ 00083 #define ino_to_cg(fs, x) ((x) / (fs)->fs_ipg) 00084 #define ino_to_fsba(fs, x) \ 00085 ((ufs2_daddr_t)(cgimin(fs, ino_to_cg(fs, x)) + \ 00086 (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs)))))) 00087 #define ino_to_fsbo(fs, x) ((x) % INOPB(fs)) 00088 00089 00090 #define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \ 00091 ((loc) & (fs)->fs_qbmask) 00092 #define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \ 00093 ((loc) >> (fs)->fs_bshift) 00094 #define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \ 00095 (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) 00096 00097 00098 #define sblksize(fs, size, lbn) \ 00099 (((lbn) >= NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \ 00100 ? (fs)->fs_bsize \ 00101 : (fragroundup(fs, blkoff(fs, (size))))) 00102 00103 00104 00105 00106 typedef int32_t ufs1_daddr_t; 00107 typedef int64_t ufs2_daddr_t; 00108 typedef int64_t ufs_lbn_t; 00109 typedef int64_t ufs_time_t; 00110 typedef __int64_t daddr_t; 00111 00112 struct dirent { 00113 __uint32_t d_fileno; /* file number of entry */ 00114 __uint16_t d_reclen; /* length of this record */ 00115 __uint8_t d_type; /* file type, see below */ 00116 __uint8_t d_namlen; /* length of string in d_name */ 00117 char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ 00118 }; 00119 00120 #define NXADDR 2 /* External addresses in inode. */ 00121 #define NDADDR 12 /* Direct addresses in inode. */ 00122 #define NIADDR 3 /* Indirect addresses in inode. */ 00123 00124 struct ufs2_dinode { 00125 u_int16_t di_mode; /* 0: IFMT, permissions; see below. */ 00126 int16_t di_nlink; /* 2: File link count. */ 00127 uint32_t di_uid; /* 4: File owner. */ 00128 uint32_t di_gid; /* 8: File group. */ 00129 uint32_t di_blksize; /* 12: Inode blocksize. */ 00130 u_int64_t di_size; /* 16: File byte count. */ 00131 u_int64_t di_blocks; /* 24: Bytes actually held. */ 00132 ufs_time_t di_atime; /* 32: Last access time. */ 00133 ufs_time_t di_mtime; /* 40: Last modified time. */ 00134 ufs_time_t di_ctime; /* 48: Last inode change time. */ 00135 ufs_time_t di_birthtime; /* 56: Inode creation time. */ 00136 int32_t di_mtimensec; /* 64: Last modified time. */ 00137 int32_t di_atimensec; /* 68: Last access time. */ 00138 int32_t di_ctimensec; /* 72: Last inode change time. */ 00139 int32_t di_birthnsec; /* 76: Inode creation time. */ 00140 int32_t di_gen; /* 80: Generation number. */ 00141 uint32_t di_kernflags; /* 84: Kernel flags. */ 00142 uint32_t di_flags; /* 88: Status flags (chflags). */ 00143 int32_t di_extsize; /* 92: External attributes block. */ 00144 ufs2_daddr_t di_extb[NXADDR];/* 96: External attributes block. */ 00145 ufs2_daddr_t di_db[NDADDR]; /* 112: Direct disk blocks. */ 00146 ufs2_daddr_t di_ib[NIADDR]; /* 208: Indirect disk blocks. */ 00147 int64_t di_spare[3]; /* 232: Reserved; currently unused */ 00148 }; 00149 00150 struct ufs1_dinode { 00151 u_int16_t di_mode; /* 0: IFMT, permissions; see below. */ 00152 int16_t di_nlink; /* 2: File link count. */ 00153 union { 00154 u_int16_t oldids[2]; /* 4: Ffs: old user and group ids. */ 00155 } di_u; 00156 u_int64_t di_size; /* 8: File byte count. */ 00157 int32_t di_atime; /* 16: Last access time. */ 00158 int32_t di_atimensec; /* 20: Last access time. */ 00159 int32_t di_mtime; /* 24: Last modified time. */ 00160 int32_t di_mtimensec; /* 28: Last modified time. */ 00161 int32_t di_ctime; /* 32: Last inode change time. */ 00162 int32_t di_ctimensec; /* 36: Last inode change time. */ 00163 ufs1_daddr_t di_db[NDADDR]; /* 40: Direct disk blocks. */ 00164 ufs1_daddr_t di_ib[NIADDR]; /* 88: Indirect disk blocks. */ 00165 uint32_t di_flags; /* 100: Status flags (chflags). */ 00166 int32_t di_blocks; /* 104: Blocks actually held. */ 00167 int32_t di_gen; /* 108: Generation number. */ 00168 uint32_t di_uid; /* 112: File owner. */ 00169 uint32_t di_gid; /* 116: File group. */ 00170 int32_t di_spare[2]; /* 120: Reserved; currently unused */ 00171 }; 00172 00173 struct csum { 00174 int32_t cs_ndir; /* number of directories */ 00175 int32_t cs_nbfree; /* number of free blocks */ 00176 int32_t cs_nifree; /* number of free inodes */ 00177 int32_t cs_nffree; /* number of free frags */ 00178 }; 00179 struct csum_total { 00180 int64_t cs_ndir; /* number of directories */ 00181 int64_t cs_nbfree; /* number of free blocks */ 00182 int64_t cs_nifree; /* number of free inodes */ 00183 int64_t cs_nffree; /* number of free frags */ 00184 int64_t cs_numclusters; /* number of free clusters */ 00185 int64_t cs_spare[3]; /* future expansion */ 00186 }; 00187 00188 00189 struct fs { 00190 int32_t fs_firstfield; /* historic filesystem linked list, */ 00191 int32_t fs_unused_1; /* used for incore super blocks */ 00192 int32_t fs_sblkno; /* offset of super-block in filesys */ 00193 int32_t fs_cblkno; /* offset of cyl-block in filesys */ 00194 int32_t fs_iblkno; /* offset of inode-blocks in filesys */ 00195 int32_t fs_dblkno; /* offset of first data after cg */ 00196 int32_t fs_old_cgoffset; /* cylinder group offset in cylinder */ 00197 int32_t fs_old_cgmask; /* used to calc mod fs_ntrak */ 00198 int32_t fs_old_time; /* last time written */ 00199 int32_t fs_old_size; /* number of blocks in fs */ 00200 int32_t fs_old_dsize; /* number of data blocks in fs */ 00201 int32_t fs_ncg; /* number of cylinder groups */ 00202 int32_t fs_bsize; /* size of basic blocks in fs */ 00203 int32_t fs_fsize; /* size of frag blocks in fs */ 00204 int32_t fs_frag; /* number of frags in a block in fs */ 00205 /* these are configuration parameters */ 00206 int32_t fs_minfree; /* minimum percentage of free blocks */ 00207 int32_t fs_old_rotdelay; /* num of ms for optimal next block */ 00208 int32_t fs_old_rps; /* disk revolutions per second */ 00209 /* these fields can be computed from the others */ 00210 int32_t fs_bmask; /* ``blkoff'' calc of blk offsets */ 00211 int32_t fs_fmask; /* ``fragoff'' calc of frag offsets */ 00212 int32_t fs_bshift; /* ``lblkno'' calc of logical blkno */ 00213 int32_t fs_fshift; /* ``numfrags'' calc number of frags */ 00214 /* these are configuration parameters */ 00215 int32_t fs_maxcontig; /* max number of contiguous blks */ 00216 int32_t fs_maxbpg; /* max number of blks per cyl group */ 00217 /* these fields can be computed from the others */ 00218 int32_t fs_fragshift; /* block to frag shift */ 00219 int32_t fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 00220 int32_t fs_sbsize; /* actual size of super block */ 00221 int32_t fs_spare1[2]; /* old fs_csmask */ 00222 /* old fs_csshift */ 00223 int32_t fs_nindir; /* value of NINDIR */ 00224 int32_t fs_inopb; /* value of INOPB */ 00225 int32_t fs_old_nspf; /* value of NSPF */ 00226 /* yet another configuration parameter */ 00227 int32_t fs_optim; /* optimization preference, see below */ 00228 int32_t fs_old_npsect; /* # sectors/track including spares */ 00229 int32_t fs_old_interleave; /* hardware sector interleave */ 00230 int32_t fs_old_trackskew; /* sector 0 skew, per track */ 00231 int32_t fs_id[2]; /* unique filesystem id */ 00232 /* sizes determined by number of cylinder groups and their sizes */ 00233 int32_t fs_old_csaddr; /* blk addr of cyl grp summary area */ 00234 int32_t fs_cssize; /* size of cyl grp summary area */ 00235 int32_t fs_cgsize; /* cylinder group size */ 00236 int32_t fs_spare2; /* old fs_ntrak */ 00237 int32_t fs_old_nsect; /* sectors per track */ 00238 int32_t fs_old_spc; /* sectors per cylinder */ 00239 int32_t fs_old_ncyl; /* cylinders in filesystem */ 00240 int32_t fs_old_cpg; /* cylinders per group */ 00241 int32_t fs_ipg; /* inodes per group */ 00242 int32_t fs_fpg; /* blocks per group * fs_frag */ 00243 /* this data must be re-computed after crashes */ 00244 struct csum fs_old_cstotal; /* cylinder summary information */ 00245 /* these fields are cleared at mount time */ 00246 int8_t fs_fmod; /* super block modified flag */ 00247 int8_t fs_clean; /* filesystem is clean flag */ 00248 int8_t fs_ronly; /* mounted read-only flag */ 00249 int8_t fs_old_flags; /* old FS_ flags */ 00250 u_char fs_fsmnt[MAXMNTLEN]; /* name mounted on */ 00251 u_char fs_volname[MAXVOLLEN]; /* volume name */ 00252 u_int64_t fs_swuid; /* system-wide uid */ 00253 int32_t fs_pad; /* due to alignment of fs_swuid */ 00254 /* these fields retain the current block allocation info */ 00255 int32_t fs_cgrotor; /* last cg searched */ 00256 void *fs_ocsp[NOCSPTRS]; /* padding; was list of fs_cs buffers */ 00257 u_int8_t *fs_contigdirs; /* (u) # of contig. allocated dirs */ 00258 struct csum *fs_csp; /* (u) cg summary info buffer */ 00259 int32_t *fs_maxcluster; /* (u) max cluster in each cyl group */ 00260 u_int *fs_active; /* (u) used by snapshots to track fs */ 00261 int32_t fs_old_cpc; /* cyl per cycle in postbl */ 00262 int32_t fs_maxbsize; /* maximum blocking factor permitted */ 00263 int64_t fs_sparecon64[17]; /* old rotation block list head */ 00264 int64_t fs_sblockloc; /* byte offset of standard superblock */ 00265 struct csum_total fs_cstotal; /* (u) cylinder summary information */ 00266 ufs_time_t fs_time; /* last time written */ 00267 int64_t fs_size; /* number of blocks in fs */ 00268 int64_t fs_dsize; /* number of data blocks in fs */ 00269 ufs2_daddr_t fs_csaddr; /* blk addr of cyl grp summary area */ 00270 int64_t fs_pendingblocks; /* (u) blocks being freed */ 00271 int32_t fs_pendinginodes; /* (u) inodes being freed */ 00272 int32_t fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */ 00273 int32_t fs_avgfilesize; /* expected average file size */ 00274 int32_t fs_avgfpdir; /* expected # of files per directory */ 00275 int32_t fs_save_cgsize; /* save real cg size to use fs_bsize */ 00276 int32_t fs_sparecon32[26]; /* reserved for future constants */ 00277 int32_t fs_flags; /* see FS_ flags below */ 00278 int32_t fs_contigsumsize; /* size of cluster summary array */ 00279 int32_t fs_maxsymlinklen; /* max length of an internal symlink */ 00280 int32_t fs_old_inodefmt; /* format of on-disk inodes */ 00281 u_int64_t fs_maxfilesize; /* maximum representable file size */ 00282 int64_t fs_qbmask; /* ~fs_bmask for use with 64-bit size */ 00283 int64_t fs_qfmask; /* ~fs_fmask for use with 64-bit size */ 00284 int32_t fs_state; /* validate fs_clean field */ 00285 int32_t fs_old_postblformat; /* format of positional layout tables */ 00286 int32_t fs_old_nrpos; /* number of rotational positions */ 00287 int32_t fs_spare5[2]; /* old fs_postbloff */ 00288 /* old fs_rotbloff */ 00289 int32_t fs_magic; /* magic number */ 00290 }; 00291 00292 00293 int ufs_init(); 00294 int ufs_initialize(); 00295 00296 #endif 00297 00298 /*** 00299 END 00300 ***/ 00301