co_rc_t co_os_manager_init(co_manager_t *manager, co_osdep_manager_t *osdep) { co_rc_t rc = CO_RC(OK); co_osdep_manager_t dep; *osdep = dep = co_os_malloc(sizeof(*dep)); if (dep == NULL) return CO_RC(OUT_OF_MEMORY); memset(dep, 0, sizeof(*dep)); dep->proc_root = proc_mkdir("colinux", CO_PROC_ROOT_PTR); if (dep->proc_root == NULL) { rc = CO_RC(ERROR); goto error; } #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) dep->proc_root->owner = THIS_MODULE; #endif dep->proc_ioctl = proc_create("ioctl", S_IFREG|S_IRUSR|S_IWUSR, dep->proc_root, &manager_fileops); if (!dep->proc_ioctl) { rc = CO_RC(ERROR); goto error_root; } //dep->proc_ioctl->proc_fops = &manager_fileops; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) dep->proc_ioctl->owner = THIS_MODULE; #endif return rc; error_root: remove_proc_entry("colinux", CO_PROC_ROOT_PTR); error: co_os_free(dep); return rc; }
/* * Clone the current process. * * The new thread is given a copy of the caller's file handles if RET * is not null. (If RET is null, what we're creating is a kernel-only * thread and it doesn't need an address space or file handles.) * However, the new thread always inherits its current working * directory from the caller. The new thread is given no address space * (the caller decides that). */ int proc_fork(struct proc **ret) { struct proc *proc; struct filetable *tbl; int result; proc = proc_create(curproc->p_name); if (proc == NULL) { return ENOMEM; } /* VM fields */ /* do not clone address space -- let caller decide on that */ /* VFS fields */ tbl = curproc->p_filetable; if (tbl != NULL) { result = filetable_copy(tbl, &proc->p_filetable); if (result) { as_destroy(proc->p_addrspace); proc->p_addrspace = NULL; proc_destroy(proc); return result; } } spinlock_acquire(&curproc->p_lock); /* we don't need to lock proc->p_lock as we have the only reference */ if (curproc->p_cwd != NULL) { VOP_INCREF(curproc->p_cwd); proc->p_cwd = curproc->p_cwd; } spinlock_release(&curproc->p_lock); *ret = proc; return 0; }
/** * This function is called from kmain, however it is not running in a * thread context yet. It should create the idle process which will * start executing idleproc_run() in a real thread context. To start * executing in the new process's context call context_make_active(), * passing in the appropriate context. This function should _NOT_ * return. * * Note: Don't forget to set curproc and curthr appropriately. * * @param arg1 the first argument (unused) * @param arg2 the second argument (unused) */ static void * bootstrap(int arg1, void *arg2) { /* If the next line is removed/altered in your submission, 20 points will be deducted. */ dbgq(DBG_CORE, "SIGNATURE: 53616c7465645f5f75d4d6807cbe46557c5894883e55a7be357a5954568eccfc0c1d901bcc73a4409c500b4c2ad2554d\n"); /* necessary to finalize page table information */ pt_template_init(); curproc = proc_create("IDLE"); KASSERT(NULL != curproc); dbg(DBG_PRINT," (GRADING1A 1.a) successfully created IDLE process with process id %d\n",curproc->p_pid); KASSERT(PID_IDLE == curproc->p_pid); dbg(DBG_PRINT," (GRADING1A 1.a) PID_IDLE value is %d and it matches with the idle process id %d\n",PID_IDLE,curproc->p_pid); curthr = kthread_create(curproc,idleproc_run,0,NULL); KASSERT(NULL != curthr); dbg(DBG_PRINT," (GRADING1A 1.a) thread for the idle process has been created successfully!!\n"); context_make_active(&curthr->kt_ctx); /*panic("weenix returned to bootstrap()!!! BAD!!!\n");*/ return NULL; }
/** * This function, called by the idle process (within 'idleproc_run'), creates the * process commonly refered to as the "init" process, which should have PID 1. * * The init process should contain a thread which begins execution in * initproc_run(). * * @return a pointer to a newly created thread which will execute * initproc_run when it begins executing */ static kthread_t * initproc_create(void) { proc_t* init_p; kthread_t* init_t; init_p = proc_create("init"); KASSERT(NULL!=init_p); dbg(DBG_PRINT, "(GRADING1A 1.b)\n"); KASSERT(PID_INIT==init_p->p_pid); dbg(DBG_PRINT, "(GRADING1A 1.b)\n"); init_t = kthread_create(init_p, initproc_run, 0, NULL); KASSERT(init_t != NULL); dbg(DBG_PRINT, "(GRADING1A 1.b)\n"); return init_t; /* NOT_YET_IMPLEMENTED("PROCS: initproc_create"); return NULL; */ }
static int __init example_init(void) { #ifdef DYNAMIC int ret; ret = kfifo_alloc(&test, FIFO_SIZE, GFP_KERNEL); if (ret) { printk(KERN_ERR "error kfifo_alloc\n"); return ret; } #else INIT_KFIFO(test); #endif testfunc(); if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) { #ifdef DYNAMIC kfifo_free(&test); #endif return -ENOMEM; } return 0; }
static int __init scanlog_init(void) { struct proc_dir_entry *ent; int err = -ENOMEM; ibm_scan_log_dump = rtas_token("ibm,scan-log-dump"); if (ibm_scan_log_dump == RTAS_UNKNOWN_SERVICE) return -ENODEV; /* Ideally we could allocate a buffer < 4G */ scanlog_buffer = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL); if (!scanlog_buffer) goto err; ent = proc_create("powerpc/rtas/scan-log-dump", S_IRUSR, NULL, &scanlog_fops); if (!ent) goto err; return 0; err: kfree(scanlog_buffer); return err; }
/* Funciones de inicialización y descarga del módulo */ int init_fifoproc_module(void){ int ret; ret = kfifo_alloc(&fifobuff, MAX_ITEMS_FIFO, GFP_KERNEL); if (ret) { printk(KERN_ERR "error al reservar espacio para kfifo\n"); return ret; } sema_init(&mtx, 1); sema_init(&sem_prod, 0); sema_init(&sem_cons, 0); proc_entry = proc_create("modfifo",0666, NULL, &proc_entry_fops); if (proc_entry == NULL) { kfifo_free(&fifobuff); return -ENOMEM; } printk(KERN_INFO "modfifo: Module loaded.\n"); return 0; }
static int TGesture_probe(struct platform_device *pdev) { int err; APS_FUN(); printk("==============TGesture==================\n"); if((err = TGesture_create_attr(&TGesture_driver.driver))) { printk("create attribute err = %d\n", err); return 0; } // Create proc file system tgesture_config_proc = proc_create(TGesture_CONFIG_PROC_FILE, 0666, NULL, &config_proc_ops); if (tgesture_config_proc == NULL) { TGESTURE_DEBUG_FUNC("create_proc_entry %s failed\n", TGesture_CONFIG_PROC_FILE); } else { TGESTURE_DEBUG_FUNC("create proc entry %s success", TGesture_CONFIG_PROC_FILE); } return 0; }
static int __init procfs_test2_init(void) { mm_proc_dir = 0; mm_proc_mem = 0; //create a directory under /proc mm_proc_dir = proc_mkdir("gdl", 0); if (mm_proc_dir == 0) { printk(KERN_ERR "/proc/gdl/ creation failed\n"); return -1; } //create /proc/gdl/memory file mm_proc_mem = proc_create("memory", S_IFREG|S_IRWXU|S_IRWXG|S_IRWXO, mm_proc_dir, &procfs_test2_fops); if (mm_proc_mem == 0) { printk(KERN_ERR "/proc/gdl/memory creation failed\n"); proc_remove(mm_proc_dir); mm_proc_dir = 0; return -1; } return 0; }
int init_clipboard_module( void ) { int ret = 0; clipboard = (char *)vmalloc( BUFFER_LENGTH ); if (!clipboard) { ret = -ENOMEM; } else { memset( clipboard, 0, BUFFER_LENGTH ); proc_entry = proc_create( "clipboard", 0666, NULL, &proc_entry_fops); if (proc_entry == NULL) { ret = -ENOMEM; vfree(clipboard); printk(KERN_INFO "Clipboard: Can't create /proc entry\n"); } else { printk(KERN_INFO "Clipboard: Module loaded\n"); } } return ret; }
int gt1x_init_tool_node(void) { memset(&cmd_head, 0, sizeof(cmd_head)); cmd_head.wr = 1; //if the first operation is read, will return fail. cmd_head.data = kzalloc(DATA_LENGTH_UINT, GFP_KERNEL); if (NULL == cmd_head.data) { GTP_ERROR("Apply for memory failed."); return -1; } GTP_INFO("Applied memory size:%d.", DATA_LENGTH_UINT); DATA_LENGTH = DATA_LENGTH_UINT - GTP_ADDR_LENGTH; set_tool_node_name(procname); gt1x_tool_proc_entry = proc_create(procname, 0666, NULL, >1x_tool_fops); if (gt1x_tool_proc_entry == NULL) { GTP_ERROR("Couldn't create proc entry!"); return -1; } else { GTP_INFO("Create proc entry success!"); } return 0; }
/* * mon_execute executes a user program. It gets the index of a user program * and executes it. */ int mon_execute(int argc, char **argv) { struct Process *proc = NULL; int program_index = 0; bool loaded = false; if (argc < 2) { kprintf("execute requires at least one argument.\n"); return -1; } program_index = argv[1][0] - '0'; proc = proc_create(); loaded = proc_load_program(proc, program_index); if (loaded) schedule(); else { kprintf("couldn't load the process.\n"); } return 0; }
/** * This function is called from kmain, however it is not running in a * thread context yet. It should create the idle process which will * start executing idleproc_run() in a real thread context. To start * executing in the new process's context call context_make_active(), * passing in the appropriate context. This function should _NOT_ * return. * * Note: Don't forget to set curproc and curthr appropriately. * * @param arg1 the first argument (unused) * @param arg2 the second argument (unused) */ static void * bootstrap(int arg1, void *arg2) { /* necessary to finalize page table information */ pt_template_init(); /* PROCS {{{ */ /* Set up our initial process and jump into it */ curproc = proc_create("idle"); KASSERT(NULL != curproc); KASSERT(PID_IDLE == curproc->p_pid); curthr = kthread_create(curproc, idleproc_run, 0, NULL); KASSERT(NULL != curthr); dbg(DBG_INIT, "Starting idle proc\n"); context_make_active(&curthr->kt_ctx); /* PROCS }}} */ panic("weenix returned to bootstrap()!!! BAD!!!\n"); return NULL; }
/** * This function is called from kmain, however it is not running in a * thread context yet. It should create the idle process which will * start executing idleproc_run() in a real thread context. To start * executing in the new process's context call context_make_active(), * passing in the appropriate context. This function should _NOT_ * return. * * Note: Don't forget to set curproc and curthr appropriately. * * @param arg1 the first argument (unused) * @param arg2 the second argument (unused) */ static void * bootstrap(int arg1, void *arg2) { dbg(DBG_CORE, "bootstrapping\n"); /* necessary to finalize page table information */ pt_template_init(); /* Create a process with pid 0 */ proc_t *p = proc_create("process 0"); kthread_t *kt = kthread_create(p, idleproc_run, arg1, arg2); KASSERT(p && (p->p_pid == 0)); KASSERT(kt); curproc = p; curthr = kt; context_make_active(&kt->kt_ctx); panic("weenix returned to bootstrap()!!! BAD!!!\n"); return NULL; }
static __init int example_init(void) { int result; /* * Register your major, and accept a dynamic number */ result = register_chrdev(example_major, "example", &example_fops); if (result < 0) { printk(KERN_WARNING "example: can't get major %d\n",example_major); return result; } if (example_major == 0) example_major = result; /* dynamic */ printk("<1> example device driver version 4: loaded at major number %d\n", example_major); example_device_stats = (example_stats *) kmalloc(sizeof(example_stats),GFP_KERNEL); if (!example_device_stats) { result = -ENOMEM; goto fail_malloc; } init_example_device_stats(); /* We assume that the /proc/driver exists. Otherwise we need to use proc_mkdir to * create it as follows: proc_mkdir("driver", NULL); */ example_proc_file = proc_create("driver/example", 0, NULL, &example_proc_fops); if (!example_proc_file) { result = -ENOMEM; goto fail_malloc; } return 0; fail_malloc: unregister_chrdev(example_major, "example"); return result; }
static int __init mtktspa_init(void) { int err = 0; struct proc_dir_entry *entry = NULL; struct proc_dir_entry *mtktspa_dir = NULL; mtktspa_dprintk("[%s]\n", __func__); err = mtktspa_register_cooler(); if (err) return err; err = mtktspa_register_thermal(); if (err) goto err_unreg; mtktspa_dir = mtk_thermal_get_proc_drv_therm_dir_entry(); if (!mtktspa_dir) { mtktspa_dprintk("[%s]: mkdir /proc/driver/thermal failed\n", __func__); } else { entry = proc_create("tzpa", S_IRUGO | S_IWUSR | S_IWGRP, mtktspa_dir, &mtktspa_fops); if (entry) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0) proc_set_user(entry, 0, 1000); #else entry->gid = 1000; #endif } } return 0; err_unreg: mtktspa_unregister_cooler(); return err; }
static int __init ppm_thermal_policy_init(void) { int i, ret = 0; struct pentry { const char *name; const struct file_operations *fops; }; const struct pentry entries[] = { PROC_ENTRY(thermal_limit), }; FUNC_ENTER(FUNC_LV_POLICY); /* create procfs */ for (i = 0; i < ARRAY_SIZE(entries); i++) { if (!proc_create(entries[i].name, S_IRUGO | S_IWUSR | S_IWGRP, policy_dir, entries[i].fops)) { ppm_err("%s(), create /proc/ppm/policy/%s failed\n", __func__, entries[i].name); ret = -EINVAL; goto out; } } if (ppm_main_register_policy(&thermal_policy)) { ppm_err("@%s: thermal policy register failed\n", __func__); ret = -EINVAL; goto out; } ppm_info("@%s: register %s done!\n", __func__, thermal_policy.name); out: FUNC_EXIT(FUNC_LV_POLICY); return ret; }
/************************************************************************ * Name: fts_create_apk_debug_channel * Brief: create apk debug channel * Input: i2c info * Output: no * Return: success =0 ***********************************************************************/ int fts_create_apk_debug_channel(struct i2c_client * client) { #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)) fts_proc_entry = proc_create(PROC_NAME, 0777, NULL, &fts_proc_fops); #else fts_proc_entry = create_proc_entry(PROC_NAME, 0777, NULL); #endif if (NULL == fts_proc_entry) { dev_err(&client->dev, "Couldn't create proc entry!\n"); return -ENOMEM; } else { dev_info(&client->dev, "Create proc entry success!\n"); #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)) fts_proc_entry->write_proc = fts_debug_write; fts_proc_entry->read_proc = fts_debug_read; #endif } return 0; }
/** * This function is called from kmain, however it is not running in a * thread context yet. It should create the idle process which will * start executing idleproc_run() in a real thread context. To start * executing in the new process's context call context_make_active(), * passing in the appropriate context. This function should _NOT_ * return. * * Note: Don't forget to set curproc and curthr appropriately. * * @param arg1 the first argument (unused) * @param arg2 the second argument (unused) */ static void * bootstrap(int arg1, void *arg2) { /* necessary to finalize page table information */ dbg(DBG_PROC, "Function: bootstrap\n"); pt_template_init(); /*NOT_YET_IMPLEMENTED("PROCS: bootstrap");*/ proc_t *p_idle=proc_create("Idle procss"); curproc=p_idle; KASSERT(NULL != curproc); dbg(DBG_PRINT,"GRADING1A 1.a-1\n"); KASSERT(PID_IDLE == curproc->p_pid); dbg(DBG_PRINT,"GRADING1A 1.a-2\n"); kthread_t *thr_idle=kthread_create(p_idle,idleproc_run,0,NULL); curthr=thr_idle; KASSERT(NULL != curthr); dbg(DBG_PRINT,"GRADING1A 1.a-3\n"); context_make_active(&curthr->kt_ctx); /*panic("weenix returned to bootstrap()!!! BAD!!!\n");*/ return NULL; }
int proc_file_create (void) { int ii = 0; char device_name[LOCAL_BUF_SZ + 1]; do { proc_dir = proc_mkdir("CDD", 0); for (ii = 0; ii < CDDNUMDEVS; ii++) { snprintf(device_name, LOCAL_BUF_SZ, "CDD%d", buf_type[ii]); proc_stats[ii] = proc_create(device_name, 0777, proc_dir, &proc_fops[ii]); } display_buffer.buf = vmalloc ((BUF_SZ + 1) * sizeof (char)); if (display_buffer.buf == NULL) { printk(KERN_ALERT "Cannot allocate memory !!!"); break; } else { display_buffer.size = BUF_SZ; } } while (0); return 0; }
static int __init mydrv_init(void) { int i; /* entry = create_proc_entry("readme", S_IRUSR, NULL); if (entry) { entry->proc_fops = &mydrv_proc_fops; } else { return -EINVAL; } */ entry = proc_create("readme", S_IRUSR, NULL, &mydrv_proc_fops); printk("we are in init function of the module\n"); //2 return 0; }
int __init au_procfs_init(void) { int err; struct proc_dir_entry *entry; err = -ENOMEM; au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL); if (unlikely(!au_procfs_dir)) goto out; entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR, au_procfs_dir, &au_procfs_plm_fop); if (unlikely(!entry)) goto out_dir; err = 0; goto out; /* success */ out_dir: remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); out: return err; }
int sys_fork(struct trapframe *tf, pid_t *retval) { int result; char* name; (void) result; (void) tf; (void) retval; struct trapframe *temp_tf = kmalloc(sizeof(*temp_tf)); *temp_tf = *tf; struct proc *newproc = proc_create("forked_process"); // TODO: concurrency issue? as_copy(curproc->p_addrspace, &newproc->p_addrspace); newproc->p_filetable = kmalloc(sizeof(struct filetable)); newproc->p_filetable->filetable_lock = lock_create("filetable_lock"); filetable_copy(newproc->p_filetable); // copied from proc.c init p_cwd spinlock_acquire(&curproc->p_lock); if (curproc->p_cwd != NULL) { VOP_INCREF(curproc->p_cwd); newproc->p_cwd = curproc->p_cwd; } spinlock_release(&curproc->p_lock); newproc->parent_pid = curproc->pid; name = kstrdup(curproc->p_name); *retval = newproc->pid; thread_fork(name, newproc ,run_forked_proc, (void *)temp_tf, 0); return 0; }
static int __init ram_console_late_init(void) { struct proc_dir_entry *entry; #ifdef CONFIG_MTK_EMMC_SUPPORT #ifdef CONFIG_MTK_AEE_IPANIC int err; static struct task_struct *thread; thread = kthread_run(emmc_read_last_kmsg, 0, "read_poweroff_log"); if (IS_ERR(thread)) { err = PTR_ERR(thread); pr_err("ram_console: failed to create kernel thread: %d\n", err); } #endif #endif entry = proc_create("last_kmsg", 0444, NULL, &ram_console_file_ops); if (!entry) { pr_err("ram_console: failed to create proc entry\n"); kfree(ram_console_old); ram_console_old = NULL; return 0; } return 0; }
static int __init init_mod(void){ int ret=0; root=NULL; proc_entry=proc_create("my_test",0,NULL,&proc_fops); if(proc_entry ==NULL){ ret=-ENOMEM; printk("Could not create the proc file\n"); } else{ printk("Module loaded successfully\n"); } ret=register_security(&rbac_ops); if(ret){ printk("Cannot register the security\n"); }else{ printk("Farhan security module : registered\n"); } return ret; }
static int __init ikconfig_init(void) { struct proc_dir_entry *entry; // our 'GetProcAddress' :D kallsyms_lookup_name_dx = (void*) OFS_KALLSYMS_LOOKUP_NAME; // get original kernel_config_data kernel_config_data_dx = (void*) kallsyms_lookup_name_dx("kernel_config_data"); printk("axperiau_config: v001. module loaded. Build target: " DEVICE_NAME); printk("axperiau_config: config.gz start at %X,size %d", (int) kernel_config_data_dx, kernel_config_data_size); /* create the current config file */ entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL, &ikconfig_file_ops); if (!entry) return -ENOMEM; printk("axperiau_config: procfs entry created at /proc/config.gz"); entry->size = kernel_config_data_size; return 0; }
static int __init sec_bsp_init(void) { struct proc_dir_entry *entry; entry = proc_create("boot_stat",S_IRUGO, NULL, &sec_boot_stat_proc_fops); if (!entry) return -ENOMEM; // boot_events[SYSTEM_START_LK].time = bootloader_start; // boot_events[SYSTEM_LK_LOGO_DISPLAY].time = bootloader_display; // boot_events[SYSTEM_END_LK].time = bootloader_end; // sec_class = class_create(THIS_MODULE, "sec"); sec_bsp_dev = sec_device_create(NULL, "bsp"); BUG_ON(!sec_bsp_dev); if (IS_ERR(sec_bsp_dev)) pr_err("%s:Failed to create devce\n",__func__); if (device_create_file(sec_bsp_dev, &dev_attr_boot_stat) < 0) pr_err("%s: Failed to create device file\n",__func__); return 0; }
static int __init otracer_init(void) { int ret; ret = misc_register(&otracer_misc); if (unlikely(ret)) { printk(KERN_ERR "otracer: failed to register misc device!\n"); return ret; } /* Set up the proc file system */ otrace_entry = proc_create("otrace_on", 0666, NULL, &otrace_proc_fops); if (!otrace_entry) { ret = -ENOMEM; goto out_misc; } printk(KERN_INFO "otracer: initialized\n"); return 0; out_misc: misc_deregister(&otracer_misc); return ret; }
static int __init bcm_fuse_net_init_module(void) { unsigned int i = 0; BNET_DEBUG(DBG_INFO,"%s: << \n", __FUNCTION__); spin_lock_init(&g_dev_lock); for (i = 0; i < BCM_NET_MAX_PDP_CNTXS; i++) { memset(&g_net_dev_tbl[i], 0, sizeof(net_drvr_info_t)); } for (i = 0; i < BCM_NET_MAX_PDP_CNTXS; i++) { bcm_fuse_net_attach(i); } bcm_fuse_net_last_tx = bcm_fuse_net_last_rx = jiffies; pentry_brcm_fuse_net_silence = proc_create("brcm_fuse_net_silence", 0666, NULL, &brcm_fuse_net_silence_ops); return(0); }
static int __init secwidevine_init(void) { #if 0 struct proc_dir_entry *secwidevine_proc; secwidevine_proc = create_proc_entry("secwidevine0", (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH), NULL); if (IS_ERR(secwidevine_proc)) { goto error; } secwidevine_proc->proc_fops = &secwidevine_fops; #else proc_create("secwidevine0", (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH), NULL, &secwidevine_fops); #endif return 0; #if 0 error: return -1; #endif }