PageRenderTime 30ms CodeModel.GetById 15ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/filesystems/unixfs/ancientfs/ancientfs_2.11bsd.h

http://macfuse.googlecode.com/
C++ Header | 229 lines | 143 code | 27 blank | 59 comment | 0 complexity | 404ede637412a5248748baf3254fce4d MD5 | raw file
  1/*
  2 * Ancient UNIX File Systems for MacFUSE
  3 * Amit Singh
  4 * http://osxbook.com
  5 */
  6
  7#ifndef _ANCIENTFS_211BSD_H_
  8#define _ANCIENTFS_211BSD_H_
  9
 10#include "unixfs_internal.h"
 11
 12typedef uint8_t  a_uchar;    /* ancient unsigned char */
 13typedef int16_t  a_short;    /* ancient short */
 14typedef uint16_t a_ushort;   /* ancient unsigned short */
 15typedef int16_t  a_int;      /* ancient int */
 16typedef uint16_t a_uint;     /* ancient unsigned int */
 17typedef int32_t  a_long;     /* ancient long */
 18typedef uint32_t a_ulong;    /* ancient unsigned long */
 19
 20typedef a_ushort a_ino_t;    /* ancient inode type (ancient unsigned int) */
 21typedef a_long   a_off_t;    /* ancient offset type (ancient long) */
 22typedef a_long   a_time_t;   /* ancient time type (ancient long) */
 23typedef a_long   a_daddr_t;  /* ancient disk address type (ancient long) */
 24typedef a_short  a_dev_t;    /* ancient device type (ancient int) */
 25typedef a_ushort a_uid_t;    /* ancient user id type (ancient unsigned short) */
 26typedef a_ushort a_gid_t;    /* ancient grp id type (ancient unsigned short) */
 27
 28/*
 29 * The file system is made out of blocks of MAXBSIZE units.
 30 */
 31#define MAXBSIZE   1024
 32
 33/*
 34 * MAXPATHLEN defines the longest permissable path length
 35 * after expanding symbolic links. It is used to allocate
 36 * a temporary buffer from the buffer pool in which to do the
 37 * name expansion, hence should be a power of two, and must
 38 * be less than or equal to MAXBSIZE.
 39 * MAXSYMLINKS defines the maximum number of symbolic links
 40 * that may be expanded in a path name. It should be set high
 41 * enough to allow all legitimate uses, but halt infinite loops
 42 * reasonably quickly.
 43 */
 44#define MAXPATHLEN      256
 45#define MAXSYMLINKS     8
 46
 47#undef  CLSIZE
 48#define CLSIZE     2           /* number of blocks / cluster */
 49#define DEV_BSIZE  1024        /* size of secondary block (bytes) */
 50#define NINDIR     (DEV_BSIZE/sizeof(a_daddr_t))
 51#define DEV_BMASK  0x3ffL      /* DEV_BSIZE - 1 */
 52#define DEV_DBMASK 0777L       /* directory block */
 53#define DEV_BSHIFT 10          /* LOG2(DEV_BSIZE) */
 54#define NMASK      0377L       /* NINDIR - 1 */
 55#define NSHIFT     8           /* LOG2(NINDIR) */
 56
 57/*
 58 * The root inode is the root of the file system.
 59 * Inode 0 can't be used for normal purposes and
 60 * historically bad blocks were linked to inode 1,
 61 * thus the root inode is 2. (inode 1 is no longer used for
 62 * this purpose, however numerous dump tapes make this
 63 * assumption, so we are stuck with it)
 64 * The lost+found directory is given the next available
 65 * inode when it is created by ``mkfs''.
 66 */
 67#define ROOTINO  2   /* i number of all roots */
 68
 69#define SUPERB   ((a_daddr_t)1) /* block number of the super block */
 70#define SBSIZE   DEV_BSIZE      /* super block size */
 71#define NICFREE  50             /* number of super block free blocks */
 72#define NICINOD  100            /* number of super block inodes */
 73
 74#define MAXMNTLEN 12
 75#define MAXNAMLEN 63
 76
 77/*
 78 * Definition of the unix super block.
 79 */
 80struct fs
 81{
 82    a_ushort  s_isize;            /* size in blocks of i-list */
 83    a_daddr_t s_fsize;            /* size in blocks of entire volume */
 84    a_short   s_nfree;            /* number of addresses in s_free */
 85    a_daddr_t s_free[NICFREE];    /* free block list */
 86    a_short   s_ninode;           /* number of i-nodes in s_inode */
 87    a_ino_t   s_inode[NICINOD];   /* free i-node list */
 88    char      s_flock;            /* lock during free list manipulation */
 89    char      s_ilock;            /* lock during i-list manipulation */
 90    char      s_fmod;             /* super block modified flag */
 91    char      s_ronly;            /* mounted read-only flag */
 92    time_t    s_time;             /* last super block update */
 93    a_daddr_t s_tfree;            /* total free blocks*/
 94    a_ino_t   s_tinode;           /* total free inodes */
 95    a_short   s_dinfo[2];         /* interleave stuff */
 96#define s_m   s_dinfo[0]          /* optimal step in free list pattern */
 97#define s_n   s_dinfo[1]          /* number of blocks per pattern */
 98    char      s_fsmnt[MAXMNTLEN]; /* ordinary file mounted on */
 99    ino_t     s_lasti;            /* start place for circular search */
100    ino_t     s_nbehind;          /* est # free inodes before s_lasti */
101    a_ushort  s_flags;            /* mount time flags */
102/* actually longer */
103} __attribute__((packed));
104
105struct icommon2 {
106    a_time_t ic_atime;
107    a_time_t ic_mtime;
108    a_time_t ic_ctime;
109} __attribute__((packed));
110
111struct icommon1 {
112    a_ushort ic_mode;  /* mode and type of file */
113    a_ushort ic_nlink; /* number of links to file */
114    a_uid_t  ic_uid;   /* owner's user id */
115    a_gid_t  ic_gid;   /* owner's group id */
116    a_off_t  ic_size;  /* number of bytes in file */
117} __attribute__((packed));
118
119/*
120 * Inode struct as it appears on a disk block.
121 */
122struct dinode
123{
124    struct    icommon1 di_icom1;
125    a_daddr_t di_addr[7];     /* 7 block addresses 4 bytes each */
126    a_ushort  di_reserved[5]; /* pad of 10 to make total size 64 */
127    a_ushort  di_flags;
128    struct    icommon2 di_icom2;
129} __attribute__((packed));
130
131#define di_ic1   di_icom1
132#define di_ic2   di_icom2
133#define di_mode  di_icom1.ic_mode
134#define di_nlink di_icom1.ic_nlink
135#define di_uid   di_icom1.ic_uid
136#define di_gid   di_icom1.ic_gid
137#define di_size  di_icom1.ic_size
138#define di_atime di_icom2.ic_atime
139#define di_mtime di_icom2.ic_mtime
140#define di_ctime di_icom2.ic_ctime
141
142/*
143 * Turn file system block numbers into disk block addresses.
144 * This maps file system blocks to device size blocks.
145 */
146#define fsbtodb(b) ((a_daddr_t)((a_daddr_t)(b) << 1))
147#define dbtofsb(b) ((a_daddr_t)((a_daddr_t)(b) >> 1))
148
149/*
150 * Macros for handling inode numbers:
151 *     inode number to file system block offset.
152 *     inode number to file system block address.
153 */
154#define itoo(x) ((a_int)(((x) + 2 * INOPB - 1) % INOPB))
155#define itod(x) ((a_daddr_t)((((a_uint)(x) + 2 * INOPB - 1) / INOPB)))
156
157/*
158 * The following macros optimize certain frequently calculated
159 * quantities by using shifts and masks in place of divisions
160 * modulos and multiplications.
161 */
162#define blkoff(loc) ((loc) & DEV_BMASK)   /* calculates (loc % fs->fs_bsize) */
163#define lblkno(loc) ((loc) >> DEV_BSHIFT) /* calculates (loc / fs->fs_bsize) */
164
165/*
166 * INOPB is the number of inodes in a secondary storage block.
167 */
168#define INOPB 16 /* MAXBSIZE / sizeof(struct dinode) */
169
170/*
171 * 28 of the di_addr address bytes are used; 7 addresses of 4
172 * bytes each: 4 direct (4Kb directly accessible) and 3 indirect.
173 */
174#define NDADDR 4                 /* direct addresses in inode */
175#define NIADDR 3                 /* indirect addresses in inode */
176#define NADDR  (NDADDR + NIADDR) /* total addresses in inode */
177
178/* i_flag */
179#define ILOCKED         0x1             /* inode is locked */
180#define IUPD            0x2             /* file has been modified */
181#define IACC            0x4             /* inode access time to be updated */
182#define IMOUNT          0x8             /* inode is mounted on */
183#define IWANT           0x10            /* some process waiting on lock */
184#define ITEXT           0x20            /* inode is pure text prototype */
185#define ICHG            0x40            /* inode has been changed */
186#define ISHLOCK         0x80            /* file has shared lock */
187#define IEXLOCK         0x100           /* file has exclusive lock */
188#define ILWAIT          0x200           /* someone waiting on file lock */
189#define IMOD            0x400           /* inode has been modified */
190#define IRENAME         0x800           /* inode is being renamed */
191#define IPIPE           0x1000          /* inode is a pipe */
192#define IRCOLL          0x2000          /* read select collision on pipe */
193#define IWCOLL          0x4000          /* write select collision on pipe */
194#define IXMOD           0x8000          /* inode is text, but impure (XXX) */
195
196/* i_mode */
197#define IFMT            0170000         /* type of file */
198#define IFCHR           0020000         /* character special */
199#define IFDIR           0040000         /* directory */
200#define IFBLK           0060000         /* block special */
201#define IFREG           0100000         /* regular */
202#define IFLNK           0120000         /* symbolic link */
203#define IFSOCK          0140000         /* socket */
204#define ISUID           04000           /* set user id on execution */
205#define ISGID           02000           /* set group id on execution */
206#define ISVTX           01000           /* save swapped text even after use */
207#define IREAD           0400            /* read, write, execute permissions */
208#define IWRITE          0200
209#define IEXEC           0100
210
211#define ANCIENTFS_211BSD_DIRBLKSIZ 512
212
213struct direct {
214    a_ino_t  d_ino;    /* inode number of entry */
215    a_ushort d_reclen; /* length of this record */
216    a_ushort d_namlen; /* length of string in d_name */
217    char     d_name[UNIXFS_MAXNAMLEN + 1];
218} __attribute__((packed));
219
220#define ANCIENTFS_211BSD_DIRSIZ(dp) \
221    ((((sizeof(struct direct) - (UNIXFS_MAXNAMLEN + 1)) + \
222        (dp)->d_namlen + 1) + 3) & ~3)
223
224struct fblk {
225    a_short   df_nfree;
226    a_daddr_t df_free[NICFREE];
227} __attribute__((packed));
228
229#endif /* _ANCIENTFS_211BSD_H_ */