diff --git a/src/lib/libast/features/lib b/src/lib/libast/features/lib index 4289f78d24d7..522c4c3002a1 100644 --- a/src/lib/libast/features/lib +++ b/src/lib/libast/features/lib @@ -4,7 +4,7 @@ cmd universe hdr dirent,direntry,filio,fmtmsg,fnmatch,jioctl,libgen,limits hdr locale,ndir,nl_types,process,spawn,syslog,utime,vfork -hdr linux/fs,sys/ioctl +hdr linux/fs,linux/msdos_fs,sys/ioctl hdr wchar note{ and isw*() really work }end execute{ #include int diff --git a/src/lib/libast/path/pathicase.c b/src/lib/libast/path/pathicase.c index 8418b2e29b94..632fe5e76387 100644 --- a/src/lib/libast/path/pathicase.c +++ b/src/lib/libast/path/pathicase.c @@ -17,11 +17,23 @@ #include #include -#if _hdr_linux_fs && _hdr_sys_ioctl +#if _hdr_linux_fs #include +#endif +#if _hdr_linux_msdos_fs +#include +#endif +#if _hdr_sys_ioctl #include #endif +#if _hdr_sys_ioctl && _hdr_linux_fs && defined(FS_IOC_GETFLAGS) && defined(FS_CASEFOLD_FL) +#define _linux_casefold 1 +#endif +#if _hdr_sys_ioctl && _hdr_linux_msdos_fs && defined(FAT_IOCTL_GET_ATTRIBUTES) +#define _linux_fatfs 1 +#endif + /* * Return 1 if the given path is on a case insensitive file system, 0 if not, -1 on error. */ @@ -40,14 +52,23 @@ pathicase(const char *path) /* Cygwin */ long r = pathconf(path, _PC_CASE_INSENSITIVE); return r < 0L ? -1 : r > 0L; -#elif _hdr_linux_fs && _hdr_sys_ioctl && defined(FS_IOC_GETFLAGS) && defined(FS_CASEFOLD_FL) - /* Linux 5.2+ */ +#elif _linux_fatfs + /* Linux */ int attr = 0, fd, r; if ((fd = open(path, O_RDONLY|O_NONBLOCK)) < 0) return -1; - r = ioctl(fd, FS_IOC_GETFLAGS, &attr); + r = ioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attr); +# if _linux_casefold + /* Linux 5.2+ */ + if (r < 0 && errno == ENOTTY) /* if it's not VFAT/FAT32...*/ + { + r = ioctl(fd, FS_IOC_GETFLAGS, &attr); + close(fd); + return r < 0 ? -1 : (attr & FS_CASEFOLD_FL) != 0; + } +# endif /* _linux_casefold */ close(fd); - return r < 0 ? -1 : attr & FS_CASEFOLD_FL != 0; + return r < 0 ? (errno != ENOTTY ? -1 : 0) : 1; #elif _WINIX || __APPLE__ /* Windows or Mac without pathconf probe: assume case insensitive */ return 1;