Exemplo n.º 1
0
static int
ramfs_mkdir(vnode_t *dir, const char *name, size_t name_len)
{
        vnode_t *vn;
        off_t i;
        ramfs_dirent_t *entry;
	
	 dbg(DBG_INIT,"RAMFS_MKDIR before KASSERT %s\n",name);
        KASSERT(0 != ramfs_lookup(dir, name, name_len, &vn));

        /* Look for space in the directory */
        entry = VNODE_TO_DIRENT(dir);
        for (i = 0; i < RAMFS_MAX_DIRENT; i++, entry++) {
                if (!entry->rd_name[0])
                        break;
        }

        if (i == RAMFS_MAX_DIRENT) {
                return -ENOSPC;
        }

        /* Allocate an inode */
        int ino;
        if (0 > (ino = ramfs_alloc_inode(dir->vn_fs, RAMFS_TYPE_DIR, 0))) {
                return ino;
        }

        /* Set entry in parent */
        entry->rd_ino = ino;
        strncpy(entry->rd_name, name, MIN(name_len, NAME_LEN - 1));
        entry->rd_name[MIN(name_len, NAME_LEN - 1)] = '\0';

        VNODE_TO_RAMFSINODE(dir)->rf_size += sizeof(ramfs_dirent_t);

        /* Set up '.' and '..' in the directory */
        entry = (ramfs_dirent_t *) VNODE_TO_RAMFS(dir)->rfs_inodes[ino]->rf_mem;
        entry->rd_ino = ino;
        strcpy(entry->rd_name, ".");
        entry++;
        entry->rd_ino = dir->vn_vno;
        strcpy(entry->rd_name, "..");

        /* Increase inode size accordingly */
        VNODE_TO_RAMFS(dir)->rfs_inodes[ino]->rf_size = 2 * sizeof(ramfs_dirent_t);

        return 0;
}
Exemplo n.º 2
0
static void
ramfs_delete_vnode(vnode_t *vn)
{
        ramfs_inode_t *inode = VNODE_TO_RAMFSINODE(vn);
        ramfs_t *rfs = VNODE_TO_RAMFS(vn);

        if (0 == --inode->rf_linkcount) {
                KASSERT(rfs->rfs_inodes[vn->vn_vno] == inode);

                rfs->rfs_inodes[vn->vn_vno] = NULL;
                if (inode->rf_mode == RAMFS_TYPE_DATA
                    || inode->rf_mode == RAMFS_TYPE_DIR) {
                        page_free(inode->rf_mem);
                }
                /* otherwise, inode->rf_mem is a devid */

                kfree(inode);
        }
}
Exemplo n.º 3
0
static void
ramfs_read_vnode(vnode_t *vn)
{
        ramfs_t *rfs = VNODE_TO_RAMFS(vn);
        ramfs_inode_t *inode = rfs->rfs_inodes[vn->vn_vno];
        KASSERT(inode && inode->rf_ino == vn->vn_vno);

        inode->rf_linkcount++;

        vn->vn_i = inode;
        vn->vn_len = inode->rf_size;

        switch (inode->rf_mode) {
                case RAMFS_TYPE_DATA:
                        vn->vn_mode = S_IFREG;
                        vn->vn_ops = &ramfs_file_vops;
                        break;
                case RAMFS_TYPE_DIR:
                        vn->vn_mode = S_IFDIR;
                        vn->vn_ops = &ramfs_dir_vops;
                        break;
                case RAMFS_TYPE_CHR:
                        vn->vn_mode = S_IFCHR;
                        vn->vn_ops = NULL;
                        vn->vn_devid = (devid_t)(inode->rf_mem);
                        break;
                case RAMFS_TYPE_BLK:
                        vn->vn_mode = S_IFBLK;
                        vn->vn_ops = NULL;
                        vn->vn_devid = (devid_t)(inode->rf_mem);
                        break;
                default:
                        panic("inode %d has unknown/invalid type %d!!\n",
                              (int)vn->vn_vno, (int)inode->rf_mode);
        }
}