KPath: Replaced booleans with flags field.

* No functional change intended; I chose the flags in a way that it
  should still work even if I missed a reference.
This commit is contained in:
Axel Dörfler
2017-04-30 17:13:39 +02:00
parent e1b4aed0cb
commit eac83fb33e
6 changed files with 42 additions and 38 deletions
+11 -6
View File
@@ -1,5 +1,6 @@
/* /*
* Copyright 2004-2008, Ingo Weinhold, [email protected]. * Copyright 2004-2008, Ingo Weinhold, [email protected].
* Copyright 2008-2017, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _K_PATH_H #ifndef _K_PATH_H
@@ -13,23 +14,27 @@ namespace BPrivate {
namespace DiskDevice { namespace DiskDevice {
class KPath { class KPath {
public:
enum {
DEFAULT = 0,
NORMALIZE = 0x01,
TRAVERSE_LEAF_LINK = 0x02,
};
public: public:
KPath(size_t bufferSize = B_PATH_NAME_LENGTH); KPath(size_t bufferSize = B_PATH_NAME_LENGTH);
KPath(const char* path, bool normalize = false, KPath(const char* path, int32 flags = DEFAULT,
size_t bufferSize = B_PATH_NAME_LENGTH); size_t bufferSize = B_PATH_NAME_LENGTH);
KPath(const KPath& other); KPath(const KPath& other);
~KPath(); ~KPath();
status_t SetTo(const char* path, bool normalize = false, status_t SetTo(const char* path, int32 flags = DEFAULT,
size_t bufferSize = B_PATH_NAME_LENGTH, size_t bufferSize = B_PATH_NAME_LENGTH);
bool traverseLeafLink = false);
void Adopt(KPath& other); void Adopt(KPath& other);
status_t InitCheck() const; status_t InitCheck() const;
status_t SetPath(const char* path, status_t SetPath(const char* path,
bool normalize = false, int32 flags = DEFAULT);
bool traverseLeafLink = false);
const char* Path() const; const char* Path() const;
size_t Length() const size_t Length() const
{ return fPathLength; } { return fPathLength; }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2009, Haiku, Inc. All rights reserved. * Copyright 2004-2017, Haiku, Inc. All rights reserved.
* Copyright 2003-2004, Ingo Weinhold, [email protected]. All rights reserved. * Copyright 2003-2004, Ingo Weinhold, [email protected]. All rights reserved.
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -750,7 +750,7 @@ KDiskDeviceManager::CreateFileDevice(const char* filePath, bool* newlyCreated)
// normalize the file path // normalize the file path
KPath normalizedFilePath; KPath normalizedFilePath;
status_t error = normalizedFilePath.SetTo(filePath, true); status_t error = normalizedFilePath.SetTo(filePath, KPath::NORMALIZE);
if (error != B_OK) if (error != B_OK)
return error; return error;
filePath = normalizedFilePath.Path(); filePath = normalizedFilePath.Path();
@@ -55,7 +55,7 @@ KFileDiskDevice::SetTo(const char* filePath, const char* devicePath)
// (should actually not be necessary, since this method is only invoked // (should actually not be necessary, since this method is only invoked
// by the DDM, which has already normalized the path) // by the DDM, which has already normalized the path)
KPath tmpFilePath; KPath tmpFilePath;
status_t error = tmpFilePath.SetTo(filePath, true); status_t error = tmpFilePath.SetTo(filePath, KPath::NORMALIZE);
if (error != B_OK) if (error != B_OK)
return error; return error;
// check the file // check the file
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2011, Haiku, Inc. All Rights Reserved. * Copyright 2003-2017, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -285,7 +285,7 @@ _user_find_file_disk_device(const char *_filename, size_t *neededSize)
if (error != B_OK) if (error != B_OK)
return error; return error;
KPath path(filename, true); KPath path(filename, KPath::NORMALIZE);
partition_id id = B_ENTRY_NOT_FOUND; partition_id id = B_ENTRY_NOT_FOUND;
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
@@ -408,7 +408,7 @@ _user_register_file_device(const char *_filename)
if (error != B_OK) if (error != B_OK)
return error; return error;
KPath path(filename, true); KPath path(filename, KPath::NORMALIZE);
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
if (ManagerLocker locker = manager) { if (ManagerLocker locker = manager) {
+8 -9
View File
@@ -29,18 +29,18 @@ KPath::KPath(size_t bufferSize)
fPathLength(0), fPathLength(0),
fLocked(false) fLocked(false)
{ {
SetTo(NULL, false, bufferSize); SetTo(NULL, KPath::DEFAULT, bufferSize);
} }
KPath::KPath(const char* path, bool normalize, size_t bufferSize) KPath::KPath(const char* path, int32 flags, size_t bufferSize)
: :
fBuffer(NULL), fBuffer(NULL),
fBufferSize(0), fBufferSize(0),
fPathLength(0), fPathLength(0),
fLocked(false) fLocked(false)
{ {
SetTo(path, normalize, bufferSize); SetTo(path, flags, bufferSize);
} }
@@ -62,8 +62,7 @@ KPath::~KPath()
status_t status_t
KPath::SetTo(const char* path, bool normalize, size_t bufferSize, KPath::SetTo(const char* path, int32 flags, size_t bufferSize)
bool traverseLeafLink)
{ {
if (bufferSize == 0) if (bufferSize == 0)
bufferSize = B_PATH_NAME_LENGTH; bufferSize = B_PATH_NAME_LENGTH;
@@ -86,7 +85,7 @@ KPath::SetTo(const char* path, bool normalize, size_t bufferSize,
fBufferSize = bufferSize; fBufferSize = bufferSize;
fBuffer[0] = '\0'; fBuffer[0] = '\0';
return SetPath(path, normalize, traverseLeafLink); return SetPath(path, flags);
} }
@@ -112,16 +111,16 @@ KPath::InitCheck() const
status_t status_t
KPath::SetPath(const char* path, bool normalize, bool traverseLeafLink) KPath::SetPath(const char* path, int32 flags)
{ {
if (fBuffer == NULL) if (fBuffer == NULL)
return B_NO_INIT; return B_NO_INIT;
if (path != NULL) { if (path != NULL) {
if (normalize) { if ((flags & NORMALIZE) != 0) {
// normalize path // normalize path
status_t error = vfs_normalize_path(path, fBuffer, fBufferSize, status_t error = vfs_normalize_path(path, fBuffer, fBufferSize,
traverseLeafLink, (flags & TRAVERSE_LEAF_LINK) != 0,
team_get_kernel_team_id() == team_get_current_team_id()); team_get_kernel_team_id() == team_get_current_team_id());
if (error != B_OK) { if (error != B_OK) {
SetPath(NULL); SetPath(NULL);
+17 -17
View File
@@ -4339,7 +4339,7 @@ vfs_read_stat(int fd, const char* path, bool traverseLeafLink,
if (path) { if (path) {
// path given: get the stat of the node referred to by (fd, path) // path given: get the stat of the node referred to by (fd, path)
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8058,7 +8058,7 @@ dev_t
_kern_mount(const char* path, const char* device, const char* fsName, _kern_mount(const char* path, const char* device, const char* fsName,
uint32 flags, const char* args, size_t argsLength) uint32 flags, const char* args, size_t argsLength)
{ {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8069,7 +8069,7 @@ _kern_mount(const char* path, const char* device, const char* fsName,
status_t status_t
_kern_unmount(const char* path, uint32 flags) _kern_unmount(const char* path, uint32 flags)
{ {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8197,7 +8197,7 @@ _kern_open_entry_ref(dev_t device, ino_t inode, const char* name, int openMode,
int int
_kern_open(int fd, const char* path, int openMode, int perms) _kern_open(int fd, const char* path, int openMode, int perms)
{ {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8252,7 +8252,7 @@ _kern_open_dir(int fd, const char* path)
if (path == NULL) if (path == NULL)
return dir_open(fd, NULL, true);; return dir_open(fd, NULL, true);;
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8313,7 +8313,7 @@ _kern_create_dir_entry_ref(dev_t device, ino_t inode, const char* name,
status_t status_t
_kern_create_dir(int fd, const char* path, int perms) _kern_create_dir(int fd, const char* path, int perms)
{ {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8325,7 +8325,7 @@ status_t
_kern_remove_dir(int fd, const char* path) _kern_remove_dir(int fd, const char* path)
{ {
if (path) { if (path) {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8358,7 +8358,7 @@ status_t
_kern_read_link(int fd, const char* path, char* buffer, size_t* _bufferSize) _kern_read_link(int fd, const char* path, char* buffer, size_t* _bufferSize)
{ {
if (path) { if (path) {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8387,7 +8387,7 @@ _kern_read_link(int fd, const char* path, char* buffer, size_t* _bufferSize)
status_t status_t
_kern_create_symlink(int fd, const char* path, const char* toPath, int mode) _kern_create_symlink(int fd, const char* path, const char* toPath, int mode)
{ {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8400,8 +8400,8 @@ status_t
_kern_create_link(int pathFD, const char* path, int toFD, const char* toPath, _kern_create_link(int pathFD, const char* path, int toFD, const char* toPath,
bool traverseLeafLink) bool traverseLeafLink)
{ {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
KPath toPathBuffer(toPath, false, B_PATH_NAME_LENGTH + 1); KPath toPathBuffer(toPath, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK || toPathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK || toPathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8426,7 +8426,7 @@ _kern_create_link(int pathFD, const char* path, int toFD, const char* toPath,
status_t status_t
_kern_unlink(int fd, const char* path) _kern_unlink(int fd, const char* path)
{ {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8455,8 +8455,8 @@ _kern_unlink(int fd, const char* path)
status_t status_t
_kern_rename(int oldFD, const char* oldPath, int newFD, const char* newPath) _kern_rename(int oldFD, const char* oldPath, int newFD, const char* newPath)
{ {
KPath oldPathBuffer(oldPath, false, B_PATH_NAME_LENGTH + 1); KPath oldPathBuffer(oldPath, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
KPath newPathBuffer(newPath, false, B_PATH_NAME_LENGTH + 1); KPath newPathBuffer(newPath, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (oldPathBuffer.InitCheck() != B_OK || newPathBuffer.InitCheck() != B_OK) if (oldPathBuffer.InitCheck() != B_OK || newPathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8468,7 +8468,7 @@ _kern_rename(int oldFD, const char* oldPath, int newFD, const char* newPath)
status_t status_t
_kern_access(int fd, const char* path, int mode, bool effectiveUserGroup) _kern_access(int fd, const char* path, int mode, bool effectiveUserGroup)
{ {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8564,7 +8564,7 @@ _kern_write_stat(int fd, const char* path, bool traverseLeafLink,
if (path) { if (path) {
// path given: write the stat of the node referred to by (fd, path) // path given: write the stat of the node referred to by (fd, path)
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -8608,7 +8608,7 @@ int
_kern_open_attr(int fd, const char* path, const char* name, uint32 type, _kern_open_attr(int fd, const char* path, const char* name, uint32 type,
int openMode) int openMode)
{ {
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY; return B_NO_MEMORY;