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:
@@ -302,7 +302,9 @@ devfs_get_partition_info( struct devfs *fs, struct devfs_vnode *v,
|
|||||||
return B_NO_ERROR;
|
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_cookie *cookie, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
struct devfs_part_map *part_map;
|
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:
|
err:
|
||||||
mutex_unlock(&fs->lock);
|
mutex_unlock(&fs->lock);
|
||||||
|
|
||||||
INSANE(("--devfs_lookup: returns %d\n",err));
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,19 +632,11 @@ devfs_open(fs_cookie _fs, fs_vnode _v, file_cookie *_cookie, int oflags)
|
|||||||
if (cookie == NULL)
|
if (cookie == NULL)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
INSANE(("zulu: calls = %p\n",vnode->stream.u.dev.calls));
|
if (vnode->stream.type != STREAM_TYPE_DEVICE)
|
||||||
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"));
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
INSANE(("got here.\n"));
|
|
||||||
|
|
||||||
status = vnode->stream.u.dev.calls->open(vnode->name, oflags, &cookie->u.dev.dcookie);
|
status = vnode->stream.u.dev.calls->open(vnode->name, oflags, &cookie->u.dev.dcookie);
|
||||||
*_cookie = cookie;
|
*_cookie = cookie;
|
||||||
INSANE(("cool!\n"));
|
|
||||||
|
|
||||||
return status;
|
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_vnode *vnode = _v;
|
||||||
struct devfs_cookie *cookie = _cookie;
|
struct devfs_cookie *cookie = _cookie;
|
||||||
struct devfs_part_map *part_map;
|
struct devfs_part_map *part_map;
|
||||||
int status;
|
|
||||||
|
|
||||||
TRACE(("devfs_read: vnode %p, cookie %p, pos %Ld, len %p\n", vnode, cookie, pos, length));
|
TRACE(("devfs_read: vnode %p, cookie %p, pos %Ld, len %p\n", vnode, cookie, pos, length));
|
||||||
|
|
||||||
INSANE(("juchu, buffer = %p!\n",buffer));
|
// 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)
|
//if (cookie->stream->type != STREAM_TYPE_DEVICE)
|
||||||
// return EINVAL;
|
// 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;
|
part_map = vnode->stream.u.dev.part_map;
|
||||||
if (part_map) {
|
if (part_map) {
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
@@ -723,11 +715,7 @@ INSANE(("name = %s\n",vnode->name));
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pass the call through to the device
|
// pass the call through to the device
|
||||||
INSANE(("calls = %p\n",vnode->stream.u.dev.calls));
|
return vnode->stream.u.dev.calls->read(cookie->u.dev.dcookie, pos, buffer, length);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -739,7 +727,6 @@ devfs_write(fs_cookie _fs, fs_vnode _v, file_cookie _cookie, const void *buf,
|
|||||||
struct devfs_cookie *cookie = _cookie;
|
struct devfs_cookie *cookie = _cookie;
|
||||||
|
|
||||||
TRACE(("devfs_write: vnode %p, cookie %p, pos %Ld, len %p\n", vnode, cookie, pos, len));
|
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) {
|
if (vnode->stream.type == STREAM_TYPE_DEVICE) {
|
||||||
struct devfs_part_map *part_map = vnode->stream.u.dev.part_map;
|
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;
|
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);
|
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 written;
|
||||||
}
|
}
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@@ -1026,7 +1010,6 @@ devfs_read_stat(fs_cookie _fs, fs_vnode _v, struct stat *stat)
|
|||||||
struct devfs_vnode *vnode = _v;
|
struct devfs_vnode *vnode = _v;
|
||||||
|
|
||||||
TRACE(("devfs_rstat: vnode %p (%Ld), stat %p\n", vnode, vnode->id, stat));
|
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_ino = vnode->id;
|
||||||
stat->st_mode = DEFFILEMODE;
|
stat->st_mode = DEFFILEMODE;
|
||||||
|
|||||||
+33
-16
@@ -757,17 +757,30 @@ dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize)
|
|||||||
if (vnode == NULL || buffer == NULL)
|
if (vnode == NULL || buffer == NULL)
|
||||||
return EINVAL;
|
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);
|
inc_vnode_ref_count(vnode);
|
||||||
|
|
||||||
path[--insert] = '\0';
|
path[--insert] = '\0';
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
char name[B_FILE_NAME_LENGTH];
|
// the name buffer is also used for fs_read_dir()
|
||||||
vnode_id parentId;
|
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
|
// lookup the parent vnode
|
||||||
status = FS_CALL(vnode,fs_lookup)(vnode->mount->cookie,vnode->priv_vnode,"..",&parentId);
|
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
|
// release the current vnode, we only need its parent from now on
|
||||||
put_vnode(vnode);
|
put_vnode(vnode);
|
||||||
|
|
||||||
@@ -789,30 +802,32 @@ dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize)
|
|||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
// okay, we got the parent node, so we can now paste its name
|
if (!FS_CALL(vnode,fs_get_vnode_name)) {
|
||||||
// in front of our working path - but we don't know the name yet...
|
// If we don't got the vnode's name yet, we have to search for it
|
||||||
|
// in the parent directory now
|
||||||
// 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 {
|
|
||||||
file_cookie cookie;
|
file_cookie cookie;
|
||||||
|
|
||||||
status = FS_CALL(vnode,fs_open_dir)(vnode->mount->cookie,vnode->priv_vnode,&cookie);
|
status = FS_CALL(vnode,fs_open_dir)(vnode->mount->cookie,vnode->priv_vnode,&cookie);
|
||||||
if (status >= B_OK) {
|
if (status >= B_OK) {
|
||||||
// ToDo: implement fall-back - iterate through the directory
|
struct dirent *dirent = (struct dirent *)nameBuffer;
|
||||||
// and find the correct entry...
|
while (true) {
|
||||||
// Does need some more stack space...
|
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);
|
FS_CALL(vnode,fs_close_dir)(vnode->mount->cookie,vnode->priv_vnode,cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = B_ERROR;
|
|
||||||
}
|
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
put_vnode(vnode);
|
put_vnode(vnode);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add the name infront of the current path
|
// add the name infront of the current path
|
||||||
name[B_FILE_NAME_LENGTH - 1] = '\0';
|
name[B_FILE_NAME_LENGTH - 1] = '\0';
|
||||||
@@ -823,7 +838,7 @@ dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize)
|
|||||||
return ENOBUFS;
|
return ENOBUFS;
|
||||||
}
|
}
|
||||||
memcpy(path + insert, name, length);
|
memcpy(path + insert, name, length);
|
||||||
path[--insert] == '/';
|
path[--insert] = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the mountpoint
|
// add the mountpoint
|
||||||
@@ -832,6 +847,7 @@ dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize)
|
|||||||
return ENOBUFS;
|
return ENOBUFS;
|
||||||
|
|
||||||
memcpy(buffer, vnode->mount->mount_point, length);
|
memcpy(buffer, vnode->mount->mount_point, length);
|
||||||
|
if (insert != sizeof(path))
|
||||||
memcpy(buffer + length, path + insert, sizeof(path) - insert);
|
memcpy(buffer + length, path + insert, sizeof(path) - insert);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -1464,6 +1480,7 @@ vfs_unlink(char *path, bool kernel)
|
|||||||
|
|
||||||
err = v->mount->fs->calls->fs_unlink(v->mount->cookie, v->priv_vnode, filename);
|
err = v->mount->fs->calls->fs_unlink(v->mount->cookie, v->priv_vnode, filename);
|
||||||
dec_vnode_ref_count(v, true, false);
|
dec_vnode_ref_count(v, true, false);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user