Here is the patch you asked for.
This patch adds a (much requested) nvram_bytes parameter to
drivers/char/nvram.c. It has not been tested. It has not even been compiled.
If it breaks, you get to keep both pieces.
--- linux-2.4.0-test6-pre2.orig/drivers/char/nvram.c Fri Aug 4 17:00:34 2000
+++ linux-2.4.0-test6-pre2/drivers/char/nvram.c Fri Aug 4 19:24:06 2000
@@ -115,8 +115,21 @@
#define NVRAM_EXCL 2 /* opened with O_EXCL */
#define RTC_FIRST_BYTE 14 /* RTC register number of first NVRAM byte */
-#define NVRAM_BYTES 50 /* number of NVRAM bytes */
+#if MACH == PC
+#define NVRAM_MIN_BYTES 14 /* minimum number of NVRAM bytes */
+#define NVRAM_DEFAULT_BYTES 50 /* default number of NVRAM bytes */
+#define NVRAM_MAX_BYTES 128 /* maximum number of NVRAM bytes */
+
+static int nvram_bytes = NVRAM_DEFAULT_BYTES;
+#else
+#define NVRAM_DEFAULT_BYTES 50
+#define NVRAM_MIN_BYTES NVRAM_DEFAULT_BYTES
+#define NVRAM_MAX_BYTES NVRAM_DEFAULT_BYTES
+
+#define nvram_bytes NVRAM_DEFAULT_BYTES
+#define NVRAM_BYTES_FIXED
+#endif
static int mach_check_checksum( void );
static void mach_set_checksum( void );
@@ -223,7 +236,7 @@
offset += file->f_pos;
break;
case 2:
- offset += NVRAM_BYTES;
+ offset += nvram_bytes;
break;
}
return( (offset >= 0) ? (file->f_pos = offset) : -EINVAL );
@@ -232,7 +245,7 @@
static ssize_t nvram_read(struct file * file,
char * buf, size_t count, loff_t *ppos )
{
- char contents [NVRAM_BYTES];
+ char contents [NVRAM_MAX_BYTES];
unsigned i = *ppos;
char *tmp;
@@ -241,7 +254,7 @@
if (!nvram_check_checksum_int())
goto checksum_err;
- for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp)
+ for (tmp = contents; count-- > 0 && i < nvram_bytes; ++i, ++tmp)
*tmp = nvram_read_int(i);
spin_unlock_irq (&rtc_lock);
@@ -260,13 +273,13 @@
static ssize_t nvram_write(struct file * file,
const char * buf, size_t count, loff_t *ppos )
{
- char contents [NVRAM_BYTES];
+ char contents [NVRAM_MAX_BYTES];
unsigned i = *ppos;
char * tmp;
/* could comebody please help me indent this better? */
- copy_from_user_ret (contents, buf, (NVRAM_BYTES - i) < count ?
- (NVRAM_BYTES - i) : count,
+ copy_from_user_ret (contents, buf, (nvram_bytes - i) < count ?
+ (nvram_bytes - i) : count,
-EFAULT);
spin_lock_irq (&rtc_lock);
@@ -274,7 +287,7 @@
if (!nvram_check_checksum_int())
goto checksum_err;
- for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp)
+ for (tmp = contents; count-- > 0 && i < nvram_bytes; ++i, ++tmp)
nvram_write_int (*tmp, i);
nvram_set_checksum_int();
@@ -303,7 +316,7 @@
spin_lock_irq (&rtc_lock);
- for( i = 0; i < NVRAM_BYTES; ++i )
+ for( i = 0; i < nvram_bytes; ++i )
nvram_write_int( 0, i );
nvram_set_checksum_int();
@@ -363,12 +376,12 @@
static int nvram_read_proc( char *buffer, char **start, off_t offset,
int size, int *eof, void *data )
{
- unsigned char contents[NVRAM_BYTES];
+ unsigned char contents[NVRAM_MAX_BYTES];
int i, len = 0;
off_t begin = 0;
spin_lock_irq (&rtc_lock);
- for( i = 0; i < NVRAM_BYTES; ++i )
+ for( i = 0; i < nvram_bytes; ++i )
contents[i] = nvram_read_int( i );
spin_unlock_irq (&rtc_lock);
@@ -412,9 +425,36 @@
&nvram_fops
};
+#ifndef NVRAM_BYTES_FIXED
+/* Why is module that easier? */
+#ifdef MODULE
+MODULE_PARM(nvram_bytes,"i");
+#else
+static int __init nvram_bytes_setup (char *str)
+{
+ int opt;
+
+ get_option (&str, &opt);
+
+ if (opt >= NVRAM_MIN_BYTES && opt <= NVRAM_MAX_BYTES)
+ nvram_bytes = opt;
+ else
+ printk (KERN_ERR "nvram: nvram_bytes out of bounds, using default of %d\n", NVRAM_BYTES_DEFAULT);
+
+ return 1;
+}
+
+__setup("nvram_bytes=", nvram_bytes_setup);
+#endif
+#endif
static int __init nvram_init(void)
{
+#if defined (MODULE) && !defined (NVRAM_BYTES_FIXED)
+ if (nvram_bytes < NVRAM_MIN_BYTES || nvram_bytes > NVRAM_MAX_BYTES)
+ goto out_of_bounds;
+#endif
+
/* First test whether the driver should init at all */
if (!CHECK_DRIVER_INIT())
return( -ENXIO );
@@ -423,6 +463,12 @@
misc_register( &nvram_dev );
create_proc_read_entry("driver/nvram",0,0,nvram_read_proc,NULL);
return( 0 );
+
+#if defined (MODULE) && !defined (NVRAM_BYTES_FIXED)
+out_of_bounds:
+ printk (KERN_ERR "nvram: nvram_bytes out of bounds\n");
+ return -EINVAL;
+#endif
}
static void __exit nvram_cleanup_module (void)
-- Cesar Eduardo Barros cesarb@nitnet.com.br cesarb@dcc.ufrj.br- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Mon Aug 07 2000 - 21:00:14 EST