* Replaced all "status < B_OK" with != B_OK - this should make the VFS layer

more robust against broken (userland) file systems.
* 80 character column cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32184 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-08-07 12:29:17 +00:00
parent b90e7304ed
commit f7a6506e0f
2 changed files with 352 additions and 297 deletions

View File

@ -1,10 +1,12 @@
/*
* Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
//! Operations on file descriptors
#include <fd.h>
#include <stdlib.h>
@ -83,7 +85,7 @@ public:
};
/*** General fd routines ***/
// #pragma mark - General fd routines
#ifdef DEBUG
@ -92,15 +94,17 @@ void dump_fd(int fd, struct file_descriptor *descriptor);
void
dump_fd(int fd,struct file_descriptor* descriptor)
{
dprintf("fd[%d] = %p: type = %ld, ref_count = %ld, ops = %p, u.vnode = %p, u.mount = %p, cookie = %p, open_mode = %lx, pos = %Ld\n",
fd, descriptor, descriptor->type, descriptor->ref_count, descriptor->ops,
descriptor->u.vnode, descriptor->u.mount, descriptor->cookie, descriptor->open_mode, descriptor->pos);
dprintf("fd[%d] = %p: type = %ld, ref_count = %ld, ops = %p, u.vnode = %p, "
"u.mount = %p, cookie = %p, open_mode = %lx, pos = %Ld\n",
fd, descriptor, descriptor->type, descriptor->ref_count,
descriptor->ops, descriptor->u.vnode, descriptor->u.mount,
descriptor->cookie, descriptor->open_mode, descriptor->pos);
}
#endif
/** Allocates and initializes a new file_descriptor */
/*! Allocates and initializes a new file_descriptor.
*/
struct file_descriptor*
alloc_fd(void)
{
@ -137,12 +141,12 @@ fd_set_close_on_exec(struct io_context *context, int fd, bool closeFD)
}
/** Searches a free slot in the FD table of the provided I/O context, and inserts
* the specified descriptor into it.
/*! Searches a free slot in the FD table of the provided I/O context, and
inserts the specified descriptor into it.
*/
int
new_fd_etc(struct io_context *context, struct file_descriptor *descriptor, int firstIndex)
new_fd_etc(struct io_context* context, struct file_descriptor* descriptor,
int firstIndex)
{
int fd = -1;
uint32 i;
@ -178,10 +182,9 @@ new_fd(struct io_context *context, struct file_descriptor *descriptor)
}
/** Reduces the descriptor's reference counter, and frees all resources
* when it's no longer used.
/*! Reduces the descriptor's reference counter, and frees all resources
when it's no longer used.
*/
void
put_fd(struct file_descriptor* descriptor)
{
@ -221,10 +224,9 @@ put_fd(struct file_descriptor *descriptor)
}
/** Decrements the open counter of the file descriptor and invokes
* its close hook when appropriate.
/*! Decrements the open counter of the file descriptor and invokes
its close hook when appropriate.
*/
void
close_fd(struct file_descriptor* descriptor)
{
@ -253,13 +255,12 @@ close_fd_index(struct io_context *context, int fd)
}
/** This descriptor's underlying object will be closed and freed
* as soon as possible (in one of the next calls to put_fd() -
* get_fd() will no longer succeed on this descriptor).
* This is useful if the underlying object is gone, for instance
* when a (mounted) volume got removed unexpectedly.
/*! This descriptor's underlying object will be closed and freed as soon as
possible (in one of the next calls to put_fd() - get_fd() will no longer
succeed on this descriptor).
This is useful if the underlying object is gone, for instance when a
(mounted) volume got removed unexpectedly.
*/
void
disconnect_fd(struct file_descriptor* descriptor)
{
@ -318,9 +319,8 @@ get_open_fd(struct io_context *context, int fd)
}
/** Removes the file descriptor from the specified slot.
/*! Removes the file descriptor from the specified slot.
*/
static struct file_descriptor*
remove_fd(struct io_context* context, int fd)
{
@ -663,15 +663,15 @@ deselect_fd(int32 fd, struct select_info* info, bool kernel)
}
/** This function checks if the specified fd is valid in the current
* context. It can be used for a quick check; the fd is not locked
* so it could become invalid immediately after this check.
/*! This function checks if the specified fd is valid in the current
context. It can be used for a quick check; the fd is not locked
so it could become invalid immediately after this check.
*/
bool
fd_is_valid(int fd, bool kernel)
{
struct file_descriptor *descriptor = get_fd(get_current_io_context(kernel), fd);
struct file_descriptor* descriptor
= get_fd(get_current_io_context(kernel), fd);
if (descriptor == NULL)
return false;
@ -739,7 +739,7 @@ common_user_io(int fd, off_t pos, void *buffer, size_t length, bool write)
else
status = descriptor->ops->fd_read(descriptor, pos, buffer, &length);
if (status < B_OK)
if (status != B_OK)
return status;
if (movePosition)
@ -759,7 +759,7 @@ common_user_vector_io(int fd, off_t pos, const iovec *userVecs, size_t count,
if (pos < -1)
return B_BAD_VALUE;
/* prevent integer overflow exploit in malloc() */
// prevent integer overflow exploit in malloc()
if (count > IOV_MAX)
return B_BAD_VALUE;
@ -778,7 +778,7 @@ common_user_vector_io(int fd, off_t pos, const iovec *userVecs, size_t count,
return B_NO_MEMORY;
MemoryDeleter _(vecs);
if (user_memcpy(vecs, userVecs, sizeof(iovec) * count) < B_OK)
if (user_memcpy(vecs, userVecs, sizeof(iovec) * count) != B_OK)
return B_BAD_ADDRESS;
bool movePosition = false;
@ -805,7 +805,7 @@ common_user_vector_io(int fd, off_t pos, const iovec *userVecs, size_t count,
&length);
}
if (status < B_OK) {
if (status != B_OK) {
if (bytesTransferred == 0)
return status;
status = B_OK;
@ -908,7 +908,8 @@ _user_ioctl(int fd, ulong op, void *buffer, size_t length)
ssize_t
_user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount)
_user_read_dir(int fd, struct dirent* buffer, size_t bufferSize,
uint32 maxCount)
{
struct file_descriptor* descriptor;
ssize_t retval;
@ -916,7 +917,8 @@ _user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount
if (!IS_USER_ADDRESS(buffer))
return B_BAD_ADDRESS;
TRACE(("user_read_dir(fd = %d, buffer = %p, bufferSize = %ld, count = %lu)\n", fd, buffer, bufferSize, maxCount));
TRACE(("user_read_dir(fd = %d, buffer = %p, bufferSize = %ld, count = "
"%lu)\n", fd, buffer, bufferSize, maxCount));
struct io_context* ioContext = get_current_io_context(false);
descriptor = get_fd(ioContext, fd);
@ -1058,7 +1060,7 @@ _kern_readv(int fd, off_t pos, const iovec *vecs, size_t count)
size_t length = vecs[i].iov_len;
status = descriptor->ops->fd_read(descriptor, pos, vecs[i].iov_base,
&length);
if (status < B_OK) {
if (status != B_OK) {
bytesRead = status;
break;
}
@ -1153,7 +1155,7 @@ _kern_writev(int fd, off_t pos, const iovec *vecs, size_t count)
size_t length = vecs[i].iov_len;
status = descriptor->ops->fd_write(descriptor, pos,
vecs[i].iov_base, &length);
if (status < B_OK) {
if (status != B_OK) {
bytesWritten = status;
break;
}
@ -1204,12 +1206,14 @@ _kern_ioctl(int fd, ulong op, void *buffer, size_t length)
ssize_t
_kern_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount)
_kern_read_dir(int fd, struct dirent* buffer, size_t bufferSize,
uint32 maxCount)
{
struct file_descriptor* descriptor;
ssize_t retval;
TRACE(("sys_read_dir(fd = %d, buffer = %p, bufferSize = %ld, count = %lu)\n",fd, buffer, bufferSize, maxCount));
TRACE(("sys_read_dir(fd = %d, buffer = %p, bufferSize = %ld, count = "
"%lu)\n",fd, buffer, bufferSize, maxCount));
struct io_context* ioContext = get_current_io_context(true);
descriptor = get_fd(ioContext, fd);

File diff suppressed because it is too large Load Diff