home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / MISC / sector0.c < prev    next >
C/C++ Source or Header  |  2009-11-06  |  4KB  |  111 lines

  1. /* sector0 - a utility to interpret the contents of sector0 of OS-9 disk */
  2. /* written by Andrzej Kotanski, 1996, e-mail kotanski@desy.de            */
  3.  
  4. #include <stdio.h>
  5. #include <rbf.h>
  6. #include <errno.h>
  7.  
  8. struct sector0 sec0;
  9. struct rbf_opt opt;
  10.  
  11. main(argc, argv)
  12. char **argv;
  13. {
  14.     unsigned boot;
  15.     char name[33];
  16.  
  17.     FILE *fp;
  18.     char device[20];
  19.  
  20.     if ( argc !=2 )
  21.       exit(_errmsg(errno, "Usage: sector0 /device\n"));
  22.       
  23.     strcpy(device, argv[1]);
  24.     strcat(device, "@");
  25.     
  26.     fp = fopen(device, "r");
  27.     
  28.     if ( fp == NULL )
  29.        exit(_errmsg(errno, "Cannot open '%s'\n", device));
  30.     if ( fread(&sec0, sizeof(struct sector0), 1, fp) == 0 )
  31.        exit(_errmsg(errno, "Cannot read sector 0\n"));
  32.  
  33.     memcpy(&opt, sec0.dd_opt, 32);
  34.  
  35.     printf("total sectors = %d, ", (sec0.dd_tot[0] << 16) +
  36.           (sec0.dd_tot[1] << 8) + sec0.dd_tot[2]);
  37.     printf("track size = %d\n", sec0.dd_tks);
  38.     printf("bytes in alloc map = %d = $%x, ", sec0.dd_map, sec0.dd_map);
  39.     printf("cluster size = %d\n", sec0.dd_bit);
  40.     printf("lsn of root dir = %x\n", (sec0.dd_dir[0] << 16) +
  41.           (sec0.dd_dir[1] << 8) + sec0.dd_dir[2]);
  42.     printf("disk owner = %d.%d\n", sec0.dd_own[0], sec0.dd_own[1]);
  43.     printf("disk attributes = %x, ", sec0.dd_att & 0xff);
  44.     printf("disk id = %x\n", sec0.dd_dsk);
  45.     printf("disk format = %x  ", sec0.dd_fmt);
  46.     if (sec0.dd_fmt & FMT_DS)
  47.        printf("double-sided ");
  48.     if (sec0.dd_fmt & FMT_DD)
  49.        printf("double-density ");
  50.     if (sec0.dd_fmt & FMT_DT)
  51.        printf("double-track ");
  52.     if (sec0.dd_fmt & FMT_QT)
  53.        printf("quad-track ");
  54.     if (sec0.dd_fmt & FMT_OT)
  55.        printf("octal-track ");
  56.     printf("\n");
  57.     printf("sectors per track = %d\n", (sec0.dd_spt[0] <<8) + sec0.dd_spt[1]);
  58.     boot =  (sec0.dd_bt[0] << 16) + (sec0.dd_bt[1] << 8) + sec0.dd_bt[2];
  59.     if ( sec0.dd_bsz ) {
  60.        printf("lsn of boot = %x\n", boot);
  61.        printf("boot size = %d\n", sec0.dd_bsz);
  62.     } else
  63.        printf("boot fd ptr = %x\n", boot);
  64.     printf("creation date = %d/%02d/%02d %02d:%02d\n", sec0.dd_date[0] & 0xff,
  65.        sec0.dd_date[1] & 0xff, sec0.dd_date[2] & 0xff, sec0.dd_date[3] & 0xff,
  66.        sec0.dd_date[4] & 0xff);
  67.     if ( strlen(sec0.dd_name) == 0 )
  68.        name[0] = 0;
  69.     else
  70.        strhcpy(name, sec0.dd_name);
  71.     printf("volume name = %s\n", name);
  72.     printf("integrity code: %s\n", sec0.dd_sync);
  73.     if ( sec0.dd_maplsn )
  74.        printf("bitmap starting lsn = %x\n", sec0.dd_maplsn);
  75.     if ( sec0.dd_lsnsize == 0 )
  76.        sec0.dd_lsnsize = 256;
  77.     printf("sector size = %d\n", sec0.dd_lsnsize);
  78.     printf("sector 0 version ID = %x\n", sec0.dd_versid);
  79.     printf("drive number = %d\n", opt.pd_drv);
  80.     printf("step rate = %d\n", opt.pd_stp);
  81.     printf("disk type: %x ", opt.pd_typ);
  82.     if ( opt.pd_typ & TYP_HARD )
  83.        printf("hard ");
  84.     if ( opt.pd_typ & TYP_DDTRK0 )
  85.        printf("DD track 0 ");
  86.     if ( opt.pd_typ & TYP_OLD ) {
  87.         printf(" old type floppy ");
  88.         if ( opt.pd_typ & TYP_SIZ8 )
  89.            printf("8\" ");
  90.         if ( opt.pd_typ & TYP_SIZ5 )
  91.            printf("5.25\" ");
  92.         if ( opt.pd_typ & TYP_SIZ3 )
  93.            printf("3.5\" ");
  94.     }
  95.     printf("\n");
  96.     printf("density: %x ", opt.pd_dns);
  97.     if ( opt.pd_dns & DNS_DD )
  98.        printf("double  ");
  99.     if ( opt.pd_dns & DNS_DT )
  100.        printf("double track  ");
  101.     if ( opt.pd_dns & DNS_QT )
  102.        printf("quad track   ");
  103.     if ( opt.pd_dns & DNS_OT )
  104.        printf("octal track  ");
  105.     printf("\n");
  106.     printf("track base = %d   sector base %d\n", opt.pd_toffs, opt.pd_soffs);
  107.     printf("sector size = %d\n", opt.pd_ssize);
  108.     printf("control word = %x\n", opt.pd_cntl);
  109. }
  110.  
  111.