kern

diff src/fs.c @ 89:2f555c81ae67

starting the filesystem
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 Dec 2011 18:19:35 +0200
parents a398bf73fe93
children 7ff2b4971216
line diff
     1.1 --- a/src/fs.c	Thu Dec 08 13:34:47 2011 +0200
     1.2 +++ b/src/fs.c	Thu Dec 08 18:19:35 2011 +0200
     1.3 @@ -1,25 +1,50 @@
     1.4  #include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <assert.h>
     1.7  #include "fs.h"
     1.8  #include "ata.h"
     1.9  #include "part.h"
    1.10  #include "panic.h"
    1.11  
    1.12 -#define PART_TYPE	0xcc
    1.13 +#define MAGIC	0xccf5ccf5
    1.14 +#define BLKSZ	1024
    1.15  
    1.16 -static int find_rootfs(int *dev, struct partition *part);
    1.17 +typedef uint32_t blkid;
    1.18 +
    1.19 +struct superblock {
    1.20 +	uint32_t magic;
    1.21 +
    1.22 +	blkid istart;
    1.23 +	unsigned int icount;
    1.24 +
    1.25 +	blkid dstart;
    1.26 +	unsigned int dcount;
    1.27 +};
    1.28 +
    1.29 +struct filesys {
    1.30 +	int dev;
    1.31 +	struct partition part;
    1.32 +
    1.33 +	struct superblock *sb;
    1.34 +};
    1.35 +
    1.36 +static int find_rootfs(struct filesys *fs);
    1.37  
    1.38  /* root device & partition */
    1.39 -static int rdev;
    1.40 -static struct partition rpart;
    1.41 +static struct filesys root;
    1.42  
    1.43  void init_fs(void)
    1.44  {
    1.45 -	if(find_rootfs(&rdev, &rpart) == -1) {
    1.46 +	root.sb = malloc(512);
    1.47 +	assert(root.sb);
    1.48 +
    1.49 +	if(find_rootfs(&root) == -1) {
    1.50  		panic("can't find root filesystem\n");
    1.51  	}
    1.52  }
    1.53  
    1.54 -static int find_rootfs(int *dev, struct partition *part)
    1.55 +#define PART_TYPE	0xcc
    1.56 +static int find_rootfs(struct filesys *fs)
    1.57  {
    1.58  	int i, num_dev, partid;
    1.59  	struct partition *plist, *p;
    1.60 @@ -31,11 +56,17 @@
    1.61  		partid = 0;
    1.62  		while(p) {
    1.63  			if(get_part_type(p) == PART_TYPE) {
    1.64 -				/* found it! */
    1.65 -				printf("using ata%dp%d\n", i, partid);
    1.66 -				*dev = i;
    1.67 -				*part = *p;
    1.68 -				return 0;
    1.69 +				/* found the correct partition, now read the superblock
    1.70 +				 * and make sure it's got the correct magic id
    1.71 +				 */
    1.72 +				ata_read_pio(i, p->start_sect + 2, fs->sb);
    1.73 +
    1.74 +				if(fs->sb->magic == MAGIC) {
    1.75 +					printf("found root ata%dp%d\n", i, partid);
    1.76 +					fs->dev = i;
    1.77 +					fs->part = *p;
    1.78 +					return 0;
    1.79 +				}
    1.80  			}
    1.81  			p = p->next;
    1.82  			partid++;