Skip to content

Commit

Permalink
Linux bugfixes for globcasedetect (re: 7193457) (att#240)
Browse files Browse the repository at this point in the history
src/lib/libast/features/lib,
src/lib/libast/path/pathicase.c:
- FAT32 file systems on Linux don't support FS_CASEFOLD_FL, which
  caused globbing to break. Reproducer using a UEFI boot partition:
      $ echo /boot/eF*
      /boot/eF*
  This is fixed by checking for FAT attributes with ioctl, then
  checking for FS_CASEFOLD_FL if that fails.
- The check for FS_CASEFOLD_FL didn't work correctly; I still wasn't
  able to get --globcasedetect to work on a case-insensitive ext4
  folder. Fix that by adding missing parentheses.
  • Loading branch information
JohnoKing committed Mar 23, 2021
1 parent bd38c80 commit ca3ec20
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/libast/features/lib
Original file line number Diff line number Diff line change
Expand Up @@ -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{ <wchar.h> and isw*() really work }end execute{
#include <wchar.h>
int
Expand Down
31 changes: 26 additions & 5 deletions src/lib/libast/path/pathicase.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@
#include <ast.h>
#include <error.h>

#if _hdr_linux_fs && _hdr_sys_ioctl
#if _hdr_linux_fs
#include <linux/fs.h>
#endif
#if _hdr_linux_msdos_fs
#include <linux/msdos_fs.h>
#endif
#if _hdr_sys_ioctl
#include <sys/ioctl.h>
#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.
*/
Expand All @@ -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;
Expand Down

0 comments on commit ca3ec20

Please sign in to comment.