core: new diskio library
authorLiu Aleaxander <Aleaxander@gmail.com>
Mon, 15 Jun 2009 23:42:07 +0000 (07:42 +0800)
committerLiu Aleaxander <Aleaxander@gmail.com>
Mon, 15 Jun 2009 23:42:07 +0000 (07:42 +0800)
Beginnings of a diskio library capable of reading and writing, and
with proper handling of bounce buffers and segment boundaries.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
core/fs.c
core/include/disk.h
core/include/fs.h

index 617e3e5..d2a82c3 100644 (file)
--- a/core/fs.c
+++ b/core/fs.c
@@ -126,9 +126,6 @@ void device_init(struct device *dev, uint8_t device_num, sector_t offset)
         dev->cache_size = sizeof core_cache_buf;
     } else 
         dev->cache_data = NULL;
-
-    /* I just considered the floppy and disk now */
-    dev->read_sectors = read_sectors;
 }
 
 
index 44a425f..1eb9f03 100644 (file)
@@ -1,11 +1,13 @@
 #ifndef DISK_H
 #define DISK_H
 
+#include <stdint.h>
+
 #define SECTOR_SHIFT     9
 #define SECTOR_SIZE      (1 << SECTOR_SHIFT)
 
-typedef unsigned int sector_t;
-typedef unsigned int block_t;
+typedef uint64_t sector_t;
+typedef uint32_t block_t;
 
 extern void read_sectors(char *, sector_t, int);
 extern void getoneblk(char *, block_t, int);
index 0cb1bfc..0c837bd 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef FS_H
 #define FS_H
 
+#include <stddef.h>
+#include <stdbool.h>
 #include <com32.h>
 #include "core.h"
 #include "disk.h"
@@ -15,7 +17,7 @@ struct fs_info {
     struct device *fs_dev;
 };
 
-struct file{
+struct file {
     void*    open_file; /* points to the fs-specific open_file_t */
     struct   fs_info *fs;
     uint32_t file_len;
@@ -58,11 +60,16 @@ struct device {
 
     /* the sector size, 512B for disk and floppy, 2048B for CD */
     uint16_t sector_size;
+    uint8_t sector_shift;
+
+    /* CHS geometry */
+    uint8_t h, s;
+    uint8_t pad1;
 
     /* the start address of this partition(in sectors) */
     sector_t part_start;
        
-    void (*read_sectors)(char *, sector_t, int );
+    int (*rdwr_sectors)(struct device *, void *, sector_t, size_t, bool);
 
     /* 
      * I think we still need the cache_data filed here, 'cause hpa said 
@@ -76,6 +83,4 @@ struct device {
     uint32_t cache_size;
 };
 
-
-
 #endif /* FS_H */