From 8c3082077ff600c4038aa5d6f43e3b5c6432a2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Tue, 6 Apr 2010 19:43:27 +0000 Subject: [PATCH] The mighty GoogleFS builds again for Haiku \o/ Still lotsa warning and panics on mount though... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36053 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../file_systems/googlefs/google_request.c | 4 +- .../file_systems/googlefs/google_request.h | 4 +- .../kernel/file_systems/googlefs/googlefs.c | 697 ++++++++---------- .../kernel/file_systems/googlefs/googlefs.h | 2 +- .../kernel/file_systems/googlefs/http_cnx.h | 2 + .../kernel/file_systems/googlefs/vnidpool.c | 5 +- 6 files changed, 334 insertions(+), 380 deletions(-) diff --git a/src/add-ons/kernel/file_systems/googlefs/google_request.c b/src/add-ons/kernel/file_systems/googlefs/google_request.c index bb175fd403..e28f123663 100644 --- a/src/add-ons/kernel/file_systems/googlefs/google_request.c +++ b/src/add-ons/kernel/file_systems/googlefs/google_request.c @@ -197,7 +197,7 @@ status_t google_request_close(struct google_request *req) return B_OK; } -status_t google_request_open(const char *query_string, struct fs_nspace *ns, struct fs_node *query_node, struct google_request **req) +status_t google_request_open(const char *query_string, struct fs_volume *volume, struct fs_node *query_node, struct google_request **req) { struct google_request *r; if (!req) @@ -207,7 +207,7 @@ status_t google_request_open(const char *query_string, struct fs_nspace *ns, str return ENOMEM; memset(r, 0, sizeof(struct google_request)); r->query_string = strdup(query_string); - r->ns = ns; + r->volume = volume; r->query_node = query_node; *req = r; return B_OK; diff --git a/src/add-ons/kernel/file_systems/googlefs/google_request.h b/src/add-ons/kernel/file_systems/googlefs/google_request.h index bb0dcbfca2..7352bbb7d7 100644 --- a/src/add-ons/kernel/file_systems/googlefs/google_request.h +++ b/src/add-ons/kernel/file_systems/googlefs/google_request.h @@ -7,7 +7,7 @@ struct google_request { struct google_request *next; - struct fs_nspace *ns; + struct fs_volume *volume; struct fs_node *query_node; /* root folder for that query */ char *query_string; struct http_cnx *cnx; @@ -35,7 +35,7 @@ extern status_t google_request_uninit(void); extern status_t google_request_process(struct google_request *req); extern status_t google_request_process_async(struct google_request *req); extern status_t google_request_close(struct google_request *req); -extern status_t google_request_open(const char *query_string, struct fs_nspace *ns, struct fs_node *query_node, struct google_request **req); +extern status_t google_request_open(const char *query_string, struct fs_volume *volume, struct fs_node *query_node, struct google_request **req); extern status_t google_request_free(struct google_request *req); #endif /* _GOOGLE_REQUEST_H */ diff --git a/src/add-ons/kernel/file_systems/googlefs/googlefs.c b/src/add-ons/kernel/file_systems/googlefs/googlefs.c index e73f8d3766..a08776d0c9 100644 --- a/src/add-ons/kernel/file_systems/googlefs/googlefs.c +++ b/src/add-ons/kernel/file_systems/googlefs/googlefs.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2008, François Revol, . + * Copyright 2004-2010, François Revol, . * Distributed under the terms of the MIT License. */ @@ -27,20 +27,18 @@ /* just publish fake entries; for debugging */ //#define NO_SEARCH -//#define DEBUG_GOOGLEFS 1 - -#if DEBUG_GOOGLEFS -#define PRINT(a) /*snooze(5000);*/ dprintf a +//#define TRACE_GOOGLEFS +#ifdef TRACE_GOOGLEFS +# define TRACE(x) dprintf x #else -#define PRINT(a) +# define TRACE(x) #endif + #define PFS "googlefs: " /* needed to get /bin/df tell the mountpoint... */ #define ALLOW_DIR_OPEN -/* test: */ - vint32 refcount = 0; @@ -54,7 +52,11 @@ extern struct attr_entry mailto_me_bookmark_attrs[]; extern char *readmestr; -static int googlefs_create_gen(fs_nspace *ns, fs_node *dir, const char *name, int omode, int perms, ino_t *vnid, fs_node **node, struct attr_entry *iattrs, bool mkdir, bool uniq); +static fs_volume_ops sGoogleFSVolumeOps; +static fs_vnode_ops sGoogleFSVnodeOps; + + +static int googlefs_create_gen(fs_volume *_volume, fs_node *dir, const char *name, int omode, int perms, ino_t *vnid, fs_node **node, struct attr_entry *iattrs, bool mkdir, bool uniq); static void fill_default_stat(struct stat *st, nspace_id nsid, ino_t vnid, mode_t mode) { @@ -75,31 +77,32 @@ static void fill_default_stat(struct stat *st, nspace_id nsid, ino_t vnid, mode_ /** Publishes some entries in the root vnode: a query template, the readme file, and a People file of the author. */ -int googlefs_publish_static_entries(fs_nspace *ns) +static int googlefs_publish_static_entries(fs_volume *_volume) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; fs_node *dir = ns->root; fs_node *n, *dummy; char ename[GOOGLEFS_NAME_LEN]; char *p; int i; - PRINT((PFS"googlefs_publish_static_entries(%ld)\n", ns->nsid)); + TRACE((PFS"googlefs_publish_static_entries(%ld)\n", ns->nsid)); if (!ns || !dir) return EINVAL; - err = googlefs_create_gen(ns, dir, "Search Google", 0, 0444, NULL, &n, template_1_attrs, false, true); + err = googlefs_create_gen(_volume, dir, "Search Google", 0, 0444, NULL, &n, template_1_attrs, false, true); if (err) return err; n->is_perm = 1; - err = googlefs_create_gen(ns, dir, "README", 0, 0444, NULL, &n, text_attrs, false, true); + err = googlefs_create_gen(_volume, dir, "README", 0, 0444, NULL, &n, text_attrs, false, true); if (err) return err; n->is_perm = 1; n->data = readmestr; n->data_size = strlen(n->data);// + 1; - err = googlefs_create_gen(ns, dir, "Author", 0, 0444, NULL, &n, mailto_me_bookmark_attrs, false, true); + err = googlefs_create_gen(_volume, dir, "Author", 0, 0444, NULL, &n, mailto_me_bookmark_attrs, false, true); if (err) return err; n->is_perm = 1; @@ -107,25 +110,17 @@ int googlefs_publish_static_entries(fs_nspace *ns) return B_OK; err: - PRINT((PFS"push_result_to_query: error 0x%08lx\n", err)); + TRACE((PFS"push_result_to_query: error 0x%08lx\n", err)); return err; } -#ifdef __HAIKU__ -int googlefs_mount(nspace_id nsid, const char *devname, uint32 flags, - const char *parms, fs_nspace **data, ino_t *vnid) -#else -int googlefs_mount(nspace_id nsid, const char *devname, ulong flags, - const char *parms, size_t len, fs_nspace **data, ino_t *vnid) -#endif +int googlefs_mount(fs_volume *_vol, const char *devname, uint32 flags, + const char *parms, ino_t *vnid) { fs_nspace *ns; fs_node *root; int err; - PRINT((PFS "mount(%ld, %s, 0x%08lx, %p, , )\n", nsid, devname, flags, parms)); -#ifndef __HAIKU__ - (void) len; -#endif + TRACE((PFS "mount(%p, %s, 0x%08lx, %s, , )\n", _vol, devname, flags, parms)); /* only allow a single mount */ if (atomic_add(&refcount, 1)) @@ -141,7 +136,8 @@ int googlefs_mount(nspace_id nsid, const char *devname, ulong flags, if (!ns) return B_NO_MEMORY; memset(ns, 0, sizeof(fs_nspace)); - ns->nsid = nsid; + ns->nsid = _vol->id; + err = vnidpool_alloc(&ns->vnids, MAX_VNIDS); if (err < 0) return err; @@ -150,9 +146,8 @@ int googlefs_mount(nspace_id nsid, const char *devname, ulong flags, return err; atomic_add(&ns->nodecount, 1); - err = new_lock(&(ns->l), "googlefs main lock"); - if (err < 0) - return err; + new_lock(&(ns->l), "googlefs main lock"); + ns->nodes = NULL; /* create root dir */ @@ -166,19 +161,19 @@ int googlefs_mount(nspace_id nsid, const char *devname, ulong flags, root->vnid = ns->rootid; fill_default_stat(&root->st, ns->nsid, ns->rootid, 0777 | S_IFDIR); root->attrs_indirect = root_folder_attrs; - err = new_lock(&(root->l), "googlefs root dir"); - if (err >= 0) { - *data = ns; - *vnid = ns->rootid; - ns->nodes = root; // sll_insert - err = publish_vnode(nsid, *vnid, root); - if (err == B_OK) { - googlefs_publish_static_entries(ns); - PRINT((PFS "mount() OK, nspace@ %p, id %ld, root@ %p, id %Ld\n", ns, ns->nsid, root, ns->rootid)); - return B_OK; - } - free_lock(&root->l); + new_lock(&(root->l), "googlefs root dir"); + + _vol->private_volume = ns; + _vol->ops = &sGoogleFSVolumeOps; + *vnid = ns->rootid; + ns->nodes = root; // sll_insert + err = publish_vnode(_vol, *vnid, root, &sGoogleFSVnodeOps, S_IFDIR, 0); + if (err == B_OK) { + googlefs_publish_static_entries(ns); + TRACE((PFS "mount() OK, nspace@ %p, id %ld, root@ %p, id %Ld\n", ns, ns->nsid, root, ns->rootid)); + return B_OK; } + free_lock(&root->l); free(root); } free_lock(&ns->l); @@ -188,11 +183,12 @@ err_http: return err; } -int googlefs_unmount(fs_nspace *ns) +status_t googlefs_unmount(fs_volume *_volume) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err; struct fs_node *node; - PRINT((PFS "unmount(%ld)\n", ns->nsid)); + TRACE((PFS "unmount(%ld)\n", ns->nsid)); err = LOCK(&ns->l); if (err) return err; @@ -203,9 +199,7 @@ int googlefs_unmount(fs_nspace *ns) } // Unlike in BeOS, we need to put the reference to our root node ourselves -#ifdef __HAIKU__ put_vnode(ns->nsid, ns->rootid); -#endif free_lock(&ns->l); vnidpool_free(ns->vnids); @@ -223,8 +217,9 @@ static int compare_fs_node_by_vnid(fs_node *node, ino_t *id) return !(node->vnid == *id); } -int googlefs_free_vnode(fs_nspace *ns, fs_node *node) +int googlefs_free_vnode(fs_volume *_volume, fs_node *node) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; free_lock(&node->l); atomic_add(&ns->nodecount, -1); vnidpool_put(ns->vnids, node->vnid); @@ -235,20 +230,17 @@ int googlefs_free_vnode(fs_nspace *ns, fs_node *node) return 0; } -#ifdef __HAIKU__ -int googlefs_remove_vnode(fs_nspace *ns, char r, fs_node *node) -#else -int googlefs_remove_vnode(fs_nspace *ns, fs_node *node, char r) -#endif +int googlefs_remove_vnode(fs_volume *_volume, char r, fs_node *node) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; - PRINT((PFS "remove_vnode(%ld, %Ld, %s)\n", ns->nsid, node->vnid, r?"r":"!r")); + TRACE((PFS "remove_vnode(%ld, %Ld, %s)\n", ns->nsid, node->vnid, r?"r":"!r")); if (!r) err = LOCK(&ns->l); if (err) return err; if (node->vnid == ns->rootid) { - PRINT((PFS "asked to remove the root node!!\n")); + TRACE((PFS "asked to remove the root node!!\n")); } //LOCK(&node->l); err = SLL_REMOVE(ns->nodes, nlnext, node); @@ -265,15 +257,12 @@ int googlefs_remove_vnode(fs_nspace *ns, fs_node *node, char r) return err; } -#ifdef __HAIKU__ -int googlefs_read_vnode(fs_nspace *ns, ino_t vnid, fs_node **node, char r) -#else -int googlefs_read_vnode(fs_nspace *ns, ino_t vnid, char r, fs_node **node) -#endif +int googlefs_read_vnode(fs_volume *_volume, ino_t vnid, fs_node **node, char r) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; fs_node *n; status_t err = B_OK; - PRINT((PFS "read_vnode(%ld, %Ld, %s)\n", ns->nsid, vnid, r?"r":"!r")); + TRACE((PFS "read_vnode(%ld, %Ld, %s)\n", ns->nsid, vnid, r?"r":"!r")); if (!r) err = LOCK(&ns->l); if (err) @@ -288,51 +277,35 @@ int googlefs_read_vnode(fs_nspace *ns, ino_t vnid, char r, fs_node **node) return err; } -#ifdef __HAIKU__ -int googlefs_release_vnode(fs_nspace *ns, fs_node *node, char r) -#else -int googlefs_write_vnode(fs_nspace *ns, fs_node *node, char r) -#endif +int googlefs_release_vnode(fs_volume *_volume, fs_node *node, char r) { - PRINT((PFS "write_vnode(%ld, %Ld, %s)\n", ns->nsid, node->vnid, r?"r":"!r")); + TRACE((PFS "write_vnode(%ld, %Ld, %s)\n", ns->nsid, node->vnid, r?"r":"!r")); return B_OK; } -#ifndef __HAIKU__ -int googlefs_secure_vnode(fs_nspace *ns, fs_node *node) -{ - PRINT((PFS "secure_vnode(%ld, %Ld)\n", ns->nsid, node->vnid)); - return B_OK; -} -#endif - static int compare_fs_node_by_name(fs_node *node, char *name) { //return memcmp(node->name, name, GOOGLEFS_NAME_LEN); - PRINT((PFS"find_by_name: '%s' <> '%s'\n", node->name, name)); + TRACE((PFS"find_by_name: '%s' <> '%s'\n", node->name, name)); return strncmp(node->name, name, GOOGLEFS_NAME_LEN); } -#ifdef __HAIKU__ -int googlefs_get_vnode_name(fs_nspace *ns, fs_node *node, char *buffer, size_t len) +int googlefs_get_vnode_name(fs_volume *_volume, fs_node *node, char *buffer, size_t len) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; fs_node *n, *dummy; status_t err = B_OK; - PRINT((PFS "get_vnode_name(%ld, %Ld, )\n", ns->nsid, (int64)(node?node->vnid:-1))); + TRACE((PFS "get_vnode_name(%ld, %Ld, )\n", ns->nsid, (int64)(node?node->vnid:-1))); strlcpy(buffer, node->name, MIN(GOOGLEFS_NAME_LEN, len)); return B_OK; } -#endif -#ifdef __HAIKU__ -int googlefs_walk(fs_nspace *ns, fs_node *base, const char *file, ino_t *vnid, int *type) -#else -int googlefs_walk(fs_nspace *ns, fs_node *base, const char *file, char **newpath, ino_t *vnid) -#endif +int googlefs_walk(fs_volume *_volume, fs_node *base, const char *file, ino_t *vnid, int *type) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; fs_node *n, *dummy; status_t err = B_OK; - PRINT((PFS "walk(%ld, %Ld, %s)\n", ns->nsid, (int64)(base?base->vnid:-1), file)); + TRACE((PFS "walk(%ld, %Ld, %s)\n", ns->nsid, (int64)(base?base->vnid:-1), file)); err = LOCK(&base->l); if (err) return err; @@ -341,17 +314,13 @@ int googlefs_walk(fs_nspace *ns, fs_node *base, const char *file, char **newpath } else if (!strcmp(file, "..")) { if (base && base->parent) { *vnid = base->parent->vnid; // XXX: LOCK(&base->l) ? -#ifdef __HAIKU__ *type = S_IFDIR; -#endif } else err = EINVAL; } else if (!strcmp(file, ".")) { /* root dir */ if (base) { // XXX: LOCK(&base->l) ? *vnid = base->vnid; -#ifdef __HAIKU__ *type = S_IFDIR; -#endif } else err = EINVAL; } else if (base) { /* child of dir */ @@ -359,9 +328,7 @@ int googlefs_walk(fs_nspace *ns, fs_node *base, const char *file, char **newpath (sll_compare_func)compare_fs_node_by_name, (void *)file); if (n) { *vnid = n->vnid; -#ifdef __HAIKU__ *type = n->st.st_type & ~S_IUMSK; /*XXX: S_IFMT ?*/ -#endif } else err = ENOENT; } else @@ -371,15 +338,16 @@ int googlefs_walk(fs_nspace *ns, fs_node *base, const char *file, char **newpath err = EINVAL; } UNLOCK(&base->l); - PRINT((PFS "walk() -> error 0x%08lx\n", err)); + TRACE((PFS "walk() -> error 0x%08lx\n", err)); return err; } -int googlefs_opendir(fs_nspace *ns, fs_node *node, fs_dir_cookie **cookie) +int googlefs_opendir(fs_volume *_volume, fs_node *node, fs_dir_cookie **cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; fs_dir_cookie *c; - PRINT((PFS "opendir(%ld, %Ld)\n", ns->nsid, node->vnid)); + TRACE((PFS "opendir(%ld, %Ld)\n", ns->nsid, node->vnid)); if (!node) return EINVAL; if (!S_ISDIR(node->st.st_mode)) @@ -404,10 +372,11 @@ int googlefs_opendir(fs_nspace *ns, fs_node *node, fs_dir_cookie **cookie) return err; } -int googlefs_closedir(fs_nspace *ns, fs_node *node, fs_dir_cookie *cookie) +int googlefs_closedir(fs_volume *_volume, fs_node *node, fs_dir_cookie *cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; - PRINT((PFS "closedir(%ld, %Ld)\n", ns->nsid, node->vnid)); + TRACE((PFS "closedir(%ld, %Ld)\n", ns->nsid, node->vnid)); err = LOCK(&node->l); if (err) return err; @@ -417,29 +386,27 @@ int googlefs_closedir(fs_nspace *ns, fs_node *node, fs_dir_cookie *cookie) return err; } -int googlefs_rewinddir(fs_nspace *ns, fs_node *node, fs_dir_cookie *cookie) +int googlefs_rewinddir(fs_volume *_volume, fs_node *node, fs_dir_cookie *cookie) { - PRINT((PFS "rewinddir(%ld, %Ld)\n", ns->nsid, node->vnid)); + fs_nspace *ns = (fs_nspace *)_volume->private_volume; + TRACE((PFS "rewinddir(%ld, %Ld)\n", ns->nsid, node->vnid)); cookie->dir_current = 0; return B_OK; } -#ifdef __HAIKU__ -int googlefs_readdir(fs_nspace *ns, fs_node *node, fs_dir_cookie *cookie, struct dirent *buf, size_t bufsize, uint32 *num) -#else -int googlefs_readdir(fs_nspace *ns, fs_node *node, fs_dir_cookie *cookie, long *num, struct dirent *buf, size_t bufsize) -#endif +int googlefs_readdir(fs_volume *_volume, fs_node *node, fs_dir_cookie *cookie, struct dirent *buf, size_t bufsize, uint32 *num) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; fs_node *n = NULL; fs_node *parent = node->parent; int index; - PRINT((PFS "readdir(%ld, %Ld) @ %d\n", ns->nsid, node->vnid, cookie->dir_current)); + TRACE((PFS "readdir(%ld, %Ld) @ %d\n", ns->nsid, node->vnid, cookie->dir_current)); if (!node || !cookie || !num || !*num || !buf || (bufsize < (sizeof(dirent_t)+GOOGLEFS_NAME_LEN))) return EINVAL; err = LOCK(&node->l); if (cookie->dir_current == 0) { /* .. */ - PRINT((PFS "readdir: giving ..\n")); + TRACE((PFS "readdir: giving ..\n")); /* the VFS will correct that anyway */ buf->d_dev = ns->nsid; buf->d_pdev = ns->nsid; @@ -450,7 +417,7 @@ int googlefs_readdir(fs_nspace *ns, fs_node *node, fs_dir_cookie *cookie, long * cookie->dir_current++; *num = 1; } else if (cookie->dir_current == 1) { /* . */ - PRINT((PFS "readdir: giving .\n")); + TRACE((PFS "readdir: giving .\n")); /* the VFS will correct that anyway */ buf->d_dev = ns->nsid; buf->d_pdev = ns->nsid; @@ -464,7 +431,7 @@ int googlefs_readdir(fs_nspace *ns, fs_node *node, fs_dir_cookie *cookie, long * index = cookie->dir_current-2; for (n = node->children; n && index; n = n->next, index--); //XXX: care about n->hidden || n->deleted if (n) { - PRINT((PFS "readdir: giving ino %Ld, %s\n", n->vnid, n->name)); + TRACE((PFS "readdir: giving ino %Ld, %s\n", n->vnid, n->name)); buf->d_dev = ns->nsid; buf->d_pdev = ns->nsid; buf->d_ino = n->vnid; @@ -481,15 +448,17 @@ int googlefs_readdir(fs_nspace *ns, fs_node *node, fs_dir_cookie *cookie, long * return B_OK; } -int googlefs_free_dircookie(fs_nspace *ns, fs_node *node, fs_dir_cookie *cookie) +int googlefs_free_dircookie(fs_volume *_volume, fs_node *node, fs_dir_cookie *cookie) { - PRINT((PFS"freedircookie(%ld, %Ld)\n", ns->nsid, node?node->vnid:0LL)); + fs_nspace *ns = (fs_nspace *)_volume->private_volume; + TRACE((PFS"freedircookie(%ld, %Ld)\n", ns->nsid, node?node->vnid:0LL)); free(cookie); return B_OK; } -int googlefs_rstat(fs_nspace *ns, fs_node *node, struct stat *st) +int googlefs_rstat(fs_volume *_volume, fs_node *node, struct stat *st) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; if (!node || !st) return EINVAL; @@ -506,8 +475,9 @@ int googlefs_rstat(fs_nspace *ns, fs_node *node, struct stat *st) return err; } -int googlefs_rfsstat(fs_nspace *ns, struct fs_info *info) +int googlefs_rfsstat(fs_volume *_volume, struct fs_info *info) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; info->block_size=1024;//googlefs_BUFF_SIZE; info->io_size=1024;//GOOGLEFS_BUFF_SIZE; info->total_blocks=0; @@ -523,12 +493,13 @@ int googlefs_rfsstat(fs_nspace *ns, struct fs_info *info) return B_OK; } -int googlefs_open(fs_nspace *ns, fs_node *node, int omode, fs_file_cookie **cookie) +int googlefs_open(fs_volume *_volume, fs_node *node, int omode, fs_file_cookie **cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; fs_node *dummy; fs_file_cookie *fc; - PRINT((PFS"open(%ld, %Ld, 0x%x)\n", ns->nsid, node->vnid, omode)); + TRACE((PFS"open(%ld, %Ld, 0x%x)\n", ns->nsid, node->vnid, omode)); if (!node || !cookie) return EINVAL; @@ -576,10 +547,11 @@ err_n_l: return err; } -int googlefs_close(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie) +int googlefs_close(fs_volume *_volume, fs_node *node, fs_file_cookie *cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err; - PRINT((PFS"close(%ld, %Ld)\n", ns->nsid, node->vnid)); + TRACE((PFS"close(%ld, %Ld)\n", ns->nsid, node->vnid)); if (!ns || !node || !cookie) return EINVAL; err = LOCK(&node->l); @@ -593,10 +565,11 @@ err_n_l: return err; } -int googlefs_free_cookie(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie) +int googlefs_free_cookie(fs_volume *_volume, fs_node *node, fs_file_cookie *cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; - PRINT((PFS"freecookie(%ld, %Ld)\n", ns->nsid, node->vnid)); + TRACE((PFS"freecookie(%ld, %Ld)\n", ns->nsid, node->vnid)); err = LOCK(&node->l); if (err) return err; @@ -606,8 +579,10 @@ int googlefs_free_cookie(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie) if (/*!node->is_perm &&*/ false) { /* not yet */ err = remove_vnode(ns->nsid, node->vnid); ns->root->st.st_mtime = time(NULL); +#if 0 notify_listener(B_ENTRY_REMOVED, ns->nsid, ns->rootid, 0LL, node->vnid, NULL); notify_listener(B_STAT_CHANGED, ns->nsid, 0LL, 0LL, ns->rootid, NULL); +#endif } UNLOCK(&node->l); free(cookie); @@ -616,10 +591,11 @@ err_n_l: return err; } -int googlefs_read(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie, off_t pos, void *buf, size_t *len) +int googlefs_read(fs_volume *_volume, fs_node *node, fs_file_cookie *cookie, off_t pos, void *buf, size_t *len) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; - PRINT((PFS"read(%ld, %Ld, %Ld, %ld)\n", ns->nsid, node->vnid, pos, *len)); + TRACE((PFS"read(%ld, %Ld, %Ld, %ld)\n", ns->nsid, node->vnid, pos, *len)); if (node->data_size == 0 || !node->data) err = ENOSYS; if (pos < 0 || pos > node->data_size) @@ -633,22 +609,22 @@ int googlefs_read(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie, off_t po return B_OK; } -int googlefs_write(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie, off_t pos, const void *buf, size_t *len) +int googlefs_write(fs_volume *_volume, fs_node *node, fs_file_cookie *cookie, off_t pos, const void *buf, size_t *len) { - PRINT((PFS"write(%ld, %Ld, %Ld, %ld)\n", ns->nsid, node->vnid, pos, *len)); + TRACE((PFS"write(%ld, %Ld, %Ld, %ld)\n", ns->nsid, node->vnid, pos, *len)); *len = 0; return ENOSYS; } -int googlefs_wstat(fs_nspace *ns, fs_node *node, struct stat *st, long mask) +int googlefs_wstat(fs_volume *_volume, fs_node *node, struct stat *st, long mask) { - PRINT((PFS"wstat(%ld, %Ld, , 0x%08lx)\n", ns->nsid, node->vnid, mask)); + TRACE((PFS"wstat(%ld, %Ld, , 0x%08lx)\n", ns->nsid, node->vnid, mask)); return ENOSYS; } -int googlefs_wfsstat(fs_nspace *ns, struct fs_info *info, long mask) +int googlefs_wfsstat(fs_volume *_volume, struct fs_info *info, long mask) { - PRINT((PFS"wfsstat(%ld, , 0x%08lx)\n", ns->nsid, mask)); + TRACE((PFS"wfsstat(%ld, , 0x%08lx)\n", ns->nsid, mask)); return ENOSYS; } @@ -662,13 +638,14 @@ int googlefs_wfsstat(fs_nspace *ns, struct fs_info *info, long mask) * @param mkdir create a directory instead of a file * @param uniq choose an unique name, appending a number if required */ -static int googlefs_create_gen(fs_nspace *ns, fs_node *dir, const char *name, int omode, int perms, ino_t *vnid, fs_node **node, struct attr_entry *iattrs, bool mkdir, bool uniq) +static int googlefs_create_gen(fs_volume *_volume, fs_node *dir, const char *name, int omode, int perms, ino_t *vnid, fs_node **node, struct attr_entry *iattrs, bool mkdir, bool uniq) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; char newname[GOOGLEFS_NAME_LEN]; status_t err; fs_node *n; int i; - PRINT((PFS"create_gen(%ld, %Ld, '%s', 0x%08lx, %c, %c)\n", ns->nsid, dir->vnid, name, omode, mkdir?'t':'f', uniq?'t':'f')); + TRACE((PFS"create_gen(%ld, %Ld, '%s', 0x%08lx, %c, %c)\n", ns->nsid, dir->vnid, name, omode, mkdir?'t':'f', uniq?'t':'f')); if (strlen(name) > GOOGLEFS_NAME_LEN-1) return ENAMETOOLONG; @@ -719,9 +696,9 @@ static int googlefs_create_gen(fs_nspace *ns, fs_node *dir, const char *name, in strcpy(n->name, name); //n->is_perm = 1; fill_default_stat(&n->st, ns->nsid, n->vnid, (perms & ~S_IFMT) | (mkdir?S_IFDIR:S_IFREG)); - err = new_lock(&(n->l), mkdir?"googlefs dir":"googlefs file"); - if (err) - goto err_m; + + new_lock(&(n->l), mkdir?"googlefs dir":"googlefs file"); + err = LOCK(&ns->l); if (err) goto err_nl; @@ -739,9 +716,9 @@ static int googlefs_create_gen(fs_nspace *ns, fs_node *dir, const char *name, in dir->st.st_nlink++; UNLOCK(&ns->l); n->attrs_indirect = iattrs; - notify_listener(B_ENTRY_CREATED, ns->nsid, dir->vnid, 0, n->vnid, name); + notify_entry_created(ns->nsid, dir->vnid, name, n->vnid); /* dosfs doesn't do that one but I believe it should */ - notify_listener(B_STAT_CHANGED, ns->nsid, 0LL, 0LL, dir->vnid, NULL); + notify_stat_changed(B_STAT_CHANGED, ns->nsid, -1); /* give node to caller if it wants it */ if (node) *node = n; @@ -764,26 +741,28 @@ done: return err; } -int googlefs_create(fs_nspace *ns, fs_node *dir, const char *name, int omode, int perms, ino_t *vnid, fs_file_cookie **cookie) +int googlefs_create(fs_volume *_volume, fs_node *dir, const char *name, int omode, int perms, ino_t *vnid, fs_file_cookie **cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err; fs_node *n; - PRINT((PFS"create(%ld, %Ld, '%s', 0x%08lx)\n", ns->nsid, dir->vnid, name, omode)); + TRACE((PFS"create(%ld, %Ld, '%s', 0x%08lx)\n", ns->nsid, dir->vnid, name, omode)); /* don't let ppl mess our fs up */ return ENOSYS; - err = googlefs_create_gen(ns, dir, name, omode, perms, vnid, &n, NULL, false, false); + err = googlefs_create_gen(_volume, dir, name, omode, perms, vnid, &n, NULL, false, false); if (err) return err; err = googlefs_open(ns, n, omode, cookie); return err; } -int googlefs_unlink(fs_nspace *ns, fs_node *dir, const char *name) +int googlefs_unlink(fs_volume *_volume, fs_node *dir, const char *name) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err; fs_node *n; - PRINT((PFS"unlink(%ld, %Ld, %s)\n", ns->nsid, dir->vnid, name)); + TRACE((PFS"unlink(%ld, %Ld, %s)\n", ns->nsid, dir->vnid, name)); //dprintf(PFS"unlink(%ld, %Ld, %s)\n", ns->nsid, dir->vnid, name); err = LOCK(&dir->l); if (err) @@ -803,8 +782,8 @@ int googlefs_unlink(fs_nspace *ns, fs_node *dir, const char *name) err = EACCES; else { SLL_REMOVE(dir->children, next, n); - notify_listener(B_ENTRY_REMOVED, ns->nsid, dir->vnid, 0LL, n->vnid, NULL); - notify_listener(B_STAT_CHANGED, ns->nsid, 0LL, 0LL, dir->vnid, NULL); + notify_entry_removed(ns->nsid, dir->vnid, name, n->vnid); + //notify_listener(B_STAT_CHANGED, ns->nsid, 0LL, 0LL, dir->vnid, NULL); remove_vnode(ns->nsid, n->vnid); err = B_OK; } @@ -813,17 +792,19 @@ int googlefs_unlink(fs_nspace *ns, fs_node *dir, const char *name) return err; } -int googlefs_rmdir(fs_nspace *ns, fs_node *dir, const char *name) +int googlefs_rmdir(fs_volume *_volume, fs_node *dir, const char *name) { - PRINT((PFS"rmdir(%ld, %Ld, %s)\n", ns->nsid, dir->vnid, name)); + fs_nspace *ns = (fs_nspace *)_volume->private_volume; + TRACE((PFS"rmdir(%ld, %Ld, %s)\n", ns->nsid, dir->vnid, name)); return googlefs_unlink(ns, dir, name); } -static int googlefs_unlink_node_rec(fs_nspace *ns, fs_node *node) +static int googlefs_unlink_node_rec(fs_volume *_volume, fs_node *node) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err; fs_node *n; - PRINT((PFS"googlefs_unlink_node_rec(%ld, %Ld:%s)\n", ns->nsid, node->vnid, node->name)); + TRACE((PFS"googlefs_unlink_node_rec(%ld, %Ld:%s)\n", ns->nsid, node->vnid, node->name)); if (!ns || !node) return EINVAL; // kill_request(); @@ -841,25 +822,27 @@ static int googlefs_unlink_node_rec(fs_nspace *ns, fs_node *node) return err; } -int googlefs_access(fs_nspace *ns, fs_node *node, int mode) +int googlefs_access(fs_volume *_volume, fs_node *node, int mode) { - PRINT((PFS"access(%ld, %Ld, 0x%x)\n", ns->nsid, node->vnid, mode)); + fs_nspace *ns = (fs_nspace *)_volume->private_volume; + TRACE((PFS"access(%ld, %Ld, 0x%x)\n", ns->nsid, node->vnid, mode)); return B_OK; } -int googlefs_setflags(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie, int flags) +int googlefs_setflags(fs_volume *_volume, fs_node *node, fs_file_cookie *cookie, int flags) { return EINVAL; } #if 0 -static int googlefs_mkdir_gen(fs_nspace *ns, fs_node *dir, const char *name, int perms, fs_node **node, bool uniq) +static int googlefs_mkdir_gen(fs_volume *_volume, fs_node *dir, const char *name, int perms, fs_node **node, bool uniq) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; char newname[GOOGLEFS_NAME_LEN]; status_t err; fs_node *n; int i; - PRINT((PFS"mkdir_gen(%ld, %Ld, '%s', 0x%08lx, %c)\n", ns->nsid, dir->vnid, name, perms, uniq?'t':'f')); + TRACE((PFS"mkdir_gen(%ld, %Ld, '%s', 0x%08lx, %c)\n", ns->nsid, dir->vnid, name, perms, uniq?'t':'f')); if (strlen(name) > GOOGLEFS_NAME_LEN-1) return ENAMETOOLONG; @@ -918,9 +901,9 @@ static int googlefs_mkdir_gen(fs_nspace *ns, fs_node *dir, const char *name, int dir->st.st_nlink++; UNLOCK(&ns->l); n->attrs_indirect = folders_attrs; - notify_listener(B_ENTRY_CREATED, ns->nsid, dir->vnid, 0, n->vnid, name); + notify_entry_created(ns->nsid, dir->vnid, name, n->vnid); /* dosfs doesn't do that one but I believe it should */ - notify_listener(B_STAT_CHANGED, ns->nsid, 0LL, 0LL, dir->vnid, NULL); + //notify_listener(B_STAT_CHANGED, ns->nsid, 0LL, 0LL, dir->vnid, NULL); /* give node to caller if it wants it */ if (node) *node = n; @@ -942,19 +925,21 @@ done: } #endif -int googlefs_mkdir(fs_nspace *ns, fs_node *dir, const char *name, int perms) +int googlefs_mkdir(fs_volume *_volume, fs_node *dir, const char *name, int perms) { - PRINT((PFS"mkdir(%ld, %Ld, '%s', 0x%08lx)\n", ns->nsid, dir->vnid, name, perms)); - return googlefs_create_gen(ns, dir, name, O_EXCL, perms, NULL, NULL, folders_attrs, true, false); + fs_nspace *ns = (fs_nspace *)_volume->private_volume; + TRACE((PFS"mkdir(%ld, %Ld, '%s', 0x%08lx)\n", ns->nsid, dir->vnid, name, perms)); + return googlefs_create_gen(_volume, dir, name, O_EXCL, perms, NULL, NULL, folders_attrs, true, false); } /* attr stuff */ -int googlefs_open_attrdir(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie **cookie) +int googlefs_open_attrdir(fs_volume *_volume, fs_node *node, fs_attr_dir_cookie **cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; fs_attr_dir_cookie *c; - PRINT((PFS "open_attrdir(%ld, %Ld)\n", ns->nsid, node->vnid)); + TRACE((PFS "open_attrdir(%ld, %Ld)\n", ns->nsid, node->vnid)); if (!node) return EINVAL; err = LOCK(&node->l); @@ -977,10 +962,11 @@ int googlefs_open_attrdir(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie **coo return err; } -int googlefs_close_attrdir(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie *cookie) +int googlefs_close_attrdir(fs_volume *_volume, fs_node *node, fs_attr_dir_cookie *cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; - PRINT((PFS "close_attrdir(%ld, %Ld)\n", ns->nsid, node->vnid)); + TRACE((PFS "close_attrdir(%ld, %Ld)\n", ns->nsid, node->vnid)); err = LOCK(&node->l); if (err) return err; @@ -989,33 +975,32 @@ int googlefs_close_attrdir(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie *coo return err; } -int googlefs_free_attrdircookie(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie *cookie) +int googlefs_free_attrdircookie(fs_volume *_volume, fs_node *node, fs_attr_dir_cookie *cookie) { - PRINT((PFS"free_attrdircookie(%ld, %Ld)\n", ns->nsid, node->vnid)); + fs_nspace *ns = (fs_nspace *)_volume->private_volume; + TRACE((PFS"free_attrdircookie(%ld, %Ld)\n", ns->nsid, node->vnid)); free(cookie); return B_OK; } -int googlefs_rewind_attrdir(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie *cookie) +int googlefs_rewind_attrdir(fs_volume *_volume, fs_node *node, fs_attr_dir_cookie *cookie) { - PRINT((PFS "rewind_attrdir(%ld, %Ld)\n", ns->nsid, node->vnid)); + fs_nspace *ns = (fs_nspace *)_volume->private_volume; + TRACE((PFS "rewind_attrdir(%ld, %Ld)\n", ns->nsid, node->vnid)); cookie->dir_current = 0; return B_OK; } -#ifdef __HAIKU__ -int googlefs_read_attrdir(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie *cookie, struct dirent *buf, size_t bufsize, uint32 *num) -#else -int googlefs_read_attrdir(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie *cookie, long *num, struct dirent *buf, size_t bufsize) -#endif +int googlefs_read_attrdir(fs_volume *_volume, fs_node *node, fs_attr_dir_cookie *cookie, struct dirent *buf, size_t bufsize, uint32 *num) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; fs_node *n = NULL; fs_node *parent = node->parent; attr_entry *ae = NULL; int i; int count_indirect; - PRINT((PFS "read_attrdir(%ld, %Ld) @ %d\n", ns->nsid, node->vnid, cookie->dir_current)); + TRACE((PFS "read_attrdir(%ld, %Ld) @ %d\n", ns->nsid, node->vnid, cookie->dir_current)); if (!node || !cookie || !num || !*num || !buf || (bufsize < (sizeof(dirent_t)+GOOGLEFS_NAME_LEN))) return EINVAL; err = LOCK(&node->l); @@ -1027,7 +1012,7 @@ int googlefs_read_attrdir(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie *cook ae = &node->attrs[i]; if (ae) { - PRINT((PFS "read_attrdir: giving %s\n", ae->name)); + TRACE((PFS "read_attrdir: giving %s\n", ae->name)); buf->d_dev = ns->nsid; buf->d_pdev = ns->nsid; buf->d_ino = node->vnid; @@ -1051,14 +1036,15 @@ int googlefs_read_attrdir(fs_nspace *ns, fs_node *node, fs_attr_dir_cookie *cook */ /* for Haiku, but also used by BeOS calls to factorize code */ -int googlefs_open_attr_h(fs_nspace *ns, fs_node *node, const char *name, int omode, fs_file_cookie **cookie) +int googlefs_open_attr_h(fs_volume *_volume, fs_node *node, const char *name, int omode, fs_file_cookie **cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; fs_node *dummy; fs_file_cookie *fc; attr_entry *ae = NULL; int i; - PRINT((PFS"open_attr(%ld, %Ld, %s, 0x%x)\n", ns->nsid, node->vnid, name, omode)); + TRACE((PFS"open_attr(%ld, %Ld, %s, 0x%x)\n", ns->nsid, node->vnid, name, omode)); if (!node || !name || !cookie) return EINVAL; @@ -1110,10 +1096,11 @@ err_n_l: return err; } -int googlefs_close_attr_h(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie) +int googlefs_close_attr_h(fs_volume *_volume, fs_node *node, fs_file_cookie *cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err; - PRINT((PFS"close_attr(%ld, %Ld:%s)\n", ns->nsid, node->vnid, cookie->attr?cookie->attr->name:"?")); + TRACE((PFS"close_attr(%ld, %Ld:%s)\n", ns->nsid, node->vnid, cookie->attr?cookie->attr->name:"?")); if (!ns || !node || !cookie) return EINVAL; err = LOCK(&node->l); @@ -1127,10 +1114,11 @@ err_n_l: return err; } -int googlefs_free_attr_cookie_h(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie) +int googlefs_free_attr_cookie_h(fs_volume *_volume, fs_node *node, fs_file_cookie *cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; - PRINT((PFS"free_attrcookie(%ld, %Ld:%s)\n", ns->nsid, node->vnid, cookie->attr?cookie->attr->name:"?")); + TRACE((PFS"free_attrcookie(%ld, %Ld:%s)\n", ns->nsid, node->vnid, cookie->attr?cookie->attr->name:"?")); err = LOCK(&node->l); if (err) return err; @@ -1144,13 +1132,12 @@ err_n_l: return err; } -#ifdef __HAIKU__ - -int googlefs_read_attr_stat_h(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie, struct stat *st) +int googlefs_read_attr_stat(fs_volume *_volume, fs_node *node, fs_file_cookie *cookie, struct stat *st) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; attr_entry *ae = cookie->attr; - PRINT((PFS"stat_attr(%ld, %Ld:%s)\n", ns->nsid, node->vnid, ae->name)); + TRACE((PFS"stat_attr(%ld, %Ld:%s)\n", ns->nsid, node->vnid, ae->name)); if (!node || !st || !cookie || !cookie->attr) return EINVAL; memcpy(st, &node->st, sizeof(struct stat)); @@ -1160,11 +1147,12 @@ int googlefs_read_attr_stat_h(fs_nspace *ns, fs_node *node, fs_file_cookie *cook return err; } -int googlefs_read_attr_h(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie, off_t pos, void *buf, size_t *len) +int googlefs_read_attr(fs_volume *_volume, fs_node *node, fs_file_cookie *cookie, off_t pos, void *buf, size_t *len) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; attr_entry *ae = cookie->attr; - PRINT((PFS"read_attr(%ld, %Ld:%s)\n", ns->nsid, node->vnid, ae->name)); + TRACE((PFS"read_attr(%ld, %Ld:%s)\n", ns->nsid, node->vnid, ae->name)); if (!node || !cookie || !len || !*len) return EINVAL; @@ -1184,94 +1172,13 @@ int googlefs_read_attr_h(fs_nspace *ns, fs_node *node, fs_file_cookie *cookie, o } -#else - -int googlefs_remove_attr_b(fs_nspace *ns, fs_node *node, const char *name) -{ - PRINT((PFS"%s()\n", __FUNCTION__)); - return ENOSYS; -} - -int googlefs_rename_attr_b(fs_nspace *ns, fs_node *node, const char *oldname, const char *newname) -{ - PRINT((PFS"%s()\n", __FUNCTION__)); - return ENOSYS; -} - -int googlefs_stat_attr_b(fs_nspace *ns, fs_node *node, const char *name, struct attr_info *buf) -{ - status_t err = B_OK; - attr_entry *ae = NULL; - int i; - PRINT((PFS"stat_attr(%ld, %Ld, %s)\n", ns->nsid, node->vnid, name)); - if (!node || !name || !buf) - return EINVAL; - err = LOCK(&node->l); - for (i = 0; node->attrs_indirect && !ae && node->attrs_indirect[i].name; i++) - if (!strcmp(name, node->attrs_indirect[i].name)) - ae = &node->attrs_indirect[i]; - for (i = 0; !ae && i < 10 && node->attrs[i].name; i++) - if (!strcmp(name, node->attrs[i].name)) - ae = &node->attrs[i]; - - if (ae) { - buf->type = ae->type; - buf->size = ae->size; - err = B_OK; - } else - err = ENOENT; - - UNLOCK(&node->l); - return err; -} - -int googlefs_write_attr_b(fs_nspace *ns, fs_node *node, const char *name, int type, - const void *buf, size_t *len, off_t pos) -{ - PRINT((PFS"%s()\n", __FUNCTION__)); - *len = 0; - return ENOSYS; -} - -int googlefs_read_attr_b(fs_nspace *ns, fs_node *node, const char *name, int type, - void *buf, size_t *len, off_t pos) -{ - status_t err = B_OK; - attr_entry *ae = NULL; - int i; - PRINT((PFS"read_attr(%ld, %Ld, %s, 0x%08lx)\n", ns->nsid, node->vnid, name, type)); - if (!node || !name || !len || !*len) - return EINVAL; - err = LOCK(&node->l); - for (i = 0; node->attrs_indirect && !ae && node->attrs_indirect[i].name; i++) - if (!strcmp(name, node->attrs_indirect[i].name)) - ae = &node->attrs_indirect[i]; - for (i = 0; !ae && i < 10 && node->attrs[i].name; i++) - if (!strcmp(name, node->attrs[i].name)) - ae = &node->attrs[i]; - - if (ae && ae->type == type && pos < ae->size) { - memcpy(buf, (char *)ae->value + pos, MIN(*len, ae->size-pos)); - *len = MIN(*len, ae->size-pos); - err = B_OK; - } else { - *len = 0; - err = ENOENT; - } - - UNLOCK(&node->l); - return err; -} - -#endif - /* query stuff */ static int compare_fs_node_by_recent_query_string(fs_node *node, char *query) { time_t tm = time(NULL); //return memcmp(node->name, name, GOOGLEFS_NAME_LEN); - PRINT((PFS"find_by_recent_query_string: '%s' <> '%s'\n", \ + TRACE((PFS"find_by_recent_query_string: '%s' <> '%s'\n", \ node->request?node->request->query_string:NULL, query)); if (!node->request || !node->request->query_string) return -1; @@ -1281,9 +1188,10 @@ static int compare_fs_node_by_recent_query_string(fs_node *node, char *query) return strcmp(node->request->query_string, query); } -int googlefs_open_query(fs_nspace *ns, const char *query, ulong flags, +int googlefs_open_query(fs_volume *_volume, const char *query, ulong flags, port_id port, long token, fs_query_cookie **cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; fs_query_cookie *c; fs_node *qn, *n, *dummy; @@ -1293,7 +1201,7 @@ int googlefs_open_query(fs_nspace *ns, const char *query, ulong flags, bool accepted = true; bool reused = false; int i; - PRINT((PFS"open_query(%ld, '%s', 0x%08lx, %ld, %ld)\n", ns->nsid, query, flags, port, token)); + TRACE((PFS"open_query(%ld, '%s', 0x%08lx, %ld, %ld)\n", ns->nsid, query, flags, port, token)); // if (flags & B_LIVE_QUERY) // return ENOSYS; /* no live query yet, they are live enough anyway */ //return ENOSYS; @@ -1338,7 +1246,7 @@ int googlefs_open_query(fs_nspace *ns, const char *query, ulong flags, *cookie = c; return B_OK; } - PRINT((PFS"open_query: QUERY: '%s'\n", qstring)); + TRACE((PFS"open_query: QUERY: '%s'\n", qstring)); /* reuse query if it's not too old */ LOCK(&ns->l); qn = SLL_FIND(ns->queries, qnext, @@ -1346,7 +1254,7 @@ int googlefs_open_query(fs_nspace *ns, const char *query, ulong flags, UNLOCK(&ns->l); reused = (qn != NULL); if (reused) { - PRINT((PFS"open_query: reusing %ld:%Ld\n", ns->nsid, qn->vnid)); + TRACE((PFS"open_query: reusing %ld:%Ld\n", ns->nsid, qn->vnid)); err = get_vnode(ns->nsid, qn->vnid, (void **)&dummy); /* inc ref count */ if (err) goto err_mkdir; @@ -1366,7 +1274,7 @@ int googlefs_open_query(fs_nspace *ns, const char *query, ulong flags, strcpy(p, p + 1); /* should get/put_vnode(ns->root); around that I think... */ - err = googlefs_create_gen(ns, ns->root, qname, 0, 0755, NULL, &qn, folders_attrs, true, true); + err = googlefs_create_gen(_volume, ns->root, qname, 0, 0755, NULL, &qn, folders_attrs, true, true); if (err) goto err_qs; @@ -1377,28 +1285,28 @@ int googlefs_open_query(fs_nspace *ns, const char *query, ulong flags, //#ifndef NO_SEARCH /* let's ask google */ - err = google_request_open(qstring, ns, qn, &qn->request); + err = google_request_open(qstring, _volume, qn, &qn->request); if (err) goto err_gn; - PRINT((PFS"open_query: request_open done\n")); + TRACE((PFS"open_query: request_open done\n")); #ifndef NO_SEARCH err = google_request_process(qn->request); if (err) goto err_gro; - PRINT((PFS"open_query: request_process done\n")); + TRACE((PFS"open_query: request_process done\n")); #else /* fake entries */ for (i = 0; i < 10; i++) { - err = googlefs_create_gen(ns, qn, "B", 0, 0644, NULL, &n, fake_bookmark_attrs, false, true); + err = googlefs_create_gen(_volume, qn, "B", 0, 0644, NULL, &n, fake_bookmark_attrs, false, true); /* fake that to test sorting */ *(int32 *)&n->attrs[1].value = i + 1; // hack n->attrs[0].type = 'LONG'; n->attrs[0].value = &n->attrs[1].value; n->attrs[0].size = sizeof(int32); n->attrs[0].name = "GOOGLE:order"; - notify_listener(B_ATTR_CHANGED, ns->nsid, 0, 0, n->vnid, n->attrs[0].name); + notify_attribute_changed(ns->nsid, n->vnid, n->attrs[0].name, B_ATTR_CHANGED); if (err) goto err_gn; } @@ -1433,15 +1341,16 @@ err_qs: free(qstring); err_m: free(c); - PRINT((PFS"open_query: error 0x%08lx\n", err)); + TRACE((PFS"open_query: error 0x%08lx\n", err)); return err; } -int googlefs_close_query(fs_nspace *ns, fs_query_cookie *cookie) +int googlefs_close_query(fs_volume *_volume, fs_query_cookie *cookie) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err; fs_node *q, *n; - PRINT((PFS"close_query(%ld, %Ld)\n", ns->nsid, cookie->node?cookie->node->vnid:0LL)); + TRACE((PFS"close_query(%ld, %Ld)\n", ns->nsid, cookie->node?cookie->node->vnid:0LL)); //return ENOSYS; q = cookie->node; if (!q) @@ -1462,25 +1371,22 @@ int googlefs_close_query(fs_nspace *ns, fs_query_cookie *cookie) #ifdef __HAIKU__ /* protos are different... */ -int googlefs_free_query_cookie(fs_nspace *ns, fs_dir_cookie *cookie) +int googlefs_free_query_cookie(fs_volume *_volume, fs_dir_cookie *cookie) { - PRINT((PFS"free_query_cookie(%ld)\n", ns->nsid)); + TRACE((PFS"free_query_cookie(%ld)\n", ns->nsid)); free(cookie); return B_OK; } #endif -#ifdef __HAIKU__ -int googlefs_read_query(fs_nspace *ns, fs_query_cookie *cookie, struct dirent *buf, size_t bufsize, uint32 *num) -#else -int googlefs_read_query(fs_nspace *ns, fs_query_cookie *cookie, long *num, struct dirent *buf, size_t bufsize) -#endif +int googlefs_read_query(fs_volume *_volume, fs_query_cookie *cookie, struct dirent *buf, size_t bufsize, uint32 *num) { + fs_nspace *ns = (fs_nspace *)_volume->private_volume; status_t err = B_OK; fs_node *n = NULL; fs_node *node = cookie->node; int index; - PRINT((PFS"read_query(%ld, %Ld) @ %d\n", ns->nsid, node?node->vnid:0LL, cookie->dir_current)); + TRACE((PFS"read_query(%ld, %Ld) @ %d\n", ns->nsid, node?node->vnid:0LL, cookie->dir_current)); if (!cookie || !num || !*num || !buf || (bufsize < (sizeof(dirent_t)+GOOGLEFS_NAME_LEN))) return EINVAL; if (!node) { @@ -1493,7 +1399,7 @@ int googlefs_read_query(fs_nspace *ns, fs_query_cookie *cookie, long *num, struc index = cookie->dir_current; for (n = node->children; n && index; n = n->next, index--); if (n) { - PRINT((PFS "read_query: giving ino %Ld, %s\n", n->vnid, n->name)); + TRACE((PFS "read_query: giving ino %Ld, %s\n", n->vnid, n->name)); buf->d_dev = ns->nsid; buf->d_pdev = ns->nsid; buf->d_ino = n->vnid; @@ -1512,13 +1418,14 @@ int googlefs_read_query(fs_nspace *ns, fs_query_cookie *cookie, long *num, struc int googlefs_push_result_to_query(struct google_request *request, struct google_result *result) { status_t err = B_OK; - fs_nspace *ns = request->ns; + fs_volume *_volume = request->volume; + fs_nspace *ns = (fs_nspace *)_volume->private_volume; fs_node *qn = request->query_node; fs_node *n, *dummy; char ename[GOOGLEFS_NAME_LEN]; char *p; int i; - PRINT((PFS"push_result_to_query(%ld, %Ld, %d:'%s')\n", ns->nsid, qn->vnid, result->id, result->name)); + TRACE((PFS"push_result_to_query(%ld, %Ld, %d:'%s')\n", ns->nsid, qn->vnid, result->id, result->name)); //dprintf(PFS"push_result_to_query(%ld, %Ld, %d:'%s')\n", ns->nsid, qn->vnid, result->id, result->name); //return ENOSYS; if (!ns || !qn) @@ -1534,7 +1441,7 @@ int googlefs_push_result_to_query(struct google_request *request, struct google_ while ((p = strchr(p, '/'))) *p++ = '_'; - err = googlefs_create_gen(ns, qn, ename, 0, 0644, NULL, &n, bookmark_attrs, false, true); + err = googlefs_create_gen(_volume, qn, ename, 0, 0644, NULL, &n, bookmark_attrs, false, true); if (err) return err; LOCK(&n->l); @@ -1544,32 +1451,32 @@ int googlefs_push_result_to_query(struct google_request *request, struct google_ n->attrs[i].value = result->name; n->attrs[i].size = strlen(result->name)+1; n->attrs[i].name = "META:title"; - notify_listener(B_ATTR_CHANGED, ns->nsid, 0, 0, n->vnid, n->attrs[i].name); + notify_attribute_changed(ns->nsid, n->vnid, n->attrs[i].name, B_ATTR_CREATED); i++; n->attrs[i].type = 'CSTR'; n->attrs[i].value = result->url; n->attrs[i].size = strlen(result->url)+1; n->attrs[i].name = "META:url"; - notify_listener(B_ATTR_CHANGED, ns->nsid, 0, 0, n->vnid, n->attrs[i].name); + notify_attribute_changed(ns->nsid, n->vnid, n->attrs[i].name, B_ATTR_CREATED); i++; n->attrs[i].type = 'CSTR'; n->attrs[i].value = request->query_string; n->attrs[i].size = strlen(request->query_string)+1; n->attrs[i].name = "META:keyw"; - notify_listener(B_ATTR_CHANGED, ns->nsid, 0, 0, n->vnid, n->attrs[i].name); + notify_attribute_changed(ns->nsid, n->vnid, n->attrs[i].name, B_ATTR_CREATED); i++; n->attrs[i].type = 'LONG'; n->attrs[i].value = &result->id; n->attrs[i].size = sizeof(int32); n->attrs[i].name = "GOOGLE:order"; - notify_listener(B_ATTR_CHANGED, ns->nsid, 0, 0, n->vnid, n->attrs[i].name); + notify_attribute_changed(ns->nsid, n->vnid, n->attrs[i].name, B_ATTR_CREATED); i++; if (result->snipset[0]) { n->attrs[i].type = 'CSTR'; n->attrs[i].value = result->snipset; n->attrs[i].size = strlen(result->snipset)+1; n->attrs[i].name = "GOOGLE:excerpt"; - notify_listener(B_ATTR_CHANGED, ns->nsid, 0, 0, n->vnid, n->attrs[i].name); + notify_attribute_changed(ns->nsid, n->vnid, n->attrs[i].name, B_ATTR_CREATED); i++; } if (result->cache_url[0]) { @@ -1577,7 +1484,7 @@ int googlefs_push_result_to_query(struct google_request *request, struct google_ n->attrs[i].value = result->cache_url; n->attrs[i].size = strlen(result->cache_url)+1; n->attrs[i].name = "GOOGLE:cache_url"; - notify_listener(B_ATTR_CHANGED, ns->nsid, 0, 0, n->vnid, n->attrs[i].name); + notify_attribute_changed(ns->nsid, n->vnid, n->attrs[i].name, B_ATTR_CREATED); i++; } if (result->similar_url[0]) { @@ -1585,37 +1492,35 @@ int googlefs_push_result_to_query(struct google_request *request, struct google_ n->attrs[i].value = result->similar_url; n->attrs[i].size = strlen(result->similar_url)+1; n->attrs[i].name = "GOOGLE:similar_url"; - notify_listener(B_ATTR_CHANGED, ns->nsid, 0, 0, n->vnid, n->attrs[i].name); + notify_attribute_changed(ns->nsid, n->vnid, n->attrs[i].name, B_ATTR_CREATED); i++; } UNLOCK(&n->l); return B_OK; err: - PRINT((PFS"push_result_to_query: error 0x%08lx\n", err)); + TRACE((PFS"push_result_to_query: error 0x%08lx\n", err)); return err; } // #pragma mark - -#ifdef __HAIKU__ - static status_t googlefs_std_ops(int32 op, ...) { switch (op) { case B_MODULE_INIT: - PRINT((PFS"std_ops(INIT)\n")); + TRACE((PFS"std_ops(INIT)\n")); return B_OK; case B_MODULE_UNINIT: - PRINT((PFS"std_ops(UNINIT)\n")); + TRACE((PFS"std_ops(UNINIT)\n")); return B_OK; default: return B_ERROR; } } - +#if 0 static file_system_module_info sGoogleFSModule = { { "file_systems/googlefs" B_CURRENT_FS_API_VERSION, @@ -1726,80 +1631,130 @@ static file_system_module_info sGoogleFSModule = { NULL, // &googlefs_rewind_query, }; +#endif + +static fs_volume_ops sGoogleFSVolumeOps = { + &googlefs_unmount, + &googlefs_rfsstat, + &googlefs_wfsstat, + NULL, // no sync! + &googlefs_read_vnode, + + /* index directory & index operations */ + NULL, // &googlefs_open_index_dir + NULL, // &googlefs_close_index_dir + NULL, // &googlefs_free_index_dir_cookie + NULL, // &googlefs_read_index_dir + NULL, // &googlefs_rewind_index_dir + + NULL, // &googlefs_create_index + NULL, // &googlefs_remove_index + NULL, // &googlefs_stat_index + + /* query operations */ + NULL, // &googlefs_open_query, + NULL, // &googlefs_close_query, + NULL, // &googlefs_free_query_cookie, + NULL, // &googlefs_read_query, + NULL, // &googlefs_rewind_query, +}; + + +static fs_vnode_ops sGoogleFSVnodeOps = { + /* vnode operations */ + &googlefs_walk, + NULL, // fs_get_vnode_name + &googlefs_release_vnode, + &googlefs_remove_vnode, + + /* VM file access */ + NULL, // &googlefs_can_page + NULL, // &googlefs_read_pages + NULL, // &googlefs_write_pages + + NULL, // io() + NULL, // cancel_io() + + NULL, // &googlefs_get_file_map, + + NULL, // &googlefs_ioctl + NULL, // &googlefs_setflags, + NULL, // &googlefs_select + NULL, // &googlefs_deselect + NULL, // &googlefs_fsync + + NULL, // &googlefs_readlink, + NULL, // &googlefs_symlink, + + NULL, // &googlefs_link, + &googlefs_unlink, + NULL, // &googlefs_rename, + + &googlefs_access, + &googlefs_rstat, + &googlefs_wstat, + + /* file operations */ + &googlefs_create, + &googlefs_open, + &googlefs_close, + &googlefs_free_cookie, + &googlefs_read, + &googlefs_write, + + /* directory operations */ + &googlefs_mkdir, + &googlefs_rmdir, + &googlefs_opendir, + &googlefs_closedir, + &googlefs_free_dircookie, + &googlefs_readdir, + &googlefs_rewinddir, + + /* attribute directory operations */ + NULL, // &googlefs_open_attrdir, + NULL, // &googlefs_close_attrdir, + NULL, // &googlefs_free_attrdircookie, + NULL, // &googlefs_read_attrdir, + NULL, // &googlefs_rewind_attrdir, + + /* attribute operations */ + NULL, // &googlefs_create_attr + NULL, // &googlefs_open_attr_h, + NULL, // &googlefs_close_attr_h, + NULL, // &googlefs_free_attr_cookie_h, + NULL, // &googlefs_read_attr_h, + NULL, // &googlefs_write_attr_h, + + NULL, // &googlefs_read_attr_stat_h, + NULL, // &googlefs_write_attr_stat + NULL, // &googlefs_rename_attr + NULL, // &googlefs_remove_attr +}; + +file_system_module_info sGoogleFSModule = { + { + "file_systems/googlefs" B_CURRENT_FS_API_VERSION, + 0, + googlefs_std_ops, + }, + + "googlefs", // short_name + GOOGLEFS_PRETTY_NAME, // pretty_name + 0,//B_DISK_SYSTEM_SUPPORTS_WRITING, // DDM flags + + // scanning + NULL, // fs_identify_partition, + NULL, // fs_scan_partition, + NULL, // fs_free_identify_partition_cookie, + NULL, // free_partition_content_cookie() + + &googlefs_mount, +}; + module_info *modules[] = { (module_info *)&sGoogleFSModule, NULL, }; -#else /* BeOS fsil api */ - -_EXPORT vnode_ops fs_entry = -{ - (op_read_vnode *)&googlefs_read_vnode, - (op_write_vnode *)&googlefs_write_vnode, - (op_remove_vnode *)&googlefs_remove_vnode, - (op_secure_vnode *)&googlefs_secure_vnode, - (op_walk *)&googlefs_walk, - (op_access *)&googlefs_access, - (op_create *)&googlefs_create, - (op_mkdir *)&googlefs_mkdir, - NULL, //(op_symlink *)&googlefs_symlink, - NULL, // &googlefs_link, - NULL, //(op_rename *)&googlefs_rename, - (op_unlink *)&googlefs_unlink, - (op_rmdir *)&googlefs_rmdir, - NULL, //(op_readlink *)&googlefs_readlink, - (op_opendir *)&googlefs_opendir, - (op_closedir *)&googlefs_closedir, - (op_free_cookie *)&googlefs_free_dircookie, - (op_rewinddir *)&googlefs_rewinddir, - (op_readdir *)&googlefs_readdir, - (op_open *)&googlefs_open, - (op_close *)&googlefs_close, - (op_free_cookie *)&googlefs_free_cookie, - (op_read *)&googlefs_read, - (op_write *)&googlefs_write, - NULL, // &googlefs_readv, - NULL, // &googlefs_writev, - NULL, // &googlefs_ioctl, - (op_setflags *)&googlefs_setflags, - (op_rstat *)&googlefs_rstat, - (op_wstat *)&googlefs_wstat, - NULL, // &googlefs_fsync, - NULL, // &googlefs_initialize, - (op_mount *)&googlefs_mount, - (op_unmount *)&googlefs_unmount, - NULL, // &googlefs_sync, - (op_rfsstat *)&googlefs_rfsstat, - (op_wfsstat *)&googlefs_wfsstat, - NULL, // &googlefs_select, - NULL, // &googlefs_deselect, - NULL, // &googlefs_open_indexdir, - NULL, // &googlefs_close_indexdir, - NULL, // &googlefs_free_indexdircookie, - NULL, // &googlefs_rewind_indexdir, - NULL, // &googlefs_read_indexdir, - NULL, // &googlefs_create_index, - NULL, // &googlefs_remove_index, - NULL, // &googlefs_rename_index, - NULL, // &googlefs_stat_index, - (op_open_attrdir *)&googlefs_open_attrdir, - (op_close_attrdir *)&googlefs_close_attrdir, - (op_free_cookie *)&googlefs_free_attrdircookie, - (op_rewind_attrdir *)&googlefs_rewind_attrdir, - (op_read_attrdir *)&googlefs_read_attrdir, - (op_write_attr *)&googlefs_write_attr_b, - (op_read_attr *)&googlefs_read_attr_b, - (op_remove_attr *)&googlefs_remove_attr_b, - (op_rename_attr *)&googlefs_rename_attr_b, - (op_stat_attr *)&googlefs_stat_attr_b, - (op_open_query *)&googlefs_open_query, - (op_close_query *)&googlefs_close_query, - (op_free_cookie *)&googlefs_free_dircookie,//&googlefs_free_querycookie, - (op_read_query *)&googlefs_read_query -}; - -_EXPORT int32 api_version=B_CUR_FS_API_VERSION; - -#endif diff --git a/src/add-ons/kernel/file_systems/googlefs/googlefs.h b/src/add-ons/kernel/file_systems/googlefs/googlefs.h index 2aaef36567..74db685714 100644 --- a/src/add-ons/kernel/file_systems/googlefs/googlefs.h +++ b/src/add-ons/kernel/file_systems/googlefs/googlefs.h @@ -124,7 +124,7 @@ typedef struct fs_file_cookie fs_file_cookie; #define fs_query_cookie fs_file_cookie ino_t new_vnid(fs_nspace *ns); -int googlefs_free_vnode(fs_nspace *ns, fs_node *node); +int googlefs_free_vnode(fs_volume *_volume, fs_node *node); int googlefs_event(fs_nspace *ns, fs_node *node, int flags); diff --git a/src/add-ons/kernel/file_systems/googlefs/http_cnx.h b/src/add-ons/kernel/file_systems/googlefs/http_cnx.h index c23990a91d..8267c59a06 100644 --- a/src/add-ons/kernel/file_systems/googlefs/http_cnx.h +++ b/src/add-ons/kernel/file_systems/googlefs/http_cnx.h @@ -5,6 +5,8 @@ #ifndef _HTTP_CNX_H #define _HTTP_CNX_H +#include + struct http_cnx { int sock; status_t err; /* 404, ... */ diff --git a/src/add-ons/kernel/file_systems/googlefs/vnidpool.c b/src/add-ons/kernel/file_systems/googlefs/vnidpool.c index e3a33d24fc..61129e03c0 100644 --- a/src/add-ons/kernel/file_systems/googlefs/vnidpool.c +++ b/src/add-ons/kernel/file_systems/googlefs/vnidpool.c @@ -28,10 +28,7 @@ status_t vnidpool_alloc(struct vnidpool **pool, size_t size) p = malloc(sizeof(struct vnidpool) + size / sizeof(BMT)); if (!p) return B_NO_MEMORY; - if (new_lock(&p->lock, "vnidpool lock") < B_OK) { - free(p); - return B_NO_MEMORY; - } + new_lock(&p->lock, "vnidpool lock"); p->nextvnid = 1LL; p->bitmap = (BMT *)(p + 1); p->bmsize = size;