Revert "VFS: Slight rework of the FD disconnect feature."
This reverts commit eb62d3337b
.
This commit is contained in:
parent
675e5dfcac
commit
15ec0b5cc8
@ -224,11 +224,13 @@ put_fd(struct file_descriptor* descriptor)
|
||||
descriptor->ops->fd_free(descriptor);
|
||||
|
||||
// prevent this descriptor from being closed/freed again
|
||||
descriptor->open_count = -1;
|
||||
descriptor->ref_count = -1;
|
||||
descriptor->ops = NULL;
|
||||
descriptor->u.vnode = NULL;
|
||||
|
||||
// the file descriptor is kept intact, so that it's not
|
||||
// reused until someone explicitly closes it
|
||||
// reused until someone explicetly closes it
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,9 +299,14 @@ get_fd_locked(struct io_context* context, int fd)
|
||||
struct file_descriptor* descriptor = context->fds[fd];
|
||||
|
||||
if (descriptor != NULL) {
|
||||
// Disconnected descriptors cannot be accessed anymore
|
||||
if (descriptor->open_mode & O_DISCONNECTED)
|
||||
descriptor = NULL;
|
||||
else {
|
||||
TFD(GetFD(context, fd, descriptor));
|
||||
inc_fd_ref_count(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
@ -320,7 +327,7 @@ get_open_fd(struct io_context* context, int fd)
|
||||
MutexLocker _(context->io_mutex);
|
||||
|
||||
file_descriptor* descriptor = get_fd_locked(context, fd);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (descriptor == NULL)
|
||||
return NULL;
|
||||
|
||||
atomic_add(&descriptor->open_count, 1);
|
||||
@ -424,8 +431,7 @@ dup2_fd(int oldfd, int newfd, bool kernel)
|
||||
// the table size could be changed)
|
||||
if ((uint32)oldfd >= context->table_size
|
||||
|| (uint32)newfd >= context->table_size
|
||||
|| context->fds[oldfd] == NULL
|
||||
|| (context->fds[oldfd]->open_mode & O_DISCONNECTED) != 0) {
|
||||
|| context->fds[oldfd] == NULL) {
|
||||
mutex_unlock(&context->io_mutex);
|
||||
return B_FILE_ERROR;
|
||||
}
|
||||
@ -506,10 +512,10 @@ fd_ioctl(bool kernelFD, int fd, uint32 op, void* buffer, size_t length)
|
||||
int status;
|
||||
|
||||
descriptor = get_fd(get_current_io_context(kernelFD), fd);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (descriptor == NULL)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
if (descriptor->ops->fd_ioctl != NULL)
|
||||
if (descriptor->ops->fd_ioctl)
|
||||
status = descriptor->ops->fd_ioctl(descriptor, op, buffer, length);
|
||||
else
|
||||
status = B_DEV_INVALID_IOCTL;
|
||||
@ -565,7 +571,7 @@ select_fd(int32 fd, struct select_info* info, bool kernel)
|
||||
MutexLocker locker(context->io_mutex);
|
||||
|
||||
struct file_descriptor* descriptor = fdGetter.SetTo(context, fd, true);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (descriptor == NULL)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
uint16 eventsToSelect = info->selected_events & ~B_EVENT_INVALID;
|
||||
@ -687,7 +693,7 @@ fd_is_valid(int fd, bool kernel)
|
||||
{
|
||||
struct file_descriptor* descriptor
|
||||
= get_fd(get_current_io_context(kernel), fd);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (descriptor == NULL)
|
||||
return false;
|
||||
|
||||
put_fd(descriptor);
|
||||
@ -728,7 +734,7 @@ common_user_io(int fd, off_t pos, void* buffer, size_t length, bool write)
|
||||
|
||||
FDGetter fdGetter;
|
||||
struct file_descriptor* descriptor = fdGetter.SetTo(fd, false);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (!descriptor)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
if (write ? (descriptor->open_mode & O_RWMASK) == O_RDONLY
|
||||
@ -780,7 +786,7 @@ common_user_vector_io(int fd, off_t pos, const iovec* userVecs, size_t count,
|
||||
|
||||
FDGetter fdGetter;
|
||||
struct file_descriptor* descriptor = fdGetter.SetTo(fd, false);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (!descriptor)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
if (write ? (descriptor->open_mode & O_RWMASK) == O_RDONLY
|
||||
@ -893,12 +899,12 @@ _user_seek(int fd, off_t pos, int seekType)
|
||||
struct file_descriptor* descriptor;
|
||||
|
||||
descriptor = get_fd(get_current_io_context(false), fd);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (!descriptor)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
TRACE(("user_seek(descriptor = %p)\n", descriptor));
|
||||
|
||||
if (descriptor->ops->fd_seek != NULL)
|
||||
if (descriptor->ops->fd_seek)
|
||||
pos = descriptor->ops->fd_seek(descriptor, pos, seekType);
|
||||
else
|
||||
pos = ESPIPE;
|
||||
@ -939,7 +945,7 @@ _user_read_dir(int fd, struct dirent* userBuffer, size_t bufferSize,
|
||||
io_context* ioContext = get_current_io_context(false);
|
||||
FDGetter fdGetter;
|
||||
struct file_descriptor* descriptor = fdGetter.SetTo(ioContext, fd, false);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (descriptor == NULL)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
if (descriptor->ops->fd_read_dir == NULL)
|
||||
@ -985,10 +991,10 @@ _user_rewind_dir(int fd)
|
||||
TRACE(("user_rewind_dir(fd = %d)\n", fd));
|
||||
|
||||
descriptor = get_fd(get_current_io_context(false), fd);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (descriptor == NULL)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
if (descriptor->ops->fd_rewind_dir != NULL)
|
||||
if (descriptor->ops->fd_rewind_dir)
|
||||
status = descriptor->ops->fd_rewind_dir(descriptor);
|
||||
else
|
||||
status = B_UNSUPPORTED;
|
||||
@ -1126,7 +1132,7 @@ _kern_write(int fd, off_t pos, const void* buffer, size_t length)
|
||||
FDGetter fdGetter;
|
||||
struct file_descriptor* descriptor = fdGetter.SetTo(fd, true);
|
||||
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (descriptor == NULL)
|
||||
return B_FILE_ERROR;
|
||||
if ((descriptor->open_mode & O_RWMASK) == O_RDONLY)
|
||||
return B_FILE_ERROR;
|
||||
@ -1254,7 +1260,7 @@ _kern_read_dir(int fd, struct dirent* buffer, size_t bufferSize,
|
||||
|
||||
struct io_context* ioContext = get_current_io_context(true);
|
||||
descriptor = get_fd(ioContext, fd);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (descriptor == NULL)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
if (descriptor->ops->fd_read_dir) {
|
||||
@ -1280,7 +1286,7 @@ _kern_rewind_dir(int fd)
|
||||
TRACE(("sys_rewind_dir(fd = %d)\n",fd));
|
||||
|
||||
descriptor = get_fd(get_current_io_context(true), fd);
|
||||
if (descriptor == NULL || (descriptor->open_mode & O_DISCONNECTED) != 0)
|
||||
if (descriptor == NULL)
|
||||
return B_FILE_ERROR;
|
||||
|
||||
if (descriptor->ops->fd_rewind_dir)
|
||||
|
@ -4990,8 +4990,7 @@ vfs_new_io_context(io_context* parentContext, bool purgeCloseOnExec)
|
||||
for (i = 0; i < tableSize; i++) {
|
||||
struct file_descriptor* descriptor = parentContext->fds[i];
|
||||
|
||||
if (descriptor != NULL
|
||||
&& (descriptor->open_mode & O_DISCONNECTED) == 0) {
|
||||
if (descriptor != NULL) {
|
||||
bool closeOnExec = fd_close_on_exec(parentContext, i);
|
||||
if (closeOnExec && purgeCloseOnExec)
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user