[Coco] LSN0 C code
Mike Rowen
mike at bcmr3.net
Thu Jun 9 18:36:01 EDT 2011
Thanks, Bob. Very cool.
On Jun 9, 2011, at 5:30 PM, "Bob Devries" <devries.bob at gmail.com> wrote:
> Since the code is quite short, I'll include it inline here:
>
> /* Lsn0 - Displays and decodes the contents of Logical Sector Number 0 */
> /* CopyRight (c) 1989 by Bob Devries */
> /* This programme may be freely distributed, provided this message is */
> /* not removed from the source code. */
> #include <stdio.h>
> #include <direct.h>
> union sec {
> long numsec;
> char tsec[4];
> unsigned usec;
> };
> main (argc,argv)
> int argc;
> char *argv[];
> {
> int fp;
> char attr[11];
> static char *at[] = {"d","s","e","w","r","e","w","r"};
> struct ddsect disk;
> int i,count;
> union sec totsec;
> pflinit();
> for (i=0;i<4;i++) totsec.tsec[i] = '\0';
> if((argc != 2) || ((argv[1][0] == '-') && (argv[1][1]) == '?'))
> {
> usage();
> exit(0);
> }
> if (argv[1][0] != '/')
> {
> usage();
> exit(0);
> }
> count = strlen(argv[1]);
> for (i=1;i <= count; i++)
> {
> if (argv[1][i] == '/')
> {
> fprintf(stderr,"%s is not a device name.\n\n",argv[1]);
> usage();
> exit(0);
> }
> }
> argv[1][count++] = '@';
> argv[1][count] = '\0';
> if ((fp = open(argv[1],_READ)) == EOF)
> {
> fprintf(stderr,"Can't open %s for reading.\n\n",argv[1]);
> usage();
> }
> read(fp,&disk,sizeof(disk));
> close(fp);
> totsec.tsec[1] = disk.dd_tot[0];
> totsec.tsec[2] = disk.dd_tot[1];
> totsec.tsec[3] = disk.dd_tot[2];
> argv[1][--count] = '\0';
> printf("\n LSN 0 description of %s.\n",argv[1]);
> printf("\n\n Total number of sectors = %ld.\n",totsec.numsec);
> printf(" Sectors per track = %d.\n",disk.dd_tsk);
> printf(" Bytes in allocation map = %u.\n",disk.dd_map);
> printf(" Cluster size = %u.\n",disk.dd_bit);
> totsec.tsec[1] = disk.dd_dir[0];
> totsec.tsec[2] = disk.dd_dir[1];
> totsec.tsec[3] = disk.dd_dir[2];
> printf(" Address of Root Directory = %ld.\n",totsec.numsec);
> printf(" Owner number = %u.\n",disk.dd_own);
> count = 256;
> strcpy(attr," = ");
> for(i=1;i<9;i++)
> {
> count = ((count>>1) & 0xff);
> if(disk.dd_att & count)
> strcat(attr,at[i-1]);
> else
> strcat(attr,"-");
> }
> printf(" Attributes = %02X%s.\n",(disk.dd_att & 0xff),attr);
> printf(" Disk ID = %u.\n",disk.dd_dsk);
> printf(" Media format = %d =",disk.dd_fmt);
> switch(disk.dd_fmt)
> {
> case 0:
> printf("48 tpi SDSS.\n");
> break;
> case 1:
> printf("48 tpi SDDS.\n");
> break;
> case 2:
> printf("48 tpi DDSS.\n");
> break;
> case 3:
> printf("48 tpi DDDS.\n");
> break;
> case 4:
> printf("96 tpi SDSS.\n");
> break;
> case 5:
> printf("96 tpi SDDS.\n");
> break;
> case 6:
> printf("96 tpi DDSS.\n");
> break;
> case 7:
> printf("96 tpi DDDS.\n");
> break;
> default:
> printf(" Can't identify format.\n");
> }
> printf(" Sectors per track (track 0) = %u.\n",disk.dd_spt);
> totsec.tsec[1] = disk.dd_bt[0];
> totsec.tsec[2] = disk.dd_bt[1];
> totsec.tsec[3] = disk.dd_bt[2];
> printf(" Address of bootstrap file = %ld.\n",totsec.numsec);
> printf(" Length of bootstrap file = %u",disk.dd_bsz);
> if (disk.dd_bsz == 0)
> printf(":No boot installed.\n");
> else
> printf(".\n");
> printf(" Creation date : %02d/%02d/%02d %02d:%02d.\n", disk.dd_date[0],disk.dd_date[1],disk.dd_date[2],disk.dd_date[3],disk.dd_date[4]);
> for (i=0; i<32; ++i)
> {
> if (disk.dd_name[i] < 0)
> {
> disk.dd_name[i] -= 128;
> disk.dd_name[++i] = '\0';
> break;
> }
> }
> printf(" Volume name = %s.\n\n",disk.dd_name);
> }
> usage()
> {
> fprintf(stderr,"\n Usage: lsn0 /devicename\n\n");
> }
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
More information about the Coco
mailing list