From: Michael Vrable Date: Sun, 23 Aug 2009 19:44:46 +0000 (-0700) Subject: Basic READDIR; not much tested. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=e1fcdf3f1a7a2de0289526a5481009c3380f7547;p=bluesky.git Basic READDIR; not much tested. --- diff --git a/bluesky.h b/bluesky.h index 40c989b..75ba2de 100644 --- a/bluesky.h +++ b/bluesky.h @@ -81,6 +81,7 @@ typedef struct { uint64_t inum; } BlueSkyDirent ; +BlueSkyFS *bluesky_new_fs(gchar *name); int64_t bluesky_get_current_time(); uint64_t bluesky_fs_alloc_inode(BlueSkyFS *fs); BlueSkyInode *bluesky_new_inode(uint64_t inum, BlueSkyFileType type); diff --git a/dir.c b/dir.c index eab71be..f8aef94 100644 --- a/dir.c +++ b/dir.c @@ -43,8 +43,8 @@ void bluesky_dirent_destroy(gpointer data) g_free(dirent); } -static gint bluesky_dirent_compare(gconstpointer a, gconstpointer b, - gpointer unused) +gint bluesky_dirent_compare(gconstpointer a, gconstpointer b, + gpointer unused) { /* We can't simply subtract the hash values, since they are 64-bit and the * result could overflow when converted to a gint. */ diff --git a/nfs3/nfs3.c b/nfs3/nfs3.c index 242875f..f13a6f2 100644 --- a/nfs3/nfs3.c +++ b/nfs3/nfs3.c @@ -149,7 +149,17 @@ nfsproc3_access_3_svc(access3args *argp, struct svc_req *rqstp) { static access3res result; - result.status = NFS3ERR_NOTSUPP; + BlueSkyInode *inode = lookup_fh(&argp->object); + if (inode == NULL) { + result.status = NFS3ERR_STALE; + result.access3res_u.resfail.present = FALSE; + return &result; + } + + result.status = NFS3_OK; + result.access3res_u.resok.obj_attributes.present = TRUE; + encode_fattr3(&result.access3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode); + result.access3res_u.resok.access = argp->access; return &result; } @@ -264,12 +274,53 @@ nfsproc3_link_3_svc(link3args *argp, struct svc_req *rqstp) return &result; } +gint bluesky_dirent_compare(gconstpointer a, gconstpointer b, + gpointer unused); + readdir3res * nfsproc3_readdir_3_svc(readdir3args *argp, struct svc_req *rqstp) { static readdir3res result; - result.status = NFS3ERR_NOTSUPP; + BlueSkyInode *dir = lookup_fh(&argp->dir); + if (dir == NULL) { + result.status = NFS3ERR_STALE; + result.readdir3res_u.resfail.present = FALSE; + return &result; + } + + result.status = NFS3_OK; + result.readdir3res_u.resok.dir_attributes.present = TRUE; + encode_fattr3(&result.readdir3res_u.resok.dir_attributes.post_op_attr_u.attributes, dir); + memset(result.readdir3res_u.resok.cookieverf, 0, + sizeof(result.readdir3res_u.resok.cookieverf)); + +#define MAX_READDIR_DIRENTS 4 + static entry3 dirents[MAX_READDIR_DIRENTS]; + int count = 0; + + BlueSkyDirent start = {NULL, argp->cookie, 0}; + GSequenceIter *i = g_sequence_search(dir->dirents, &start, + bluesky_dirent_compare, NULL); + + while (count < MAX_READDIR_DIRENTS && !g_sequence_iter_is_end(i)) { + BlueSkyDirent *d = g_sequence_get(i); + dirents[count].fileid = d->inum; + dirents[count].name = d->name; + dirents[count].cookie = d->hash; + dirents[count].nextentry = NULL; + if (count > 0) + dirents[count - 1].nextentry = &dirents[count]; + i = g_sequence_iter_next(i); + count++; + printf("readdir: %s %lld\n", d->name, d->inum); + } + + if (count > 0) + result.readdir3res_u.resok.reply.entries = &dirents[0]; + else + result.readdir3res_u.resok.reply.entries = NULL; + result.readdir3res_u.resok.reply.eof = g_sequence_iter_is_end(i); return &result; } diff --git a/nfs3/nfsd.c b/nfs3/nfsd.c index 03b39fb..abd1050 100644 --- a/nfs3/nfsd.c +++ b/nfs3/nfsd.c @@ -30,14 +30,22 @@ int main(int argc, char *argv[]) g_thread_init(NULL); register_rpc(); + fs = bluesky_new_fs("export"); + BlueSkyInode *root; root = bluesky_new_inode(BLUESKY_ROOT_INUM, BLUESKY_DIRECTORY); root->nlink = 1; root->mode = 0755; bluesky_insert_inode(fs, root); - svc_run (); - fprintf (stderr, "%s", "svc_run returned"); - exit (1); - /* NOTREACHED */ + BlueSkyInode *file; + file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), BLUESKY_REGULAR); + file->nlink = 1; + file->mode = 0755; + bluesky_insert_inode(fs, file); + bluesky_directory_insert(root, "demo", file->inum); + + svc_run(); + fprintf(stderr, "%s", "svc_run returned"); + exit(1); }