kernel/fs: Standardize AutoDeleters for file_descriptor on FileDescriptorPutter.
No functional change intended.
This commit is contained in:
+38
-92
@@ -50,53 +50,6 @@ static void deselect_select_infos(file_descriptor* descriptor,
|
|||||||
select_info* infos, bool putSyncObjects);
|
select_info* infos, bool putSyncObjects);
|
||||||
|
|
||||||
|
|
||||||
struct FDGetterLocking {
|
|
||||||
inline bool Lock(file_descriptor* /*lockable*/)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Unlock(file_descriptor* lockable)
|
|
||||||
{
|
|
||||||
put_fd(lockable);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class FDGetter : public AutoLocker<file_descriptor, FDGetterLocking> {
|
|
||||||
public:
|
|
||||||
inline FDGetter()
|
|
||||||
: AutoLocker<file_descriptor, FDGetterLocking>()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline FDGetter(io_context* context, int fd, bool contextLocked = false)
|
|
||||||
: AutoLocker<file_descriptor, FDGetterLocking>(
|
|
||||||
contextLocked ? get_fd_locked(context, fd) : get_fd(context, fd))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline file_descriptor* SetTo(io_context* context, int fd,
|
|
||||||
bool contextLocked = false)
|
|
||||||
{
|
|
||||||
file_descriptor* descriptor
|
|
||||||
= contextLocked ? get_fd_locked(context, fd) : get_fd(context, fd);
|
|
||||||
AutoLocker<file_descriptor, FDGetterLocking>::SetTo(descriptor, true);
|
|
||||||
return descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline file_descriptor* SetTo(int fd, bool kernel,
|
|
||||||
bool contextLocked = false)
|
|
||||||
{
|
|
||||||
return SetTo(get_current_io_context(kernel), fd, contextLocked);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline file_descriptor* FD() const
|
|
||||||
{
|
|
||||||
return fLockable;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - General fd routines
|
// #pragma mark - General fd routines
|
||||||
|
|
||||||
|
|
||||||
@@ -572,14 +525,14 @@ select_fd(int32 fd, struct select_info* info, bool kernel)
|
|||||||
TRACE(("select_fd(fd = %" B_PRId32 ", info = %p (%p), 0x%x)\n", fd, info,
|
TRACE(("select_fd(fd = %" B_PRId32 ", info = %p (%p), 0x%x)\n", fd, info,
|
||||||
info->sync, info->selected_events));
|
info->sync, info->selected_events));
|
||||||
|
|
||||||
FDGetter fdGetter;
|
FileDescriptorPutter descriptor;
|
||||||
// define before the context locker, so it will be destroyed after it
|
// define before the context locker, so it will be destroyed after it
|
||||||
|
|
||||||
io_context* context = get_current_io_context(kernel);
|
io_context* context = get_current_io_context(kernel);
|
||||||
MutexLocker locker(context->io_mutex);
|
MutexLocker locker(context->io_mutex);
|
||||||
|
|
||||||
struct file_descriptor* descriptor = fdGetter.SetTo(context, fd, true);
|
descriptor.SetTo(get_fd_locked(context, fd));
|
||||||
if (descriptor == NULL)
|
if (!descriptor.IsSet())
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
|
|
||||||
uint16 eventsToSelect = info->selected_events & ~B_EVENT_INVALID;
|
uint16 eventsToSelect = info->selected_events & ~B_EVENT_INVALID;
|
||||||
@@ -605,7 +558,7 @@ select_fd(int32 fd, struct select_info* info, bool kernel)
|
|||||||
|
|
||||||
for (uint16 event = 1; event < 16; event++) {
|
for (uint16 event = 1; event < 16; event++) {
|
||||||
if ((eventsToSelect & SELECT_FLAG(event)) != 0
|
if ((eventsToSelect & SELECT_FLAG(event)) != 0
|
||||||
&& descriptor->ops->fd_select(descriptor, event,
|
&& descriptor->ops->fd_select(descriptor.Get(), event,
|
||||||
(selectsync*)info) == B_OK) {
|
(selectsync*)info) == B_OK) {
|
||||||
selectedEvents |= SELECT_FLAG(event);
|
selectedEvents |= SELECT_FLAG(event);
|
||||||
}
|
}
|
||||||
@@ -616,14 +569,14 @@ select_fd(int32 fd, struct select_info* info, bool kernel)
|
|||||||
// Add the info to the IO context. Even if nothing has been selected -- we
|
// Add the info to the IO context. Even if nothing has been selected -- we
|
||||||
// always support B_EVENT_INVALID.
|
// always support B_EVENT_INVALID.
|
||||||
locker.Lock();
|
locker.Lock();
|
||||||
if (context->fds[fd] != descriptor) {
|
if (context->fds[fd] != descriptor.Get()) {
|
||||||
// Someone close()d the index in the meantime. deselect() all
|
// Someone close()d the index in the meantime. deselect() all
|
||||||
// events.
|
// events.
|
||||||
info->next = NULL;
|
info->next = NULL;
|
||||||
deselect_select_infos(descriptor, info, false);
|
deselect_select_infos(descriptor.Get(), info, false);
|
||||||
|
|
||||||
// Release our open reference of the descriptor.
|
// Release our open reference of the descriptor.
|
||||||
close_fd(context, descriptor);
|
close_fd(context, descriptor.Get());
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,14 +604,14 @@ deselect_fd(int32 fd, struct select_info* info, bool kernel)
|
|||||||
TRACE(("deselect_fd(fd = %" B_PRId32 ", info = %p (%p), 0x%x)\n", fd, info,
|
TRACE(("deselect_fd(fd = %" B_PRId32 ", info = %p (%p), 0x%x)\n", fd, info,
|
||||||
info->sync, info->selected_events));
|
info->sync, info->selected_events));
|
||||||
|
|
||||||
FDGetter fdGetter;
|
FileDescriptorPutter descriptor;
|
||||||
// define before the context locker, so it will be destroyed after it
|
// define before the context locker, so it will be destroyed after it
|
||||||
|
|
||||||
io_context* context = get_current_io_context(kernel);
|
io_context* context = get_current_io_context(kernel);
|
||||||
MutexLocker locker(context->io_mutex);
|
MutexLocker locker(context->io_mutex);
|
||||||
|
|
||||||
struct file_descriptor* descriptor = fdGetter.SetTo(context, fd, true);
|
descriptor.SetTo(get_fd_locked(context, fd));
|
||||||
if (descriptor == NULL)
|
if (!descriptor.IsSet())
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
|
|
||||||
// remove the info from the IO context
|
// remove the info from the IO context
|
||||||
@@ -680,7 +633,7 @@ deselect_fd(int32 fd, struct select_info* info, bool kernel)
|
|||||||
if (descriptor->ops->fd_deselect != NULL && eventsToDeselect != 0) {
|
if (descriptor->ops->fd_deselect != NULL && eventsToDeselect != 0) {
|
||||||
for (uint16 event = 1; event < 16; event++) {
|
for (uint16 event = 1; event < 16; event++) {
|
||||||
if ((eventsToDeselect & SELECT_FLAG(event)) != 0) {
|
if ((eventsToDeselect & SELECT_FLAG(event)) != 0) {
|
||||||
descriptor->ops->fd_deselect(descriptor, event,
|
descriptor->ops->fd_deselect(descriptor.Get(), event,
|
||||||
(selectsync*)info);
|
(selectsync*)info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -737,9 +690,8 @@ common_user_io(int fd, off_t pos, void* buffer, size_t length, bool write)
|
|||||||
if (pos < -1)
|
if (pos < -1)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
FDGetter fdGetter;
|
FileDescriptorPutter descriptor(get_fd(get_current_io_context(false), fd));
|
||||||
struct file_descriptor* descriptor = fdGetter.SetTo(fd, false);
|
if (!descriptor.IsSet())
|
||||||
if (!descriptor)
|
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
|
|
||||||
if (write ? (descriptor->open_mode & O_RWMASK) == O_RDONLY
|
if (write ? (descriptor->open_mode & O_RWMASK) == O_RDONLY
|
||||||
@@ -767,16 +719,16 @@ common_user_io(int fd, off_t pos, void* buffer, size_t length, bool write)
|
|||||||
SyscallRestartWrapper<status_t> status;
|
SyscallRestartWrapper<status_t> status;
|
||||||
|
|
||||||
if (write)
|
if (write)
|
||||||
status = descriptor->ops->fd_write(descriptor, pos, buffer, &length);
|
status = descriptor->ops->fd_write(descriptor.Get(), pos, buffer, &length);
|
||||||
else
|
else
|
||||||
status = descriptor->ops->fd_read(descriptor, pos, buffer, &length);
|
status = descriptor->ops->fd_read(descriptor.Get(), pos, buffer, &length);
|
||||||
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (movePosition) {
|
if (movePosition) {
|
||||||
descriptor->pos = write && (descriptor->open_mode & O_APPEND) != 0
|
descriptor->pos = write && (descriptor->open_mode & O_APPEND) != 0
|
||||||
? descriptor->ops->fd_seek(descriptor, 0, SEEK_END) : pos + length;
|
? descriptor->ops->fd_seek(descriptor.Get(), 0, SEEK_END) : pos + length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return length <= SSIZE_MAX ? (ssize_t)length : SSIZE_MAX;
|
return length <= SSIZE_MAX ? (ssize_t)length : SSIZE_MAX;
|
||||||
@@ -796,9 +748,8 @@ common_user_vector_io(int fd, off_t pos, const iovec* userVecs, size_t count,
|
|||||||
return error;
|
return error;
|
||||||
MemoryDeleter _(vecs);
|
MemoryDeleter _(vecs);
|
||||||
|
|
||||||
FDGetter fdGetter;
|
FileDescriptorPutter descriptor(get_fd(get_current_io_context(false), fd));
|
||||||
struct file_descriptor* descriptor = fdGetter.SetTo(fd, false);
|
if (!descriptor.IsSet())
|
||||||
if (!descriptor)
|
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
|
|
||||||
if (write ? (descriptor->open_mode & O_RWMASK) == O_RDONLY
|
if (write ? (descriptor->open_mode & O_RWMASK) == O_RDONLY
|
||||||
@@ -826,10 +777,10 @@ common_user_vector_io(int fd, off_t pos, const iovec* userVecs, size_t count,
|
|||||||
|
|
||||||
size_t length = vecs[i].iov_len;
|
size_t length = vecs[i].iov_len;
|
||||||
if (write) {
|
if (write) {
|
||||||
status = descriptor->ops->fd_write(descriptor, pos,
|
status = descriptor->ops->fd_write(descriptor.Get(), pos,
|
||||||
vecs[i].iov_base, &length);
|
vecs[i].iov_base, &length);
|
||||||
} else {
|
} else {
|
||||||
status = descriptor->ops->fd_read(descriptor, pos, vecs[i].iov_base,
|
status = descriptor->ops->fd_read(descriptor.Get(), pos, vecs[i].iov_base,
|
||||||
&length);
|
&length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -853,7 +804,7 @@ common_user_vector_io(int fd, off_t pos, const iovec* userVecs, size_t count,
|
|||||||
|
|
||||||
if (movePosition) {
|
if (movePosition) {
|
||||||
descriptor->pos = write && (descriptor->open_mode & O_APPEND) != 0
|
descriptor->pos = write && (descriptor->open_mode & O_APPEND) != 0
|
||||||
? descriptor->ops->fd_seek(descriptor, 0, SEEK_END) : pos;
|
? descriptor->ops->fd_seek(descriptor.Get(), 0, SEEK_END) : pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesTransferred;
|
return bytesTransferred;
|
||||||
@@ -956,9 +907,8 @@ _user_read_dir(int fd, struct dirent* userBuffer, size_t bufferSize,
|
|||||||
|
|
||||||
// get I/O context and FD
|
// get I/O context and FD
|
||||||
io_context* ioContext = get_current_io_context(false);
|
io_context* ioContext = get_current_io_context(false);
|
||||||
FDGetter fdGetter;
|
FileDescriptorPutter descriptor(get_fd(ioContext, fd));
|
||||||
struct file_descriptor* descriptor = fdGetter.SetTo(ioContext, fd, false);
|
if (!descriptor.IsSet())
|
||||||
if (descriptor == NULL)
|
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
|
|
||||||
if (descriptor->ops->fd_read_dir == NULL)
|
if (descriptor->ops->fd_read_dir == NULL)
|
||||||
@@ -974,7 +924,7 @@ _user_read_dir(int fd, struct dirent* userBuffer, size_t bufferSize,
|
|||||||
|
|
||||||
// read the directory
|
// read the directory
|
||||||
uint32 count = maxCount;
|
uint32 count = maxCount;
|
||||||
status_t status = descriptor->ops->fd_read_dir(ioContext, descriptor,
|
status_t status = descriptor->ops->fd_read_dir(ioContext, descriptor.Get(),
|
||||||
buffer, bufferSize, &count);
|
buffer, bufferSize, &count);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
@@ -1051,10 +1001,9 @@ _kern_read(int fd, off_t pos, void* buffer, size_t length)
|
|||||||
if (pos < -1)
|
if (pos < -1)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
FDGetter fdGetter;
|
FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
|
||||||
struct file_descriptor* descriptor = fdGetter.SetTo(fd, true);
|
|
||||||
|
|
||||||
if (!descriptor)
|
if (!descriptor.IsSet())
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
if ((descriptor->open_mode & O_RWMASK) == O_WRONLY)
|
if ((descriptor->open_mode & O_RWMASK) == O_WRONLY)
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
@@ -1070,7 +1019,7 @@ _kern_read(int fd, off_t pos, void* buffer, size_t length)
|
|||||||
if (descriptor->ops->fd_read == NULL)
|
if (descriptor->ops->fd_read == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
ssize_t bytesRead = descriptor->ops->fd_read(descriptor, pos, buffer,
|
ssize_t bytesRead = descriptor->ops->fd_read(descriptor.Get(), pos, buffer,
|
||||||
&length);
|
&length);
|
||||||
if (bytesRead >= B_OK) {
|
if (bytesRead >= B_OK) {
|
||||||
if (length > SSIZE_MAX)
|
if (length > SSIZE_MAX)
|
||||||
@@ -1095,10 +1044,9 @@ _kern_readv(int fd, off_t pos, const iovec* vecs, size_t count)
|
|||||||
if (pos < -1)
|
if (pos < -1)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
FDGetter fdGetter;
|
FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
|
||||||
struct file_descriptor* descriptor = fdGetter.SetTo(fd, true);
|
|
||||||
|
|
||||||
if (!descriptor)
|
if (!descriptor.IsSet())
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
if ((descriptor->open_mode & O_RWMASK) == O_WRONLY)
|
if ((descriptor->open_mode & O_RWMASK) == O_WRONLY)
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
@@ -1117,8 +1065,8 @@ _kern_readv(int fd, off_t pos, const iovec* vecs, size_t count)
|
|||||||
|
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
size_t length = vecs[i].iov_len;
|
size_t length = vecs[i].iov_len;
|
||||||
status = descriptor->ops->fd_read(descriptor, pos, vecs[i].iov_base,
|
status = descriptor->ops->fd_read(descriptor.Get(), pos,
|
||||||
&length);
|
vecs[i].iov_base, &length);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
bytesRead = status;
|
bytesRead = status;
|
||||||
break;
|
break;
|
||||||
@@ -1145,10 +1093,9 @@ _kern_write(int fd, off_t pos, const void* buffer, size_t length)
|
|||||||
if (pos < -1)
|
if (pos < -1)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
FDGetter fdGetter;
|
FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
|
||||||
struct file_descriptor* descriptor = fdGetter.SetTo(fd, true);
|
|
||||||
|
|
||||||
if (descriptor == NULL)
|
if (!descriptor.IsSet())
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
if ((descriptor->open_mode & O_RWMASK) == O_RDONLY)
|
if ((descriptor->open_mode & O_RWMASK) == O_RDONLY)
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
@@ -1164,8 +1111,8 @@ _kern_write(int fd, off_t pos, const void* buffer, size_t length)
|
|||||||
|
|
||||||
SyscallFlagUnsetter _;
|
SyscallFlagUnsetter _;
|
||||||
|
|
||||||
ssize_t bytesWritten = descriptor->ops->fd_write(descriptor, pos, buffer,
|
ssize_t bytesWritten = descriptor->ops->fd_write(descriptor.Get(), pos,
|
||||||
&length);
|
buffer, &length);
|
||||||
if (bytesWritten >= B_OK) {
|
if (bytesWritten >= B_OK) {
|
||||||
if (length > SSIZE_MAX)
|
if (length > SSIZE_MAX)
|
||||||
bytesWritten = SSIZE_MAX;
|
bytesWritten = SSIZE_MAX;
|
||||||
@@ -1189,10 +1136,9 @@ _kern_writev(int fd, off_t pos, const iovec* vecs, size_t count)
|
|||||||
if (pos < -1)
|
if (pos < -1)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
FDGetter fdGetter;
|
FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
|
||||||
struct file_descriptor* descriptor = fdGetter.SetTo(fd, true);
|
|
||||||
|
|
||||||
if (!descriptor)
|
if (!descriptor.IsSet())
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
if ((descriptor->open_mode & O_RWMASK) == O_RDONLY)
|
if ((descriptor->open_mode & O_RWMASK) == O_RDONLY)
|
||||||
return B_FILE_ERROR;
|
return B_FILE_ERROR;
|
||||||
@@ -1211,7 +1157,7 @@ _kern_writev(int fd, off_t pos, const iovec* vecs, size_t count)
|
|||||||
|
|
||||||
for (size_t i = 0; i < count; i++) {
|
for (size_t i = 0; i < count; i++) {
|
||||||
size_t length = vecs[i].iov_len;
|
size_t length = vecs[i].iov_len;
|
||||||
status = descriptor->ops->fd_write(descriptor, pos,
|
status = descriptor->ops->fd_write(descriptor.Get(), pos,
|
||||||
vecs[i].iov_base, &length);
|
vecs[i].iov_base, &length);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
bytesWritten = status;
|
bytesWritten = status;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <module.h>
|
#include <module.h>
|
||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
#include <AutoDeleterDrivers.h>
|
||||||
|
|
||||||
#include <syscall_utils.h>
|
#include <syscall_utils.h>
|
||||||
|
|
||||||
@@ -45,22 +46,6 @@ static vint32 sStackInterfaceInitialized = 0;
|
|||||||
static mutex sLock = MUTEX_INITIALIZER("stack interface");
|
static mutex sLock = MUTEX_INITIALIZER("stack interface");
|
||||||
|
|
||||||
|
|
||||||
struct FDPutter {
|
|
||||||
FDPutter(file_descriptor* descriptor)
|
|
||||||
: descriptor(descriptor)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~FDPutter()
|
|
||||||
{
|
|
||||||
if (descriptor != NULL)
|
|
||||||
put_fd(descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
file_descriptor* descriptor;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static net_stack_interface_module_info*
|
static net_stack_interface_module_info*
|
||||||
get_stack_interface_module()
|
get_stack_interface_module()
|
||||||
{
|
{
|
||||||
@@ -394,7 +379,7 @@ common_bind(int fd, const struct sockaddr *address, socklen_t addressLength,
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->bind(descriptor->u.socket, address, addressLength);
|
return sStackInterface->bind(descriptor->u.socket, address, addressLength);
|
||||||
}
|
}
|
||||||
@@ -405,7 +390,7 @@ common_shutdown(int fd, int how, bool kernel)
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->shutdown(descriptor->u.socket, how);
|
return sStackInterface->shutdown(descriptor->u.socket, how);
|
||||||
}
|
}
|
||||||
@@ -417,7 +402,7 @@ common_connect(int fd, const struct sockaddr *address,
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->connect(descriptor->u.socket, address,
|
return sStackInterface->connect(descriptor->u.socket, address,
|
||||||
addressLength);
|
addressLength);
|
||||||
@@ -429,7 +414,7 @@ common_listen(int fd, int backlog, bool kernel)
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->listen(descriptor->u.socket, backlog);
|
return sStackInterface->listen(descriptor->u.socket, backlog);
|
||||||
}
|
}
|
||||||
@@ -441,7 +426,7 @@ common_accept(int fd, struct sockaddr *address, socklen_t *_addressLength,
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
net_socket* acceptedSocket;
|
net_socket* acceptedSocket;
|
||||||
status_t error = sStackInterface->accept(descriptor->u.socket, address,
|
status_t error = sStackInterface->accept(descriptor->u.socket, address,
|
||||||
@@ -468,7 +453,7 @@ common_recv(int fd, void *data, size_t length, int flags, bool kernel)
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->recv(descriptor->u.socket, data, length, flags);
|
return sStackInterface->recv(descriptor->u.socket, data, length, flags);
|
||||||
}
|
}
|
||||||
@@ -480,7 +465,7 @@ common_recvfrom(int fd, void *data, size_t length, int flags,
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->recvfrom(descriptor->u.socket, data, length,
|
return sStackInterface->recvfrom(descriptor->u.socket, data, length,
|
||||||
flags, address, _addressLength);
|
flags, address, _addressLength);
|
||||||
@@ -492,7 +477,7 @@ common_recvmsg(int fd, struct msghdr *message, int flags, bool kernel)
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->recvmsg(descriptor->u.socket, message, flags);
|
return sStackInterface->recvmsg(descriptor->u.socket, message, flags);
|
||||||
}
|
}
|
||||||
@@ -503,7 +488,7 @@ common_send(int fd, const void *data, size_t length, int flags, bool kernel)
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->send(descriptor->u.socket, data, length, flags);
|
return sStackInterface->send(descriptor->u.socket, data, length, flags);
|
||||||
}
|
}
|
||||||
@@ -515,7 +500,7 @@ common_sendto(int fd, const void *data, size_t length, int flags,
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->sendto(descriptor->u.socket, data, length, flags,
|
return sStackInterface->sendto(descriptor->u.socket, data, length, flags,
|
||||||
address, addressLength);
|
address, addressLength);
|
||||||
@@ -527,7 +512,7 @@ common_sendmsg(int fd, const struct msghdr *message, int flags, bool kernel)
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->sendmsg(descriptor->u.socket, message, flags);
|
return sStackInterface->sendmsg(descriptor->u.socket, message, flags);
|
||||||
}
|
}
|
||||||
@@ -539,7 +524,7 @@ common_getsockopt(int fd, int level, int option, void *value,
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->getsockopt(descriptor->u.socket, level, option,
|
return sStackInterface->getsockopt(descriptor->u.socket, level, option,
|
||||||
value, _length);
|
value, _length);
|
||||||
@@ -552,7 +537,7 @@ common_setsockopt(int fd, int level, int option, const void *value,
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->setsockopt(descriptor->u.socket, level, option,
|
return sStackInterface->setsockopt(descriptor->u.socket, level, option,
|
||||||
value, length);
|
value, length);
|
||||||
@@ -565,7 +550,7 @@ common_getpeername(int fd, struct sockaddr *address,
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->getpeername(descriptor->u.socket, address,
|
return sStackInterface->getpeername(descriptor->u.socket, address,
|
||||||
_addressLength);
|
_addressLength);
|
||||||
@@ -578,7 +563,7 @@ common_getsockname(int fd, struct sockaddr *address,
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->getsockname(descriptor->u.socket, address,
|
return sStackInterface->getsockname(descriptor->u.socket, address,
|
||||||
_addressLength);
|
_addressLength);
|
||||||
@@ -590,7 +575,7 @@ common_sockatmark(int fd, bool kernel)
|
|||||||
{
|
{
|
||||||
file_descriptor* descriptor;
|
file_descriptor* descriptor;
|
||||||
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
GET_SOCKET_FD_OR_RETURN(fd, kernel, descriptor);
|
||||||
FDPutter _(descriptor);
|
FileDescriptorPutter _(descriptor);
|
||||||
|
|
||||||
return sStackInterface->sockatmark(descriptor->u.socket);
|
return sStackInterface->sockatmark(descriptor->u.socket);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include <StorageDefs.h>
|
#include <StorageDefs.h>
|
||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
#include <AutoDeleterDrivers.h>
|
||||||
#include <block_cache.h>
|
#include <block_cache.h>
|
||||||
#include <boot/kernel_args.h>
|
#include <boot/kernel_args.h>
|
||||||
#include <debug_heap.h>
|
#include <debug_heap.h>
|
||||||
@@ -6439,7 +6440,7 @@ 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)
|
||||||
{
|
{
|
||||||
CObjectDeleter<struct file_descriptor, void, put_fd> descriptor;
|
FileDescriptorPutter descriptor;
|
||||||
struct vnode* vnode;
|
struct vnode* vnode;
|
||||||
|
|
||||||
if (offset < 0 || length == 0)
|
if (offset < 0 || length == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user