+ fprintf(stderr, "Usage: nfs-ls [-?|--help|--usage] [-R|--recursive] [-s|--summary] <url>\n");
+}
+
+void process_dir(struct nfs_context *nfs, char *dir, int level) {
+ int ret;
+ struct nfsdirent *nfsdirent;
+ struct statvfs svfs;
+ struct nfsdir *nfsdir;
+ struct stat st;
+
+ if (!level) {
+ printf("Recursion detected!\n");
+ exit(10);
+ }
+
+ ret = nfs_opendir(nfs, dir, &nfsdir);
+ if (ret != 0) {
+ printf("Failed to opendir(\"%s\")\n", dir, nfs_get_error(nfs));
+ exit(10);
+ }
+ while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) {
+ char path[1024];
+
+ if (!strcmp(nfsdirent->name, ".") || !strcmp(nfsdirent->name, "..")) {
+ continue;
+ }
+
+ snprintf(path, 1024, "%s/%s", dir, 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) {
+#ifndef WIN32
+ case S_IFLNK:
+ printf("l");
+ break;
+#endif
+ 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", (int) st.st_nlink);
+ printf(" %5d", st.st_uid);
+ printf(" %5d", st.st_gid);
+ printf(" %12" PRId64, st.st_size);
+
+ printf(" %s\n", path + 1);
+
+ if (recursive && (st.st_mode & S_IFMT) == S_IFDIR) {
+ process_dir(nfs, path, level - 1);
+ }
+ }
+ nfs_closedir(nfs, nfsdir);