home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / mtools_3.6.src.lzh / MTOOLS_3.6 / minfo.c < prev    next >
Text File  |  1997-11-12  |  4KB  |  151 lines

  1. /*
  2.  * mlabel.c
  3.  * Make an MSDOS volume label
  4.  */
  5.  
  6. #include "sysincludes.h"
  7. #include "msdos.h"
  8. #include "mainloop.h"
  9. #include "vfat.h"
  10. #include "mtools.h"
  11. #include "nameclash.h"
  12.  
  13.  
  14. static void usage(void)
  15. {
  16.     fprintf(stderr, 
  17.         "Mtools version %s, dated %s\n", mversion, mdate);
  18.     fprintf(stderr, 
  19.         "Usage: %s [-v] drive\n", progname);
  20.     exit(1);
  21. }
  22.  
  23.  
  24. static void displayInfosector(Stream_t *Stream, struct bootsector *boot)
  25. {
  26.     InfoSector_t *infosec;
  27.  
  28.     if(WORD(ext.fat32.infoSector) == MAX32)
  29.         return;
  30.  
  31.     infosec = (InfoSector_t *) safe_malloc(WORD(secsiz));
  32.     force_read(Stream, (char *) infosec, 
  33.            WORD(secsiz) * WORD(ext.fat32.infoSector),
  34.            WORD(secsiz));
  35.     printf("\nInfosector:\n");
  36.     printf("signature=0x%08x\n", _DWORD(infosec->signature));
  37.     if(_DWORD(infosec->count) != MAX32)
  38.         printf("free clusters=%u\n", _DWORD(infosec->count));
  39.     if(_DWORD(infosec->pos) != MAX32)
  40.         printf("last allocated cluster=%u\n", _DWORD(infosec->pos));
  41. }
  42.  
  43.  
  44. void minfo(int argc, char **argv, int type)
  45. {
  46.     struct bootsector boot0;
  47. #define boot (&boot0)
  48.     char name[EXPAND_BUF];
  49.     int media;
  50.     int tot_sectors;
  51.     struct device dev;
  52.     char drive;
  53.     int verbose=0;
  54.     int c;
  55.     Stream_t *Stream;
  56.     
  57.     while ((c = getopt(argc, argv, "v")) != EOF) {
  58.         switch (c) {
  59.             case 'v':
  60.                 verbose = 1;
  61.                 break;
  62.             default:
  63.                 usage();
  64.         }
  65.     }
  66.  
  67.     if(argc == optind)
  68.         usage();
  69.  
  70.     for(;optind < argc; optind++) {
  71.         if(!argv[optind][0] || argv[optind][1] != ':')
  72.             usage();
  73.         drive = toupper(argv[optind][0]);
  74.  
  75.         if(! (Stream = find_device(drive, O_RDONLY, &dev, boot, 
  76.                        name, &media)))
  77.             exit(1);
  78.  
  79.         tot_sectors = DWORD(bigsect);
  80.         SET_INT(tot_sectors, WORD(psect));
  81.         printf("device information:\n");
  82.         printf("===================\n");
  83.         printf("sectors per track: %d\n", dev.sectors);
  84.         printf("heads: %d\n", dev.heads);
  85.         printf("cylinders: %d\n\n", dev.tracks);
  86.         printf("mformat command line: mformat -t %d -h %d -s %d ",
  87.                dev.tracks, dev.heads, dev.sectors);
  88.         if(DWORD(nhs))
  89.             printf("-H %d ", DWORD(nhs));
  90.         printf("%c:\n", tolower(drive));
  91.         printf("\n");
  92.         
  93.         printf("bootsector information\n");
  94.         printf("======================\n");
  95.         printf("filename=\"%s\"\n", name);
  96.         printf("banner:\"%8s\"\n", boot->banner);
  97.         printf("sector size: %d bytes\n", WORD(secsiz));
  98.         printf("cluster size: %d sectors\n", boot->clsiz);
  99.         printf("reserved (boot) sectors: %d\n", WORD(nrsvsect));
  100.         printf("fats: %d\n", boot->nfat);
  101.         printf("max available root directory slots: %d\n", 
  102.                WORD(dirents));
  103.         printf("small size: %d sectors\n", WORD(psect));
  104.         printf("media descriptor byte: 0x%x\n", boot->descr);
  105.         printf("sectors per fat: %d\n", WORD(fatlen));
  106.         printf("sectors per track: %d\n", WORD(nsect));
  107.         printf("heads: %d\n", WORD(nheads));
  108.         printf("hidden sectors: %d\n", DWORD(nhs));
  109.         printf("big size: %d sectors\n", DWORD(bigsect));
  110.  
  111.         if(WORD(fatlen)){
  112.             printf("physical drive id: 0x%x\n", 
  113.                    boot->ext.old.physdrive);
  114.             printf("reserved=0x%x\n", 
  115.                    boot->ext.old.reserved);
  116.             printf("dos4=0x%x\n", 
  117.                    boot->ext.old.dos4);
  118.             printf("serial number: %X\n", 
  119.                    DWORD(ext.old.serial));
  120.             printf("disk label=\"%11.11s\"\n", 
  121.                    boot->ext.old.label);
  122.             printf("disk type=\"%8.8s\"\n", 
  123.                    boot->ext.old.fat_type);
  124.         } else {
  125.             printf("Big fatlen=%u\n",
  126.                    DWORD(ext.fat32.bigFat));
  127.             printf("Extended flags=0x%04x\n",
  128.                    WORD(ext.fat32.extFlags));
  129.             printf("FS version=0x%04x\n",
  130.                    WORD(ext.fat32.fsVersion));
  131.             printf("rootCluster=%u\n",
  132.                    DWORD(ext.fat32.rootCluster));
  133.             if(WORD(ext.fat32.infoSector) != MAX32)
  134.                 printf("infoSector location=%d\n",
  135.                        WORD(ext.fat32.infoSector));
  136.             if(WORD(ext.fat32.backupBoot) != MAX32)
  137.                 printf("backup boot sector=%d\n",
  138.                        WORD(ext.fat32.backupBoot));
  139.             displayInfosector(Stream,boot);
  140.         }
  141.  
  142.         if(verbose) {
  143.             printf("\n");
  144.             print_sector("Boot sector hexdump", 
  145.                      (unsigned char*) boot);
  146.         }
  147.     }
  148.  
  149.     exit(0);
  150. }
  151.