Make the device interface universal.
authorcoderain <coderain@sdf.org>
Wed, 15 Feb 2017 05:45:34 +0000 (06:45 +0100)
committercoderain <coderain@sdf.org>
Wed, 15 Feb 2017 05:45:34 +0000 (06:45 +0100)
13 files changed:
kernel/include/cache.h
kernel/include/device.h
kernel/include/filesystem.h
kernel/include/video.h
kernel/src/device.c
kernel/src/drivers/floppy.c
kernel/src/drivers/fs/fat.c
kernel/src/drivers/ps2.c
kernel/src/drivers/ps2.h
kernel/src/drivers/serial.c
kernel/src/drivers/serial.h
kernel/src/drivers/speaker.c
kernel/src/video.c

index 9db9f7d9587206f0a3a141461bbc4ef70054fd2f..0943c701cb261f65046ab9493c812f2341119217 100644 (file)
@@ -36,9 +36,9 @@ typedef struct
     byte_t data[VARIABLE_SIZE];
 } cache_entry_t;
 
-#ifndef BLOCK_DEVICE_TYPEDEF
-#define BLOCK_DEVICE_TYPEDEF
-typedef struct block_device block_device_t;
+#ifndef DEVICE_TYPEDEF
+#define DEVICE_TYPEDEF
+typedef struct device device_t;
 #endif
 
 typedef struct
index 26ebb61c5c7cca42b7b36baffd8d0cd3e934fa2a..671448cd8618a1dc2f5000906e41e43ebb481946 100644 (file)
@@ -26,8 +26,7 @@
 #include <cache.h>
 #include <filesystem.h>
 
-#define MAX_BLOCK_DEV_NAME 32
-#define MAX_CHAR_DEV_NAME  32
+#define MAX_DEVICE_NAME 32
 
 #define BLOCK_DEVICE_REMOVABLE_MEDIA  (1 << 0)
 
 #define IOCTL_CHAR_DEV_CHECK_INPUT  0xC0000000
 #define IOCTL_CHAR_DEV_CHECK_OUTPUT 0xC0000001
 
-#ifndef BLOCK_DEVICE_TYPEDEF
-#define BLOCK_DEVICE_TYPEDEF
-typedef struct block_device block_device_t;
+#ifndef DEVICE_TYPEDEF
+#define DEVICE_TYPEDEF
+typedef struct device device_t;
 #endif
 
-typedef dword_t (*block_dev_init_proc_t)(void);
-typedef dword_t (*block_dev_cleanup_proc_t)(void);
-typedef dword_t (*block_dev_read_proc_t)(block_device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
-typedef dword_t (*block_dev_write_proc_t)(block_device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
-typedef dword_t (*block_dev_ioctl_proc_t)(
-    block_device_t *device,
+typedef dword_t (*device_init_proc_t)(void);
+typedef dword_t (*device_cleanup_proc_t)(void);
+typedef dword_t (*device_ioctl_proc_t)(
+    device_t *device,
     dword_t control_code,
     const void *in_buffer,
     size_t in_length,
@@ -57,26 +54,55 @@ typedef dword_t (*block_dev_ioctl_proc_t)(
     size_t out_length
 );
 
+typedef dword_t (*block_dev_read_proc_t)(device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
+typedef dword_t (*block_dev_write_proc_t)(device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
+
+typedef dword_t (*char_dev_read_proc_t)(device_t *device, void *buffer, size_t length, size_t *bytes_read);
+typedef dword_t (*char_dev_write_proc_t)(device_t *device, const void *buffer, size_t length, size_t *bytes_written);
+
+typedef enum
+{
+    BLOCK_DEVICE,
+    CHAR_DEVICE
+} device_type_t;
+
 typedef struct
 {
     list_entry_t list;
     dword_t mounted_devices;
-    block_dev_init_proc_t init_proc;
-    block_dev_cleanup_proc_t cleanup_proc;
+    device_init_proc_t init_proc;
+    device_cleanup_proc_t cleanup_proc;
     block_dev_read_proc_t read_proc;
     block_dev_write_proc_t write_proc;
-    block_dev_ioctl_proc_t ioctl_proc;
+    device_ioctl_proc_t ioctl_proc;
 } block_dev_driver_t;
 
-struct block_device
+typedef struct
+{
+    list_entry_t list;
+    device_init_proc_t init_proc;
+    device_cleanup_proc_t cleanup_proc;
+    char_dev_read_proc_t read_proc;
+    char_dev_write_proc_t write_proc;
+    device_ioctl_proc_t ioctl_proc;
+} char_dev_driver_t;
+
+typedef struct device
 {
     list_entry_t list;
+    device_type_t type;
+    char name[MAX_DEVICE_NAME];
+    resource_t resource;
     dword_t flags;
-    block_dev_driver_t *driver;
-    char name[MAX_BLOCK_DEV_NAME];
     qword_t capacity;
-    resource_t resource;
-};
+
+    union
+    {
+        void *driver;
+        block_dev_driver_t *block_driver;
+        char_dev_driver_t *char_driver;
+    };
+} device_t;
 
 typedef struct
 {
@@ -86,75 +112,30 @@ typedef struct
     dword_t bytes_per_sector;
 } block_dev_media_info_t;
 
-typedef struct char_device char_device_t;
-
-typedef dword_t (*char_dev_init_proc_t)(void);
-typedef dword_t (*char_dev_cleanup_proc_t)(void);
-typedef dword_t (*char_dev_read_proc_t)(char_device_t *device, void *buffer, size_t length, size_t *bytes_read);
-typedef dword_t (*char_dev_write_proc_t)(char_device_t *device, const void *buffer, size_t length, size_t *bytes_written);
-typedef dword_t (*char_dev_ioctl_proc_t)(
-    char_device_t *device,
-    dword_t control_code,
-    const void *in_buffer,
-    size_t in_length,
-    void *out_buffer,
-    size_t out_length
-);
-
-typedef struct
-{
-    list_entry_t list;
-    char_dev_init_proc_t init_proc;
-    char_dev_cleanup_proc_t cleanup_proc;
-    char_dev_read_proc_t read_proc;
-    char_dev_write_proc_t write_proc;
-    char_dev_ioctl_proc_t ioctl_proc;
-} char_dev_driver_t;
-
-struct char_device
-{
-    list_entry_t list;
-    char_dev_driver_t *driver;
-    char name[MAX_CHAR_DEV_NAME];
-    resource_t resource;
-};
-
 typedef struct
 {
     file_t header;
-
-    union
-    {
-        block_device_t *block_device;
-        char_device_t *char_device;
-    };
+    device_t *device;
 } device_file_t;
 
 typedef struct
 {
     file_instance_t header;
-
-    union
-    {
-        block_device_t *next_block_device;
-        char_device_t *next_char_device;
-    };
+    device_t *next_device;
 } device_dir_inst_t;
 
-block_device_t *get_block_device(const char *name);
+device_t *get_block_device(const char *name);
 dword_t register_block_dev_driver(block_dev_driver_t *driver);
 dword_t unregister_block_dev_driver(block_dev_driver_t *driver);
-block_device_t *get_block_device(const char *name);
-dword_t register_block_device(block_device_t *device);
-dword_t unregister_block_device(block_device_t *device);
-char_device_t *get_char_device(const char *name);
+dword_t register_block_device(device_t *device);
+dword_t unregister_block_device(device_t *device);
+device_t *get_char_device(const char *name);
 dword_t register_char_dev_driver(char_dev_driver_t *driver);
 dword_t unregister_char_dev_driver(char_dev_driver_t *driver);
-char_device_t *get_char_device(const char *name);
-dword_t register_char_device(char_device_t *device);
-dword_t unregister_char_device(char_device_t *device);
-dword_t block_device_read(block_device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
-dword_t block_device_write(block_device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
+dword_t register_char_device(device_t *device);
+dword_t unregister_char_device(device_t *device);
+dword_t device_read(device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
+dword_t device_write(device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
 dword_t device_ioctl(handle_t device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
 void device_init(void);
 
index 5d065940b3e847da426d01cc80039c0b0feea21b..d269beb5be0329b630b5248acbe3cca87cd02875 100644 (file)
@@ -120,7 +120,7 @@ struct mounted_volume
     list_entry_t list;
     dword_t flags;
     resource_t resource;
-    block_device_t *device;
+    device_t *device;
     qword_t open_files;
     fs_driver_t *driver;
 };
index 33770cc9640eca9c4c4a69b66e087b1df753932a..057649a99ca4311cf65bf2547f3b70aa8b398361 100644 (file)
@@ -137,7 +137,7 @@ typedef struct
 
 struct video_device
 {
-    char_device_t header;
+    device_t header;
     list_entry_t list;
     pci_device_t *pci_device;
     video_driver_t *driver;
index 2296f19b9278b3a4a5425df0888a2af36ac3a427..9cff553d0eb7abe5358947bb51ac6c61d582bccd 100644 (file)
@@ -61,7 +61,7 @@ static fs_driver_t device_fs_driver =
     .set_file    = device_set_file
 };
 
-static block_device_t block_device_volume_device =
+static device_t block_device_volume_device =
 {
     .flags  = 0,
     .driver = NULL,
@@ -79,7 +79,7 @@ static mounted_volume_t block_device_volume =
     .driver     = &device_fs_driver
 };
 
-static block_device_t char_device_volume_device =
+static device_t char_device_volume_device =
 {
     .flags  = 0,
     .driver = NULL,
@@ -97,15 +97,15 @@ static mounted_volume_t char_device_volume =
     .driver     = &device_fs_driver
 };
 
-block_device_t *get_block_device(const char *name)
+device_t *get_block_device(const char *name)
 {
     list_entry_t *i;
-    block_device_t *ptr = NULL;
+    device_t *ptr = NULL;
     acquire_resource_shared(&block_device_list_res);
 
     for (i = block_devices.next; i != &block_devices; i = i->next)
     {
-        ptr = CONTAINER_OF(i, block_device_t, list);
+        ptr = CONTAINER_OF(i, device_t, list);
         if (strcmp(ptr->name, name) == 0) break;
     }
 
@@ -142,16 +142,18 @@ dword_t unregister_block_dev_driver(block_dev_driver_t *driver)
     return ERR_SUCCESS;
 }
 
-dword_t register_block_device(block_device_t *device)
+dword_t register_block_device(device_t *device)
 {
     dword_t ret = ERR_SUCCESS;
     list_entry_t *i;
 
+    device->type = BLOCK_DEVICE;
+
     acquire_resource_exclusive(&block_device_list_res);
 
     for (i = block_devices.next; i != &block_devices; i = i->next)
     {
-        block_device_t *ptr = CONTAINER_OF(i, block_device_t, list);
+        device_t *ptr = CONTAINER_OF(i, device_t, list);
         
         if (strcmp(ptr->name, device->name) == 0)
         {
@@ -167,7 +169,7 @@ cleanup:
     return ret;
 }
 
-dword_t unregister_block_device(block_device_t *device)
+dword_t unregister_block_device(device_t *device)
 {
     acquire_resource_exclusive(&block_device_list_res);
     list_remove(&device->list);
@@ -176,15 +178,15 @@ dword_t unregister_block_device(block_device_t *device)
     return ERR_SUCCESS;
 }
 
-char_device_t *get_char_device(const char *name)
+device_t *get_char_device(const char *name)
 {
     list_entry_t *i;
-    char_device_t *device;
+    device_t *device;
 
     acquire_resource_shared(&block_device_list_res);
     for (i = char_devices.next; i != &char_devices; i = i->next)
     {
-        device = CONTAINER_OF(i, char_device_t, list);
+        device = CONTAINER_OF(i, device_t, list);
         if (strcmp(device->name, name) == 0) break;
     }
     release_resource(&block_device_list_res);
@@ -216,16 +218,18 @@ dword_t unregister_char_dev_driver(char_dev_driver_t *driver)
     return ERR_SUCCESS;
 }
 
-dword_t register_char_device(char_device_t *device)
+dword_t register_char_device(device_t *device)
 {
     dword_t ret = ERR_SUCCESS;
     list_entry_t *i;
 
+    device->type = CHAR_DEVICE;
+
     acquire_resource_exclusive(&char_device_list_res);
 
     for (i = char_devices.next; i != &char_devices; i = i->next)
     {
-        char_device_t *ptr = CONTAINER_OF(i, char_device_t, list);
+        device_t *ptr = CONTAINER_OF(i, device_t, list);
 
         if (strcmp(ptr->name, device->name) == 0)
         {
@@ -241,7 +245,7 @@ cleanup:
     return ret;
 }
 
-dword_t unregister_char_device(char_device_t *device)
+dword_t unregister_char_device(device_t *device)
 {
     acquire_resource_exclusive(&char_device_list_res);
     list_remove(&device->list);
@@ -270,13 +274,13 @@ dword_t device_load_file(file_t **_file)
     {
         if (file->header.volume == &block_device_volume)
         {
-            file->block_device = get_block_device(file->header.path);
-            return file->block_device ? ERR_SUCCESS : ERR_NOTFOUND;
+            file->device = get_block_device(file->header.path);
+            return file->device ? ERR_SUCCESS : ERR_NOTFOUND;
         }
         else if (file->header.volume == &char_device_volume)
         {
-            file->char_device = get_char_device(file->header.path);
-            return file->char_device ? ERR_SUCCESS : ERR_NOTFOUND;
+            file->device = get_char_device(file->header.path);
+            return file->device ? ERR_SUCCESS : ERR_NOTFOUND;
         }
         else
         {
@@ -285,7 +289,7 @@ dword_t device_load_file(file_t **_file)
     }
     else
     {
-        file->block_device = NULL;
+        file->device = NULL;
         return ERR_SUCCESS;
     } 
 }
@@ -330,21 +334,8 @@ dword_t device_read_file(file_instance_t *_file, void *buffer, qword_t offset, s
         safe_buffer = buffer;
     }
 
-    if (file->header.volume == &block_device_volume)
-    {
-        block_device_read(file->block_device, safe_buffer, offset, length, &safe_bytes_read);
-    }
-    else if (file->header.volume == &char_device_volume)
-    {
-        acquire_resource_shared(&file->char_device->resource);
-        ret = file->char_device->driver->read_proc(file->char_device, safe_buffer, length, &safe_bytes_read);
-        release_resource(&file->char_device->resource);
-    }
-    else
-    {
-        ret = ERR_INVALID;
-    }
-    
+    ret = device_read(file->device, safe_buffer, offset, length, &safe_bytes_read);
+
     if (get_previous_mode() == USER_MODE)
     {
         EH_TRY *bytes_read = safe_bytes_read;
@@ -377,20 +368,7 @@ dword_t device_write_file(file_instance_t *_file, const void *buffer, qword_t of
         safe_buffer = (void*)buffer;
     }
 
-    if (file->header.volume == &block_device_volume)
-    {
-        ret = block_device_write(file->block_device, safe_buffer, offset, length, &safe_bytes_written);
-    }
-    else if (file->header.volume == &char_device_volume)
-    {
-        acquire_resource_exclusive(&file->char_device->resource);
-        ret = file->char_device->driver->write_proc(file->char_device, safe_buffer, length, &safe_bytes_written);
-        release_resource(&file->char_device->resource);
-    }
-    else
-    {
-        ret = ERR_INVALID;
-    }
+        ret = device_write(file->device, safe_buffer, offset, length, &safe_bytes_written);
 
     if (get_previous_mode() == USER_MODE)
     {
@@ -407,29 +385,27 @@ dword_t device_write_file(file_instance_t *_file, const void *buffer, qword_t of
 dword_t device_list_dir(file_instance_t *directory, char *filename, bool_t continue_scan)
 {
     device_file_t *file = CONTAINER_OF(directory->global, device_file_t, header);
-    if (!file->block_device && !file->char_device) return ERR_ISNOTDIR;
+    if (!file->device && !file->device) return ERR_ISNOTDIR;
 
     device_dir_inst_t *instance = CONTAINER_OF(directory, device_dir_inst_t, header);
 
-    if (file->header.volume == &block_device_volume)
+    if (!continue_scan)
     {
-        if (!continue_scan) instance->next_block_device = CONTAINER_OF(block_devices.next, block_device_t, list);
-        if (&instance->next_block_device->list == &block_devices) return ERR_NOMORE;
-        strcpy(filename, instance->next_block_device->name);
-        instance->next_block_device = CONTAINER_OF(instance->next_block_device->list.next, block_device_t, list);
+        instance->next_device = CONTAINER_OF(file->header.volume == &block_device_volume
+                                             ? block_devices.next : char_devices.next,
+                                             device_t,
+                                             list);
     }
-    else if (file->header.volume == &char_device_volume)
-    {
-        if (!continue_scan) instance->next_char_device = CONTAINER_OF(char_devices.next, char_device_t, list);
-        if (&instance->next_char_device->list == &char_devices) return ERR_NOMORE;
-        strcpy(filename, instance->next_char_device->name);
-        instance->next_char_device = CONTAINER_OF(instance->next_char_device->list.next, char_device_t, list);
-    }
-    else
+
+    if (&instance->next_device->list == &block_devices
+        || &instance->next_device->list == &char_devices)
     {
-        return ERR_INVALID;
+        return ERR_NOMORE;
     }
 
+    strcpy(filename, instance->next_device->name);
+    instance->next_device = CONTAINER_OF(instance->next_device->list.next, device_t, list);
+
     return ERR_SUCCESS;
 }
 
@@ -438,21 +414,69 @@ dword_t device_set_file(file_t *file, dword_t info_type, const void *buffer, siz
     return ERR_INVALID;
 }
 
-dword_t block_device_read(block_device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read)
+dword_t device_read(device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read)
 {
+    dword_t ret;
     acquire_resource_shared(&device->resource);
-    dword_t ret = device->driver->read_proc(device, buffer, offset, length, bytes_read);
-    release_resource(&device->resource);
 
+    if (device->type == BLOCK_DEVICE)
+    {
+        ret = device->block_driver->read_proc(device, buffer, offset, length, bytes_read);
+    }
+    else if (device->type == CHAR_DEVICE)
+    {
+        ret = device->char_driver->read_proc(device, buffer, length, bytes_read);
+    }
+    else
+    {
+        ret = ERR_INVALID;
+    }
+    
+    release_resource(&device->resource);
     return ret;
 }
 
-dword_t block_device_write(block_device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written)
+dword_t device_write(device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written)
 {
+    dword_t ret;
     acquire_resource_exclusive(&device->resource);
-    dword_t ret = device->driver->write_proc(device, buffer, offset, length, bytes_written);
+
+    if (device->type == BLOCK_DEVICE)
+    {
+        ret = device->block_driver->write_proc(device, buffer, offset, length, bytes_written);
+    }
+    else if (device->type == CHAR_DEVICE)
+    {
+        ret = device->char_driver->write_proc(device, buffer, length, bytes_written);
+    }
+    else
+    {
+        ret = ERR_INVALID;
+    }
+    
     release_resource(&device->resource);
+    return ret;
+}
 
+dword_t device_ioctl_internal(device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length)
+{
+    dword_t ret;
+    acquire_resource_exclusive(&device->resource);
+    
+    if (device->type == BLOCK_DEVICE)
+    {
+        ret = device->block_driver->ioctl_proc(device, control_code, in_buffer, in_length, out_buffer, out_length);
+    }
+    else if (device->type == CHAR_DEVICE)
+    {
+        ret = device->char_driver->ioctl_proc(device, control_code, in_buffer, in_length, out_buffer, out_length);
+    }
+    else
+    {
+        ret = ERR_INVALID;
+    }
+    
+    release_resource(&device->resource);
     return ret;
 }
 
@@ -499,33 +523,7 @@ dword_t device_ioctl(handle_t device, dword_t control_code, const void *in_buffe
     }
 
     device_file_t *file = CONTAINER_OF(instance->global, device_file_t, header);
-
-    if (file->header.volume == &block_device_volume)
-    {
-        acquire_resource_exclusive(&file->block_device->resource);
-        ret = file->block_device->driver->ioctl_proc(file->block_device,
-                                                     control_code,
-                                                     safe_in_buffer,
-                                                     in_length,
-                                                     safe_out_buffer,
-                                                     out_length);
-        release_resource(&file->block_device->resource);
-    }
-    else if (file->header.volume == &char_device_volume)
-    {
-        acquire_resource_exclusive(&file->char_device->resource);
-        ret = file->char_device->driver->ioctl_proc(file->char_device,
-                                                    control_code,
-                                                    safe_in_buffer,
-                                                    in_length,
-                                                    safe_out_buffer,
-                                                    out_length);
-        release_resource(&file->char_device->resource);
-    }
-    else
-    {
-        ret = ERR_INVALID;
-    }
+    ret = device_ioctl_internal(file->device, control_code, safe_in_buffer, in_length, safe_out_buffer, out_length);
 
 cleanup:
     if (get_previous_mode() == USER_MODE)
@@ -540,6 +538,7 @@ cleanup:
         if (safe_in_buffer) free(safe_in_buffer);
         if (safe_out_buffer) free(safe_out_buffer);
     }
+    
     return ret;
 }
 
index d2fb526d8a29154e1a7a2d302a1d2f904719350a..206986e5256f5f50d332e8f73c1948d482843600 100644 (file)
@@ -31,10 +31,10 @@ static thread_t *floppy_thread = NULL;
 
 static dword_t floppy_init(void);
 static dword_t floppy_cleanup(void);
-static dword_t floppy_read(block_device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
-static dword_t floppy_write(block_device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
+static dword_t floppy_read(device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
+static dword_t floppy_write(device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
 static dword_t floppy_ioctl(
-    block_device_t *device,
+    device_t *device,
     dword_t control_code,
     const void *in_buffer,
     size_t in_length,
@@ -239,7 +239,7 @@ static dword_t floppy_init(void)
     {
         floppy_recalibrate(0);
 
-        block_device_t *device = (block_device_t*)malloc(sizeof(block_device_t));
+        device_t *device = (device_t*)malloc(sizeof(device_t));
         if (device == NULL)
         {
             ret = ERR_NOMEMORY;
@@ -259,7 +259,7 @@ static dword_t floppy_init(void)
     {
         floppy_recalibrate(1);
 
-        block_device_t *device = (block_device_t*)malloc(sizeof(block_device_t));
+        device_t *device = (device_t*)malloc(sizeof(device_t));
         if (device == NULL)
         {
             ret = ERR_NOMEMORY;
@@ -280,8 +280,8 @@ cleanup:
     {
         if (floppy_thread) terminate_thread_internal(floppy_thread, 0);
 
-        block_device_t *first = get_block_device(FLOPPY_FIRST_NAME);
-        block_device_t *second = get_block_device(FLOPPY_SECOND_NAME);
+        device_t *first = get_block_device(FLOPPY_FIRST_NAME);
+        device_t *second = get_block_device(FLOPPY_SECOND_NAME);
 
         if (first)
         {
@@ -303,8 +303,8 @@ cleanup:
 
 static dword_t floppy_cleanup(void)
 {
-    block_device_t *first = get_block_device(FLOPPY_FIRST_NAME);
-    block_device_t *second = get_block_device(FLOPPY_SECOND_NAME);
+    device_t *first = get_block_device(FLOPPY_FIRST_NAME);
+    device_t *second = get_block_device(FLOPPY_SECOND_NAME);
 
     if (first)
     {
@@ -322,7 +322,7 @@ static dword_t floppy_cleanup(void)
     return floppy_thread ? terminate_thread_internal(floppy_thread, 0) : ERR_SUCCESS;
 }
 
-static dword_t floppy_read(block_device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read)
+static dword_t floppy_read(device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read)
 {
     dword_t ret = ERR_SUCCESS;
     dword_t count = 0;
@@ -420,7 +420,7 @@ done:
     return ret;
 }
 
-static dword_t floppy_write(block_device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written)
+static dword_t floppy_write(device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written)
 {
     dword_t ret = ERR_SUCCESS;
     dword_t count = 0;
@@ -544,7 +544,7 @@ done:
     return ret;
 }
 
-static dword_t floppy_ioctl(block_device_t *device,
+static dword_t floppy_ioctl(device_t *device,
                             dword_t control_code,
                             const void *in_buffer,
                             size_t in_length,
index 9ccd16e36ec346fd2e6641ee287e0a250f7b546b..ba6df8ddaf13744f255bfb50ea8ea645edcea5c2 100644 (file)
@@ -157,11 +157,11 @@ static dword_t fatfs_get_next_cluster(fatfs_volume_t *volume, dword_t cluster)
 
     dword_t entry;
     dword_t bytes_read;
-    dword_t ret = block_device_read(volume->header.device,
-                                    (byte_t*)&entry,
-                                    entry_offset,
-                                    (volume->type == FAT32) ? sizeof(dword_t) : sizeof(word_t),
-                                    &bytes_read);
+    dword_t ret = device_read(volume->header.device,
+                              (byte_t*)&entry,
+                              entry_offset,
+                              (volume->type == FAT32) ? sizeof(dword_t) : sizeof(word_t),
+                              &bytes_read);
     if (ret != ERR_SUCCESS) return FATFS_INVALID_CLUSTER;
 
     switch (volume->type)
@@ -213,7 +213,7 @@ static dword_t fatfs_set_next_cluster(fatfs_volume_t *volume, dword_t cluster, d
     if (volume->type == FAT12)
     {
         dword_t bytes_read;
-        dword_t ret = block_device_read(volume->header.device, (byte_t*)&entry, entry_offset, sizeof(word_t), &bytes_read);
+        dword_t ret = device_read(volume->header.device, (byte_t*)&entry, entry_offset, sizeof(word_t), &bytes_read);
         if (ret != ERR_SUCCESS) return ret;
 
         entry &= 0xF000 >> ((cluster & 1) * 12);
@@ -225,11 +225,11 @@ static dword_t fatfs_set_next_cluster(fatfs_volume_t *volume, dword_t cluster, d
     }
 
     dword_t bytes_written;
-    return block_device_write(volume->header.device,
-                              (byte_t*)&entry,
-                              entry_offset,
-                              (volume->type == FAT32) ? sizeof(dword_t) : sizeof(word_t),
-                              &bytes_written);
+    return device_write(volume->header.device,
+                        (byte_t*)&entry,
+                        entry_offset,
+                        (volume->type == FAT32) ? sizeof(dword_t) : sizeof(word_t),
+                        &bytes_written);
 }
 
 static qword_t fatfs_get_cluster_offset(fatfs_volume_t *volume, dword_t number)
@@ -251,11 +251,11 @@ static qword_t fatfs_get_cluster_offset(fatfs_volume_t *volume, dword_t number)
 static dword_t fatfs_read_cluster(fatfs_volume_t *volume, dword_t number, void *buffer)
 {
     dword_t bytes_read;
-    return block_device_read(volume->header.device,
-                             buffer,
-                             fatfs_get_cluster_offset(volume, number),
-                             volume->sectors_per_cluster * volume->bytes_per_sector,
-                             &bytes_read);
+    return device_read(volume->header.device,
+                       buffer,
+                       fatfs_get_cluster_offset(volume, number),
+                       volume->sectors_per_cluster * volume->bytes_per_sector,
+                       &bytes_read);
 }
 
 static dword_t fatfs_zero_cluster(fatfs_volume_t *volume, dword_t number)
@@ -264,11 +264,11 @@ static dword_t fatfs_zero_cluster(fatfs_volume_t *volume, dword_t number)
     memset(buffer, 0, volume->sectors_per_cluster * volume->bytes_per_sector);
 
     dword_t bytes_written;
-    return block_device_write(volume->header.device,
-                              buffer,
-                              fatfs_get_cluster_offset(volume, number),
-                              volume->sectors_per_cluster * volume->bytes_per_sector,
-                              &bytes_written);
+    return device_write(volume->header.device,
+                        buffer,
+                        fatfs_get_cluster_offset(volume, number),
+                        volume->sectors_per_cluster * volume->bytes_per_sector,
+                        &bytes_written);
 }
 
 static dword_t fatfs_get_free_cluster(fatfs_volume_t *volume, dword_t *cluster)
@@ -473,11 +473,11 @@ static dword_t fatfs_resize_file(fatfs_file_t *file, qword_t new_size)
     file->header.size = new_size;
     fatfs_dirent_t dirent;
 
-    ret = block_device_read(volume->header.device,
-                            &dirent,
-                            fatfs_get_cluster_offset(volume, file->dirent_cluster) + (qword_t)file->dirent_index * sizeof(fatfs_dirent_t),
-                            sizeof(fatfs_dirent_t),
-                            &bytes);
+    ret = device_read(volume->header.device,
+                      &dirent,
+                      fatfs_get_cluster_offset(volume, file->dirent_cluster) + (qword_t)file->dirent_index * sizeof(fatfs_dirent_t),
+                      sizeof(fatfs_dirent_t),
+                      &bytes);
     if (ret != ERR_SUCCESS) return ret;
 
     dirent.size = file->header.size;
@@ -485,11 +485,11 @@ static dword_t fatfs_resize_file(fatfs_file_t *file, qword_t new_size)
     dirent.first_cluster_high = file->first_cluster >> 16;
     fatfs_pack_file_time(&current_time, &dirent.modification_date, &dirent.modification_time);
 
-    return block_device_write(volume->header.device,
-                              &dirent,
-                              fatfs_get_cluster_offset(volume, file->dirent_cluster) + (qword_t)file->dirent_index * sizeof(fatfs_dirent_t),
-                              sizeof(fatfs_dirent_t),
-                              &bytes);
+    return device_write(volume->header.device,
+                        &dirent,
+                        fatfs_get_cluster_offset(volume, file->dirent_cluster) + (qword_t)file->dirent_index * sizeof(fatfs_dirent_t),
+                        sizeof(fatfs_dirent_t),
+                        &bytes);
 }
 
 static inline dword_t fatfs_rw_file(object_t *object, byte_t *buffer, qword_t offset, size_t length, size_t *bytes, bool_t write)
@@ -560,20 +560,20 @@ static inline dword_t fatfs_rw_file(object_t *object, byte_t *buffer, qword_t of
 
         if (write)
         {
-            ret = block_device_write(volume->header.device,
-                                     &buffer[count],
-                                     fatfs_get_cluster_offset(volume, current_cluster) + (qword_t)offset_low,
-                                     amount,
-                                     &actually_rw);
+            ret = device_write(volume->header.device,
+                               &buffer[count],
+                               fatfs_get_cluster_offset(volume, current_cluster) + (qword_t)offset_low,
+                               amount,
+                               &actually_rw);
 
         }
         else
         {
-            ret = block_device_read(volume->header.device,
-                                    &buffer[count],
-                                    fatfs_get_cluster_offset(volume, current_cluster) + (qword_t)offset_low,
-                                    amount,
-                                    &actually_rw);
+            ret = device_read(volume->header.device,
+                              &buffer[count],
+                              fatfs_get_cluster_offset(volume, current_cluster) + (qword_t)offset_low,
+                              amount,
+                              &actually_rw);
         }
         
         if (ret != ERR_SUCCESS) goto cleanup;
@@ -606,9 +606,9 @@ static dword_t fatfs_mount(const char *device, dword_t flags)
 {
     fatfs_bpb_t bpb;
     fat_version_t type;
-    block_device_t *block_device = get_block_device(device);
+    device_t *block_device = get_block_device(device);
 
-    dword_t ret = block_device_read(block_device, (byte_t*)&bpb, 0ULL, sizeof(fatfs_bpb_t), NULL);
+    dword_t ret = device_read(block_device, (byte_t*)&bpb, 0ULL, sizeof(fatfs_bpb_t), NULL);
     if (ret != ERR_SUCCESS) return ret;
     if (bpb.sectors_per_cluster == 0) return ERR_INVALID;
 
@@ -783,11 +783,11 @@ static dword_t fatfs_load_file(file_t **_file)
         dirent.size = 0;
 
         dword_t actually_written;
-        ret = block_device_write(volume->header.device,
-                                 &dirent,
-                                 fatfs_get_cluster_offset(volume, cluster) + (qword_t)(entry * sizeof(fatfs_dirent_t)),
-                                 sizeof(fatfs_dirent_t),
-                                 &actually_written);
+        ret = device_write(volume->header.device,
+                           &dirent,
+                           fatfs_get_cluster_offset(volume, cluster) + (qword_t)(entry * sizeof(fatfs_dirent_t)),
+                           sizeof(fatfs_dirent_t),
+                           &actually_written);
         if (ret != ERR_SUCCESS) return ret;
     }
 
@@ -873,11 +873,11 @@ static dword_t fatfs_delete_file(mounted_volume_t *_volume, const char *path, bo
     byte_t deleted = FATFS_DELETED;
     size_t actually_written = 0;
 
-    ret = block_device_write(volume->header.device,
-                             &deleted,
-                             fatfs_get_cluster_offset(volume, cluster_num) + (qword_t)(entry_num * sizeof(fatfs_dirent_t)),
-                             sizeof(byte_t),
-                             &actually_written);
+    ret = device_write(volume->header.device,
+                       &deleted,
+                       fatfs_get_cluster_offset(volume, cluster_num) + (qword_t)(entry_num * sizeof(fatfs_dirent_t)),
+                       sizeof(byte_t),
+                       &actually_written);
     if (ret != ERR_SUCCESS) return ret;
 
     if (cluster_num != volume->root_dir_cluster)
@@ -940,11 +940,12 @@ static dword_t fatfs_delete_file(mounted_volume_t *_volume, const char *path, bo
                 parent_dirent.first_cluster_low = next_in_directory & 0xFFFF;
                 parent_dirent.first_cluster_high = next_in_directory >> 16;
 
-                block_device_write(volume->header.device,
-                                   &parent_dirent,
-                                   fatfs_get_cluster_offset(volume, parent_dir_entry_cluster) + (qword_t)(parent_dir_entry_number * sizeof(fatfs_dirent_t)),
-                                   sizeof(fatfs_dirent_t),
-                                   &actually_written);
+                device_write(volume->header.device,
+                             &parent_dirent,
+                             fatfs_get_cluster_offset(volume, parent_dir_entry_cluster)
+                             + (qword_t)(parent_dir_entry_number * sizeof(fatfs_dirent_t)),
+                             sizeof(fatfs_dirent_t),
+                             &actually_written);
             }
             else
             {
@@ -1011,11 +1012,11 @@ static dword_t fatfs_list_dir(file_instance_t *_directory, char *filename, bool_
     fatfs_dirent_t dirent;
     size_t actually_read;
 
-    dword_t ret = block_device_read(volume->header.device,
-                                    &dirent,
-                                    fatfs_get_cluster_offset(volume, instance->last_cluster) + (instance->last_offset & 0x1FF),
-                                    sizeof(fatfs_dirent_t),
-                                    &actually_read);
+    dword_t ret = device_read(volume->header.device,
+                              &dirent,
+                              fatfs_get_cluster_offset(volume, instance->last_cluster) + (instance->last_offset & 0x1FF),
+                              sizeof(fatfs_dirent_t),
+                              &actually_read);
     if (ret != ERR_SUCCESS) return ret;
 
     instance->last_offset += sizeof(fatfs_dirent_t);
index 1d2649f35a0bdd88dadaf482abe891bcc1130b86..0da15f45e0b014017a064c63914b43cc34b02a86 100644 (file)
@@ -25,9 +25,9 @@
 
 static dword_t ps2_init(void);
 static dword_t ps2_cleanup(void);
-static dword_t ps2_read(char_device_t *device, void *buffer, size_t length, size_t *bytes_read);
-static dword_t ps2_write(char_device_t *device, const void *buffer, size_t length, size_t *bytes_written);
-static dword_t ps2_ioctl(char_device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
+static dword_t ps2_read(device_t *device, void *buffer, size_t length, size_t *bytes_read);
+static dword_t ps2_write(device_t *device, const void *buffer, size_t length, size_t *bytes_written);
+static dword_t ps2_ioctl(device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
 
 static char_dev_driver_t ps2_driver_block = {
     .init_proc = ps2_init,
@@ -311,7 +311,7 @@ static dword_t ps2_cleanup(void)
     return ERR_SUCCESS;
 }
 
-static dword_t ps2_read(char_device_t *device, void *buffer, size_t length, size_t *bytes_read)
+static dword_t ps2_read(device_t *device, void *buffer, size_t length, size_t *bytes_read)
 {
     ps2_device_t *ps2_device = CONTAINER_OF(device, ps2_device_t, header);
     
@@ -368,12 +368,12 @@ static dword_t ps2_read(char_device_t *device, void *buffer, size_t length, size
     }
 }
 
-static dword_t ps2_write(char_device_t *device, const void *buffer, size_t length, size_t *bytes_written)
+static dword_t ps2_write(device_t *device, const void *buffer, size_t length, size_t *bytes_written)
 {
     return ERR_INVALID;
 }
 
-static dword_t ps2_ioctl(char_device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length)
+static dword_t ps2_ioctl(device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length)
 {
     ps2_device_t *ps2_device = CONTAINER_OF(device, ps2_device_t, header);
 
index 208903281691769312789e73032d63fed39de080..bf60631dc2df07eb6461b3491675189f5ea3cc57 100644 (file)
@@ -68,7 +68,7 @@ typedef enum
 
 typedef struct
 {
-    char_device_t header;
+    device_t header;
     byte_t port;
     ps2_device_type_t type;
     lock_t buffer_lock;
index 5b808d68995be3a5eeb98cc0b01d7ad69ff7f40d..3e5544aaf89b898526f219010dd9d0474ea7bdca 100644 (file)
@@ -27,9 +27,9 @@ static byte_t num_ports = 0;
 
 static dword_t serial_init(void);
 static dword_t serial_cleanup(void);
-static dword_t serial_read(char_device_t *device, void *buffer, size_t length, size_t *bytes_read);
-static dword_t serial_write(char_device_t *device, const void *buffer, size_t length, size_t *bytes_read);
-static dword_t serial_ioctl(char_device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
+static dword_t serial_read(device_t *device, void *buffer, size_t length, size_t *bytes_read);
+static dword_t serial_write(device_t *device, const void *buffer, size_t length, size_t *bytes_read);
+static dword_t serial_ioctl(device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
 
 static char_dev_driver_t serial_driver =
 {
@@ -54,7 +54,7 @@ static void set_baud_rate(serial_port_t *device, dword_t baud)
 static void serial_irq_handler(registers_t *regs, byte_t irq_num)
 {
     dword_t i;
-    char name[MAX_CHAR_DEV_NAME];
+    char name[MAX_DEVICE_NAME];
 
     UNUSED_PARAMETER(regs);
     UNUSED_PARAMETER(irq_num);
@@ -77,7 +77,7 @@ static dword_t serial_init(void)
     dword_t ret;
     dword_t i;
     word_t bda_data[9];
-    char name[MAX_CHAR_DEV_NAME];
+    char name[MAX_DEVICE_NAME];
 
     ret = read_physical((void*)0x400, &bda_data, sizeof(bda_data));
     if (ret != ERR_SUCCESS) return ret;
@@ -130,7 +130,7 @@ cleanup:
         for (i = 0; i < num_ports; i++)
         {
             sprintf(name, "COM%d", i + 1);
-            char_device_t *device = get_char_device(name);
+            device_t *device = get_char_device(name);
 
             if (device)
             {
@@ -149,12 +149,12 @@ cleanup:
 static dword_t serial_cleanup(void)
 {
     dword_t i;
-    char name[MAX_CHAR_DEV_NAME];
+    char name[MAX_DEVICE_NAME];
 
     for (i = 0; i < num_ports; i++)
     {
         sprintf(name, "COM%d", i + 1);
-        char_device_t *device = get_char_device(name);
+        device_t *device = get_char_device(name);
 
         if (device)
         {
@@ -169,7 +169,7 @@ static dword_t serial_cleanup(void)
     return ERR_SUCCESS;
 }
 
-static dword_t serial_read(char_device_t *device, void *buffer, size_t length, size_t *bytes_read)
+static dword_t serial_read(device_t *device, void *buffer, size_t length, size_t *bytes_read)
 {
     dword_t i;
     dword_t ret = ERR_SUCCESS;
@@ -199,7 +199,7 @@ static dword_t serial_read(char_device_t *device, void *buffer, size_t length, s
     return ret;
 }
 
-static dword_t serial_write(char_device_t *device, const void *buffer, size_t length, size_t *bytes_read)
+static dword_t serial_write(device_t *device, const void *buffer, size_t length, size_t *bytes_read)
 {
     dword_t i;
     dword_t ret = ERR_SUCCESS;
@@ -229,7 +229,7 @@ static dword_t serial_write(char_device_t *device, const void *buffer, size_t le
     return ret;
 }
 
-static dword_t serial_ioctl(char_device_t *_device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length)
+static dword_t serial_ioctl(device_t *_device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length)
 {
     serial_port_t *serial = CONTAINER_OF(_device, serial_port_t, header);
 
index 9d34f88992b03d291553281b5c95ed897910c8f6..cb84b0513fa777f144ab17f65fd39aa21a721b46 100644 (file)
@@ -52,7 +52,7 @@
 
 typedef struct
 {
-    char_device_t header;
+    device_t header;
     word_t port;
     semaphore_t read_mutex;
     semaphore_t write_mutex;
index feebcf27fe51939029e0ef646fa553c715a80f4a..0701f93a908c695b1e37d17077d41a4689ec1b3c 100644 (file)
@@ -23,7 +23,7 @@
 
 static dword_t speaker_init(void);
 static dword_t speaker_cleanup(void);
-static dword_t speaker_ioctl(char_device_t *device,
+static dword_t speaker_ioctl(device_t *device,
                              dword_t control_code,
                              const void *in_buffer,
                              size_t in_length,
@@ -65,7 +65,7 @@ static dword_t speaker_cleanup(void)
     return ERR_SUCCESS;
 }
 
-static dword_t speaker_ioctl(char_device_t *device,
+static dword_t speaker_ioctl(device_t *device,
                              dword_t control_code,
                              const void *in_buffer,
                              size_t in_length,
index 24cca88c4183bc224913505fd9252c41f269f421..c9be30713bf63e3f91c763f64679f4628c2daa02 100644 (file)
@@ -27,8 +27,8 @@
 
 static dword_t video_device_init(void);
 static dword_t video_device_cleanup(void);
-static dword_t video_device_read_write(char_device_t *device, void *buffer, size_t length, size_t *bytes_read);
-static dword_t video_device_ioctl(char_device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
+static dword_t video_device_read_write(device_t *device, void *buffer, size_t length, size_t *bytes_read);
+static dword_t video_device_ioctl(device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
 
 static dword_t video_default_init(list_entry_t *video_devices);
 static dword_t video_default_cleanup(void);
@@ -191,12 +191,12 @@ static dword_t video_device_cleanup(void)
     return ERR_SUCCESS;
 }
 
-static dword_t video_device_read_write(char_device_t *device, void *buffer, size_t length, size_t *bytes_read)
+static dword_t video_device_read_write(device_t *device, void *buffer, size_t length, size_t *bytes_read)
 {
     return ERR_INVALID;
 }
 
-static dword_t video_device_ioctl(char_device_t *device,
+static dword_t video_device_ioctl(device_t *device,
                                   dword_t control_code,
                                   const void *in_buffer,
                                   size_t in_length,