int init(void) { inode_t* ino; if(unlikely((ino = vfs_mkdev("tty", 0, S_IFCHR | 0666)) == NULL)) return E_ERR; memset(&ios, 0, sizeof(ios)); ios.c_iflag |= 0; ios.c_oflag |= 0; ios.c_cflag |= 0; ios.c_lflag |= ISIG | ICANON | ECHO | ECHOE; ios.c_cc[VEOF] = 000; ios.c_cc[VEOL] = 000; ios.c_cc[VERASE] = 0177; ios.c_cc[VINTR] = 003; ios.c_cc[VKILL] = 025; ios.c_cc[VQUIT] = 034; ios.c_cc[VMIN] = 0; ino->read = tty_read; ino->write = tty_write; //ino->ioctl = tty_ioctl; ino->userdata = (void*) &ios; sys_symlink("/dev/tty0", "/dev/stdin"); sys_symlink("/dev/tty0", "/dev/stdout"); sys_symlink("/dev/tty0", "/dev/stderr"); return E_OK; }
static int filemon_wrapper_symlink(struct lwp * l, struct sys_symlink_args * uap, register_t * retval) { int ret; int error; size_t done; struct filemon *filemon; if ((ret = sys_symlink(l, uap, retval)) == 0) { filemon = filemon_lookup(curproc); if (filemon) { error = copyinstr(SCARG(uap, path), filemon->fm_fname1, sizeof(filemon->fm_fname1), &done); if (error == 0) error = copyinstr(SCARG(uap, link), filemon->fm_fname2, sizeof(filemon->fm_fname2), &done); if (error == 0) { filemon_printf(filemon, "L %d '%s' '%s'\n", curproc->p_pid, filemon->fm_fname1, filemon->fm_fname2); } rw_exit(&filemon->fm_mtx); } } return (ret); }
int vfswrap_symlink(vfs_handle_struct *handle, connection_struct *conn, const char *oldpath, const char *newpath) { int result; START_PROFILE(syscall_symlink); result = sys_symlink(oldpath, newpath); END_PROFILE(syscall_symlink); return result; }
/* * create a device node called <name> which points to * <devfs_name> if possible, otherwise find a device node * which matches <dev> and make <name> a symlink pointing to it. */ int __init create_dev(char *name, dev_t dev, char *devfs_name) { char path[64]; sys_unlink(name); if (devfs_name && devfs_name[0]) { if (strncmp(devfs_name, "/dev/", 5) == 0) devfs_name += 5; sprintf(path, "/dev/%s", devfs_name); if (sys_access(path, 0) == 0) return sys_symlink(devfs_name, name); } if (!dev) return -1; strcpy(path, "/dev"); if (find_in_devfs(path, new_encode_dev(dev)) < 0) return -1; return sys_symlink(path + 5, name); }
/* called under sb->s_umount semaphore */ static int vz_restore_symlink(struct super_block *sb, char *path, int type) { mm_segment_t oldfs; char *newpath; char dest[64]; const char *names[] = { [USRQUOTA] "aquota.user", [GRPQUOTA] "aquota.group" }; int err; newpath = kmalloc(strlen(path) + sizeof(".new"), GFP_KERNEL); if (newpath == NULL) return -ENOMEM; strcpy(newpath, path); strcat(newpath, ".new"); sprintf(dest, "/proc/vz/vzaquota/%08x/%s", new_encode_dev(sb->s_dev), names[type]); /* * Lockdep will learn unneeded dependency while unlink(2): * ->s_umount => ->i_mutex/1 => ->i_mutex * Reverse dependency is, * open_namei() => ->i_mutex => lookup_hash() => __lookup_hash() * => ->lookup() \eq vzdq_aquotq_lookup() => find_qmblk_by_dev() * => user_get_super() => ->s_umount * * However, first set of ->i_mutex'es belong to /, second to /proc . * Right fix is to get rid of vz_restore_symlink(), of course. */ up_read(&sb->s_umount); oldfs = get_fs(); set_fs(KERNEL_DS); err = sys_unlink(newpath); if (err < 0 && err != -ENOENT) goto out_restore; err = sys_symlink(dest, newpath); if (err < 0) goto out_restore; err = sys_rename(newpath, path); out_restore: set_fs(oldfs); down_read(&sb->s_umount); /* umounted meanwhile? */ if (err == 0 && !sb->s_root) err = -ENODEV; kfree(newpath); return err; }
static int __init create_dev(char *name, kdev_t dev, char *devfs_name) { void *handle; char path[64]; int n; sys_unlink(name); if (!do_devfs) return sys_mknod(name, S_IFBLK|0600, kdev_t_to_nr(dev)); handle = devfs_find_handle(NULL, dev ? NULL : devfs_name, MAJOR(dev), MINOR(dev), DEVFS_SPECIAL_BLK, 1); if (!handle) return -1; n = devfs_generate_path(handle, path + 5, sizeof (path) - 5); if (n < 0) return -1; return sys_symlink(path + n + 5, name); }
void rcv_file_symlink (struct htlc_conn *htlc) { u_int16_t fnlen = 0, newfnlen = 0; char dir[MAXPATHLEN], newdir[MAXPATHLEN], filename[NAME_MAX], newfilename[NAME_MAX], oldbuf[MAXPATHLEN], newbuf[MAXPATHLEN]; char rsrcpath_old[MAXPATHLEN], rsrcpath_new[MAXPATHLEN]; struct stat rsb; int err; dir[0] = newdir[0] = 0; dh_start(htlc) switch (dh_type) { case HTLC_DATA_FILE_NAME: fnlen = dh_len >= NAME_MAX ? NAME_MAX - 1 : dh_len; read_filename(filename, dh_data, fnlen); break; case HTLC_DATA_FILE_RENAME: newfnlen = dh_len >= NAME_MAX ? NAME_MAX - 1 : dh_len; read_filename(newfilename, dh_data, newfnlen); break; case HTLC_DATA_DIR: if ((err = hldir_to_path(dh, ROOTDIR, dir, dir))) { snd_strerror(htlc, err); return; } break; case HTLC_DATA_DIR_RENAME: if ((err = hldir_to_path(dh, ROOTDIR, newdir, newdir))) { snd_strerror(htlc, err); return; } break; } dh_end() if ((!dir[0] && !fnlen) || !newdir[0]) { hlwrite(htlc, HTLS_HDR_TASK, 1, 1, HTLS_DATA_TASKERROR, 6, "huh?!?"); return; } if (!dir[0]) strcpy(dir, ROOTDIR); if (fnlen) { snprintf(oldbuf, sizeof(oldbuf), "%s/%s", dir, filename); snprintf(newbuf, sizeof(newbuf), "%s/%s", newdir, newfnlen ? newfilename : filename); } else { strcpy(oldbuf, dir); strcpy(newbuf, newdir); } if (check_dropbox(htlc, oldbuf)) { snd_strerror(htlc, EPERM); return; } if (log_symlink) hxd_log("%s:%s:%u - symlink %s to %s", htlc->name, htlc->login, htlc->uid, newbuf, oldbuf); if (sys_symlink(oldbuf, newbuf)) snd_strerror(htlc, errno); else hlwrite(htlc, HTLS_HDR_TASK, 0, 0); #if defined(CONFIG_HFS) if (!hxd_cfg.operation.hfs) return; if (hxd_cfg.files.fork == HFS_FORK_CAP) { if (!resource_path(rsrcpath_old, oldbuf, &rsb)) { if ((err = resource_path(rsrcpath_new, newbuf, 0))) { /* (void)unlink(newbuf); */ snd_strerror(htlc, err); return; } else { if (sys_symlink(rsrcpath_old, rsrcpath_new)) { /* (void)unlink(newbuf); */ snd_strerror(htlc, errno); return; } } } } if (!finderinfo_path(rsrcpath_old, oldbuf, &rsb)) { if ((err = finderinfo_path(rsrcpath_new, newbuf, 0))) { /* (void)unlink(newbuf); */ snd_strerror(htlc, err); return; } else { if (sys_symlink(rsrcpath_old, rsrcpath_new)) { /* (void)unlink(newbuf); */ snd_strerror(htlc, errno); return; } } } #endif /* CONFIG_HFS */ }
int parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx) { int process_mode = 0; int ret = 0; struct stat stbuf = {0, }; struct tm *tm = NULL; time_t utime; char timestr[256]; char tmp_logfile[1024] = { 0 }; char *tmp_logfile_dyn = NULL; char *tmp_logfilebase = NULL; cmd_args_t *cmd_args = NULL; cmd_args = &ctx->cmd_args; argp_parse (&argp, argc, argv, ARGP_IN_ORDER, NULL, cmd_args); if (ENABLE_DEBUG_MODE == cmd_args->debug_mode) { cmd_args->log_level = GF_LOG_DEBUG; cmd_args->log_file = "/dev/stderr"; cmd_args->no_daemon_mode = ENABLE_NO_DAEMON_MODE; } process_mode = gf_get_process_mode (argv[0]); if ((cmd_args->volfile_server == NULL) && (cmd_args->volfile == NULL)) { if (process_mode == GF_SERVER_PROCESS) cmd_args->volfile = gf_strdup (DEFAULT_SERVER_VOLFILE); else if (process_mode == GF_GLUSTERD_PROCESS) cmd_args->volfile = gf_strdup (DEFAULT_GLUSTERD_VOLFILE); else cmd_args->volfile = gf_strdup (DEFAULT_CLIENT_VOLFILE); } if (cmd_args->run_id) { ret = sys_lstat (cmd_args->log_file, &stbuf); /* If its /dev/null, or /dev/stdout, /dev/stderr, * let it use the same, no need to alter */ if (((ret == 0) && (S_ISREG (stbuf.st_mode) || S_ISLNK (stbuf.st_mode))) || (ret == -1)) { /* Have seperate logfile per run */ tm = localtime (&utime); strftime (timestr, 256, "%Y%m%d.%H%M%S", tm); sprintf (tmp_logfile, "%s.%s.%d", cmd_args->log_file, timestr, getpid ()); /* Create symlink to actual log file */ sys_unlink (cmd_args->log_file); tmp_logfile_dyn = gf_strdup (tmp_logfile); tmp_logfilebase = basename (tmp_logfile_dyn); ret = sys_symlink (tmp_logfilebase, cmd_args->log_file); if (ret == -1) { fprintf (stderr, "symlink of logfile failed"); } else { GF_FREE (cmd_args->log_file); cmd_args->log_file = gf_strdup (tmp_logfile); } GF_FREE (tmp_logfile_dyn); } } return ret; }
int init(void) { tty_read_init(); inode_t* ino_outp; if(unlikely((ino_outp = vfs_mkdev("tty", 0, S_IFCHR | 0666)) == NULL)) return -1; inode_t* ino_inp; if(unlikely((ino_inp = vfs_mkdev("tty", 1, S_IFCHR | 0666)) == NULL)) return -1; struct tty_context* tio = (struct tty_context*) kmalloc(sizeof(struct tty_context), GFP_KERNEL); if(unlikely(!tio)) { kprintf(ERROR "tty: no memory left!"); return -1; } memset(tio, 0, sizeof(struct tty_context)); tio->ios.c_iflag = TTYDEF_IFLAG; tio->ios.c_oflag = TTYDEF_OFLAG; tio->ios.c_cflag = TTYDEF_CFLAG; tio->ios.c_lflag = TTYDEF_LFLAG; tio->ios.c_cc[VEOF] = CEOF; tio->ios.c_cc[VEOL] = CEOL; tio->ios.c_cc[VERASE] = CERASE; tio->ios.c_cc[VINTR] = CINTR; tio->ios.c_cc[VKILL] = CKILL; tio->ios.c_cc[VMIN] = CMIN; tio->ios.c_cc[VQUIT] = CQUIT; tio->ios.c_cc[VSUSP] = CSUSP; tio->ios.c_cc[VTIME] = CTIME; tio->ios.c_cc[VSTART] = CSTART; tio->ios.c_cc[VSTOP] = CSTOP; tio->ios.__c_ispeed = tio->ios.__c_ospeed = TTYDEF_SPEED; tio->winsize.ws_row = 25; tio->winsize.ws_col = 80; tio->winsize.ws_xpixel = 80 * 8; tio->winsize.ws_ypixel = 25 * 16; tio->lined = 0; tio->output = 1; tio->outlen = 0; fifo_init(&tio->in, TTY_BUFSIZ, O_NONBLOCK); fifo_init(&tio->uin, TTY_BUFSIZ, O_NONBLOCK); ino_outp->read = tty_read; ino_outp->write = tty_output_write; ino_outp->ioctl = tty_ioctl; ino_outp->userdata = (void*) tio; ino_inp->read = tty_read; ino_inp->write = tty_input_write; ino_inp->ioctl = tty_ioctl; ino_inp->userdata = (void*) tio; extern int tty_daemon(void*); if(sys_clone(tty_daemon, NULL, CLONE_VM | CLONE_FILES | CLONE_FS | CLONE_SIGHAND, NULL) < 0) kprintf(ERROR "tty: daemon could not start! Some actions like keystroke's binding will be disabled\n"); sys_symlink("/dev/tty1", "/dev/stdin"); sys_symlink("/dev/tty0", "/dev/stdout"); sys_symlink("/dev/tty0", "/dev/stderr"); sys_symlink("/dev/tty0", "/dev/tty"); /* fallback */ return 0; }