[freenos] r350 committed - Modified the ATAController::read() function to correctly copy sectors ...

  • From: codesite-noreply@xxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Fri, 04 Sep 2009 23:09:37 +0000

Revision: 350
Author: nieklinnenbank
Date: Fri Sep  4 15:56:06 2009
Log: Modified the ATAController::read() function to correctly copy sectors to buffers.
Previously, the function ignored the offset argument.

http://code.google.com/p/freenos/source/detail?r=350

Modified:
 /trunk/srv/ata/ATAController.cpp

=======================================
--- /trunk/srv/ata/ATAController.cpp    Thu Sep  3 15:52:22 2009
+++ /trunk/srv/ata/ATAController.cpp    Fri Sep  4 15:56:06 2009
@@ -108,12 +108,14 @@

 Error ATAController::read(s8 *buffer, Size size, Size offset)
 {
-    u16 sectors = (size / 512), word;
-    u32 lba     = (offset / 512);
+    u8 sectors = CEIL(size, 512);
+    u16 block[256];
+    u32 lba     = offset / 512;
     Size result = 0;

     /* Verify LBA. */
-    if (lba > drives.head()->identity.sectors28)
+    if (!drives.head() ||
+         drives.head()->identity.sectors28 < lba)
     {
        return EIO;
     }
@@ -136,11 +138,18 @@
         /* Read out bytes. */
        for (int i = 0; i < 256; i++)
        {
-           word = inw(ATA_BASE_CMD0 + ATA_REG_DATA);
-           buffer[(i * 2)]     = (u8)  (word & 0xff);
-           buffer[(i * 2) + 1] = (u8) ((word & 0xff00) >> 8);
-       }
-       result += 512;
+           block[i] = inw(ATA_BASE_CMD0 + ATA_REG_DATA);
+       }
+       /* Calculate maximum bytes. */
+       Size bytes = (size - result) < 512 - (offset % 512) ?
+                    (size - result) : 512 - (offset % 512);
+
+       /* Copy to buffer. */
+       memcpy(buffer + result, ((u8 *)block) + (offset % 512), bytes);
+
+       /* Update state. */
+       result += bytes;
+       offset += bytes;
     }
     return result;
 }

Other related posts:

  • » [freenos] r350 committed - Modified the ATAController::read() function to correctly copy sectors ... - codesite-noreply