int chdir(char *path) { if(!path) return -EINVAL; struct inode *i = get_idir(path, 0); if(!i) return -ENOENT; return ichdir(i); }
int sys_stat(char *f, struct stat *statbuf, int lin) { if(!f || !statbuf) return -EINVAL; struct inode *i; i = (struct inode *) (lin ? lget_idir(f, 0) : get_idir(f, 0)); if(!i) return -ENOENT; do_stat(i, statbuf); iput(i); return 0; }
int chroot(char *n) { if(!n) return -EINVAL; struct inode *i, *old = current_task->thread->root; if(current_task->thread->uid != 0) return -EPERM; i = get_idir(n, 0); if(!i) return -ENOENT; if(!is_directory(i)) { iput(i); return -ENOTDIR; } current_task->thread->root = i; add_atomic(&i->count, 1); ichdir(i); iput(old); return 0; }
int chroot(char *n) { if(!n) return -EINVAL; struct inode *i=0; struct inode *old = current_task->root; if(current_task->uid != GOD) return -EPERM; i = get_idir(n, 0); if(!i) return -ENOENT; if(!is_directory(i)) { iput(i); return -ENOTDIR; } current_task->root = i; change_ireq(i, 1); change_ireq(old, -1); iput(old); chdir("/"); return 0; }
struct inode *ext2_mount(dev_t dev, u64 block, char *node) { ext2_fs_t *fs = get_new_fsvol(); if(!fs) { printk(5, "[ext2]: Unable to allocate new filesystem!\n"); release_fsvol(fs); return 0; } struct inode *in = get_idir(node, 0); if(in && dev == -1) dev = in->dev; if(in && (int)in->dev != dev) printk(4, "[ext2]: Odd...node device is different from given device...\n"); iput(in); fs->block = block; fs->dev = dev; fs->sb->block_size=0; if(node) strncpy(fs->node, node, 16); ext2_read_block(fs, 1, (unsigned char *)fs->sb); if(fs->sb->magic != EXT2_SB_MAGIC) { release_fsvol(fs); return 0; } if(fs->sb->state == 2) { printk(5, "[ext2]: Filesystem has errors: "); if(fs->sb->errors == 2) { printk(5, "Mounting as read-only\n"); fs->read_only=1; } else if(fs->sb->errors == 3) panic(0, "ext2 mount failed!"); else printk(5, "Ignoring...\n"); } unsigned reqf = fs->sb->features_req; if(!(reqf&0x2) || (reqf & 0x1) || (reqf &0x4) || (reqf&0x8)) { release_fsvol(fs); printk(5, "[ext2]: Cannot mount %s due to feature flags\n", node); return 0; } unsigned rof = fs->sb->features_ro; if(ext2_sb_inodesize(fs->sb) != 128) { release_fsvol(fs); printk(5, "[ext2]: Inode size %d is not supported\n", ext2_sb_inodesize(fs->sb)); return 0; } if(!(rof&0x1) || (rof & 0x2) || (rof&0x4)) { printk(5, "[ext2]: Filesystem on %s must be mounted read-only due to feature flags\n", node); fs->read_only=1; } ext2_inode_t root; ext2_inode_read(fs, 2, &root); fs->root = create_sea_inode(&root, "ext2"); strncpy(fs->root->node_str, node, 128); if(fs->sb->mount_count > fs->sb->max_mount_count) fs->sb->mount_count=0; fs->sb->mount_time = get_epoch_time(); ext2_sb_update(fs, fs->sb); printk(0, "[ext2]: Optional features flags are %x\n", fs->sb->features_opt); if(fs->sb->features_opt & 0x4) printk(0, "[ext2]: Hmm...looks like an ext3 filesystem to me. Oh well. It should still work.\n"); if(fs->sb->features_opt & 0x20) printk(0, "[ext2]: Hmm...directories have a hash index. I'll look into that later...\n"); return fs->root; }