void mount_root(void) { register struct file_system_type **fs_type; register struct super_block *sb; struct inode *inode, d_inode; struct file filp; int retval; retry_floppy: memset(&filp, 0, sizeof(filp)); filp.f_inode = &d_inode; filp.f_mode = ((root_mountflags & MS_RDONLY) ? 1 : 3); memset(&d_inode, 0, sizeof(d_inode)); d_inode.i_rdev = ROOT_DEV; retval = blkdev_open(&d_inode, &filp); if (retval == -EROFS) { root_mountflags |= MS_RDONLY; filp.f_mode = 1; retval = blkdev_open(&d_inode, &filp); } for (fs_type = &file_systems[0]; *fs_type; fs_type++) { struct file_system_type *fp = *fs_type; if (retval) break; #ifdef BLOAT_FS if (!fp->requires_dev) continue; #endif sb = read_super(ROOT_DEV, fp->name, root_mountflags, NULL, 1); if (sb) { inode = sb->s_mounted; /* NOTE! it is logically used 4 times, not 1 */ inode->i_count += 3; sb->s_covered = inode; sb->s_flags = (unsigned short int) root_mountflags; current->fs.pwd = current->fs.root = inode; printk("VFS: Mounted root (%s filesystem)%s.\n", fp->name, (sb->s_flags & MS_RDONLY) ? " readonly" : ""); return; } } #ifdef CONFIG_BLK_DEV_BIOS if (ROOT_DEV == 0x0380) { if (filp.f_op->release) filp.f_op->release(&d_inode, &filp); else printk("Release not defined\n"); printk("VFS: Insert root floppy and press ENTER\n"); wait_for_keypress(); goto retry_floppy; } #endif panic("VFS: Unable to mount root fs on %s\n", kdevname(ROOT_DEV)); }
static void do_mount_root(void) { struct file_system_type * fs_type; struct super_block * sb; struct vfsmount *vfsmnt; struct inode * inode, d_inode; struct file filp; int retval; #ifdef CONFIG_ROOT_NFS if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) if (nfs_root_init(nfs_root_name, nfs_root_addrs) < 0) { printk(KERN_ERR "Root-NFS: Unable to contact NFS " "server for root fs, using /dev/fd0 instead\n"); ROOT_DEV = MKDEV(FLOPPY_MAJOR, 0); } if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) { ROOT_DEV = 0; if ((fs_type = get_fs_type("nfs"))) { sb = &super_blocks[0]; while (sb->s_dev) sb++; sb->s_dev = get_unnamed_dev(); sb->s_flags = root_mountflags & ~MS_RDONLY; if (nfs_root_mount(sb) >= 0) { inode = sb->s_mounted; inode->i_count += 3 ; sb->s_covered = inode; sb->s_rd_only = 0; sb->s_dirt = 0; sb->s_type = fs_type; current->fs->pwd = inode; current->fs->root = inode; ROOT_DEV = sb->s_dev; printk (KERN_NOTICE "VFS: Mounted root (nfs filesystem).\n"); vfsmnt = add_vfsmnt(ROOT_DEV, "rootfs", "/"); if (!vfsmnt) panic("VFS: add_vfsmnt failed for NFS root.\n"); vfsmnt->mnt_sb = sb; vfsmnt->mnt_flags = sb->s_flags; return; } sb->s_dev = 0; } if (!ROOT_DEV) { printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n"); ROOT_DEV = MKDEV(FLOPPY_MAJOR, 0); } } #endif #ifdef CONFIG_BLK_DEV_FD if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) { floppy_eject(); printk(KERN_NOTICE "VFS: Insert root floppy and press ENTER\n"); wait_for_keypress(); } #endif memset(&filp, 0, sizeof(filp)); memset(&d_inode, 0, sizeof(d_inode)); d_inode.i_rdev = ROOT_DEV; filp.f_inode = &d_inode; if ( root_mountflags & MS_RDONLY) filp.f_mode = 1; /* read only */ else filp.f_mode = 3; /* read write */ retval = blkdev_open(&d_inode, &filp); if (retval == -EROFS) { root_mountflags |= MS_RDONLY; filp.f_mode = 1; retval = blkdev_open(&d_inode, &filp); } if (retval) /* * Allow the user to distinguish between failed open * and bad superblock on root device. */ printk("VFS: Cannot open root device %s\n", kdevname(ROOT_DEV)); else for (fs_type = file_systems ; fs_type ; fs_type = fs_type->next) { if (!fs_type->requires_dev) continue; sb = read_super(ROOT_DEV,fs_type->name,root_mountflags,NULL,1); if (sb) { inode = sb->s_mounted; inode->i_count += 3 ; /* NOTE! it is logically used 4 times, not 1 */ sb->s_covered = inode; sb->s_flags = root_mountflags; current->fs->pwd = inode; current->fs->root = inode; printk ("VFS: Mounted root (%s filesystem)%s.\n", fs_type->name, (sb->s_flags & MS_RDONLY) ? " readonly" : ""); vfsmnt = add_vfsmnt(ROOT_DEV, "rootfs", "/"); if (!vfsmnt) panic("VFS: add_vfsmnt failed for root fs"); vfsmnt->mnt_sb = sb; vfsmnt->mnt_flags = root_mountflags; return; } } panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV)); }
void __init mount_root(void) { struct file_system_type * fs_type; struct super_block * sb; struct vfsmount *vfsmnt; struct inode * d_inode = NULL; struct file filp; int retval; #ifdef CONFIG_ROOT_NFS if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) { ROOT_DEV = 0; if ((fs_type = get_fs_type("nfs"))) { sb = get_empty_super(); /* "can't fail" */ sb->s_dev = get_unnamed_dev(); sb->s_flags = root_mountflags; sema_init(&sb->s_vfs_rename_sem,1); vfsmnt = add_vfsmnt(sb, "/dev/root", "/"); if (vfsmnt) { if (nfs_root_mount(sb) >= 0) { sb->s_dirt = 0; sb->s_type = fs_type; current->fs->root = dget(sb->s_root); current->fs->pwd = dget(sb->s_root); ROOT_DEV = sb->s_dev; printk (KERN_NOTICE "VFS: Mounted root (NFS filesystem)%s.\n", (sb->s_flags & MS_RDONLY) ? " readonly" : ""); return; } remove_vfsmnt(sb->s_dev); } put_unnamed_dev(sb->s_dev); sb->s_dev = 0; } if (!ROOT_DEV) { printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n"); ROOT_DEV = MKDEV(FLOPPY_MAJOR, 0); } } #endif #ifdef CONFIG_BLK_DEV_FD if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) { #ifdef CONFIG_BLK_DEV_RAM extern int rd_doload; #endif floppy_eject(); #ifndef CONFIG_BLK_DEV_RAM printk(KERN_NOTICE "(Warning, this kernel has no ramdisk support)\n"); #else /* rd_doload is 2 for a dual initrd/ramload setup */ if(rd_doload==2) rd_load_secondary(); else #endif { printk(KERN_NOTICE "VFS: Insert root floppy and press ENTER\n"); wait_for_keypress(); } } #endif memset(&filp, 0, sizeof(filp)); d_inode = get_empty_inode(); d_inode->i_rdev = ROOT_DEV; filp.f_dentry = NULL; if ( root_mountflags & MS_RDONLY) filp.f_mode = 1; /* read only */ else filp.f_mode = 3; /* read write */ retval = blkdev_open(d_inode, &filp); if (retval == -EROFS) { root_mountflags |= MS_RDONLY; filp.f_mode = 1; retval = blkdev_open(d_inode, &filp); } iput(d_inode); if (retval) /* * Allow the user to distinguish between failed open * and bad superblock on root device. */ printk("VFS: Cannot open root device %s\n", kdevname(ROOT_DEV)); else for (fs_type = file_systems ; fs_type ; fs_type = fs_type->next) { if (!(fs_type->fs_flags & FS_REQUIRES_DEV)) continue; sb = read_super(ROOT_DEV,fs_type->name,root_mountflags,root_mount_data,1); if (sb) { sb->s_flags = root_mountflags; current->fs->root = dget(sb->s_root); current->fs->pwd = dget(sb->s_root); printk ("VFS: Mounted root (%s filesystem)%s.\n", fs_type->name, (sb->s_flags & MS_RDONLY) ? " readonly" : ""); vfsmnt = add_vfsmnt(sb, "/dev/root", "/"); if (vfsmnt) return; panic("VFS: add_vfsmnt failed for root fs"); } } #ifdef CONFIG_EMPEG_DISPLAY display_bootfail(); #endif panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV)); }
asmlinkage int sys_swapoff(const char * specialfile) { struct swap_info_struct * p; struct inode * inode; struct file filp; int i, type, prev; int err; if (!suser()) return -EPERM; err = namei(specialfile,&inode); if (err) return err; prev = -1; for (type = swap_list.head; type >= 0; type = swap_info[type].next) { p = swap_info + type; if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) { if (p->swap_file) { if (p->swap_file == inode) break; } else { if (S_ISBLK(inode->i_mode) && (p->swap_device == inode->i_rdev)) break; } } prev = type; } if (type < 0){ iput(inode); return -EINVAL; } if (prev < 0) { swap_list.head = p->next; } else { swap_info[prev].next = p->next; } if (type == swap_list.next) { /* just pick something that's safe... */ swap_list.next = swap_list.head; } p->flags = SWP_USED; err = try_to_unuse(type); if (err) { iput(inode); /* re-insert swap space back into swap_list */ for (prev = -1, i = swap_list.head; i >= 0; prev = i, i = swap_info[i].next) if (p->prio >= swap_info[i].prio) break; p->next = i; if (prev < 0) swap_list.head = swap_list.next = p - swap_info; else swap_info[prev].next = p - swap_info; p->flags = SWP_WRITEOK; return err; } if(p->swap_device){ memset(&filp, 0, sizeof(filp)); filp.f_inode = inode; filp.f_mode = 3; /* read write */ /* open it again to get fops */ if( !blkdev_open(inode, &filp) && filp.f_op && filp.f_op->release){ filp.f_op->release(inode,&filp); filp.f_op->release(inode,&filp); } } iput(inode); nr_swap_pages -= p->pages; iput(p->swap_file); p->swap_file = NULL; p->swap_device = 0; vfree(p->swap_map); p->swap_map = NULL; free_page((long) p->swap_lockmap); p->swap_lockmap = NULL; p->flags = 0; return 0; }
int main(int argc, char** argv) { blkdev_t blk; bool live_dangerously = false; bio_random_args_t a = {}; a.blk = &blk; a.xfer = 32768; a.seed = 7891263897612ULL; a.max_pending = 128; a.write = false; a.linear = true; const char* output_file = nullptr; size_t total = 0; nextarg(); while (argc > 0) { if (argv[0][0] != '-') { break; } if (!strcmp(argv[0], "-bs")) { needparam(); a.xfer = number(argv[0]); if ((a.xfer == 0) || (a.xfer % 4096)) { error("error: block size must be multiple of 4K\n"); } } else if (!strcmp(argv[0], "-tt")) { needparam(); total = number(argv[0]); } else if (!strcmp(argv[0], "-mo")) { needparam(); size_t n = number(argv[0]); if ((n < 1) || (n > 128)) { error("error: max pending must be between 1 and 128\n"); } a.max_pending = static_cast<int>(n); } else if (!strcmp(argv[0], "-read")) { a.write = false; } else if (!strcmp(argv[0], "-write")) { a.write = true; } else if (!strcmp(argv[0], "-live-dangerously")) { live_dangerously = true; } else if (!strcmp(argv[0], "-linear")) { a.linear = true; } else if (!strcmp(argv[0], "-random")) { a.linear = false; } else if (!strcmp(argv[0], "-output-file")) { needparam(); output_file = argv[0]; } else if (!strcmp(argv[0], "-h")) { usage(); return 0; } else { error("error: unknown option: %s\n", argv[0]); } nextarg(); } if (argc == 0) { error("error: no device specified\n"); } if (argc > 1) { error("error: unexpected arguments\n"); } if (a.write && !live_dangerously) { error("error: the option \"-live-dangerously\" is required when using" " \"-write\"\n"); } const char* device_filename = argv[0]; int fd; if ((fd = open(device_filename, O_RDONLY)) < 0) { fprintf(stderr, "error: cannot open '%s'\n", device_filename); return -1; } if (blkdev_open(fd, device_filename, 8*1024*1024, &blk) != ZX_OK) { return -1; } size_t devtotal = blk.info.block_count * blk.info.block_size; // default to entire device if ((total == 0) || (total > devtotal)) { total = devtotal; } a.count = total / a.xfer; zx_duration_t res = 0; total = 0; if (bio_random(&a, &total, &res) != ZX_OK) { return -1; } fprintf(stderr, "%zu bytes in %zu ns: ", total, res); bytes_per_second(total, res); fprintf(stderr, "%zu ops in %zu ns: ", a.count, res); ops_per_second(a.count, res); if (output_file) { perftest::ResultsSet results; auto* test_case = results.AddTestCase( "fuchsia.zircon", "BlockDeviceThroughput", "bytes/second"); double time_in_seconds = static_cast<double>(res) / 1e9; test_case->AppendValue(static_cast<double>(total) / time_in_seconds); if (!results.WriteJSONFile(output_file)) { return 1; } } return 0; }