summaryrefslogtreecommitdiff
path: root/com32/gpllib
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-19 21:06:39 -0700
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-19 21:06:39 -0700
commit8f67b34b0b99fbae6264dc0a34331d557e674b86 (patch)
tree5c8edca5968b463f0549f8fec327a526657ba876 /com32/gpllib
parentd48c9f289d527656480199e844103a9907ebc4c5 (diff)
downloadsyslinux-8f67b34b0b99fbae6264dc0a34331d557e674b86.tar.gz
gpllib: Add read_mbr helper (disk)
Impact: disk API extension read_mbr takes a drive number and returns a pointer to a malloced buffer containing its mbr. Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Diffstat (limited to 'com32/gpllib')
-rw-r--r--com32/gpllib/disk/read.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/com32/gpllib/disk/read.c b/com32/gpllib/disk/read.c
index 0e0be8ec..1db60fdd 100644
--- a/com32/gpllib/disk/read.c
+++ b/com32/gpllib/disk/read.c
@@ -6,6 +6,17 @@
#include <disk/read.h>
/**
+ **/
+void *read_mbr(int drive)
+{
+ struct driveinfo drive_info;
+ drive_info.disk = drive;
+
+ /* MBR: lba = 0, 1 sector */
+ return read_sectors(&drive_info, 0, 1);
+}
+
+/**
* dev_read - read from a drive
* @drive: Drive number
* @lba: Position to start reading from
@@ -37,7 +48,7 @@ void *read_sectors(struct driveinfo* drive_info, const unsigned int lba,
void *buf = (char *)__com32.cs_bounce + sectors * SECTOR;
void *data;
- if (get_drive_parameters(drive_info))
+ if (get_drive_parameters(drive_info) == -1)
return NULL;
memset(&inreg, 0, sizeof inreg);
@@ -59,14 +70,14 @@ void *read_sectors(struct driveinfo* drive_info, const unsigned int lba,
if (!drive_info->cbios) {
/* We failed to get the geometry */
if (lba)
- return NULL; /* Can only read MBR */
+ return NULL; /* Can only read MBR */
s = 1; h = 0; c = 0;
} else
lba_to_chs(drive_info, lba, &s, &h, &c);
if ( s > 63 || h > 256 || c > 1023 )
- return NULL;
+ return NULL;
inreg.eax.w[0] = 0x0201; /* Read one sector */
inreg.ecx.b[1] = c & 0xff;