Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Jun 2000 20:47:08 -0400
From:      James Howard <howardjp@wam.umd.edu>
To:        freebsd-hackers@freebsd.org
Subject:   Why is this architecture dependent?
Message-ID:  <200006190047.UAA02830@rac9.wam.umd.edu>

next in thread | raw e-mail | index | archive | help
We know I ask dumb questions a lot, but this one may not be so dumb.  A
friend of mine was joking about having a device called /dev/foo which
would be like /dev/zero, except it would spit out the word "foo" over and
over again.  Well, we laughed about it, but today, I implemented
it.  (This was cool since this was the first time I've ever hacked the
kernel and it worked right...)  

Needless to say, since this is so similar to /dev/zero, I just copied the
code and modified it for foo in instead of 0s.  But the file I had to
modify was sys/i386/i386/mem.c.  The relevant code for this is this:

	/* minor device 12 (/dev/zero) is source of nulls on read, rathole on write */
                case 12:
                        if (uio->uio_rw == UIO_WRITE) {
                                c = iov->iov_len;
                                break;
                        }
                        if (zbuf == NULL) {
                                zbuf = (caddr_t)
                                    malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
                                bzero(zbuf, PAGE_SIZE);
                        }
                        c = min(iov->iov_len, PAGE_SIZE);
                        error = uiomove(zbuf, (int)c, uio);
                        continue;

What makes this architecture dependent?

The equivalent call from sys/alpha/alpha/mem.c is identical, except for
this comment after the first if block:

                        /*
                         * On the first call, allocate and zero a page
                         * of memory for use with /dev/zero.
                         */

So why have this duplication?  Why not implement it once and be done?  Is
there some subtle  difference I am not seeing?

Thanks, Jamie



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006190047.UAA02830>