void fs_private_dev(void){ // install a new /dev directory if (arg_debug) printf("Mounting tmpfs on /dev\n"); if (mount("tmpfs", "/dev", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=777,gid=0") < 0) errExit("mounting /dev"); // create /dev/shm if (arg_debug) printf("Create /dev/shm directory\n"); int rv = mkdir("/dev/shm", S_IRWXU | S_IRWXG | S_IRWXO); if (rv == -1) errExit("mkdir"); if (chown("/dev/shm", 0, 0) < 0) errExit("chown"); if (chmod("/dev/shm", S_IRWXU | S_IRWXG | S_IRWXO) < 0) errExit("chmod"); // create devices create_char_dev("/dev/zero", 0666, 1, 5); // mknod -m 666 /dev/zero c 1 5 create_char_dev("/dev/null", 0666, 1, 3); // mknod -m 666 /dev/null c 1 3 create_char_dev("/dev/full", 0666, 1, 7); // mknod -m 666 /dev/full c 1 7 create_char_dev("/dev/random", 0666, 1, 8); // Mknod -m 666 /dev/random c 1 8 create_char_dev("/dev/urandom", 0666, 1, 9); // mknod -m 666 /dev/urandom c 1 9 create_char_dev("/dev/tty", 0666, 5, 0); // mknod -m 666 /dev/tty c 5 0 #if 0 create_dev("/dev/tty0", "mknod -m 666 /dev/tty0 c 4 0"); create_dev("/dev/console", "mknod -m 622 /dev/console c 5 1"); #endif // pseudo-terminal rv = mkdir("/dev/pts", 0755); if (rv == -1) errExit("mkdir"); if (chown("/dev/pts", 0, 0) < 0) errExit("chown"); if (chmod("/dev/pts", 0755) < 0) errExit("chmod"); create_char_dev("/dev/pts/ptmx", 0666, 5, 2); //"mknod -m 666 /dev/pts/ptmx c 5 2"); create_link("/dev/pts/ptmx", "/dev/ptmx"); // mount -vt devpts -o newinstance -o ptmxmode=0666 devpts //dev/pts if (mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, "newinstance,ptmxmode=0666") < 0) errExit("mounting /dev/pts"); #if 0 // stdin, stdout, stderr create_link("/proc/self/fd", "/dev/fd"); create_link("/proc/self/fd/0", "/dev/stdin"); create_link("/proc/self/fd/1", "/dev/stdout"); create_link("/proc/self/fd/2", "/dev/stderr"); #endif }
static int __init mount_cramfs_linear_root(void) { create_dev("/dev/root", ROOT_DEV, root_device_name); if (do_mount_root("/dev/root","cramfs",root_mountflags,root_mount_data) == 0) return 1; return 0; }
void __init mount_root(void) { #ifdef CONFIG_ROOT_NFS if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) { if (mount_nfs_root()) return; printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n"); ROOT_DEV = Root_FD0; } #endif #ifdef CONFIG_BLK_DEV_FD if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) { /* rd_doload is 2 for a dual initrd/ramload setup */ if (rd_doload==2) { if (rd_load_disk(1)) { ROOT_DEV = Root_RAM1; root_device_name = NULL; } } else change_floppy("root floppy"); } #endif create_dev("/dev/root", ROOT_DEV, root_device_name); mount_block_root("/dev/root", root_mountflags); }
void create_mtree(const char *path) { struct dev *dev; create_dev(path); dev = open_dev(path, NUM_MTREE_BLOCKS); close_dev(dev); }
static int __init mount_nfs_root(void) { void *data = nfs_root_data(); create_dev("/dev/root", ROOT_DEV, NULL); if (data && do_mount_root("/dev/root", "nfs", root_mountflags, data) == 0) return 1; return 0; }
void Shell::create_context() { create_dev(); vk::init_dispatch_table_bottom(ctx_.instance, ctx_.dev); vk::GetDeviceQueue(ctx_.dev, ctx_.game_queue_family, 0, &ctx_.game_queue); vk::GetDeviceQueue(ctx_.dev, ctx_.present_queue_family, 0, &ctx_.present_queue); create_back_buffers(); // initialize ctx_.{surface,format} before attach_shell create_swapchain(); game_.attach_shell(*this); }
static void md_run_setup(void) { create_dev("/dev/md0", makedev(MD_MAJOR, 0)); if (raid_noautodetect) fprintf(stderr, "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n"); else { int fd = open("/dev/md0", 0, 0); if (fd >= 0) { ioctl(fd, RAID_AUTORUN, (void *)(intptr_t) raid_autopart); close(fd); } } md_setup_drive(); }
int __init initrd_load(void) { if (mount_initrd) { create_dev("/dev/ram", Root_RAM0); /* * Load the initrd data into /dev/ram0. Execute it as initrd * unless /dev/ram0 is supposed to be our actual root device, * in that case the ram disk is just set up here, and gets * mounted in the normal path. */ if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) { sys_unlink((const char __user *)"/initrd.image"); handle_initrd(); return 1; } } sys_unlink((const char __user *)"/initrd.image"); return 0; }
int initrd_load(int argc, char *argv[], dev_t root_dev) { if (access("/initrd.image", R_OK)) return 0; /* No initrd */ dprintf("kinit: initrd found\n"); create_dev("/dev/ram0", Root_RAM0); if (rd_copy_image("/initrd.image") || unlink("/initrd.image")) { fprintf(stderr, "%s: initrd installation failed (too big?)\n", progname); return 0; /* Failed to copy initrd */ } dprintf("kinit: initrd copied\n"); if (root_dev == Root_MULTI) { dprintf("kinit: skipping linuxrc: incompatible with multiple roots\n"); /* Mounting initrd as ordinary root */ return 0; } if (root_dev != Root_RAM0) { int err; dprintf("kinit: running linuxrc\n"); err = run_linuxrc(argc, argv, root_dev); if (err) fprintf(stderr, "%s: running linuxrc: %s\n", progname, strerror(-err)); return 1; /* initrd is root, or run_linuxrc took care of it */ } else { dprintf("kinit: permament (or pivoting) initrd, not running linuxrc\n"); return 0; /* Mounting initrd as ordinary root */ } }
int init_module(void) { int err; remove_dev(); if( (err = alloc_chrdev_region(&devno, 0, 1, DEVICE_NAME)) < 0 ) { printk( "alloc_chrdev_region() error!\n" ); return err; } if( (mydev = cdev_alloc()) == 0 ) { printk( "cdev_alloc() error\n" ); return -1; } cdev_init( mydev, &fops ); mydev->owner = THIS_MODULE; mydev->ops = &fops; if( (err = cdev_add( mydev, devno, 1 )) < 0 ) { printk( "cdev_add() fails\n" ); return err; } printk(KERN_INFO "I was assigned major number %d, minor number %d. To talk to\n", MAJOR(devno), MINOR(devno)); printk(KERN_INFO "the driver, create a dev file with\n"); printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, MAJOR(devno)); printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n"); printk(KERN_INFO "the device file.\n"); printk(KERN_INFO "Remove the device file and module when done.\n"); create_dev( MAJOR(devno), MINOR(devno) ); return 0; }
static void md_setup_drive(void) { int dev_minor, i, ent, partitioned; dev_t dev; dev_t devices[MD_SB_DISKS + 1]; for (ent = 0; ent < md_setup_ents; ent++) { int fd; int err = 0; char *devname; mdu_disk_info_t dinfo; char name[16]; struct stat st_chk; dev_minor = md_setup_args[ent].minor; partitioned = md_setup_args[ent].partitioned; devname = md_setup_args[ent].device_names; snprintf(name, sizeof name, "/dev/md%s%d", partitioned ? "_d" : "", dev_minor); if (stat(name, &st_chk) == 0) continue; if (partitioned) dev = makedev(mdp_major(), dev_minor << MdpMinorShift); else dev = makedev(MD_MAJOR, dev_minor); create_dev(name, dev); for (i = 0; i < MD_SB_DISKS && devname != 0; i++) { char *p; p = strchr(devname, ','); if (p) *p++ = 0; dev = name_to_dev_t(devname); if (!dev) { fprintf(stderr, "md: Unknown device name: %s\n", devname); break; } devices[i] = dev; devname = p; } devices[i] = 0; if (!i) continue; fprintf(stderr, "md: Loading md%s%d: %s\n", partitioned ? "_d" : "", dev_minor, md_setup_args[ent].device_names); fd = open(name, 0, 0); if (fd < 0) { fprintf(stderr, "md: open failed - cannot start " "array %s\n", name); continue; } if (ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) { fprintf(stderr, "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n", dev_minor); close(fd); continue; } if (md_setup_args[ent].level != LEVEL_NONE) { /* non-persistent */ mdu_array_info_t ainfo; ainfo.level = md_setup_args[ent].level; ainfo.size = 0; ainfo.nr_disks = 0; ainfo.raid_disks = 0; while (devices[ainfo.raid_disks]) ainfo.raid_disks++; ainfo.md_minor = dev_minor; ainfo.not_persistent = 1; ainfo.state = (1 << MD_SB_CLEAN); ainfo.layout = 0; ainfo.chunk_size = md_setup_args[ent].chunk; err = ioctl(fd, SET_ARRAY_INFO, &ainfo); for (i = 0; !err && i <= MD_SB_DISKS; i++) { dev = devices[i]; if (!dev) break; dinfo.number = i; dinfo.raid_disk = i; dinfo.state = (1 << MD_DISK_ACTIVE) | (1 << MD_DISK_SYNC); dinfo.major = major(dev); dinfo.minor = minor(dev); err = ioctl(fd, ADD_NEW_DISK, &dinfo); } } else { /* persistent */ for (i = 0; i <= MD_SB_DISKS; i++) { dev = devices[i]; if (!dev) break; dinfo.major = major(dev); dinfo.minor = minor(dev); ioctl(fd, ADD_NEW_DISK, &dinfo); } } if (!err) err = ioctl(fd, RUN_ARRAY, 0); if (err) fprintf(stderr, "md: starting md%d failed\n", dev_minor); else { /* reread the partition table. * I (neilb) and not sure why this is needed, but I * cannot boot a kernel with devfs compiled in from * partitioned md array without it */ close(fd); fd = open(name, 0, 0); ioctl(fd, BLKRRPART, 0); } close(fd); } }
static void __init handle_initrd(void) { int error; int pid; real_root_dev = new_encode_dev(ROOT_DEV); create_dev("/dev/root.old", Root_RAM0); /* mount initrd on rootfs' /root */ mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); sys_mkdir((const char __user *)"/old", 0700); root_fd = sys_open((const char __user *)"/", 0, 0); old_fd = sys_open((const char __user *)"/old", 0, 0); /* move initrd over / and chdir/chroot in initrd root */ sys_chdir((const char __user *)"/root"); sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL); sys_chroot((const char __user *)"."); /* * In case that a resume from disk is carried out by linuxrc or one of * its children, we need to tell the freezer not to wait for us. */ current->flags |= PF_FREEZER_SKIP; pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD); if (pid > 0) while (pid != sys_wait4(-1, NULL, 0, NULL)) yield(); current->flags &= ~PF_FREEZER_SKIP; /* move initrd to rootfs' /old */ sys_fchdir(old_fd); sys_mount((char __user *)"/", (char __user *)".", NULL, MS_MOVE, NULL); /* switch root and cwd back to / of rootfs */ sys_fchdir(root_fd); sys_chroot((const char __user *)"."); sys_close(old_fd); sys_close(root_fd); if (new_decode_dev(real_root_dev) == Root_RAM0) { sys_chdir((const char __user *)"/old"); return; } ROOT_DEV = new_decode_dev(real_root_dev); mount_root(); printk(KERN_NOTICE "Trying to move old root to /initrd ... "); error = sys_mount((char __user *)"/old", (char __user *)"/root/initrd", NULL, MS_MOVE, NULL); if (!error) printk("okay\n"); else { int fd = sys_open((const char __user *)"/dev/root.old", O_RDWR, 0); if (error == -ENOENT) printk("/initrd does not exist. Ignored.\n"); else printk("failed\n"); printk(KERN_NOTICE "Unmounting old root\n"); sys_umount((char __user *)"/old", MNT_DETACH); printk(KERN_NOTICE "Trying to free ramdisk memory ... "); if (fd < 0) { error = fd; } else { error = sys_ioctl(fd, BLKFLSBUF, 0); sys_close(fd); } printk(!error ? "okay\n" : "failed\n"); } }
static int __init mount_nfs_root(void) { char *root_dev, *root_data; unsigned int timeout; int try, err; err = nfs_root_data(&root_dev, &root_data); if (err != 0) return 0; /* * The server or network may not be ready, so try several * times. Stop after a few tries in case the client wants * to fall back to other boot methods. */ timeout = NFSROOT_TIMEOUT_MIN; for (try = 1; ; try++) { err = do_mount_root(root_dev, "nfs", root_mountflags, root_data); if (err == 0) return 1; if (try > NFSROOT_RETRY_MAX) break; /* Wait, in case the server refused us immediately */ ssleep(timeout); timeout <<= 1; if (timeout > NFSROOT_TIMEOUT_MAX) timeout = NFSROOT_TIMEOUT_MAX; } return 0; } #endif #if defined(CONFIG_BLK_DEV_RAM) || defined(CONFIG_BLK_DEV_FD) void __init change_floppy(char *fmt, ...) { struct termios termios; char buf[80]; char c; int fd; va_list args; va_start(args, fmt); vsprintf(buf, fmt, args); va_end(args); fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0); if (fd >= 0) { sys_ioctl(fd, FDEJECT, 0); sys_close(fd); } printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf); fd = sys_open("/dev/console", O_RDWR, 0); if (fd >= 0) { sys_ioctl(fd, TCGETS, (long)&termios); termios.c_lflag &= ~ICANON; sys_ioctl(fd, TCSETSF, (long)&termios); sys_read(fd, &c, 1); termios.c_lflag |= ICANON; sys_ioctl(fd, TCSETSF, (long)&termios); sys_close(fd); } } #endif void __init mount_root(void) { #ifdef CONFIG_ROOT_NFS if (ROOT_DEV == Root_NFS) { if (mount_nfs_root()) return; printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n"); ROOT_DEV = Root_FD0; } #endif #ifdef CONFIG_BLK_DEV_FD if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) { /* rd_doload is 2 for a dual initrd/ramload setup */ if (rd_doload==2) { if (rd_load_disk(1)) { ROOT_DEV = Root_RAM1; root_device_name = NULL; } } else change_floppy("root floppy"); } #endif #ifdef CONFIG_BLOCK create_dev("/dev/root", ROOT_DEV); mount_block_root("/dev/root", root_mountflags); #endif } /* * Prepare the namespace - decide what/where to mount, load ramdisks, etc. */ void __init prepare_namespace(void) { int is_floppy; if (root_delay) { printk(KERN_INFO "Waiting %dsec before mounting root device...\n", root_delay); ssleep(root_delay); } /* * wait for the known devices to complete their probing * * Note: this is a potential source of long boot delays. * For example, it is not atypical to wait 5 seconds here * for the touchpad of a laptop to initialize. */ wait_for_device_probe(); md_run_setup(); if (saved_root_name[0]) { root_device_name = saved_root_name; if (!strncmp(root_device_name, "mtd", 3) || !strncmp(root_device_name, "ubi", 3)) { mount_block_root(root_device_name, root_mountflags); goto out; } ROOT_DEV = name_to_dev_t(root_device_name); if (strncmp(root_device_name, "/dev/", 5) == 0) root_device_name += 5; } if (initrd_load()) goto out; /* wait for any asynchronous scanning to complete */ if ((ROOT_DEV == 0) && root_wait) { printk(KERN_INFO "Waiting for root device %s...\n", saved_root_name); while (driver_probe_done() != 0 || (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0) msleep(100); async_synchronize_full(); } is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR; if (is_floppy && rd_doload && rd_load_disk(0)) ROOT_DEV = Root_RAM0; mount_root(); out: devtmpfs_mount("dev"); sys_mount(".", "/", NULL, MS_MOVE, NULL); sys_chroot("."); }
void fs_private_dev(void){ int rv; // install a new /dev directory if (arg_debug) printf("Mounting tmpfs on /dev\n"); int have_dri = 0; struct stat s; if (stat("/dev/dri", &s) == 0) have_dri = 1; // create DRI_DIR fs_build_mnt_dir(); if (have_dri) { /* coverity[toctou] */ rv = mkdir(RUN_DRI_DIR, 0755); if (rv == -1) errExit("mkdir"); if (chown(RUN_DRI_DIR, 0, 0) < 0) errExit("chown"); if (chmod(RUN_DRI_DIR, 0755) < 0) errExit("chmod"); // keep a copy of /dev/dri under DRI_DIR if (mount("/dev/dri", RUN_DRI_DIR, NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev/dri"); } // restore /dev/log int have_devlog = 0; if (stat("/dev/log", &s) == 0) { have_devlog = 1; FILE *fp = fopen(RUN_DEVLOG_FILE, "w"); if (!fp) have_devlog = 0; else { fprintf(fp, "\n"); fclose(fp); if (mount("/dev/log", RUN_DEVLOG_FILE, NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev/log"); } } // mount tmpfs on top of /dev if (mount("tmpfs", "/dev", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=777,gid=0") < 0) errExit("mounting /dev"); fs_logger("mount tmpfs on /dev"); // bring back /dev/log if (have_devlog) { FILE *fp = fopen("/dev/log", "w"); if (fp) { fprintf(fp, "\n"); fclose(fp); if (mount(RUN_DEVLOG_FILE, "/dev/log", NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev/log"); fs_logger("clone /dev/log"); } } // bring back the /dev/dri directory if (have_dri) { /* coverity[toctou] */ rv = mkdir("/dev/dri", 0755); if (rv == -1) errExit("mkdir"); if (chown("/dev/dri", 0, 0) < 0) errExit("chown"); if (chmod("/dev/dri",0755) < 0) errExit("chmod"); if (mount(RUN_DRI_DIR, "/dev/dri", NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev/dri"); fs_logger("clone /dev/dri"); } // create /dev/shm if (arg_debug) printf("Create /dev/shm directory\n"); rv = mkdir("/dev/shm", 0777); if (rv == -1) errExit("mkdir"); if (chown("/dev/shm", 0, 0) < 0) errExit("chown"); if (chmod("/dev/shm", 0777) < 0) errExit("chmod"); fs_logger("mkdir /dev/shm"); // create devices create_char_dev("/dev/zero", 0666, 1, 5); // mknod -m 666 /dev/zero c 1 5 fs_logger("mknod /dev/zero"); create_char_dev("/dev/null", 0666, 1, 3); // mknod -m 666 /dev/null c 1 3 fs_logger("mknod /dev/null"); create_char_dev("/dev/full", 0666, 1, 7); // mknod -m 666 /dev/full c 1 7 fs_logger("mknod /dev/full"); create_char_dev("/dev/random", 0666, 1, 8); // Mknod -m 666 /dev/random c 1 8 fs_logger("mknod /dev/random"); create_char_dev("/dev/urandom", 0666, 1, 9); // mknod -m 666 /dev/urandom c 1 9 fs_logger("mknod /dev/urandom"); create_char_dev("/dev/tty", 0666, 5, 0); // mknod -m 666 /dev/tty c 5 0 fs_logger("mknod /dev/tty"); #if 0 create_dev("/dev/tty0", "mknod -m 666 /dev/tty0 c 4 0"); create_dev("/dev/console", "mknod -m 622 /dev/console c 5 1"); #endif // pseudo-terminal rv = mkdir("/dev/pts", 0755); if (rv == -1) errExit("mkdir"); if (chown("/dev/pts", 0, 0) < 0) errExit("chown"); if (chmod("/dev/pts", 0755) < 0) errExit("chmod"); fs_logger("mkdir /dev/pts"); create_char_dev("/dev/pts/ptmx", 0666, 5, 2); //"mknod -m 666 /dev/pts/ptmx c 5 2"); fs_logger("mknod /dev/pts/ptmx"); create_link("/dev/pts/ptmx", "/dev/ptmx"); // mount -vt devpts -o newinstance -o ptmxmode=0666 devpts //dev/pts if (mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, "newinstance,ptmxmode=0666") < 0) errExit("mounting /dev/pts"); fs_logger("mount devpts"); #if 0 // stdin, stdout, stderr create_link("/proc/self/fd", "/dev/fd"); create_link("/proc/self/fd/0", "/dev/stdin"); create_link("/proc/self/fd/1", "/dev/stdout"); create_link("/proc/self/fd/2", "/dev/stderr"); #endif }
int main(int argc, char *argv[]) { char **cmdv, **args; char *cmdlines[3]; int i; const char *errmsg; int ret = 0; int cmdc; int fd; struct timeval now; char *mount_argv[] = {"mount_part", "rootfs", "/root"}; pid_t pid; int nandboot = 0; gettimeofday(&now, NULL); srand48(now.tv_usec ^ (now.tv_sec << 24)); /* Default parameters for anything init-like we execute */ init_argc = argc; init_argv = alloca((argc+1)*sizeof(char *)); memcpy(init_argv, argv, (argc+1)*sizeof(char *)); /* * omit /dev/console when generating initramfs, * so we create it dynamically */ if (access("/dev/console", O_RDWR)) { mknod("/dev/console", S_IFCHR|0644, makedev(5, 1)); } if ((fd = open("/dev/console", O_RDWR)) != -1) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); if (fd > STDERR_FILENO) { close(fd); } } mnt_procfs = mount_sys_fs("/proc/cmdline", "/proc", "proc") >= 0; if (!mnt_procfs) { ret = 1; goto bail; } mnt_sysfs = mount_sys_fs("/sys/bus", "/sys", "sysfs") >= 0; if (!mnt_sysfs) { ret = 1; goto bail; } /* Construct the effective kernel command line. The effective kernel command line consists of /arch.cmd, if it exists, /proc/cmdline, plus any arguments after an -- argument on the proper command line, in that order. */ ret = readfile("/arch.cmd", &cmdlines[0]); if (ret < 0) cmdlines[0] = ""; ret = readfile("/proc/cmdline", &cmdlines[1]); if (ret < 0) { fprintf(stderr, "%s: cannot read /proc/cmdline\n", progname); ret = 1; goto bail; } cmdlines[2] = NULL; /* Find an -- argument, and if so append to the command line */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "--")) { i++; break; } } args = &argv[i]; /* Points either to first argument past -- or to the final NULL */ /* Count the number of arguments */ cmdc = split_cmdline(INT_MAX, NULL, argv[0], cmdlines, args); /* Actually generate the cmdline array */ cmdv = (char **)alloca((cmdc+1)*sizeof(char *)); if (split_cmdline(cmdc, cmdv, argv[0], cmdlines, args) != cmdc) { ret = 1; goto bail; } /* Debugging... */ dump_args(cmdc, cmdv); { const char * root_device_name = get_arg(cmdc, cmdv, "root="); if (strncmp(root_device_name, "/dev/mtdblock", strlen("/dev/mtdblock")) == 0) { nandboot = 1; printf("kinit: NAND mode, check online upgrade flag\n"); do_rootfs_OU(); } else { nandboot = 0; printf("kinit: None-NAND mode, ignore online upgrade flag\n"); } } /* Resume from suspend-to-disk, if appropriate */ /* If successful, does not return */ do_resume(cmdc, cmdv); /* Initialize networking, if applicable */ do_ipconfig(cmdc, cmdv); check_path("/root"); if (nandboot) { int index = 0; while (1) { char name[128]; snprintf(name, sizeof(name), "/sys/block/mtdblock%d", index); if (access(name, F_OK) == 0) { snprintf(name, sizeof(name), "/dev/mtdblock%d", index); create_dev(name, name_to_dev_t(name)); index++; } else { break; } } if((pid=fork())<0) fprintf(stderr, "fork error.\n"); else if(pid == 0) { if((ret = execve("/bin/mount_part", mount_argv, NULL)) <0) perror("excute mount_part error\n"); } if(waitpid(pid, NULL, 0) < 0) fprintf(stderr, "wait mount_part error.\n"); } else { do_mounts(cmdc, cmdv); } if (mnt_procfs) { umount2("/proc", 0); mnt_procfs = 0; } if (mnt_sysfs) { umount2("/sys", 0); mnt_sysfs = 0; } make_devices(); init_path = find_init("/root", get_arg(cmdc, cmdv, "init=")); if (!init_path) { fprintf(stderr, "%s: init not found!\n", progname); ret = 2; goto bail; } DEBUG(("kinit: init_path = %s, init=%s\n", init_path, get_arg(cmdc, cmdv, "init="))); init_argv[0] = strrchr(init_path, '/') + 1; errmsg = run_init("/root", "/dev/console", init_path, init_argv); /* If run_init returned, something went bad */ fprintf(stderr, "%s: %s: %s\n", progname, errmsg, strerror(errno)); ret = 2; goto bail; bail: if (mnt_procfs) umount2("/proc", 0); if (mnt_sysfs) umount2("/sys", 0); /* * If we get here, something bad probably happened, and the kernel * will most likely panic. Drain console output so the user can * figure out what happened. */ tcdrain(2); tcdrain(1); return ret; }
void fs_private_dev(void){ // install a new /dev directory if (arg_debug) printf("Mounting tmpfs on /dev\n"); // create DRI_DIR fs_build_mnt_dir(); // keep a copy of dev directory if (mkdir(RUN_DEV_DIR, 0755) == -1) errExit("mkdir"); if (chmod(RUN_DEV_DIR, 0755) == -1) errExit("chmod"); ASSERT_PERMS(RUN_DEV_DIR, 0, 0, 0755); if (mount("/dev", RUN_DEV_DIR, NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev/dri"); // create DEVLOG_FILE int have_devlog = 0; struct stat s; if (stat("/dev/log", &s) == 0) { have_devlog = 1; FILE *fp = fopen(RUN_DEVLOG_FILE, "w"); if (!fp) have_devlog = 0; else { fprintf(fp, "\n"); fclose(fp); if (mount("/dev/log", RUN_DEVLOG_FILE, NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev/log"); } } // mount tmpfs on top of /dev if (mount("tmpfs", "/dev", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0) errExit("mounting /dev"); fs_logger("tmpfs /dev"); deventry_mount(); // bring back /dev/log if (have_devlog) { FILE *fp = fopen("/dev/log", "w"); if (fp) { fprintf(fp, "\n"); fclose(fp); if (mount(RUN_DEVLOG_FILE, "/dev/log", NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev/log"); fs_logger("clone /dev/log"); } } if (mount(RUN_RO_DIR, RUN_DEV_DIR, "none", MS_BIND, "mode=400,gid=0") < 0) errExit("disable /dev/snd"); // create /dev/shm if (arg_debug) printf("Create /dev/shm directory\n"); if (mkdir("/dev/shm", 01777) == -1) errExit("mkdir"); // mkdir sets only the file permission bits if (chmod("/dev/shm", 01777) < 0) errExit("chmod"); ASSERT_PERMS("/dev/shm", 0, 0, 01777); fs_logger("mkdir /dev/shm"); // create devices create_char_dev("/dev/zero", 0666, 1, 5); // mknod -m 666 /dev/zero c 1 5 fs_logger("mknod /dev/zero"); create_char_dev("/dev/null", 0666, 1, 3); // mknod -m 666 /dev/null c 1 3 fs_logger("mknod /dev/null"); create_char_dev("/dev/full", 0666, 1, 7); // mknod -m 666 /dev/full c 1 7 fs_logger("mknod /dev/full"); create_char_dev("/dev/random", 0666, 1, 8); // Mknod -m 666 /dev/random c 1 8 fs_logger("mknod /dev/random"); create_char_dev("/dev/urandom", 0666, 1, 9); // mknod -m 666 /dev/urandom c 1 9 fs_logger("mknod /dev/urandom"); create_char_dev("/dev/tty", 0666, 5, 0); // mknod -m 666 /dev/tty c 5 0 fs_logger("mknod /dev/tty"); #if 0 create_dev("/dev/tty0", "mknod -m 666 /dev/tty0 c 4 0"); create_dev("/dev/console", "mknod -m 622 /dev/console c 5 1"); #endif // pseudo-terminal if (mkdir("/dev/pts", 0755) == -1) errExit("mkdir"); if (chmod("/dev/pts", 0755) == -1) errExit("chmod"); ASSERT_PERMS("/dev/pts", 0, 0, 0755); fs_logger("mkdir /dev/pts"); create_char_dev("/dev/pts/ptmx", 0666, 5, 2); //"mknod -m 666 /dev/pts/ptmx c 5 2"); fs_logger("mknod /dev/pts/ptmx"); create_link("/dev/pts/ptmx", "/dev/ptmx"); // code before github issue #351 // mount -vt devpts -o newinstance -o ptmxmode=0666 devpts //dev/pts // if (mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, "newinstance,ptmxmode=0666") < 0) // errExit("mounting /dev/pts"); // mount /dev/pts gid_t ttygid = get_tty_gid(); char *data; if (asprintf(&data, "newinstance,gid=%d,mode=620,ptmxmode=0666", (int) ttygid) == -1) errExit("asprintf"); if (mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, data) < 0) errExit("mounting /dev/pts"); free(data); fs_logger("clone /dev/pts"); #if 0 // stdin, stdout, stderr create_link("/proc/self/fd", "/dev/fd"); create_link("/proc/self/fd/0", "/dev/stdin"); create_link("/proc/self/fd/1", "/dev/stdout"); create_link("/proc/self/fd/2", "/dev/stderr"); #endif }
static void __init handle_initrd(void) { int error; int pid; real_root_dev = new_encode_dev(ROOT_DEV); create_dev("/dev/root.old", Root_RAM0); /* mount initrd on rootfs' /root */ mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); sys_mkdir("/old", 0700); root_fd = sys_open("/", 0, 0); old_fd = sys_open("/old", 0, 0); /* move initrd over / and chdir/chroot in initrd root */ sys_chdir("/root"); sys_mount(".", "/", NULL, MS_MOVE, NULL); sys_chroot("."); pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD); if (pid > 0) { while (pid != sys_wait4(-1, NULL, 0, NULL)) { try_to_freeze(); yield(); } } /* move initrd to rootfs' /old */ sys_fchdir(old_fd); sys_mount("/", ".", NULL, MS_MOVE, NULL); /* switch root and cwd back to / of rootfs */ sys_fchdir(root_fd); sys_chroot("."); sys_close(old_fd); sys_close(root_fd); if (new_decode_dev(real_root_dev) == Root_RAM0) { sys_chdir("/old"); return; } ROOT_DEV = new_decode_dev(real_root_dev); mount_root(); printk(KERN_NOTICE "Trying to move old root to /initrd ... "); error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL); if (!error) printk("okay\n"); else { int fd = sys_open("/dev/root.old", O_RDWR, 0); if (error == -ENOENT) printk("/initrd does not exist. Ignored.\n"); else printk("failed\n"); printk(KERN_NOTICE "Unmounting old root\n"); sys_umount("/old", MNT_DETACH); printk(KERN_NOTICE "Trying to free ramdisk memory ... "); if (fd < 0) { error = fd; } else { error = sys_ioctl(fd, BLKFLSBUF, 0); sys_close(fd); } printk(!error ? "okay\n" : "failed\n"); } }
void fs_private_dev(void){ // install a new /dev directory if (arg_debug) printf("Mounting tmpfs on /dev\n"); // create DRI_DIR // keep a copy of dev directory mkdir_attr(RUN_DEV_DIR, 0755, 0, 0); if (mount("/dev", RUN_DEV_DIR, NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev"); // create DEVLOG_FILE int have_devlog = 0; struct stat s; if (stat("/dev/log", &s) == 0) { have_devlog = 1; FILE *fp = fopen(RUN_DEVLOG_FILE, "w"); if (!fp) have_devlog = 0; else { fprintf(fp, "\n"); fclose(fp); if (mount("/dev/log", RUN_DEVLOG_FILE, NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev/log"); } } // mount tmpfs on top of /dev if (mount("tmpfs", "/dev", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0) errExit("mounting /dev"); fs_logger("tmpfs /dev"); // optional devices: sound, video cards etc... deventry_mount(); // bring back /dev/log if (have_devlog) { FILE *fp = fopen("/dev/log", "w"); if (fp) { fprintf(fp, "\n"); fclose(fp); if (mount(RUN_DEVLOG_FILE, "/dev/log", NULL, MS_BIND|MS_REC, NULL) < 0) errExit("mounting /dev/log"); fs_logger("clone /dev/log"); } } // bring forward the current /dev/shm directory if necessary if (arg_debug) printf("Process /dev/shm directory\n"); process_dev_shm(); if (mount(RUN_RO_DIR, RUN_DEV_DIR, "none", MS_BIND, "mode=400,gid=0") < 0) errExit("disable run dev directory"); // create default devices create_char_dev("/dev/zero", 0666, 1, 5); // mknod -m 666 /dev/zero c 1 5 fs_logger("mknod /dev/zero"); create_char_dev("/dev/null", 0666, 1, 3); // mknod -m 666 /dev/null c 1 3 fs_logger("mknod /dev/null"); create_char_dev("/dev/full", 0666, 1, 7); // mknod -m 666 /dev/full c 1 7 fs_logger("mknod /dev/full"); create_char_dev("/dev/random", 0666, 1, 8); // Mknod -m 666 /dev/random c 1 8 fs_logger("mknod /dev/random"); create_char_dev("/dev/urandom", 0666, 1, 9); // mknod -m 666 /dev/urandom c 1 9 fs_logger("mknod /dev/urandom"); create_char_dev("/dev/tty", 0666, 5, 0); // mknod -m 666 /dev/tty c 5 0 fs_logger("mknod /dev/tty"); #if 0 create_dev("/dev/tty0", "mknod -m 666 /dev/tty0 c 4 0"); create_dev("/dev/console", "mknod -m 622 /dev/console c 5 1"); #endif // pseudo-terminal mkdir_attr("/dev/pts", 0755, 0, 0); fs_logger("mkdir /dev/pts"); fs_logger("create /dev/pts"); create_char_dev("/dev/pts/ptmx", 0666, 5, 2); //"mknod -m 666 /dev/pts/ptmx c 5 2"); fs_logger("mknod /dev/pts/ptmx"); create_link("/dev/pts/ptmx", "/dev/ptmx"); // code before github issue #351 // mount -vt devpts -o newinstance -o ptmxmode=0666 devpts //dev/pts // if (mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, "newinstance,ptmxmode=0666") < 0) // errExit("mounting /dev/pts"); // mount /dev/pts gid_t ttygid = get_group_id("tty"); char *data; if (asprintf(&data, "newinstance,gid=%d,mode=620,ptmxmode=0666", (int) ttygid) == -1) errExit("asprintf"); if (mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, data) < 0) errExit("mounting /dev/pts"); free(data); fs_logger("clone /dev/pts"); // stdin, stdout, stderr #if 0 create_link("/proc/self/fd", "/dev/fd"); create_link("/proc/self/fd/0", "/dev/stdin"); create_link("/proc/self/fd/1", "/dev/stdout"); create_link("/proc/self/fd/2", "/dev/stderr"); #endif // symlinks for DVD/CD players if (stat("/dev/sr0", &s) == 0) { create_link("/dev/sr0", "/dev/cdrom"); create_link("/dev/sr0", "/dev/cdrw"); create_link("/dev/sr0", "/dev/dvd"); create_link("/dev/sr0", "/dev/dvdrw"); } }