/* * MSDIR.C Program to list a directory of files from an MS-DOS disk * * Copyright (c) 1991 Shal Farley * Cheshire Engineering Corporation * 650 Sierra Madre Villa Avenue, Suite 201 * Pasadena, California 91107 * (818) 351-5493 * (818) 351-8645 FAX * shal@alumni.caltech.edu * * This software may be used and distributed for any purpose without license or * royalty payments so long as the above copyright notice is preserved. If you * have any comments, bug fixes, improvements, or new programs based upon this * software I'd like to hear from you. */ #include #include "msport.h" #include "msdefs.h" #include "msfio.h" #include "msdir.h" #include "msstat.h" #include "mserrn.h" long nBytes; int nFiles; main(argc,argv) int argc; char *argv[]; { MSSTAT fs; MSDEV *pd; int nClust; /* Number of clusters on the device */ int ncFree; /* Number of those which don't contain data */ int i; /* * Open our input and output files */ if ( argc != 2) { fprintf(stderr, "Usage: MSDIR device-or-file-name"); exit(1); } switch (msffirst(argv[1], 0, &fs)) { case 0: do { printentry(&fs); } while ( msfnext(&fs) == 0); case MSE_FNF: break; default: fprintf(stderr, "?MSDIR-F-"); msperror(NULL); fprintf(stderr, " %s\n", argv[1]); exit(1); } printf(" %d File%s, %ld Bytes", nFiles, (nFiles == 1)? "" : "s", nBytes); /* * Calculate the number of free bytes remaining on disk */ pd = fs.pDEV; nClust = pd->nsTotal /* Compute how many available */ -pd->nsBoot -(pd->nFATs*pd->nsFAT) -(pd->nDirEntries*sizeof(MSDE)/SECTOR); nClust /= pd->nsCluster; ncFree = 0; for (i = 0; i < nClust+2; i ++) { if (msfeclust(i, pd) == 0) ncFree++; } printf(" in %d Sectors\n", (nClust-ncFree)*pd->nsCluster); printf(" %ld Free bytes in %d Sectors\n", (long)SECTOR*ncFree*pd->nsCluster, ncFree*pd->nsCluster); exit(0); } printentry(pFS) MSSTAT *pFS; { char *t; nFiles++; nBytes += pFS->size; printf(" "); printf("%c", pFS->stat & MSS_DIRTY? 'a' : '-'); printf("%c", pFS->stat & MSS_DIR? 'd' : '-'); printf("%c", pFS->stat & MSS_ROOT? 'v' : '-'); printf("%c", pFS->stat & MSS_SYSTEM? 's' : '-'); printf("%c", pFS->stat & MSS_HIDDEN? 'h' : '-'); printf("%c", pFS->stat & MSS_RONLY? 'r' : '-'); printf(" %10lu", pFS->size); printf(" 0x%03X", pFS->cluster); printf(" %02u", MONTH(pFS->date)); printf("/%02u", DAY(pFS->date)); printf("/%02u", YEAR(pFS->date)); printf(" %02u", HOUR(pFS->time)); printf(":%02u", MINUTE(pFS->time)); printf(":%02u", SECOND(pFS->time)); if ( (t = strchr(pFS->name,'.') ) != NULL ) { *t++ = EOS; printf(" %-8.8s.%-3.3s\n", pFS->name, t); } else { printf(" %-8.8s. \n", pFS->name); } }