kern

diff src/fs.h @ 98:921a264297a4

merged the filesystem stuff
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 17 Apr 2014 17:03:30 +0300
parents 07fe6a614185
children
line diff
     1.1 --- a/src/fs.h	Thu Apr 17 12:30:02 2014 +0300
     1.2 +++ b/src/fs.h	Thu Apr 17 17:03:30 2014 +0300
     1.3 @@ -3,8 +3,12 @@
     1.4  
     1.5  #include <inttypes.h>
     1.6  
     1.7 -#define MAGIC	0xccf5ccf5
     1.8 -#define BLKSZ	1024
     1.9 +#define MAGIC		0xccf5ccf5
    1.10 +#define FS_VER		1
    1.11 +#define BLKSZ		1024
    1.12 +
    1.13 +#define NAME_MAX	27	/* +1 termin. +4 ino = 32 per dirent */
    1.14 +#define PATH_MAX	256
    1.15  
    1.16  #define SECT_TO_BLK(x)	((x) / (BLKSZ / 512))
    1.17  
    1.18 @@ -16,34 +20,6 @@
    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 @@ -59,7 +35,59 @@
    1.54  	blkid dind;			/* double-indirect */
    1.55  } __attribute__((packed));
    1.56  
    1.57 +struct dir_entry {
    1.58 +	int ino;
    1.59 +	char name[NAME_MAX + 1];
    1.60 +} __attribute__((packed));
    1.61  
    1.62 +struct superblock {
    1.63 +	uint32_t magic;	/* magic number */
    1.64 +	int ver;		/* filesystem version */
    1.65 +	int blksize;	/* only BLKSZ supported at the moment */
    1.66 +
    1.67 +	/* total number of blocks */
    1.68 +	unsigned int num_blocks;
    1.69 +	/* total number of inodes */
    1.70 +	unsigned int num_inodes;
    1.71 +
    1.72 +	/* inode allocation bitmap start and count */
    1.73 +	blkid ibm_start;
    1.74 +	unsigned int ibm_count;
    1.75 +	/* inode table start and count */
    1.76 +	blkid itbl_start;
    1.77 +	unsigned int itbl_count;
    1.78 +	/* block allocation bitmap start and count */
    1.79 +	blkid bm_start;
    1.80 +	unsigned int bm_count;
    1.81 +
    1.82 +	int root_ino;	/* root direcotry inode number */
    1.83 +
    1.84 +	/* the following are valid only at runtime, ignored on disk */
    1.85 +	uint32_t *ibm;	/* in-memory inode bitmap */
    1.86 +	uint32_t *bm;	/* in-memory block bitmap */
    1.87 +	struct inode *root;	/* in-memory root inode */
    1.88 +
    1.89 +} __attribute__((packed));
    1.90 +
    1.91 +
    1.92 +
    1.93 +struct filesys {
    1.94 +	struct block_device *bdev;
    1.95 +
    1.96 +	struct superblock *sb;
    1.97 +
    1.98 +	void *zeroblock;
    1.99 +
   1.100 +	struct filesys *next;
   1.101 +};
   1.102 +
   1.103 +/* defined in fs.c */
   1.104 +int openfs(struct filesys *fs, dev_t dev);
   1.105 +int mkfs(struct filesys *fs, dev_t dev);
   1.106 +void closefs(struct filesys *fs);
   1.107 +int find_inode(const char *path);
   1.108 +
   1.109 +/* defined in fs_sys.c */
   1.110  int sys_mount(char *mntpt, char *devname, unsigned int flags);
   1.111  int sys_umount(char *devname);
   1.112  
   1.113 @@ -70,7 +98,5 @@
   1.114  int sys_write(int fd, void *buf, int sz);
   1.115  long sys_lseek(int fd, long offs, int from);
   1.116  
   1.117 -int lookup_path(const char *path);
   1.118 -
   1.119  
   1.120  #endif	/* FS_H_ */