[kernel] Fix bugs related to opening/listing devices
authorcoderain <coderain@sdf.org>
Wed, 15 Nov 2017 04:21:09 +0000 (05:21 +0100)
committercoderain <coderain@sdf.org>
Wed, 15 Nov 2017 04:21:09 +0000 (05:21 +0100)
kernel/src/device.c

index 817d70b46b7dda714585a6583103ed1af236c3c9..a3398ce0d3104dbc8ed909fa775a8204e7cf5821 100644 (file)
@@ -284,8 +284,17 @@ dword_t device_unload_file(file_t *file)
     return ERR_SUCCESS;
 }
 
-dword_t device_open_file(file_instance_t **instance)
+dword_t device_open_file(file_instance_t **_instance)
 {
+    device_file_t *file = (device_file_t*)(*_instance)->global;
+
+    if (!file->device)
+    {
+        device_dir_inst_t *instance = (device_dir_inst_t*)realloc(*_instance, sizeof(device_dir_inst_t));
+        if (instance == NULL) return ERR_NOMEMORY;
+        *_instance = &instance->header;
+    }
+
     return ERR_SUCCESS;
 }
 
@@ -370,7 +379,7 @@ 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->device && !file->device) return ERR_ISNOTDIR;
+    if (file->device) return ERR_ISNOTDIR;
 
     device_dir_inst_t *instance = CONTAINER_OF(directory, device_dir_inst_t, header);