diff options
author | Ron Yorston <rmy@pobox.com> | 2022-05-19 12:47:41 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-05-19 15:43:23 +0100 |
commit | 055902330c448a5bbd59d12231bcb0aa00e50970 (patch) | |
tree | dca58bc94c2af44e402d3163b2bc0239b21c1884 | |
parent | 6ba1bb6d0245ecfca39224a44e2b3af3b2fef3d3 (diff) | |
download | busybox-w32-055902330c448a5bbd59d12231bcb0aa00e50970.tar.gz busybox-w32-055902330c448a5bbd59d12231bcb0aa00e50970.tar.bz2 busybox-w32-055902330c448a5bbd59d12231bcb0aa00e50970.zip |
win32: return reparse tag in struct stat
If a file is a junction or symlink return its tag in the st_tag
member of struct stat.
get_symlink_data() and is_symlink() also return the tag or zero,
as appropriate.
-rw-r--r-- | include/mingw.h | 1 | ||||
-rw-r--r-- | win32/mingw.c | 20 |
2 files changed, 15 insertions, 6 deletions
diff --git a/include/mingw.h b/include/mingw.h index b91fbb531..bfd6128e1 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -343,6 +343,7 @@ struct mingw_stat { | |||
343 | blksize_t st_blksize; | 343 | blksize_t st_blksize; |
344 | blkcnt_t st_blocks; | 344 | blkcnt_t st_blocks; |
345 | DWORD st_attr; | 345 | DWORD st_attr; |
346 | DWORD st_tag; | ||
346 | }; | 347 | }; |
347 | #define st_atime st_atim.tv_sec | 348 | #define st_atime st_atim.tv_sec |
348 | #define st_mtime st_mtim.tv_sec | 349 | #define st_mtime st_mtim.tv_sec |
diff --git a/win32/mingw.c b/win32/mingw.c index 5e743d94a..bea800435 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -563,22 +563,26 @@ static uid_t file_owner(HANDLE fh) | |||
563 | } | 563 | } |
564 | #endif | 564 | #endif |
565 | 565 | ||
566 | static int get_symlink_data(DWORD attr, const char *pathname, | 566 | static DWORD get_symlink_data(DWORD attr, const char *pathname, |
567 | WIN32_FIND_DATAA *fbuf) | 567 | WIN32_FIND_DATAA *fbuf) |
568 | { | 568 | { |
569 | if (attr & FILE_ATTRIBUTE_REPARSE_POINT) { | 569 | if (attr & FILE_ATTRIBUTE_REPARSE_POINT) { |
570 | HANDLE handle = FindFirstFileA(pathname, fbuf); | 570 | HANDLE handle = FindFirstFileA(pathname, fbuf); |
571 | if (handle != INVALID_HANDLE_VALUE) { | 571 | if (handle != INVALID_HANDLE_VALUE) { |
572 | FindClose(handle); | 572 | FindClose(handle); |
573 | return ((fbuf->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && | 573 | if ((fbuf->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) { |
574 | (fbuf->dwReserved0 == IO_REPARSE_TAG_SYMLINK || | 574 | switch (fbuf->dwReserved0) { |
575 | fbuf->dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT)); | 575 | case IO_REPARSE_TAG_SYMLINK: |
576 | case IO_REPARSE_TAG_MOUNT_POINT: | ||
577 | return fbuf->dwReserved0; | ||
578 | } | ||
579 | } | ||
576 | } | 580 | } |
577 | } | 581 | } |
578 | return 0; | 582 | return 0; |
579 | } | 583 | } |
580 | 584 | ||
581 | static int is_symlink(const char *pathname) | 585 | static DWORD is_symlink(const char *pathname) |
582 | { | 586 | { |
583 | WIN32_FILE_ATTRIBUTE_DATA fdata; | 587 | WIN32_FILE_ATTRIBUTE_DATA fdata; |
584 | WIN32_FIND_DATAA fbuf; | 588 | WIN32_FIND_DATAA fbuf; |
@@ -629,8 +633,10 @@ static int do_lstat(int follow, const char *file_name, struct mingw_stat *buf) | |||
629 | buf->st_uid = DEFAULT_UID; | 633 | buf->st_uid = DEFAULT_UID; |
630 | buf->st_gid = DEFAULT_GID; | 634 | buf->st_gid = DEFAULT_GID; |
631 | buf->st_dev = buf->st_rdev = 0; | 635 | buf->st_dev = buf->st_rdev = 0; |
636 | buf->st_tag = | ||
637 | get_symlink_data(fdata.dwFileAttributes, file_name, &findbuf); | ||
632 | 638 | ||
633 | if (get_symlink_data(fdata.dwFileAttributes, file_name, &findbuf)) { | 639 | if (buf->st_tag) { |
634 | char *name = auto_string(xmalloc_realpath(file_name)); | 640 | char *name = auto_string(xmalloc_realpath(file_name)); |
635 | 641 | ||
636 | if (follow) { | 642 | if (follow) { |
@@ -745,6 +751,7 @@ int mingw_fstat(int fd, struct mingw_stat *buf) | |||
745 | buf->st_mode = (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) | 751 | buf->st_mode = (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) |
746 | & ~(current_umask & 0022); | 752 | & ~(current_umask & 0022); |
747 | buf->st_attr = FILE_ATTRIBUTE_NORMAL; | 753 | buf->st_attr = FILE_ATTRIBUTE_NORMAL; |
754 | buf->st_tag = 0; | ||
748 | buf->st_size = buf64.st_size; | 755 | buf->st_size = buf64.st_size; |
749 | buf->st_atim.tv_sec = buf64.st_atime; | 756 | buf->st_atim.tv_sec = buf64.st_atime; |
750 | buf->st_atim.tv_nsec = 0; | 757 | buf->st_atim.tv_nsec = 0; |
@@ -764,6 +771,7 @@ int mingw_fstat(int fd, struct mingw_stat *buf) | |||
764 | if (GetFileInformationByHandle(fh, &fdata)) { | 771 | if (GetFileInformationByHandle(fh, &fdata)) { |
765 | buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes); | 772 | buf->st_mode = file_attr_to_st_mode(fdata.dwFileAttributes); |
766 | buf->st_attr = fdata.dwFileAttributes; | 773 | buf->st_attr = fdata.dwFileAttributes; |
774 | buf->st_tag = 0; | ||
767 | buf->st_size = fdata.nFileSizeLow | | 775 | buf->st_size = fdata.nFileSizeLow | |
768 | (((off64_t)fdata.nFileSizeHigh)<<32); | 776 | (((off64_t)fdata.nFileSizeHigh)<<32); |
769 | buf->st_atim = filetime_to_timespec(&(fdata.ftLastAccessTime)); | 777 | buf->st_atim = filetime_to_timespec(&(fdata.ftLastAccessTime)); |