nuclear@88: #include nuclear@89: #include nuclear@89: #include nuclear@88: #include "fs.h" nuclear@88: #include "ata.h" nuclear@88: #include "part.h" nuclear@88: #include "panic.h" nuclear@88: nuclear@89: #define MAGIC 0xccf5ccf5 nuclear@89: #define BLKSZ 1024 nuclear@88: nuclear@89: typedef uint32_t blkid; nuclear@89: nuclear@89: struct superblock { nuclear@89: uint32_t magic; nuclear@89: nuclear@89: blkid istart; nuclear@89: unsigned int icount; nuclear@89: nuclear@89: blkid dstart; nuclear@89: unsigned int dcount; nuclear@89: }; nuclear@89: nuclear@89: struct filesys { nuclear@89: int dev; nuclear@89: struct partition part; nuclear@89: nuclear@89: struct superblock *sb; nuclear@89: }; nuclear@89: nuclear@89: static int find_rootfs(struct filesys *fs); nuclear@88: nuclear@88: /* root device & partition */ nuclear@89: static struct filesys root; nuclear@88: nuclear@88: void init_fs(void) nuclear@88: { nuclear@89: root.sb = malloc(512); nuclear@89: assert(root.sb); nuclear@89: nuclear@89: if(find_rootfs(&root) == -1) { nuclear@88: panic("can't find root filesystem\n"); nuclear@88: } nuclear@88: } nuclear@88: nuclear@89: #define PART_TYPE 0xcc nuclear@89: static int find_rootfs(struct filesys *fs) nuclear@88: { nuclear@88: int i, num_dev, partid; nuclear@88: struct partition *plist, *p; nuclear@88: nuclear@88: num_dev = ata_num_devices(); nuclear@88: for(i=0; istart_sect + 2, fs->sb); nuclear@89: nuclear@89: if(fs->sb->magic == MAGIC) { nuclear@89: printf("found root ata%dp%d\n", i, partid); nuclear@89: fs->dev = i; nuclear@89: fs->part = *p; nuclear@89: return 0; nuclear@89: } nuclear@88: } nuclear@88: p = p->next; nuclear@88: partid++; nuclear@88: } nuclear@88: free_part_list(plist); nuclear@88: } nuclear@88: return -1; nuclear@88: }