1 typedef struct Xfs Xfs;
2 typedef struct Xfile Xfile;
3 typedef struct Iobuf Iobuf;
4 typedef struct Ext2 Ext2;
6 typedef struct SuperBlock SuperBlock;
7 typedef struct GroupDesc GroupDesc;
8 typedef struct Inode Inode;
9 typedef struct DirEntry DirEntry;
11 #define SECTORSIZE 512
12 #define OFFSET_SUPER_BLOCK 1024
14 #define EXT2_SUPER_MAGIC 0xEF53
15 #define EXT2_MIN_BLOCK_SIZE 1024
16 #define EXT2_MAX_BLOCK_SIZE 4096
17 #define EXT2_ROOT_INODE 2
18 #define EXT2_FIRST_INO 11
19 #define EXT2_VALID_FS 0x0001
20 #define EXT2_ERROR_FS 0x0002
23 * Structure of the super block
26 uint s_inodes_count; /* Inodes count */
27 uint s_blocks_count; /* Blocks count */
28 uint s_r_blocks_count; /* Reserved blocks count */
29 uint s_free_blocks_count; /* Free blocks count */
30 uint s_free_inodes_count; /* Free inodes count */
31 uint s_first_data_block; /* First Data Block */
32 uint s_log_block_size; /* Block size */
33 int s_log_frag_size; /* Fragment size */
34 uint s_blocks_per_group; /* # Blocks per group */
35 uint s_frags_per_group; /* # Fragments per group */
36 uint s_inodes_per_group; /* # Inodes per group */
37 uint s_mtime; /* Mount time */
38 uint s_wtime; /* Write time */
39 ushort s_mnt_count; /* Mount count */
40 short s_max_mnt_count; /* Maximal mount count */
41 ushort s_magic; /* Magic signature */
42 ushort s_state; /* File system state */
43 ushort s_errors; /* Behaviour when detecting errors */
45 uint s_lastcheck; /* time of last check */
46 uint s_checkinterval; /* max. time between checks */
47 uint s_creator_os; /* OS */
48 uint s_rev_level; /* Revision level */
49 ushort s_def_resuid; /* Default uid for reserved blocks */
50 ushort s_def_resgid; /* Default gid for reserved blocks */
51 uint s_reserved[235]; /* Padding to the end of the block */
55 * Structure of a blocks group descriptor
59 uint bg_block_bitmap; /* Blocks bitmap block */
60 uint bg_inode_bitmap; /* Inodes bitmap block */
61 uint bg_inode_table; /* Inodes table block */
62 ushort bg_free_blocks_count; /* Free blocks count */
63 ushort bg_free_inodes_count; /* Free inodes count */
64 ushort bg_used_dirs_count; /* Directories count */
70 * Constants relative to the data blocks
72 #define EXT2_NDIR_BLOCKS 12
73 #define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
74 #define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
75 #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
76 #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
79 * Structure of an inode on the disk
82 ushort i_mode; /* File mode */
83 ushort i_uid; /* Owner Uid */
84 uint i_size; /* Size in bytes */
85 uint i_atime; /* Access time */
86 uint i_ctime; /* Creation time */
87 uint i_mtime; /* Modification time */
88 uint i_dtime; /* Deletion Time */
89 ushort i_gid; /* Group Id */
90 ushort i_links_count; /* Links count */
91 uint i_blocks; /* Blocks count */
92 uint i_flags; /* File flags */
94 uint i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
95 uint i_version; /* File version (for NFS) */
96 uint i_file_acl; /* File ACL */
97 uint i_dir_acl; /* Directory ACL */
98 uint i_faddr; /* Fragment address */
103 * Structure of a directory entry
105 #define EXT2_NAME_LEN 255
106 #define DIR_REC_LEN(name_len) (((name_len) + 8 + 3) & ~3)
109 uint inode; /* Inode number */
110 ushort rec_len; /* Directory entry length */
111 uchar name_len; /* Name length */
113 char name[EXT2_NAME_LEN]; /* File name */
116 #define S_IFMT 00170000
117 #define S_IFLNK 0120000
118 #define S_IFREG 0100000
119 #define S_IFDIR 0040000
121 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
122 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
123 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
125 #define DEFAULT_UID 200
126 #define DEFAULT_GID 100
142 char *name; /* of file containing external f.s. */
143 Qid qid; /* of file containing external f.s. */
144 long ref; /* attach count */
145 Qid rootqid; /* of plan9 constructed root directory */
150 /* data from super block */
154 int inodes_per_group;
155 int inodes_per_block;
157 int blocks_per_group;
160 int superaddr, superoff;
165 Xfile *next; /* in hash bucket */
171 uint inbr; /* inode nbr */
172 uint pinbr; /* parrent inode */
173 ulong bufaddr; /* addr of inode block */
175 int root; /* true on attach for ref count */
176 int dirindex; /* next dir entry to read */
181 #define EXT2_BBLOCK 3
182 #define EXT2_BINODE 4
194 #define DESC_ADDR(xf,n) ( (xf)->grpaddr + ((n)/(xf)->desc_per_block) )
195 #define DESC_OFFSET(xf,d,n) ( ((GroupDesc *)(d)) + ((n)%(xf)->desc_per_block) )
221 extern char *deffile;