kern

annotate src/fs.c @ 88:a398bf73fe93

- added the partition table parsing code - starting with the filesystem
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 Dec 2011 13:34:47 +0200
parents
children 2f555c81ae67
rev   line source
nuclear@88 1 #include <stdio.h>
nuclear@88 2 #include "fs.h"
nuclear@88 3 #include "ata.h"
nuclear@88 4 #include "part.h"
nuclear@88 5 #include "panic.h"
nuclear@88 6
nuclear@88 7 #define PART_TYPE 0xcc
nuclear@88 8
nuclear@88 9 static int find_rootfs(int *dev, struct partition *part);
nuclear@88 10
nuclear@88 11 /* root device & partition */
nuclear@88 12 static int rdev;
nuclear@88 13 static struct partition rpart;
nuclear@88 14
nuclear@88 15 void init_fs(void)
nuclear@88 16 {
nuclear@88 17 if(find_rootfs(&rdev, &rpart) == -1) {
nuclear@88 18 panic("can't find root filesystem\n");
nuclear@88 19 }
nuclear@88 20 }
nuclear@88 21
nuclear@88 22 static int find_rootfs(int *dev, struct partition *part)
nuclear@88 23 {
nuclear@88 24 int i, num_dev, partid;
nuclear@88 25 struct partition *plist, *p;
nuclear@88 26
nuclear@88 27 num_dev = ata_num_devices();
nuclear@88 28 for(i=0; i<num_dev; i++) {
nuclear@88 29 plist = p = get_part_list(i);
nuclear@88 30
nuclear@88 31 partid = 0;
nuclear@88 32 while(p) {
nuclear@88 33 if(get_part_type(p) == PART_TYPE) {
nuclear@88 34 /* found it! */
nuclear@88 35 printf("using ata%dp%d\n", i, partid);
nuclear@88 36 *dev = i;
nuclear@88 37 *part = *p;
nuclear@88 38 return 0;
nuclear@88 39 }
nuclear@88 40 p = p->next;
nuclear@88 41 partid++;
nuclear@88 42 }
nuclear@88 43 free_part_list(plist);
nuclear@88 44 }
nuclear@88 45 return -1;
nuclear@88 46 }