From 981aa8f4725a7e0177583370d826e1ded0247918 Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Thu, 10 Jul 2003 19:47:31 +0000 Subject: [PATCH] Initial implementations of: - udf_get_vnode() - udf_release_vnode() - udf_walk - udf_open_dir() - udf_read_dir() git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3942 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/udf/vfs_interface.cpp | 219 ++++++++++++------ 1 file changed, 150 insertions(+), 69 deletions(-) diff --git a/src/add-ons/kernel/file_systems/udf/vfs_interface.cpp b/src/add-ons/kernel/file_systems/udf/vfs_interface.cpp index f945bafe9a..218612a4ea 100644 --- a/src/add-ons/kernel/file_systems/udf/vfs_interface.cpp +++ b/src/add-ons/kernel/file_systems/udf/vfs_interface.cpp @@ -35,7 +35,9 @@ extern "C" { # define dprintf printf #endif +#include "DirectoryIterator.h" #include "Icb.h" +#include "Utils.h" #include "Volume.h" extern "C" { @@ -287,7 +289,7 @@ int udf_read_fs_stat(void *ns, struct fs_info *info) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -296,7 +298,7 @@ udf_write_fs_stat(void *ns, struct fs_info *info, long mask) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); // FUNCTION_START(("mask = %ld\n",mask)); - return B_ERROR; + RETURN(B_ERROR); } @@ -305,7 +307,7 @@ udf_initialize(const char *deviceName, void *parms, size_t parmsLength) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); // FUNCTION_START(("deviceName = %s, parameter len = %ld\n", deviceName, parmsLength)); - return B_ERROR; + RETURN(B_ERROR); } @@ -320,14 +322,28 @@ udf_sync(void *ns) int udf_read_vnode(void *ns, vnode_id id, char reenter, void **node) { - DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - // FUNCTION_START(("vnode_id = %lld\n", id)); - - if (id == 1) { - *node = (void*)0; - return B_OK; - } else - return B_ERROR; + DEBUG_INIT_ETC(CF_ENTRY | CF_VOLUME_OPS, NULL, ("id = %lld, reenter = %s", id, (reenter ? "true" : "false"))); + + if (!ns) + RETURN(B_BAD_VALUE); + + Udf::Volume *volume = reinterpret_cast(ns); + + // Convert the given vnode id to an address, and create + // and return a corresponding Icb object for it. + Udf::Icb *icb = new Udf::Icb(volume, Udf::to_long_address(id, volume->BlockSize())); + status_t err = icb ? B_NO_MEMORY : B_OK; + if (!err) { + err = icb->InitCheck(); + if (!err) { + if (node) + *node = reinterpret_cast(icb); + } else { + delete icb; + } + } + + RETURN(err); } @@ -346,7 +362,7 @@ int udf_remove_vnode(void *ns, void *node, char reenter) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -354,7 +370,7 @@ int udf_wake_vnode(void *ns, void *node) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -362,16 +378,32 @@ int udf_suspend_vnode(void *ns, void *node) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } int -udf_walk(void *ns, void *dir, const char *filename, char **resolvedPath, vnode_id *vnodeID) +udf_walk(void *ns, void *_dir, const char *filename, char **resolvedPath, vnode_id *vnodeId) { - DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - // FUNCTION_START(("dir = %p, filename = `%s'\n", dir, filename)); - return B_ERROR; + DEBUG_INIT_ETC(CF_ENTRY | CF_VOLUME_OPS, NULL, ("dir = %p, filename = `%s'", _dir, filename)); + + if (!ns || !_dir || !filename || !vnodeId) + RETURN(B_BAD_VALUE); + + Udf::Volume *volume = reinterpret_cast(ns); + Udf::Icb *dir = reinterpret_cast(_dir); + Udf::Icb *node = NULL; + + status_t err = B_OK; + + if (strcmp(filename, ".") == 0) { + *vnodeId = dir->Id(); + err = get_vnode(volume->Id(), *vnodeId, reinterpret_cast(&node)) == B_OK ? B_OK : B_BAD_VALUE; + } else { + err = B_ERROR; + } + + RETURN(err); } @@ -380,7 +412,7 @@ udf_ioctl(void *ns, void *node, void *cookie, int cmd, void *buffer, size_t buff { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); // FUNCTION_START(("node = %p, cmd = %d, buf = %p, len = %ld\n", node, cmd, buffer, bufferLength)); - return B_ERROR; + RETURN(B_ERROR); } @@ -389,7 +421,7 @@ udf_setflags(void *ns, void *node, void *cookie, int flags) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); // FUNCTION_START(("node = %p, flags = %d", node, flags)); - return B_ERROR; + RETURN(B_ERROR); } @@ -398,7 +430,7 @@ udf_select(void *ns, void *node, void *cookie, uint8 event, uint32 ref, selectsy { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); // FUNCTION_START(("event = %d, ref = %lu, sync = %p\n", event, ref, sync)); - return B_ERROR; + RETURN(B_ERROR); } @@ -406,7 +438,7 @@ int udf_deselect(void *ns, void *node, void *cookie, uint8 event, selectsync *sync) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -414,7 +446,7 @@ int udf_fsync(void *_ns, void *_node) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -422,7 +454,7 @@ int udf_read_stat(void *ns, void *node, struct stat *st) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -430,7 +462,7 @@ int udf_write_stat(void *ns, void *node, struct stat *stat, long mask) { DEBUG_INIT(CF_ENTRY | CF_VOLUME_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -445,7 +477,7 @@ udf_create(void *ns, void *dir, const char *name, int omode, int mode, { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); // FUNCTION_START(("name = \"%s\", perms = %d, omode = %d\n", name, mode, omode)); - return B_ERROR; + RETURN(B_ERROR); } @@ -453,7 +485,7 @@ int udf_symlink(void *ns, void *dir, const char *name, const char *path) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -462,7 +494,7 @@ udf_link(void *ns, void *dir, const char *name, void *node) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); // FUNCTION_START(("name = \"%s\"\n", name)); - return B_ERROR; + RETURN(B_ERROR); } @@ -471,7 +503,7 @@ udf_unlink(void *ns, void *dir, const char *name) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); // FUNCTION_START(("name = \"%s\"\n",name)); - return B_ERROR; + RETURN(B_ERROR); } @@ -480,21 +512,21 @@ udf_rename(void *ns, void *oldDir, const char *oldName, void *newDir, const char { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); // FUNCTION_START(("oldDir = %p, oldName = \"%s\", newDir = %p, newName = \"%s\"\n", oldDir, oldName, newDir, newName)); - return B_ERROR; + RETURN(B_ERROR); } int udf_open(void *_ns, void *_node, int omode, void **_cookie) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } int udf_read(void *_ns, void *_node, void *_cookie, off_t pos, void *buffer, size_t *_length) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -502,7 +534,7 @@ int udf_write(void *_ns, void *_node, void *_cookie, off_t pos, const void *buffer, size_t *_length) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -510,7 +542,7 @@ int udf_close(void *_ns, void *_node, void *_cookie) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -518,7 +550,7 @@ int udf_free_cookie(void *_ns, void *_node, void *_cookie) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -526,7 +558,7 @@ int udf_access(void *_ns, void *_node, int accessMode) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -534,7 +566,7 @@ int udf_read_link(void *_ns, void *_node, char *buffer, size_t *bufferSize) { DEBUG_INIT(CF_ENTRY | CF_FILE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -548,7 +580,7 @@ udf_mkdir(void *ns, void *dir, const char *name, int mode) { DEBUG_INIT(CF_ENTRY | CF_DIRECTORY_OPS, NULL); // FUNCTION_START(("name = \"%s\", perms = %d\n", name, mode)); - return B_ERROR; + RETURN(B_ERROR); } @@ -557,15 +589,36 @@ udf_rmdir(void *ns, void *dir, const char *name) { DEBUG_INIT(CF_ENTRY | CF_DIRECTORY_OPS, NULL); // FUNCTION_START(("name = \"%s\"\n", name)); - return B_ERROR; + RETURN(B_ERROR); } int udf_open_dir(void *ns, void *node, void **cookie) { - DEBUG_INIT(CF_ENTRY | CF_DIRECTORY_OPS, NULL); - return B_ERROR; + DEBUG_INIT_ETC(CF_ENTRY | CF_DIRECTORY_OPS, NULL, ("node = %p, cookie = %p", node, cookie)); + + if (!ns || !node || !cookie) + RETURN(B_BAD_VALUE); + + Udf::Icb *dir = reinterpret_cast(node); + + status_t err = B_OK; + + if (dir->IsDirectory()) { + Udf::DirectoryIterator *iterator = NULL; + err = dir->GetDirectoryIterator(&iterator); + if (!err) { + *cookie = reinterpret_cast(iterator); + } else { + PRINT(("Error getting directory iterator: 0x%lx, `%s'\n", err, strerror(err))); + } + } else { + PRINT(("Given icb is not a directory (type = %d)\n", dir->Type())); + err = B_BAD_VALUE; + } + + RETURN(err); } @@ -573,8 +626,36 @@ int udf_read_dir(void *ns, void *node, void *cookie, long *num, struct dirent *dirent, size_t bufferSize) { - DEBUG_INIT(CF_ENTRY | CF_DIRECTORY_OPS, NULL); - return B_ERROR; + DEBUG_INIT_ETC(CF_ENTRY | CF_DIRECTORY_OPS, NULL, + ("node = %p, cookie = %p, bufferSize = %ld", node, cookie, bufferSize)); + + if (!ns || !node || !cookie || !num) + RETURN(B_BAD_VALUE); + + Udf::Volume *volume = reinterpret_cast(ns); + Udf::Icb *icb = reinterpret_cast(node); + Udf::DirectoryIterator *dir = reinterpret_cast(cookie); + + if (icb != dir->Parent()) { + PRINT(("Icb does not match parent Icb of given DirectoryIterator! (dir->Parent = %p)\n", + dir->Parent())); + return B_BAD_VALUE; + } + + uint32 nameLength = 0; + + status_t err = dir->GetNextEntry(&(dirent->d_ino), dirent->d_name, &nameLength); + if (!err) { + *num = 1; + dirent->d_dev = volume->Id(); + } else { + *num = 0; + // Clear the error for end of directory + if (err == B_ENTRY_NOT_FOUND) + err = B_OK; + } + + RETURN(err); } @@ -582,7 +663,7 @@ int udf_rewind_dir(void *ns, void *node, void *cookie) { DEBUG_INIT(CF_ENTRY | CF_DIRECTORY_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -590,7 +671,7 @@ int udf_close_dir(void *ns, void *node, void *cookie) { DEBUG_INIT(CF_ENTRY | CF_DIRECTORY_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -598,7 +679,7 @@ int udf_free_dir_cookie(void *ns, void *node, void *cookie) { DEBUG_INIT(CF_ENTRY | CF_DIRECTORY_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -611,7 +692,7 @@ int udf_open_attrdir(void *ns, void *node, void **cookie) { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -619,7 +700,7 @@ int udf_close_attrdir(void *ns, void *node, void *cookie) { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -627,7 +708,7 @@ int udf_free_attrdir_cookie(void *ns, void *node, void *_cookie) { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -635,7 +716,7 @@ int udf_rewind_attrdir(void *_ns, void *_node, void *_cookie) { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -643,7 +724,7 @@ int udf_read_attrdir(void *_ns, void *node, void *_cookie, long *num, struct dirent *dirent, size_t bufsize) { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -652,7 +733,7 @@ udf_remove_attr(void *_ns, void *_node, const char *name) { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); // FUNCTION_START(("name = \"%s\"\n",name)); - return B_ERROR; + RETURN(B_ERROR); } @@ -661,7 +742,7 @@ udf_rename_attr(void *ns, void *node, const char *oldname, const char *newname) { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); // FUNCTION_START(("name = \"%s\",to = \"%s\"\n", oldname, newname)); - return B_ERROR; + RETURN(B_ERROR); } @@ -670,7 +751,7 @@ udf_stat_attr(void *ns, void *_node, const char *name, struct attr_info *attrInf { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); // FUNCTION_START(("name = \"%s\"\n",name)); - return B_ERROR; + RETURN(B_ERROR); } @@ -680,7 +761,7 @@ udf_write_attr(void *_ns, void *_node, const char *name, int type, const void *b { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); // FUNCTION_START(("name = \"%s\"\n",name)); - return B_ERROR; + RETURN(B_ERROR); } @@ -689,7 +770,7 @@ udf_read_attr(void *_ns, void *_node, const char *name, int type, void *buffer, size_t *_length, off_t pos) { DEBUG_INIT(CF_ENTRY | CF_ATTRIBUTE_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -702,7 +783,7 @@ int udf_open_indexdir(void *_ns, void **_cookie) { DEBUG_INIT(CF_ENTRY | CF_INDEX_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -710,7 +791,7 @@ int udf_close_indexdir(void *_ns, void *_cookie) { DEBUG_INIT(CF_ENTRY | CF_INDEX_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -718,7 +799,7 @@ int udf_free_indexdir_cookie(void *_ns, void *_node, void *_cookie) { DEBUG_INIT(CF_ENTRY | CF_INDEX_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -726,7 +807,7 @@ int udf_rewind_indexdir(void *_ns, void *_cookie) { DEBUG_INIT(CF_ENTRY | CF_INDEX_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -734,7 +815,7 @@ int udf_read_indexdir(void *_ns, void *_cookie, long *num, struct dirent *dirent, size_t bufferSize) { DEBUG_INIT(CF_ENTRY | CF_INDEX_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -743,7 +824,7 @@ udf_create_index(void *_ns, const char *name, int type, int flags) { DEBUG_INIT(CF_ENTRY | CF_INDEX_OPS, NULL); // FUNCTION_START(("name = \"%s\", type = %d, flags = %d\n", name, type, flags)); - return B_ERROR; + RETURN(B_ERROR); } @@ -751,7 +832,7 @@ int udf_remove_index(void *_ns, const char *name) { DEBUG_INIT(CF_ENTRY | CF_INDEX_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -760,7 +841,7 @@ udf_rename_index(void *ns, const char *oldname, const char *newname) { DEBUG_INIT(CF_ENTRY | CF_INDEX_OPS, NULL); // FUNCTION_START(("from = %s, to = %s\n", oldname, newname)); - return B_ERROR; + RETURN(B_ERROR); } @@ -769,7 +850,7 @@ udf_stat_index(void *_ns, const char *name, struct index_info *indexInfo) { DEBUG_INIT(CF_ENTRY | CF_INDEX_OPS, NULL); // FUNCTION_START(("name = %s\n",name)); - return B_ERROR; + RETURN(B_ERROR); } //---------------------------------------------------------------------- @@ -781,7 +862,7 @@ udf_open_query(void *_ns, const char *queryString, ulong flags, port_id port, long token, void **cookie) { DEBUG_INIT(CF_ENTRY | CF_QUERY_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -789,7 +870,7 @@ int udf_close_query(void *ns, void *cookie) { DEBUG_INIT(CF_ENTRY | CF_QUERY_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -797,7 +878,7 @@ int udf_free_query_cookie(void *ns, void *node, void *cookie) { DEBUG_INIT(CF_ENTRY | CF_QUERY_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); } @@ -805,6 +886,6 @@ int udf_read_query(void *ns, void *cookie, long *num, struct dirent *dirent, size_t bufferSize) { DEBUG_INIT(CF_ENTRY | CF_QUERY_OPS, NULL); - return B_ERROR; + RETURN(B_ERROR); }