Fail open_file_internal if the file is marked as deleted and we don't intend to recre...
authorcoderain <coderain@sdf.org>
Mon, 24 Jul 2017 21:40:53 +0000 (23:40 +0200)
committercoderain <coderain@sdf.org>
Mon, 24 Jul 2017 21:40:53 +0000 (23:40 +0200)
kernel/src/filesystem.c

index 97da66002c58d3f8701caf105f16334ceccf3116..c17edb1695a45907299a473b9b06544c6544d2f9 100644 (file)
@@ -334,9 +334,19 @@ dword_t open_file_internal(const char *path, file_instance_t **file_instance, dw
     mounted_volume_t *vol = get_volume_from_path(normalized_path);
     if (vol == NULL) return ERR_NOTFOUND;
 
-
     if (reference_by_name(normalized_path, OBJECT_FILE, (object_t**)&file))
     {
+        if (file->attributes & FILE_ATTR_DELETED)
+        {
+            if (!(mode & FILE_MODE_CREATE))
+            {
+                dereference(&file->header);
+                return ERR_NOTFOUND;
+            }
+
+            mode |= FILE_MODE_TRUNCATE;
+        }
+
         if (((file->global_mode ^ mode) & (FILE_MODE_SHARE_READ | FILE_MODE_SHARE_WRITE))
             || (!(file->global_mode & FILE_MODE_SHARE_READ) && (mode & FILE_MODE_READ))
             || (!(file->global_mode & FILE_MODE_SHARE_WRITE) && (mode & (FILE_MODE_WRITE | FILE_MODE_TRUNCATE))))