Subject: Re: How to retrieve CD disk id.
To: None <port-i386@netbsd.org>
From: Stephen Borrill <netbsd@precedence.co.uk>
List: port-i386
Date: 05/13/2005 08:41:48
> Sometimes when I access CD's under other environment
> (for instance as windows) I can observe CD disk
> identification string i.e. "volume label".
>I know that it is possible to define and set this
> string during iso image creation process by makeisofs
> etc.
>However, I don't know how to retrieve this string from
> CD disk that has it?

It can be found at offset 0x8028. Here's a little program I wrote some
years ago that returns the label, sector size and number of sectors:

#include <stdio.h>

#define VERSION "$Revision: 1.3 $ $Date: 2003/05/08 17:03:37 $"

void usage()
{
   fprintf(stderr,"Syntax: cdinfo <cd device>\n");
   fprintf(stderr,"Version: %s\n",VERSION);
   exit(1);
}

int main(int argc, char *argv[])
{
   FILE *fp;
   unsigned int num,size;
   unsigned char buf[2048],*c;

   if(argc!=2) usage();

   if((fp=fopen(argv[1],"rb"))==NULL) {
     fprintf(stderr,"Cannot open device %s\n",argv[1]);
     exit(2);
   }

   fseek(fp,0x8000,SEEK_SET);
   fread(buf,sizeof(buf),sizeof(unsigned char),fp);
   fclose(fp);
   num=buf[0x50]+(buf[0x51]<<8)+(buf[0x52]<<16)+(buf[0x53]<<24);
   size=buf[0x80]+(buf[0x81]<<8);

   for(c=buf+0x47;*c==20 && c>buf+0x28;c--);
   *(c+1)=0;
   printf("%u %u %s\n",num,size,buf+0x28);
   return 0;
}

-- 
Stephen