-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.h
More file actions
151 lines (131 loc) · 4.24 KB
/
Copy pathtype.h
File metadata and controls
151 lines (131 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*************** type.h file for LEVEL-1 ****************/
#ifndef TYPE
#define TYPE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <ext2fs/ext2_fs.h>
#include <string.h>
#include <libgen.h>
#include <sys/stat.h>
#include <time.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
// struct ext2_super_block {
// u32 s_inodes_count; /* Inodes count */
// u32 s_blocks_count; /* Blocks count */
// u32 s_r_blocks_count; /* Reserved blocks count */
// u32 s_free_blocks_count; /* Free blocks count */
// u32 s_free_inodes_count; /* Free inodes count */
// u32 s_first_data_block; /* First Data Block */
// u32 s_log_block_size; /* Block size */
// u32 s_log_cluster_size; /* Allocation cluster size */
// u32 s_blocks_per_group; /* # Blocks per group */
// u32 s_clusters_per_group; /* # Fragments per group */
// u32 s_inodes_per_group; /* # Inodes per group */
// u32 s_mtime; /* Mount time */
// u32 s_wtime; /* Write time */
// u16 s_mnt_count; /* Mount count */
// s16 s_max_mnt_count; /* Maximal mount count */
// u16 s_magic; /* Magic signature */
// // more non-essential fields
// u16 s_inode_size; /* size of inode structure */
// }
typedef struct ext2_super_block SUPER;
// struct ext2_group_desc {
// u32 bg_block_bitmap; // Bmap block number
// u32 bg_inode_bitmap; // Imap block number
// u32 bg_inode_table; // Inodes begin block number
// u16 bg_free_blocks_count; // THESE are OBVIOUS
// u16 bg_free_inodes_count;
// u16 bg_used_dirs_count;
// u16 bg_pad; // ignore these
// u32 bg_reserved[3];
// };
typedef struct ext2_group_desc GD;
// struct ext2_inode {
// u16 i_mode; // 16 bits = |tttt|ugs|rwx|rwx|rwx|
// u16 i_uid; // owner uid
// u32 i_size; // file size in bytes
// u32 i_atime; // time fields in seconds
// u32 i_ctime; // since 00:00:00,1-1-1970
// u32 i_mtime;
// u32 i_dtime;
// u16 i_gid; // group ID
// u16 i_links_count; // hard-link count
// u32 i_blocks; // number of 512-byte sectors
// u32 i_flags; // IGNORE
// u32 i_reserved1; // IGNORE
// u32 i_block[15]; // See details below
// u32 i_pad[7]; // for inode size = 128 bytes
// };
typedef struct ext2_inode INODE;
// struct ext2_dir_entry_2{
// u32 inode; // inode number; count from 1, NOT 0
// u16 rec_len; // this entry’s length in bytes
// u8 name_len; // name length in bytes
// u8 file_type; // not used
// char name[EXT2_NAME_LEN]; // name: 1-255 chars, no ending NULL
// };
typedef struct ext2_dir_entry_2 DIR;
SUPER *sp;
GD *gp;
INODE *ip;
DIR *dp;
#define FREE 0
#define READY 1
#define BLKSIZE 1024
#define NMINODE 128
#define NPROC 4
#define NOFT 64
#define NFD 10
#define NMTABLE 8
typedef struct minode{
INODE INODE; // INODE structure on disk
int dev, ino; // (dev, ino) of INODE
int refCount; // in use count
int dirty; // 0 for clean, 1 for modified
int mounted; // for level-3
struct Mount *mptr; // for level-3
}MINODE;
typedef struct oft { // OpenFileTable
int mode; // 0 R | 1 W | 2 RW | 3 APP
int refCount;
MINODE *minodePtr;
int offset;
} OFT;
typedef struct Mount {
int dev; // dev (opened vdisk fd number) 0 means FREE
int ninodes; // from superblock
int nblocks;
int bmap; // from GD block
int imap;
int iblk;
MINODE *mounted_inode;
char name[64]; // device name e.g. mydisk
char mount_name[64]; // mounted DIR pathname
} MOUNT;
typedef struct proc{
struct proc *next;
int pid; // process ID
int uid; // user ID
int gid;
int ppid; // parent process ID
int status; // 0 = free, 1 = alive, 2 = dead
MINODE *cwd; // CWD directory pointer
OFT *fd[NFD];
}PROC;
MINODE minode[NMINODE];
OFT oft[NOFT];
MINODE *root;
PROC proc[NPROC], *running;
MOUNT mountTable[NMTABLE]; // set all dev = 0 in init()
char gpath[128]; // global for tokenized components
char *name[64]; // assume at most 64 components in pathname
int n; // number of component strings
int fd, dev;
int nblocks, ninodes, bmap, imap, iblk;
char line[128], cmd[32], pathname[128];
char *disk = "disk2copy"; // change this to YOUR virtual
#endif