From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mod.civil.su.OZ.AU ([129.78.142.6]) by hawkwind.utcs.toronto.edu with SMTP id <2704>; Thu, 25 Mar 1993 19:46:48 -0500 Received: by mod.civil.su.oz.au id <28678>; Fri, 26 Mar 1993 10:45:57 +1000 From: John (Most modern computers would break if you stood on them) Mackin Date: Thu, 25 Mar 1993 19:38:16 -0500 To: The rc Mailing List Subject: /dev/fd driver for Ultrix DECstations Message-ID: <199303261038.9018.rc.bagav@civil.su.oz.au> X-Face: 39seV7n\`#asqOFdx#oj/Uz*lseO_1n9n7rQS;~ve\e`&Z},nU1+>0X^>mg&M.^X$[ez>{F k5[Ah<7xBWF-@-ru?& @4K4-b`ydd^`(n%Z{ I thought this was posted to comp.sources.unix. In any case it was certainly ok'd for public release; I would have given a reference to comp.sources.unix for it but when I looked I couldn't work out what was going on there -- maybe the archive site I looked at was busted. Anyway. Since rc can use /dev/fd to advantage, maybe this will interest people on this list. As the Subject: says, this is a device driver implementing /dev/fd for DECstations running Ultrix, version 4.2 (or later, it says; I have only tried 4.2 myself). This is by Boyd Roberts. You need the kernel objects that come with your Ultrix distribution to re-build the kernel to include this driver. Follow the build instructions in the README; they work :). OK, John. # To unbundle, sh this file echo README 1>&2 sed 's/.//' >README <<'//GO.SYSIN DD README' -Installation instructions for a Ninth Edition style /dev/fd driver for -4.2 (and later) ULTRIX systems. - - 1. cp devfd.c /usr/sys/fs/gfs - - 2. Edit /usr/sys/machine/common/conf.c and before `cdevsw' add : - -#if DEVFD > 0 -int devfdopen(); -#else -#define devfdopen nodev -#endif - - 3. Choose a free slot in the `cdevsw' (I used 90) and put: - - {devfdopen, nodev, nodev, nodev, /*90*/ - nodev, nodev, nodev, 0, - nodev, nodev, 0, 0}, - - 4. Edit /usr/sys/conf/mips/files.mips and add: - -fs/gfs/devfd.c optional devfd device-driver Notbinary - - 5. To enable this driver for your kernel, the following two lines - must be added to /usr/sys/conf/mips/ - -options DEVFD -pseudo-device devfd - - - 6. Re-configure your kernel and make it: - - cd /usr/sys/conf/mips/ - config - cd /usr/sys/MIPS/ - make depend - make - - 7. Boot the new `vmunix'. - - 8. Create the necessary special files with /usr/bin/sh5: - - cd /dev - mkdir fd - cd fd - umask 0111 - i=0 - while test $i -lt 64 - do - mknod $i c 90 $i # use major device (ie. 90) that - i=`expr $i + 1` # concurs with your cdevsw entry - done - ln /dev/fd/0 /dev/stdin - ln /dev/fd/1 /dev/stdout - ln /dev/fd/2 /dev/stderr - - 9. You now have a /dev/fd driver, test it with: - - echo '/dev/fd ok?' | cat /dev/stdin - -Thanks to Norman Wilson for an essential piece of insight which allows /dev/fd -to be implemented as a driver, rather than a foul hack in the kernel [c]open(). - - -Boyd Roberts -Member of Technical Staff -Paris Research Laboratory -Digital Equipment Corporation //GO.SYSIN DD README echo devfd.c 1>&2 sed 's/.//' >devfd.c <<'//GO.SYSIN DD devfd.c' -/* Copyright 1991 Digital Equipment Corporation - * All Rights Reserved - * - * Permission to use, copy, and modify this software and its documentation is - * hereby granted only under the following terms and conditions. Both the - * above copyright notice and this permission notice must appear in all copies - * of the software, derivative works or modified versions, and any portions - * thereof, and both notices must appear in supporting documentation. - * - * Users of this software agree to the terms and conditions set forth herein, - * and hereby grant back to Digital a non-exclusive, unrestricted, royalty-free - * right and license under any changes, enhancements or extensions made to the - * core functions of the software, including but not limited to those affording - * compatibility with other hardware or software environments, but excluding - * applications which incorporate this software. Users further agree to use - * their best efforts to return to Digital any such changes, enhancements or - * extensions that they make and inform Digital of noteworthy uses of this - * software. Correspondence should be provided to Digital at: - * - * Director of Licensing - * Paris Research Laboratory - * Digital Equipment Corporation - * 85 Avenue Victor Hugo - * 92500 Rueil Malmaison - * France - * - * This software may be distributed (but not offered for sale or transferred - * for compensation) to third parties, provided such third parties agree to - * abide by the terms and conditions of this notice. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -/* - * Ninth Edition style /dev/fd/... driver. - * - * Boyd Roberts - * Digital PRL - * September '91 - */ - -#include "../h/param.h" -#include "../h/systm.h" -#include "../h/dir.h" -#include "../h/user.h" -#include "../h/kernel.h" -#include "../h/gnode.h" -#include "../h/proc.h" -#include "../h/conf.h" -#include "../h/file.h" -#include "../h/socket.h" -#include "../h/socketvar.h" -#include "../h/mount.h" -#include "../h/stat.h" -#include "../h/ioctl.h" -#include "../h/flock.h" -#include "../h/exec.h" - -#undef GETF -#define GETF(fp, fd) if ((fp = getf(fd)) == NULL) return u.u_error - -int -devfdopen(dev, flag) -dev_t dev; -int flag; -{ - struct file *fp; /* file table entry for this open */ - struct file *dfp; /* file table entry for /dev/fd/`minor(dev)' */ - int fd; /* fd allocated for this open */ - int dfd; /* fd allocated for /dev/fd/`minor(dev)' */ - - dfd = minor(dev); - fd = u.u_r.r_val1; /* courtesy of ufalloc() */ - -#ifdef DEBUG - mprintf("/dev/fd/%d will be %d\n", dfd, fd); -#endif DEBUG - - GETF(dfp, dfd); - GETF(fp, fd); - - /* If both are the same then it's opening a closed /dev/fd/... */ - if (fp == dfp) - return EBADF; - - /* fake dup() */ - smp_lock(&lk_file, LK_RETRY); - U_OFILE_SET(fd, dfp); - dfp->f_count++; - U_POFILE_SET(fd, U_POFILE(dfd)); - smp_unlock(&lk_file); - - /* free my file table entry and return */ - return closef(fp); -} - //GO.SYSIN DD devfd.c