RAMFS: More cleanup of Locker usages in kernel_interface.

No functional change intended.
This commit is contained in:
Augustin Cavalier 2024-11-22 23:29:41 -05:00
parent ce5375c0bf
commit 608fd0cdb9

View File

@ -80,7 +80,6 @@ notify_if_stat_changed(Volume *volume, Node *node)
// #pragma mark - FS
// ramfs_mount
static status_t
ramfs_mount(fs_volume* _volume, const char* /*device*/, uint32 flags,
const char* /*args*/, ino_t* _rootID)
@ -113,7 +112,6 @@ ramfs_mount(fs_volume* _volume, const char* /*device*/, uint32 flags,
}
// ramfs_unmount
static status_t
ramfs_unmount(fs_volume* _volume)
{
@ -130,14 +128,16 @@ ramfs_unmount(fs_volume* _volume)
}
// ramfs_read_fs_info
static status_t
ramfs_read_fs_info(fs_volume* _volume, struct fs_info *info)
{
FUNCTION_START();
Volume* volume = (Volume*)_volume->private_volume;
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
info->flags = B_FS_HAS_ATTR | B_FS_HAS_MIME | B_FS_HAS_QUERY
| B_FS_IS_REMOVABLE;
info->block_size = B_PAGE_SIZE;
@ -148,24 +148,24 @@ ramfs_read_fs_info(fs_volume* _volume, struct fs_info *info)
strlcpy(info->volume_name, volume->GetName(),
sizeof(info->volume_name));
strcpy(info->fsh_name, "ramfs");
} else
SET_ERROR(error, B_ERROR);
return error;
return B_OK;
}
// ramfs_write_fs_info
static status_t
ramfs_write_fs_info(fs_volume* _volume, const struct fs_info *info, uint32 mask)
{
FUNCTION_START();
Volume* volume = (Volume*)_volume->private_volume;
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
if (VolumeWriteLocker locker = volume) {
if (mask & FS_WRITE_FSINFO_NAME)
error = volume->SetName(info->volume_name);
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
@ -182,7 +182,6 @@ ramfs_sync(fs_volume* /*fs*/)
// #pragma mark - VNodes
// ramfs_lookup
static status_t
ramfs_lookup(fs_volume* _volume, fs_vnode* _dir, const char* entryName,
ino_t* _vnodeID)
@ -195,11 +194,14 @@ ramfs_lookup(fs_volume* _volume, fs_vnode* _dir, const char* entryName,
entryName));
// check for non-directories
if (!dir)
if (dir == NULL)
RETURN_ERROR(B_NOT_A_DIRECTORY);
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
Node *node = NULL;
// special entries: "." and ".."
@ -218,42 +220,37 @@ ramfs_lookup(fs_volume* _volume, fs_vnode* _dir, const char* entryName,
} else {
// find the entry
error = dir->FindAndGetNode(entryName, &node);
SET_ERROR(error, error);
if (error == B_OK)
*_vnodeID = node->GetID();
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_get_vnode
static status_t
ramfs_get_vnode(fs_volume* _volume, ino_t vnid, fs_vnode* node, int* _type,
uint32* _flags, bool reenter)
{
// FUNCTION_START();
FUNCTION(("node: %lld\n", vnid));
Volume* volume = (Volume*)_volume->private_volume;
Node *foundNode = NULL;
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
error = volume->FindNode(vnid, &foundNode);
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = volume->FindNode(vnid, &foundNode);
if (error == B_OK) {
node->private_node = foundNode;
node->ops = &gRamFSVnodeOps;
*_type = foundNode->GetMode();
*_flags = 0;
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_write_vnode
static status_t
ramfs_write_vnode(fs_volume* /*fs*/, fs_vnode* DARG(_node), bool /*reenter*/)
{
@ -269,7 +266,6 @@ ramfs_write_vnode(fs_volume* /*fs*/, fs_vnode* DARG(_node), bool /*reenter*/)
}
// ramfs_remove_vnode
static status_t
ramfs_remove_vnode(fs_volume* _volume, fs_vnode* _node, bool /*reenter*/)
{
@ -277,12 +273,13 @@ ramfs_remove_vnode(fs_volume* _volume, fs_vnode* _node, bool /*reenter*/)
Volume* volume = (Volume*)_volume->private_volume;
Node* node = (Node*)_node->private_node;
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
if (VolumeWriteLocker locker = volume) {
volume->NodeRemoved(node);
delete node;
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
@ -290,7 +287,6 @@ ramfs_remove_vnode(fs_volume* _volume, fs_vnode* _node, bool /*reenter*/)
// #pragma mark - Nodes
// ramfs_ioctl
static status_t
ramfs_ioctl(fs_volume* _volume, fs_vnode* /*node*/, void* /*cookie*/,
uint32 cmd, void *buffer, size_t /*length*/)
@ -303,7 +299,8 @@ ramfs_ioctl(fs_volume* _volume, fs_vnode* /*node*/, void* /*cookie*/,
case RAMFS_IOCTL_GET_ALLOCATION_INFO:
{
if (buffer) {
if (VolumeReadLocker locker = volume) {
VolumeReadLocker locker(volume);
if (!locker.IsLocked()) {
AllocationInfo *info = (AllocationInfo*)buffer;
volume->GetAllocationInfo(*info);
} else
@ -315,7 +312,8 @@ ramfs_ioctl(fs_volume* _volume, fs_vnode* /*node*/, void* /*cookie*/,
case RAMFS_IOCTL_DUMP_INDEX:
{
if (buffer) {
if (VolumeReadLocker locker = volume) {
VolumeReadLocker locker(volume);
if (!locker.IsLocked()) {
const char *name = (const char*)buffer;
PRINT(" RAMFS_IOCTL_DUMP_INDEX, `%s'\n", name);
IndexDirectory *indexDir = volume->GetIndexDirectory();
@ -340,7 +338,6 @@ PRINT(" RAMFS_IOCTL_DUMP_INDEX, `%s'\n", name);
}
// ramfs_set_flags
static status_t
ramfs_set_flags(fs_volume* /*fs*/, fs_vnode* /*node*/, void* /*cookie*/,
int /*flags*/)
@ -351,7 +348,6 @@ ramfs_set_flags(fs_volume* /*fs*/, fs_vnode* /*node*/, void* /*cookie*/,
}
// ramfs_fsync
static status_t
ramfs_fsync(fs_volume* /*fs*/, fs_vnode* /*node*/)
{
@ -360,7 +356,6 @@ ramfs_fsync(fs_volume* /*fs*/, fs_vnode* /*node*/)
}
// ramfs_read_symlink
static status_t
ramfs_read_symlink(fs_volume* _volume, fs_vnode* _node, char *buffer,
size_t *bufferSize)
@ -369,8 +364,11 @@ ramfs_read_symlink(fs_volume* _volume, fs_vnode* _node, char *buffer,
Volume* volume = (Volume*)_volume->private_volume;
Node* node = (Node*)_node->private_node;
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
// read symlinks only
if (!node->IsSymLink())
error = B_BAD_VALUE;
@ -390,13 +388,10 @@ ramfs_read_symlink(fs_volume* _volume, fs_vnode* _node, char *buffer,
error = B_BAD_VALUE;
}
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_create_symlink
static status_t
ramfs_create_symlink(fs_volume* _volume, fs_vnode* _dir, const char *name,
const char *path, int mode)
@ -405,14 +400,16 @@ ramfs_create_symlink(fs_volume* _volume, fs_vnode* _dir, const char *name,
Volume* volume = (Volume*)_volume->private_volume;
Directory* dir = dynamic_cast<Directory*>((Node*)_dir->private_node);
if (name == NULL || *name == '\0')
RETURN_ERROR(B_BAD_VALUE);
if (dir == NULL)
RETURN_ERROR(B_BAD_VALUE);
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
// check name
if (!name || *name == '\0') {
SET_ERROR(error, B_BAD_VALUE);
// check directory
} else if (!dir) {
SET_ERROR(error, B_BAD_VALUE);
} else if (VolumeWriteLocker locker = volume) {
NodeMTimeUpdater mTimeUpdater(dir);
// directory deleted?
bool removed;
@ -420,6 +417,7 @@ ramfs_create_symlink(fs_volume* _volume, fs_vnode* _dir, const char *name,
!= B_OK || removed) {
SET_ERROR(error, B_NOT_ALLOWED);
}
// check directory write permissions
error = dir->CheckPermissions(ACCESS_W);
Node *node = NULL;
@ -448,13 +446,11 @@ ramfs_create_symlink(fs_volume* _volume, fs_vnode* _dir, const char *name,
notify_entry_created(volume->GetID(), dir->GetID(), name,
node->GetID());
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_link
static status_t
ramfs_link(fs_volume* _volume, fs_vnode* _dir, const char *name,
fs_vnode* _node)
@ -464,11 +460,14 @@ ramfs_link(fs_volume* _volume, fs_vnode* _dir, const char *name,
Directory* dir = dynamic_cast<Directory*>((Node*)_dir->private_node);
Node* node = (Node*)_node->private_node;
if (dir == NULL)
RETURN_ERROR(B_BAD_VALUE);
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
// check directory
if (!dir) {
SET_ERROR(error, B_BAD_VALUE);
} else if (VolumeWriteLocker locker = volume) {
NodeMTimeUpdater mTimeUpdater(dir);
// directory deleted?
bool removed;
@ -493,13 +492,11 @@ ramfs_link(fs_volume* _volume, fs_vnode* _dir, const char *name,
notify_entry_created(volume->GetID(), dir->GetID(), name,
node->GetID());
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_unlink
static status_t
ramfs_unlink(fs_volume* _volume, fs_vnode* _dir, const char *name)
{
@ -508,13 +505,15 @@ ramfs_unlink(fs_volume* _volume, fs_vnode* _dir, const char *name)
Directory* dir = dynamic_cast<Directory*>((Node*)_dir->private_node);
status_t error = B_OK;
// check name
if (!name || *name == '\0' || !strcmp(name, ".") || !strcmp(name, "..")) {
SET_ERROR(error, B_BAD_VALUE);
// check node
} else if (!dir) {
SET_ERROR(error, B_BAD_VALUE);
} else if (VolumeWriteLocker locker = volume) {
if (name == NULL || *name == '\0' || strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
RETURN_ERROR(B_BAD_VALUE);
if (dir == NULL)
RETURN_ERROR(B_BAD_VALUE);
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
NodeMTimeUpdater mTimeUpdater(dir);
// check directory write permissions
error = dir->CheckPermissions(ACCESS_W);
@ -538,13 +537,11 @@ ramfs_unlink(fs_volume* _volume, fs_vnode* _dir, const char *name)
// notify listeners
if (error == B_OK)
notify_entry_removed(volume->GetID(), dir->GetID(), name, nodeID);
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_rename
static status_t
ramfs_rename(fs_volume* _volume, fs_vnode* _oldDir, const char *oldName,
fs_vnode* _newDir, const char *newName)
@ -553,11 +550,16 @@ ramfs_rename(fs_volume* _volume, fs_vnode* _oldDir, const char *oldName,
Directory* oldDir = dynamic_cast<Directory*>((Node*)_oldDir->private_node);
Directory* newDir = dynamic_cast<Directory*>((Node*)_newDir->private_node);
status_t error = B_OK;
if (VolumeWriteLocker locker = volume) {
FUNCTION(("old dir: %lld, old name: `%s', new dir: %lld, new name: `%s'\n",
oldDir->GetID(), oldName, newDir->GetID(), newName));
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
NodeMTimeUpdater mTimeUpdater1(oldDir);
NodeMTimeUpdater mTimeUpdater2(newDir);
@ -584,8 +586,7 @@ oldDir->GetID(), oldName, newDir->GetID(), newName));
if (oldDir != newDir) {
// check whether the entry is a descendent of the target
// directory
for (Directory *parent = newDir;
parent;
for (Directory *parent = newDir; parent != NULL;
parent = parent->GetParent()) {
if (parent == node) {
error = B_BAD_VALUE;
@ -654,14 +655,11 @@ oldDir->GetID(), oldName, newDir->GetID(), newName));
notify_entry_moved(volume->GetID(), oldDir->GetID(), oldName,
newDir->GetID(), newName, node->GetID());
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_access
static status_t
ramfs_access(fs_volume* _volume, fs_vnode* _node, int mode)
{
@ -669,16 +667,15 @@ ramfs_access(fs_volume* _volume, fs_vnode* _node, int mode)
Volume* volume = (Volume*)_volume->private_volume;
Node* node = (Node*)_node->private_node;
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
error = node->CheckPermissions(mode);
} else
SET_ERROR(error, B_ERROR);
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = node->CheckPermissions(mode);
RETURN_ERROR(error);
}
// ramfs_read_stat
static status_t
ramfs_read_stat(fs_volume* _volume, fs_vnode* _node, struct stat *st)
{
@ -687,8 +684,11 @@ ramfs_read_stat(fs_volume* _volume, fs_vnode* _node, struct stat *st)
Node* node = (Node*)_node->private_node;
FUNCTION(("node: %lld\n", node->GetID()));
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
st->st_dev = volume->GetID();
st->st_ino = node->GetID();
st->st_mode = node->GetMode();
@ -702,23 +702,25 @@ ramfs_read_stat(fs_volume* _volume, fs_vnode* _node, struct stat *st)
st->st_mtime = node->GetMTime();
st->st_ctime = node->GetCTime();
st->st_crtime = node->GetCrTime();
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
RETURN_ERROR(B_OK);
}
// ramfs_write_stat
static status_t
ramfs_write_stat(fs_volume* _volume, fs_vnode* _node, const struct stat *st,
uint32 mask)
{
FUNCTION(("mask: %lx\n", mask));
Volume* volume = (Volume*)_volume->private_volume;
Node* node = (Node*)_node->private_node;
FUNCTION(("mask: %lx\n", mask));
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
if (VolumeWriteLocker locker = volume) {
NodeMTimeUpdater mTimeUpdater(node);
// check permissions
error = node->CheckPermissions(ACCESS_W);
@ -744,11 +746,11 @@ ramfs_write_stat(fs_volume* _volume, fs_vnode* _node, const struct stat *st,
if (mask & B_STAT_CREATION_TIME)
node->SetCrTime(st->st_crtime);
}
// notify listeners
if (error == B_OK)
notify_if_stat_changed(volume, node);
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
@ -756,7 +758,6 @@ ramfs_write_stat(fs_volume* _volume, fs_vnode* _node, const struct stat *st,
// #pragma mark - Files
// FileCookie
class FileCookie {
public:
FileCookie(int openMode) : fOpenMode(openMode), fLastNotificationTime(0) {}
@ -782,28 +783,28 @@ private:
};
// ramfs_create
static status_t
ramfs_create(fs_volume* _volume, fs_vnode* _dir, const char *name, int openMode,
int mode, void** _cookie, ino_t *vnid)
{
// FUNCTION_START();
FUNCTION(("name: `%s', open mode: %x, mode: %x\n", name, openMode, mode));
Volume* volume = (Volume*)_volume->private_volume;
Directory* dir = dynamic_cast<Directory*>((Node*)_dir->private_node);
status_t error = B_OK;
// check name
if (!name || *name == '\0') {
SET_ERROR(error, B_BAD_VALUE);
// check directory
} else if (!dir) {
SET_ERROR(error, B_BAD_VALUE);
// check special names
} else if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
SET_ERROR(error, B_FILE_EXISTS);
} else if (VolumeWriteLocker locker = volume) {
if (name == NULL || *name == '\0')
RETURN_ERROR(B_BAD_VALUE);
if (dir == NULL)
RETURN_ERROR(B_BAD_VALUE);
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
RETURN_ERROR(B_FILE_EXISTS);
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
NodeMTimeUpdater mTimeUpdater(dir);
status_t error = B_OK;
// directory deleted?
bool removed;
if (get_vnode_removed(volume->FSVolume(), dir->GetID(), &removed)
@ -870,13 +871,11 @@ ramfs_create(fs_volume* _volume, fs_vnode* _dir, const char *name, int openMode,
// notify listeners
if (error == B_OK)
notify_entry_created(volume->GetID(), dir->GetID(), name, *vnid);
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_open
static status_t
ramfs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie)
{
@ -885,8 +884,12 @@ ramfs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie)
Node* node = (Node*)_node->private_node;
FUNCTION(("node: %lld\n", node->GetID()));
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
// directory can be opened read-only
if (node->IsDirectory() && (openMode & O_RWMASK) != O_RDONLY)
error = B_IS_A_DIRECTORY;
@ -916,13 +919,11 @@ ramfs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie)
*_cookie = cookie;
else if (cookie)
delete cookie;
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_close
static status_t
ramfs_close(fs_volume* _volume, fs_vnode* _node, void* /*cookie*/)
{
@ -931,18 +932,19 @@ ramfs_close(fs_volume* _volume, fs_vnode* _node, void* /*cookie*/)
Node* node = (Node*)_node->private_node;
FUNCTION(("node: %lld\n", node->GetID()));
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
// notify listeners
if (VolumeReadLocker locker = volume) {
notify_if_stat_changed(volume, node);
} else
SET_ERROR(error, B_ERROR);
return error;
return error;
}
// ramfs_free_cookie
static status_t
ramfs_free_cookie(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
{
@ -953,7 +955,6 @@ ramfs_free_cookie(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
}
// ramfs_read
static status_t
ramfs_read(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
void *buffer, size_t *bufferSize)
@ -965,32 +966,36 @@ ramfs_read(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
// FUNCTION(("((%lu, %lu), %lld, %p, %lu)\n", node->GetDirID(),
// node->GetObjectID(), pos, buffer, *bufferSize));
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
// don't read anything but files
if (!node->IsFile())
SET_ERROR(error, B_BAD_VALUE);
// check, if reading is allowed
int rwMode = cookie->GetOpenMode() & O_RWMASK;
if (error == B_OK && rwMode != O_RDONLY && rwMode != O_RDWR)
SET_ERROR(error, B_FILE_ERROR);
// read
if (error == B_OK) {
if (File *file = dynamic_cast<File*>(node))
if (File *file = dynamic_cast<File*>(node)) {
error = file->ReadAt(pos, buffer, *bufferSize, bufferSize);
else {
} else {
FATAL("Node %" B_PRIdINO " pretends to be a File, but isn't!\n",
node->GetID());
error = B_BAD_VALUE;
}
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_write
static status_t
ramfs_write(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
const void *buffer, size_t *bufferSize)
@ -1002,8 +1007,12 @@ ramfs_write(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
FileCookie *cookie = (FileCookie*)_cookie;
// FUNCTION(("((%lu, %lu), %lld, %p, %lu)\n", node->GetDirID(),
// node->GetObjectID(), pos, buffer, *bufferSize));
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
if (VolumeWriteLocker locker = volume) {
// don't write anything but files
if (!node->IsFile())
SET_ERROR(error, B_BAD_VALUE);
@ -1031,8 +1040,6 @@ ramfs_write(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
if (error == B_OK && cookie->NotificationIntervalElapsed(true))
notify_if_stat_changed(volume, node);
NodeMTimeUpdater mTimeUpdater(node);
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
@ -1040,7 +1047,6 @@ ramfs_write(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,
// #pragma mark - Directories
// DirectoryCookie
class DirectoryCookie {
public:
DirectoryCookie(Directory *directory = NULL)
@ -1122,7 +1128,6 @@ private:
int32 DirectoryCookie::fNextIteratorID = 0;
// ramfs_create_dir
static status_t
ramfs_create_dir(fs_volume* _volume, fs_vnode* _dir, const char *name, int mode)
{
@ -1130,24 +1135,26 @@ ramfs_create_dir(fs_volume* _volume, fs_vnode* _dir, const char *name, int mode)
Volume* volume = (Volume*)_volume->private_volume;
Directory* dir = dynamic_cast<Directory*>((Node*)_dir->private_node);
status_t error = B_OK;
// check name
if (!name || *name == '\0') {
SET_ERROR(error, B_BAD_VALUE);
// check directory
} else if (!dir) {
SET_ERROR(error, B_BAD_VALUE);
// check special names
} else if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
SET_ERROR(error, B_FILE_EXISTS);
} else if (VolumeWriteLocker locker = volume) {
if (name == NULL || *name == '\0')
RETURN_ERROR(B_BAD_VALUE);
if (dir == NULL)
RETURN_ERROR(B_BAD_VALUE);
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
RETURN_ERROR(B_FILE_EXISTS);
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
NodeMTimeUpdater mTimeUpdater(dir);
// directory deleted?
bool removed;
status_t error = B_OK;
if (get_vnode_removed(volume->FSVolume(), dir->GetID(), &removed)
!= B_OK || removed) {
SET_ERROR(error, B_NOT_ALLOWED);
}
// check directory write permissions
error = dir->CheckPermissions(ACCESS_W);
Node *node = NULL;
@ -1176,31 +1183,30 @@ ramfs_create_dir(fs_volume* _volume, fs_vnode* _dir, const char *name, int mode)
notify_entry_created(volume->GetID(), dir->GetID(), name,
node->GetID());
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_remove_dir
static status_t
ramfs_remove_dir(fs_volume* _volume, fs_vnode* _dir, const char *name)
{
FUNCTION(("name: `%s'\n", name));
Volume* volume = (Volume*)_volume->private_volume;
Directory* dir = dynamic_cast<Directory*>((Node*)_dir->private_node);
status_t error = B_OK;
// check name
if (!name || *name == '\0' || !strcmp(name, ".") || !strcmp(name, "..")) {
SET_ERROR(error, B_BAD_VALUE);
// check node
} else if (!dir) {
SET_ERROR(error, B_BAD_VALUE);
} else if (VolumeWriteLocker locker = volume) {
if (name == NULL || *name == '\0' || !strcmp(name, ".") || !strcmp(name, ".."))
RETURN_ERROR(B_BAD_VALUE);
if (dir == NULL)
RETURN_ERROR(B_BAD_VALUE);
VolumeWriteLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
NodeMTimeUpdater mTimeUpdater(dir);
// check directory write permissions
error = dir->CheckPermissions(ACCESS_W);
status_t error = dir->CheckPermissions(ACCESS_W);
ino_t nodeID = -1;
if (error == B_OK) {
// check if entry exists
@ -1221,13 +1227,11 @@ ramfs_remove_dir(fs_volume* _volume, fs_vnode* _dir, const char *name)
// notify listeners
if (error == B_OK)
notify_entry_removed(volume->GetID(), dir->GetID(), name, nodeID);
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_open_dir
static status_t
ramfs_open_dir(fs_volume* /*fs*/, fs_vnode* _node, void** _cookie)
{
@ -1236,17 +1240,19 @@ ramfs_open_dir(fs_volume* /*fs*/, fs_vnode* _node, void** _cookie)
Node* node = (Node*)_node->private_node;
FUNCTION(("dir: (%Lu)\n", node->GetID()));
if (!node->IsDirectory())
RETURN_ERROR(B_NOT_A_DIRECTORY);
// get the Directory
status_t error = (node->IsDirectory() ? B_OK : B_NOT_A_DIRECTORY);
Directory *dir = NULL;
if (error == B_OK) {
dir = dynamic_cast<Directory*>(node);
if (!dir) {
Directory *dir = dynamic_cast<Directory*>(node);
status_t error = B_OK;
if (dir == NULL) {
FATAL("Node %" B_PRIdINO " pretends to be a Directory, but isn't!\n",
node->GetID());
error = B_NOT_A_DIRECTORY;
}
}
// create a DirectoryCookie
if (error == B_OK) {
DirectoryCookie *cookie = new(nothrow) DirectoryCookie(dir);
@ -1264,7 +1270,6 @@ ramfs_open_dir(fs_volume* /*fs*/, fs_vnode* _node, void** _cookie)
}
// ramfs_close_dir
static status_t
ramfs_close_dir(fs_volume* /*fs*/, fs_vnode* DARG(_node), void* _cookie)
{
@ -1278,7 +1283,6 @@ ramfs_close_dir(fs_volume* /*fs*/, fs_vnode* DARG(_node), void* _cookie)
}
// ramfs_free_dir_cookie
static status_t
ramfs_free_dir_cookie(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
{
@ -1289,7 +1293,6 @@ ramfs_free_dir_cookie(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
}
// ramfs_read_dir
static status_t
ramfs_read_dir(fs_volume* _volume, fs_vnode* DARG(_node), void* _cookie,
struct dirent *buffer, size_t bufferSize, uint32 *count)
@ -1300,9 +1303,12 @@ ramfs_read_dir(fs_volume* _volume, fs_vnode* DARG(_node), void* _cookie,
FUNCTION(("dir: (%Lu)\n", node->GetID()));
DirectoryCookie *cookie = (DirectoryCookie*)_cookie;
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
error = cookie->Resume();
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = cookie->Resume();
if (error == B_OK) {
// read one entry
ino_t nodeID = -1;
@ -1328,14 +1334,11 @@ ramfs_read_dir(fs_volume* _volume, fs_vnode* DARG(_node), void* _cookie,
cookie->Suspend();
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_rewind_dir
static status_t
ramfs_rewind_dir(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
{
@ -1352,7 +1355,6 @@ ramfs_rewind_dir(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
// #pragma mark - Attribute Directories
// ramfs_open_attr_dir
static status_t
ramfs_open_attr_dir(fs_volume* _volume, fs_vnode* _node, void** _cookie)
{
@ -1360,8 +1362,11 @@ ramfs_open_attr_dir(fs_volume* _volume, fs_vnode* _node, void** _cookie)
Volume* volume = (Volume*)_volume->private_volume;
Node* node = (Node*)_node->private_node;
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
// check permissions
error = node->CheckPermissions(ACCESS_R);
// create iterator
@ -1378,13 +1383,10 @@ ramfs_open_attr_dir(fs_volume* _volume, fs_vnode* _node, void** _cookie)
*_cookie = iterator;
else
delete iterator;
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_close_attr_dir
static status_t
ramfs_close_attr_dir(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
{
@ -1397,7 +1399,6 @@ ramfs_close_attr_dir(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
}
// ramfs_free_attr_dir_cookie
static status_t
ramfs_free_attr_dir_cookie(fs_volume* /*fs*/, fs_vnode* /*_node*/,
void* _cookie)
@ -1411,7 +1412,6 @@ ramfs_free_attr_dir_cookie(fs_volume* /*fs*/, fs_vnode* /*_node*/,
}
// ramfs_read_attr_dir
static status_t
ramfs_read_attr_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie,
struct dirent *buffer, size_t bufferSize, uint32 *count)
@ -1420,9 +1420,12 @@ ramfs_read_attr_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie,
Volume* volume = (Volume*)_volume->private_volume;
AttributeIterator *iterator = (AttributeIterator*)_cookie;
status_t error = B_OK;
if (VolumeReadLocker locker = volume) {
error = iterator->Resume();
VolumeReadLocker locker(volume);
if (!locker.IsLocked())
RETURN_ERROR(B_ERROR);
status_t error = iterator->Resume();
if (error == B_OK) {
// get next attribute
Attribute *attribute = NULL;
@ -1447,14 +1450,11 @@ ramfs_read_attr_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie,
iterator->Suspend();
}
} else
SET_ERROR(error, B_ERROR);
RETURN_ERROR(error);
}
// ramfs_rewind_attr_dir
static status_t
ramfs_rewind_attr_dir(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
{
@ -1471,7 +1471,6 @@ ramfs_rewind_attr_dir(fs_volume* /*fs*/, fs_vnode* /*_node*/, void* _cookie)
// #pragma mark - Attributes
// AttributeCookie
class AttributeCookie {
public:
AttributeCookie() : fOpenMode(0), fLastNotificationTime(0) {}
@ -2297,4 +2296,3 @@ module_info *modules[] = {
(module_info *)&sRamFSModuleInfo,
NULL,
};