From 3ab7b90aba64b2341f74d1e5b85a3f8fef216258 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 19 May 2022 13:02:26 +0100 Subject: lsattr: distinguish between junctions and symlinks Use the new st_tag member of struct stat to display whether a reparse point is a junction or a symlink. --- e2fsprogs/e2fs_lib.c | 39 +++++++++++++++++++++++++++++++++++++++ e2fsprogs/e2fs_lib.h | 7 ++++++- e2fsprogs/lsattr.c | 4 ++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c index e40702e78..07de5eda7 100644 --- a/e2fsprogs/e2fs_lib.c +++ b/e2fsprogs/e2fs_lib.c @@ -105,10 +105,18 @@ static const char e2attr_flags_lname[] ALIGN1 = /* Another trailing NUL is added by compiler */; #endif +#if !ENABLE_PLATFORM_MINGW32 void print_e2flags_long(unsigned flags) +#else +#define flags sb->st_attr +void print_e2flags_long(struct stat *sb) +#endif { const uint32_t *fv; const char *fn; +#if ENABLE_PLATFORM_MINGW32 + const char *ln; +#endif int first = 1; fv = e2attr_flags_value; @@ -117,7 +125,22 @@ void print_e2flags_long(unsigned flags) if (flags & *fv) { if (!first) fputs(", ", stdout); +#if ENABLE_PLATFORM_MINGW32 + ln = fn; + if (*fv == FILE_ATTRIBUTE_REPARSE_POINT) { + switch (sb->st_tag) { + case IO_REPARSE_TAG_SYMLINK: + ln = "Symbolic_Link"; + break; + case IO_REPARSE_TAG_MOUNT_POINT: + ln = "Junction"; + break; + } + } + fputs(ln, stdout); +#else fputs(fn, stdout); +#endif first = 0; } fv++; @@ -127,7 +150,11 @@ void print_e2flags_long(unsigned flags) fputs("---", stdout); } +#if !ENABLE_PLATFORM_MINGW32 void print_e2flags(unsigned flags) +#else +void print_e2flags(struct stat *sb) +#endif { const uint32_t *fv; const char *fn; @@ -138,6 +165,18 @@ void print_e2flags(unsigned flags) char c = '-'; if (flags & *fv) c = *fn; +#if ENABLE_PLATFORM_MINGW32 + if (*fv == FILE_ATTRIBUTE_REPARSE_POINT) { + switch (sb->st_tag) { + case IO_REPARSE_TAG_SYMLINK: + c = 'l'; + break; + case IO_REPARSE_TAG_MOUNT_POINT: + c = 'j'; + break; + } + } +#endif putchar(c); fv++; fn++; diff --git a/e2fsprogs/e2fs_lib.h b/e2fsprogs/e2fs_lib.h index fd6948fc7..5ce206ad6 100644 --- a/e2fsprogs/e2fs_lib.h +++ b/e2fsprogs/e2fs_lib.h @@ -16,11 +16,16 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN #define CHATTR_MASK (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | \ FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE | \ FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) -#endif + +/* Print file attributes on an NTFS file system */ +void print_e2flags_long(struct stat *sb); +void print_e2flags(struct stat *sb); +#else /* Print file attributes on an ext2 file system */ void print_e2flags_long(unsigned flags); void print_e2flags(unsigned flags); +#endif extern const uint32_t e2attr_flags_value[]; extern const char e2attr_flags_sname[]; diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index 461ce39e6..e86807e85 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c @@ -53,8 +53,8 @@ enum { static void list_attributes(const char *name) { - unsigned fsflags; #if !ENABLE_PLATFORM_MINGW32 + unsigned fsflags; int fd, r; /* There is no way to run needed ioctls on a symlink. @@ -95,7 +95,7 @@ static void list_attributes(const char *name) S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))) goto read_err; - fsflags = st.st_attr; +#define fsflags &st #endif if (option_mask32 & OPT_PF_LONG) { -- cgit v1.2.3-55-g6feb