void dm_init_char_devices(void) { int zero = dm_device_register(&__zero_kdev); int null = dm_device_register(&__null_kdev); sys_mknod("/dev/null", S_IFCHR | 0666, GETDEV(null, 0)); sys_mknod("/dev/zero", S_IFCHR | 0666, GETDEV(zero, 0)); }
int sys_openpty(int *master, int *slave, char *slavename, const struct termios *term, const struct winsize *win) { int num = atomic_fetch_add(&__pty_next_num, 1); char mname[32]; char sname[32]; snprintf(mname, 32, "/dev/ptym%d", num); snprintf(sname, 32, "/dev/ptys%d", num); sys_mknod(mname, S_IFCHR | 0666, GETDEV(pty_major, num)); sys_mknod(sname, S_IFCHR | 0666, GETDEV(pty_major, num)); int mfd = sys_open(mname, O_RDWR, 0); int sfd = sys_open(sname, O_RDWR, 0); if(mfd < 0 || sfd < 0) { sys_unlink(mname); sys_unlink(sname); return -ENOENT; } struct file *mf = file_get(mfd); struct file *sf = file_get(sfd); vfs_inode_get(mf->inode); vfs_inode_get(sf->inode); pty_create(mf->inode); sf->inode->devdata = mf->inode->devdata; struct pty *pty = mf->inode->devdata; assert(pty); pty->master = mf->inode; pty->slave = sf->inode; pty->num = num; if(term) memcpy(&pty->term, term, sizeof(*term)); if(win) memcpy(&pty->size, win, sizeof(*win)); file_put(mf); file_put(sf); if(slavename) strncpy(slavename, sname, 32); if(master) *master = mfd; if(slave) *slave = sfd; return 0; }
int vfswrap_mknod(vfs_handle_struct *handle, connection_struct *conn, const char *pathname, mode_t mode, SMB_DEV_T dev) { int result; START_PROFILE(syscall_mknod); result = sys_mknod(pathname, mode, dev); END_PROFILE(syscall_mknod); return result; }
int osf1_sys_mknod(struct lwp *l, const struct osf1_sys_mknod_args *uap, register_t *retval) { struct sys_mknod_args a; SCARG(&a, path) = SCARG(uap, path); SCARG(&a, mode) = SCARG(uap, mode); SCARG(&a, dev) = osf1_cvt_dev_to_native(SCARG(uap, dev)); return sys_mknod(l, &a, retval); }
int module_install(void) { printk(1, "[keyboard]: Driver loading\n"); spinlock_create(&lock); irqk = cpu_interrupt_register_handler(IRQ1, __int_handle); flush_port(); keyboard_major = dm_device_register(&kbkd); sys_mknod("/dev/keyboard", S_IFCHR | 0644, GETDEV(keyboard_major, 0)); printk(1, "[keyboard]: initialized keyboard\n"); return 0; }
asmlinkage long sys_csci3411_set_attr ( char *filename, char *attrname, char *attrvalue, int size ) { struct stat sb ; /* necessary structure for using stat() */ char *fstring ; /* file/directory to give attribute to */ char *dstring ; /* temporary string for strstr() */ char buf[128] ; /* copy of the original filename */ char loc[128] ; /* full filepath for attr folder */ char cmd[128] ; /* command for system calls */ bool_t filetype ; /* is the tag for a file or dir? */ int fd ; /* file descriptor for attribute file */ mm_segment_t fs ; /* FS segment used to make sys calls */ fs = get_fs(); set_fs(get_ds()); /* check if filename is an existing file or directory */ if( sys_newstat(filename,&sb)==0 && S_ISREG(sb.st_mode) ) filetype = CSCI3411_FILE; else if( sys_newstat(filename,&sb)==0 && S_ISDIR(sb.st_mode) ) filetype = CSCI3411_DIR; else return -1; /* file/directory does not exist */ /* split filename strings into containing folder and file */ fstring = strrchr(filename, '/'); fstring += sizeof(char); copy_from_user( buf, filename, sizeof(buf)/sizeof(char)); dstring = strstr( buf, fstring ); strncpy( dstring,"\0",1); sprintf(loc,"%s.%s_attr",buf,fstring); /* check if attributes directory exists, mkdir if it doesn't */ if( sys_newstat(loc,&sb)==0 && S_ISDIR(sb.st_mode) ); else sys_mkdir(loc,sb.st_mode); /* create file in attribute directory * in the event of a duplicate attribute file, * overwrite with newer information */ sprintf(cmd,"%s/%s",loc,attrname); sys_unlink(cmd); //remove file if it exists so we can make a new one sys_mknod(cmd,sb.st_mode,0); fd = sys_open(cmd,O_CREAT|O_WRONLY,0); if(fd<0) printk("file creation failed\n"); else sys_write(fd,attrvalue,size); set_fs(fs); 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 ; } }
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); }
int sys_open(char *path, int flag, mode_t mode) { extern int sys_mknod(char *filename, mode_t mode, dev_t dev); int fd; struct file *file; struct inode *inode; struct task *current = CURRENT_TASK(); for (fd = 0; fd < NR_OPEN; fd++) { if (!current->file[fd]) break; } if (fd >= NR_OPEN) return -EINVAL; for (file = file_table; file < file_table + NR_FILE; file++) if (!file->f_count) break; if (file >= file_table + NR_FILE) return -EINVAL; if (!(inode = namei(path, NULL))) { if (!(flag & O_CREAT)) { if (sys_mknod(path, S_IFREG | (mode & 07777), 0) < 0) return -EAGAIN; } inode = namei(path, NULL); } iunlock(inode); file->f_count = 1; file->f_inode = inode; file->f_pos = 0; file->f_mode = flag; current->file[fd] = file; return fd; }
/* * Create a simple rootfs that is similar to the default initramfs */ static int __init default_rootfs(void) { int err; err = sys_mkdir("/dev", 0755); if (err < 0) goto out; err = sys_mknod((const char __user *) "/dev/console", S_IFCHR | S_IRUSR | S_IWUSR, new_encode_dev(MKDEV(5, 1))); if (err < 0) goto out; err = sys_mkdir("/root", 0700); if (err < 0) goto out; return 0; out: printk(KERN_WARNING "Failed to create a rootfs\n"); return err; }
void pty_init(void) { pty_major = dm_device_register(&__pty_kdev); sys_mknod("/dev/tty", S_IFCHR | 0666, GETDEV(pty_major, 0)); }
static void build_console(void) { #define mknoddev(m,s) (m<<8|s) printk(KERN_INFO "Build the /dev/console node.\n"); sys_mknod("/dev/console", 0662 | S_IFCHR, mknoddev(5,1)); }
void build_console(void) { #define mknoddev(m,s) (m<<8|s) printk(KERN_WARNING "Build the dev/console in kernel mode.\n"); sys_mknod("/dev/console",0660 | S_IFCHR,mknoddev(5,1)); }
/* cr_mknod * * Creates regular files or fifos (no devices) making them anonymous (unlinked) * if desired, populating the struct path appropriatly. * In the event of an error, no dput() or path_put() is required, * otherwise they are. * * In the event that an object exists with the given name, it will be * check for the proper mode prior to return, yielding -EEXIST on conflict. */ int cr_mknod(cr_errbuf_t *eb, struct path *path, const char *name, int mode, unsigned long unlinked_id) { mm_segment_t oldfs; int err; #if CRI_DEBUG /* first validate mode */ switch (mode & S_IFMT) { case S_IFREG: case S_IFIFO: break; default: CR_ERR_EB(eb, "Unknown/invalid type %d passed to cr_mknod %s.", (mode&S_IFMT), name); err = -EINVAL; goto out; } #endif if (unlinked_id) { /* Generate a replacement name which we will use instead of the original one. */ name = cr_anonymous_rename(eb, name, unlinked_id); if (!name) { CR_ERR_EB(eb, "cr_mknod - failed to rename unlinked object"); err = -ENOMEM; goto out; } } /* sys_mknod() */ oldfs = get_fs(); set_fs(KERNEL_DS); err = sys_mknod(name, mode, 0); set_fs(oldfs); if (err == -EEXIST) { /* Keep going, it may be the one we want */ } else if (err < 0) { goto out_free; } /* Now get the (struct path) for the newly-created object. * YES, there is a potential race, but we check below that we have the right object. */ err = cr_kern_path(name, LOOKUP_FOLLOW, path); if (err < 0) { CR_ERR_EB(eb, "cr_mknod: cr_kern_path(%s) returned %d after sys_mknod()", name, err); goto out_free; } /* Check that we have the desired object type. * Needed for sys_mknod() == -EEXIST and for the mknod-to-lookup race. */ if ((path->dentry->d_inode->i_mode ^ mode) & S_IFMT) { CR_ERR_EB(eb, "cr_mknod: cr_kern_path(%s) found conflicting object", name); err = -EEXIST; path_put(path); goto out_free; } /* unlink if required */ if (unlinked_id) { /* Note possibility of silent failure here: */ oldfs = get_fs(); set_fs(KERNEL_DS); (void) sys_unlink(name); set_fs(oldfs); } out_free: if (unlinked_id) { __putname(name); } out: return err; }