lkml.org 
[lkml]   [1998]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: /dev/ones
On Tue, 22 Dec 1998, Charles Cazabon wrote:

> Steffen Grunewald <steffen@gfz-potsdam.de> wrote:
> > Charles Cazabon wrote:
> > |>
> > |> >> Hmmm I guess we need a /dev/one? (Actually not a bad thing to have)
> > |> >
> > How about /dev/minusone :-) ?
> > Or /dev/allones ...
>
> CaT <cat@zip.com.au> suggested /dev/ones, which sounds as good a suggestion
> as any to me.
>
> The big question, however, is thus: where in the kernel tree does the code
> for /dev/zero live? I had a look through some obvious files, and grepped
> through most of the rest. I had assumed it would be in the character mode
> device drivers, but unless I'm blind (a distinct possibility) it doesn't
> seem to be there.
>
> Obviously, I'm not a kernel hacker -- but cloning /dev/zero to /dev/ones sounds
> like it might be an ideal first kernel project. :)

Well, I havn't tried writing kernel code before and I have a couple of
projects in mind, so I came up with this patch agains 2.0.36.

It adds character device major 1, minor 10 from which bytes 0xff can
be read. To use: patch, compile and boot your kernel and make a device
with something like

mknod /dev/one c 1 10
or mknod /dev/ones c 1 10
or mknod /dev/~zero c 1 10
or ...

I do _NOT_ propose this for addition to the kernel because

a) The device char major 1, minor 10 has not been officially allocated.
b) There is no need for this device anyway - you can use /dev/zero and tr.
c) We do not seem to have a sensible name for it.

This is just a newbie exercise in kernel hacking :-)

Chris.


--- linux/drivers/char/mem.c-2.0.36 Wed Dec 23 00:57:09 1998
+++ linux/drivers/char/mem.c Wed Dec 23 00:59:18 1998
@@ -185,6 +185,19 @@
return count;
}

+static int read_ones(struct inode * node, struct file * file, char * buf, int count)
+{
+ int left;
+
+ for (left = count; left > 0; left--) {
+ put_user(~0,buf);
+ buf++;
+ if (need_resched)
+ schedule();
+ }
+ return count;
+}
+
static int mmap_zero(struct inode * inode, struct file * file, struct vm_area_struct * vma)
{
if (vma->vm_flags & VM_SHARED)
@@ -239,6 +252,8 @@
#define full_lseek null_lseek
#define write_zero write_null
#define read_full read_null
+#define ones_lseek null_lseek
+#define write_ones write_null

static struct file_operations ram_fops = {
memory_lseek,
@@ -317,6 +332,18 @@
NULL /* no special release code */
};

+static struct file_operations ones_fops = {
+ ones_lseek,
+ read_ones,
+ write_ones,
+ NULL, /* ones_readdir */
+ NULL, /* ones_select */
+ NULL, /* ones_ioctl */
+ NULL,
+ NULL, /* no special open code */
+ NULL /* no special release code */
+};
+
static struct file_operations full_fops = {
full_lseek,
read_full,
@@ -366,6 +393,9 @@
break;
case 9:
filp->f_op = &urandom_fops;
+ break;
+ case 10:
+ filp->f_op = &ones_fops;
break;
default:
return -ENXIO;



--
.sig lost in a filesystem 'accident'.



-
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/

\
 
 \ /
  Last update: 2005-03-22 13:46    [W:0.126 / U:0.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site