libnfs.c: add nlink to nfsdirent so we can get it for 'free'
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Sun, 8 Jun 2014 18:40:35 +0000 (11:40 -0700)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Sun, 8 Jun 2014 18:40:35 +0000 (11:40 -0700)
update the nfs-ls utility to just use nfsdirent as is instead of having to
stat the files.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
include/nfsc/libnfs.h
lib/libnfs.c
utils/nfs-ls.c

index d960f7f60d72f6ed61f5107fafd07902ad74ec60..b6cb806dac48b7b1a8967533f5d8fd2644158888 100644 (file)
@@ -781,6 +781,7 @@ struct nfsdirent  {
        struct timeval ctime;
        uint32_t uid;
        uint32_t gid;
+       uint32_t nlink;
 };
 /*
  * nfs_readdir() never blocks, so no special sync/async versions are available
index 1328aed1cf81278e37163003f66e8f87c4e15a66..30719ab562809cb59172cf5cd3b6b2434d0bffa3 100644 (file)
@@ -2861,6 +2861,7 @@ static void nfs_opendir3_cb(struct rpc_context *rpc, int status, void *command_d
                        nfsdirent->ctime.tv_usec = attributes->ctime.nseconds/1000;
                        nfsdirent->uid = attributes->uid;
                        nfsdirent->gid = attributes->gid;
+                       nfsdirent->nlink = attributes->nlink;
                }
        }
 
@@ -3101,6 +3102,7 @@ static void nfs_opendir_cb(struct rpc_context *rpc, int status, void *command_da
                        nfsdirent->ctime.tv_usec = entry->name_attributes.post_op_attr_u.attributes.ctime.nseconds/1000;
                        nfsdirent->uid = entry->name_attributes.post_op_attr_u.attributes.uid;
                        nfsdirent->gid = entry->name_attributes.post_op_attr_u.attributes.gid;
+                       nfsdirent->nlink = entry->name_attributes.post_op_attr_u.attributes.nlink;
                }
 
                nfsdirent->next  = nfsdir->entries;
index 974a6e16ec32fca2414d45cf43e0301293816e59..7653f56d9b6439981c8e1d4a6cdc5ed2e2e63d49 100644 (file)
@@ -91,7 +91,6 @@ void process_dir(struct nfs_context *nfs, char *dir, int level) {
        struct nfsdirent *nfsdirent;
        struct statvfs svfs;
        struct nfsdir *nfsdir;
-       struct nfs_stat_64 st;
        
        if (!level) {
                printf("Recursion detected!\n");
@@ -109,15 +108,9 @@ void process_dir(struct nfs_context *nfs, char *dir, int level) {
                if (!strcmp(nfsdirent->name, ".") || !strcmp(nfsdirent->name, "..")) {
                        continue;
                }
-
                snprintf(path, 1024, "%s/%s", dir, nfsdirent->name);
-               ret = nfs_stat64(nfs, path, &st);
-               if (ret != 0) {
-                       fprintf(stderr, "Failed to stat(%s) %s\n", path, nfs_get_error(nfs));
-                       continue;
-               }
 
-               switch (st.nfs_mode & S_IFMT) {
+               switch (nfsdirent->mode & S_IFMT) {
 #ifndef WIN32
                case S_IFLNK:
                        printf("l");
@@ -137,28 +130,28 @@ void process_dir(struct nfs_context *nfs, char *dir, int level) {
                        break;
                }
                printf("%c%c%c",
-                       "-r"[!!(st.nfs_mode & S_IRUSR)],
-                       "-w"[!!(st.nfs_mode & S_IWUSR)],
-                       "-x"[!!(st.nfs_mode & S_IXUSR)]
+                       "-r"[!!(nfsdirent->mode & S_IRUSR)],
+                       "-w"[!!(nfsdirent->mode & S_IWUSR)],
+                       "-x"[!!(nfsdirent->mode & S_IXUSR)]
                );
                printf("%c%c%c",
-                       "-r"[!!(st.nfs_mode & S_IRGRP)],
-                       "-w"[!!(st.nfs_mode & S_IWGRP)],
-                       "-x"[!!(st.nfs_mode & S_IXGRP)]
+                       "-r"[!!(nfsdirent->mode & S_IRGRP)],
+                       "-w"[!!(nfsdirent->mode & S_IWGRP)],
+                       "-x"[!!(nfsdirent->mode & S_IXGRP)]
                );
                printf("%c%c%c",
-                       "-r"[!!(st.nfs_mode & S_IROTH)],
-                       "-w"[!!(st.nfs_mode & S_IWOTH)],
-                       "-x"[!!(st.nfs_mode & S_IXOTH)]
+                       "-r"[!!(nfsdirent->mode & S_IROTH)],
+                       "-w"[!!(nfsdirent->mode & S_IWOTH)],
+                       "-x"[!!(nfsdirent->mode & S_IXOTH)]
                );
-               printf(" %2d", (int)st.nfs_nlink);
-               printf(" %5d", (int)st.nfs_uid);
-               printf(" %5d", (int)st.nfs_gid);
-               printf(" %12" PRId64, st.nfs_size);
+               printf(" %2d", (int)nfsdirent->nlink);
+               printf(" %5d", (int)nfsdirent->uid);
+               printf(" %5d", (int)nfsdirent->gid);
+               printf(" %12" PRId64, nfsdirent->size);
 
                printf(" %s\n", path + 1);
                
-               if (recursive && (st.nfs_mode & S_IFMT) == S_IFDIR) {
+               if (recursive && (nfsdirent->mode & S_IFMT) == S_IFDIR) {
                        process_dir(nfs, path, level - 1);
                }
        }