Finally fixed all warnings (we probably won't really need bootfs later anymore

for the standard boot process).
Removed the STREAM_TYPE_* definitions, it's now using the stat definitions
instead.
Cleaned the source a bit.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5188 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2003-10-28 13:46:48 +00:00
parent 9699c52992
commit 7530b569ec
+51 -151
View File
@@ -22,7 +22,6 @@
#define BOOTFS_TRACE 0 #define BOOTFS_TRACE 0
#if BOOTFS_TRACE #if BOOTFS_TRACE
# define TRACE(x) dprintf x # define TRACE(x) dprintf x
#else #else
@@ -33,20 +32,15 @@ static char *bootdir = NULL;
static off_t bootdir_len = 0; static off_t bootdir_len = 0;
static region_id bootdir_region = -1; static region_id bootdir_region = -1;
typedef enum {
STREAM_TYPE_FILE = S_IFREG,
STREAM_TYPE_DIR = S_IFDIR,
} stream_type;
struct bootfs_stream { struct bootfs_stream {
stream_type type; int type;
union { union {
struct stream_dir { struct stream_dir {
struct bootfs_vnode *dir_head; struct bootfs_vnode *dir_head;
struct bootfs_cookie *jar_head; struct bootfs_cookie *jar_head;
} dir; } dir;
struct stream_file { struct stream_file {
void *start; uint8 *start;
off_t len; off_t len;
} file; } file;
} u; } u;
@@ -142,7 +136,7 @@ bootfs_delete_vnode(struct bootfs *fs, struct bootfs_vnode *v, bool force_delete
// cant delete it if it's in a directory or is a directory // cant delete it if it's in a directory or is a directory
// and has children // and has children
if (!force_delete if (!force_delete
&& ((v->stream.type == STREAM_TYPE_DIR && v->stream.u.dir.dir_head != NULL) && ((v->stream.type == S_IFDIR && v->stream.u.dir.dir_head != NULL)
|| v->dir_next != NULL)) || v->dir_next != NULL))
return EPERM; return EPERM;
@@ -156,7 +150,7 @@ bootfs_delete_vnode(struct bootfs *fs, struct bootfs_vnode *v, bool force_delete
return 0; return 0;
} }
#if 0
static void static void
insert_cookie_in_jar(struct bootfs_vnode *dir, struct bootfs_cookie *cookie) insert_cookie_in_jar(struct bootfs_vnode *dir, struct bootfs_cookie *cookie)
{ {
@@ -193,6 +187,7 @@ update_dircookies(struct bootfs_vnode *dir, struct bootfs_vnode *v)
} }
} }
} }
#endif
static struct bootfs_vnode * static struct bootfs_vnode *
@@ -200,7 +195,7 @@ bootfs_find_in_dir(struct bootfs_vnode *dir, const char *path)
{ {
struct bootfs_vnode *v; struct bootfs_vnode *v;
if(dir->stream.type != STREAM_TYPE_DIR) if (dir->stream.type != S_IFDIR)
return NULL; return NULL;
if (!strcmp(path, ".")) if (!strcmp(path, "."))
@@ -222,7 +217,7 @@ bootfs_find_in_dir(struct bootfs_vnode *dir, const char *path)
static status_t static status_t
bootfs_insert_in_dir(struct bootfs_vnode *dir, struct bootfs_vnode *v) bootfs_insert_in_dir(struct bootfs_vnode *dir, struct bootfs_vnode *v)
{ {
if(dir->stream.type != STREAM_TYPE_DIR) if (dir->stream.type != S_IFDIR)
return EINVAL; return EINVAL;
v->dir_next = dir->stream.u.dir.dir_head; v->dir_next = dir->stream.u.dir.dir_head;
@@ -232,7 +227,7 @@ bootfs_insert_in_dir(struct bootfs_vnode *dir, struct bootfs_vnode *v)
return 0; return 0;
} }
#if 0
static status_t static status_t
bootfs_remove_from_dir(struct bootfs_vnode *dir, struct bootfs_vnode *findit) bootfs_remove_from_dir(struct bootfs_vnode *dir, struct bootfs_vnode *findit)
{ {
@@ -256,15 +251,14 @@ bootfs_remove_from_dir(struct bootfs_vnode *dir, struct bootfs_vnode *findit)
} }
/* XXX seems to be unused
static bool static bool
bootfs_is_dir_empty(struct bootfs_vnode *dir) bootfs_is_dir_empty(struct bootfs_vnode *dir)
{ {
if(dir->stream.type != STREAM_TYPE_DIR) if(dir->stream.type != S_IFDIR)
return false; return false;
return !dir->stream.u.dir.dir_head; return !dir->stream.u.dir.dir_head;
} }
*/ #endif
/** Creates a path of vnodes up to the last part of the passed in path. /** Creates a path of vnodes up to the last part of the passed in path.
@@ -322,7 +316,7 @@ bootfs_create_path(struct bootfs *fs, char *path, struct bootfs_vnode *base, cha
if (!v) if (!v)
return NULL; return NULL;
v->stream.type = STREAM_TYPE_DIR; v->stream.type = S_IFDIR;
v->stream.u.dir.dir_head = NULL; v->stream.u.dir.dir_head = NULL;
v->stream.u.dir.jar_head = NULL; v->stream.u.dir.jar_head = NULL;
@@ -330,7 +324,7 @@ bootfs_create_path(struct bootfs *fs, char *path, struct bootfs_vnode *base, cha
hash_insert(fs->vnode_list_hash, v); hash_insert(fs->vnode_list_hash, v);
} else { } else {
// we found one // we found one
if(v->stream.type != STREAM_TYPE_DIR) if (v->stream.type != S_IFDIR)
return NULL; return NULL;
} }
base = v; base = v;
@@ -344,7 +338,6 @@ bootfs_create_vnode_tree(struct bootfs *fs, struct bootfs_vnode *root)
{ {
int i; int i;
boot_entry *entry; boot_entry *entry;
int err;
struct bootfs_vnode *new_vnode; struct bootfs_vnode *new_vnode;
struct bootfs_vnode *dir; struct bootfs_vnode *dir;
char path[SYS_MAX_PATH_LEN]; char path[SYS_MAX_PATH_LEN];
@@ -353,8 +346,7 @@ bootfs_create_vnode_tree(struct bootfs *fs, struct bootfs_vnode *root)
entry = (boot_entry *)bootdir; entry = (boot_entry *)bootdir;
for (i = 0; i < BOOTDIR_MAX_ENTRIES; i++) { for (i = 0; i < BOOTDIR_MAX_ENTRIES; i++) {
if (entry[i].be_type != BE_TYPE_NONE && entry[i].be_type != BE_TYPE_DIRECTORY) { if (entry[i].be_type != BE_TYPE_NONE && entry[i].be_type != BE_TYPE_DIRECTORY) {
strncpy(path, entry[i].be_name, SYS_MAX_PATH_LEN-1); strlcpy(path, entry[i].be_name, SYS_MAX_PATH_LEN);
path[SYS_MAX_PATH_LEN-1] = '\0';
dir = bootfs_create_path(fs, path, root, &leaf); dir = bootfs_create_path(fs, path, root, &leaf);
if (!dir) if (!dir)
@@ -365,8 +357,8 @@ bootfs_create_vnode_tree(struct bootfs *fs, struct bootfs_vnode *root)
return ENOMEM; return ENOMEM;
// set up the new node // set up the new node
new_vnode->stream.type = STREAM_TYPE_FILE; new_vnode->stream.type = S_IFREG;
new_vnode->stream.u.file.start = bootdir + entry[i].be_offset * PAGE_SIZE; new_vnode->stream.u.file.start = bootdir + entry[i].be_offset * B_PAGE_SIZE;
new_vnode->stream.u.file.len = entry[i].be_vsize; new_vnode->stream.u.file.len = entry[i].be_vsize;
dprintf("bootfs_create_vnode_tree: added entry '%s', start %p, len 0x%Lx\n", new_vnode->name, dprintf("bootfs_create_vnode_tree: added entry '%s', start %p, len 0x%Lx\n", new_vnode->name,
@@ -396,18 +388,15 @@ bootfs_mount(mount_id id, const char *device, void *args, fs_volume *_fs, vnode_
TRACE(("bootfs_mount: entry\n")); TRACE(("bootfs_mount: entry\n"));
fs = malloc(sizeof(struct bootfs)); fs = malloc(sizeof(struct bootfs));
if(fs == NULL) { if (fs == NULL)
err = ENOMEM; return B_NO_MEMORY;
goto err;
}
fs->id = id; fs->id = id;
fs->next_vnode_id = 0; fs->next_vnode_id = 0;
err = mutex_init(&fs->lock, "bootfs_mutex"); err = mutex_init(&fs->lock, "bootfs_mutex");
if(err < 0) { if (err < 0)
goto err1; goto err1;
}
fs->vnode_list_hash = hash_init(BOOTFS_HASH_SIZE, (addr)&v->all_next - (addr)v, fs->vnode_list_hash = hash_init(BOOTFS_HASH_SIZE, (addr)&v->all_next - (addr)v,
&bootfs_vnode_compare_func, &bootfs_vnode_hash_func); &bootfs_vnode_compare_func, &bootfs_vnode_hash_func);
@@ -427,16 +416,15 @@ bootfs_mount(mount_id id, const char *device, void *args, fs_volume *_fs, vnode_
v->parent = v; v->parent = v;
// create a dir stream for it to hold // create a dir stream for it to hold
v->stream.type = STREAM_TYPE_DIR; v->stream.type = S_IFDIR;
v->stream.u.dir.dir_head = NULL; v->stream.u.dir.dir_head = NULL;
fs->root_vnode = v; fs->root_vnode = v;
hash_insert(fs->vnode_list_hash, v); hash_insert(fs->vnode_list_hash, v);
err = bootfs_create_vnode_tree(fs, fs->root_vnode); err = bootfs_create_vnode_tree(fs, fs->root_vnode);
if(err < 0) { if (err < 0)
goto err4; goto err4;
}
*root_vnid = v->id; *root_vnid = v->id;
*_fs = fs; *_fs = fs;
@@ -451,7 +439,7 @@ err2:
mutex_destroy(&fs->lock); mutex_destroy(&fs->lock);
err1: err1:
free(fs); free(fs);
err:
return err; return err;
} }
@@ -499,7 +487,7 @@ bootfs_lookup(fs_volume _fs, fs_vnode _dir, const char *name, vnode_id *_id, int
TRACE(("bootfs_lookup: entry dir %p, name '%s'\n", dir, name)); TRACE(("bootfs_lookup: entry dir %p, name '%s'\n", dir, name));
if (dir->stream.type != STREAM_TYPE_DIR) if (dir->stream.type != S_IFDIR)
return B_NOT_A_DIRECTORY; return B_NOT_A_DIRECTORY;
mutex_lock(&fs->lock); mutex_lock(&fs->lock);
@@ -564,9 +552,7 @@ bootfs_get_vnode(fs_volume _fs, vnode_id id, fs_vnode *v, bool r)
static status_t static status_t
bootfs_put_vnode(fs_volume _fs, fs_vnode _v, bool r) bootfs_put_vnode(fs_volume _fs, fs_vnode _v, bool r)
{ {
struct bootfs_vnode *v = (struct bootfs_vnode *)_v; TRACE(("bootfs_put_vnode: entry on vnode 0x%Lx r %d\n", ((struct bootfs_vnode *)_v)->id, r));
TRACE(("bootfs_put_vnode: entry on vnode 0x%Lx r %d\n", v->id, r));
return 0; // whatever return 0; // whatever
} }
@@ -577,8 +563,6 @@ bootfs_remove_vnode(fs_volume _fs, fs_vnode _v, bool reenter)
{ {
struct bootfs *fs = (struct bootfs *)_fs; struct bootfs *fs = (struct bootfs *)_fs;
struct bootfs_vnode *v = (struct bootfs_vnode *)_v; struct bootfs_vnode *v = (struct bootfs_vnode *)_v;
struct bootfs_vnode dummy;
status_t err;
TRACE(("bootfs_remove_vnode: remove %p (0x%Lx) r %d\n", v, v->id, reenter)); TRACE(("bootfs_remove_vnode: remove %p (0x%Lx) r %d\n", v, v->id, reenter));
@@ -592,13 +576,10 @@ bootfs_remove_vnode(fs_volume _fs, fs_vnode _v, bool reenter)
bootfs_delete_vnode(fs, v, false); bootfs_delete_vnode(fs, v, false);
err = 0;
err:
if (!reenter) if (!reenter)
mutex_unlock(&fs->lock); mutex_unlock(&fs->lock);
return err; return B_OK;
} }
@@ -637,54 +618,45 @@ bootfs_open(fs_volume _fs, fs_vnode _v, int oflags, fs_cookie *_cookie)
static status_t static status_t
bootfs_close(fs_volume _fs, fs_vnode _v, fs_cookie _cookie) bootfs_close(fs_volume _fs, fs_vnode _v, fs_cookie _cookie)
{ {
struct bootfs *fs = _fs; TRACE(("bootfs_close: entry vnode %p, cookie %p\n", _v, _cookie));
struct bootfs_vnode *v = _v;
struct bootfs_cookie *cookie = _cookie;
TRACE(("bootfs_close: entry vnode %p, cookie %p\n", v, cookie)); return B_OK;
return 0;
} }
static status_t static status_t
bootfs_free_cookie(fs_volume _fs, fs_vnode _v, fs_cookie _cookie) bootfs_free_cookie(fs_volume _fs, fs_vnode _v, fs_cookie _cookie)
{ {
struct bootfs *fs = _fs;
struct bootfs_vnode *v = _v;
struct bootfs_cookie *cookie = _cookie; struct bootfs_cookie *cookie = _cookie;
TRACE(("bootfs_freecookie: entry vnode %p, cookie %p\n", v, cookie)); TRACE(("bootfs_freecookie: entry vnode %p, cookie %p\n", _v, cookie));
if (cookie)
free(cookie); free(cookie);
return B_OK;
return 0;
} }
static status_t static status_t
bootfs_fsync(fs_volume _fs, fs_vnode _v) bootfs_fsync(fs_volume _fs, fs_vnode _v)
{ {
return 0; return B_OK;
} }
static ssize_t static ssize_t
bootfs_read(fs_volume _fs, fs_vnode _v, fs_cookie _cookie, off_t pos, void *buf, size_t *len) bootfs_read(fs_volume _fs, fs_vnode _v, fs_cookie _cookie, off_t pos, void *buffer, size_t *_length)
{ {
struct bootfs *fs = _fs; struct bootfs *fs = _fs;
struct bootfs_vnode *v = _v;
struct bootfs_cookie *cookie = _cookie; struct bootfs_cookie *cookie = _cookie;
ssize_t err = 0; ssize_t err = 0;
TRACE(("bootfs_read: vnode %p, cookie %p, pos 0x%Lx, len 0x%lx\n", v, cookie, pos, *len)); TRACE(("bootfs_read: vnode %p, cookie %p, pos 0x%Lx, len 0x%lx\n", _v, cookie, pos, *_length));
mutex_lock(&fs->lock); mutex_lock(&fs->lock);
switch (cookie->s->type) { switch (cookie->s->type) {
case STREAM_TYPE_FILE: case S_IFREG:
if(*len <= 0) { if (*_length <= 0) {
err = 0; err = 0;
break; break;
} }
@@ -693,23 +665,24 @@ bootfs_read(fs_volume _fs, fs_vnode _v, fs_cookie _cookie, off_t pos, void *buf,
pos = cookie->u.file.pos; pos = cookie->u.file.pos;
} }
if (pos >= cookie->s->u.file.len) { if (pos >= cookie->s->u.file.len) {
*len = 0; *_length = 0;
err = ESPIPE; err = ESPIPE;
break; break;
} }
if(pos + *len > cookie->s->u.file.len) { if (pos + *_length > cookie->s->u.file.len) {
// trim the read // trim the read
*len = cookie->s->u.file.len - pos; *_length = cookie->s->u.file.len - pos;
} }
err = user_memcpy(buf, cookie->s->u.file.start + pos, *len); err = user_memcpy(buffer, cookie->s->u.file.start + pos, *_length);
if(err < 0) { if (err < 0)
goto err; goto err;
}
cookie->u.file.pos = pos + *len; cookie->u.file.pos = pos + *_length;
err = 0; err = 0;
break; break;
default: default:
*len = 0; *_length = 0;
err = EINVAL; err = EINVAL;
} }
err: err:
@@ -728,60 +701,6 @@ bootfs_write(fs_volume fs, fs_vnode v, fs_cookie cookie, off_t pos, const void *
} }
static off_t
bootfs_seek(fs_volume _fs, fs_vnode _v, fs_cookie _cookie, off_t pos, int seekType)
{
struct bootfs *fs = _fs;
struct bootfs_vnode *v = _v;
struct bootfs_cookie *cookie = _cookie;
status_t err = B_OK;
TRACE(("bootfs_seek: vnode %p, cookie %p, pos 0x%Lx , seek_type %d\n", v, cookie, pos, seekType));
if (cookie->s->type != STREAM_TYPE_FILE)
return EINVAL;
mutex_lock(&fs->lock);
switch (seekType) {
case SEEK_SET:
if (pos < 0)
pos = 0;
if (pos > cookie->s->u.file.len)
pos = cookie->s->u.file.len;
cookie->u.file.pos = pos;
break;
case SEEK_CUR:
if (pos + cookie->u.file.pos > cookie->s->u.file.len)
pos = cookie->s->u.file.len;
else if (pos + cookie->u.file.pos < 0)
pos = 0;
else
pos += cookie->u.file.pos;
break;
case SEEK_END:
if (pos > 0)
pos = cookie->s->u.file.len;
else if (pos + cookie->s->u.file.len < 0)
pos = 0;
else
pos += cookie->s->u.file.len;
break;
default:
err = EINVAL;
}
if (err == B_OK)
cookie->u.file.pos = pos;
mutex_unlock(&fs->lock);
if (err < B_OK)
return err;
return pos;
}
static status_t static status_t
bootfs_create_dir(fs_volume _fs, fs_vnode _dir, const char *name, int perms, vnode_id *new_vnid) bootfs_create_dir(fs_volume _fs, fs_vnode _dir, const char *name, int perms, vnode_id *new_vnid)
{ {
@@ -799,7 +718,7 @@ bootfs_open_dir(fs_volume _fs, fs_vnode _v, fs_cookie *_cookie)
TRACE(("bootfs_open_dir: vnode %p\n", vnode)); TRACE(("bootfs_open_dir: vnode %p\n", vnode));
if (vnode->stream.type != STREAM_TYPE_DIR) if (vnode->stream.type != S_IFDIR)
return EINVAL; return EINVAL;
cookie = malloc(sizeof(struct bootfs_cookie)); cookie = malloc(sizeof(struct bootfs_cookie));
@@ -887,7 +806,7 @@ bootfs_can_page(fs_volume _fs, fs_vnode _v)
TRACE(("bootfs_canpage: vnode %p\n", v)); TRACE(("bootfs_canpage: vnode %p\n", v));
if (v->stream.type == STREAM_TYPE_FILE) if (v->stream.type == S_IFREG)
return 1; return 1;
else else
return 0; return 0;
@@ -897,11 +816,10 @@ bootfs_can_page(fs_volume _fs, fs_vnode _v)
static ssize_t static ssize_t
bootfs_read_pages(fs_volume _fs, fs_vnode _v, iovecs *vecs, off_t pos) bootfs_read_pages(fs_volume _fs, fs_vnode _v, iovecs *vecs, off_t pos)
{ {
struct bootfs *fs = _fs;
struct bootfs_vnode *v = _v; struct bootfs_vnode *v = _v;
unsigned int i; unsigned int i;
TRACE(("bootfs_readpage: fs_cookie %p vnode %p, vecs %p, pos 0x%Ld\n",fs, v, vecs, pos)); TRACE(("bootfs_readpage: fs_cookie %p vnode %p, vecs %p, pos 0x%Ld\n", _fs, v, vecs, pos));
for (i = 0; i < vecs->num; i++) { for (i = 0; i < vecs->num; i++) {
if (pos >= v->stream.u.file.len) { if (pos >= v->stream.u.file.len) {
@@ -928,10 +846,7 @@ bootfs_read_pages(fs_volume _fs, fs_vnode _v, iovecs *vecs, off_t pos)
static ssize_t static ssize_t
bootfs_write_pages(fs_volume _fs, fs_vnode _v, iovecs *vecs, off_t pos) bootfs_write_pages(fs_volume _fs, fs_vnode _v, iovecs *vecs, off_t pos)
{ {
struct bootfs *fs = _fs; TRACE(("bootfs_writepage: fs_cookie %p vnode %p, vecs %p, pos %Ld \n", _fs, _v, vecs, pos));
struct bootfs_vnode *v = _v;
TRACE(("bootfs_writepage: fs_cookie %p vnode %p, vecs %p, pos %Ld \n", fs, v, vecs, pos));
return EPERM; return EPERM;
} }
@@ -966,24 +881,14 @@ bootfs_read_stat(fs_volume _fs, fs_vnode _v, struct stat *stat)
/** XXX - no pretense at access control, just tell people /** XXX - no pretense at access control, just tell people
* they can read it :) * they can read it :)
*/ */
stat->st_mode = (S_IRUSR | S_IRGRP | S_IROTH);
stat->st_size = 0;
stat->st_ino = v->id; stat->st_ino = v->id;
stat->st_mode = v->stream.type | S_IRUSR | S_IRGRP | S_IROTH;
switch(v->stream.type) { if (v->stream.type == S_IFREG)
case STREAM_TYPE_DIR:
stat->st_mode |= S_IFDIR;
break;
case STREAM_TYPE_FILE:
stat->st_size = v->stream.u.file.len; stat->st_size = v->stream.u.file.len;
stat->st_mode |= S_IFREG; else
break; stat->st_size = 0;
default:
err = EINVAL;
break;
}
err:
mutex_unlock(&fs->lock); mutex_unlock(&fs->lock);
return err; return err;
@@ -991,13 +896,8 @@ err:
static status_t static status_t
bootfs_write_stat(fs_volume _fs, fs_vnode _v, const struct stat *stat, int stat_mask) bootfs_write_stat(fs_volume _fs, fs_vnode _v, const struct stat *stat, int statMask)
{ {
struct bootfs *fs = _fs;
struct bootfs_vnode *v = _v;
TRACE(("bootfs_wstat: fs_cookie %p, vnode %p, v->id 0x%Lx, stat 0x%p, stat_mask 0x%x\n", fs, v, v->id, stat, stat_mask));
// cannot change anything // cannot change anything
return EROFS; return EROFS;
} }