Ejemplo n.º 1
0
diskfs_ino_t lookup(diskfs_sb_t *sb, diskfs_inode_t *inode, char *name) {

    diskfs_dirent_t *dirents = (diskfs_dirent_t *) buffer;
    int32_t dirents_per_block = sb->block_size/sizeof(diskfs_dirent_t);
    int32_t i = 0; /* counter for blocks. */
    int32_t j = 0; /* counter for dirents per block. */

    /* loop on dirents. */
    while(1) {
        /* beginning of a new block? */
        if (j == 0)
            read_file_block(sb, inode, i++, buffer);

        /* done? */
        if (dirents[j].ino == 0)
            return 0;

        /* name matching? */
        if (dirents[j].ino > 1 && !strcmp(dirents[j].name, name))
            return dirents[j].ino;

        /* next dirent: */
        if (++j == dirents_per_block)
            j = 0;
    }

}
Ejemplo n.º 2
0
void diskfs_loadfile(char *path, uint32_t base) {

    /* counter */
    int32_t i = 0, j = 0;

    /* root inode: */
    diskfs_ino_t ino = DISKFS_ROOT_INO;
    diskfs_inode_t inode;

    /* loop on path components */
    while (path[i]) {

        /* Read name: */
        char name[32] = {0};
        j = 0;

        while (path[i] == '/')
            i++; /* skip slash. */

        while (path[i] != 0 && path[i] != '/')
            name[j++] = path[i++];

        if (name[0] == 0)
            continue;

        /* look for the name inside the hierarchy: */
        read_inode(sb, &inode, ino);
        if (!(ino = lookup(sb, &inode, name))) {
            /* not found! */
            printf("%s is missing.\n", path);
            while(1);
        }

    }

    /* load kernel */
    printf("Loading %s (inode %d) to 0x%x...", path, ino, base);
    read_inode(sb, &inode, ino);
    for (i = 0; i < inode.blocks; i++) {
        uint8_t *dest = (uint8_t *)(base+i*sb->block_size);
        read_file_block(sb,&inode, i, buffer);
        for (j = 0; j < sb->block_size; j++)
            dest[j] = buffer[j];
    }
    printf(" done\n");

}
Ejemplo n.º 3
0
void diskfs_load(char *path, uint32_t base) {

    /* Get superblock */
    diskfs_sb_t *sb = (diskfs_sb_t *)(DISK_BASE+512);

    /* Read Root Inode: */
    diskfs_ino_t ino = DISKFS_ROOT_INO;
    diskfs_inode_t inode;

    /* loop on path components */
    int32_t i = 0;
    while (path[i]) {

        /* Read name: */
        char name[32] = {0};
        int32_t j = 0;

        while (path[i] == '/')
            i++; /* skip slash. */

        while (path[i] != 0 && path[i] != '/')
            name[j++] = path[i++];

        if (name[0] == 0)
            continue;

        /* look for the name inside the hierarchy: */
        read_inode(sb, &inode, ino);
        if (!(ino = lookup(sb, &inode, name))) {
            /* not found! */
            printf("%s is missing.\n", path);
            while(1);
        }

    }

    /* load kernel */
    printf("Loading %s (inode %d) to 0x%x...", path, ino, base);
    read_inode(sb, &inode, ino);
    for (i = 0; i < inode.blocks; i++)
        read_file_block(sb,&inode,i,(void *)(base+i*sb->block_size));
    printf(" done\n");

}