Newsgroups: comp.sources.unix From: vancleef@netcom.netcom.com (Henry van Cleef) Subject: v25i103: xenix patches for mtools2 Sender: sources-moderator@pa.dec.com Approved: vixie@pa.dec.com Submitted-By: vancleef@netcom.netcom.com (Henry van Cleef) Posting-Number: Volume 25, Issue 103 Archive-Name: mtools2-xenixpatch This patch to Emmett Gray's Mtools revision 2.0.5 was produced from the changes I made to the distribution to install mtools on my Xenix 286 system. There were a number of places where the Xenix int of 16 bits caused trouble, particularly with use of mtools on hard disks. The table in devices.c is one that illustrates several ways of handling /dev/drivers. It is set up to work with two hard disks, one of which has two DOS partitions. You will have to change the permissions on the /dev/hd* disks to use this code. I did not set these programs up for setuid/setgid. My thanks to Emmett Gray for writing mtools. It was a fairly easy port as things go with Xenix. I had to prepare this patch file on my 3b1 Unix PC because Xenix 286 does not have a context switch in diff, and the gnu diff program blows up the compiler because the macros in regex.c are too big. So it goes. WARNING: If you have problems, they will most likely be with the fat calculations in fat_read.c and fat_write.c and show up when working with hard disks. BACK UP YOUR SYSTEM before you try writing to the hard disk. I blew up my hard disk fat a number of times and was glad I had nothing sacred on those disks. A good check is to see that file sizes and free space are reported correctly with mdir, but this does not test fat_write.c. Take a careful look at the patches for these two files---the context lines, particularly the ones showing showing start = num * 2 are important---this was a bug in earlier releases. vancleef@netcom.netcom.com (Henry van Cleef) #!/bin/sh # This is a shell archive (produced by shar 3.49) # To extract the files from this archive, save it to a file, remove # everything above the "!/bin/sh" line above, and type "sh file_name". # # made 01/12/1992 05:09 UTC by install@jennifer # Source directory /users/xenix/patches # # existing files will NOT be overwritten unless -c is specified # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 7978 -rw-r--r-- mtools.patch # # ============= mtools.patch ============== if test -f 'mtools.patch' -a X"$1" != X"-c"; then echo 'x - skipping mtools.patch (File already exists)' else echo 'x - extracting mtools.patch (Text)' sed 's/^X//' << 'SHAR_EOF' > 'mtools.patch' && diff -c ../mtools/Makefile .//Makefile *** ../mtools/Makefile Sat Jan 4 18:59:15 1992 --- .//Makefile Sat Jan 11 23:21:39 1992 *************** *** 3,17 **** X # X # check the Configure file for some examples of device-specific setups X # Berkeley flavors of Unix should include -DBSD in the CFLAGS X ! CFLAGS = -O ! LDFLAGS = -s X LD = cc X LINT = lint X SHLIB = ! SHAR = shar -a X BINDIR = /usr/local/bin ! MANSECT = 1 X MANDIR = /usr/man/man$(MANSECT) X # X # for AT&T Unix PC 7300/3b1 style shared libraries. --- 3,18 ---- X # X # check the Configure file for some examples of device-specific setups X # Berkeley flavors of Unix should include -DBSD in the CFLAGS + # This setup is for Xenix 286. A stack of 5000 seems to work OK. X ! CFLAGS = -O -M2e ! LDFLAGS = -s -M2e -i -F 5000 #Small model, separate I and D space X LD = cc X LINT = lint X SHLIB = ! SHAR = shar X BINDIR = /usr/local/bin ! MANSECT = LOCAL X MANDIR = /usr/man/man$(MANSECT) X # X # for AT&T Unix PC 7300/3b1 style shared libraries. *************** *** 116,122 **** X cp Mkmanifest.1 $(MANDIR)/mkmanifest.$(MANSECT) X X clean: ! rm $(PROGS) X X lint: X $(LINT) mattrib.c buf_read.c buf_write.c devices.c dir_read.c \ --- 117,126 ---- X cp Mkmanifest.1 $(MANDIR)/mkmanifest.$(MANSECT) X X clean: ! rm -f $(PROGS) core *.o ! ! relink: ! rm -f $(PROGS) X X lint: X $(LINT) mattrib.c buf_read.c buf_write.c devices.c dir_read.c \ diff -c ../mtools/buf_read.c .//buf_read.c *** ../mtools/buf_read.c Sat Jan 4 18:59:30 1992 --- .//buf_read.c Sat Jan 11 17:09:06 1992 *************** *** 27,32 **** --- 27,34 ---- X long where, tail, lseek(); X void perror(), exit(), disk_flush(); X + long debug_num; + X /* don't use cache? */ X if (disk_size == 1) { X where = (start * MSECTOR_SIZE) + disk_offset; diff -c ../mtools/devices.c .//devices.c *** ../mtools/devices.c Sat Jan 4 18:59:32 1992 --- .//devices.c Sat Jan 11 18:05:52 1992 *************** *** 46,51 **** --- 46,77 ---- X }; X #endif /* SPARC */ X + /* The following table is for a 1.44 3.5 drive in A:, a 1.2 5.25 + * drive in B:, and two hard disks, each beginning with a DOS + * partition. Drives H: and L: force drive A: to hi and lo + * density; X: and Y: do the same for B:. This shows all the + * possibilities. /dev/install and /dev/install1 are the preferred + * driver entries. If you do not have a second hard disk, do not + * include an entry for /dev/hd1d. (Table added by H. van Cleef, + * 12-20-91) + */ + #ifdef M_XENIX + struct device devices[] = { + {'A', "/dev/install", 0L, 12, 0, (int (*) ()) 0, 80, 2, 18}, + {'A', "/dev/install", 0L, 12, 0, (int (*) ()) 0, 80, 2, 9}, + {'B', "/dev/install1", 0L, 12, 0, (int (*) ()) 0, 80, 2, 15}, + {'B', "/dev/install1", 0L, 12, 0, (int (*) ()) 0, 40, 2, 9}, + {'C', "/dev/hd0d", 0L, 16, 0, (int (*) ()) 0, 0, 0, 0}, + {'D', "/dev/hd1d", 0L, 16, 0, (int (*) ()) 0, 0, 0, 0}, + {'E', "/dev/hd12", 0L, 16, 0, (int (*) ()) 0, 0, 0, 0}, + {'H', "/dev/fd0135ds18", 0L, 12, 0, (int (*) ()) 0, 80, 2, 18}, + {'L', "/dev/fd0135ds9", 0L, 12, 0, (int (*) ()) 0, 80, 2, 9}, + {'X', "/dev/fd196ds15", 0L, 12, 0, (int (*) ()) 0, 80, 2, 15}, + {'Y', "/dev/fd148ds9", 0L, 12, 0, (int (*) ()) 0, 40, 2, 9}, + {'\0', (char *) NULL, 0L, 0, 0, (int (*) ()) 0, 0, 0, 0} + }; + #endif /*M_XENIX*/ + X #ifdef UNIXPC X #include X #include diff -c ../mtools/fat_read.c .//fat_read.c *** ../mtools/fat_read.c Sat Jan 4 18:59:54 1992 --- .//fat_read.c Sat Jan 11 01:12:31 1992 *************** *** 17,24 **** X fat_decode(num) X unsigned int num; X { ! unsigned int fat, fat_hi, fat_low, byte_1, byte_2; ! int start; X X if (fat_bits == 12) { X /* --- 17,24 ---- X fat_decode(num) X unsigned int num; X { ! unsigned long fat, fat_hi, fat_low, byte_1, byte_2; ! long start; X X if (fat_bits == 12) { X /* *************** *** 60,66 **** X */ X /* which bytes contain the entry */ X start = num * 2; ! if (start <= 3 || start + 1 > (fat_len * MSECTOR_SIZE)) X return(1); X X fat = (*(fat_buf + start + 1) * 0x100) + *(fat_buf + start); --- 60,66 ---- X */ X /* which bytes contain the entry */ X start = num * 2; ! if (start <= 3 || start + 1 > ((long)fat_len * MSECTOR_SIZE)) X return(1); X X fat = (*(fat_buf + start + 1) * 0x100) + *(fat_buf + start); *************** *** 76,82 **** X fat_read(start) X int start; X { ! int buflen; X char *malloc(); X void perror(), exit(), disk_read(); X /* only the first copy of the FAT */ --- 76,82 ---- X fat_read(start) X int start; X { ! long buflen; X char *malloc(); X void perror(), exit(), disk_read(); X /* only the first copy of the FAT */ diff -c ../mtools/fat_write.c .//fat_write.c *** ../mtools/fat_write.c Sat Jan 4 18:59:55 1992 --- .//fat_write.c Sat Jan 11 01:13:49 1992 *************** *** 14,20 **** X unsigned int num; X unsigned int code; X { ! int start; X X if (fat_bits == 12) { X /* --- 14,20 ---- X unsigned int num; X unsigned int code; X { ! long start; X X if (fat_bits == 12) { X /* *************** *** 52,58 **** X */ X /* which bytes contain the entry */ X start = num * 2; ! if (start <= 3 || start + 1 > (fat_len * MSECTOR_SIZE)) X return(1); X X *(fat_buf + start + 1) = code / 0x100; --- 52,58 ---- X */ X /* which bytes contain the entry */ X start = num * 2; ! if (start <= 3 || start + 1 > ((long)fat_len * MSECTOR_SIZE)) X return(1); X X *(fat_buf + start + 1) = code / 0x100; *************** *** 70,76 **** X void X fat_write() X { ! int fat_start, buflen, dups; X void disk_write(); X X if (fd < 0) --- 70,76 ---- X void X fat_write() X { ! long fat_start, buflen, dups; X void disk_write(); X X if (fd < 0) diff -c ../mtools/mdir.c .//mdir.c *** ../mtools/mdir.c Sat Jan 4 19:00:07 1992 --- .//mdir.c Sat Jan 11 18:12:58 1992 *************** *** 78,86 **** X if (last_drive != 'x') { X blocks = getfree() * MSECTOR_SIZE; X if (!files) ! printf("File \"%s\" not found\n\n", newname); X else ! printf(" %3d File(s) %6ld bytes free\n\n", files, blocks); X } X if (init(drive, 0)) { X fprintf(stderr, "%s: Cannot initialize '%c:'\n", argv[0], drive); --- 78,86 ---- X if (last_drive != 'x') { X blocks = getfree() * MSECTOR_SIZE; X if (!files) ! printf("File \"%s\" not found %8ld bytes free\n\n", newname,blocks); X else ! printf(" %3d File(s) %8ld bytes free\n\n", files, blocks); X } X if (init(drive, 0)) { X fprintf(stderr, "%s: Cannot initialize '%c:'\n", argv[0], drive); *************** *** 196,204 **** X X blocks = getfree() * MSECTOR_SIZE; X if (!files) ! printf("File \"%s\" not found\n", newname); X else ! printf(" %3d File(s) %6ld bytes free\n", files, blocks); X close(fd); X exit(0); X } --- 196,204 ---- X X blocks = getfree() * MSECTOR_SIZE; X if (!files) ! printf("File \"%s\" not found %8ld bytes free\n\n", newname,blocks); X else ! printf(" %3d File(s) %8ld bytes free\n", files, blocks); X close(fd); X exit(0); X } diff -c ../mtools/msdos.h .//msdos.h *** ../mtools/msdos.h Sat Jan 4 19:00:29 1992 --- .//msdos.h Sat Jan 11 14:56:34 1992 *************** *** 2,10 **** X * msdos common header file X */ X ! #define MSECTOR_SIZE 512 /* MSDOS sector size in bytes */ X #define MDIR_SIZE 32 /* MSDOS directory size in bytes */ ! #define MAX_CLUSTER 8192 /* largest cluster size */ X #define MAX_PATH 128 /* largest MSDOS path length */ X #define MAX_DIR_SECS 64 /* largest directory (in sectors) */ X --- 2,10 ---- X * msdos common header file X */ X ! #define MSECTOR_SIZE 512L /* MSDOS sector size in bytes */ X #define MDIR_SIZE 32 /* MSDOS directory size in bytes */ ! #define MAX_CLUSTER 8192L /* largest cluster size */ X #define MAX_PATH 128 /* largest MSDOS path length */ X #define MAX_DIR_SECS 64 /* largest directory (in sectors) */ X Only in ./: mtools.patch SHAR_EOF chmod 0644 mtools.patch || echo 'restore of mtools.patch failed' Wc_c="`wc -c < 'mtools.patch'`" test 7978 -eq "$Wc_c" || echo 'mtools.patch: original size 7978, current size' "$Wc_c" fi exit 0 -- Hank van Cleef---The Union Institute---History of Science and Technology Unix, X11, networked systems vancleef@netcom.com, vancleef@tmn.com