Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site hadron.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!qantel!lll-crg!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.unix-wizards Subject: Re: /dev/null Message-ID: <96@hadron.UUCP> Date: Wed, 27-Nov-85 22:48:00 EST Article-I.D.: hadron.96 Posted: Wed Nov 27 22:48:00 1985 Date-Received: Fri, 29-Nov-85 10:35:28 EST References: <593@ttrdc.UUCP> <808@dcl-cs.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 47 Summary: You're kidding, right? (write??) In article <808@dcl-cs.UUCP> stephen@comp.lancs.ac.uk (Stephen J. Muir) writes: >write (filedes, buffer, nbytes) > char *buffer > { if (major_minor (filedes) == that_of ("/dev/null")) > return (nbytes); > else > go_do_the_REAL_write (filedes, buffer, nbytes); > } I don't know whether to hope that this is a bad joke, or to hope that no-one would on purpose perpetrate this kind of misinformation. The write system call i s a system call: the arguments get passed down to the kernel. The kernel checks various parameters, and especially what type of file is being written to. (At this point, we have common code for read and write, with a flag saying what is being done.) Since /dev/{kmem,null,mem,Ukmem} are char devices, the kernel looks in the character device driver table, and indexes off the major device number to find which driver to use. The driver write routine for this particular major device number does the following things: If minor == KMEM, then while (u.u_count > 0) c = getc(); put c at *u.u_offset++ in such a way that if there is a seg violation, the error gets returned to the user instead of causing a system crash. else if minor == MEM, then map *u.u_offset into space accessible via suword() and subyte(). while (u.u_count > 0) c = getc(); if (subyte(c, u.u_offset++) < 0) return error; else if minor == NULL, then just set u.u_count to 0. that's it. nothing else. that pretends that everything got writ. else ... Some versions of UNIX may do this more elegantly/efficiently, e.g. with copyout() rather than subyte(); but this is the original, common idea. It is NOT handled at user level. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}