kern

annotate 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
rev   line source
nuclear@88 1 #include <stdio.h>
nuclear@89 2 #include <stdlib.h>
nuclear@89 3 #include <assert.h>
nuclear@88 4 #include "fs.h"
nuclear@88 5 #include "ata.h"
nuclear@88 6 #include "part.h"
nuclear@88 7 #include "panic.h"
nuclear@88 8
nuclear@89 9 #define MAGIC 0xccf5ccf5
nuclear@89 10 #define BLKSZ 1024
nuclear@88 11
nuclear@89 12 typedef uint32_t blkid;
nuclear@89 13
nuclear@89 14 struct superblock {
nuclear@89 15 uint32_t magic;
nuclear@89 16
nuclear@89 17 blkid istart;
nuclear@89 18 unsigned int icount;
nuclear@89 19
nuclear@89 20 blkid dstart;
nuclear@89 21 unsigned int dcount;
nuclear@89 22 };
nuclear@89 23
nuclear@89 24 struct filesys {
nuclear@89 25 int dev;
nuclear@89 26 struct partition part;
nuclear@89 27
nuclear@89 28 struct superblock *sb;
nuclear@89 29 };
nuclear@89 30
nuclear@89 31 static int find_rootfs(struct filesys *fs);
nuclear@88 32
nuclear@88 33 /* root device & partition */
nuclear@89 34 static struct filesys root;
nuclear@88 35
nuclear@88 36 void init_fs(void)
nuclear@88 37 {
nuclear@89 38 root.sb = malloc(512);
nuclear@89 39 assert(root.sb);
nuclear@89 40
nuclear@89 41 if(find_rootfs(&root) == -1) {
nuclear@88 42 panic("can't find root filesystem\n");
nuclear@88 43 }
nuclear@88 44 }
nuclear@88 45
nuclear@89 46 #define PART_TYPE 0xcc
nuclear@89 47 static int find_rootfs(struct filesys *fs)
nuclear@88 48 {
nuclear@88 49 int i, num_dev, partid;
nuclear@88 50 struct partition *plist, *p;
nuclear@88 51
nuclear@88 52 num_dev = ata_num_devices();
nuclear@88 53 for(i=0; i<num_dev; i++) {
nuclear@88 54 plist = p = get_part_list(i);
nuclear@88 55
nuclear@88 56 partid = 0;
nuclear@88 57 while(p) {
nuclear@88 58 if(get_part_type(p) == PART_TYPE) {
nuclear@89 59 /* found the correct partition, now read the superblock
nuclear@89 60 * and make sure it's got the correct magic id
nuclear@89 61 */
nuclear@89 62 ata_read_pio(i, p->start_sect + 2, fs->sb);
nuclear@89 63
nuclear@89 64 if(fs->sb->magic == MAGIC) {
nuclear@89 65 printf("found root ata%dp%d\n", i, partid);
nuclear@89 66 fs->dev = i;
nuclear@89 67 fs->part = *p;
nuclear@89 68 return 0;
nuclear@89 69 }
nuclear@88 70 }
nuclear@88 71 p = p->next;
nuclear@88 72 partid++;
nuclear@88 73 }
nuclear@88 74 free_part_list(plist);
nuclear@88 75 }
nuclear@88 76 return -1;
nuclear@88 77 }