From 41cf3876974fa4f855fed199a3839868c4fde86f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 27 Nov 2004 13:47:18 +0000 Subject: [PATCH] bfs_create() now only checks for write access in the parent directory if a file really has to be created, thanks to Ingo for reporting this. Inode::Create() now checks for write access to the inode when O_TRUNC is set. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10272 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Inode.cpp | 9 +++++++++ src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp | 4 ---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index 4425381197..ceee31b55c 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -2109,6 +2109,11 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name, int32 m return B_NOT_ALLOWED; if (openMode & O_TRUNC) { + // we need write access in order to truncate the file + status = inode->CheckPermission(W_OK); + if (status != B_OK) + return status; + // truncate the existing file WriteLocked locked(inode->Lock()); @@ -2131,6 +2136,10 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name, int32 m } else if (parent && (mode & S_ATTR_DIR) == 0) return B_BAD_VALUE; + // do we have the power to create new files at all? + if (parent != NULL && (status = parent->CheckPermissions(W_OK)) != B_OK) + RETURN_ERROR(status); + // allocate space for the new inode InodeAllocator allocator(transaction); block_run run; diff --git a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp index 9bd9375b0c..c317ecdd59 100644 --- a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp @@ -726,10 +726,6 @@ bfs_create(void *_ns, void *_directory, const char *name, int omode, int mode, if (!directory->IsDirectory()) RETURN_ERROR(B_BAD_TYPE); - status_t status = directory->CheckPermissions(W_OK); - if (status < B_OK) - RETURN_ERROR(status); - // We are creating the cookie at this point, so that we don't have // to remove the inode if we don't have enough free memory later... file_cookie *cookie = (file_cookie *)malloc(sizeof(file_cookie));