kern

diff 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 diff
     1.1 --- a/src/fs.h	Thu Dec 08 18:19:35 2011 +0200
     1.2 +++ b/src/fs.h	Fri Dec 09 13:44:15 2011 +0200
     1.3 @@ -1,7 +1,75 @@
     1.4  #ifndef FS_H_
     1.5  #define FS_H_
     1.6  
     1.7 -void init_fs(void);
     1.8 +#include <inttypes.h>
     1.9 +
    1.10 +#define MAGIC	0xccf5ccf5
    1.11 +#define BLKSZ	1024
    1.12 +
    1.13 +#define SECT_TO_BLK(x)	((x) / (BLKSZ / 512))
    1.14 +
    1.15 +#define DEV_MAJOR(dev)	(((dev) >> 8) & 0xff)
    1.16 +#define DEV_MINOR(dev)	((dev) & 0xff)
    1.17 +
    1.18 +
    1.19 +typedef uint32_t dev_t;
    1.20 +typedef uint32_t blkid;
    1.21 +
    1.22 +struct superblock {
    1.23 +	uint32_t magic;	/* magic number */
    1.24 +	int ver;		/* filesystem version */
    1.25 +	int blksize;	/* only BLKSZ supported at the moment */
    1.26 +
    1.27 +	/* total number of blocks */
    1.28 +	unsigned int num_blocks;
    1.29 +	/* inode allocation bitmap start and count */
    1.30 +	blkid ibm_start;
    1.31 +	unsigned int ibm_count;
    1.32 +	/* inode table start and count */
    1.33 +	blkid itbl_start;
    1.34 +	unsigned int itbl_count;
    1.35 +	/* data block allocation bitmap start and count */
    1.36 +	blkid dbm_start;
    1.37 +	unsigned int dbm_count;
    1.38 +	/* data blocks start and count */
    1.39 +	blkid data_start;
    1.40 +	unsigned int data_count;
    1.41 +
    1.42 +	int root_ino;	/* root direcotry inode */
    1.43 +
    1.44 +	/* the following are valid only at runtime, ignored on disk */
    1.45 +	uint32_t *ibm;	/* memory inode bitmap */
    1.46 +	uint32_t *dbm;	/* memory datablock bitmap */
    1.47 +
    1.48 +} __attribute__((packed));
    1.49 +
    1.50 +
    1.51 +/* 20 direct blocks + 10 attributes + 2 indirect = 128 bytes per inode */
    1.52 +#define NDIRBLK	20
    1.53 +struct inode {
    1.54 +	int ino;
    1.55 +	int uid, gid, mode;
    1.56 +	int nlink;
    1.57 +	dev_t dev;
    1.58 +	uint32_t atime, ctime, mtime;
    1.59 +	uint32_t size;
    1.60 +	blkid blk[NDIRBLK];	/* direct blocks */
    1.61 +	blkid ind;			/* indirect */
    1.62 +	blkid dind;			/* double-indirect */
    1.63 +} __attribute__((packed));
    1.64 +
    1.65 +
    1.66 +int sys_mount(char *mntpt, char *devname, unsigned int flags);
    1.67 +int sys_umount(char *devname);
    1.68 +
    1.69 +int sys_open(char *pathname, int flags, unsigned int mode);
    1.70 +int sys_close(int fd);
    1.71 +
    1.72 +int sys_read(int fd, void *buf, int sz);
    1.73 +int sys_write(int fd, void *buf, int sz);
    1.74 +long sys_lseek(int fd, long offs, int from);
    1.75 +
    1.76 +int lookup_path(const char *path);
    1.77  
    1.78  
    1.79  #endif	/* FS_H_ */