- ret = nfs_close(nfs, nfsfh);
- if (ret < 0) {
- printf("Failed to close(%s) %s\n", NFSFILEW, nfs_get_error(nfs));
- exit(10);
- }
-
-
- ret = nfs_statvfs(nfs, NFSDIR, &svfs);
- if (ret < 0) {
- printf("Failed to statvfs(%s) %s\n", NFSDIR, nfs_get_error(nfs));
- exit(10);
- }
- printf("files %d/%d/%d\n", (int)svfs.f_files, (int)svfs.f_ffree, (int)svfs.f_favail);
-
-
- ret = nfs_access(nfs, NFSFILE, R_OK);
- if (ret != 0) {
- printf("Failed to access(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+ while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) {
+ char path[1024];
+
+ if (!strcmp(nfsdirent->name, ".") || !strcmp(nfsdirent->name, "..")) {
+ continue;
+ }
+
+ snprintf(path, 1024, "%s/%s", "/", nfsdirent->name);
+ ret = nfs_stat(nfs, path, &st);
+ if (ret != 0) {
+ fprintf(stderr, "Failed to stat(%s) %s\n", path, nfs_get_error(nfs));
+ continue;
+ }
+
+ switch (st.st_mode & S_IFMT) {
+ case S_IFLNK:
+ case S_IFREG:
+ printf("-");
+ break;
+ case S_IFDIR:
+ printf("d");
+ break;
+ case S_IFCHR:
+ printf("c");
+ break;
+ case S_IFBLK:
+ printf("b");
+ break;
+ }
+ printf("%c%c%c",
+ "-r"[!!(st.st_mode & S_IRUSR)],
+ "-w"[!!(st.st_mode & S_IWUSR)],
+ "-x"[!!(st.st_mode & S_IXUSR)]
+ );
+ printf("%c%c%c",
+ "-r"[!!(st.st_mode & S_IRGRP)],
+ "-w"[!!(st.st_mode & S_IWGRP)],
+ "-x"[!!(st.st_mode & S_IXGRP)]
+ );
+ printf("%c%c%c",
+ "-r"[!!(st.st_mode & S_IROTH)],
+ "-w"[!!(st.st_mode & S_IWOTH)],
+ "-x"[!!(st.st_mode & S_IXOTH)]
+ );
+ printf(" %2d", st.st_nlink);
+ printf(" %5d", st.st_uid);
+ printf(" %5d", st.st_gid);
+ printf(" %12" PRId64, st.st_size);
+
+ printf(" %s\n", nfsdirent->name);