[syslinux] gpllib write_sectors() patch

Don Hiatt donhiatt at gmail.com
Wed Apr 28 13:51:03 PDT 2010


- Fixes the buffer size in write.
- Adds a dev_write() to compliment dev_read()
- Adds a call to get_drive_parameters to be similar to read_sectors()

diff --git a/com32/gplinclude/disk/write.h b/com32/gplinclude/disk/write.h
index 89d26fc..407d660 100644
--- a/com32/gplinclude/disk/write.h
+++ b/com32/gplinclude/disk/write.h
@@ -16,7 +16,7 @@
 #define _WRITE_H_

 #include <disk/geom.h>
-
+int dev_write(int, void *, unsigned int, int);
 int write_sectors(const struct driveinfo *, const unsigned int,
 		  const void *, const int);
 int write_verify_sector(struct driveinfo *drive_info,
diff --git a/com32/gpllib/disk/write.c b/com32/gpllib/disk/write.c
index 89e530d..2eaa189 100644
--- a/com32/gpllib/disk/write.c
+++ b/com32/gpllib/disk/write.c
@@ -23,6 +23,25 @@
 #include <disk/write.h>

 /**
+ * dev_write - write to a drive
+ * @drive:	Drive number
+ * @buf:	Pre-allocated buffer for output
+ * @lba:	Position to start writing to
+ * @sectors:	Number of sectors to write
+ *
+ * High-level routine to read from a hard drive.
+ * Return the number of sectors written on success or -1 on failure.
+ * errno_disk contains the error number.
+ **/
+int dev_write(int drive, void *buf, unsigned int lba, int sectors)
+{
+    struct driveinfo drive_info;
+    drive_info.disk = drive;
+
+    return write_sectors(&drive_info, lba, buf, sectors);
+}
+
+/**
  * write_sectors - write several sectors from disk
  * @drive_info:		driveinfo struct describing the disk
  * @lba:		Position to write
@@ -37,9 +56,13 @@ int write_sectors(const struct driveinfo
*drive_info, const unsigned int lba,
 {
     com32sys_t inreg, outreg;
     struct ebios_dapa *dapa = __com32.cs_bounce;
-    void *buf = (char *)__com32.cs_bounce + size;
+    void *buf = (char *)__com32.cs_bounce + (size * SECTOR);
+
+    if (get_drive_parameters(drive_info) == -1) {
+      return -1;
+    }

-    memcpy(buf, data, size);
+    memcpy(buf, data, (size * SECTOR));
     memset(&inreg, 0, sizeof inreg);

     if (drive_info->ebios) {




More information about the Syslinux mailing list