From 13e14a6bfd9f29cbfeab0c5161d2a994f97532e7 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 26 Mar 2026 12:53:53 +0100 Subject: Update/gnulib 2026 03 (#2247) * Sync with the 202601-stable Gnulib code (4a3650d887) * Ignore more deps stuff in gnulib * Remove autogenerated gnulib files * Ignore more gnulib generated headers --- gl/mountlist.c | 399 ++++++++++++++++++++++++++------------------------------- 1 file changed, 185 insertions(+), 214 deletions(-) (limited to 'gl/mountlist.c') diff --git a/gl/mountlist.c b/gl/mountlist.c index dcff6f83..66b3f3d5 100644 --- a/gl/mountlist.c +++ b/gl/mountlist.c @@ -1,6 +1,6 @@ /* mountlist.c -- return a list of mounted file systems - Copyright (C) 1991-1992, 1997-2025 Free Software Foundation, Inc. + Copyright (C) 1991-1992, 1997-2026 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -41,7 +41,7 @@ # include #endif -#if defined MOUNTED_GETFSSTAT /* OSF/1, also (obsolete) Apple Darwin 1.3 */ +#if defined MOUNTED_GETFSSTAT /* (obsolete) Apple Darwin 1.3 */ # if HAVE_SYS_UCRED_H # include /* needed on OSF V4.0 for definition of NGROUPS, NGROUPS is used as an array dimension in ucred.h */ @@ -60,7 +60,7 @@ # endif #endif /* MOUNTED_GETFSSTAT */ -#ifdef MOUNTED_GETMNTENT1 /* glibc, HP-UX, IRIX, Cygwin, Android, +#ifdef MOUNTED_GETMNTENT1 /* glibc, HP-UX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS */ # include # include @@ -171,23 +171,21 @@ #endif #define ME_DUMMY_0(Fs_name, Fs_type) \ - (strcmp (Fs_type, "autofs") == 0 \ - || strcmp (Fs_type, "proc") == 0 \ - || strcmp (Fs_type, "subfs") == 0 \ + (streq (Fs_type, "autofs") \ + || streq (Fs_type, "proc") \ + || streq (Fs_type, "subfs") \ /* for Linux 2.6/3.x */ \ - || strcmp (Fs_type, "debugfs") == 0 \ - || strcmp (Fs_type, "devpts") == 0 \ - || strcmp (Fs_type, "fusectl") == 0 \ - || strcmp (Fs_type, "fuse.portal") == 0 \ - || strcmp (Fs_type, "mqueue") == 0 \ - || strcmp (Fs_type, "rpc_pipefs") == 0 \ - || strcmp (Fs_type, "sysfs") == 0 \ + || streq (Fs_type, "debugfs") \ + || streq (Fs_type, "devpts") \ + || streq (Fs_type, "fusectl") \ + || streq (Fs_type, "fuse.portal") \ + || streq (Fs_type, "mqueue") \ + || streq (Fs_type, "rpc_pipefs") \ + || streq (Fs_type, "sysfs") \ /* FreeBSD, Linux 2.4 */ \ - || strcmp (Fs_type, "devfs") == 0 \ + || streq (Fs_type, "devfs") \ /* for NetBSD 3.0 */ \ - || strcmp (Fs_type, "kernfs") == 0 \ - /* for Irix 6.5 */ \ - || strcmp (Fs_type, "ignore") == 0) + || streq (Fs_type, "kernfs")) /* Historically, we have marked as "dummy" any file system of type "none", but now that programs like du need to know about bind-mounted directories, @@ -196,10 +194,10 @@ #ifdef MOUNTED_GETMNTENT1 # define ME_DUMMY(Fs_name, Fs_type, Bind) \ (ME_DUMMY_0 (Fs_name, Fs_type) \ - || (strcmp (Fs_type, "none") == 0 && !Bind)) + || (streq (Fs_type, "none") && !Bind)) #else # define ME_DUMMY(Fs_name, Fs_type) \ - (ME_DUMMY_0 (Fs_name, Fs_type) || strcmp (Fs_type, "none") == 0) + (ME_DUMMY_0 (Fs_name, Fs_type) || streq (Fs_type, "none")) #endif #ifdef __CYGWIN__ @@ -240,19 +238,19 @@ me_remote (char const *fs_name, _GL_UNUSED char const *fs_type) (strchr (Fs_name, ':') != NULL \ || ((Fs_name)[0] == '/' \ && (Fs_name)[1] == '/' \ - && (strcmp (Fs_type, "smbfs") == 0 \ - || strcmp (Fs_type, "smb3") == 0 \ - || strcmp (Fs_type, "cifs") == 0)) \ - || strcmp (Fs_type, "acfs") == 0 \ - || strcmp (Fs_type, "afs") == 0 \ - || strcmp (Fs_type, "coda") == 0 \ - || strcmp (Fs_type, "auristorfs") == 0 \ - || strcmp (Fs_type, "fhgfs") == 0 \ - || strcmp (Fs_type, "gpfs") == 0 \ - || strcmp (Fs_type, "ibrix") == 0 \ - || strcmp (Fs_type, "ocfs2") == 0 \ - || strcmp (Fs_type, "vxfs") == 0 \ - || strcmp ("-hosts", Fs_name) == 0) + && (streq (Fs_type, "smbfs") \ + || streq (Fs_type, "smb3") \ + || streq (Fs_type, "cifs"))) \ + || streq (Fs_type, "acfs") \ + || streq (Fs_type, "afs") \ + || streq (Fs_type, "coda") \ + || streq (Fs_type, "auristorfs") \ + || streq (Fs_type, "fhgfs") \ + || streq (Fs_type, "gpfs") \ + || streq (Fs_type, "ibrix") \ + || streq (Fs_type, "ocfs2") \ + || streq (Fs_type, "vxfs") \ + || streq ("-hosts", Fs_name)) #endif #if MOUNTED_GETMNTINFO /* Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD */ @@ -369,9 +367,7 @@ fsp_to_string (const struct statfs *fsp) static char * fstype_to_string (int t) { - struct vfs_ent *e; - - e = getvfsbytype (t); + struct vfs_ent *e = getvfsbytype (t); if (!e || !e->vfsent_name) return "none"; else @@ -400,10 +396,9 @@ dev_from_mount_options (char const *mount_options) char const *optval = devopt + sizeof dev_pattern - 1; if (c_isxdigit (*optval)) { - char *optvalend; - unsigned long int dev; errno = 0; - dev = strtoul (optval, &optvalend, 16); + char *optvalend; + unsigned long int dev = strtoul (optval, &optvalend, 16); if (optval != optvalend && (*optvalend == '\0' || *optvalend == ',') && ! (dev == ULONG_MAX && errno == ERANGE) @@ -427,9 +422,9 @@ dev_from_mount_options (char const *mount_options) static void unescape_tab (char *str) { - size_t i, j = 0; + size_t j = 0; size_t len = strlen (str) + 1; - for (i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { if (str[i] == '\\' && (i + 4 < len) && str[i + 1] >= '0' && str[i + 1] <= '3' @@ -468,18 +463,16 @@ read_file_system_list (bool need_fs_type) struct mount_entry **mtail = &mount_list; (void) need_fs_type; -#ifdef MOUNTED_GETMNTENT1 /* glibc, HP-UX, IRIX, Cygwin, Android, +#ifdef MOUNTED_GETMNTENT1 /* glibc, HP-UX, Cygwin, Android, also (obsolete) 4.3BSD, SunOS */ { - FILE *fp; - # if defined __linux__ || defined __ANDROID__ /* Try parsing mountinfo first, as that make device IDs available. Note we could use libmount routines to simplify this parsing a little (and that code is in previous versions of this function), however libmount depends on libselinux which pulls in many dependencies. */ char const *mountinfo = "/proc/self/mountinfo"; - fp = fopen (mountinfo, "re"); + FILE *fp = fopen (mountinfo, "re"); if (fp != NULL) { char *line = NULL; @@ -497,61 +490,61 @@ read_file_system_list (bool need_fs_type) &devmaj, &devmin, &mntroot_s); - if (rc != 2 && rc != 3) /* 3 if %n included in count. */ - continue; - - /* find end of MNTROOT. */ - char *mntroot = line + mntroot_s; - char *blank = terminate_at_blank (mntroot); - if (! blank) - continue; - - /* find end of TARGET. */ - char *target = blank + 1; - blank = terminate_at_blank (target); - if (! blank) - continue; - - /* skip optional fields, terminated by " - " */ - char *dash = strstr (blank + 1, " - "); - if (! dash) - continue; - - /* advance past the " - " separator. */ - char *fstype = dash + 3; - blank = terminate_at_blank (fstype); - if (! blank) - continue; - - /* find end of SOURCE. */ - char *source = blank + 1; - if (! terminate_at_blank (source)) - continue; - - /* manipulate the sub-strings in place. */ - unescape_tab (source); - unescape_tab (target); - unescape_tab (mntroot); - unescape_tab (fstype); - - me = xmalloc (sizeof *me); - - me->me_devname = xstrdup (source); - me->me_mountdir = xstrdup (target); - me->me_mntroot = xstrdup (mntroot); - me->me_type = xstrdup (fstype); - me->me_type_malloced = 1; - me->me_dev = makedev (devmaj, devmin); - /* we pass "false" for the "Bind" option as that's only - significant when the Fs_type is "none" which will not be - the case when parsing "/proc/self/mountinfo", and only - applies for static /etc/mtab files. */ - me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, false); - me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; + if (rc == 2 || rc == 3) /* 3 if %n included in count. */ + { + /* find end of MNTROOT. */ + char *mntroot = line + mntroot_s; + char *blank = terminate_at_blank (mntroot); + if (blank) + { + /* find end of TARGET. */ + char *target = blank + 1; + blank = terminate_at_blank (target); + if (blank) + { + /* skip optional fields, terminated by " - " */ + char *dash = strstr (blank + 1, " - "); + if (dash) + { + /* advance past the " - " separator. */ + char *fstype = dash + 3; + blank = terminate_at_blank (fstype); + if (blank) + { + /* find end of SOURCE. */ + char *source = blank + 1; + if (terminate_at_blank (source)) + { + /* manipulate the sub-strings in place. */ + unescape_tab (source); + unescape_tab (target); + unescape_tab (mntroot); + unescape_tab (fstype); + + me = xmalloc (sizeof *me); + + me->me_devname = xstrdup (source); + me->me_mountdir = xstrdup (target); + me->me_mntroot = xstrdup (mntroot); + me->me_type = xstrdup (fstype); + me->me_type_malloced = 1; + me->me_dev = makedev (devmaj, devmin); + /* we pass "false" for the "Bind" option as that's only + significant when the Fs_type is "none" which will not be + the case when parsing "/proc/self/mountinfo", and only + applies for static /etc/mtab files. */ + me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, false); + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; + } + } + } + } + } + } } free (line); @@ -570,14 +563,14 @@ read_file_system_list (bool need_fs_type) else /* fallback to /proc/self/mounts (/etc/mtab). */ # endif /* __linux__ || __ANDROID__ */ { - struct mntent *mnt; char const *table = MOUNTED; - fp = setmntent (table, "r"); - if (fp == NULL) + FILE *mfp = setmntent (table, "r"); + if (mfp == NULL) return NULL; - while ((mnt = getmntent (fp))) + struct mntent *mnt; + while ((mnt = getmntent (mfp))) { bool bind = hasmntopt (mnt, "bind"); @@ -596,7 +589,7 @@ read_file_system_list (bool need_fs_type) mtail = &me->me_next; } - if (endmntent (fp) == 0) + if (endmntent (mfp) == 0) goto free_then_fail; } } @@ -605,9 +598,7 @@ read_file_system_list (bool need_fs_type) #ifdef MOUNTED_GETMNTINFO /* Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD */ { struct statfs *fsp; - int entries; - - entries = getmntinfo (&fsp, MNT_NOWAIT); + int entries = getmntinfo (&fsp, MNT_NOWAIT); if (entries < 0) return NULL; for (; entries-- > 0; fsp++) @@ -634,9 +625,7 @@ read_file_system_list (bool need_fs_type) #ifdef MOUNTED_GETMNTINFO2 /* NetBSD, Minix */ { struct statvfs *fsp; - int entries; - - entries = getmntinfo (&fsp, MNT_NOWAIT); + int entries = getmntinfo (&fsp, MNT_NOWAIT); if (entries < 0) return NULL; for (; entries-- > 0; fsp++) @@ -670,7 +659,6 @@ read_file_system_list (bool need_fs_type) We therefore get the list of subdirectories of /, and the list of all file systems, and match the two lists. */ - DIR *dirp; struct rootdir_entry { char *name; @@ -678,16 +666,11 @@ read_file_system_list (bool need_fs_type) ino_t ino; struct rootdir_entry *next; }; - struct rootdir_entry *rootdir_list; - struct rootdir_entry **rootdir_tail; - int32 pos; - dev_t dev; - fs_info fi; /* All volumes are mounted in the rootfs, directly under /. */ - rootdir_list = NULL; - rootdir_tail = &rootdir_list; - dirp = opendir ("/"); + struct rootdir_entry *rootdir_list = NULL; + struct rootdir_entry **rootdir_tail = &rootdir_list; + DIR *dirp = opendir ("/"); if (dirp) { struct dirent *d; @@ -697,61 +680,64 @@ read_file_system_list (bool need_fs_type) char *name; struct stat statbuf; - if (strcmp (d->d_name, "..") == 0) - continue; - - if (strcmp (d->d_name, ".") == 0) - name = xstrdup ("/"); - else + if (! streq (d->d_name, "..")) { - name = xmalloc (1 + strlen (d->d_name) + 1); - name[0] = '/'; - strcpy (name + 1, d->d_name); - } + if (streq (d->d_name, ".")) + name = xstrdup ("/"); + else + { + name = xmalloc (1 + strlen (d->d_name) + 1); + name[0] = '/'; + strcpy (name + 1, d->d_name); + } - if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode)) - { - struct rootdir_entry *re = xmalloc (sizeof *re); - re->name = name; - re->dev = statbuf.st_dev; - re->ino = statbuf.st_ino; - - /* Add to the linked list. */ - *rootdir_tail = re; - rootdir_tail = &re->next; + if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode)) + { + struct rootdir_entry *re = xmalloc (sizeof *re); + re->name = name; + re->dev = statbuf.st_dev; + re->ino = statbuf.st_ino; + + /* Add to the linked list. */ + *rootdir_tail = re; + rootdir_tail = &re->next; + } + else + free (name); } - else - free (name); } closedir (dirp); } *rootdir_tail = NULL; - for (pos = 0; (dev = next_dev (&pos)) >= 0; ) - if (fs_stat_dev (dev, &fi) >= 0) - { - /* Note: fi.dev == dev. */ - struct rootdir_entry *re; - - for (re = rootdir_list; re; re = re->next) - if (re->dev == fi.dev && re->ino == fi.root) - break; - - me = xmalloc (sizeof *me); - me->me_devname = xstrdup (fi.device_name[0] != '\0' - ? fi.device_name : fi.fsh_name); - me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name); - me->me_mntroot = NULL; - me->me_type = xstrdup (fi.fsh_name); - me->me_type_malloced = 1; - me->me_dev = fi.dev; - me->me_dummy = 0; - me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; - } + dev_t dev; + for (int32 pos = 0; (dev = next_dev (&pos)) >= 0; ) + { + fs_info fi; + if (fs_stat_dev (dev, &fi) >= 0) + { + /* Note: fi.dev == dev. */ + struct rootdir_entry *re; + for (re = rootdir_list; re; re = re->next) + if (re->dev == fi.dev && re->ino == fi.root) + break; + + me = xmalloc (sizeof *me); + me->me_devname = xstrdup (fi.device_name[0] != '\0' + ? fi.device_name : fi.fsh_name); + me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name); + me->me_mntroot = NULL; + me->me_type = xstrdup (fi.fsh_name); + me->me_type_malloced = 1; + me->me_dev = fi.dev; + me->me_dummy = 0; + me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; + } + } *mtail = NULL; while (rootdir_list != NULL) @@ -764,19 +750,17 @@ read_file_system_list (bool need_fs_type) } #endif /* MOUNTED_FS_STAT_DEV */ -#if defined MOUNTED_GETFSSTAT /* OSF/1, also (obsolete) Apple Darwin 1.3 */ +#if defined MOUNTED_GETFSSTAT /* (obsolete) Apple Darwin 1.3 */ { - int numsys, counter; - size_t bufsize; - struct statfs *stats; - numsys = getfsstat (NULL, 0L, MNT_NOWAIT); + int numsys = getfsstat (NULL, 0L, MNT_NOWAIT); if (numsys < 0) return NULL; + + struct statfs *stats; if (SIZE_MAX / sizeof *stats <= numsys) xalloc_die (); - - bufsize = (1 + numsys) * sizeof *stats; + size_t bufsize = (1 + numsys) * sizeof *stats; stats = xmalloc (bufsize); numsys = getfsstat (stats, bufsize, MNT_NOWAIT); @@ -786,7 +770,7 @@ read_file_system_list (bool need_fs_type) return NULL; } - for (counter = 0; counter < numsys; counter++) + for (int counter = 0; counter < numsys; counter++) { me = xmalloc (sizeof *me); me->me_devname = xstrdup (stats[counter].f_mntfromname); @@ -809,14 +793,13 @@ read_file_system_list (bool need_fs_type) #if defined MOUNTED_FREAD_FSTYP /* (obsolete) SVR3 */ { - struct mnttab mnt; char *table = "/etc/mnttab"; - FILE *fp; - fp = fopen (table, "re"); + FILE *fp = fopen (table, "re"); if (fp == NULL) return NULL; + struct mnttab mnt; while (fread (&mnt, sizeof mnt, 1, fp) > 0) { me = xmalloc (sizeof *me); @@ -862,20 +845,19 @@ read_file_system_list (bool need_fs_type) #ifdef MOUNTED_GETEXTMNTENT /* Solaris >= 8 */ { - struct extmnttab mnt; const char *table = MNTTAB; - FILE *fp; - int ret; /* No locking is needed, because the contents of /etc/mnttab is generated by the kernel. */ errno = 0; - fp = fopen (table, "re"); + FILE *fp = fopen (table, "re"); + int ret; if (fp == NULL) ret = errno; else { + struct extmnttab mnt; while ((ret = getextmntent (fp, &mnt, 1)) == 0) { me = xmalloc (sizeof *me); @@ -909,10 +891,7 @@ read_file_system_list (bool need_fs_type) #ifdef MOUNTED_GETMNTENT2 /* Solaris < 8, also (obsolete) SVR4 */ { - struct mnttab mnt; const char *table = MNTTAB; - FILE *fp; - int ret; int lockfd = -1; # if defined F_RDLCK && defined F_SETLKW @@ -945,11 +924,13 @@ read_file_system_list (bool need_fs_type) # endif errno = 0; - fp = fopen (table, "re"); + FILE *fp = fopen (table, "re"); + int ret; if (fp == NULL) ret = errno; else { + struct mnttab mnt; while ((ret = getmntent (fp, &mnt)) == 0) { me = xmalloc (sizeof *me); @@ -984,34 +965,24 @@ read_file_system_list (bool need_fs_type) #ifdef MOUNTED_VMOUNT /* AIX */ { - int bufsize; - void *entries; - char *thisent; - struct vmount *vmp; - int n_entries; - int i; - /* Ask how many bytes to allocate for the mounted file system info. */ - entries = &bufsize; - if (mntctl (MCTL_QUERY, sizeof bufsize, entries) != 0) + int bufsize; + if (mntctl (MCTL_QUERY, sizeof bufsize, &bufsize) != 0) return NULL; - entries = xmalloc (bufsize); + void *entries = xmalloc (bufsize); /* Get the list of mounted file systems. */ - n_entries = mntctl (MCTL_QUERY, bufsize, entries); + int n_entries = mntctl (MCTL_QUERY, bufsize, entries); if (n_entries < 0) { free (entries); return NULL; } - for (i = 0, thisent = entries; - i < n_entries; - i++, thisent += vmp->vmt_length) + char *thisent = entries; + for (int i = 0; i < n_entries; i++) { - char *options, *ignore; - - vmp = (struct vmount *) thisent; + struct vmount *vmp = (struct vmount *) thisent; me = xmalloc (sizeof *me); if (vmp->vmt_flags & MNT_REMOTE) { @@ -1036,8 +1007,8 @@ read_file_system_list (bool need_fs_type) me->me_mntroot = NULL; me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype)); me->me_type_malloced = 1; - options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; - ignore = strstr (options, "ignore"); + char *options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; + char *ignore = strstr (options, "ignore"); me->me_dummy = (ignore && (ignore == options || ignore[-1] == ',') && (ignore[sizeof "ignore" - 1] == ',' @@ -1047,6 +1018,8 @@ read_file_system_list (bool need_fs_type) /* Add to the linked list. */ *mtail = me; mtail = &me->me_next; + + thisent += vmp->vmt_length; } free (entries); } @@ -1055,25 +1028,23 @@ read_file_system_list (bool need_fs_type) #ifdef MOUNTED_INTERIX_STATVFS /* Interix */ { DIR *dirp = opendir ("/dev/fs"); - char node[9 + NAME_MAX]; - if (!dirp) goto free_then_fail; while (1) { - struct statvfs dev; - struct dirent entry; - struct dirent *result; - /* FIXME: readdir_r is planned to be withdrawn from POSIX and marked obsolescent in glibc. Use readdir instead. */ + struct dirent entry; + struct dirent *result; if (readdir_r (dirp, &entry, &result) || result == NULL) break; + char node[9 + NAME_MAX]; strcpy (node, "/dev/fs/"); strcat (node, entry.d_name); + struct statvfs dev; if (statvfs (node, &dev) == 0) { me = xmalloc (sizeof *me); @@ -1107,18 +1078,18 @@ read_file_system_list (bool need_fs_type) if ASCII 'A' + i is an available drive. See: . */ DWORD value = GetLogicalDrives (); - unsigned int i; - for (i = 0; i < 26; ++i) + for (unsigned int i = 0; i < 26; ++i) { if (value & (1U << i)) { char mountdir[4]; - char fs_name[MAX_PATH + 1]; mountdir[0] = 'A' + i; mountdir[1] = ':'; mountdir[2] = '\\'; mountdir[3] = '\0'; + + char fs_name[MAX_PATH + 1]; /* Test whether the drive actually exists, and get the name of the file system. See: . */ @@ -1141,10 +1112,10 @@ read_file_system_list (bool need_fs_type) For testing of SUBST: For testing of NET USE: */ wchar_t drive[3]; - wchar_t mapping[MAX_PATH + 1]; drive[0] = L'A' + i; drive[1] = L':'; drive[2] = L'\0'; + wchar_t mapping[MAX_PATH + 1]; DWORD mapping_len = QueryDosDeviceW (drive, mapping, sizeof (mapping) / sizeof (mapping[0])); if (mapping_len > 4 && wcsncmp (mapping, L"\\??\\", 4) == 0) { -- cgit v1.2.3-74-g34f1