kern

view src/fs.h @ 90:7ff2b4971216

started work on the filesystem
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 09 Dec 2011 13:44:15 +0200
parents 2f555c81ae67
children f83f50c17c3b
line source
1 #ifndef FS_H_
2 #define FS_H_
4 #include <inttypes.h>
6 #define MAGIC 0xccf5ccf5
7 #define BLKSZ 1024
9 #define SECT_TO_BLK(x) ((x) / (BLKSZ / 512))
11 #define DEV_MAJOR(dev) (((dev) >> 8) & 0xff)
12 #define DEV_MINOR(dev) ((dev) & 0xff)
15 typedef uint32_t dev_t;
16 typedef uint32_t blkid;
18 struct superblock {
19 uint32_t magic; /* magic number */
20 int ver; /* filesystem version */
21 int blksize; /* only BLKSZ supported at the moment */
23 /* total number of blocks */
24 unsigned int num_blocks;
25 /* inode allocation bitmap start and count */
26 blkid ibm_start;
27 unsigned int ibm_count;
28 /* inode table start and count */
29 blkid itbl_start;
30 unsigned int itbl_count;
31 /* data block allocation bitmap start and count */
32 blkid dbm_start;
33 unsigned int dbm_count;
34 /* data blocks start and count */
35 blkid data_start;
36 unsigned int data_count;
38 int root_ino; /* root direcotry inode */
40 /* the following are valid only at runtime, ignored on disk */
41 uint32_t *ibm; /* memory inode bitmap */
42 uint32_t *dbm; /* memory datablock bitmap */
44 } __attribute__((packed));
47 /* 20 direct blocks + 10 attributes + 2 indirect = 128 bytes per inode */
48 #define NDIRBLK 20
49 struct inode {
50 int ino;
51 int uid, gid, mode;
52 int nlink;
53 dev_t dev;
54 uint32_t atime, ctime, mtime;
55 uint32_t size;
56 blkid blk[NDIRBLK]; /* direct blocks */
57 blkid ind; /* indirect */
58 blkid dind; /* double-indirect */
59 } __attribute__((packed));
62 int sys_mount(char *mntpt, char *devname, unsigned int flags);
63 int sys_umount(char *devname);
65 int sys_open(char *pathname, int flags, unsigned int mode);
66 int sys_close(int fd);
68 int sys_read(int fd, void *buf, int sz);
69 int sys_write(int fd, void *buf, int sz);
70 long sys_lseek(int fd, long offs, int from);
72 int lookup_path(const char *path);
75 #endif /* FS_H_ */