root@relay.eu.net (06/05/90)
Here is my "makedev.sh".
First off, I changed the order in the C-sourse, since the
compiler issued the well-known "NULL" warning.
Then I generated it with the "mkmakedev" program, and finally
I hand-added the indents and comments.
The resulting list of devices is the one found on my
"minixug" machine, which uses COM1:-COM4: (simple trick
in rs2.x) and a modified version of the VC-driver.
This is why you will find tty and tty0..tty8 in the list...
Hope this helps,
Fred van Kempen
MINIX User group Holland
------------------------------------------------------------------------
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive"
# Contents:
# mkmakedev.c makedev.sh
#
# Wrapped by root@minixug on Mon Jun 4 14:35:20 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'mkmakedev.c' -a "${1}" != "-c"
then
echo "$0: Will not overwrite existing file: 'mkmakedev.c'"
else
echo "x - mkmakedev.c (5940 characters)"
sed 's/^X//' <<\END_OF_SHAR >mkmakedev.c
X/*
X * mkmakedev.c
X *
X * Goes through the named directory and builds a shell script
X * on standard output which, when run, will create appropriate
X * special files.
X *
X * Usage:
X * mkmakedev /dev >makedev.sh
X * For the paranoid, before sending this out, do:
X * mkdir /dev2
X * sh makedev.sh (use full pathname)
X * ls -lR /dev >/tmp/dev
X * ls -lR /dev2 >/tmp/dev2
X * paste /tmp/dev /tmp/dev2 >/tmp/dev.both
X * tr '\011' '\012' </tmp/dev.both | more
X * This last line will show pairs of lines. Both lines should be
X * identical with the exception of the date. As a last step, don't
X * forget to "rm /tmp/dev /tmp/dev2 /tmp/dev.both. (This procedure
X * assumes that there are no "regular" files in /dev.)
X *
X * To use the resulting script:
X * su (commands need root permissions)
X * cd /dev
X * sh makedev.sh
X * The "cd" command is optional so that the receiver of the file
X * can try out the script in some "safe" directory, and look at the
X * results. If it looks OK, then the user can try it in "/dev".
X *
X * This could probably be written as a clever shell file. However,
X * I couldn't see an easy way to do it, so I hacked this simple program
X * together.
X *
X * "Tar" also does this job, but not in a "clear text" fashion.
X *
X * Several routines are "borrowed" from the ls.c. The rest is written
X * by me, and is public domain.
X *
X * Dave Regan 2 June 1990
X * PO Box 601 regan@jacobs.cs.orst.edu
X * Corvallis OR 97339 USA
X */
X
X/*
X * Known bugs (feel free to fix):
X * ------------------------------
X *
X * The code that deals with linking a special device to another
X * will fail if the two files involved are not in the same directory.
X * So far, it appears that most minix "/dev" directories are flat,
X * so this shouldn't be much of a problem.
X *
X * The indentation style matches my style, not "Minix Normal". Sorry.
X * If I have to maintain it, I like it my way.
X *
X * FIX 06/04/90 Fred van Kempen: Moved <stdio.h> downwards to get rid
X * of the NULL problem.
X */
X
X#include <ctype.h>
X#include <stdlib.h>
X#include <string.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <dirent.h>
X#include <pwd.h>
X#include <grp.h>
X#include <time.h>
X#include <stdio.h>
X
X#define VERSION "0.2"
X
X#define major(x) ( (x>>8) & 0377)
X#define minor(x) (x & 0377)
X
Xextern void dofile( /* fname, buf, type */ );
Xextern void dowork( /* char *dir_name */ );
Xextern void dofile( /* */ );
Xextern char *check_link( /* fname, buf */ );
X
Xextern char *owner( /* int uid */ );
Xextern char *groupname( /* int gid */ );
X
Xstruct linktab
X {
X struct linktab *next;
X ino_t ino;
X char fname[1];
X };
X
Xstruct linktab *Root = (struct linktab *) NULL;
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X {
X time_t time_val;
X
X if (argv[1] != (char *) NULL)
X chdir(argv[1]);
X
X time(&time_val);
X printf("# Script built by \"mkmakedev\" v%s on %s",
X VERSION, ctime(&time_val));
X dowork(".");
X exit(0);
X }
X
Xvoid
Xdowork(dir_name)
X char *dir_name;
X {
X struct stat buf;
X DIR *dir;
X struct dirent *dp;
X
X /* Open up the directory and read entries */
X if ((dir = opendir(dir_name)) == (DIR *) NULL)
X {
X fprintf(stderr, "Cannot open directory \"%s\"\n", dir_name);
X exit(1);
X }
X
X chdir(dir_name);
X
X while ((dp = readdir(dir)) != (struct dirent *) NULL)
X {
X if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
X continue;
X if (stat(dp->d_name, &buf) < 0)
X continue;
X switch (buf.st_mode & S_IFMT)
X {
X case S_IFDIR:
X printf("mkdir %s\n", dp->d_name);
X printf("chmod %03o %s\n", buf.st_mode & 0777, dp->d_name);
X printf("chown %s %s\n", owner(buf.st_uid), dp->d_name);
X printf("chgrp %s %s\n", groupname(buf.st_gid), dp->d_name);
X printf("cd %s\n", dp->d_name);
X dowork(dp->d_name);
X printf("cd ..\n");
X break;
X
X case S_IFCHR:
X dofile(dp->d_name, &buf, 'c');
X break;
X
X case S_IFBLK:
X dofile(dp->d_name, &buf, 'b');
X break;
X
X default:
X /* ignore */
X break;
X }
X }
X closedir(dir);
X chdir("..");
X }
X
X
Xvoid
Xdofile(fname, buf, type)
X char *fname;
X struct stat *buf;
X char type;
X {
X char *cptr;
X
X if ((cptr = check_link(fname, buf)) != (char *) NULL)
X printf("ln %s %s\n", cptr, fname);
X else
X {
X printf("mknod %s %c %d %d",
X fname, type, major(buf->st_rdev), minor(buf->st_rdev));
X if (type == 'b')
X printf(" %ld", (long) buf->st_size / 1024);
X printf("\n");
X printf("chmod %03o %s\n", buf->st_mode & 0777, fname);
X printf("chown %s %s\n", owner(buf->st_uid), fname);
X printf("chgrp %s %s\n", groupname(buf->st_gid), fname);
X }
X }
X
X
Xchar *
Xcheck_link(fname, buf)
X char *fname;
X struct stat *buf;
X {
X struct linktab *item;
X
X if (buf->st_nlink == 1)
X return ((char *) NULL);
X for (item = Root; item != (struct linktab *) NULL; item = item->next)
X {
X if (item->ino == buf->st_ino)
X return (item->fname);
X }
X item = (struct linktab *) malloc(sizeof(struct linktab) + strlen(fname));
X if (item != (struct linktab *) NULL)
X {
X item->next = Root;
X Root = item;
X item->ino = buf->st_ino;
X strcpy(item->fname, fname);
X }
X return ((char *) NULL);
X }
X
X
X/*** Lifted from ls.c */
X
X/*@*User and group id's.
X * |owner()| and |groupname()| are used to translate user and group
X * id's to names for the long-format listing. The last id translated
X * is cached.
X */
Xchar *owner(uid)
Xint uid;
X{
X static int ouid = -1;
X static char uname[16];
X struct passwd *pw, *getpwuid( /* int uid */ );
X
X if (uid == ouid) return uname;
X
X if ((pw = getpwuid(uid)) == (struct passwd *) NULL)
X sprintf(uname, "%d", uid);
X else
X strcpy(uname, pw->pw_name);
X
X return uname;
X}
X
Xchar *groupname(gid)
Xint gid;
X{
X static int ogid = -1;
X static char gname[16];
X struct group *gr, *getgrgid( /* int gid */ );
X
X if (gid == ogid) return gname;
X
X if ((gr = getgrgid(gid)) == (struct group *) NULL)
X sprintf(gname, "%d", gid);
X else
X strcpy(gname, gr->gr_name);
X
X return gname;
X}
END_OF_SHAR
if test 5940 -ne `wc -c <'mkmakedev.c'`
then
echo "$0: unpacked with wrong size: mkmakedev.c"
fi
fi
if test -f 'makedev.sh' -a "${1}" != "-c"
then
echo "$0: Will not overwrite existing file: 'makedev.sh'"
else
echo "x - makedev.sh (5373 characters)"
sed 's/^X//' <<\END_OF_SHAR >makedev.sh
X#
X# Script built by "mkmakedev" v0.2 on Mon Jun 4 13:56:18 1990
X#
X# Hand-edited by Fred van Kempen, waltje@minixug.hobby.nl
X# These are the entries in /dev on the 'minixug' machine. Note,
X# that this system uses 4 serial ports (COM1: through COM4:),
X# plus the Virtual Console driver with 4 consoles.
X# Also note, that this directory contains the "format" devices
X# for most of the disks, which are used only by the "/etc/format"
X# program. If you don't have that, or don't want it, you may
X# remove the "FORMAT" entries in this list.
X#
Xmknod PS0 b 2 28 1440 # 3.5" 1.44Mbyte, drive 0
X chmod 600 PS0
X chown bin PS0
X chgrp sys PS0
Xmknod PS1 b 2 29 1440 # 3.5" 1.44Mbyte, drive 1
X chmod 600 PS1
X chown bin PS1
X chgrp sys PS1
Xmknod at0 b 2 8 1200 # 5.25" 1.2Mbyte, drive 0
X chmod 600 at0
X chown bin at0
X chgrp sys at0
Xmknod at0f b 2 136 0 # 5.25" 1.2Mbyte FORMAT, drive 0
X chmod 600 at0f
X chown bin at0f
X chgrp sys at0f
Xmknod at1 b 2 9 1200 # 5.25" 1.2Mbyte, drive 1
X chmod 600 at1
X chown bin at1
X chgrp sys at1
Xmknod at1f b 2 137 0 # 5.25" 1.2Mbyte FORMAT, drive 1
X chmod 600 at1f
X chown bin at1f
X chgrp sys at1f
Xmknod cmos b 7 0 0 # CMOS device (NLMUG specific)
X chmod 600 cmos
X chown bin cmos
X chgrp sys cmos
Xmknod fd0 b 2 0 0 # Floppy drive 0 (auto-density)
X chmod 600 fd0
X chown bin fd0
X chgrp sys fd0
Xmknod fd0f b 2 148 0 # 5.25" 360K in 1.2Mb in FORMAT drive 0
X chmod 600 fd0f
X chown bin fd0f
X chgrp sys fd0f
Xmknod fd1 b 2 1 0 # Floppy drive 1 (auto-density)
X chmod 600 fd1
X chown bin fd1
X chgrp sys fd1
Xmknod fd1f b 2 149 0 # 5.25" 360K in 1.2Mb in FORMAT drive 1
X chmod 600 fd1f
X chown bin fd1f
X chgrp sys fd1f
Xmknod hd0 b 3 0 0 # Hard Disk 0 (entire disk, for FDISK)
X chmod 600 hd0
X chown bin hd0
X chgrp sys hd0
Xmknod hd1 b 3 1 0 # HD0 partition 1
X chmod 600 hd1
X chown bin hd1
X chgrp sys hd1
Xmknod hd2 b 3 2 0 # HD0 partition 2
X chmod 600 hd2
X chown bin hd2
X chgrp sys hd2
Xmknod hd3 b 3 3 0 # HD0 partition 3
X chmod 600 hd3
X chown bin hd3
X chgrp sys hd3
Xmknod hd4 b 3 4 0 # HD0 partition 4
X chmod 600 hd4
X chown bin hd4
X chgrp sys hd4
Xmknod hd5 b 3 5 0 # Hard Disk 1 (entire disk, for FDISK)
X chmod 600 hd5
X chown bin hd5
X chgrp sys hd5
Xmknod hd6 b 3 6 0 # HD1 partition 1
X chmod 600 hd6
X chown bin hd6
X chgrp sys hd6
Xmknod hd7 b 3 7 0 # HD1 partition 2
X chmod 600 hd7
X chown bin hd7
X chgrp sys hd7
Xmknod hd8 b 3 8 0 # HD1 partition 3
X chmod 600 hd8
X chown bin hd8
X chgrp sys hd8
Xmknod hd9 b 3 9 0 # HD1 partition 4
X chmod 600 hd9
X chown bin hd9
X chgrp sys hd9
Xmknod kmem c 1 2 # KERNEL MEMORY, for PS
X chmod 644 kmem
X chown bin kmem
X chgrp sys kmem
Xmknod lp c 6 0 # Parallel printer
X chmod 600 lp
X chown lp lp
X chgrp daemon lp
Xmknod mem c 1 1 # SYSTEM MEMORY, for PS
X chmod 644 mem
X chown bin mem
X chgrp sys mem
Xmknod null c 1 3 # General NULL device
X chmod 666 null
X chown bin null
X chgrp sys null
Xmknod pat0 b 2 20 360 # 5.25" 360Kb in 1.2Mb AT drive, drive 0
X chmod 600 pat0
X chown bin pat0
X chgrp sys pat0
Xmknod pat1 b 2 21 360 # 5.25" 360Kb in 1.2Mb AT drive, drive 1
X chmod 600 pat1
X chown bin pat1
X chgrp sys pat1
Xmknod pc0 b 2 4 360 # 5.25" 360Kbyte, drive 0
X chmod 600 pc0
X chown bin pc0
X chgrp sys pc0
Xmknod pc0f b 2 132 0 # 5.25" 360Kbyte FORMAT, drive 0
X chmod 600 pc0f
X chown bin pc0f
X chgrp sys pc0f
Xmknod pc1 b 2 5 360 # 5.25" 360Kbyte, drive 1
X chmod 600 pc1
X chown bin pc1
X chgrp sys pc1
Xmknod pc1f b 2 133 0 # 5.25" 360Kbyte FORMAT, drive 1
X chmod 600 pc1f
X chown bin pc1f
X chgrp sys pc1f
Xmknod port b 1 4 0 # INTEL PORT I/O
X chmod 600 port
X chown bin port
X chgrp sys port
Xmknod ps0 b 2 16 720 # 3.5" 720Kbyte, drive 0
X chmod 600 ps0
X chown bin ps0
X chgrp sys ps0
Xmknod ps0f b 2 144 0 # 3.5" 720Kbyte FORMAT, drive 0
X chmod 600 ps0f
X chown bin ps0f
X chgrp sys ps0f
Xmknod ps1 b 2 17 720 # 3.5" 720Kbyte, drive 1
X chmod 600 ps1
X chown bin ps1
X chgrp sys ps1
Xmknod ps1f b 2 145 0 # 3.5" 720Kbyte FORMAT, drive 1
X chmod 600 ps1f
X chown bin ps1f
X chgrp sys ps1f
Xmknod ram b 1 0 0 # RAM disk
X chmod 600 ram
X chown bin ram
X chgrp sys ram
Xmknod tty c 5 0 # Default terminal
X chmod 666 tty
X chown bin tty
X chgrp sys tty
Xmknod tty0 c 4 0 # Terminal 0 (default console)
X chmod 622 tty0
X chown bin tty0
X chgrp sys tty0
Xmknod tty1 c 4 1 # Terminal 1 (virtual console 1 or COM1: )
X chmod 622 tty1
X chown bin tty1
X chgrp sys tty1
Xmknod tty2 c 4 2 # Terminal 2 (virtual console 2 or COM2: )
X chmod 622 tty2
X chown bin tty2
X chgrp sys tty2
Xmknod tty3 c 4 3 # Terminal 3 (virtual console 3 or COM3: )
X chmod 622 tty3
X chown bin tty3
X chgrp sys tty3
Xmknod tty4 c 4 4 # Terminal 4 (virtual console 4 or COM4: )
X chmod 622 tty4
X chown bin tty4
X chgrp sys tty4
Xmknod tty5 c 4 5 # Terminal 5 (COM1: )
X chmod 622 tty5
X chown uucp tty5
X chgrp uucp tty5
Xmknod tty6 c 4 6 # Terminal 6 (COM2: )
X chmod 622 tty6
X chown uucp tty6
X chgrp uucp tty6
Xmknod tty7 c 4 7 # Terminal 7 (COM3: )
X chmod 622 tty7
X chown uucp tty7
X chgrp uucp tty7
Xmknod tty8 c 4 8 # Terminal 8 (COM4: )
X chmod 622 tty8
X chown uucp tty8
X chgrp uucp tty8
X
X# Now, for the various links.
Xln tty0 console # Tty0 is a bit old-fashioned...
X
X# These links are for use with the "dos{read,write,dir} program.
X# Just make sure it matches your system configuration.
Xln at0 dosA # A: is 1.2Mbyte 5.25"
Xln PS1 dosB # B: is 1.44Mbyte 3.5"
Xln pat0 dosE # E: is 360Kbyte 5.25"
Xln ps1 dosF # F: is 720Kbyte 3.5"
Xln hd1 dosC # C: is the MS-DOS partition C:
X
END_OF_SHAR
if test 5373 -ne `wc -c <'makedev.sh'`
then
echo "$0: unpacked with wrong size: makedev.sh"
fi
fi
echo " End of archive"
exit 0
#
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| MINIX User Group Holland UUCP: waltje@minixug.hobby.nl |
| c/o Fred van Kempen, or: hp4nl!minixug!waltje |
| Hoefbladhof 27 |
| 2215 DV VOORHOUT |
| The Netherlands "A good programmer knows his Sources" |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+