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 13:42:16 +02:00
parent e1b4aed0cb
commit eac83fb33e
6 changed files with 42 additions and 38 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright 2004-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2008-2017, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _K_PATH_H
@ -13,23 +14,27 @@ namespace BPrivate {
namespace DiskDevice {
class KPath {
public:
enum {
DEFAULT = 0,
NORMALIZE = 0x01,
TRAVERSE_LEAF_LINK = 0x02,
};
public:
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);
KPath(const KPath& other);
~KPath();
status_t SetTo(const char* path, bool normalize = false,
size_t bufferSize = B_PATH_NAME_LENGTH,
bool traverseLeafLink = false);
status_t SetTo(const char* path, int32 flags = DEFAULT,
size_t bufferSize = B_PATH_NAME_LENGTH);
void Adopt(KPath& other);
status_t InitCheck() const;
status_t SetPath(const char* path,
bool normalize = false,
bool traverseLeafLink = false);
int32 flags = DEFAULT);
const char* Path() const;
size_t Length() const
{ return fPathLength; }

View File

@ -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, bonefish@cs.tu-berlin.de. All rights reserved.
*
* Distributed under the terms of the MIT License.
@ -750,7 +750,7 @@ KDiskDeviceManager::CreateFileDevice(const char* filePath, bool* newlyCreated)
// normalize the file path
KPath normalizedFilePath;
status_t error = normalizedFilePath.SetTo(filePath, true);
status_t error = normalizedFilePath.SetTo(filePath, KPath::NORMALIZE);
if (error != B_OK)
return error;
filePath = normalizedFilePath.Path();

View File

@ -55,7 +55,7 @@ KFileDiskDevice::SetTo(const char* filePath, const char* devicePath)
// (should actually not be necessary, since this method is only invoked
// by the DDM, which has already normalized the path)
KPath tmpFilePath;
status_t error = tmpFilePath.SetTo(filePath, true);
status_t error = tmpFilePath.SetTo(filePath, KPath::NORMALIZE);
if (error != B_OK)
return error;
// check the file

View 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.
*
* Authors:
@ -285,7 +285,7 @@ _user_find_file_disk_device(const char *_filename, size_t *neededSize)
if (error != B_OK)
return error;
KPath path(filename, true);
KPath path(filename, KPath::NORMALIZE);
partition_id id = B_ENTRY_NOT_FOUND;
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
@ -408,7 +408,7 @@ _user_register_file_device(const char *_filename)
if (error != B_OK)
return error;
KPath path(filename, true);
KPath path(filename, KPath::NORMALIZE);
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
if (ManagerLocker locker = manager) {

View File

@ -29,18 +29,18 @@ KPath::KPath(size_t bufferSize)
fPathLength(0),
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),
fBufferSize(0),
fPathLength(0),
fLocked(false)
{
SetTo(path, normalize, bufferSize);
SetTo(path, flags, bufferSize);
}
@ -62,8 +62,7 @@ KPath::~KPath()
status_t
KPath::SetTo(const char* path, bool normalize, size_t bufferSize,
bool traverseLeafLink)
KPath::SetTo(const char* path, int32 flags, size_t bufferSize)
{
if (bufferSize == 0)
bufferSize = B_PATH_NAME_LENGTH;
@ -86,7 +85,7 @@ KPath::SetTo(const char* path, bool normalize, size_t bufferSize,
fBufferSize = bufferSize;
fBuffer[0] = '\0';
return SetPath(path, normalize, traverseLeafLink);
return SetPath(path, flags);
}
@ -112,16 +111,16 @@ KPath::InitCheck() const
status_t
KPath::SetPath(const char* path, bool normalize, bool traverseLeafLink)
KPath::SetPath(const char* path, int32 flags)
{
if (fBuffer == NULL)
return B_NO_INIT;
if (path != NULL) {
if (normalize) {
if ((flags & NORMALIZE) != 0) {
// normalize path
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());
if (error != B_OK) {
SetPath(NULL);

View File

@ -4339,7 +4339,7 @@ vfs_read_stat(int fd, const char* path, bool traverseLeafLink,
if (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)
return B_NO_MEMORY;
@ -8058,7 +8058,7 @@ dev_t
_kern_mount(const char* path, const char* device, const char* fsName,
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)
return B_NO_MEMORY;
@ -8069,7 +8069,7 @@ _kern_mount(const char* path, const char* device, const char* fsName,
status_t
_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)
return B_NO_MEMORY;
@ -8197,7 +8197,7 @@ _kern_open_entry_ref(dev_t device, ino_t inode, const char* name, int openMode,
int
_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)
return B_NO_MEMORY;
@ -8252,7 +8252,7 @@ _kern_open_dir(int fd, const char* path)
if (path == NULL)
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)
return B_NO_MEMORY;
@ -8313,7 +8313,7 @@ _kern_create_dir_entry_ref(dev_t device, ino_t inode, const char* name,
status_t
_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)
return B_NO_MEMORY;
@ -8325,7 +8325,7 @@ status_t
_kern_remove_dir(int fd, const char* 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)
return B_NO_MEMORY;
@ -8358,7 +8358,7 @@ status_t
_kern_read_link(int fd, const char* path, char* buffer, size_t* _bufferSize)
{
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)
return B_NO_MEMORY;
@ -8387,7 +8387,7 @@ _kern_read_link(int fd, const char* path, char* buffer, size_t* _bufferSize)
status_t
_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)
return B_NO_MEMORY;
@ -8400,8 +8400,8 @@ status_t
_kern_create_link(int pathFD, const char* path, int toFD, const char* toPath,
bool traverseLeafLink)
{
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1);
KPath toPathBuffer(toPath, false, B_PATH_NAME_LENGTH + 1);
KPath pathBuffer(path, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
KPath toPathBuffer(toPath, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK || toPathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY;
@ -8426,7 +8426,7 @@ _kern_create_link(int pathFD, const char* path, int toFD, const char* toPath,
status_t
_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)
return B_NO_MEMORY;
@ -8455,8 +8455,8 @@ _kern_unlink(int fd, const char* path)
status_t
_kern_rename(int oldFD, const char* oldPath, int newFD, const char* newPath)
{
KPath oldPathBuffer(oldPath, false, B_PATH_NAME_LENGTH + 1);
KPath newPathBuffer(newPath, false, B_PATH_NAME_LENGTH + 1);
KPath oldPathBuffer(oldPath, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
KPath newPathBuffer(newPath, KPath::DEFAULT, B_PATH_NAME_LENGTH + 1);
if (oldPathBuffer.InitCheck() != B_OK || newPathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY;
@ -8468,7 +8468,7 @@ _kern_rename(int oldFD, const char* oldPath, int newFD, const char* newPath)
status_t
_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)
return B_NO_MEMORY;
@ -8564,7 +8564,7 @@ _kern_write_stat(int fd, const char* path, bool traverseLeafLink,
if (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)
return B_NO_MEMORY;
@ -8608,7 +8608,7 @@ int
_kern_open_attr(int fd, const char* path, const char* name, uint32 type,
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)
return B_NO_MEMORY;