Changed the argument order of sys_read/write() to be more intuitive.

Fixed a bug in module.c that I caused due to changes in the VFS.
Added the sys_write_link() call.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@666 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2002-08-09 17:03:03 +00:00
parent 75cf4c1ea5
commit 2f5118ccdc
16 changed files with 216 additions and 126 deletions

View File

@ -356,12 +356,10 @@ KernelStaticLibraryObjects libc.a :
<$(SOURCE_GRIST)!libc!unistd>open.o
<$(SOURCE_GRIST)!libc!unistd>opendir.o
<$(SOURCE_GRIST)!libc!unistd>link.o
<$(SOURCE_GRIST)!libc!unistd>pread.o
<$(SOURCE_GRIST)!libc!unistd>pwrite.o
<$(SOURCE_GRIST)!libc!unistd>read.o
<$(SOURCE_GRIST)!libc!unistd>write.o
<$(SOURCE_GRIST)!libc!unistd>sleep.o
<$(SOURCE_GRIST)!libc!unistd>usleep.o
<$(SOURCE_GRIST)!libc!unistd>write.o
;
KernelLd libc.so :
@ -473,12 +471,10 @@ KernelLd libc.so :
<$(SOURCE_GRIST)!libc!unistd>open.o
<$(SOURCE_GRIST)!libc!unistd>opendir.o
<$(SOURCE_GRIST)!libc!unistd>link.o
<$(SOURCE_GRIST)!libc!unistd>pread.o
<$(SOURCE_GRIST)!libc!unistd>pwrite.o
<$(SOURCE_GRIST)!libc!unistd>read.o
<$(SOURCE_GRIST)!libc!unistd>write.o
<$(SOURCE_GRIST)!libc!unistd>sleep.o
<$(SOURCE_GRIST)!libc!unistd>usleep.o
<$(SOURCE_GRIST)!libc!unistd>write.o
:
$(SUBDIR)/ldscripts/$(OBOS_ARCH)/library.ld
:

View File

@ -2,11 +2,15 @@
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <string.h>
#include <stdio.h>
#include <syscalls.h>
int printf(const char *fmt, ...)
int
printf(const char *fmt, ...)
{
va_list args;
char buf[1024];
@ -16,7 +20,7 @@ int printf(const char *fmt, ...)
i = vsprintf(buf, fmt, args);
va_end(args);
sys_write(2, buf, 0, strlen(buf));
sys_write(2, 0, buf, strlen(buf));
return i;
}

View File

@ -748,41 +748,41 @@ load_container(char const *path, char const *name, bool fixed)
struct Elf32_Ehdr eheader;
found= find_image(name);
if(found) {
found->refcount+= 1;
found = find_image(name);
if (found) {
found->refcount += 1;
return found;
}
fd= sys_open(path, 0);
FATAL((fd< 0), "cannot open file %s\n", path);
fd = sys_open(path, 0);
FATAL((fd < 0), "cannot open file %s\n", path);
len= sys_read(fd, &eheader, 0, sizeof(eheader));
FATAL((len!= sizeof(eheader)), "troubles reading ELF header\n");
len = sys_read(fd, 0, &eheader, sizeof(eheader));
FATAL((len != sizeof(eheader)), "troubles reading ELF header\n");
ph_len= parse_eheader(&eheader);
FATAL((ph_len<= 0), "incorrect ELF header\n");
FATAL((ph_len> (int)sizeof(ph_buff)), "cannot handle Program headers bigger than %lu\n", (long unsigned)sizeof(ph_buff));
ph_len = parse_eheader(&eheader);
FATAL((ph_len <= 0), "incorrect ELF header\n");
FATAL((ph_len > (int)sizeof(ph_buff)), "cannot handle Program headers bigger than %lu\n", (long unsigned)sizeof(ph_buff));
len= sys_read(fd, ph_buff, eheader.e_phoff, ph_len);
FATAL((len!= ph_len), "troubles reading Program headers\n");
len = sys_read(fd, eheader.e_phoff, ph_buff, ph_len);
FATAL((len != ph_len), "troubles reading Program headers\n");
num_regions= count_regions(ph_buff, eheader.e_phnum, eheader.e_phentsize);
FATAL((num_regions<= 0), "troubles parsing Program headers, num_regions= %d\n", num_regions);
num_regions = count_regions(ph_buff, eheader.e_phnum, eheader.e_phentsize);
FATAL((num_regions <= 0), "troubles parsing Program headers, num_regions= %d\n", num_regions);
image= create_image(name, num_regions);
image = create_image(name, num_regions);
FATAL((!image), "failed to allocate image_t control block\n");
parse_program_headers(image, ph_buff, eheader.e_phnum, eheader.e_phentsize);
FATAL(!assert_dynamic_loadable(image), "dynamic segment must be loadable (implementation restriction)\n");
map_success= map_image(fd, path, image, fixed);
map_success = map_image(fd, path, image, fixed);
FATAL(!map_success, "troubles reading image\n");
dynamic_success= parse_dynamic_segment(image);
dynamic_success = parse_dynamic_segment(image);
FATAL(!dynamic_success, "troubles handling dynamic section\n");
image->entry_point= eheader.e_entry + image->regions[0].delta;
image->entry_point = eheader.e_entry + image->regions[0].delta;
sys_close(fd);
@ -804,11 +804,10 @@ load_dependencies(image_t *img)
char path[256];
d = (struct Elf32_Dyn *)img->dynamic_ptr;
if(!d) {
if (!d)
return;
}
img->needed= rldalloc(img->num_needed*sizeof(image_t*));
img->needed = rldalloc(img->num_needed*sizeof(image_t*));
FATAL((!img->needed), "failed to allocate needed struct\n");
memset(img->needed, 0, img->num_needed*sizeof(image_t*));

View File

@ -118,7 +118,7 @@ int cmd_cat(int argc, char *argv[])
}
for(;;) {
rc = sys_read(fd, buf, -1, sizeof(buf) -1);
rc = sys_read(fd, -1, buf, sizeof(buf) -1);
if(rc <= 0)
break;

View File

@ -91,18 +91,18 @@ int read_file_in_buffer(const char *filename,char **buffer)
*buffer = NULL;
file_no = open(filename, O_RDONLY);
if (file_no < 0){
if (file_no < 0)
return file_no;
}
err = fstat(file_no,&stat);
if (err < 0)
return err;
*buffer = malloc(stat.st_size + 1);
if(*buffer == NULL) return ENOMEM;
if (*buffer == NULL)
return ENOMEM;
size = sys_read(file_no,*buffer,0,stat.st_size);
size = sys_read(file_no, 0, *buffer, stat.st_size);
sys_close(file_no);

View File

@ -30,29 +30,33 @@ struct console_op_xy_struct {
static int console_fd = -1;
int kprintf(const char *fmt, ...)
int
kprintf(const char *fmt, ...)
{
int ret = 0;
va_list args;
char temp[256];
if(console_fd >= 0) {
if (console_fd >= 0) {
va_start(args, fmt);
ret = vsprintf(temp,fmt,args);
va_end(args);
sys_write(console_fd, temp, 0, ret);
sys_write(console_fd, 0, temp, ret);
}
return ret;
}
int kprintf_xy(int x, int y, const char *fmt, ...)
int
kprintf_xy(int x, int y, const char *fmt, ...)
{
int ret = 0;
va_list args;
struct console_op_xy_struct buf;
if(console_fd >= 0) {
if (console_fd >= 0) {
va_start(args, fmt);
ret = vsprintf(buf.buf,fmt,args);
va_end(args);
@ -64,7 +68,9 @@ int kprintf_xy(int x, int y, const char *fmt, ...)
return ret;
}
int con_init(kernel_args *ka)
int
con_init(kernel_args *ka)
{
dprintf("con_init: entry\n");

View File

@ -632,7 +632,7 @@ elf_load_uspace(const char *path, struct team *p, int flags, addr *entry)
// read and verify the ELF header
len = sys_read(fd, &eheader, 0, sizeof(eheader));
len = sys_read(fd, 0, &eheader, sizeof(eheader));
if (len < 0) {
err = len;
goto error;
@ -657,7 +657,7 @@ elf_load_uspace(const char *path, struct team *p, int flags, addr *entry)
}
dprintf("reading in program headers at 0x%x, len 0x%x\n", eheader.e_phoff, eheader.e_phnum * eheader.e_phentsize);
len = sys_read(fd, pheaders, eheader.e_phoff, eheader.e_phnum * eheader.e_phentsize);
len = sys_read(fd, eheader.e_phoff, pheaders, eheader.e_phnum * eheader.e_phentsize);
if (len < 0) {
err = len;
dprintf("error reading in program headers\n");
@ -815,7 +815,7 @@ elf_load_kspace(const char *path, const char *sym_prepend)
goto error;
}
len = sys_read(fd, eheader, 0, sizeof(*eheader));
len = sys_read(fd, 0, eheader, sizeof(*eheader));
if (len < 0) {
err = len;
goto error1;
@ -846,7 +846,7 @@ elf_load_kspace(const char *path, const char *sym_prepend)
}
PRINT(("reading in program headers at 0x%x, len 0x%x\n", eheader->e_phoff, eheader->e_phnum * eheader->e_phentsize));
len = sys_read(fd, pheaders, eheader->e_phoff, eheader->e_phnum * eheader->e_phentsize);
len = sys_read(fd, eheader->e_phoff, pheaders, eheader->e_phnum * eheader->e_phentsize);
if (len < 0) {
err = len;
PRINT(("error reading in program headers\n"));
@ -918,8 +918,9 @@ elf_load_kspace(const char *path, const char *sym_prepend)
PRINT(("elf_load_kspace: created a region at %p\n", (void *)image->regions[image_region].start));
len = sys_read(fd, (void *)(image->regions[image_region].start + (pheaders[i].p_vaddr % PAGE_SIZE)),
pheaders[i].p_offset, pheaders[i].p_filesz);
len = sys_read(fd, pheaders[i].p_offset,
(void *)(image->regions[image_region].start + (pheaders[i].p_vaddr % PAGE_SIZE)),
pheaders[i].p_filesz);
if (len < 0) {
err = len;
dprintf("error reading in seg %d\n", i);

View File

@ -229,7 +229,7 @@ fd_dup2(int oldfd, int newfd, bool kernel)
ssize_t
user_read(int fd, void *buffer, off_t pos, size_t length)
user_read(int fd, off_t pos, void *buffer, size_t length)
{
struct file_descriptor *descriptor;
ssize_t retval;
@ -242,7 +242,7 @@ user_read(int fd, void *buffer, off_t pos, size_t length)
return EBADF;
if (descriptor->ops->fd_read) {
retval = descriptor->ops->fd_read(descriptor, buffer, pos, &length);
retval = descriptor->ops->fd_read(descriptor, pos, buffer, &length);
if (retval >= 0)
retval = (ssize_t)length;
} else
@ -254,7 +254,7 @@ user_read(int fd, void *buffer, off_t pos, size_t length)
ssize_t
user_write(int fd, const void *buffer, off_t pos, size_t length)
user_write(int fd, off_t pos, const void *buffer, size_t length)
{
struct file_descriptor *descriptor;
ssize_t retval = 0;
@ -266,7 +266,7 @@ user_write(int fd, const void *buffer, off_t pos, size_t length)
return EBADF;
if (descriptor->ops->fd_write) {
retval = descriptor->ops->fd_write(descriptor, buffer, pos, &length);
retval = descriptor->ops->fd_write(descriptor, pos, buffer, &length);
if (retval >= 0)
retval = (ssize_t)length;
} else
@ -439,7 +439,7 @@ user_dup2(int ofd, int nfd)
ssize_t
sys_read(int fd, void *buffer, off_t pos, size_t length)
sys_read(int fd, off_t pos, void *buffer, size_t length)
{
struct file_descriptor *descriptor;
ssize_t retval;
@ -449,7 +449,7 @@ sys_read(int fd, void *buffer, off_t pos, size_t length)
return EBADF;
if (descriptor->ops->fd_read) {
retval = descriptor->ops->fd_read(descriptor, buffer, pos, &length);
retval = descriptor->ops->fd_read(descriptor, pos, buffer, &length);
if (retval >= 0)
retval = (ssize_t)length;
} else
@ -461,7 +461,7 @@ sys_read(int fd, void *buffer, off_t pos, size_t length)
ssize_t
sys_write(int fd, const void *buffer, off_t pos, size_t length)
sys_write(int fd, off_t pos, const void *buffer, size_t length)
{
struct file_descriptor *descriptor;
ssize_t retval;
@ -471,7 +471,7 @@ sys_write(int fd, const void *buffer, off_t pos, size_t length)
return EBADF;
if (descriptor->ops->fd_write) {
retval = descriptor->ops->fd_write(descriptor, buffer, pos, &length);
retval = descriptor->ops->fd_write(descriptor, pos, buffer, &length);
if (retval >= 0)
retval = (ssize_t)length;

View File

@ -671,7 +671,7 @@ bootfs_fsync(fs_cookie _fs, fs_vnode _v)
static ssize_t
bootfs_read(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, void *buf, off_t pos, size_t *len)
bootfs_read(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, off_t pos, void *buf, size_t *len)
{
struct bootfs *fs = _fs;
struct bootfs_vnode *v = _v;
@ -720,7 +720,7 @@ err:
static ssize_t
bootfs_write(fs_cookie fs, fs_vnode v, file_cookie cookie, const void *buf, off_t pos, size_t *len)
bootfs_write(fs_cookie fs, fs_vnode v, file_cookie cookie, off_t pos, const void *buf, size_t *len)
{
TRACE(("bootfs_write: vnode 0x%x, cookie 0x%x, pos 0x%x 0x%x, len 0x%x\n", v, cookie, pos, *len));

View File

@ -696,7 +696,7 @@ devfs_fsync(fs_cookie _fs, fs_vnode _v)
static ssize_t
devfs_read(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, void *buffer, off_t pos, size_t *length)
devfs_read(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, off_t pos, void *buffer, size_t *length)
{
struct devfs *fs = _fs;
struct devfs_vnode *vnode = _v;
@ -729,8 +729,7 @@ devfs_read(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, void *buffer, off_t
static ssize_t
devfs_write(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, const void *buf,
off_t pos, size_t *len)
devfs_write(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, off_t pos, const void *buf, size_t *len)
{
struct devfs_vnode *vnode = _v;
struct devfs_cookie *cookie = _cookie;

View File

@ -490,14 +490,14 @@ rootfs_fsync(fs_cookie _fs, fs_vnode _v)
static ssize_t
rootfs_read(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, void *buf, off_t pos, size_t *len)
rootfs_read(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, off_t pos, void *buf, size_t *len)
{
return EINVAL;
}
static ssize_t
rootfs_write(fs_cookie fs, fs_vnode v, file_cookie cookie, const void *buf, off_t pos, size_t *len)
rootfs_write(fs_cookie fs, fs_vnode v, file_cookie cookie, off_t pos, const void *buf, size_t *len)
{
TRACE(("rootfs_write: vnode 0x%x, cookie 0x%x, pos 0x%x 0x%x, len 0x%x\n", v, cookie, pos, *len));

View File

@ -121,8 +121,8 @@ static int vfs_close(struct file_descriptor *, int, struct io_context *);
static int common_ioctl(struct file_descriptor *, ulong, void *buf, size_t len);
static int common_read_stat(struct file_descriptor *, struct stat *);
static ssize_t file_read(struct file_descriptor *, void *, off_t, size_t *);
static ssize_t file_write(struct file_descriptor *, const void *, off_t, size_t *);
static ssize_t file_read(struct file_descriptor *, off_t pos, void *buffer, size_t *);
static ssize_t file_write(struct file_descriptor *, off_t pos, const void *buffer, size_t *);
static off_t file_seek(struct file_descriptor *, off_t pos, int seek_type);
static status_t dir_read(struct file_descriptor *,struct dirent *buffer,size_t bufferSize,uint32 *_count);
static status_t dir_rewind(struct file_descriptor *);
@ -1771,22 +1771,22 @@ file_close(struct file_descriptor *descriptor)
static ssize_t
file_read(struct file_descriptor *descriptor, void *buffer, off_t pos, size_t *length)
file_read(struct file_descriptor *descriptor, off_t pos, void *buffer, size_t *length)
{
struct vnode *vnode = descriptor->vnode;
FUNCTION(("file_read: buf %p, pos %Ld, len %p = %ld\n", buffer, pos, length, *length));
return FS_CALL(vnode,fs_read)(vnode->mount->cookie, vnode->private_node, descriptor->cookie, buffer, pos, length);
return FS_CALL(vnode,fs_read)(vnode->mount->cookie, vnode->private_node, descriptor->cookie, pos, buffer, length);
}
static ssize_t
file_write(struct file_descriptor *descriptor, const void *buffer, off_t pos, size_t *length)
file_write(struct file_descriptor *descriptor, off_t pos, const void *buffer, size_t *length)
{
struct vnode *vnode = descriptor->vnode;
FUNCTION(("file_write: buf %p, pos %Ld, len %p\n", buffer, pos, length));
return FS_CALL(vnode,fs_write)(vnode->mount->cookie, vnode->private_node, descriptor->cookie, buffer, pos, length);
return FS_CALL(vnode,fs_write)(vnode->mount->cookie, vnode->private_node, descriptor->cookie, pos, buffer, length);
}
@ -2322,7 +2322,7 @@ fs_unmount(char *path, bool kernel)
dec_vnode_ref_count(mount->root_vnode, false);
dec_vnode_ref_count(mount->root_vnode, false);
// XXX when full vnode cache in place, will need to force
// ToDo: when full vnode cache in place, will need to force
// a putvnode/removevnode here
/* remove the mount structure from the hash table */
@ -2389,7 +2389,7 @@ fs_read_info(dev_t device, struct fs_info *info)
else
status = EOPNOTSUPP;
// fill in other info the file system doesn't know about
// fill in other info the file system doesn't (have to) know about
info->dev = mount->id;
info->root = mount->root_vnode->id;
@ -2651,6 +2651,27 @@ sys_read_link(const char *path, char *buffer, size_t bufferSize)
}
int
sys_write_link(const char *path, const char *toPath)
{
char pathCopy[SYS_MAX_PATH_LEN + 1];
char toPathCopy[SYS_MAX_PATH_LEN + 1];
int status;
strncpy(pathCopy, path, SYS_MAX_PATH_LEN);
pathCopy[SYS_MAX_PATH_LEN] = '\0';
strncpy(toPathCopy, toPath, SYS_MAX_PATH_LEN);
toPathCopy[SYS_MAX_PATH_LEN] = '\0';
status = check_path(toPathCopy);
if (status < B_OK)
return status;
return common_write_link(pathCopy, toPathCopy, true);
}
int
sys_create_symlink(const char *userPath, const char *userToPath, int mode)
{
@ -3014,6 +3035,35 @@ user_read_link(const char *userPath, char *userBuffer, size_t bufferSize)
}
int
user_write_link(const char *userPath, const char *userToPath)
{
char path[SYS_MAX_PATH_LEN + 1];
char toPath[SYS_MAX_PATH_LEN + 1];
int status;
if (!CHECK_USER_ADDRESS(userPath)
|| !CHECK_USER_ADDRESS(userToPath))
return B_BAD_ADDRESS;
status = user_strncpy(path, userPath, SYS_MAX_PATH_LEN);
if (status < 0)
return status;
path[SYS_MAX_PATH_LEN] = '\0';
status = user_strncpy(toPath, userToPath, SYS_MAX_PATH_LEN);
if (status < 0)
return status;
toPath[SYS_MAX_PATH_LEN] = '\0';
status = check_path(toPath);
if (status < B_OK)
return status;
return common_write_link(path, toPath, false);
}
int
user_create_symlink(const char *userPath, const char *userToPath, int mode)
{

View File

@ -194,6 +194,7 @@ const char *const module_paths[] = {
new_hash_table *module_files = NULL;
new_hash_table *modules_list = NULL;
/* load_module_file
* Try to load the module file we've found into memory.
* This may fail if all the symbols can't be resolved.
@ -206,7 +207,9 @@ new_hash_table *modules_list = NULL;
* NULL on failure
* pointer to modules symbol on success
*/
static module_info **load_module_file(const char *path)
static module_info **
load_module_file(const char *path)
{
image_id file_image = elf_load_kspace(path, "");
loaded_module *lm;
@ -246,7 +249,9 @@ static module_info **load_module_file(const char *path)
return lm->info;
}
static inline void unload_module_file(const char *path)
static inline void
unload_module_file(const char *path)
{
loaded_module *themod;
dprintf("unload_mdoule_file: %s\n", path);
@ -271,6 +276,7 @@ dprintf("unload_mdoule_file: %s\n", path);
kfree(themod);
}
/* simple_module_info()
* Extract the information from the module_info structure pointed at
* by mod and create the entries required for access to it's details.
@ -279,7 +285,9 @@ dprintf("unload_mdoule_file: %s\n", path);
* -1 if error
* 0 if ok
*/
static int simple_module_info(module_info *mod, const char *file, int offset)
static int
simple_module_info(module_info *mod, const char *file, int offset)
{
module *m;
@ -326,6 +334,7 @@ static int simple_module_info(module_info *mod, const char *file, int offset)
return 0;
}
/* recurse_check_file
* Load the file filepath and check to see if we have a module within it
* that matches module_wanted.
@ -337,7 +346,9 @@ static int simple_module_info(module_info *mod, const char *file, int offset)
* 0 on no match
* 1 on match
*/
static int recurse_check_file(const char *filepath, const char *module_wanted)
static int
recurse_check_file(const char *filepath, const char *module_wanted)
{
module_info **hdr = NULL, **chk;
int i = 0, match = 0;
@ -369,6 +380,7 @@ static int recurse_check_file(const char *filepath, const char *module_wanted)
return match;
}
/* recurse_directory
* Enter the directory and try every entry, entering directories if
* we encounter them.
@ -381,7 +393,9 @@ static int recurse_check_file(const char *filepath, const char *module_wanted)
* 0 for no match
* 1 for match
*/
static int recurse_directory(const char *path, const char *match)
static int
recurse_directory(const char *path, const char *match)
{
/* ToDo: should just use opendir(), readdir(), ... */
struct stat stat;
@ -448,10 +462,13 @@ static int recurse_directory(const char *path, const char *match)
return res;
}
/* This is only called if we fail to find a module already in our cache...saves us
* some extra checking here :)
*/
static module *search_module(const char *name)
static module *
search_module(const char *name)
{
int i, res = 0;
SHOW_FLOW(3, "search_module(%s)\n", name);
@ -461,15 +478,15 @@ static module *search_module(const char *name)
break;
}
if (res != 1) {
if (res != 1)
return NULL;
}
return (module*)hash_get(modules_list, name, strlen(name));
}
static inline int init_module(module *module)
static inline int
init_module(module *module)
{
int res = 0;
@ -513,7 +530,9 @@ static inline int init_module(module *module)
return res;
}
static inline int uninit_module(module *module)
static inline int
uninit_module(module *module)
{
switch( module->state ) {
case MOD_QUERIED:
@ -556,7 +575,9 @@ static inline int uninit_module(module *module)
}
}
static int process_module_info(module_iterator *iter, char *buf, size_t *bufsize)
static int
process_module_info(module_iterator *iter, char *buf, size_t *bufsize)
{
module *m = NULL;
module_info **mod;
@ -588,7 +609,9 @@ static int process_module_info(module_iterator *iter, char *buf, size_t *bufsize
return res;
}
static inline int module_create_dir_iterator( module_iterator *iter, int file, const char *name )
static inline int
module_create_dir_iterator(module_iterator *iter, int file, const char *name)
{
module_dir_iterator *dir;
@ -598,13 +621,13 @@ static inline int module_create_dir_iterator( module_iterator *iter, int file, c
*/
iter->cur_header = NULL;
dir = (struct module_dir_iterator *)kmalloc( sizeof( *dir ));
dir = (struct module_dir_iterator *)kmalloc(sizeof(*dir));
if (dir == NULL )
return ENOMEM;
dir->name = (char *)kstrdup( name );
if (dir->name == NULL ) {
kfree( dir );
dir->name = (char *)kstrdup(name);
if (dir->name == NULL) {
kfree(dir);
return ENOMEM;
}
@ -612,7 +635,7 @@ static inline int module_create_dir_iterator( module_iterator *iter, int file, c
dir->sub_dir = NULL;
dir->parent_dir = iter->cur_dir;
if (iter->cur_dir )
if (iter->cur_dir)
iter->cur_dir->sub_dir = dir;
else
iter->base_dir = dir;
@ -623,13 +646,15 @@ static inline int module_create_dir_iterator( module_iterator *iter, int file, c
return B_NO_ERROR;
}
static inline int module_enter_dir(module_iterator *iter, const char *path)
static inline int
module_enter_dir(module_iterator *iter, const char *path)
{
int dir;
int res;
dir = sys_open_dir(path);
if (dir < 0 ) {
if (dir < 0) {
SHOW_FLOW(3, "couldn't open directory %s (%s)\n", path, strerror(dir));
// there are so many errors for "not found" that we don't bother
@ -648,7 +673,8 @@ static inline int module_enter_dir(module_iterator *iter, const char *path)
}
static inline void destroy_dir_iterator( module_iterator *iter )
static inline void
destroy_dir_iterator( module_iterator *iter )
{
module_dir_iterator *dir;
@ -666,7 +692,8 @@ static inline void destroy_dir_iterator( module_iterator *iter )
}
static inline void module_leave_dir( module_iterator *iter )
static inline void
module_leave_dir( module_iterator *iter )
{
module_dir_iterator *parent_dir;
@ -705,6 +732,7 @@ static void compose_path( char *path, module_iterator *iter, const char *name, b
path );
}
/* module_traverse_directory
* Logic as follows...
* If we have a headers pointer,
@ -714,11 +742,14 @@ static void compose_path( char *path, module_iterator *iter, const char *name, b
* This function tries to find the next module filename and then set the headers
* pointer in the cur_dir structure.
*/
static inline int module_traverse_dir(module_iterator *iter)
static inline int
module_traverse_dir(module_iterator *iter)
{
int res;
struct stat stat;
char name[SYS_MAX_NAME_LEN];
char buffer[SYS_MAX_NAME_LEN + sizeof(struct dirent)];
struct dirent *dirent = (struct dirent *)buffer;
char path[SYS_MAX_PATH_LEN];
/* If (*iter->cur_header) != NULL we have another module within
@ -732,25 +763,20 @@ static inline int module_traverse_dir(module_iterator *iter)
return B_NO_ERROR;
}
SHOW_FLOW( 3, "scanning %s\n", iter->cur_dir->name );
if ((res = sys_read(iter->cur_dir->file, name, 0, sizeof(name))) <= 0) {
SHOW_FLOW( 3, "scanning %s\n", iter->cur_dir->name);
if ((res = sys_read_dir(iter->cur_dir->file, dirent, sizeof(buffer), 1)) <= 0) {
SHOW_FLOW(3, "got error: %s\n", strerror(res));
module_leave_dir(iter);
return B_NO_ERROR;
}
SHOW_FLOW( 3, "got %s\n", name );
SHOW_FLOW(3, "got %s\n", dirent->d_name);
if (strcmp(name, ".") == 0 ||
strcmp(name, "..") == 0 )
if (strcmp(dirent->d_name, ".") == 0 ||
strcmp(dirent->d_name, "..") == 0 )
return B_NO_ERROR;
/* currently, sys_read returns an error if buffer is too small
* I don't know the official specification, so it's always safe
* to add a trailing end-of-string
*/
name[sizeof(name) - 1] = 0;
compose_path(path, iter, name, true);
compose_path(path, iter, dirent->d_name, true);
/* As we're doing a new file, reset the pointers that might get
* screwed up...
@ -774,15 +800,18 @@ static inline int module_traverse_dir(module_iterator *iter)
if (S_ISDIR(stat.st_mode))
return module_enter_dir(iter, path);
SHOW_FLOW( 3, "entry %s not a file nor a directory - ignored\n", name );
SHOW_FLOW(3, "entry %s not a file nor a directory - ignored\n", dirent->d_name);
return B_NO_ERROR;
}
/* module_enter_base_path
* Basically try each of the directories we have listed as module paths,
* trying each with the prefix we've been allocated.
*/
static inline int module_enter_base_path(module_iterator *iter)
static inline int
module_enter_base_path(module_iterator *iter)
{
char path[SYS_MAX_PATH_LEN];
@ -808,6 +837,7 @@ static inline int module_enter_base_path(module_iterator *iter)
return module_enter_dir(iter, path);
}
/* open_module_list
* This returns a pointer to a structure that can be used to
* iterate through a list of all modules available under
@ -817,7 +847,9 @@ static inline int module_enter_base_path(module_iterator *iter)
* The structure is then used by the read_next_module_name function
* and MUST be freed or memory will be leaked.
*/
void *open_module_list(const char *prefix)
void *
open_module_list(const char *prefix)
{
module_iterator *iter;
@ -841,19 +873,22 @@ void *open_module_list(const char *prefix)
return (void *)iter;
}
/* read_next_module_name
* Return the next module name from the available list, using
* a structure previously created by a call to open_module_list.
* Returns 0 if a module was available.
*/
int read_next_module_name(void *cookie, char *buf, size_t *bufsize )
int
read_next_module_name(void *cookie, char *buf, size_t *bufsize)
{
module_iterator *iter = (module_iterator *)cookie;
int res;
*buf = '\0';
if(!iter)
if (!iter)
return EINVAL;
res = iter->err;

View File

@ -73,10 +73,10 @@ int syscall_dispatcher(unsigned long call_num, void *arg_buffer, uint64 *call_re
*call_ret = user_fsync((int)arg0);
break;
case SYSCALL_READ:
*call_ret = user_read((int)arg0, (void *)arg1, (off_t)INT32TOINT64(arg2, arg3), (ssize_t)arg4);
*call_ret = user_read((int)arg0, (off_t)INT32TOINT64(arg1, arg2), (void *)arg3, (ssize_t)arg4);
break;
case SYSCALL_WRITE:
*call_ret = user_write((int)arg0, (const void *)arg1, (off_t)INT32TOINT64(arg2, arg3), (ssize_t)arg4);
*call_ret = user_write((int)arg0, (off_t)INT32TOINT64(arg1, arg2), (const void *)arg3, (ssize_t)arg4);
break;
case SYSCALL_SEEK:
*call_ret = user_seek((int)arg0, (off_t)INT32TOINT64(arg1, arg2), (int)arg3);

View File

@ -177,10 +177,10 @@ static int console_close(void * cookie)
return 0;
}
static ssize_t console_read(void * cookie, off_t pos, void *buf, size_t *len)
static ssize_t console_read(void *cookie, off_t pos, void *buf, size_t *len)
{
/* XXX - optimistic!! */
*len = sys_read(keyboard_fd, buf, 0, *len);
*len = sys_read(keyboard_fd, 0, buf, *len);
return 0;
}

View File

@ -267,7 +267,7 @@ static int console_close(void * cookie)
static ssize_t console_read(void * cookie, off_t pos, void *buf,
size_t *len)
{
return sys_read(console.keyboard_fd, buf, 0, *len);
return sys_read(console.keyboard_fd, 0, buf, *len);
}
static ssize_t _console_write(const void *buf, size_t *len)