kernel/fs: More usage of FileDescriptorDeleter.

Remaining non-uses are mostly in specialized functions that e.g. operate
on many file descriptors at once (like vfs_exec_io_context.)

Reduces "goto"s. Should not have any functional change.
This commit is contained in:
Augustin Cavalier
2024-01-08 14:57:38 -05:00
parent 1bde6f6c36
commit 76f69a9e77
2 changed files with 98 additions and 164 deletions
+22 -40
View File
@@ -468,22 +468,19 @@ dup_foreign_fd(team_id fromTeam, int fd, bool kernel)
static status_t static status_t
fd_ioctl(bool kernelFD, int fd, uint32 op, void* buffer, size_t length) fd_ioctl(bool kernelFD, int fd, uint32 op, void* buffer, size_t length)
{ {
struct file_descriptor* descriptor; FileDescriptorPutter descriptor(get_fd(get_current_io_context(kernelFD), fd));
int status; if (!descriptor.IsSet())
descriptor = get_fd(get_current_io_context(kernelFD), fd);
if (descriptor == NULL)
return B_FILE_ERROR; return B_FILE_ERROR;
status_t status;
if (descriptor->ops->fd_ioctl) if (descriptor->ops->fd_ioctl)
status = descriptor->ops->fd_ioctl(descriptor, op, buffer, length); status = descriptor->ops->fd_ioctl(descriptor.Get(), op, buffer, length);
else else
status = B_DEV_INVALID_IOCTL; status = B_DEV_INVALID_IOCTL;
if (status == B_DEV_INVALID_IOCTL) if (status == B_DEV_INVALID_IOCTL)
status = ENOTTY; status = ENOTTY;
put_fd(descriptor);
return status; return status;
} }
@@ -856,20 +853,17 @@ _user_seek(int fd, off_t pos, int seekType)
{ {
syscall_64_bit_return_value(); syscall_64_bit_return_value();
struct file_descriptor* descriptor; FileDescriptorPutter descriptor(get_fd(get_current_io_context(false), fd));
if (!descriptor.IsSet())
descriptor = get_fd(get_current_io_context(false), fd);
if (!descriptor)
return B_FILE_ERROR; return B_FILE_ERROR;
TRACE(("user_seek(descriptor = %p)\n", descriptor)); TRACE(("user_seek(descriptor = %p)\n", descriptor));
if (descriptor->ops->fd_seek) if (descriptor->ops->fd_seek)
pos = descriptor->ops->fd_seek(descriptor, pos, seekType); pos = descriptor->ops->fd_seek(descriptor.Get(), pos, seekType);
else else
pos = ESPIPE; pos = ESPIPE;
put_fd(descriptor);
return pos; return pos;
} }
@@ -952,21 +946,18 @@ _user_read_dir(int fd, struct dirent* userBuffer, size_t bufferSize,
status_t status_t
_user_rewind_dir(int fd) _user_rewind_dir(int fd)
{ {
struct file_descriptor* descriptor;
status_t status;
TRACE(("user_rewind_dir(fd = %d)\n", fd)); TRACE(("user_rewind_dir(fd = %d)\n", fd));
descriptor = get_fd(get_current_io_context(false), fd); FileDescriptorPutter descriptor(get_fd(get_current_io_context(false), fd));
if (descriptor == NULL) if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
status_t status;
if (descriptor->ops->fd_rewind_dir) if (descriptor->ops->fd_rewind_dir)
status = descriptor->ops->fd_rewind_dir(descriptor); status = descriptor->ops->fd_rewind_dir(descriptor.Get());
else else
status = B_UNSUPPORTED; status = B_UNSUPPORTED;
put_fd(descriptor);
return status; return status;
} }
@@ -1182,18 +1173,15 @@ _kern_writev(int fd, off_t pos, const iovec* vecs, size_t count)
off_t off_t
_kern_seek(int fd, off_t pos, int seekType) _kern_seek(int fd, off_t pos, int seekType)
{ {
struct file_descriptor* descriptor; FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
if (!descriptor.IsSet())
descriptor = get_fd(get_current_io_context(true), fd);
if (!descriptor)
return B_FILE_ERROR; return B_FILE_ERROR;
if (descriptor->ops->fd_seek) if (descriptor->ops->fd_seek)
pos = descriptor->ops->fd_seek(descriptor, pos, seekType); pos = descriptor->ops->fd_seek(descriptor.Get(), pos, seekType);
else else
pos = ESPIPE; pos = ESPIPE;
put_fd(descriptor);
return pos; return pos;
} }
@@ -1213,27 +1201,24 @@ ssize_t
_kern_read_dir(int fd, struct dirent* buffer, size_t bufferSize, _kern_read_dir(int fd, struct dirent* buffer, size_t bufferSize,
uint32 maxCount) uint32 maxCount)
{ {
struct file_descriptor* descriptor;
ssize_t retval;
TRACE(("sys_read_dir(fd = %d, buffer = %p, bufferSize = %ld, count = " TRACE(("sys_read_dir(fd = %d, buffer = %p, bufferSize = %ld, count = "
"%" B_PRIu32 ")\n",fd, buffer, bufferSize, maxCount)); "%" B_PRIu32 ")\n",fd, buffer, bufferSize, maxCount));
struct io_context* ioContext = get_current_io_context(true); struct io_context* ioContext = get_current_io_context(true);
descriptor = get_fd(ioContext, fd); FileDescriptorPutter descriptor(get_fd(ioContext, fd));
if (descriptor == NULL) if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
ssize_t retval;
if (descriptor->ops->fd_read_dir) { if (descriptor->ops->fd_read_dir) {
uint32 count = maxCount; uint32 count = maxCount;
retval = descriptor->ops->fd_read_dir(ioContext, descriptor, buffer, retval = descriptor->ops->fd_read_dir(ioContext, descriptor.Get(), buffer,
bufferSize, &count); bufferSize, &count);
if (retval >= 0) if (retval >= 0)
retval = count; retval = count;
} else } else
retval = B_UNSUPPORTED; retval = B_UNSUPPORTED;
put_fd(descriptor);
return retval; return retval;
} }
@@ -1241,21 +1226,18 @@ _kern_read_dir(int fd, struct dirent* buffer, size_t bufferSize,
status_t status_t
_kern_rewind_dir(int fd) _kern_rewind_dir(int fd)
{ {
struct file_descriptor* descriptor;
status_t status;
TRACE(("sys_rewind_dir(fd = %d)\n",fd)); TRACE(("sys_rewind_dir(fd = %d)\n",fd));
descriptor = get_fd(get_current_io_context(true), fd); FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
if (descriptor == NULL) if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
status_t status;
if (descriptor->ops->fd_rewind_dir) if (descriptor->ops->fd_rewind_dir)
status = descriptor->ops->fd_rewind_dir(descriptor); status = descriptor->ops->fd_rewind_dir(descriptor.Get());
else else
status = B_UNSUPPORTED; status = B_UNSUPPORTED;
put_fd(descriptor);
return status; return status;
} }
+76 -124
View File
@@ -4080,18 +4080,15 @@ read_file_io_vec_pages(int fd, const file_io_vec* fileVecs, size_t fileVecCount,
const iovec* vecs, size_t vecCount, uint32* _vecIndex, size_t* _vecOffset, const iovec* vecs, size_t vecCount, uint32* _vecIndex, size_t* _vecOffset,
size_t* _bytes) size_t* _bytes)
{ {
struct file_descriptor* descriptor;
struct vnode* vnode; struct vnode* vnode;
FileDescriptorPutter descriptor(get_fd_and_vnode(fd, &vnode, true));
descriptor = get_fd_and_vnode(fd, &vnode, true); if (!descriptor.IsSet())
if (descriptor == NULL)
return B_FILE_ERROR; return B_FILE_ERROR;
status_t status = common_file_io_vec_pages(vnode, descriptor->cookie, status_t status = common_file_io_vec_pages(vnode, descriptor->cookie,
fileVecs, fileVecCount, vecs, vecCount, _vecIndex, _vecOffset, _bytes, fileVecs, fileVecCount, vecs, vecCount, _vecIndex, _vecOffset, _bytes,
false); false);
put_fd(descriptor);
return status; return status;
} }
@@ -4101,18 +4098,15 @@ write_file_io_vec_pages(int fd, const file_io_vec* fileVecs, size_t fileVecCount
const iovec* vecs, size_t vecCount, uint32* _vecIndex, size_t* _vecOffset, const iovec* vecs, size_t vecCount, uint32* _vecIndex, size_t* _vecOffset,
size_t* _bytes) size_t* _bytes)
{ {
struct file_descriptor* descriptor;
struct vnode* vnode; struct vnode* vnode;
FileDescriptorPutter descriptor(get_fd_and_vnode(fd, &vnode, true));
descriptor = get_fd_and_vnode(fd, &vnode, true); if (!descriptor.IsSet())
if (descriptor == NULL)
return B_FILE_ERROR; return B_FILE_ERROR;
status_t status = common_file_io_vec_pages(vnode, descriptor->cookie, status_t status = common_file_io_vec_pages(vnode, descriptor->cookie,
fileVecs, fileVecCount, vecs, vecCount, _vecIndex, _vecOffset, _bytes, fileVecs, fileVecCount, vecs, vecCount, _vecIndex, _vecOffset, _bytes,
true); true);
put_fd(descriptor);
return status; return status;
} }
@@ -4370,17 +4364,15 @@ vfs_read_stat(int fd, const char* path, bool traverseLeafLink,
traverseLeafLink, stat, kernel); traverseLeafLink, stat, kernel);
} else { } else {
// no path given: get the FD and use the FD operation // no path given: get the FD and use the FD operation
struct file_descriptor* descriptor FileDescriptorPutter descriptor
= get_fd(get_current_io_context(kernel), fd); (get_fd(get_current_io_context(kernel), fd));
if (descriptor == NULL) if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
if (descriptor->ops->fd_read_stat) if (descriptor->ops->fd_read_stat)
status = descriptor->ops->fd_read_stat(descriptor, stat); status = descriptor->ops->fd_read_stat(descriptor.Get(), stat);
else else
status = B_UNSUPPORTED; status = B_UNSUPPORTED;
put_fd(descriptor);
} }
return status; return status;
@@ -6192,11 +6184,11 @@ common_fcntl(int fd, int op, size_t argument, bool kernel)
struct io_context* context = get_current_io_context(kernel); struct io_context* context = get_current_io_context(kernel);
struct file_descriptor* descriptor = get_fd(context, fd); FileDescriptorPutter descriptor(get_fd(context, fd));
if (descriptor == NULL) if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
struct vnode* vnode = fd_vnode(descriptor); struct vnode* vnode = fd_vnode(descriptor.Get());
status_t status = B_OK; status_t status = B_OK;
@@ -6208,10 +6200,8 @@ common_fcntl(int fd, int op, size_t argument, bool kernel)
else if (user_memcpy(&flock, (struct flock*)argument, else if (user_memcpy(&flock, (struct flock*)argument,
sizeof(struct flock)) != B_OK) sizeof(struct flock)) != B_OK)
status = B_BAD_ADDRESS; status = B_BAD_ADDRESS;
if (status != B_OK) { if (status != B_OK)
put_fd(descriptor);
return status; return status;
}
} }
switch (op) { switch (op) {
@@ -6243,7 +6233,7 @@ common_fcntl(int fd, int op, size_t argument, bool kernel)
// we only accept changes to O_APPEND and O_NONBLOCK // we only accept changes to O_APPEND and O_NONBLOCK
argument &= O_APPEND | O_NONBLOCK; argument &= O_APPEND | O_NONBLOCK;
if (descriptor->ops->fd_set_flags != NULL) { if (descriptor->ops->fd_set_flags != NULL) {
status = descriptor->ops->fd_set_flags(descriptor, argument); status = descriptor->ops->fd_set_flags(descriptor.Get(), argument);
} else if (vnode != NULL && HAS_FS_CALL(vnode, set_flags)) { } else if (vnode != NULL && HAS_FS_CALL(vnode, set_flags)) {
status = FS_CALL(vnode, set_flags, descriptor->cookie, status = FS_CALL(vnode, set_flags, descriptor->cookie,
(int)argument); (int)argument);
@@ -6266,7 +6256,7 @@ common_fcntl(int fd, int op, size_t argument, bool kernel)
case F_DUPFD: case F_DUPFD:
case F_DUPFD_CLOEXEC: case F_DUPFD_CLOEXEC:
{ {
status = new_fd_etc(context, descriptor, (int)argument); status = new_fd_etc(context, descriptor.Get(), (int)argument);
if (status >= 0) { if (status >= 0) {
mutex_lock(&context->io_mutex); mutex_lock(&context->io_mutex);
fd_set_close_on_exec(context, status, op == F_DUPFD_CLOEXEC); fd_set_close_on_exec(context, status, op == F_DUPFD_CLOEXEC);
@@ -6282,7 +6272,7 @@ common_fcntl(int fd, int op, size_t argument, bool kernel)
struct flock normalizedLock; struct flock normalizedLock;
memcpy(&normalizedLock, &flock, sizeof(struct flock)); memcpy(&normalizedLock, &flock, sizeof(struct flock));
status = normalize_flock(descriptor, &normalizedLock); status = normalize_flock(descriptor.Get(), &normalizedLock);
if (status != B_OK) if (status != B_OK)
break; break;
@@ -6324,7 +6314,7 @@ common_fcntl(int fd, int op, size_t argument, bool kernel)
case F_SETLK: case F_SETLK:
case F_SETLKW: case F_SETLKW:
status = normalize_flock(descriptor, &flock); status = normalize_flock(descriptor.Get(), &flock);
if (status != B_OK) if (status != B_OK)
break; break;
@@ -6363,7 +6353,6 @@ common_fcntl(int fd, int op, size_t argument, bool kernel)
status = B_BAD_VALUE; status = B_BAD_VALUE;
} }
put_fd(descriptor);
return status; return status;
} }
@@ -6371,22 +6360,19 @@ common_fcntl(int fd, int op, size_t argument, bool kernel)
static status_t static status_t
common_sync(int fd, bool kernel) common_sync(int fd, bool kernel)
{ {
struct file_descriptor* descriptor;
struct vnode* vnode;
status_t status;
FUNCTION(("common_fsync: entry. fd %d kernel %d\n", fd, kernel)); FUNCTION(("common_fsync: entry. fd %d kernel %d\n", fd, kernel));
descriptor = get_fd_and_vnode(fd, &vnode, kernel); struct vnode* vnode;
if (descriptor == NULL) FileDescriptorPutter descriptor(get_fd_and_vnode(fd, &vnode, kernel));
if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
status_t status;
if (HAS_FS_CALL(vnode, fsync)) if (HAS_FS_CALL(vnode, fsync))
status = FS_CALL_NO_PARAMS(vnode, fsync); status = FS_CALL_NO_PARAMS(vnode, fsync);
else else
status = B_UNSUPPORTED; status = B_UNSUPPORTED;
put_fd(descriptor);
return status; return status;
} }
@@ -6394,34 +6380,9 @@ common_sync(int fd, bool kernel)
static status_t static status_t
common_lock_node(int fd, bool kernel) common_lock_node(int fd, bool kernel)
{ {
struct file_descriptor* descriptor;
struct vnode* vnode; struct vnode* vnode;
FileDescriptorPutter descriptor(get_fd_and_vnode(fd, &vnode, kernel));
descriptor = get_fd_and_vnode(fd, &vnode, kernel); if (!descriptor.IsSet())
if (descriptor == NULL)
return B_FILE_ERROR;
status_t status = B_OK;
// We need to set the locking atomically - someone
// else might set one at the same time
if (atomic_pointer_test_and_set(&vnode->mandatory_locked_by, descriptor,
(file_descriptor*)NULL) != NULL)
status = B_BUSY;
put_fd(descriptor);
return status;
}
static status_t
common_unlock_node(int fd, bool kernel)
{
struct file_descriptor* descriptor;
struct vnode* vnode;
descriptor = get_fd_and_vnode(fd, &vnode, kernel);
if (descriptor == NULL)
return B_FILE_ERROR; return B_FILE_ERROR;
status_t status = B_OK; status_t status = B_OK;
@@ -6429,10 +6390,29 @@ common_unlock_node(int fd, bool kernel)
// We need to set the locking atomically - someone // We need to set the locking atomically - someone
// else might set one at the same time // else might set one at the same time
if (atomic_pointer_test_and_set(&vnode->mandatory_locked_by, if (atomic_pointer_test_and_set(&vnode->mandatory_locked_by,
(file_descriptor*)NULL, descriptor) != descriptor) descriptor.Get(), (file_descriptor*)NULL) != NULL)
status = B_BUSY;
return status;
}
static status_t
common_unlock_node(int fd, bool kernel)
{
struct vnode* vnode;
FileDescriptorPutter descriptor(get_fd_and_vnode(fd, &vnode, kernel));
if (!descriptor.IsSet())
return B_FILE_ERROR;
status_t status = B_OK;
// We need to set the locking atomically - someone
// else might set one at the same time
if (atomic_pointer_test_and_set(&vnode->mandatory_locked_by,
(file_descriptor*)NULL, descriptor.Get()) != descriptor.Get())
status = B_BAD_VALUE; status = B_BAD_VALUE;
put_fd(descriptor);
return status; return status;
} }
@@ -6440,15 +6420,13 @@ common_unlock_node(int fd, bool kernel)
static status_t static status_t
common_preallocate(int fd, off_t offset, off_t length, bool kernel) common_preallocate(int fd, off_t offset, off_t length, bool kernel)
{ {
FileDescriptorPutter descriptor;
struct vnode* vnode;
if (offset < 0 || length == 0) if (offset < 0 || length == 0)
return B_BAD_VALUE; return B_BAD_VALUE;
if (offset > OFF_MAX - length) if (offset > OFF_MAX - length)
return B_FILE_TOO_LARGE; return B_FILE_TOO_LARGE;
descriptor.SetTo(get_fd_and_vnode(fd, &vnode, kernel)); struct vnode* vnode;
FileDescriptorPutter descriptor(get_fd_and_vnode(fd, &vnode, kernel));
if (!descriptor.IsSet() || (descriptor->open_mode & O_RWMASK) == O_RDONLY) if (!descriptor.IsSet() || (descriptor->open_mode & O_RWMASK) == O_RDONLY)
return B_FILE_ERROR; return B_FILE_ERROR;
@@ -7048,27 +7026,23 @@ attr_write_stat(struct file_descriptor* descriptor, const struct stat* stat,
static status_t static status_t
attr_remove(int fd, const char* name, bool kernel) attr_remove(int fd, const char* name, bool kernel)
{ {
struct file_descriptor* descriptor;
struct vnode* vnode;
status_t status;
if (name == NULL || *name == '\0') if (name == NULL || *name == '\0')
return B_BAD_VALUE; return B_BAD_VALUE;
FUNCTION(("attr_remove: fd = %d, name = \"%s\", kernel %d\n", fd, name, FUNCTION(("attr_remove: fd = %d, name = \"%s\", kernel %d\n", fd, name,
kernel)); kernel));
descriptor = get_fd_and_vnode(fd, &vnode, kernel); struct vnode* vnode;
if (descriptor == NULL) FileDescriptorPutter descriptor(get_fd_and_vnode(fd, &vnode, kernel));
if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
status_t status;
if (HAS_FS_CALL(vnode, remove_attr)) if (HAS_FS_CALL(vnode, remove_attr))
status = FS_CALL(vnode, remove_attr, name); status = FS_CALL(vnode, remove_attr, name);
else else
status = B_READ_ONLY_DEVICE; status = B_READ_ONLY_DEVICE;
put_fd(descriptor);
return status; return status;
} }
@@ -7077,12 +7051,6 @@ static status_t
attr_rename(int fromFD, const char* fromName, int toFD, const char* toName, attr_rename(int fromFD, const char* fromName, int toFD, const char* toName,
bool kernel) bool kernel)
{ {
struct file_descriptor* fromDescriptor;
struct file_descriptor* toDescriptor;
struct vnode* fromVnode;
struct vnode* toVnode;
status_t status;
if (fromName == NULL || *fromName == '\0' || toName == NULL if (fromName == NULL || *fromName == '\0' || toName == NULL
|| *toName == '\0') || *toName == '\0')
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -7090,32 +7058,26 @@ attr_rename(int fromFD, const char* fromName, int toFD, const char* toName,
FUNCTION(("attr_rename: from fd = %d, from name = \"%s\", to fd = %d, to " FUNCTION(("attr_rename: from fd = %d, from name = \"%s\", to fd = %d, to "
"name = \"%s\", kernel %d\n", fromFD, fromName, toFD, toName, kernel)); "name = \"%s\", kernel %d\n", fromFD, fromName, toFD, toName, kernel));
fromDescriptor = get_fd_and_vnode(fromFD, &fromVnode, kernel); struct vnode* fromVnode;
if (fromDescriptor == NULL) FileDescriptorPutter fromDescriptor(get_fd_and_vnode(fromFD, &fromVnode, kernel));
if (!fromDescriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
toDescriptor = get_fd_and_vnode(toFD, &toVnode, kernel); struct vnode* toVnode;
if (toDescriptor == NULL) { FileDescriptorPutter toDescriptor(get_fd_and_vnode(toFD, &toVnode, kernel));
status = B_FILE_ERROR; if (!toDescriptor.IsSet())
goto err; return B_FILE_ERROR;
}
// are the files on the same volume? // are the files on the same volume?
if (fromVnode->device != toVnode->device) { if (fromVnode->device != toVnode->device)
status = B_CROSS_DEVICE_LINK; return B_CROSS_DEVICE_LINK;
goto err1;
}
status_t status;
if (HAS_FS_CALL(fromVnode, rename_attr)) { if (HAS_FS_CALL(fromVnode, rename_attr)) {
status = FS_CALL(fromVnode, rename_attr, fromName, toVnode, toName); status = FS_CALL(fromVnode, rename_attr, fromName, toVnode, toName);
} else } else
status = B_READ_ONLY_DEVICE; status = B_READ_ONLY_DEVICE;
err1:
put_fd(toDescriptor);
err:
put_fd(fromDescriptor);
return status; return status;
} }
@@ -8760,17 +8722,15 @@ _kern_write_stat(int fd, const char* path, bool traverseLeafLink,
traverseLeafLink, stat, statMask, true); traverseLeafLink, stat, statMask, true);
} else { } else {
// no path given: get the FD and use the FD operation // no path given: get the FD and use the FD operation
struct file_descriptor* descriptor FileDescriptorPutter descriptor
= get_fd(get_current_io_context(true), fd); (get_fd(get_current_io_context(true), fd));
if (descriptor == NULL) if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
if (descriptor->ops->fd_write_stat) if (descriptor->ops->fd_write_stat)
status = descriptor->ops->fd_write_stat(descriptor, stat, statMask); status = descriptor->ops->fd_write_stat(descriptor.Get(), stat, statMask);
else else
status = B_UNSUPPORTED; status = B_UNSUPPORTED;
put_fd(descriptor);
} }
return status; return status;
@@ -9314,16 +9274,13 @@ _user_flock(int fd, int operation)
return B_BAD_VALUE; return B_BAD_VALUE;
} }
struct file_descriptor* descriptor;
struct vnode* vnode; struct vnode* vnode;
descriptor = get_fd_and_vnode(fd, &vnode, false); FileDescriptorPutter descriptor(get_fd_and_vnode(fd, &vnode, false));
if (descriptor == NULL) if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
if (descriptor->type != FDTYPE_FILE) { if (descriptor->type != FDTYPE_FILE)
put_fd(descriptor);
return B_BAD_VALUE; return B_BAD_VALUE;
}
struct flock flock; struct flock flock;
flock.l_start = 0; flock.l_start = 0;
@@ -9336,20 +9293,19 @@ _user_flock(int fd, int operation)
if (HAS_FS_CALL(vnode, release_lock)) if (HAS_FS_CALL(vnode, release_lock))
status = FS_CALL(vnode, release_lock, descriptor->cookie, &flock); status = FS_CALL(vnode, release_lock, descriptor->cookie, &flock);
else else
status = release_advisory_lock(vnode, NULL, descriptor, &flock); status = release_advisory_lock(vnode, NULL, descriptor.Get(), &flock);
} else { } else {
if (HAS_FS_CALL(vnode, acquire_lock)) { if (HAS_FS_CALL(vnode, acquire_lock)) {
status = FS_CALL(vnode, acquire_lock, descriptor->cookie, &flock, status = FS_CALL(vnode, acquire_lock, descriptor->cookie, &flock,
(operation & LOCK_NB) == 0); (operation & LOCK_NB) == 0);
} else { } else {
status = acquire_advisory_lock(vnode, NULL, descriptor, &flock, status = acquire_advisory_lock(vnode, NULL, descriptor.Get(), &flock,
(operation & LOCK_NB) == 0); (operation & LOCK_NB) == 0);
} }
} }
syscall_restart_handle_post(status); syscall_restart_handle_post(status);
put_fd(descriptor);
return status; return status;
} }
@@ -9726,17 +9682,15 @@ _user_read_stat(int fd, const char* userPath, bool traverseLink,
status = common_path_read_stat(fd, path, traverseLink, &stat, false); status = common_path_read_stat(fd, path, traverseLink, &stat, false);
} else { } else {
// no path given: get the FD and use the FD operation // no path given: get the FD and use the FD operation
struct file_descriptor* descriptor FileDescriptorPutter descriptor
= get_fd(get_current_io_context(false), fd); (get_fd(get_current_io_context(false), fd));
if (descriptor == NULL) if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
if (descriptor->ops->fd_read_stat) if (descriptor->ops->fd_read_stat)
status = descriptor->ops->fd_read_stat(descriptor, &stat); status = descriptor->ops->fd_read_stat(descriptor.Get(), &stat);
else else
status = B_UNSUPPORTED; status = B_UNSUPPORTED;
put_fd(descriptor);
} }
if (status != B_OK) if (status != B_OK)
@@ -9784,18 +9738,16 @@ _user_write_stat(int fd, const char* userPath, bool traverseLeafLink,
statMask, false); statMask, false);
} else { } else {
// no path given: get the FD and use the FD operation // no path given: get the FD and use the FD operation
struct file_descriptor* descriptor FileDescriptorPutter descriptor
= get_fd(get_current_io_context(false), fd); (get_fd(get_current_io_context(false), fd));
if (descriptor == NULL) if (!descriptor.IsSet())
return B_FILE_ERROR; return B_FILE_ERROR;
if (descriptor->ops->fd_write_stat) { if (descriptor->ops->fd_write_stat) {
status = descriptor->ops->fd_write_stat(descriptor, &stat, status = descriptor->ops->fd_write_stat(descriptor.Get(), &stat,
statMask); statMask);
} else } else
status = B_UNSUPPORTED; status = B_UNSUPPORTED;
put_fd(descriptor);
} }
return status; return status;