[comp.sys.atari.st.tech] Hard Disk Sector 0 Questions

ric@mcrware.UUCP (Ric Yeates) (03/07/91)

Netlanders:

I need to write some software to add partitions to the partition table
stored on sector 0 of a hard disk.  I will be adding partitions for the
areas that are not yet used on the disk.  For instance, Joe User has a
80Meg drive and sets up two 30Meg partitions with HDX.PRG.  My program
wants to then go in there (at the request of the user) and add a partition
or two in the unused 20Meg of space.  These are not to be GEM partitions, but
they should conform as far as the partition table information is concerned.

What I've been able to figure out so far is:

    * the partition table starts at 0x1c7
    * the table entries are in the following form:
          struct part_entry {
              char name[3];
              long start;      /* 32-bit sector number */
              long length;     /* 32-bit length in sectors */
              char flag;       /* 1 byte flag where 0x01 means bootable */
          };
    * offset 0x1c2 is the start of a 32-bit value for the total number of
      sectors on the device
      
My questions are:

1. Is any of the above information inaccurate? Incomplete?

2. What is the significance of the byte at 0x1c6 (sandwiched between the
   total sectors and the partition table)?  On my drive it has the value
   0x81 (%10000001).

3. Is there other information in this sector that I will need to write a
   partitioner?
   
4. Is there a checksum/parity value kept for sector 0? How does HDX3.01 know
   it was used to format the hard disk?

5. How might an application read sector 0?  All the GEMDOS calls I found
   dealt with files only, not the whole device.

6. Are there any decent/recent books on this sort of thing?

I suppose that's enough for now.

Thanks in advance for any help that you may be able to provide.

Ric Yeates


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Ric Yeates                                             Microware Systems Corp.
  "I found these opinions on the floor, so I don't think they belong
                                                              to Microware."
                         1. Grease Generously
                         2. Wax Philosophically
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

bjoern@drdhh.hanse.de (Bjoern Kriews) (03/13/91)

From article <5208@mcrware.UUCP>, by ric@mcrware.UUCP (Ric Yeates):
> I need to write some software to add partitions to the partition table
> stored on sector 0 of a hard disk.


>     * the table entries are in the following form:
>           struct part_entry {

					WRONG !!! flag has to be here, bit 7 means bootable

>               char name[3];
>               long start;      /* 32-bit sector number */
>               long length;     /* 32-bit length in sectors */
>               char flag;       /* 1 byte flag where 0x01 means bootable */
>           };
> 1. Is any of the above information inaccurate? Incomplete?

Yes. :-)

More questions answered below.

> 5. How might an application read sector 0?  All the GEMDOS calls I found
>    dealt with files only, not the whole device.

If you detect an AHDI or compatible driver, you can set bit 3 in the
Rwabs() mode-word to read physical sectors, but to be safe you will
have to use direct DMA access. (Ask your Microware devdrvr writers)

In germany, there's a VERY good book, called 'Scheibenkleister', 
published by Maxon. It's about all mass-storage devices on the ST.
I don't think that there is an english version, so you'll have to
search somebody reading ger-mish - it worth the action.

I include the C definitions I use for such tools:
(ICD/Supra Rootsectors only - there are official docs from Atari
describing HDX 3.0 Format, but they are (c), so you have to ask Atari.

Hope that helps, Bjoern

---------

#define	PART_EXIST						1
#define	PART_BOOT							128

/* partition definition */
struct part {
  unsigned char   flag;				/* bit 0: exists bit 7: boot		*/
  unsigned char   id[3];			/* partition name								*/					
  unsigned long   start;			/* start sector									*/
  unsigned long   size;				/* size in sectors							*/
    };

/* rootsector structure */
typedef struct {
  unsigned char   prg[0x150];	/* bootprogram									*/
  unsigned char   version;		/* rootsector version number		*/
  unsigned long   cbhd;       /* Driver magic longword        */
  struct part     extp[8];    /* extended parts SED/ICD/Supra	*/
  unsigned int    hi_cc;			/* cylinders on disk						*/
  unsigned char   hi_dhc;			/* number of heads							*/
  unsigned char   filler;			/* unused												*/
  unsigned int    hi_rwcc;		/* reduced current start				*/
  unsigned int    hi_wpc;			/* write precomp start					*/
  unsigned char   hi_lz;			/* landing zone distance				*/
  unsigned char   hi_rt;			/* steprate											*/
  unsigned char   hi_in;			/* interleave										*/
  unsigned char   hi_spt;			/* sectors per track						*/
  unsigned long   hi_size; 		/* total size in sectors				*/
  struct   part   p[4];       /* atari hdx<3.0 partitions     */
  unsigned long   bsl_start;	/* bad sector list start				*/
  unsigned long   bsl_count;	/* number of sectors in bsl			*/
  unsigned int    checksum;		/* fixup for $1234							*/
    } ROOTBLK;


*
*	bjoern@drdhh.hanse.de / Bjoern Kriews, D-2000 Hamburg 76
*

apratt@atari.UUCP (Allan Pratt) (03/22/91)

Somebody asks:
>>[How do I read device sector 0?]

bjoern@drdhh.hanse.de (Bjoern Kriews) writes:
>If you detect an AHDI or compatible driver, you can set bit 3 in the
>Rwabs() mode-word to read physical sectors, but to be safe you will
>have to use direct DMA access. (Ask your Microware devdrvr writers)

Yikes!  Do I really have to go into the dangers of this kind of thinking?
NEVER use direct DMA access.  You are SURE to get it wrong and screw up
something.  Who has drivers which DON'T support the raw-device bit? 
Whoever they are, their drivers are not complete, at least as defined by
Atari's documentation of the Rwabs() call.

============================================
Opinions expressed above do not necessarily	-- Allan Pratt, Atari Corp.
reflect those of Atari Corp. or anyone else.	  ...ames!atari!apratt