srm_env.c (c35f2e49f88e72ffcb0cc6af2f93fe153fa88dd8) | srm_env.c (1c1ec6c6255cce0fa48391e36b419cf951800b50) |
---|---|
1/* 2 * srm_env.c - Access to SRM environment 3 * variables through linux' procfs 4 * 5 * (C) 2001,2002,2006 by Jan-Benedict Glaw <jbglaw@lug-owl.de> 6 * 7 * This driver is a modified version of Erik Mouw's example proc 8 * interface, so: thank you, Erik! He can be reached via email at --- 42 unchanged lines hidden (view full) --- 51typedef struct _srm_env { 52 char *name; 53 unsigned long id; 54} srm_env_t; 55 56static struct proc_dir_entry *base_dir; 57static struct proc_dir_entry *named_dir; 58static struct proc_dir_entry *numbered_dir; | 1/* 2 * srm_env.c - Access to SRM environment 3 * variables through linux' procfs 4 * 5 * (C) 2001,2002,2006 by Jan-Benedict Glaw <jbglaw@lug-owl.de> 6 * 7 * This driver is a modified version of Erik Mouw's example proc 8 * interface, so: thank you, Erik! He can be reached via email at --- 42 unchanged lines hidden (view full) --- 51typedef struct _srm_env { 52 char *name; 53 unsigned long id; 54} srm_env_t; 55 56static struct proc_dir_entry *base_dir; 57static struct proc_dir_entry *named_dir; 58static struct proc_dir_entry *numbered_dir; |
59static char number[256][4]; | |
60 61static srm_env_t srm_named_entries[] = { 62 { "auto_action", ENV_AUTO_ACTION }, 63 { "boot_dev", ENV_BOOT_DEV }, 64 { "bootdef_dev", ENV_BOOTDEF_DEV }, 65 { "booted_dev", ENV_BOOTED_DEV }, 66 { "boot_file", ENV_BOOT_FILE }, 67 { "booted_file", ENV_BOOTED_FILE }, 68 { "boot_osflags", ENV_BOOT_OSFLAGS }, 69 { "booted_osflags", ENV_BOOTED_OSFLAGS }, 70 { "boot_reset", ENV_BOOT_RESET }, 71 { "dump_dev", ENV_DUMP_DEV }, 72 { "enable_audit", ENV_ENABLE_AUDIT }, 73 { "license", ENV_LICENSE }, 74 { "char_set", ENV_CHAR_SET }, 75 { "language", ENV_LANGUAGE }, 76 { "tty_dev", ENV_TTY_DEV }, 77 { NULL, 0 }, 78}; | 59 60static srm_env_t srm_named_entries[] = { 61 { "auto_action", ENV_AUTO_ACTION }, 62 { "boot_dev", ENV_BOOT_DEV }, 63 { "bootdef_dev", ENV_BOOTDEF_DEV }, 64 { "booted_dev", ENV_BOOTED_DEV }, 65 { "boot_file", ENV_BOOT_FILE }, 66 { "booted_file", ENV_BOOTED_FILE }, 67 { "boot_osflags", ENV_BOOT_OSFLAGS }, 68 { "booted_osflags", ENV_BOOTED_OSFLAGS }, 69 { "boot_reset", ENV_BOOT_RESET }, 70 { "dump_dev", ENV_DUMP_DEV }, 71 { "enable_audit", ENV_ENABLE_AUDIT }, 72 { "license", ENV_LICENSE }, 73 { "char_set", ENV_CHAR_SET }, 74 { "language", ENV_LANGUAGE }, 75 { "tty_dev", ENV_TTY_DEV }, 76 { NULL, 0 }, 77}; |
79static srm_env_t srm_numbered_entries[256]; | |
80 | 78 |
81 | |
82static int srm_env_proc_show(struct seq_file *m, void *v) 83{ 84 unsigned long ret; | 79static int srm_env_proc_show(struct seq_file *m, void *v) 80{ 81 unsigned long ret; |
85 srm_env_t *entry; | 82 unsigned long id = (unsigned long)m->private; |
86 char *page; 87 | 83 char *page; 84 |
88 entry = m->private; | |
89 page = (char *)__get_free_page(GFP_USER); 90 if (!page) 91 return -ENOMEM; 92 | 85 page = (char *)__get_free_page(GFP_USER); 86 if (!page) 87 return -ENOMEM; 88 |
93 ret = callback_getenv(entry->id, page, PAGE_SIZE); | 89 ret = callback_getenv(id, page, PAGE_SIZE); |
94 95 if ((ret >> 61) == 0) { 96 seq_write(m, page, ret); 97 ret = 0; 98 } else 99 ret = -EFAULT; 100 free_page((unsigned long)page); 101 return ret; 102} 103 104static int srm_env_proc_open(struct inode *inode, struct file *file) 105{ 106 return single_open(file, srm_env_proc_show, PDE_DATA(inode)); 107} 108 109static ssize_t srm_env_proc_write(struct file *file, const char __user *buffer, 110 size_t count, loff_t *pos) 111{ 112 int res; | 90 91 if ((ret >> 61) == 0) { 92 seq_write(m, page, ret); 93 ret = 0; 94 } else 95 ret = -EFAULT; 96 free_page((unsigned long)page); 97 return ret; 98} 99 100static int srm_env_proc_open(struct inode *inode, struct file *file) 101{ 102 return single_open(file, srm_env_proc_show, PDE_DATA(inode)); 103} 104 105static ssize_t srm_env_proc_write(struct file *file, const char __user *buffer, 106 size_t count, loff_t *pos) 107{ 108 int res; |
113 srm_env_t *entry = PDE_DATA(file_inode(file)); | 109 unsigned long id = (unsigned long)PDE_DATA(file_inode(file)); |
114 char *buf = (char *) __get_free_page(GFP_USER); 115 unsigned long ret1, ret2; 116 117 if (!buf) 118 return -ENOMEM; 119 120 res = -EINVAL; 121 if (count >= PAGE_SIZE) 122 goto out; 123 124 res = -EFAULT; 125 if (copy_from_user(buf, buffer, count)) 126 goto out; 127 buf[count] = '\0'; 128 | 110 char *buf = (char *) __get_free_page(GFP_USER); 111 unsigned long ret1, ret2; 112 113 if (!buf) 114 return -ENOMEM; 115 116 res = -EINVAL; 117 if (count >= PAGE_SIZE) 118 goto out; 119 120 res = -EFAULT; 121 if (copy_from_user(buf, buffer, count)) 122 goto out; 123 buf[count] = '\0'; 124 |
129 ret1 = callback_setenv(entry->id, buf, count); | 125 ret1 = callback_setenv(id, buf, count); |
130 if ((ret1 >> 61) == 0) { 131 do 132 ret2 = callback_save_env(); 133 while((ret2 >> 61) == 1); 134 res = (int) ret1; 135 } 136 137 out: --- 23 unchanged lines hidden (view full) --- 161 printk(KERN_INFO "%s: This Alpha system doesn't " 162 "know about SRM (or you've booted " 163 "SRM->MILO->Linux, which gets " 164 "misdetected)...\n", __func__); 165 return -ENODEV; 166 } 167 168 /* | 126 if ((ret1 >> 61) == 0) { 127 do 128 ret2 = callback_save_env(); 129 while((ret2 >> 61) == 1); 130 res = (int) ret1; 131 } 132 133 out: --- 23 unchanged lines hidden (view full) --- 157 printk(KERN_INFO "%s: This Alpha system doesn't " 158 "know about SRM (or you've booted " 159 "SRM->MILO->Linux, which gets " 160 "misdetected)...\n", __func__); 161 return -ENODEV; 162 } 163 164 /* |
169 * Init numbers 170 */ 171 for (var_num = 0; var_num <= 255; var_num++) 172 sprintf(number[var_num], "%ld", var_num); 173 174 /* | |
175 * Create base directory 176 */ 177 base_dir = proc_mkdir(BASE_DIR, NULL); 178 if (!base_dir) { 179 printk(KERN_ERR "Couldn't create base dir /proc/%s\n", 180 BASE_DIR); 181 return -ENOMEM; 182 } --- 20 unchanged lines hidden (view full) --- 203 } 204 205 /* 206 * Create all named nodes 207 */ 208 entry = srm_named_entries; 209 while (entry->name && entry->id) { 210 if (!proc_create_data(entry->name, 0644, named_dir, | 165 * Create base directory 166 */ 167 base_dir = proc_mkdir(BASE_DIR, NULL); 168 if (!base_dir) { 169 printk(KERN_ERR "Couldn't create base dir /proc/%s\n", 170 BASE_DIR); 171 return -ENOMEM; 172 } --- 20 unchanged lines hidden (view full) --- 193 } 194 195 /* 196 * Create all named nodes 197 */ 198 entry = srm_named_entries; 199 while (entry->name && entry->id) { 200 if (!proc_create_data(entry->name, 0644, named_dir, |
211 &srm_env_proc_fops, entry)) | 201 &srm_env_proc_fops, (void *)entry->id)) |
212 goto cleanup; 213 entry++; 214 } 215 216 /* 217 * Create all numbered nodes 218 */ 219 for (var_num = 0; var_num <= 255; var_num++) { | 202 goto cleanup; 203 entry++; 204 } 205 206 /* 207 * Create all numbered nodes 208 */ 209 for (var_num = 0; var_num <= 255; var_num++) { |
220 entry = &srm_numbered_entries[var_num]; 221 entry->name = number[var_num]; 222 223 if (!proc_create_data(entry->name, 0644, numbered_dir, 224 &srm_env_proc_fops, entry)) | 210 char name[4]; 211 sprintf(name, "%ld", var_num); 212 if (!proc_create_data(name, 0644, numbered_dir, 213 &srm_env_proc_fops, (void *)var_num)) |
225 goto cleanup; | 214 goto cleanup; |
226 227 entry->id = var_num; | |
228 } 229 230 printk(KERN_INFO "%s: version %s loaded successfully\n", NAME, 231 VERSION); 232 233 return 0; 234 235cleanup: 236 remove_proc_subtree(BASE_DIR, NULL); 237 return -ENOMEM; 238} 239 240static void __exit 241srm_env_exit(void) 242{ 243 remove_proc_subtree(BASE_DIR, NULL); 244 printk(KERN_INFO "%s: unloaded successfully\n", NAME); | 215 } 216 217 printk(KERN_INFO "%s: version %s loaded successfully\n", NAME, 218 VERSION); 219 220 return 0; 221 222cleanup: 223 remove_proc_subtree(BASE_DIR, NULL); 224 return -ENOMEM; 225} 226 227static void __exit 228srm_env_exit(void) 229{ 230 remove_proc_subtree(BASE_DIR, NULL); 231 printk(KERN_INFO "%s: unloaded successfully\n", NAME); |
245 246 return; | |
247} 248 249module_init(srm_env_init); 250module_exit(srm_env_exit); | 232} 233 234module_init(srm_env_init); 235module_exit(srm_env_exit); |