srm_env.c (d9dda78bad879595d8c4220a067fc029d6484a16) | srm_env.c (c35f2e49f88e72ffcb0cc6af2f93fe153fa88dd8) |
---|---|
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 --- 37 unchanged lines hidden (view full) --- 46 47MODULE_AUTHOR("Jan-Benedict Glaw <jbglaw@lug-owl.de>"); 48MODULE_DESCRIPTION("Accessing Alpha SRM environment through procfs interface"); 49MODULE_LICENSE("GPL"); 50 51typedef struct _srm_env { 52 char *name; 53 unsigned long id; | 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 --- 37 unchanged lines hidden (view full) --- 46 47MODULE_AUTHOR("Jan-Benedict Glaw <jbglaw@lug-owl.de>"); 48MODULE_DESCRIPTION("Accessing Alpha SRM environment through procfs interface"); 49MODULE_LICENSE("GPL"); 50 51typedef struct _srm_env { 52 char *name; 53 unsigned long id; |
54 struct proc_dir_entry *proc_entry; | |
55} srm_env_t; 56 57static struct proc_dir_entry *base_dir; 58static struct proc_dir_entry *named_dir; 59static struct proc_dir_entry *numbered_dir; 60static char number[256][4]; 61 62static srm_env_t srm_named_entries[] = { --- 81 unchanged lines hidden (view full) --- 144 .owner = THIS_MODULE, 145 .open = srm_env_proc_open, 146 .read = seq_read, 147 .llseek = seq_lseek, 148 .release = single_release, 149 .write = srm_env_proc_write, 150}; 151 | 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[] = { --- 81 unchanged lines hidden (view full) --- 143 .owner = THIS_MODULE, 144 .open = srm_env_proc_open, 145 .read = seq_read, 146 .llseek = seq_lseek, 147 .release = single_release, 148 .write = srm_env_proc_write, 149}; 150 |
152static void 153srm_env_cleanup(void) 154{ 155 srm_env_t *entry; 156 unsigned long var_num; 157 158 if (base_dir) { 159 /* 160 * Remove named entries 161 */ 162 if (named_dir) { 163 entry = srm_named_entries; 164 while (entry->name != NULL && entry->id != 0) { 165 if (entry->proc_entry) { 166 remove_proc_entry(entry->name, 167 named_dir); 168 entry->proc_entry = NULL; 169 } 170 entry++; 171 } 172 remove_proc_entry(NAMED_DIR, base_dir); 173 } 174 175 /* 176 * Remove numbered entries 177 */ 178 if (numbered_dir) { 179 for (var_num = 0; var_num <= 255; var_num++) { 180 entry = &srm_numbered_entries[var_num]; 181 182 if (entry->proc_entry) { 183 remove_proc_entry(entry->name, 184 numbered_dir); 185 entry->proc_entry = NULL; 186 entry->name = NULL; 187 } 188 } 189 remove_proc_entry(NUMBERED_DIR, base_dir); 190 } 191 192 remove_proc_entry(BASE_DIR, NULL); 193 } 194 195 return; 196} 197 | |
198static int __init 199srm_env_init(void) 200{ 201 srm_env_t *entry; 202 unsigned long var_num; 203 204 /* 205 * Check system --- 14 unchanged lines hidden (view full) --- 220 221 /* 222 * Create base directory 223 */ 224 base_dir = proc_mkdir(BASE_DIR, NULL); 225 if (!base_dir) { 226 printk(KERN_ERR "Couldn't create base dir /proc/%s\n", 227 BASE_DIR); | 151static int __init 152srm_env_init(void) 153{ 154 srm_env_t *entry; 155 unsigned long var_num; 156 157 /* 158 * Check system --- 14 unchanged lines hidden (view full) --- 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); |
228 goto cleanup; | 181 return -ENOMEM; |
229 } 230 231 /* 232 * Create per-name subdirectory 233 */ 234 named_dir = proc_mkdir(NAMED_DIR, base_dir); 235 if (!named_dir) { 236 printk(KERN_ERR "Couldn't create dir /proc/%s/%s\n", --- 12 unchanged lines hidden (view full) --- 249 250 } 251 252 /* 253 * Create all named nodes 254 */ 255 entry = srm_named_entries; 256 while (entry->name && entry->id) { | 182 } 183 184 /* 185 * Create per-name subdirectory 186 */ 187 named_dir = proc_mkdir(NAMED_DIR, base_dir); 188 if (!named_dir) { 189 printk(KERN_ERR "Couldn't create dir /proc/%s/%s\n", --- 12 unchanged lines hidden (view full) --- 202 203 } 204 205 /* 206 * Create all named nodes 207 */ 208 entry = srm_named_entries; 209 while (entry->name && entry->id) { |
257 entry->proc_entry = proc_create_data(entry->name, 0644, named_dir, 258 &srm_env_proc_fops, entry); 259 if (!entry->proc_entry) | 210 if (!proc_create_data(entry->name, 0644, named_dir, 211 &srm_env_proc_fops, entry)) |
260 goto cleanup; 261 entry++; 262 } 263 264 /* 265 * Create all numbered nodes 266 */ 267 for (var_num = 0; var_num <= 255; var_num++) { 268 entry = &srm_numbered_entries[var_num]; 269 entry->name = number[var_num]; 270 | 212 goto cleanup; 213 entry++; 214 } 215 216 /* 217 * Create all numbered nodes 218 */ 219 for (var_num = 0; var_num <= 255; var_num++) { 220 entry = &srm_numbered_entries[var_num]; 221 entry->name = number[var_num]; 222 |
271 entry->proc_entry = proc_create_data(entry->name, 0644, numbered_dir, 272 &srm_env_proc_fops, entry); 273 if (!entry->proc_entry) | 223 if (!proc_create_data(entry->name, 0644, numbered_dir, 224 &srm_env_proc_fops, entry)) |
274 goto cleanup; 275 276 entry->id = var_num; 277 } 278 279 printk(KERN_INFO "%s: version %s loaded successfully\n", NAME, 280 VERSION); 281 282 return 0; 283 284cleanup: | 225 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: |
285 srm_env_cleanup(); 286 | 236 remove_proc_subtree(BASE_DIR, NULL); |
287 return -ENOMEM; 288} 289 290static void __exit 291srm_env_exit(void) 292{ | 237 return -ENOMEM; 238} 239 240static void __exit 241srm_env_exit(void) 242{ |
293 srm_env_cleanup(); | 243 remove_proc_subtree(BASE_DIR, NULL); |
294 printk(KERN_INFO "%s: unloaded successfully\n", NAME); 295 296 return; 297} 298 299module_init(srm_env_init); 300module_exit(srm_env_exit); | 244 printk(KERN_INFO "%s: unloaded successfully\n", NAME); 245 246 return; 247} 248 249module_init(srm_env_init); 250module_exit(srm_env_exit); |