egray@fthood.UUCP (12/02/88)
This is patch #2 to Mtools v1.5 This patch will remove the restrictions I had placed on directories that ignored the directory name extension (if any). For some reason, I thought that MSDOS directories could not have file name extensions. Much to my suprize, I tried to create a directory in MSDOS with a ".tst" extension, and it worked! Oh well, that shows you how much I use DOS. WARNING: The "init.c" file is one of the files to be patched. I can't know which version of "init.c" you're using (remember, there is a "generic" version, and a AT&T Unix PC 7300/3b1 version in Unixpc.shar). So, I'm patching the init.c in the current directory and the init.c inside the Unixpc.shar file. At least one of the files will accept the patch. Sorry for the confusion. Many thanks to Jim Sanchez (..!uunet!mcvax.bitnet!syteke!jim) for bringing this to my attention. Emmet P. Gray US Army, HQ III Corps & Fort Hood ...!uunet!uiucuxc!fthood!egray Attn: AFZF-DE-ENV Directorate of Engineering & Housing Environmental Management Office Fort Hood, TX 76544-5057 ----------------------------------------------------------------------------- *** old/Unixpc.shar Tue Nov 1 12:12:00 1988 --- Unixpc.shar Thu Dec 1 10:26:32 1988 *************** *** 120,124 fi fi ! echo shar: "extracting 'init.c'" '(5150 characters)' if test -f 'init.c' then --- 120,124 ----- fi fi ! echo shar: "extracting 'init.c'" '(6142 characters)' if test -f 'init.c' then *************** *** 136,139 X#include <sys/gdioctl.h> X#include <ctype.h> X#include "msdos.h" X --- 136,140 ----- X#include <sys/gdioctl.h> X#include <ctype.h> + X#include <signal.h> X#include "msdos.h" X *************** *** 138,141 X#include "msdos.h" X Xextern int fd, dir_len, dir_start, clus_size, fat_len, num_clus; Xextern unsigned char *fatbuf; --- 139,144 ----- X#include "msdos.h" X + X#undef DUP_FAT + X Xextern int fd, dir_len, dir_start, clus_size, fat_len, num_clus; Xextern unsigned char *fatbuf; *************** *** 146,150 Xint mode; X{ ! X int code, buflen; X unsigned char read_fat(), fat; X char *getenv(), *fixmcwd(), *malloc(); --- 149,153 ----- Xint mode; X{ ! X int code, buflen, intr(); X unsigned char read_fat(), fat; X char *getenv(), *fixmcwd(), *malloc(); *************** *** 250,253 X exit(1); X } X return(0); X} --- 253,262 ----- X exit(1); X } + X /* catch signals if open for write */ + X if (mode == 2) { + X signal(SIGINT, intr); + X signal(SIGTERM, intr); + X signal(SIGQUIT, intr); + X } X return(0); X} *************** *** 309,313 X X if (dirname == NULL) ! X return(""); X X ans = malloc((unsigned int) strlen(dirname)+2); --- 318,322 ----- X X if (dirname == NULL) ! X return("/"); X X ans = malloc((unsigned int) strlen(dirname)+2); *************** *** 356,359 X return(buf[0]); X} SHAR_EOF if test 5150 -ne "`wc -c < 'init.c'`" --- 365,412 ----- X return(buf[0]); X} + X + X/* + X * Do a graceful exit if the program is interupted. This will reduce + X * (but not eliminate) the risk of generating a corrupted disk on + X * a user abort. + X */ + X + Xint + Xintr() + X{ + X void writefat(); + X + X writefat(); + X close(fd); + X exit(1); + X} + X + X/* + X * Write the FAT table to the disk. Up to now the FAT manipulation has + X * been done in memory. All errors are fatal. (Might not be too smart + X * to wait till the end of the program to write the table. Oh well...) + X */ + X + Xvoid + Xwritefat() + X{ + X int buflen; + X void move(); + X + X move(1); + X buflen = fat_len * MSECSIZ; + X if (write(fd, (char *) fatbuf, buflen) != buflen) { + X perror("writefat: write"); + X exit(1); + X } + X#ifdef DUP_FAT + X /* the duplicate FAT table */ + X if (write(fd, (char *) fatbuf, buflen) != buflen) { + X perror("writefat: write"); + X exit(1); + X } + X#endif DUP_FAT + X return; + X} SHAR_EOF if test 6142 -ne "`wc -c < 'init.c'`" *************** *** 357,361 X} SHAR_EOF ! if test 5150 -ne "`wc -c < 'init.c'`" then echo shar: "error transmitting 'init.c'" '(should have been 5150 characters)' --- 410,414 ----- X} SHAR_EOF ! if test 6142 -ne "`wc -c < 'init.c'`" then echo shar: "error transmitting 'init.c'" '(should have been 6142 characters)' *************** *** 359,363 if test 5150 -ne "`wc -c < 'init.c'`" then ! echo shar: "error transmitting 'init.c'" '(should have been 5150 characters)' fi fi --- 412,416 ----- if test 6142 -ne "`wc -c < 'init.c'`" then ! echo shar: "error transmitting 'init.c'" '(should have been 6142 characters)' fi fi *** old/init.c Tue Nov 1 12:10:27 1988 --- init.c Thu Dec 1 10:28:38 1988 *************** *** 8,11 #include <stdio.h> #include <ctype.h> #include "msdos.h" --- 8,12 ----- #include <stdio.h> #include <ctype.h> + #include <signal.h> #include "msdos.h" *************** *** 10,13 #include "msdos.h" extern int fd, dir_len, dir_start, clus_size, fat_len, num_clus; extern unsigned char *fatbuf; --- 11,16 ----- #include "msdos.h" + #undef DUP_FAT + extern int fd, dir_len, dir_start, clus_size, fat_len, num_clus; extern unsigned char *fatbuf; *************** *** 18,22 int mode; { ! int code, buflen; unsigned char read_fat(), fat; char *getenv(), *fixmcwd(), *malloc(), version, get_dos_ver(); --- 21,25 ----- int mode; { ! int code, buflen, intr(); unsigned char read_fat(), fat; char *getenv(), *fixmcwd(), *malloc(), version, get_dos_ver(); *************** *** 170,173 exit(1); } return(0); } --- 173,182 ----- exit(1); } + /* catch signals if open for write */ + if (mode == 2) { + signal(SIGINT, intr); + signal(SIGTERM, intr); + signal(SIGQUIT, intr); + } return(0); } *************** *** 214,218 if (dirname == NULL) ! dirname = ""; ans = malloc((unsigned int) strlen(dirname)+2); --- 223,227 ----- if (dirname == NULL) ! return("/"); ans = malloc((unsigned int) strlen(dirname)+2); *************** *** 280,282 } return(buf[10]); } --- 289,335 ----- } return(buf[10]); + } + + /* + * Do a graceful exit if the program is interupted. This will reduce + * (but not eliminate) the risk of generating a corrupted disk on + * a user abort. + */ + + int + intr() + { + void writefat(); + + writefat(); + close(fd); + exit(1); + } + + /* + * Write the FAT table to the disk. Up to now the FAT manipulation has + * been done in memory. All errors are fatal. (Might not be too smart + * to wait till the end of the program to write the table. Oh well...) + */ + + void + writefat() + { + int buflen; + void move(); + + move(1); + buflen = fat_len * MSECSIZ; + if (write(fd, (char *) fatbuf, buflen) != buflen) { + perror("writefat: write"); + exit(1); + } + #ifdef DUP_FAT + /* the duplicate FAT table */ + if (write(fd, (char *) fatbuf, buflen) != buflen) { + perror("writefat: write"); + exit(1); + } + #endif DUP_FAT + return; } *** old/mdir.c Thu Dec 1 10:29:35 1988 --- mdir.c Wed Nov 30 15:37:11 1988 *************** *** 164,168 if (dir->attr & 0x10) { if (wide) ! printf("%-15.15s", name); else printf("%8s <DIR> %s %s\n", name, date, time); --- 164,168 ----- if (dir->attr & 0x10) { if (wide) ! printf("%-9.9s%-6.6s", name, ext); else printf("%8s %3s <DIR> %s %s\n", name, ext, date, time); *************** *** 166,170 printf("%-15.15s", name); else ! printf("%8s <DIR> %s %s\n", name, date, time); continue; } --- 166,170 ----- printf("%-9.9s%-6.6s", name, ext); else ! printf("%8s %3s <DIR> %s %s\n", name, ext, date, time); continue; } *** old/mmd.c Sun Oct 9 13:18:28 1988 --- mmd.c Wed Nov 30 15:06:44 1988 *************** *** 61,68 pathname = getpath(argv[fargn]); - if (strcmp(text, " ")) { - fprintf(stderr, "mmd: Directory names cannot have extensions\n"); - exit(1); - } if (subdir(pathname)) exit(1); --- 61,64 ----- pathname = getpath(argv[fargn]); if (subdir(pathname)) exit(1); *** old/mread.c Sun Oct 9 13:19:25 1988 --- mread.c Wed Nov 30 15:30:28 1988 *************** *** 159,162 void exit(), getcluster(); FILE *fp; #ifdef LOWERCASE --- 159,163 ----- void exit(), getcluster(); FILE *fp; + struct stat stbuf; #ifdef LOWERCASE *************** *** 180,183 if (ans[0] == 'y' || ans[0] == 'Y') break; } } --- 181,191 ----- if (ans[0] == 'y' || ans[0] == 'Y') break; + } + /* sanity checking */ + if (!stat(target, &stbuf)) { + if ((stbuf.st_mode & S_IFREG) != S_IFREG) { + fprintf(stderr, "mread: \"%s\" is not a regular file\n", target); + return; + } } } *** old/mren.c Sun Oct 9 13:20:02 1988 --- mren.c Wed Nov 30 15:17:05 1988 *************** *** 57,65 temp = getname(argv[fargn+1]); target = fixname(argv[fargn+1], verbose); ! if (isdir(filename) && strcmp(target+8, " ")) { ! strcpy(target+8, " "); ! if (verbose) ! fprintf(stderr, "mren: Directory names may not have extentions\n"); ! } strncpy(tname, target, 8); strncpy(text, target+8, 3); --- 57,61 ----- temp = getname(argv[fargn+1]); target = fixname(argv[fargn+1], verbose); ! strncpy(tname, target, 8); strncpy(text, target+8, 3); *** old/mwrite.c Mon Oct 17 18:11:05 1988 --- mwrite.c Thu Dec 1 11:02:12 1988 *************** *** 210,213 slot = entry; } /* write the file */ if (dir = writeit(fixed, argv[i])) { --- 210,215 ----- slot = entry; } + if (!single) + printf("Copying %s\n", target); /* write the file */ if (dir = writeit(fixed, argv[i], verbose)) *************** *** 211,215 } /* write the file */ ! if (dir = writeit(fixed, argv[i])) { writedir(slot, dir); if (!single) --- 213,217 ----- printf("Copying %s\n", target); /* write the file */ ! if (dir = writeit(fixed, argv[i], verbose)) writedir(slot, dir); *************** *** 213,219 if (dir = writeit(fixed, argv[i])) { writedir(slot, dir); ! if (!single) ! printf("Copying %s\n", target); ! } free(fixed); free(target); --- 215,219 ----- if (dir = writeit(fixed, argv[i], verbose)) writedir(slot, dir); ! free(fixed); free(target); *************** *** 238,244 struct directory * ! writeit(fixed, path) ! char *fixed; ! char *path; { FILE *fp; --- 238,244 ----- struct directory * ! writeit(fixed, path, verbose) ! char *fixed, *path; ! int verbose; { FILE *fp; *************** *** 253,256 } if ((stbuf.st_mode & S_IFREG) != S_IFREG) { fprintf(stderr, "mwrite: \"%s\" is not a regular file\n", path); --- 253,262 ----- } + if ((stbuf.st_mode & S_IFMT) == S_IFDIR) { + if (verbose) + fprintf(stderr, "mwrite: \"%s\" is a directory\n", path); + return(NULL); + } + if ((stbuf.st_mode & S_IFREG) != S_IFREG) { fprintf(stderr, "mwrite: \"%s\" is not a regular file\n", path); *************** *** 366,368 } return(-1); } --- 372,375 ----- } return(-1); + } *** old/putfat.c Wed Sep 28 13:21:14 1988 --- putfat.c Thu Dec 1 09:48:04 1988 *************** *** 1,4 /* ! * putfat(), writedir(), zapit(), writefat() */ --- 1,4 ----- /* ! * putfat(), writedir(), zapit() */ *************** *** 5,9 #include <stdio.h> #include "msdos.h" - #undef DUP_FAT extern int fd, fat_len, dir_chain[25]; --- 5,8 ----- #include <stdio.h> #include "msdos.h" extern int fd, fat_len, dir_chain[25]; *************** *** 109,140 fat = next; } - return; - } - - /* - * Write the FAT table to the disk. Up to now the FAT manipulation has - * been done in memory. All errors are fatal. (Might not be too smart - * to wait till the end of the program to write the table. Oh well...) - */ - - void - writefat() - { - int buflen; - void move(); - - move(1); - buflen = fat_len * MSECSIZ; - if (write(fd, (char *) fatbuf, buflen) != buflen) { - perror("writefat: write"); - exit(1); - } - #ifdef DUP_FAT - /* the duplicate FAT table */ - if (write(fd, (char *) fatbuf, buflen) != buflen) { - perror("writefat: write"); - exit(1); - } - #endif DUP_FAT return; } --- 108,111 ----- fat = next; } return; }