void __init proc_root_init(void) { int err; proc_init_inodecache(); err = register_filesystem(&proc_fs_type); if (err) return; proc_mnt = kern_mount_data(&proc_fs_type, &init_pid_ns); if (IS_ERR(proc_mnt)) { unregister_filesystem(&proc_fs_type); return; } proc_symlink("mounts", NULL, "self/mounts"); proc_net_init(); #ifdef CONFIG_SYSVIPC proc_mkdir("sysvipc", NULL); #endif proc_mkdir("fs", NULL); proc_mkdir("driver", NULL); proc_mkdir("fs/nfsd", NULL); /* somewhere for the nfsd filesystem to be mounted */ #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE) /* just give it a mountpoint */ proc_mkdir("openprom", NULL); #endif proc_tty_init(); #ifdef CONFIG_PROC_DEVICETREE proc_device_tree_init(); #endif proc_mkdir("bus", NULL); proc_sys_init(); }
void __init proc_root_init(void) { int err; proc_init_inodecache(); err = register_filesystem(&proc_fs_type); if (err) return; proc_self_init(); proc_symlink("mounts", NULL, "self/mounts"); proc_net_init(); #ifdef CONFIG_SYSVIPC proc_mkdir("sysvipc", NULL); #endif proc_mkdir("fs", NULL); proc_mkdir("driver", NULL); proc_mkdir("fs/nfsd", NULL); /* somewhere for the nfsd filesystem to be mounted */ #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE) /* just give it a mountpoint */ proc_mkdir("openprom", NULL); #endif proc_tty_init(); proc_mkdir("bus", NULL); proc_sys_init(); }
void __init proc_root_init(void) { int err; proc_init_inodecache(); err = register_filesystem(&proc_fs_type); if (err) return; proc_self_init(); #ifdef CONFIG_DEFERRED_INITCALLS proc_create("deferred_initcalls", 0, NULL, &deferred_initcalls_fops); #endif proc_symlink("mounts", NULL, "self/mounts"); proc_net_init(); #ifdef CONFIG_SYSVIPC proc_mkdir("sysvipc", NULL); #endif proc_mkdir("fs", NULL); proc_mkdir("driver", NULL); proc_mkdir("fs/nfsd", NULL); /* somewhere for the nfsd filesystem to be mounted */ #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE) /* just give it a mountpoint */ proc_mkdir("openprom", NULL); #endif proc_tty_init(); #ifdef CONFIG_PROC_DEVICETREE proc_device_tree_init(); #endif proc_mkdir("bus", NULL); proc_sys_init(); }
int __init hello_init(void) { struct proc_dir_entry *dir; dir = proc_symlink("link", NULL, "/no"); if (!dir) return -1; printk(KERN_ALERT "init ok\n"); return 0; }
static int power_sysfs_make_path(void) { int arr_num, group_num; struct proc_dir_entry *p, *temp_p; struct proc_dir_entry *groups_p[PWR_SYSFS_GROUPS_NUM]; /* Set Power Sysfs root directory */ p = proc_mkdir("lge_power", NULL); if (p == NULL) { pr_err("%s : ERROR make root sysfs \n", __func__); return -ENOMEM; } /* Set Power Sysfs group directory */ if (groups_p != NULL) { for (group_num = 0; group_num < PWR_SYSFS_GROUPS_NUM; group_num++) { groups_p[group_num] = proc_mkdir(group_names[group_num], p); if (groups_p[group_num] == NULL) { pr_err("%s : ERROR make %s group \n", __func__, group_names[group_num]); return -ENOMEM; } } } else { pr_err("%s : ERROR make groups pointer \n", __func__); return -ENOMEM; } /* Set Power Sysfs Path */ for (arr_num = 0; arr_num < arr_cnt; arr_num++) { for (group_num = 0; group_num < PWR_SYSFS_GROUPS_NUM; group_num++) if (!strcmp(arr[arr_num].group, group_names[group_num])) break; if (!strcmp(arr[arr_num].kernel_node, "NULL")) { pr_info("%s : %s user node didn't have kernel node \n", __func__, arr[arr_num].user_node); continue; } else { temp_p = proc_symlink(arr[arr_num].user_node, groups_p[group_num], arr[arr_num].kernel_node); if (temp_p == NULL) { pr_err("%s : ERROR make %ith sysfs path(%s, %s, %s)\n", __func__, arr_num, arr[arr_num].group, arr[arr_num].kernel_node, arr[arr_num].user_node); return -ENOMEM; } } } return 0; }
/* * register the card proc file * called from init.c */ int snd_info_card_register(struct snd_card *card) { struct proc_dir_entry *p; snd_assert(card != NULL, return -ENXIO); if (!strcmp(card->id, card->proc_root->name)) return 0; p = proc_symlink(card->id, snd_proc_root, card->proc_root->name); if (p == NULL) return -ENOMEM; card->proc_root_link = p; return 0; }
/* * Create the ppc64 and ppc64/rtas directories early. This allows us to * assume that they have been previously created in drivers. */ static int __init proc_ppc64_create(void) { struct proc_dir_entry *root; root = proc_mkdir("powerpc", NULL); if (!root) return 1; #ifdef CONFIG_PPC64 if (!proc_symlink("ppc64", NULL, "powerpc")) pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n"); #endif if (!of_find_node_by_path("/rtas")) return 0; if (!proc_mkdir("rtas", root)) return 1; if (!proc_symlink("rtas", NULL, "powerpc/rtas")) return 1; return 0; }
static int __init rk_last_log_init(void) { size_t early_log_size; char *buf; struct proc_dir_entry *entry; if (!cpu_is_rockchip()) return 0; buf = (char *)__get_free_pages(GFP_KERNEL, LOG_BUF_PAGE_ORDER); if (!buf) { pr_err("failed to __get_free_pages(%d)\n", LOG_BUF_PAGE_ORDER); return 0; } log_buf = last_log_vmap(virt_to_phys(buf), 1 << LOG_BUF_PAGE_ORDER); if (!log_buf) { pr_err("failed to map %d pages at 0x%08x\n", 1 << LOG_BUF_PAGE_ORDER, virt_to_phys(buf)); return 0; } last_log_buf = (char *)vmalloc(LOG_BUF_LEN); if (!last_log_buf) { pr_err("failed to vmalloc(%d)\n", LOG_BUF_LEN); return 0; } memcpy(last_log_buf, buf, LOG_BUF_LEN); early_log_size = log_pos > sizeof(early_log_buf) ? sizeof(early_log_buf) : log_pos; memcpy(log_buf, early_log_buf, early_log_size); memset(log_buf + early_log_size, 0, LOG_BUF_LEN - early_log_size); pr_info("0x%08x map to 0x%p and copy to 0x%p, size 0x%x early 0x%x (version 3.0)\n", virt_to_phys(buf), log_buf, last_log_buf, LOG_BUF_LEN, early_log_size); entry = proc_create("last_kmsg", S_IRUSR, NULL, &last_log_fops); if (!entry) { pr_err("failed to create proc entry\n"); return 0; } proc_set_size(entry, LOG_BUF_LEN); proc_symlink("last_log", NULL, "last_kmsg"); return 0; }
static int seqfile_example_init(void) { pde_dir = proc_mkdir("seqfile_dir", NULL); if (!pde_dir) goto out_dir; pde_symlink = proc_symlink("seqfile_link", NULL, "seqfile_dir/counter"); if (!pde_symlink) goto out_symlink; pde_file = proc_create("counter", 0444, pde_dir, &ct_file_ops); if (!pde_file) goto out_file; return 0; out_file: proc_remove(pde_symlink); out_symlink: proc_remove(pde_dir); out_dir: return -ENOMEM; }
/* * Create the ppc64 and ppc64/rtas directories early. This allows us to * assume that they have been previously created in drivers. */ static int __init proc_ppc64_create(void) { struct proc_dir_entry *root; root = proc_mkdir("ppc64", NULL); if (!root) return 1; if (!of_find_node_by_path("/rtas")) return 0; if (!proc_mkdir("rtas", root)) return 1; if (!proc_symlink("rtas", NULL, "ppc64/rtas")) return 1; return 0; }
/* * Create the ppc64 and ppc64/rtas directories early. This allows us to * assume that they have been previously created in drivers. */ static int __init proc_ppc64_create(void) { struct proc_dir_entry *root; root = proc_mkdir("ppc64", NULL); if (!root) return 1; if (!(systemcfg->platform & PLATFORM_PSERIES)) return 0; if (!proc_mkdir("rtas", root)) return 1; if (!proc_symlink("rtas", NULL, "ppc64/rtas")) return 1; return 0; }
void ide_proc_port_register_devices(ide_hwif_t *hwif) { struct proc_dir_entry *ent; struct proc_dir_entry *parent = hwif->proc; ide_drive_t *drive; char name[64]; int i; ide_port_for_each_dev(i, drive, hwif) { if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc) continue; drive->proc = proc_mkdir(drive->name, parent); if (drive->proc) ide_add_proc_entries(drive->proc, generic_drive_entries, drive); sprintf(name, "ide%d/%s", (drive->name[2]-'a')/2, drive->name); ent = proc_symlink(drive->name, proc_ide_root, name); if (!ent) return; } }
void ide_proc_port_register_devices(ide_hwif_t *hwif) { int d; struct proc_dir_entry *ent; struct proc_dir_entry *parent = hwif->proc; char name[64]; for (d = 0; d < MAX_DRIVES; d++) { ide_drive_t *drive = &hwif->drives[d]; if (!drive->present) continue; if (drive->proc) continue; drive->proc = proc_mkdir(drive->name, parent); if (drive->proc) ide_add_proc_entries(drive->proc, generic_drive_entries, drive); sprintf(name, "ide%d/%s", (drive->name[2]-'a')/2, drive->name); ent = proc_symlink(drive->name, proc_ide_root, name); if (!ent) return; } }
int ipsec_proc_init(void) { int error = 0; struct proc_dir_entry *item; struct ipsec_proc_list *it; /* create /proc/net/ipsec */ proc_net_ipsec_dir = proc_mkdir("ipsec", PROC_NET); if (proc_net_ipsec_dir == NULL) { /* no point in continuing */ return 1; } for (it = proc_items; it->name; it++) { if (it->dir) { item = proc_mkdir(it->name, *it->parent); *it->dir = item; } else item = proc_create_data(it->name, it->mode, *it->parent, &ipsec_proc_fops, it); if (!item) error |= 1; } /* now create some symlinks to provide compatibility */ proc_symlink("ipsec_eroute", PROC_NET, "ipsec/eroute/all"); proc_symlink("ipsec_spi", PROC_NET, "ipsec/spi/all"); proc_symlink("ipsec_spigrp", PROC_NET, "ipsec/spigrp/all"); #ifdef IPSEC_SA_RECOUNT_DEBUG proc_symlink("ipsec_saraw", PROC_NET, "ipsec/saraw/all"); #endif proc_symlink("ipsec_tncfg", PROC_NET, "ipsec/tncfg"); proc_symlink("ipsec_version", PROC_NET, "ipsec/version"); proc_symlink("ipsec_klipsdebug", PROC_NET, "ipsec/klipsdebug"); return error; }
/* ---------------------------------------------------------------- */ static int ibuddy_probe( struct usb_interface* interface, const struct usb_device_id* id ) { struct usb_device* udev = interface_to_usbdev(interface); struct ibuddy_dev* mydev = NULL; int pos; int retval = -ENOMEM; PRINT("probe\n"); /* we only attach to 1st interface */ if( interface->cur_altsetting->desc.bInterfaceNumber != 1 ) { ERROR("ignored interface\n"); return -ENXIO; } /* find out our enumeration 0-9 */ for( pos = 0; pos < 10; pos++ ) { if( ibuddy_enumeration[pos] == 0 ) { ibuddy_enumeration[pos] = 1; break; } } if( pos == 10 ) { ERROR( "more than 10 devices not supported\n" ); return -ENOSPC; } mydev = kzalloc(sizeof(struct ibuddy_dev), GFP_KERNEL); if (mydev == NULL) { ERROR( "out of memory\n" ); return retval; } mydev->num = pos; /* usb_get_dev - increments the reference count of the usb device structure*/ mydev->udev = usb_get_dev( udev ); /* extra info from usb core probe */ mydev->type = id->driver_info; /* save the kobj location */ mydev->kobj = &interface->dev.kobj; /* save our data to interface */ usb_set_intfdata(interface, mydev); mydev->procname = NULL; #ifdef CONFIG_PROC_FS { /* create symlink from /proc/driver to sysfs entry e.g. /proc/driver/ibuddy/0 -> /sys/... */ struct kobject* k = mydev->kobj; char** path_parts = NULL; char* path = NULL; int idx = 0; char* from; /* FIXME: magic constant */ path_parts = kzalloc( 40*sizeof(char*), GFP_KERNEL ); if( path_parts == NULL ) { ERROR( "out of memory\n" ); return retval; } while( k->parent != NULL ) { path_parts[idx++] = (char*)k->name; // const char* -> char* // PRINT( "%s\n", k->name ); // DEBUG k = k->parent; if( idx >= 39 ) { ERROR( "kobj name nesting too deep\n" ); break; } } path = kzalloc( 40*16, GFP_KERNEL ); /* FIXME: magic constants */ if( path == NULL ) { ERROR( "out of memory\n" ); return retval; } strcat( path, "/sys/devices/" ); while( idx > 0 ) { strcat( path, path_parts[idx-1] ); strcat( path, "/" ); idx--; } kfree( path_parts ); /* when path is ready the parts no longer needed */ from = kzalloc( 20*sizeof(char), GFP_KERNEL ); if( from == NULL ) { ERROR( "out of memory\n" ); return retval; } strcat( from, "driver/ibuddy/X" ); from[14] = '0' + mydev->num; mydev->procname = from; if( proc_symlink( from, NULL, path ) ) { PRINT( "created /proc/%s -> %s\n", from, path ); } kfree( path ); } #endif /* create attributes for the device in the sysfs */ ibuddy_attr_init( interface ); /* set initial values */ mydev->raw = IBUDDY_INITIAL_VALUE; ibuddy_cmd( mydev, mydev->raw ); dev_info( &interface->dev, DRIVER_NAME " USB driver attached\n" ); /* increment module use count */ if( !try_module_get(THIS_MODULE) ) ERROR( "try_module_get failed!\n" ); return 0; } /* ibuddy_probe() */
static int __init init_procfs_example(void) { int rv = 0; /* create directory */ example_dir = proc_mkdir(MODULE_NAME, NULL); if(example_dir == NULL) { rv = -ENOMEM; goto out; } /* create jiffies using convenience function */ jiffies_file = create_proc_read_entry("jiffies", 0444, example_dir, proc_read_jiffies, NULL); if(jiffies_file == NULL) { rv = -ENOMEM; goto no_jiffies; } /* create foo and bar files using same callback * functions */ foo_file = create_proc_entry("foo", 0644, example_dir); if(foo_file == NULL) { rv = -ENOMEM; goto no_foo; } strcpy(foo_data.name, "foo"); strcpy(foo_data.value, "foo"); foo_file->data = &foo_data; foo_file->read_proc = proc_read_foobar; foo_file->write_proc = proc_write_foobar; bar_file = create_proc_entry("bar", 0644, example_dir); if(bar_file == NULL) { rv = -ENOMEM; goto no_bar; } strcpy(bar_data.name, "bar"); strcpy(bar_data.value, "bar"); bar_file->data = &bar_data; bar_file->read_proc = proc_read_foobar; bar_file->write_proc = proc_write_foobar; /* create symlink */ symlink = proc_symlink("jiffies_too", example_dir, "jiffies"); if(symlink == NULL) { rv = -ENOMEM; goto no_symlink; } /* everything OK */ printk(KERN_INFO "%s %s initialised\n", MODULE_NAME, MODULE_VERS); return 0; no_symlink: remove_proc_entry("bar", example_dir); no_bar: remove_proc_entry("foo", example_dir); no_foo: remove_proc_entry("jiffies", example_dir); no_jiffies: remove_proc_entry(MODULE_NAME, NULL); out: return rv; }
int __init proc_net_init(void) { proc_symlink("net", NULL, "self/net"); return register_pernet_subsys(&proc_net_ns_ops); }
void __init proc_misc_init(void) { struct proc_dir_entry *entry; static struct { char *name; int (*read_proc)(char*,char**,off_t,int,int*,void*); } *p, simple_ones[] = { {"loadavg", loadavg_read_proc}, {"uptime", uptime_read_proc}, {"meminfo", meminfo_read_proc}, {"version", version_read_proc}, #ifdef CONFIG_PROC_HARDWARE {"hardware", hardware_read_proc}, #endif #ifdef CONFIG_STRAM_PROC {"stram", stram_read_proc}, #endif {"devices", devices_read_proc}, {"filesystems", filesystems_read_proc}, {"cmdline", cmdline_read_proc}, {"locks", locks_read_proc}, {"execdomains", execdomains_read_proc}, {NULL,} }; for (p = simple_ones; p->name; p++) create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL); proc_symlink("mounts", NULL, "self/mounts"); /* And now for trickier ones */ entry = create_proc_entry("kmsg", S_IRUSR, &proc_root); if (entry) entry->proc_fops = &proc_kmsg_operations; create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations); create_seq_entry("partitions", 0, &proc_partitions_operations); create_seq_entry("stat", 0, &proc_stat_operations); create_seq_entry("interrupts", 0, &proc_interrupts_operations); create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations); create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations); create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations); create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations); create_seq_entry("diskstats", 0, &proc_diskstats_operations); #ifdef CONFIG_MODULES create_seq_entry("modules", 0, &proc_modules_operations); #endif #ifdef CONFIG_SCHEDSTATS create_seq_entry("schedstat", 0, &proc_schedstat_operations); #endif #ifdef CONFIG_PROC_KCORE proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL); if (proc_root_kcore) { proc_root_kcore->proc_fops = &proc_kcore_operations; proc_root_kcore->size = (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; } #endif #ifdef CONFIG_PROC_VMCORE proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL); if (proc_vmcore) proc_vmcore->proc_fops = &proc_vmcore_operations; #endif #ifdef CONFIG_MAGIC_SYSRQ entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL); if (entry) entry->proc_fops = &proc_sysrq_trigger_operations; #endif #ifdef CONFIG_PPC32 { extern struct file_operations ppc_htab_operations; entry = create_proc_entry("ppc_htab", S_IRUGO|S_IWUSR, NULL); if (entry) entry->proc_fops = &ppc_htab_operations; } #endif }
/* * Process a node, adding entries for its children and its properties. */ static void add_node(struct device_node *np, struct proc_dir_entry *de) { struct property *pp; struct proc_dir_entry *ent; struct device_node *child, *sib; const char *p, *at; int l; struct proc_dir_entry *list, **lastp, *al; lastp = &list; for (pp = np->properties; pp != 0; pp = pp->next) { /* * Unfortunately proc_register puts each new entry * at the beginning of the list. So we rearrange them. */ ent = create_proc_read_entry(pp->name, strncmp(pp->name, "security-", 9) ? S_IRUGO : S_IRUSR, de, property_read_proc, pp); if (ent == 0) break; if (!strncmp(pp->name, "security-", 9)) ent->size = 0; /* don't leak number of password chars */ else ent->size = pp->length; *lastp = ent; lastp = &ent->next; } for (child = np->child; child != 0; child = child->sibling) { p = strrchr(child->full_name, '/'); if (p == 0) p = child->full_name; else ++p; /* chop off '@0' if the name ends with that */ l = strlen(p); if (l > 2 && p[l-2] == '@' && p[l-1] == '0') l -= 2; ent = proc_mkdir(p, de); if (ent == 0) break; *lastp = ent; lastp = &ent->next; add_node(child, ent); /* * If we left the address part on the name, consider * adding symlinks from the name and address parts. */ if (p[l] != 0 || (at = strchr(p, '@')) == 0) continue; /* * If this is the first node with a given name property, * add a symlink with the name property as its name. */ for (sib = np->child; sib != child; sib = sib->sibling) if (sib->name && strcmp(sib->name, child->name) == 0) break; if (sib == child && strncmp(p, child->name, l) != 0) { al = proc_symlink(child->name, de, ent->name); if (al == 0) break; *lastp = al; lastp = &al->next; } /* * Add another directory with the @address part as its name. */ al = proc_symlink(at, de, ent->name); if (al == 0) break; *lastp = al; lastp = &al->next; } *lastp = 0; de->subdir = list; }
void __init proc_misc_init(void) { struct proc_dir_entry *entry; static struct { char *name; int (*read_proc)(char*,char**,off_t,int,int*,void*); } *p, simple_ones[] = { {"loadavg", loadavg_read_proc}, {"uptime", uptime_read_proc}, {"meminfo", meminfo_read_proc}, {"version", version_read_proc}, #ifdef CONFIG_PROC_HARDWARE {"hardware", hardware_read_proc}, #endif #ifdef CONFIG_STRAM_PROC {"stram", stram_read_proc}, #endif #ifdef CONFIG_MODULES {"modules", modules_read_proc}, #endif {"stat", kstat_read_proc}, {"devices", devices_read_proc}, #if !defined(CONFIG_ARCH_S390) {"interrupts", interrupts_read_proc}, #endif {"filesystems", filesystems_read_proc}, {"dma", dma_read_proc}, {"ioports", ioports_read_proc}, {"cmdline", cmdline_read_proc}, #ifdef CONFIG_SGI_DS1286 {"rtc", ds1286_read_proc}, #endif {"locks", locks_read_proc}, {"swaps", swaps_read_proc}, {"iomem", memory_read_proc}, {"execdomains", execdomains_read_proc}, {NULL,} }; for (p = simple_ones; p->name; p++) create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL); proc_symlink("mounts", NULL, "self/mounts"); /* And now for trickier ones */ entry = create_proc_entry("kmsg", S_IRUSR, &proc_root); if (entry) entry->proc_fops = &proc_kmsg_operations; create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations); create_seq_entry("partitions", 0, &proc_partitions_operations); create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations); #ifdef CONFIG_MODULES create_seq_entry("ksyms", 0, &proc_ksyms_operations); #endif proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL); if (proc_root_kcore) { proc_root_kcore->proc_fops = &proc_kcore_operations; proc_root_kcore->size = (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE; } if (prof_shift) { entry = create_proc_entry("profile", S_IWUSR | S_IRUGO, NULL); if (entry) { entry->proc_fops = &proc_profile_operations; entry->size = (1+prof_len) * sizeof(unsigned int); } } #ifdef CONFIG_MAGIC_SYSRQ entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL); if (entry) entry->proc_fops = &proc_sysrq_trigger_operations; #endif #ifdef CONFIG_PPC32 { extern struct file_operations ppc_htab_operations; entry = create_proc_entry("ppc_htab", S_IRUGO|S_IWUSR, NULL); if (entry) entry->proc_fops = &ppc_htab_operations; } #endif }