/* * mount a file system */ int mount(const char * dev, const char * dir, const char * fs, u32_t flags) { char dev_path[MAX_PATH]; char dir_path[MAX_PATH]; struct stat st; int err; if((err = vfs_path_conv(dir, dir_path)) != 0) return err; if(dev != NULL) { if((err = vfs_path_conv(dev, dev_path)) != 0) return err; if(stat(dev_path, &st) != 0) return EEXIST; if(! S_ISBLK(st.st_mode)) return EACCES; return sys_mount(dev_path, dir_path, (char *)fs, flags); } else return sys_mount(NULL, dir_path, (char *)fs, flags); }
/* * process MOUNT command, mount the device to the target directory. */ static void rfs_mount(struct aipc_rfs_msg *msg) { struct aipc_rfs_mount *param = (struct aipc_rfs_mount*)msg->parameter; int dev_name_size, dir_name_size, fs_name_size, ret; char dev_name[450], dir_name[450], fs_type[24]; mm_segment_t oldfs = get_fs(); dev_name_size = param->dev_name_size; dir_name_size = param->dir_name_size; fs_name_size = param->fs_name_size; memset(dev_name, 0x0, sizeof(dev_name)); memset(dir_name, 0x0, sizeof(dir_name)); memset(fs_type, 0x0, sizeof(fs_type)); memcpy(dev_name, param->name, dev_name_size); memcpy(dir_name, ¶m->name[dev_name_size], dir_name_size); memcpy(fs_type, ¶m->name[dev_name_size + dir_name_size], fs_name_size); set_fs(KERNEL_DS); ret = sys_mount(dev_name, dir_name, fs_type, MS_MGC_VAL | MS_RDONLY | MS_NOSUID, (void *)NULL); set_fs(oldfs); if(ret < 0) { DMSG("rfs_mount error: %d\n", ret); } msg->parameter[0] = ret; }
/* * Prepare the namespace - decide what/where to mount, load ramdisks, etc. */ void __init prepare_namespace(void) { int is_floppy; mount_devfs(); md_run_setup(); if (saved_root_name[0]) { root_device_name = saved_root_name; ROOT_DEV = name_to_dev_t(root_device_name); if (strncmp(root_device_name, "/dev/", 5) == 0) root_device_name += 5; } is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR; if (initrd_load()) goto out; if (is_floppy && rd_doload && rd_load_disk(0)) ROOT_DEV = Root_RAM0; mount_root(); out: umount_devfs("/dev"); sys_mount(".", "/", NULL, MS_MOVE, NULL); sys_chroot("."); security_sb_post_mountroot(); mount_devfs_fs (); }
/* * 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; printk(KERN_DEBUG "root_device_name: %s\n",root_device_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"); printk(KERN_DEBUG "after devtmpfs_mount\n"); sys_mount(".", "/", NULL, MS_MOVE, NULL); printk(KERN_DEBUG "after sys_mount\n"); sys_chroot((const char __user __force *)"."); }
static int __init mount_nfs_root(void) { void *data = nfs_root_data(); if (data && sys_mount("/dev/root","/root","nfs",root_mountflags,data) == 0) return 1; return 0; }
/* * mount a file system */ int mount(const char * dev, const char * dir, const char * fs, u32_t flags) { char dir_path[MAX_PATH]; int err; if((err = vfs_path_conv(dir, dir_path)) != 0) return err; return sys_mount((char *)dev, dir_path, (char *)fs, flags); }
/* * 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 */ while (driver_probe_done() != 0) msleep(100); 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) || !strncmp(root_device_name, "mmc", 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); } is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR; if (is_floppy && rd_doload && rd_load_disk(0)) ROOT_DEV = Root_RAM0; mount_root(); out: sys_mount(".", "/", NULL, MS_MOVE, NULL); sys_chroot("."); security_sb_post_mountroot(); }
asmlinkage int sys_compat_mount (char *devname, char *dirname, char *type, unsigned long flags, void *data, struct pt_regs *regs) { extern int sys_mount (char *, char *, char *, unsigned long, void *); if (old_calling_standard (regs)) { printk (KERN_NOTICE "%s (%d): unsupported mount call standard\n", current->comm, current->pid); return -EINVAL; } return sys_mount (devname, dirname, type, flags, data); }
static int __init do_mount_root(char *name, char *fs, int flags, void *data) { int err = sys_mount(name, "/root", fs, flags, data); if (err) return err; sys_chdir((const char __user __force *)"/root"); ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev; printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n", current->fs->pwd.mnt->mnt_sb->s_type->name, current->fs->pwd.mnt->mnt_sb->s_flags & MS_RDONLY ? " readonly" : "", MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); return 0; }
static int parasite_get_proc_fd() { int ret, fd = -1; char buf[2]; ret = sys_readlink("/proc/self", buf, sizeof(buf)); if (ret < 0 && ret != -ENOENT) { sys_write_msg("Can't readlink /proc/self\n"); return ret; } /* Fast path -- if /proc belongs to this pidns */ if (ret == 1 && buf[0] == '1') { fd = sys_open("/proc", O_RDONLY, 0); goto out_send_fd; } if (sys_mkdir(proc_mountpoint, 0700)) { sys_write_msg("Can't create a directory "); sys_write_msg(proc_mountpoint); sys_write_msg("\n"); return ret; } if (sys_mount("proc", proc_mountpoint, "proc", MS_MGC_VAL, NULL)) { sys_write_msg("mount failed\n"); ret = -1; goto out_rmdir; } fd = sys_open(proc_mountpoint, O_RDONLY, 0); if (sys_umount2(proc_mountpoint, MNT_DETACH)) { sys_write_msg("Can't umount procfs\n"); return -1; } out_rmdir: if (sys_rmdir(proc_mountpoint)) { sys_write_msg("Can't remove directory\n"); return -1; } out_send_fd: if (fd < 0) return fd; ret = send_fd(tsock, NULL, 0, fd); sys_close(fd); return ret; }
static int __init do_mount_root(char *name, char *fs, int flags, void *data) { int err = sys_mount(name, "/root", fs, flags, data); if (err) return err; sys_chdir("/root"); ROOT_DEV = current->fs->pwdmnt->mnt_sb->s_dev; printk("VFS: Mounted root (%s filesystem)%s.\n", current->fs->pwdmnt->mnt_sb->s_type->name, current->fs->pwdmnt->mnt_sb->s_flags & MS_RDONLY ? " readonly" : ""); return 0; }
asmlinkage int sunos_mount(char *type, char *dir, int flags, void *data) { int linux_flags = MS_MGC_MSK; /* new semantics */ int error; char *dev_fname = 0; /* We don't handle the integer fs type */ if ((flags & SMNT_NEWTYPE) == 0) return -EINVAL; /* Do not allow for those flags we don't support */ if (flags & (SMNT_GRPID|SMNT_NOSUB|SMNT_MULTI|SMNT_SYS5)) return -EINVAL; if(flags & SMNT_REMOUNT) linux_flags |= MS_REMOUNT; if(flags & SMNT_RDONLY) linux_flags |= MS_RDONLY; if(flags & SMNT_NOSUID) linux_flags |= MS_NOSUID; error = verify_area(VERIFY_READ, type, 16); if(error) return error; if(strcmp(type, "ext2") == 0) { dev_fname = (char *) data; } else if(strcmp(type, "iso9660") == 0) { dev_fname = (char *) data; } else if(strcmp(type, "minix") == 0) { dev_fname = (char *) data; } else if(strcmp(type, "ext") == 0) { dev_fname = (char *) data; } else if(strcmp(type, "xiafs") == 0) { dev_fname = (char *) data; } else if(strcmp(type, "nfs") == 0) { error = sunos_nfs_mount (dir, flags, data); return error; } else if(strcmp(type, "ufs") == 0) { printk("Warning: UFS filesystem mounts unsupported.\n"); return -ENODEV; } else if(strcmp(type, "proc")) { return -ENODEV; } if(error) return error; error = sys_mount(dev_fname, dir, type, linux_flags, NULL); return error; }
/* * If configured, or requested by the commandline, devtmpfs will be * auto-mounted after the kernel mounted the root filesystem. */ int devtmpfs_mount(const char *mntdir) { int err; if (!mount_dev) return 0; if (!thread) return 0; err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL); if (err) printk(KERN_INFO "devtmpfs: error mounting %i\n", err); else printk(KERN_INFO "devtmpfs: mounted\n"); return err; }
static int __init do_mount_root(char *name, char *fs, int flags, void *data) { struct super_block *s; int err = sys_mount(name, "/root", fs, flags, data); if (err) return err; sys_chdir("/root"); s = current->fs->pwd.dentry->d_sb; ROOT_DEV = s->s_dev; printk(KERN_INFO "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n", s->s_type->name, s->s_flags & MS_RDONLY ? " readonly" : "", MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); return 0; }
/***************************************************************************** 函 数 名 : mount_early_partition 功能描述 : 挂载列表中的分区 输入参数 : mount_item:挂载列表 输出参数 : 返 回 值 : 成功/失败 调用函数 : 被调函数 : *****************************************************************************/ static int mount_early_partition(mount_early *mount_item) { struct mtd_info *mtd; int rt = 0; char mount_name[32] ={0}; struct ST_PART_TBL *part = NULL; part = find_early_partition(mount_item->img_type); if(part != NULL){ mtd = get_mtd_device_nm(part->name); if (IS_ERR(mtd)) { printk("get_mtd_device_nm error.\n"); return PTR_ERR(mtd); } snprintf(mount_name, sizeof(mount_name) - 1, "/dev/block/mtdblock%d", mtd->index); printk(KERN_DEBUG "going to mount %s mount point %s\n", mount_name, mount_item->mount_point); if((rt = sys_mkdir(mount_item->mount_point, S_IRUSR | S_IRGRP)) < 0) { printk(KERN_ERR "create dir failed %s ret 0x%x\n", mount_item->mount_point, rt); return rt ; } rt = sys_mknod(mount_name, S_IFBLK|S_IRWXU|S_IRWXG|S_IRWXO, MDEV_FS(31, mtd->index)); if(rt < 0) { printk(KERN_ERR "mknod failed %s ret 0x%x\n", mount_name, rt); return rt ; } rt = sys_mount(mount_name, mount_item->mount_point, "yaffs2", 0, NULL); if(rt < 0) { printk(KERN_ERR "mount failed %s %s ret 0x%x 0x%x\n", mount_name, \ mount_item->mount_point, rt, MKDEV(31,mtd->index)); return rt ; } return 0; }else{ printk(KERN_ERR "no find nv dload partition!!!\n"); return 1 ; } }
/* * If configured, or requested by the commandline, devtmpfs will be * auto-mounted after the kernel mounted the root filesystem. */ int devtmpfs_mount(const char *mntdir) { int err; if (!mount_dev) return 0; if (!thread) return 0; err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL); if (err) #ifdef CONFIG_DEBUG_PRINTK printk(KERN_INFO "devtmpfs: error mounting %i\n", err); #else ; #endif else
/*! 2017. 6. 3 study -ing */ static int devtmpfsd(void *p) { char options[] = "mode=0755"; int *err = p; /*! sys_unshare는 fork.c의 "SYSCALL_DEFINE1(unshare" 를 참조 */ *err = sys_unshare(CLONE_NEWNS); if (*err) goto out; /*! sys_mount는 fs/namespace.c의 "SYSCALL_DEFINE5(mount" 를 참조 */ *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options); if (*err) goto out; /*! sys_chdir는 fs/open.c 의 "SYSCALL_DEFINE1(chdir" 을 참조 */ sys_chdir("/.."); /* will traverse into overmounted root */ /*! sys_chdir는 fs/open.c 의 "SYSCALL_DEFINE1(chroot" 을 참조 */ sys_chroot("."); complete(&setup_done); while (1) { spin_lock(&req_lock); while (requests) { struct req *req = requests; requests = NULL; spin_unlock(&req_lock); while (req) { struct req *next = req->next; req->err = handle(req->name, req->mode, req->uid, req->gid, req->dev); complete(&req->done); req = next; } spin_lock(&req_lock); } __set_current_state(TASK_INTERRUPTIBLE); spin_unlock(&req_lock); schedule(); } return 0; out: complete(&setup_done); return *err; }
/* * If configured, or requested by the commandline, devtmpfs will be * auto-mounted after the kernel mounted the root filesystem. */ int devtmpfs_mount(const char *mntdir) { int err; int mflags = MS_SILENT; if (!mount_dev) return 0; if (!thread) return 0; #ifdef CONFIG_DEVTMPFS_SAFE mflags |= MS_NOEXEC | MS_NOSUID; #endif err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", mflags, NULL); if (err) printk(KERN_INFO "devtmpfs: error mounting %i\n", err); else printk(KERN_INFO "devtmpfs: mounted\n"); return err; }
static int devtmpfsd(void *p) { char options[] = "mode=0755"; int *err = p; *err = sys_unshare(CLONE_NEWNS); printk(KERN_INFO "%s, %s\n", __FILE__,__func__); if (*err) goto out; *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options); if (*err) goto out; sys_chdir("/.."); /* will traverse into overmounted root */ sys_chroot("."); complete(&setup_done); while (1) { spin_lock(&req_lock); while (requests) { struct req *req = requests; requests = NULL; spin_unlock(&req_lock); while (req) { struct req *next = req->next; req->err = handle(req->name, req->mode, req->dev); complete(&req->done); req = next; } spin_lock(&req_lock); } __set_current_state(TASK_INTERRUPTIBLE); spin_unlock(&req_lock); schedule(); } return 0; out: complete(&setup_done); return *err; }
static void __init mount_block_root(char *name, int flags) { char *fs_names = __getname(); char *p; get_fs_names(fs_names); retry: for (p = fs_names; *p; p += strlen(p)+1) { int err = sys_mount(name, "/root", p, flags, root_mount_data); switch (err) { case 0: goto out; case -EACCES: flags |= MS_RDONLY; goto retry; case -EINVAL: case -EBUSY: continue; } /* * Allow the user to distinguish between failed open * and bad superblock on root device. */ printk ("VFS: Cannot open root device \"%s\" or %s\n", root_device_name, kdevname (ROOT_DEV)); printk ("Please append a correct \"root=\" boot option\n"); panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV)); } panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV)); out: putname(fs_names); sys_chdir("/root"); ROOT_DEV = current->fs->pwdmnt->mnt_sb->s_dev; printk("VFS: Mounted root (%s filesystem)%s.\n", current->fs->pwdmnt->mnt_sb->s_type->name, (current->fs->pwdmnt->mnt_sb->s_flags & MS_RDONLY) ? " readonly" : ""); }
dev_t name_to_dev_t(char *name) { char s[32]; char *p; dev_t res = 0; int part; #ifdef CONFIG_SYSFS int mkdir_err = sys_mkdir("/sys", 0700); if (sys_mount("sysfs", "/sys", "sysfs", 0, NULL) < 0) goto out; #endif if (strncmp(name, "/dev/", 5) != 0) { unsigned maj, min; if (sscanf(name, "%u:%u", &maj, &min) == 2) { res = MKDEV(maj, min); if (maj != MAJOR(res) || min != MINOR(res)) goto fail; } else { res = new_decode_dev(simple_strtoul(name, &p, 16)); if (*p) goto fail; } goto done; } name += 5; res = Root_NFS; if (strcmp(name, "nfs") == 0) goto done; res = Root_RAM0; if (strcmp(name, "ram") == 0) goto done; if (strlen(name) > 31) goto fail; strcpy(s, name); for (p = s; *p; p++) if (*p == '/') *p = '!'; res = try_name(s, 0); if (res) goto done; while (p > s && isdigit(p[-1])) p--; if (p == s || !*p || *p == '0') goto fail; part = simple_strtoul(p, NULL, 10); *p = '\0'; res = try_name(s, part); if (res) goto done; if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p') goto fail; p[-1] = '\0'; res = try_name(s, part); done: #ifdef CONFIG_SYSFS sys_umount("/sys", 0); out: if (!mkdir_err) sys_rmdir("/sys"); #endif return res; fail: res = 0; goto done; }
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("."); }
static int syscall_dispatch(uint32_t sysnum, uint32_t args, regs_t *regs) { switch (sysnum) { case SYS_waitpid: return sys_waitpid((waitpid_args_t *)args); case SYS_exit: do_exit((int)args); panic("exit failed!\n"); return 0; case SYS_thr_exit: kthread_exit((void *)args); panic("thr_exit failed!\n"); return 0; case SYS_thr_yield: sched_make_runnable(curthr); sched_switch(); return 0; case SYS_fork: return sys_fork(regs); case SYS_getpid: return curproc->p_pid; case SYS_sync: sys_sync(); return 0; #ifdef __MOUNTING__ case SYS_mount: return sys_mount((mount_args_t *) args); case SYS_umount: return sys_umount((argstr_t *) args); #endif case SYS_mmap: return (int) sys_mmap((mmap_args_t *) args); case SYS_munmap: return sys_munmap((munmap_args_t *) args); case SYS_open: return sys_open((open_args_t *) args); case SYS_close: return sys_close((int)args); case SYS_read: return sys_read((read_args_t *)args); case SYS_write: return sys_write((write_args_t *)args); case SYS_dup: return sys_dup((int)args); case SYS_dup2: return sys_dup2((dup2_args_t *)args); case SYS_mkdir: return sys_mkdir((mkdir_args_t *)args); case SYS_rmdir: return sys_rmdir((argstr_t *)args); case SYS_unlink: return sys_unlink((argstr_t *)args); case SYS_link: return sys_link((link_args_t *)args); case SYS_rename: return sys_rename((rename_args_t *)args); case SYS_chdir: return sys_chdir((argstr_t *)args); case SYS_getdents: return sys_getdents((getdents_args_t *)args); case SYS_brk: return (int) sys_brk((void *)args); case SYS_lseek: return sys_lseek((lseek_args_t *)args); case SYS_halt: sys_halt(); return -1; case SYS_set_errno: curthr->kt_errno = (int)args; return 0; case SYS_errno: return curthr->kt_errno; case SYS_execve: return sys_execve((execve_args_t *)args, regs); case SYS_stat: return sys_stat((stat_args_t *)args); case SYS_uname: return sys_uname((struct utsname *)args); case SYS_debug: return sys_debug((argstr_t *)args); case SYS_kshell: return sys_kshell((int)args); default: dbg(DBG_ERROR, "ERROR: unknown system call: %d (args: %#08x)\n", sysnum, args); curthr->kt_errno = ENOSYS; return -1; } }
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"); } }
long um_mount(char * dev_name, char * dir_name, char * type, unsigned long new_flags, void * data) { if(type == NULL) type = ""; return(sys_mount(dev_name, dir_name, type, new_flags, data)); }
/* * 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; } #ifdef CONFIG_RTL_FLASH_DUAL_IMAGE_ENABLE extern int is_bank2_root(); //extern from rtl_gpio.c if(is_bank2_root()) //assume bank1 root is mtdblock1 , bank2's root is mtdblock3 strcpy(root_device_name,"/dev/mtdblock3"); #endif 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: sys_mount(".", "/", NULL, MS_MOVE, NULL); sys_chroot("."); }
dev_t name_to_dev_t(char *name) { char s[32]; char *p; dev_t res = 0; int part; #ifdef CONFIG_SYSFS int mkdir_err = sys_mkdir("/sys", 0700); if (sys_mount("sysfs", "/sys", "sysfs", 0, NULL) < 0) goto out; #endif if (strncmp(name, "/dev/", 5) != 0) { unsigned maj, min; if (sscanf(name, "%u:%u", &maj, &min) == 2) { res = MKDEV(maj, min); if (maj != MAJOR(res) || min != MINOR(res)) goto fail; } else { res = new_decode_dev(simple_strtoul(name, &p, 16)); if (*p) goto fail; } goto done; } name += 5; res = Root_NFS; if (strcmp(name, "nfs") == 0) goto done; res = Root_RAM0; if (strcmp(name, "ram") == 0) goto done; #if defined(CONFIG_MTD_BLOCK) || defined(CONFIG_MTD_BLOCK_RO) /* Allow specification of MTD device by name, e.g. * root=/dev/mtdblock:foo * Similar to JFFS2-specific hack in prepare_namespace(), * but more generic. */ if (strncmp(name, "mtdblock:", sizeof("mtdblock:") - 1) == 0) { struct mtd_info *mtd = get_mtd_device_nm(name + sizeof("mtdblock:") - 1); if (unlikely(!mtd)) goto fail; sprintf(name, "mtdblock%d", mtd->index); put_mtd_device(mtd); } #endif if (strlen(name) > 31) goto fail; strcpy(s, name); for (p = s; *p; p++) if (*p == '/') *p = '!'; res = try_name(s, 0); if (res) goto done; while (p > s && isdigit(p[-1])) p--; if (p == s || !*p || *p == '0') goto fail; part = simple_strtoul(p, NULL, 10); *p = '\0'; res = try_name(s, part); if (res) goto done; if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p') goto fail; p[-1] = '\0'; res = try_name(s, part); done: #ifdef CONFIG_SYSFS sys_umount("/sys", 0); out: if (!mkdir_err) sys_rmdir("/sys"); #endif return res; fail: res = 0; goto done; }
void * init_fs(char *disk_name) { int err; void *data = NULL; init_block_cache(1024, 0); init_vnode_layer(); err = sys_mkdir(1, -1, "/myfs", 0); if (install_file_system(&myfs_ops, "myfs", 1, -1) == NULL) { printf("can't install my file system\n"); exit(0); } data = sys_mount(1, "myfs", -1, "/myfs", disk_name, 0, NULL, 0); if (data == NULL) { printf("could not mount %s on /myfs\n", disk_name); exit(0); } return data; }
void * init_fs(char *disk_name) { int err; void *data = NULL; init_block_cache(16348, 0); init_vnode_layer(); err = sys_mkdir(1, -1, "/myfs", 0); if (install_file_system(&fs_entry, "myfs", 1, -1) == NULL) { printf("can't install my file system\n"); exit(0); } data = sys_mount(1, "myfs", -1, "/myfs", disk_name, 0, NULL, 0); if (data == NULL) { printf("could not mount %s on /myfs\n", disk_name); exit(0); } err = sys_chdir(1, -1, "/myfs"); if (err != 0) { printf("Failed to cd into /myfs."); sys_unmount(1, -1, "/myfs"); exit(0); } return data; }