PageRenderTime 15ms CodeModel.GetById 6ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/filesystems/unixfs/ancientfs/ancientfs_v1,2,3.h

http://macfuse.googlecode.com/
C++ Header | 149 lines | 83 code | 25 blank | 41 comment | 9 complexity | a16f75c632ae1c59e2e08496324fa5e3 MD5 | raw file
  1/*
  2 * Ancient UNIX File Systems for MacFUSE
  3 * Amit Singh
  4 * http://osxbook.com
  5 */
  6
  7#ifndef _ANCIENTFS_V123_H_
  8#define _ANCIENTFS_V123_H_
  9
 10#include "unixfs_internal.h"
 11#include "ancientfs.h"
 12
 13typedef int16_t a_int;   /* ancient int */
 14typedef a_int   a_ino_t; /* ancient i-node type */
 15
 16#define BSIZE   512
 17
 18#define ROOTINO 41
 19#define DIRSIZ  8
 20
 21/*
 22 * Disk blocks 0 and 1 are collectively known as the super-block
 23 */
 24
 25#define SUPERB  (off_t)0
 26#define SBSIZE  BSIZE * 2
 27
 28struct filsys
 29{
 30    a_int    s_bmapsz;     /* free storage map bytes; always even */
 31    uint8_t* s_bmap;       /* free storage map */
 32    a_int    s_imapsz;     /* i-node map bytes; always even */
 33    uint8_t* s_imap;       /* i-node map */
 34} __attribute__((packed));
 35
 36/*
 37 * b-map
 38 *
 39 * There is one bit for each block on the device; the bit is "1" if the
 40 * block is free. Thus, if s_bmapsz is n, the blocks on the device are
 41 * numbered 0 through 8n - 1. In s_bmap, the bit for block k of the device
 42 * is in byte k/8 of the map; it is offset k (mod 8) bits from the right.
 43 * Note that bits exist for the super-block and the i-node list, even though
 44 * they are never allocated or freed.
 45 */
 46
 47 /*
 48  * i-map
 49  *
 50  * s_imapsz is also even. I-numbers below 41 are reserved for special files,
 51  * and are never allocated. The first bit in s_imap refers to i-number 41.
 52  * Therefore, the byte number in s_imap for i-node i is (i - 41)/8. It is
 53  * offset (i - 41) (mod 8) bits from the right; unlike s_bmap, a "0" bit
 54  * indicates an available i-node.
 55  */
 56
 57struct dinode
 58{
 59    a_int   di_flags;      /* flags (see below) */
 60    char    di_nlink;      /* number of links */
 61    char    di_uid;        /* user ID of owner */
 62    a_int   di_size;       /* size in bytes */
 63    a_int   di_addr[8];    /* indirect block or contents block 1 through 8 */
 64    a_int   di_crtime[2];  /* creation time */
 65    a_int   di_mtime[2];   /* modification time */
 66    char    di_unused[2];  /* unused */
 67} __attribute__((packed)); /* 32 bytes */
 68
 69/*
 70 * I-numbers begin at 1, and the storage for i-nodes begins at disk block 2.
 71 * Also, i-nodes are 32 bytes long, so 16 of them fit into a block. Therefore,
 72 * i-node i is located in block (i + 31)/16 of the file system, and begins
 73 * 32 * ((i + 31)(mod 16)) bytes from its start.
 74 */
 75
 76#define INOPB 16           /* i-nodes per block */
 77
 78/* flags */
 79#define IALLOC  0100000    /* i-node is allocated */
 80#define IFMT    060000
 81#define IFDIR   040000     /* directory */
 82#define IMOD    020000     /* file has been modified (always on) */
 83#define ILARG   010000     /* large file */
 84#define ISUID   000040     /* set user ID on execution */
 85#define IEXEC   000020     /* executable */
 86#define IRUSR   000010     /* read, owner */
 87#define IWUSR   000004     /* write, owner */
 88#define IROTH   000002     /* read, non-owner */
 89#define IWOTH   000001     /* write, non-owner */
 90
 91static inline int
 92ancientfs_v123_mode(mode_t mode, uint32_t flags)
 93{
 94    int newmode = 0;
 95
 96    mode = mode & ~(IALLOC | ILARG | IMOD);
 97
 98    if ((mode & IFMT) == 0)
 99        newmode |= S_IFREG;
100    else
101        newmode |= (mode & IFMT);
102    if (mode & ISUID)
103        newmode |= S_ISUID;
104    if (mode & IEXEC)
105        newmode |= S_IXUSR;
106    if (mode & IRUSR)
107        newmode |= S_IRUSR;
108    if (mode & IWUSR)
109        newmode |= S_IWUSR;
110    if (mode & IROTH) {
111        newmode |= S_IROTH;
112        if (mode & IEXEC)
113            newmode |= S_IXOTH;
114    }
115    if (mode & IWOTH)
116        newmode |= S_IWOTH;
117
118    return newmode;
119}
120
121/*
122 * v1 00:00 Jan 1, 1971 /60
123 * v2 00:00 Jan 1, 1971 /60
124 * v3 00:00 Jan 1, 1972 /60
125 *
126 * modern 00:00 Jan 1, 1970 full seconds
127 */
128static inline uint32_t
129ancientfs_v123_time(uint32_t t, uint32_t flags)
130{
131    uint32_t cvt = t;
132
133    cvt = cvt / 60; /* times were measured in sixtieths of a second */
134
135    uint32_t epoch_years = (flags & ANCIENTFS_UNIX_V1) ? 1 :
136                           (flags & ANCIENTFS_UNIX_V2) ? 1 :
137                           (flags & ANCIENTFS_UNIX_V3) ? 2 : 0;
138
139    cvt += (epoch_years * 365 * 24 * 3600); /* epoch fixup */
140
141    return cvt;
142}
143
144struct dent {
145    a_int u_ino;          /* i-node table pointer */
146    char  u_name[DIRSIZ]; /* component name */
147} __attribute__((packed));
148
149#endif /* _ANCIENTFS_V123_H_ */