From 93303d0ab759f2c5e1842fc7b1416f7f6c4e1106 Mon Sep 17 00:00:00 2001 From: nakst <> Date: Wed, 1 Sep 2021 20:41:52 +0100 Subject: [PATCH] rename file write access flags --- desktop/desktop.cpp | 4 ++-- desktop/os.header | 4 ++-- desktop/posix.cpp | 4 ++-- desktop/syscall.cpp | 8 ++++---- kernel/files.cpp | 14 +++++++------- kernel/memory.cpp | 2 +- kernel/posix.cpp | 10 +++++----- kernel/syscall.cpp | 14 +++++++------- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/desktop/desktop.cpp b/desktop/desktop.cpp index c1879cc..bc4b811 100644 --- a/desktop/desktop.cpp +++ b/desktop/desktop.cpp @@ -1371,7 +1371,7 @@ void ApplicationInstanceRequestSave(ApplicationInstance *instance, const char *n document->temporarySavePath = nullptr; EsHandle fileHandle; - m.tabOperation.error = TemporaryFileCreate(&fileHandle, &document->temporarySavePath, &document->temporarySavePathBytes, ES_FILE_WRITE_EXCLUSIVE); + m.tabOperation.error = TemporaryFileCreate(&fileHandle, &document->temporarySavePath, &document->temporarySavePathBytes, ES_FILE_WRITE); if (m.tabOperation.error == ES_SUCCESS) { document->currentWriter = instance->embeddedWindowID; @@ -1904,7 +1904,7 @@ void DesktopMessage2(EsMessage *message, uint8_t *buffer, EsBuffer *pipe) { EsHandle handle; char *path; size_t pathBytes; - EsError error = TemporaryFileCreate(&handle, &path, &pathBytes, ES_FILE_WRITE_EXCLUSIVE); + EsError error = TemporaryFileCreate(&handle, &path, &pathBytes, ES_FILE_WRITE); if (error == ES_SUCCESS) { if (desktop.nextClipboardFile) { diff --git a/desktop/os.header b/desktop/os.header index a419cc9..ff28905 100644 --- a/desktop/os.header +++ b/desktop/os.header @@ -378,8 +378,8 @@ define ES_TEXT_PLAN_NO_FONT_SUBSTITUTION (1 << 12) define ES_FILE_READ_SHARED (0x1) // Read-only. The file can still be opened for writing. define ES_FILE_READ (0x2) // Read-only. The file will not openable for writing. This will fail if the file is already opened for writing. -define ES_FILE_WRITE (0x4) // Read-write. The file can still be opened for writing. This will fail if the file is already opened for exclusive writing. -define ES_FILE_WRITE_EXCLUSIVE (0x8) // Read-write. The file will not openable for writing. This will fail if the file is already opened for writing. +define ES_FILE_WRITE_SHARED (0x4) // Read-write. The file can still be opened for writing. This will fail if the file is already opened for exclusive writing. +define ES_FILE_WRITE (0x8) // Read-write. The file will not openable for writing. This will fail if the file is already opened for writing. define ES_NODE_FILE (0) define ES_NODE_DIRECTORY (0x10) diff --git a/desktop/posix.cpp b/desktop/posix.cpp index 1f12ab7..180d45a 100644 --- a/desktop/posix.cpp +++ b/desktop/posix.cpp @@ -295,7 +295,7 @@ long EsPOSIXSystemCall(long n, long a1, long a2, long a3, long a4, long a5, long node.handle = NodeFindMountPoint(EsLiteral("|POSIX:"))->base; size_t pathBytes; char *path = EsPOSIXConvertPath((const char *) a1, &pathBytes, false); - EsError error = EsSyscall(ES_SYSCALL_NODE_OPEN, (uintptr_t) path, pathBytes, ES_NODE_FAIL_IF_NOT_FOUND | ES_FILE_WRITE_EXCLUSIVE, (uintptr_t) &node); + EsError error = EsSyscall(ES_SYSCALL_NODE_OPEN, (uintptr_t) path, pathBytes, ES_NODE_FAIL_IF_NOT_FOUND | ES_FILE_WRITE, (uintptr_t) &node); EsHeapFree(path); if (error == ES_ERROR_FILE_DOES_NOT_EXIST) returnValue = -ENOENT; else if (error == ES_ERROR_PATH_NOT_TRAVERSABLE) returnValue = -ENOTDIR; @@ -315,7 +315,7 @@ long EsPOSIXSystemCall(long n, long a1, long a2, long a3, long a4, long a5, long node.handle = NodeFindMountPoint(EsLiteral("|POSIX:"))->base; size_t pathBytes; char *path = EsPOSIXConvertPath((const char *) a1, &pathBytes, false); - EsError error = EsSyscall(ES_SYSCALL_NODE_OPEN, (uintptr_t) path, pathBytes, ES_NODE_FAIL_IF_NOT_FOUND | ES_FILE_WRITE_EXCLUSIVE, (uintptr_t) &node); + EsError error = EsSyscall(ES_SYSCALL_NODE_OPEN, (uintptr_t) path, pathBytes, ES_NODE_FAIL_IF_NOT_FOUND | ES_FILE_WRITE, (uintptr_t) &node); EsHeapFree(path); if (error == ES_ERROR_FILE_DOES_NOT_EXIST) returnValue = -ENOENT; else if (error == ES_ERROR_PATH_NOT_TRAVERSABLE) returnValue = -ENOTDIR; diff --git a/desktop/syscall.cpp b/desktop/syscall.cpp index 6092dbf..97194e7 100644 --- a/desktop/syscall.cpp +++ b/desktop/syscall.cpp @@ -139,7 +139,7 @@ EsError EsFileWriteAllGather(const char *filePath, ptrdiff_t filePathLength, con filePathLength = EsCStringLength(filePath); } - EsFileInformation information = EsFileOpen((char *) filePath, filePathLength, ES_FILE_WRITE_EXCLUSIVE | ES_NODE_CREATE_DIRECTORIES); + EsFileInformation information = EsFileOpen((char *) filePath, filePathLength, ES_FILE_WRITE | ES_NODE_CREATE_DIRECTORIES); if (ES_SUCCESS != information.error) { return information.error; @@ -237,7 +237,7 @@ EsError EsFileCopy(const char *source, ptrdiff_t sourceBytes, const char *destin EsFileInformation sourceFile = EsFileOpen(source, sourceBytes, ES_FILE_READ | ES_NODE_FILE | ES_NODE_FAIL_IF_NOT_FOUND); if (sourceFile.error == ES_SUCCESS) { - EsFileInformation destinationFile = EsFileOpen(destination, destinationBytes, ES_FILE_WRITE_EXCLUSIVE | ES_NODE_FILE | ES_NODE_FAIL_IF_FOUND); + EsFileInformation destinationFile = EsFileOpen(destination, destinationBytes, ES_FILE_WRITE | ES_NODE_FILE | ES_NODE_FAIL_IF_FOUND); if (destinationFile.error == ES_SUCCESS) { error = EsFileResize(destinationFile.handle, sourceFile.size); @@ -473,7 +473,7 @@ void EsBatch(EsBatchCall *calls, size_t count) { EsError EsPathDelete(const char *path, ptrdiff_t pathBytes) { _EsNodeInformation node; if (pathBytes == -1) pathBytes = EsCStringLength(path); - EsError error = NodeOpen(path, pathBytes, ES_NODE_FAIL_IF_NOT_FOUND | ES_FILE_WRITE_EXCLUSIVE, &node); + EsError error = NodeOpen(path, pathBytes, ES_NODE_FAIL_IF_NOT_FOUND | ES_FILE_WRITE, &node); if (ES_CHECK_ERROR(error)) return error; error = EsSyscall(ES_SYSCALL_NODE_DELETE, node.handle, 0, 0, 0); EsHandleClose(node.handle); @@ -486,7 +486,7 @@ EsError EsFileDelete(EsHandle handle) { void *EsFileMap(const char *path, ptrdiff_t pathBytes, size_t *fileSize, uint32_t flags) { EsFileInformation information = EsFileOpen(path, pathBytes, - ES_NODE_FAIL_IF_NOT_FOUND | ((flags & ES_MAP_OBJECT_READ_WRITE) ? ES_FILE_WRITE_EXCLUSIVE : ES_FILE_READ)); + ES_NODE_FAIL_IF_NOT_FOUND | ((flags & ES_MAP_OBJECT_READ_WRITE) ? ES_FILE_WRITE : ES_FILE_READ)); if (ES_CHECK_ERROR(information.error)) { return nullptr; diff --git a/kernel/files.cpp b/kernel/files.cpp index e8bd4d2..a08af86 100644 --- a/kernel/files.cpp +++ b/kernel/files.cpp @@ -1077,7 +1077,7 @@ EsError FSNodeOpenHandle(KNode *node, uint32_t flags, uint8_t mode) { if (flags & ES_FILE_READ) { if (file->countWrite > 0) return ES_ERROR_FILE_HAS_WRITERS; - } else if (flags & ES_FILE_WRITE_EXCLUSIVE) { + } else if (flags & ES_FILE_WRITE) { if (flags & _ES_NODE_FROM_WRITE_EXCLUSIVE) { if (!file->countWrite || (~file->flags & NODE_HAS_EXCLUSIVE_WRITER)) { KernelPanic("FSNodeOpenHandle - File %x is invalid state for a handle to have the _ES_NODE_FROM_WRITE_EXCLUSIVE flag.\n", file); @@ -1087,19 +1087,19 @@ EsError FSNodeOpenHandle(KNode *node, uint32_t flags, uint8_t mode) { return ES_ERROR_FILE_CANNOT_GET_EXCLUSIVE_USE; } } - } else if (flags & ES_FILE_WRITE) { + } else if (flags & ES_FILE_WRITE_SHARED) { if ((file->flags & NODE_HAS_EXCLUSIVE_WRITER) || file->countWrite < 0) return ES_ERROR_FILE_IN_EXCLUSIVE_USE; } - if (flags & (ES_FILE_WRITE | ES_FILE_WRITE_EXCLUSIVE)) { + if (flags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE)) { if (!file->fileSystem->write) { return ES_ERROR_FILE_ON_READ_ONLY_VOLUME; } } - if (flags & (ES_FILE_WRITE | ES_FILE_WRITE_EXCLUSIVE)) file->countWrite++; + if (flags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE)) file->countWrite++; if (flags & ES_FILE_READ) file->countWrite--; - if (flags & ES_FILE_WRITE_EXCLUSIVE) __sync_fetch_and_or(&node->flags, NODE_HAS_EXCLUSIVE_WRITER); + if (flags & ES_FILE_WRITE) __sync_fetch_and_or(&node->flags, NODE_HAS_EXCLUSIVE_WRITER); } NODE_INCREMENT_HANDLE_COUNT(node); @@ -1146,7 +1146,7 @@ void FSNodeCloseHandle(KNode *node, uint32_t flags) { if (node->directoryEntry->type == ES_NODE_FILE) { FSFile *file = (FSFile *) node; - if ((flags & (ES_FILE_WRITE | ES_FILE_WRITE_EXCLUSIVE))) { + if ((flags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE))) { if (file->countWrite <= 0) KernelPanic("FSNodeCloseHandle - Invalid countWrite on node %x.\n", node); file->countWrite--; } @@ -1156,7 +1156,7 @@ void FSNodeCloseHandle(KNode *node, uint32_t flags) { file->countWrite++; } - if ((flags & ES_FILE_WRITE_EXCLUSIVE) && file->countWrite == 0) { + if ((flags & ES_FILE_WRITE) && file->countWrite == 0) { if (~file->flags & NODE_HAS_EXCLUSIVE_WRITER) KernelPanic("FSNodeCloseHandle - Missing exclusive flag on node %x.\n", node); __sync_fetch_and_and(&node->flags, ~NODE_HAS_EXCLUSIVE_WRITER); } diff --git a/kernel/memory.cpp b/kernel/memory.cpp index 1c6366f..4f8b314 100644 --- a/kernel/memory.cpp +++ b/kernel/memory.cpp @@ -1056,7 +1056,7 @@ void *MMMapFile(MMSpace *space, FSFile *node, EsFileOffset offset, size_t bytes, MMRegion *region = nullptr; uint64_t fileHandleFlags = ES_NODE_PREVENT_RESIZE - | (protection == ES_MAP_OBJECT_READ_WRITE ? ES_FILE_WRITE : ES_FILE_READ_SHARED); + | (protection == ES_MAP_OBJECT_READ_WRITE ? ES_FILE_WRITE_SHARED : ES_FILE_READ_SHARED); bool decommit = false; // Register a handle to the node. diff --git a/kernel/posix.cpp b/kernel/posix.cpp index 121c291..30f8965 100644 --- a/kernel/posix.cpp +++ b/kernel/posix.cpp @@ -236,9 +236,9 @@ namespace POSIX { else if (flags & O_CREAT) {} else openFlags |= ES_NODE_FAIL_IF_NOT_FOUND; if (flags & O_DIRECTORY) openFlags |= ES_NODE_DIRECTORY; - if (flags & O_APPEND) openFlags |= ES_FILE_WRITE; - else if (flags & O_RDWR) openFlags |= ES_FILE_WRITE; - else if (flags & O_WRONLY) openFlags |= ES_FILE_WRITE; + if (flags & O_APPEND) openFlags |= ES_FILE_WRITE_SHARED; + else if (flags & O_RDWR) openFlags |= ES_FILE_WRITE_SHARED; + else if (flags & O_WRONLY) openFlags |= ES_FILE_WRITE_SHARED; else if (!(flags & O_PATH)) openFlags |= ES_FILE_READ; KNodeInformation information = FSNodeOpen(path, pathLength, openFlags, (KNode *) syscall.arguments[4]); @@ -408,7 +408,7 @@ namespace POSIX { SYSCALL_HANDLE_POSIX(syscall.arguments[0], file, 1); SYSCALL_BUFFER_POSIX(syscall.arguments[1], syscall.arguments[2], 3, true); - if (file->type == POSIX_FILE_NORMAL && !(file->openFlags & (ES_FILE_WRITE | ES_FILE_WRITE_EXCLUSIVE))) { + if (file->type == POSIX_FILE_NORMAL && !(file->openFlags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE))) { return -EACCES; } @@ -428,7 +428,7 @@ namespace POSIX { size_t bytesWritten = 0; - if (file->type == POSIX_FILE_NORMAL && !(file->openFlags & (ES_FILE_WRITE | ES_FILE_WRITE_EXCLUSIVE))) { + if (file->type == POSIX_FILE_NORMAL && !(file->openFlags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE))) { return -EACCES; } diff --git a/kernel/syscall.cpp b/kernel/syscall.cpp index 1d5533e..2313fcd 100644 --- a/kernel/syscall.cpp +++ b/kernel/syscall.cpp @@ -702,7 +702,7 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_MEMORY_MAP_OBJECT) { if (file->directoryEntry->type != ES_NODE_FILE) SYSCALL_RETURN(ES_FATAL_ERROR_INCORRECT_NODE_TYPE, true); if (argument3 == ES_MAP_OBJECT_READ_WRITE) { - if (!(object.flags & (ES_FILE_WRITE | ES_FILE_WRITE_EXCLUSIVE))) { + if (!(object.flags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE))) { SYSCALL_RETURN(ES_FATAL_ERROR_INCORRECT_FILE_ACCESS, true); } } else { @@ -774,7 +774,7 @@ SYSCALL_IMPLEMENT(syscallName) { \ SYSCALL_SHARE_OBJECT(ES_SYSCALL_PROCESS_SHARE, KERNEL_OBJECT_PROCESS, share.flags); SYSCALL_SHARE_OBJECT(ES_SYSCALL_NODE_SHARE, KERNEL_OBJECT_NODE, - (argument3 & 1) && (share.flags & (ES_FILE_WRITE | ES_FILE_WRITE_EXCLUSIVE)) ? ES_FILE_READ_SHARED : share.flags); + (argument3 & 1) && (share.flags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE)) ? ES_FILE_READ_SHARED : share.flags); SYSCALL_IMPLEMENT(ES_SYSCALL_VOLUME_GET_INFORMATION) { if (~currentProcess->permissions & ES_PERMISSION_GET_VOLUME_INFORMATION) { @@ -806,7 +806,7 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_NODE_OPEN) { flags &= ~_ES_NODE_FROM_WRITE_EXCLUSIVE | _ES_NODE_NO_WRITE_BASE; - bool needWritePermission = flags & (ES_FILE_WRITE_EXCLUSIVE | ES_FILE_WRITE | _ES_NODE_DIRECTORY_WRITE); + bool needWritePermission = flags & (ES_FILE_WRITE | ES_FILE_WRITE_SHARED | _ES_NODE_DIRECTORY_WRITE); char *path; if (argument1 > K_MAX_PATH) SYSCALL_RETURN(ES_FATAL_ERROR_OUT_OF_RANGE, true); @@ -840,7 +840,7 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_NODE_OPEN) { SYSCALL_RETURN(_information.error, false); } - if (flags & ES_FILE_WRITE_EXCLUSIVE) { + if (flags & ES_FILE_WRITE) { // Mark this handle as being the exclusive writer for this file. // This way, when the handle is used, OpenHandleToObject succeeds. // The exclusive writer flag will only be removed from the file where countWrite drops to zero. @@ -866,7 +866,7 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_NODE_DELETE) { SYSCALL_RETURN(ES_ERROR_FILE_PERMISSION_NOT_GRANTED, false); } - if (node->directoryEntry->type == ES_NODE_FILE && (~object.flags & ES_FILE_WRITE_EXCLUSIVE)) { + if (node->directoryEntry->type == ES_NODE_FILE && (~object.flags & ES_FILE_WRITE)) { SYSCALL_RETURN(ES_FATAL_ERROR_INCORRECT_FILE_ACCESS, true); } @@ -919,7 +919,7 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_FILE_WRITE_SYNC) { SYSCALL_BUFFER(argument3, argument2, 1, true /* write */); - if (object.flags & (ES_FILE_WRITE | ES_FILE_WRITE_EXCLUSIVE)) { + if (object.flags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE)) { size_t result = FSFileWriteSync(file, (void *) argument3, argument1, argument2, (_region1->flags & MM_REGION_FILE) ? FS_FILE_ACCESS_USER_BUFFER_MAPPED : 0); SYSCALL_RETURN(result, false); @@ -943,7 +943,7 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_FILE_RESIZE) { if (file->directoryEntry->type != ES_NODE_FILE) SYSCALL_RETURN(ES_FATAL_ERROR_INCORRECT_NODE_TYPE, true); - if (object.flags & (ES_FILE_WRITE | ES_FILE_WRITE_EXCLUSIVE)) { + if (object.flags & (ES_FILE_WRITE_SHARED | ES_FILE_WRITE)) { SYSCALL_RETURN(FSFileResize(file, argument1), false); } else { SYSCALL_RETURN(ES_FATAL_ERROR_INCORRECT_FILE_ACCESS, true);