blkdev: Support for flushing device caches on BLOCK_FLUSH_CACHE ioctl.
authorWill Sowerbutts <will@sowerbutts.com>
Sun, 11 Jan 2015 23:44:27 +0000 (23:44 +0000)
committerWill Sowerbutts <will@sowerbutts.com>
Sun, 11 Jan 2015 23:44:27 +0000 (23:44 +0000)
Kernel/dev/blkdev.c
Kernel/dev/blkdev.h

index 44e0397..3531514 100644 (file)
@@ -120,6 +120,25 @@ int blkdev_write(uint8_t minor, uint8_t rawflag, uint8_t flag)
     return blkdev_transfer(minor, false, rawflag);
 }
 
+int blkdev_ioctl(uint8_t minor, uint16_t request, char *data)
+{
+    blkdev_t *blk;
+    data; /* unused */
+
+    if(request != BLOCK_FLUSH_CACHE){
+       udata.u_error = ENXIO;
+       return -1;
+    }
+
+    /* we trust that blkdev_open() has already verified that this minor number is valid */
+    blk = &blkdev_table[minor >> 4];
+
+    if(blk->flush)
+       return blk->flush(blk->drive_number);
+    else
+       return 0;
+}
+
 /* FIXME: this would tidier and handle odd partition types sanely if split
    into blkdev_alloc() - just returns a device, and blkdev_scan() */
 
index a720dbf..c75e360 100644 (file)
@@ -4,12 +4,13 @@
 /* block device drives should call blkdev_add() for each block device found,
    and implement a sector transfer function matching the following prototype. */
 typedef bool (*transfer_function_t)(uint8_t drive, uint32_t lba, void *buffer, bool read_notwrite);
-
+typedef int (*flush_function_t)(uint8_t drive);
 
 /* the following details should be required only by partition parsing code */
 #define MAX_PARTITIONS 15                  /* must be at least 4, at most 15 */
 typedef struct {
     transfer_function_t transfer;          /* function to read and write sectors */
+    flush_function_t flush;                /* flush device cache */
     uint32_t drive_lba_count;              /* count of sectors on raw disk device */
     uint32_t lba_first[MAX_PARTITIONS];            /* LBA of first sector of each partition; 0 if partition absent */
     uint32_t lba_count[MAX_PARTITIONS];            /* count of sectors in each partition; 0 if partition absent */
@@ -24,5 +25,7 @@ extern void blkdev_scan(blkdev_t *blk, uint8_t flags);
 extern int blkdev_open(uint8_t minor, uint16_t flags);
 extern int blkdev_read(uint8_t minor, uint8_t rawflag, uint8_t flag);
 extern int blkdev_write(uint8_t minor, uint8_t rawflag, uint8_t flag);
+extern int blkdev_flush(uint8_t minor);
+extern int blkdev_ioctl(uint8_t minor, uint16_t request, char *data);
 
 #endif