From: Ronnie Sahlberg Date: Sun, 8 Jun 2014 18:40:35 +0000 (-0700) Subject: libnfs.c: add nlink to nfsdirent so we can get it for 'free' X-Git-Tag: upstream/1.9.6^2~28 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=390ff38ad1689f0708cdb18811b3b7d5d616cba7;p=deb_libnfs.git libnfs.c: add nlink to nfsdirent so we can get it for 'free' update the nfs-ls utility to just use nfsdirent as is instead of having to stat the files. Signed-off-by: Ronnie Sahlberg --- diff --git a/include/nfsc/libnfs.h b/include/nfsc/libnfs.h index d960f7f..b6cb806 100644 --- a/include/nfsc/libnfs.h +++ b/include/nfsc/libnfs.h @@ -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 diff --git a/lib/libnfs.c b/lib/libnfs.c index 1328aed..30719ab 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -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; diff --git a/utils/nfs-ls.c b/utils/nfs-ls.c index 974a6e1..7653f56 100644 --- a/utils/nfs-ls.c +++ b/utils/nfs-ls.c @@ -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); } }