From: Arvind Raghavan <raghavan.arvind@gmail.com>
To: fstests <fstests@vger.kernel.org>
Cc: Amir Goldstein <amir73il@gmail.com>,
Jayashree Mohan <jaya@cs.utexas.edu>,
Vijay Chidambaram <vijay@cs.utexas.edu>,
Arvind Raghavan <raghavan.arvind@gmail.com>
Subject: [PATCH v2 6/7] src/fssum: Allow single file input
Date: Sun, 21 Jun 2020 19:16:46 -0400 [thread overview]
Message-ID: <4d2fa44b88c5f4f7aa53074220abba7beafa4fe8.1592779555.git.raghavan.arvind@gmail.com> (raw)
In-Reply-To: <cover.1592779555.git.raghavan.arvind@gmail.com>
Allow regular links and symlinks to be passed as input to fssum.
Signed-off-by: Arvind Raghavan <raghavan.arvind@gmail.com>
Signed-off-by: Jayashree Mohan <jaya@cs.utexas.edu>
Signed-off-by: Vijay Chidambaram <vijay@cs.utexas.edu>
---
Since v1:
- Simplified logic by using sum_one
src/fssum.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/fssum.c b/src/fssum.c
index 26b0096c..c5c27486 100644
--- a/src/fssum.c
+++ b/src/fssum.c
@@ -29,6 +29,7 @@
#include <inttypes.h>
#include <assert.h>
#include <endian.h>
+#include <libgen.h>
#define CS_SIZE 16
#define CHUNKS 128
@@ -600,7 +601,8 @@ sum_one(int dirfd, int level, sum_t *dircs, char *path_prefix,
goto out;
}
- ret = fstatat64(dirfd, name, &st, AT_SYMLINK_NOFOLLOW);
+ ret = fstatat64(dirfd, name, &st, AT_SYMLINK_NOFOLLOW |
+ AT_EMPTY_PATH);
if (ret) {
fprintf(stderr, "stat failed for %s/%s: %s\n",
path_prefix, path, strerror(errno));
@@ -890,8 +892,23 @@ main(int argc, char *argv[])
if (gen_manifest)
fprintf(out_fp, "Flags: %s\n", flagstring);
+ struct stat64 path_st;
+ if (fstat64(fd, &path_st)) {
+ perror("fstat");
+ exit(-1);
+ }
+
sum_init(&cs);
- sum(fd, 1, &cs, path, "");
+
+ if (S_ISDIR(path_st.st_mode)) {
+ sum(fd, 1, &cs, path, "");
+ } else if (S_ISREG(path_st.st_mode) || S_ISLNK(path_st.st_mode)) {
+ sum_one(fd, 1, &cs, path, "", "");
+ } else {
+ fprintf(stderr, "path must be file or dir: %s", path);
+ exit(-1);
+ }
+
sum_fini(&cs);
close(fd);
--
2.20.1
next prev parent reply other threads:[~2020-06-21 23:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-21 23:14 [PATCH v2 0/7] Change fssum to support POSIX Arvind Raghavan
2020-06-21 23:15 ` [PATCH v2 1/7] src/fssum: Make sum_file_data global Arvind Raghavan
2020-06-21 23:15 ` [PATCH v2 2/7] src/fssum: Refactoring changes for recursive traversal Arvind Raghavan
2020-06-22 6:47 ` Amir Goldstein
2020-06-21 23:16 ` [PATCH v2 3/7] src/fssum: Recursive traversal refactoring Arvind Raghavan
2020-06-22 7:42 ` Amir Goldstein
2020-06-21 23:16 ` [PATCH v2 4/7] src/fssum: Add flag -R for non-recursive mode Arvind Raghavan
2020-06-21 23:16 ` [PATCH v2 5/7] src/fssum: Add a flag for including file size in checksum Arvind Raghavan
2020-06-21 23:16 ` Arvind Raghavan [this message]
2020-06-22 6:56 ` [PATCH v2 6/7] src/fssum: Allow single file input Amir Goldstein
2020-06-21 23:17 ` [PATCH v2 7/7] src/fssum: Fix whitespace in usage Arvind Raghavan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4d2fa44b88c5f4f7aa53074220abba7beafa4fe8.1592779555.git.raghavan.arvind@gmail.com \
--to=raghavan.arvind@gmail.com \
--cc=amir73il@gmail.com \
--cc=fstests@vger.kernel.org \
--cc=jaya@cs.utexas.edu \
--cc=vijay@cs.utexas.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).