1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/*
* srm_env.c - Access to SRC environment variables through
* the linux procfs
*
* (C)2001, Jan-Benedict Glaw <jbglaw@lug-owl.de>
*
* This driver is at all a modified version of Erik Mouw's
* ./linux/Documentation/DocBook/procfs_example.c, so: thanky
* you, Erik! He can be reached via email at
* <J.A.K.Mouw@its.tudelft.nl>. It is based on an idea
* provided by DEC^WCompaq's "Jumpstart" CD. They included
* a patch like this as well. Thanks for idea!
*
*
* This software has been developed while working on the LART
* computing board (http://www.lart.tudelft.nl/). The
* development has been sponsored by the Mobile Multi-media
* Communications (http://www.mmc.tudelft.nl/) and Ubiquitous
* Communications (http://www.ubicom.tudelft.nl/) projects.
*
* This program is free software; you can redistribute
* it and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation version 2.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <asm/console.h>
#include <asm/uaccess.h>
#define DIRNAME "srm_environment" /* Subdir in /proc/ */
#define VERSION "0.0.2" /* Module version */
#define NAME "srm_env" /* Module name */
#define DEBUG
MODULE_AUTHOR("Jan-Benedict Glaw <jbglaw@lug-owl.de>");
MODULE_DESCRIPTION("Accessing Alpha SRM environment through procfs interface");
MODULE_LICENSE("GPL");
EXPORT_NO_SYMBOLS;
typedef struct _srm_env {
char *name;
unsigned long id;
struct proc_dir_entry *proc_entry;
} srm_env_t;
static struct proc_dir_entry *directory;
static srm_env_t srm_entries[] = {
{ "auto_action", ENV_AUTO_ACTION },
{ "boot_dev", ENV_BOOT_DEV },
{ "bootdef_dev", ENV_BOOTDEF_DEV },
{ "booted_dev", ENV_BOOTED_DEV },
{ "boot_file", ENV_BOOT_FILE },
{ "booted_file", ENV_BOOTED_FILE },
{ "boot_osflags", ENV_BOOT_OSFLAGS },
{ "booted_osflags", ENV_BOOTED_OSFLAGS },
{ "boot_reset", ENV_BOOT_RESET },
{ "dump_dev", ENV_DUMP_DEV },
{ "enable_audit", ENV_ENABLE_AUDIT },
{ "license", ENV_LICENSE },
{ "char_set", ENV_CHAR_SET },
{ "language", ENV_LANGUAGE },
{ "tty_dev", ENV_TTY_DEV },
{ NULL, 0 },
};
static int srm_env_read(char *page, char **start, off_t off, int count,
int *eof, void *data)
{
int nbytes;
unsigned long ret;
srm_env_t *entry;
MOD_INC_USE_COUNT;
if(off != 0) {
MOD_DEC_USE_COUNT;
return -EFAULT;
}
entry = (srm_env_t *)data;
ret = callback_getenv(entry->id, page, count);
if((ret >> 61) == 0)
nbytes = (int)ret;
else
nbytes = -EFAULT;
MOD_DEC_USE_COUNT;
return nbytes;
}
static int srm_env_write(struct file *file, const char *buffer,
unsigned long count, void *data)
{
#define BUFLEN 512
int nbytes;
srm_env_t *entry;
char buf[BUFLEN];
unsigned long ret1, ret2;
MOD_INC_USE_COUNT;
entry = (srm_env_t *) data;
nbytes = strlen(buffer) + 1;
if(nbytes > BUFLEN) {
MOD_DEC_USE_COUNT;
return -ENOMEM;
}
//memcpy(aligned_buffer, buffer, nbytes)
if(copy_from_user(buf, buffer, count)) {
MOD_DEC_USE_COUNT;
return -EFAULT;
}
buf[count] = 0x00;
ret1 = callback_setenv(entry->id, buf, count);
if((ret1 >> 61) == 0) {
do
ret2 = callback_save_env();
while((ret2 >> 61) == 1);
nbytes = (int)ret1;
} else
nbytes = -EFAULT;
MOD_DEC_USE_COUNT;
return nbytes;
}
static void srm_env_cleanup(void)
{
srm_env_t *entry;
if(directory) {
entry = srm_entries;
while(entry->name != NULL && entry->id != 0) {
if(entry->proc_entry) {
remove_proc_entry(entry->name, directory);
entry->proc_entry = NULL;
}
entry++;
}
remove_proc_entry(DIRNAME, NULL);
}
return;
}
static int __init srm_env_init(void)
{
srm_env_t *entry;
if(!alpha_using_srm) {
printk(KERN_INFO "%s: This Alpha system doesn't "
"know about SRM...\n", __FUNCTION__);
return -ENODEV;
}
directory = proc_mkdir(DIRNAME, NULL);
if(directory == NULL)
return -ENOMEM;
directory->owner = THIS_MODULE;
/* Now create all the nodes... */
entry = srm_entries;
while(entry->name != NULL && entry->id != 0) {
entry->proc_entry = create_proc_entry(entry->name, 0644,
directory);
if(entry->proc_entry == NULL)
goto cleanup;
entry->proc_entry->data = entry;
entry->proc_entry->read_proc = srm_env_read;
entry->proc_entry->write_proc = srm_env_write;
entry->proc_entry->owner = THIS_MODULE;
entry++;
}
printk(KERN_INFO "%s: version %s loaded successfully\n", NAME,
VERSION);
return 0;
cleanup:
srm_env_cleanup();
return -ENOMEM;
}
static void __exit srm_env_exit(void)
{
srm_env_cleanup();
printk(KERN_INFO "%s: unloaded successfully\n", NAME);
return;
}
module_init(srm_env_init);
module_exit(srm_env_exit);
|