diff options
author | Jeff Garzik <jeff@garzik.org> | 2006-04-23 01:19:05 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2006-04-23 01:19:05 -0400 |
commit | 0f905a875db0136b01a6ac444e06d1f24cecb647 (patch) | |
tree | 0e90ec69218837687a13099375da43d83affb3e2 | |
parent | 820cede9cebaacf9ada47e66b7df45a13f6012cf (diff) | |
download | dbfs-0f905a875db0136b01a6ac444e06d1f24cecb647.tar.gz |
Implement readlink operation, pprefix() helper.
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | dbfs.c | 64 |
2 files changed, 53 insertions, 13 deletions
diff --git a/Makefile.am b/Makefile.am index 1188254..913e3cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = @GNET_CFLAGS@ @FUSE_CFLAGS@ sbin_PROGRAMS = dbfs dbfs_SOURCES = dbfs.c -dbfs_LDADD = @GNET_LIBS@ @FUSE_LIBS@ @DB_LIBS@ +dbfs_LDADD = @GNET_LIBS@ @FUSE_LIBS@ EXTRA_DIST = autogen.sh @@ -28,6 +28,20 @@ struct ndb_val { unsigned int len; }; +static gchar *pprefix(const char *pfx, const char *path_in) +{ + gchar *path, *s; + + path = g_strdup(path_in); + while ((*path) && (path[strlen(path) - 1] == '/')) + path[strlen(path) - 1] = 0; + + s = g_strdup_printf("%s%s", pfx, path); + + g_free(path); + return s; +} + static void ndb_free(struct ndb_val *val) { /* TODO */ @@ -40,21 +54,20 @@ static int ndb_lookup(const char *path, struct ndb_val **val) return -ENOMEM; } -static int ndb_lookup_data(const char *path, size_t size, off_t offset, - struct ndb_val **val) +static int dfs_fill_stat(struct stat *stbuf, struct ndb_val *val) { /* TODO */ - *val = NULL; - return -ENOMEM; + return -EIO; } -static int dfs_fill_stat(struct stat *stbuf, struct ndb_val *val) +static int dfs_fill_dir(fuse_fill_dir_t filler, struct ndb_val *val) { /* TODO */ return -EIO; } -static int dfs_fill_dir(fuse_fill_dir_t filler, struct ndb_val *val) +static int dfs_fill_data(char *buf, size_t size, off_t offset, + struct ndb_val *val) { /* TODO */ return -EIO; @@ -68,7 +81,7 @@ static int dfs_getattr(const char *path, struct stat *stbuf) memset(stbuf, 0, sizeof(struct stat)); - nspath = g_strdup_printf("/meta/%s", path); + nspath = pprefix("/meta", path); rc = ndb_lookup(nspath, &val); if (rc) goto out; @@ -82,6 +95,26 @@ out: return rc; } +static int dfs_readlink(const char *path, char *buf, size_t size) +{ + int rc = -ENOENT; + struct ndb_val *val = NULL; + char *nspath; + + nspath = pprefix("/symlink", path); + rc = ndb_lookup(nspath, &val); + if (rc) + goto out; + + memcpy(buf, val->data, size < val->len ? size : val->len); + + ndb_free(val); + +out: + g_free(nspath); + return rc; +} + static int dfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { @@ -89,7 +122,7 @@ static int dfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, char *nspath; int rc; - nspath = g_strdup_printf("/dir/%s", path); + nspath = pprefix("/dir", path); rc = ndb_lookup(nspath, &val); if (rc) { if (rc == -ENOENT) @@ -113,19 +146,26 @@ static int dfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { struct ndb_val *val = NULL; - int rc; + char *nspath; + int rc = 0; - rc = ndb_lookup_data(path, size, offset, &val); + nspath = pprefix("/data", path); + rc = ndb_lookup(path, &val); if (rc) - return rc; + goto out; + + rc = dfs_fill_data(buf, size, offset, val); ndb_free(val); - return 0; +out: + g_free(nspath); + return rc; } static const struct fuse_operations dfs_ops = { .getattr = dfs_getattr, + .readlink = dfs_readlink, .read = dfs_read, .readdir = dfs_readdir, }; |