summaryrefslogtreecommitdiffstats
path: root/getgeo.c
diff options
context:
space:
mode:
Diffstat (limited to 'getgeo.c')
-rw-r--r--getgeo.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/getgeo.c b/getgeo.c
index 1de9463..2a17a65 100644
--- a/getgeo.c
+++ b/getgeo.c
@@ -44,15 +44,17 @@ get_geometry(int fd, struct image_geometry *geo)
unsigned int secsize;
const struct image_geometry *sg;
const struct image_geometry standard_geometries[] = {
- { 40, 1, 8, 160<<10, 0, 9 },
- { 40, 1, 9, 180<<10, 0, 9 },
- { 40, 2, 8, 320<<10, 0, 9 },
- { 40, 2, 9, 360<<10, 0, 9 },
- { 80, 2, 9, 720<<10, 0, 9 },
- { 80, 2, 15, 1200<<10, 0, 9 },
- { 80, 2, 18, 1440<<10, 0, 9 },
- { 80, 2, 36, 2880<<10, 0, 9 },
- { 0, 0, 0, 0, 0, 0 }
+ { 40, 1, 8, 0xfe, 160<<10, 0, 9 }, /* 160K 5.25" SSDD standard */
+ { 40, 1, 9, 0xfc, 180<<10, 0, 9 }, /* 180K 5.25" SSDD standard */
+ { 40, 2, 8, 0xff, 320<<10, 0, 9 }, /* 320K 5.25" DSDD standard */
+ { 40, 2, 9, 0xfd, 360<<10, 0, 9 }, /* 360K 5.25" DSDD standard */
+ { 80, 2, 9, 0xf9, 720<<10, 0, 9 }, /* 720K 3.5" DSDD standard */
+ { 80, 2, 15, 0xf9, 1200<<10, 0, 9 }, /* 1200K 5.25" DSHD standard */
+ { 80, 2, 18, 0xf0, 1440<<10, 0, 9 }, /* 1440K 3.5" DSHD standard */
+ { 80, 2, 21, 0xf0, 1680<<10, 0, 9 }, /* 1680K 3.5" DSHD extended */
+ { 82, 2, 21, 0xf0, 1722<<10, 0, 9 }, /* 1722K 3.5" DSHD extended */
+ { 80, 2, 36, 0xf0, 2880<<10, 0, 9 }, /* 2880K 3.5" DSED standard */
+ { 0, 0, 0, 0, 0, 0, 0 }
};
if ( fstat(fd, &st) )
@@ -61,7 +63,7 @@ get_geometry(int fd, struct image_geometry *geo)
memset(geo, 0, sizeof(*geo));
if ( S_ISBLK(st.st_mode) ) {
-#if 1 /*def BLKGETSIZE64*/
+#ifdef BLKGETSIZE64
if ( !ioctl(fd, BLKGETSIZE64, &blksize64) ) {
geo->size = blksize64;
} else
@@ -76,16 +78,26 @@ get_geometry(int fd, struct image_geometry *geo)
}
}
- if ( !ioctl(fd, HDIO_GETGEO, &hdgeo) ) {
+ if ( !ioctl(fd, FDGETPRM, &fdgeo) ) {
+ geo->c = fdgeo.track; /* IS THIS CORRECT?!? */
+ geo->h = fdgeo.head;
+ geo->s = fdgeo.sect;
+ geo->idbyte = 0xf0; /* Floppy disk "other" */
+ } else if ( !ioctl(fd, HDIO_GETGEO, &hdgeo) ) {
/* Got the geometry */
geo->c = hdgeo.cylinders; /* Don't use... may be truncated */
geo->h = hdgeo.heads;
geo->s = hdgeo.sectors;
+ geo->idbyte = 0xf8; /* Hard disk */
geo->offset = (uint64_t)hdgeo.start << geo->secshift;
- } else if ( !ioctl(fd, FDGETPRM, &fdgeo) ) {
- geo->c = fdgeo.track; /* IS THIS CORRECT?!? */
- geo->h = fdgeo.head;
- geo->s = fdgeo.sect;
+ }
+
+ /* If it's one of the standard floppy geometries set the ID byte correctly */
+ for ( sg = standard_geometries ; sg->size ; sg++ ) {
+ if ( sg->c == geo->c && sg->h == geo->h && sg->s == geo->s ) {
+ geo->idbyte = sg->idbyte;
+ break;
+ }
}
} else if ( S_ISREG(st.st_mode) ) {
/* Plain file; set the size and hunt for a standard geometry, otherwise
@@ -98,8 +110,8 @@ get_geometry(int fd, struct image_geometry *geo)
return 0;
}
}
-
- /* DO SOMETHING! */
+ /* FIX: Assume it's a hard disk and make something up */
+ geo->idbyte = 0xf8;
} else if ( S_ISDIR(st.st_mode) ) {
errno = EISDIR;
return -1;
@@ -128,8 +140,8 @@ int main(int argc, char *argv[])
exit(1);
}
- printf("c = %lu, h = %lu, s = %lu\n",
- geo.c, geo.h, geo.s);
+ printf("c = %lu, h = %lu, s = %lu, id = 0x%02x\n",
+ geo.c, geo.h, geo.s, geo.idbyte);
printf("size = %llu\n", geo.size);
printf("secshift = %d\n", geo.secshift);