comparison lib/mountlist.c @ 39908:f2b5499e6ee2

mountlist: Improve support for Solaris in 64-bit mode. Reported by David Wood <David.Wood@deshaw.com> in <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=6816>. * m4/ls-mntd-fs.m4 (gl_LIST_MOUNTED_FILE_SYSTEMS): On Solaris 8 or newer, define MOUNTED_GETEXTMNTENT instead of MOUNTED_GETMNTENT2. * lib/mountlist.c: Add code for MOUNTED_GETEXTMNTENT case.
author Bruno Haible <bruno@clisp.org>
date Fri, 12 Oct 2018 11:12:53 +0200
parents b14bcf3a1610
children dc86d8546fe5
comparison
equal deleted inserted replaced
39907:b14bcf3a1610 39908:f2b5499e6ee2
109 109
110 #ifdef MOUNTED_LISTMNTENT /* (obsolete) Cray UNICOS 9 */ 110 #ifdef MOUNTED_LISTMNTENT /* (obsolete) Cray UNICOS 9 */
111 # include <mntent.h> 111 # include <mntent.h>
112 #endif 112 #endif
113 113
114 #ifdef MOUNTED_GETMNTENT2 /* Solaris, also (obsolete) SVR4 */ 114 #ifdef MOUNTED_GETEXTMNTENT /* Solaris >= 8 */
115 # include <sys/mnttab.h>
116 #endif
117
118 #ifdef MOUNTED_GETMNTENT2 /* Solaris < 8, also (obsolete) SVR4 */
115 # include <sys/mnttab.h> 119 # include <sys/mnttab.h>
116 #endif 120 #endif
117 121
118 #ifdef MOUNTED_VMOUNT /* AIX */ 122 #ifdef MOUNTED_VMOUNT /* AIX */
119 # include <fshelp.h> 123 # include <fshelp.h>
916 } 920 }
917 endmnttbl (); 921 endmnttbl ();
918 } 922 }
919 #endif /* MOUNTED_GETMNTTBL */ 923 #endif /* MOUNTED_GETMNTTBL */
920 924
921 #ifdef MOUNTED_GETMNTENT2 /* Solaris, also (obsolete) SVR4 */ 925 #ifdef MOUNTED_GETEXTMNTENT /* Solaris >= 8 */
926 {
927 struct extmnttab mnt;
928 const char *table = MNTTAB;
929 FILE *fp;
930 int ret;
931
932 /* No locking is needed, because the contents of /etc/mnttab is generated
933 by the kernel. */
934
935 errno = 0;
936 fp = fopen (table, "r");
937 if (fp == NULL)
938 ret = errno;
939 else
940 {
941 while ((ret = getextmntent (fp, &mnt, 1)) == 0)
942 {
943 me = xmalloc (sizeof *me);
944 me->me_devname = xstrdup (mnt.mnt_special);
945 me->me_mountdir = xstrdup (mnt.mnt_mountp);
946 me->me_mntroot = NULL;
947 me->me_type = xstrdup (mnt.mnt_fstype);
948 me->me_type_malloced = 1;
949 me->me_dummy = MNT_IGNORE (&mnt) != 0;
950 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
951 me->me_dev = makedev (mnt.mnt_major, mnt.mnt_minor);
952
953 /* Add to the linked list. */
954 *mtail = me;
955 mtail = &me->me_next;
956 }
957
958 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1;
959 /* Here ret = -1 means success, ret >= 0 means failure. */
960 }
961
962 if (0 <= ret)
963 {
964 errno = ret;
965 goto free_then_fail;
966 }
967 }
968 #endif /* MOUNTED_GETMNTTBL */
969
970 #ifdef MOUNTED_GETMNTENT2 /* Solaris < 8, also (obsolete) SVR4 */
922 { 971 {
923 struct mnttab mnt; 972 struct mnttab mnt;
924 char *table = MNTTAB; 973 const char *table = MNTTAB;
925 FILE *fp; 974 FILE *fp;
926 int ret; 975 int ret;
927 int lockfd = -1; 976 int lockfd = -1;
928 977
929 # if defined F_RDLCK && defined F_SETLKW 978 # if defined F_RDLCK && defined F_SETLKW
977 *mtail = me; 1026 *mtail = me;
978 mtail = &me->me_next; 1027 mtail = &me->me_next;
979 } 1028 }
980 1029
981 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1; 1030 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1;
1031 /* Here ret = -1 means success, ret >= 0 means failure. */
982 } 1032 }
983 1033
984 if (0 <= lockfd && close (lockfd) != 0) 1034 if (0 <= lockfd && close (lockfd) != 0)
985 ret = errno; 1035 ret = errno;
986 1036