nuclear@90: /* This code is used by the kernel AND by userspace filesystem-related tools. nuclear@90: * The kernel-specific parts are conditionally compiled in #ifdef KERNEL blocks nuclear@90: * the rest of the code should be independent. nuclear@90: */ nuclear@88: #include nuclear@89: #include nuclear@89: #include nuclear@90: #include nuclear@88: #include "fs.h" nuclear@90: #include "part.h" nuclear@90: nuclear@90: #ifdef KERNEL nuclear@88: #include "ata.h" nuclear@88: #include "panic.h" nuclear@90: #endif nuclear@89: nuclear@89: struct filesys { nuclear@89: int dev; nuclear@89: struct partition part; nuclear@89: nuclear@89: struct superblock *sb; nuclear@90: nuclear@90: struct filesys *next; nuclear@89: }; nuclear@89: nuclear@89: static int find_rootfs(struct filesys *fs); nuclear@90: static int readblock(int dev, uint32_t blk, void *buf); nuclear@90: static int writeblock(int dev, uint32_t blk, void *buf); nuclear@88: nuclear@88: /* root device & partition */ nuclear@90: static struct filesys *fslist; nuclear@90: nuclear@90: int sys_mount(char *mtpt, char *devname, unsigned int flags) nuclear@90: { nuclear@90: if(strcmp(mtpt, "/") != 0) { nuclear@90: printf("mount: only root can be mounted at the moment\n"); nuclear@90: return -EBUG; nuclear@90: } nuclear@90: nuclear@90: /* mounting root filesystem */ nuclear@90: if(fslist) { nuclear@90: nuclear@90: } nuclear@88: nuclear@88: void init_fs(void) nuclear@88: { nuclear@89: root.sb = malloc(512); nuclear@89: assert(root.sb); nuclear@89: nuclear@90: #ifdef KERNEL nuclear@89: if(find_rootfs(&root) == -1) { nuclear@88: panic("can't find root filesystem\n"); nuclear@88: } nuclear@90: #endif nuclear@88: } nuclear@88: nuclear@90: nuclear@90: #ifdef KERNEL 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 + 1, 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: } nuclear@90: nuclear@90: #define NSECT (BLKSZ / 512) nuclear@90: nuclear@90: static int readblock(struct block_device *bdev, uint32_t blk, void *buf) nuclear@90: { nuclear@90: return blk_read(bdev, blk, buf); nuclear@90: } nuclear@90: nuclear@90: static int writeblock(struct block_device *bdev, uint32_t blk, void *buf) nuclear@90: { nuclear@90: return blk_write(bdev, blk, buf); nuclear@90: } nuclear@90: #else nuclear@90: nuclear@90: /* if this is compiled as part of the user-space tools instead of the kernel nuclear@90: * forward the call to a user read/write block function supplied by the app. nuclear@90: */ nuclear@90: int user_readblock(uint32_t, void*); nuclear@90: int user_writeblock(uint32_t, void*); nuclear@90: nuclear@90: static int readblock(struct block_device *bdev, uint32_t blk, void *buf) nuclear@90: { nuclear@90: return user_readblock(blk, buf); nuclear@90: } nuclear@90: nuclear@90: static int writeblock(struct block_device *bdev, uint32_t blk, void *buf) nuclear@90: { nuclear@90: return user_writeblock(blk, buf); nuclear@90: } nuclear@90: #endif /* KERNEL */