--- 3,161 ---- */ #include + #include + #include + #include #include "msdos.h" + #ifdef LOADDEVS + + #define CFG_FILE "/etc/mtools" + + #define MAX_LINE PATH_MAX+40 + #define MAX_DEVICES 10 + + #ifdef __STDC__ + # define AUX(x) #x + # define STR(x) AUX(x) + #else + # define STR(x) "x" + #endif + + #define SET(f,t,h,s) \ + { devices[dev].fat_bits = (f); devices[dev].tracks = (t); \ + devices[dev].heads = (h); devices[dev].sectors = (s); } + + struct device devices[MAX_DEVICES+1]; + + void load_devices(void) + { + FILE *cfg; + char buffer[MAX_LINE+1],name[PATH_MAX+1]; + char *here,*start; + int items,dev,fat_bits; + + if ((cfg = fopen(CFG_FILE,"r")) == NULL) { + perror(CFG_FILE); + exit(1); + } + dev = 0; + while (fgets(buffer,MAX_LINE,cfg)) { + if (here = strchr(buffer,'#')) *here = 0; + else if (here = strchr(buffer,'\n')) *here = 0; + for (start = buffer; *start == ' ' || *start == '\t'; start++); + if (!*start) continue; + items = sscanf(start,"%c %" STR(PATH_MAX) "s %d %d %d %d", + &devices[dev].drive,name,&fat_bits,&devices[dev].tracks, + &devices[dev].heads,&devices[dev].sectors); + if (dev >= MAX_DEVICES) { + fprintf(stderr,"Too many devices\n"); + exit(1); + } + if (items == 6) devices[dev].fat_bits = fat_bits; + else { + if (items == 2 || items == 3) { + #ifdef oldLINUX + if (!strncmp("/dev/at",name,7)) { SET(12,80,2,15) } + else if (!strncmp("/dev/PS",name,7)) { SET(12,80,2,18) } + else if (!strncmp("/dev/ps",name,7)) { SET(12,80,2,9) } + else if (!strncmp("/dev/hd",name,7)) { SET(16,0,0,0) } + else + #endif + { + fprintf(stderr,"Unknown device %s, please specify all " + "parameters\n",name); + exit(1); + } + if (items == 3) devices[dev].fat_bits = fat_bits; + } + else { + f