srm_env.c (d585a021c0b10b0477d6b608c53e1feb8cde0507) srm_env.c (0ead0f84e81a41c3e98aeceab04af8ab1bb08d1f)
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 at all a modified version of Erik Mouw's
8 * Documentation/DocBook/procfs_example.c, so: thank

--- 19 unchanged lines hidden (view full) ---

28 * Suite 330, Boston, MA 02111-1307 USA
29 *
30 */
31
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/proc_fs.h>
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 at all a modified version of Erik Mouw's
8 * Documentation/DocBook/procfs_example.c, so: thank

--- 19 unchanged lines hidden (view full) ---

28 * Suite 330, Boston, MA 02111-1307 USA
29 *
30 */
31
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/proc_fs.h>
36#include <linux/seq_file.h>
36#include <asm/console.h>
37#include <asm/uaccess.h>
38#include <asm/machvec.h>
39
40#define BASE_DIR "srm_environment" /* Subdir in /proc/ */
41#define NAMED_DIR "named_variables" /* Subdir for known variables */
42#define NUMBERED_DIR "numbered_variables" /* Subdir for all variables */
43#define VERSION "0.0.6" /* Module version */

--- 30 unchanged lines hidden (view full) ---

74 { "char_set", ENV_CHAR_SET },
75 { "language", ENV_LANGUAGE },
76 { "tty_dev", ENV_TTY_DEV },
77 { NULL, 0 },
78};
79static srm_env_t srm_numbered_entries[256];
80
81
37#include <asm/console.h>
38#include <asm/uaccess.h>
39#include <asm/machvec.h>
40
41#define BASE_DIR "srm_environment" /* Subdir in /proc/ */
42#define NAMED_DIR "named_variables" /* Subdir for known variables */
43#define NUMBERED_DIR "numbered_variables" /* Subdir for all variables */
44#define VERSION "0.0.6" /* Module version */

--- 30 unchanged lines hidden (view full) ---

75 { "char_set", ENV_CHAR_SET },
76 { "language", ENV_LANGUAGE },
77 { "tty_dev", ENV_TTY_DEV },
78 { NULL, 0 },
79};
80static srm_env_t srm_numbered_entries[256];
81
82
82static int
83srm_env_read(char *page, char **start, off_t off, int count, int *eof,
84 void *data)
83static int srm_env_proc_show(struct seq_file *m, void *v)
85{
84{
86 int nbytes;
87 unsigned long ret;
88 srm_env_t *entry;
85 unsigned long ret;
86 srm_env_t *entry;
87 char *page;
89
88
90 if (off != 0) {
91 *eof = 1;
92 return 0;
93 }
89 entry = (srm_env_t *)m->private;
90 page = (char *)__get_free_page(GFP_USER);
91 if (!page)
92 return -ENOMEM;
94
93
95 entry = (srm_env_t *) data;
96 ret = callback_getenv(entry->id, page, count);
94 ret = callback_getenv(entry->id, page, PAGE_SIZE);
97
98 if ((ret >> 61) == 0) {
95
96 if ((ret >> 61) == 0) {
99 nbytes = (int) ret;
100 *eof = 1;
97 seq_write(m, page, ret);
98 ret = 0;
101 } else
99 } else
102 nbytes = -EFAULT;
100 ret = -EFAULT;
101 free_page((unsigned long)page);
102 return ret;
103}
103
104
104 return nbytes;
105static int srm_env_proc_open(struct inode *inode, struct file *file)
106{
107 return single_open(file, srm_env_proc_show, PDE(inode)->data);
105}
106
108}
109
107static int
108srm_env_write(struct file *file, const char __user *buffer, unsigned long count,
109 void *data)
110static ssize_t srm_env_proc_write(struct file *file, const char __user *buffer,
111 size_t count, loff_t *pos)
110{
111 int res;
112{
113 int res;
112 srm_env_t *entry;
114 srm_env_t *entry = PDE(file->f_path.dentry->d_inode)->data;
113 char *buf = (char *) __get_free_page(GFP_USER);
114 unsigned long ret1, ret2;
115
115 char *buf = (char *) __get_free_page(GFP_USER);
116 unsigned long ret1, ret2;
117
116 entry = (srm_env_t *) data;
117
118 if (!buf)
119 return -ENOMEM;
120
121 res = -EINVAL;
122 if (count >= PAGE_SIZE)
123 goto out;
124
125 res = -EFAULT;

--- 9 unchanged lines hidden (view full) ---

135 res = (int) ret1;
136 }
137
138 out:
139 free_page((unsigned long)buf);
140 return res;
141}
142
118 if (!buf)
119 return -ENOMEM;
120
121 res = -EINVAL;
122 if (count >= PAGE_SIZE)
123 goto out;
124
125 res = -EFAULT;

--- 9 unchanged lines hidden (view full) ---

135 res = (int) ret1;
136 }
137
138 out:
139 free_page((unsigned long)buf);
140 return res;
141}
142
143static const struct file_operations srm_env_proc_fops = {
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
143static void
144srm_env_cleanup(void)
145{
146 srm_env_t *entry;
147 unsigned long var_num;
148
149 if (base_dir) {
150 /*

--- 89 unchanged lines hidden (view full) ---

240
241 }
242
243 /*
244 * Create all named nodes
245 */
246 entry = srm_named_entries;
247 while (entry->name && entry->id) {
152static void
153srm_env_cleanup(void)
154{
155 srm_env_t *entry;
156 unsigned long var_num;
157
158 if (base_dir) {
159 /*

--- 89 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) {
248 entry->proc_entry = create_proc_entry(entry->name,
249 0644, named_dir);
257 entry->proc_entry = proc_create_data(entry->name, 0644, named_dir,
258 &srm_env_proc_fops, entry);
250 if (!entry->proc_entry)
251 goto cleanup;
259 if (!entry->proc_entry)
260 goto cleanup;
252
253 entry->proc_entry->data = (void *) entry;
254 entry->proc_entry->read_proc = srm_env_read;
255 entry->proc_entry->write_proc = srm_env_write;
256
257 entry++;
258 }
259
260 /*
261 * Create all numbered nodes
262 */
263 for (var_num = 0; var_num <= 255; var_num++) {
264 entry = &srm_numbered_entries[var_num];
265 entry->name = number[var_num];
266
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
267 entry->proc_entry = create_proc_entry(entry->name,
268 0644, numbered_dir);
271 entry->proc_entry = proc_create_data(entry->name, 0644, numbered_dir,
272 &srm_env_proc_fops, entry);
269 if (!entry->proc_entry)
270 goto cleanup;
271
272 entry->id = var_num;
273 if (!entry->proc_entry)
274 goto cleanup;
275
276 entry->id = var_num;
273 entry->proc_entry->data = (void *) entry;
274 entry->proc_entry->read_proc = srm_env_read;
275 entry->proc_entry->write_proc = srm_env_write;
276 }
277
278 printk(KERN_INFO "%s: version %s loaded successfully\n", NAME,
279 VERSION);
280
281 return 0;
282
283cleanup:

--- 16 unchanged lines hidden ---
277 }
278
279 printk(KERN_INFO "%s: version %s loaded successfully\n", NAME,
280 VERSION);
281
282 return 0;
283
284cleanup:

--- 16 unchanged lines hidden ---