We now have a completely working "pwd" command; dir_vnode_to_path() is
fully implemented. I removed all those insane INSANE() debug output and found what made the difference between a working and a crashing kernel - will have to investigate this later, because those two lines a) really belong there, and b) even if they are there, the kernel shouldn't crash just because of that. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@330 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f913779a80
commit
8480ee0c2c
@ -184,11 +184,11 @@ insert_cookie_in_jar(struct devfs_vnode *dir, struct devfs_cookie *cookie)
|
||||
static void
|
||||
remove_cookie_from_jar(struct devfs_vnode *dir, struct devfs_cookie *cookie)
|
||||
{
|
||||
if(cookie->u.dir.next)
|
||||
if (cookie->u.dir.next)
|
||||
cookie->u.dir.next->u.dir.prev = cookie->u.dir.prev;
|
||||
if(cookie->u.dir.prev)
|
||||
if (cookie->u.dir.prev)
|
||||
cookie->u.dir.prev->u.dir.next = cookie->u.dir.next;
|
||||
if(dir->stream.u.dir.jar_head == cookie)
|
||||
if (dir->stream.u.dir.jar_head == cookie)
|
||||
dir->stream.u.dir.jar_head = cookie->u.dir.next;
|
||||
|
||||
cookie->u.dir.prev = cookie->u.dir.next = NULL;
|
||||
@ -281,7 +281,7 @@ devfs_is_dir_empty(struct devfs_vnode *dir)
|
||||
|
||||
static int
|
||||
devfs_get_partition_info( struct devfs *fs, struct devfs_vnode *v,
|
||||
struct devfs_cookie *cookie, void *buf, size_t len)
|
||||
struct devfs_cookie *cookie, void *buf, size_t len)
|
||||
{
|
||||
devfs_partition_info *info = (devfs_partition_info *)buf;
|
||||
struct devfs_part_map *part_map = v->stream.u.dev.part_map;
|
||||
@ -297,12 +297,14 @@ devfs_get_partition_info( struct devfs *fs, struct devfs_vnode *v,
|
||||
|
||||
// XXX: todo - create raw device name out of raw_vnode
|
||||
// we need vfs support for that (see vfs_get_cwd)
|
||||
strcpy( info->raw_device, "something_raw" );
|
||||
strcpy(info->raw_device, "something_raw");
|
||||
|
||||
return B_NO_ERROR;
|
||||
}
|
||||
|
||||
static int devfs_set_partition( struct devfs *fs, struct devfs_vnode *v,
|
||||
|
||||
static int
|
||||
devfs_set_partition( struct devfs *fs, struct devfs_vnode *v,
|
||||
struct devfs_cookie *cookie, void *buf, size_t len)
|
||||
{
|
||||
struct devfs_part_map *part_map;
|
||||
@ -531,7 +533,6 @@ devfs_lookup(fs_cookie _fs, fs_vnode _dir, const char *name, vnode_id *id)
|
||||
err:
|
||||
mutex_unlock(&fs->lock);
|
||||
|
||||
INSANE(("--devfs_lookup: returns %d\n",err));
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -631,19 +632,11 @@ devfs_open(fs_cookie _fs, fs_vnode _v, file_cookie *_cookie, int oflags)
|
||||
if (cookie == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
INSANE(("zulu: calls = %p\n",vnode->stream.u.dev.calls));
|
||||
if (vnode->stream.u.dev.calls)
|
||||
INSANE(("hellacious: open = %p!\n",vnode->stream.u.dev.calls->open));
|
||||
|
||||
if (vnode->stream.type != STREAM_TYPE_DEVICE) {
|
||||
INSANE(("bye bye!\n"));
|
||||
if (vnode->stream.type != STREAM_TYPE_DEVICE)
|
||||
return EINVAL;
|
||||
}
|
||||
INSANE(("got here.\n"));
|
||||
|
||||
status = vnode->stream.u.dev.calls->open(vnode->name, oflags, &cookie->u.dev.dcookie);
|
||||
*_cookie = cookie;
|
||||
INSANE(("cool!\n"));
|
||||
|
||||
return status;
|
||||
}
|
||||
@ -700,16 +693,15 @@ devfs_read(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, void *buffer, off_t
|
||||
struct devfs_vnode *vnode = _v;
|
||||
struct devfs_cookie *cookie = _cookie;
|
||||
struct devfs_part_map *part_map;
|
||||
int status;
|
||||
|
||||
TRACE(("devfs_read: vnode %p, cookie %p, pos %Ld, len %p\n", vnode, cookie, pos, length));
|
||||
|
||||
INSANE(("juchu, buffer = %p!\n",buffer));
|
||||
// if (cookie->stream->type != STREAM_TYPE_DEVICE)
|
||||
// return EINVAL;
|
||||
// Whoa! If the next to lines are uncommented, our kernel crashes at some point
|
||||
// I haven't yet found the time to investigate, but I'll doubtlessly have to do
|
||||
// that at some point -- axeld.
|
||||
//if (cookie->stream->type != STREAM_TYPE_DEVICE)
|
||||
// return EINVAL;
|
||||
|
||||
INSANE((":%p:%p:%p:%p\n",vnode->all_next,vnode->name,vnode->redir_vnode,vnode->parent));
|
||||
INSANE(("name = %s\n",vnode->name));
|
||||
part_map = vnode->stream.u.dev.part_map;
|
||||
if (part_map) {
|
||||
if (pos < 0)
|
||||
@ -723,11 +715,7 @@ INSANE(("name = %s\n",vnode->name));
|
||||
}
|
||||
|
||||
// pass the call through to the device
|
||||
INSANE(("calls = %p\n",vnode->stream.u.dev.calls));
|
||||
status = vnode->stream.u.dev.calls->read(cookie->u.dev.dcookie, pos, buffer, length);
|
||||
INSANE(("hulu: calls = %p\n",vnode->stream.u.dev.calls));
|
||||
INSANE((":%p:%p:%p:%p\n",vnode->all_next,vnode->name,vnode->redir_vnode,vnode->parent));
|
||||
return status;
|
||||
return vnode->stream.u.dev.calls->read(cookie->u.dev.dcookie, pos, buffer, length);
|
||||
}
|
||||
|
||||
|
||||
@ -739,7 +727,6 @@ devfs_write(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, const void *buf,
|
||||
struct devfs_cookie *cookie = _cookie;
|
||||
|
||||
TRACE(("devfs_write: vnode %p, cookie %p, pos %Ld, len %p\n", vnode, cookie, pos, len));
|
||||
INSANE((":%p:%p:%p:%p\n",vnode->all_next,vnode->name,vnode->redir_vnode,vnode->parent));
|
||||
|
||||
if (vnode->stream.type == STREAM_TYPE_DEVICE) {
|
||||
struct devfs_part_map *part_map = vnode->stream.u.dev.part_map;
|
||||
@ -756,10 +743,7 @@ devfs_write(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, const void *buf,
|
||||
pos += part_map->offset;
|
||||
}
|
||||
|
||||
INSANE(("hela: name = \"%s\", calls = %p\n",vnode->name,vnode->stream.u.dev.calls));
|
||||
written = vnode->stream.u.dev.calls->write(cookie->u.dev.dcookie, pos, buf, len);
|
||||
INSANE(("helu: calls = %p\n",vnode->stream.u.dev.calls));
|
||||
INSANE((":%p:%p:%p:%p\n",vnode->all_next,vnode->name,vnode->redir_vnode,vnode->parent));
|
||||
return written;
|
||||
}
|
||||
return EINVAL;
|
||||
@ -1026,7 +1010,6 @@ devfs_read_stat(fs_cookie _fs, fs_vnode _v, struct stat *stat)
|
||||
struct devfs_vnode *vnode = _v;
|
||||
|
||||
TRACE(("devfs_rstat: vnode %p (%Ld), stat %p\n", vnode, vnode->id, stat));
|
||||
INSANE(("-> calls = %p\n",vnode->stream.u.dev.calls));
|
||||
|
||||
stat->st_ino = vnode->id;
|
||||
stat->st_mode = DEFFILEMODE;
|
||||
|
@ -757,17 +757,30 @@ dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize)
|
||||
if (vnode == NULL || buffer == NULL)
|
||||
return EINVAL;
|
||||
|
||||
// we don't use get_vnode() here because this call is more
|
||||
// efficient and does all we need from get_vnode()
|
||||
inc_vnode_ref_count(vnode);
|
||||
|
||||
path[--insert] = '\0';
|
||||
|
||||
while (true) {
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
vnode_id parentId;
|
||||
// the name buffer is also used for fs_read_dir()
|
||||
char nameBuffer[sizeof(struct dirent) + B_FILE_NAME_LENGTH];
|
||||
char *name = &((struct dirent *)nameBuffer)->d_name[0];
|
||||
vnode_id parentId, id;
|
||||
|
||||
// lookup the parent vnode
|
||||
status = FS_CALL(vnode,fs_lookup)(vnode->mount->cookie,vnode->priv_vnode,"..",&parentId);
|
||||
|
||||
// Does the file system support getting the name of a vnode?
|
||||
// If so, get it here...
|
||||
if (status == B_OK && FS_CALL(vnode,fs_get_vnode_name))
|
||||
status = FS_CALL(vnode,fs_get_vnode_name)(vnode->mount->cookie,vnode->priv_vnode,name,B_FILE_NAME_LENGTH);
|
||||
|
||||
// ... if not, find it out later (by iterating through
|
||||
// the parent directory, searching for the id)
|
||||
id = vnode->vnid;
|
||||
|
||||
// release the current vnode, we only need its parent from now on
|
||||
put_vnode(vnode);
|
||||
|
||||
@ -789,29 +802,31 @@ dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize)
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
// okay, we got the parent node, so we can now paste its name
|
||||
// in front of our working path - but we don't know the name yet...
|
||||
|
||||
// does the file system support getting the name of a vnode?
|
||||
if (FS_CALL(vnode,fs_get_vnode_name))
|
||||
status = FS_CALL(vnode,fs_get_vnode_name)(vnode->mount->cookie,vnode->priv_vnode,name,sizeof(name));
|
||||
else {
|
||||
if (!FS_CALL(vnode,fs_get_vnode_name)) {
|
||||
// If we don't got the vnode's name yet, we have to search for it
|
||||
// in the parent directory now
|
||||
file_cookie cookie;
|
||||
|
||||
status = FS_CALL(vnode,fs_open_dir)(vnode->mount->cookie,vnode->priv_vnode,&cookie);
|
||||
if (status >= B_OK) {
|
||||
// ToDo: implement fall-back - iterate through the directory
|
||||
// and find the correct entry...
|
||||
// Does need some more stack space...
|
||||
/* ... */
|
||||
struct dirent *dirent = (struct dirent *)nameBuffer;
|
||||
while (true) {
|
||||
uint32 num = 1;
|
||||
status = FS_CALL(vnode,fs_read_dir)(vnode->mount->cookie,vnode->priv_vnode,cookie,dirent,sizeof(nameBuffer),&num);
|
||||
if (status < B_OK)
|
||||
break;
|
||||
|
||||
if (id == dirent->d_ino)
|
||||
// found correct entry!
|
||||
break;
|
||||
}
|
||||
FS_CALL(vnode,fs_close_dir)(vnode->mount->cookie,vnode->priv_vnode,cookie);
|
||||
}
|
||||
|
||||
status = B_ERROR;
|
||||
}
|
||||
if (status < B_OK) {
|
||||
put_vnode(vnode);
|
||||
return status;
|
||||
if (status < B_OK) {
|
||||
put_vnode(vnode);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
// add the name infront of the current path
|
||||
@ -823,7 +838,7 @@ dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize)
|
||||
return ENOBUFS;
|
||||
}
|
||||
memcpy(path + insert, name, length);
|
||||
path[--insert] == '/';
|
||||
path[--insert] = '/';
|
||||
}
|
||||
|
||||
// add the mountpoint
|
||||
@ -832,7 +847,8 @@ dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize)
|
||||
return ENOBUFS;
|
||||
|
||||
memcpy(buffer, vnode->mount->mount_point, length);
|
||||
memcpy(buffer + length, path + insert, sizeof(path) - insert);
|
||||
if (insert != sizeof(path))
|
||||
memcpy(buffer + length, path + insert, sizeof(path) - insert);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@ -1459,11 +1475,12 @@ vfs_unlink(char *path, bool kernel)
|
||||
FUNCTION(("vfs_unlink: path '%s', kernel %d\n", path, kernel));
|
||||
|
||||
err = path_to_dir_vnode(path, &v, filename, kernel);
|
||||
if(err < 0)
|
||||
if (err < 0)
|
||||
goto err;
|
||||
|
||||
err = v->mount->fs->calls->fs_unlink(v->mount->cookie, v->priv_vnode, filename);
|
||||
dec_vnode_ref_count(v, true, false);
|
||||
|
||||
err:
|
||||
return err;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user