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