summaryrefslogtreecommitdiffstats
path: root/gl/mountlist.c
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2010-04-08 01:11:46 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2010-04-13 01:26:35 (GMT)
commit74da141e618ef99959d509cb2e7be35a348a39db (patch)
tree88ebc38b381a1021fc2d74864a71e230ae591c3d /gl/mountlist.c
parentc63a4f726a0b6ad8cf6040f947754a81fd4683bb (diff)
downloadmonitoring-plugins-74da141e618ef99959d509cb2e7be35a348a39db.tar.gz
Sync with the latest Gnulib code (177f525)
Signed-off-by: Thomas Guyot-Sionnest <dermoth@aei.ca>
Diffstat (limited to 'gl/mountlist.c')
-rw-r--r--gl/mountlist.c476
1 files changed, 238 insertions, 238 deletions
diff --git a/gl/mountlist.c b/gl/mountlist.c
index 50e90ee..996b71a 100644
--- a/gl/mountlist.c
+++ b/gl/mountlist.c
@@ -1,6 +1,6 @@
1/* mountlist.c -- return a list of mounted file systems 1/* mountlist.c -- return a list of mounted file systems
2 2
3 Copyright (C) 1991, 1992, 1997-2009 Free Software Foundation, Inc. 3 Copyright (C) 1991-1992, 1997-2010 Free Software Foundation, Inc.
4 4
5 This program is free software: you can redistribute it and/or modify 5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
@@ -37,10 +37,10 @@
37# include <sys/param.h> 37# include <sys/param.h>
38#endif 38#endif
39 39
40#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */ 40#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */
41# if HAVE_SYS_UCRED_H 41# if HAVE_SYS_UCRED_H
42# include <grp.h> /* needed on OSF V4.0 for definition of NGROUPS, 42# include <grp.h> /* needed on OSF V4.0 for definition of NGROUPS,
43 NGROUPS is used as an array dimension in ucred.h */ 43 NGROUPS is used as an array dimension in ucred.h */
44# include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */ 44# include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */
45# endif 45# endif
46# if HAVE_SYS_MOUNT_H 46# if HAVE_SYS_MOUNT_H
@@ -56,44 +56,44 @@
56# endif 56# endif
57#endif /* MOUNTED_GETFSSTAT */ 57#endif /* MOUNTED_GETFSSTAT */
58 58
59#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ 59#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
60# include <mntent.h> 60# include <mntent.h>
61# if !defined MOUNTED 61# if !defined MOUNTED
62# if defined _PATH_MOUNTED /* GNU libc */ 62# if defined _PATH_MOUNTED /* GNU libc */
63# define MOUNTED _PATH_MOUNTED 63# define MOUNTED _PATH_MOUNTED
64# endif 64# endif
65# if defined MNT_MNTTAB /* HP-UX. */ 65# if defined MNT_MNTTAB /* HP-UX. */
66# define MOUNTED MNT_MNTTAB 66# define MOUNTED MNT_MNTTAB
67# endif 67# endif
68# if defined MNTTABNAME /* Dynix. */ 68# if defined MNTTABNAME /* Dynix. */
69# define MOUNTED MNTTABNAME 69# define MOUNTED MNTTABNAME
70# endif 70# endif
71# endif 71# endif
72#endif 72#endif
73 73
74#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ 74#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
75# include <sys/mount.h> 75# include <sys/mount.h>
76#endif 76#endif
77 77
78#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ 78#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */
79# include <sys/statvfs.h> 79# include <sys/statvfs.h>
80#endif 80#endif
81 81
82#ifdef MOUNTED_GETMNT /* Ultrix. */ 82#ifdef MOUNTED_GETMNT /* Ultrix. */
83# include <sys/mount.h> 83# include <sys/mount.h>
84# include <sys/fs_types.h> 84# include <sys/fs_types.h>
85#endif 85#endif
86 86
87#ifdef MOUNTED_FS_STAT_DEV /* BeOS. */ 87#ifdef MOUNTED_FS_STAT_DEV /* BeOS. */
88# include <fs_info.h> 88# include <fs_info.h>
89# include <dirent.h> 89# include <dirent.h>
90#endif 90#endif
91 91
92#ifdef MOUNTED_FREAD /* SVR2. */ 92#ifdef MOUNTED_FREAD /* SVR2. */
93# include <mnttab.h> 93# include <mnttab.h>
94#endif 94#endif
95 95
96#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */ 96#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */
97# include <mnttab.h> 97# include <mnttab.h>
98# include <sys/fstyp.h> 98# include <sys/fstyp.h>
99# include <sys/statfs.h> 99# include <sys/statfs.h>
@@ -103,11 +103,11 @@
103# include <mntent.h> 103# include <mntent.h>
104#endif 104#endif
105 105
106#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ 106#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
107# include <sys/mnttab.h> 107# include <sys/mnttab.h>
108#endif 108#endif
109 109
110#ifdef MOUNTED_VMOUNT /* AIX. */ 110#ifdef MOUNTED_VMOUNT /* AIX. */
111# include <fshelp.h> 111# include <fshelp.h>
112# include <sys/vfs.h> 112# include <sys/vfs.h>
113#endif 113#endif
@@ -125,7 +125,7 @@
125 125
126#undef MNT_IGNORE 126#undef MNT_IGNORE
127#if defined MNTOPT_IGNORE && defined HAVE_HASMNTOPT 127#if defined MNTOPT_IGNORE && defined HAVE_HASMNTOPT
128# define MNT_IGNORE(M) hasmntopt ((M), MNTOPT_IGNORE) 128# define MNT_IGNORE(M) hasmntopt (M, MNTOPT_IGNORE)
129#else 129#else
130# define MNT_IGNORE(M) 0 130# define MNT_IGNORE(M) 0
131#endif 131#endif
@@ -145,26 +145,26 @@
145#undef closedir 145#undef closedir
146 146
147#ifndef ME_DUMMY 147#ifndef ME_DUMMY
148# define ME_DUMMY(Fs_name, Fs_type) \ 148# define ME_DUMMY(Fs_name, Fs_type) \
149 (strcmp (Fs_type, "autofs") == 0 \ 149 (strcmp (Fs_type, "autofs") == 0 \
150 || strcmp (Fs_type, "none") == 0 \ 150 || strcmp (Fs_type, "none") == 0 \
151 || strcmp (Fs_type, "proc") == 0 \ 151 || strcmp (Fs_type, "proc") == 0 \
152 || strcmp (Fs_type, "subfs") == 0 \ 152 || strcmp (Fs_type, "subfs") == 0 \
153 /* for NetBSD 3.0 */ \ 153 /* for NetBSD 3.0 */ \
154 || strcmp (Fs_type, "kernfs") == 0 \ 154 || strcmp (Fs_type, "kernfs") == 0 \
155 /* for Irix 6.5 */ \ 155 /* for Irix 6.5 */ \
156 || strcmp (Fs_type, "ignore") == 0) 156 || strcmp (Fs_type, "ignore") == 0)
157#endif 157#endif
158 158
159#ifndef ME_REMOTE 159#ifndef ME_REMOTE
160/* A file system is `remote' if its Fs_name contains a `:' 160/* A file system is `remote' if its Fs_name contains a `:'
161 or if (it is of type (smbfs or cifs) and its Fs_name starts with `//'). */ 161 or if (it is of type (smbfs or cifs) and its Fs_name starts with `//'). */
162# define ME_REMOTE(Fs_name, Fs_type) \ 162# define ME_REMOTE(Fs_name, Fs_type) \
163 (strchr (Fs_name, ':') != NULL \ 163 (strchr (Fs_name, ':') != NULL \
164 || ((Fs_name)[0] == '/' \ 164 || ((Fs_name)[0] == '/' \
165 && (Fs_name)[1] == '/' \ 165 && (Fs_name)[1] == '/' \
166 && (strcmp (Fs_type, "smbfs") == 0 \ 166 && (strcmp (Fs_type, "smbfs") == 0 \
167 || strcmp (Fs_type, "cifs") == 0))) 167 || strcmp (Fs_type, "cifs") == 0)))
168#endif 168#endif
169 169
170#if MOUNTED_GETMNTINFO 170#if MOUNTED_GETMNTINFO
@@ -277,7 +277,7 @@ fsp_to_string (const struct statfs *fsp)
277 277
278#endif /* MOUNTED_GETMNTINFO */ 278#endif /* MOUNTED_GETMNTINFO */
279 279
280#ifdef MOUNTED_VMOUNT /* AIX. */ 280#ifdef MOUNTED_VMOUNT /* AIX. */
281static char * 281static char *
282fstype_to_string (int t) 282fstype_to_string (int t)
283{ 283{
@@ -315,10 +315,10 @@ dev_from_mount_options (char const *mount_options)
315 errno = 0; 315 errno = 0;
316 dev = strtoul (optval, &optvalend, 16); 316 dev = strtoul (optval, &optvalend, 16);
317 if (optval != optvalend 317 if (optval != optvalend
318 && (*optvalend == '\0' || *optvalend == ',') 318 && (*optvalend == '\0' || *optvalend == ',')
319 && ! (dev == ULONG_MAX && errno == ERANGE) 319 && ! (dev == ULONG_MAX && errno == ERANGE)
320 && dev == (dev_t) dev) 320 && dev == (dev_t) dev)
321 return dev; 321 return dev;
322 } 322 }
323 323
324# endif 324# endif
@@ -383,18 +383,18 @@ read_file_system_list (bool need_fs_type)
383 383
384 while ((mnt = getmntent (fp))) 384 while ((mnt = getmntent (fp)))
385 { 385 {
386 me = xmalloc (sizeof *me); 386 me = xmalloc (sizeof *me);
387 me->me_devname = xstrdup (mnt->mnt_fsname); 387 me->me_devname = xstrdup (mnt->mnt_fsname);
388 me->me_mountdir = xstrdup (mnt->mnt_dir); 388 me->me_mountdir = xstrdup (mnt->mnt_dir);
389 me->me_type = xstrdup (mnt->mnt_type); 389 me->me_type = xstrdup (mnt->mnt_type);
390 me->me_type_malloced = 1; 390 me->me_type_malloced = 1;
391 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 391 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
392 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 392 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
393 me->me_dev = dev_from_mount_options (mnt->mnt_opts); 393 me->me_dev = dev_from_mount_options (mnt->mnt_opts);
394 394
395 /* Add to the linked list. */ 395 /* Add to the linked list. */
396 *mtail = me; 396 *mtail = me;
397 mtail = &me->me_next; 397 mtail = &me->me_next;
398 } 398 }
399 399
400 if (endmntent (fp) == 0) 400 if (endmntent (fp) == 0)
@@ -402,7 +402,7 @@ read_file_system_list (bool need_fs_type)
402 } 402 }
403#endif /* MOUNTED_GETMNTENT1. */ 403#endif /* MOUNTED_GETMNTENT1. */
404 404
405#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ 405#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
406 { 406 {
407 struct statfs *fsp; 407 struct statfs *fsp;
408 int entries; 408 int entries;
@@ -412,25 +412,25 @@ read_file_system_list (bool need_fs_type)
412 return NULL; 412 return NULL;
413 for (; entries-- > 0; fsp++) 413 for (; entries-- > 0; fsp++)
414 { 414 {
415 char *fs_type = fsp_to_string (fsp); 415 char *fs_type = fsp_to_string (fsp);
416 416
417 me = xmalloc (sizeof *me); 417 me = xmalloc (sizeof *me);
418 me->me_devname = xstrdup (fsp->f_mntfromname); 418 me->me_devname = xstrdup (fsp->f_mntfromname);
419 me->me_mountdir = xstrdup (fsp->f_mntonname); 419 me->me_mountdir = xstrdup (fsp->f_mntonname);
420 me->me_type = fs_type; 420 me->me_type = fs_type;
421 me->me_type_malloced = 0; 421 me->me_type_malloced = 0;
422 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 422 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
423 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 423 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
424 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 424 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
425 425
426 /* Add to the linked list. */ 426 /* Add to the linked list. */
427 *mtail = me; 427 *mtail = me;
428 mtail = &me->me_next; 428 mtail = &me->me_next;
429 } 429 }
430 } 430 }
431#endif /* MOUNTED_GETMNTINFO */ 431#endif /* MOUNTED_GETMNTINFO */
432 432
433#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ 433#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */
434 { 434 {
435 struct statvfs *fsp; 435 struct statvfs *fsp;
436 int entries; 436 int entries;
@@ -440,44 +440,44 @@ read_file_system_list (bool need_fs_type)
440 return NULL; 440 return NULL;
441 for (; entries-- > 0; fsp++) 441 for (; entries-- > 0; fsp++)
442 { 442 {
443 me = xmalloc (sizeof *me); 443 me = xmalloc (sizeof *me);
444 me->me_devname = xstrdup (fsp->f_mntfromname); 444 me->me_devname = xstrdup (fsp->f_mntfromname);
445 me->me_mountdir = xstrdup (fsp->f_mntonname); 445 me->me_mountdir = xstrdup (fsp->f_mntonname);
446 me->me_type = xstrdup (fsp->f_fstypename); 446 me->me_type = xstrdup (fsp->f_fstypename);
447 me->me_type_malloced = 1; 447 me->me_type_malloced = 1;
448 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 448 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
449 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 449 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
450 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 450 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
451 451
452 /* Add to the linked list. */ 452 /* Add to the linked list. */
453 *mtail = me; 453 *mtail = me;
454 mtail = &me->me_next; 454 mtail = &me->me_next;
455 } 455 }
456 } 456 }
457#endif /* MOUNTED_GETMNTINFO2 */ 457#endif /* MOUNTED_GETMNTINFO2 */
458 458
459#ifdef MOUNTED_GETMNT /* Ultrix. */ 459#ifdef MOUNTED_GETMNT /* Ultrix. */
460 { 460 {
461 int offset = 0; 461 int offset = 0;
462 int val; 462 int val;
463 struct fs_data fsd; 463 struct fs_data fsd;
464 464
465 while (errno = 0, 465 while (errno = 0,
466 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, 466 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
467 (char *) 0))) 467 (char *) 0)))
468 { 468 {
469 me = xmalloc (sizeof *me); 469 me = xmalloc (sizeof *me);
470 me->me_devname = xstrdup (fsd.fd_req.devname); 470 me->me_devname = xstrdup (fsd.fd_req.devname);
471 me->me_mountdir = xstrdup (fsd.fd_req.path); 471 me->me_mountdir = xstrdup (fsd.fd_req.path);
472 me->me_type = gt_names[fsd.fd_req.fstype]; 472 me->me_type = gt_names[fsd.fd_req.fstype];
473 me->me_type_malloced = 0; 473 me->me_type_malloced = 0;
474 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 474 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
475 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 475 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
476 me->me_dev = fsd.fd_req.dev; 476 me->me_dev = fsd.fd_req.dev;
477 477
478 /* Add to the linked list. */ 478 /* Add to the linked list. */
479 *mtail = me; 479 *mtail = me;
480 mtail = &me->me_next; 480 mtail = &me->me_next;
481 } 481 }
482 if (val < 0) 482 if (val < 0)
483 goto free_then_fail; 483 goto free_then_fail;
@@ -537,7 +537,7 @@ read_file_system_list (bool need_fs_type)
537 537
538 if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode)) 538 if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode))
539 { 539 {
540 struct rootdir_entry *re = xmalloc (sizeof *re); 540 struct rootdir_entry *re = xmalloc (sizeof *re);
541 re->name = name; 541 re->name = name;
542 re->dev = statbuf.st_dev; 542 re->dev = statbuf.st_dev;
543 re->ino = statbuf.st_ino; 543 re->ino = statbuf.st_ino;
@@ -563,11 +563,11 @@ read_file_system_list (bool need_fs_type)
563 if (re->dev == fi.dev && re->ino == fi.root) 563 if (re->dev == fi.dev && re->ino == fi.root)
564 break; 564 break;
565 565
566 me = xmalloc (sizeof *me); 566 me = xmalloc (sizeof *me);
567 me->me_devname = xstrdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name); 567 me->me_devname = xstrdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name);
568 me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name); 568 me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name);
569 me->me_type = xstrdup (fi.fsh_name); 569 me->me_type = xstrdup (fi.fsh_name);
570 me->me_type_malloced = 1; 570 me->me_type_malloced = 1;
571 me->me_dev = fi.dev; 571 me->me_dev = fi.dev;
572 me->me_dummy = 0; 572 me->me_dummy = 0;
573 me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; 573 me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0;
@@ -588,7 +588,7 @@ read_file_system_list (bool need_fs_type)
588 } 588 }
589#endif /* MOUNTED_FS_STAT_DEV */ 589#endif /* MOUNTED_FS_STAT_DEV */
590 590
591#if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */ 591#if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */
592 { 592 {
593 int numsys, counter; 593 int numsys, counter;
594 size_t bufsize; 594 size_t bufsize;
@@ -606,24 +606,24 @@ read_file_system_list (bool need_fs_type)
606 606
607 if (numsys < 0) 607 if (numsys < 0)
608 { 608 {
609 free (stats); 609 free (stats);
610 return (NULL); 610 return (NULL);
611 } 611 }
612 612
613 for (counter = 0; counter < numsys; counter++) 613 for (counter = 0; counter < numsys; counter++)
614 { 614 {
615 me = xmalloc (sizeof *me); 615 me = xmalloc (sizeof *me);
616 me->me_devname = xstrdup (stats[counter].f_mntfromname); 616 me->me_devname = xstrdup (stats[counter].f_mntfromname);
617 me->me_mountdir = xstrdup (stats[counter].f_mntonname); 617 me->me_mountdir = xstrdup (stats[counter].f_mntonname);
618 me->me_type = xstrdup (FS_TYPE (stats[counter])); 618 me->me_type = xstrdup (FS_TYPE (stats[counter]));
619 me->me_type_malloced = 1; 619 me->me_type_malloced = 1;
620 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 620 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
621 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 621 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
622 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 622 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
623 623
624 /* Add to the linked list. */ 624 /* Add to the linked list. */
625 *mtail = me; 625 *mtail = me;
626 mtail = &me->me_next; 626 mtail = &me->me_next;
627 } 627 }
628 628
629 free (stats); 629 free (stats);
@@ -642,47 +642,47 @@ read_file_system_list (bool need_fs_type)
642 642
643 while (fread (&mnt, sizeof mnt, 1, fp) > 0) 643 while (fread (&mnt, sizeof mnt, 1, fp) > 0)
644 { 644 {
645 me = xmalloc (sizeof *me); 645 me = xmalloc (sizeof *me);
646# ifdef GETFSTYP /* SVR3. */ 646# ifdef GETFSTYP /* SVR3. */
647 me->me_devname = xstrdup (mnt.mt_dev); 647 me->me_devname = xstrdup (mnt.mt_dev);
648# else 648# else
649 me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6); 649 me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6);
650 strcpy (me->me_devname, "/dev/"); 650 strcpy (me->me_devname, "/dev/");
651 strcpy (me->me_devname + 5, mnt.mt_dev); 651 strcpy (me->me_devname + 5, mnt.mt_dev);
652# endif 652# endif
653 me->me_mountdir = xstrdup (mnt.mt_filsys); 653 me->me_mountdir = xstrdup (mnt.mt_filsys);
654 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 654 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
655 me->me_type = ""; 655 me->me_type = "";
656 me->me_type_malloced = 0; 656 me->me_type_malloced = 0;
657# ifdef GETFSTYP /* SVR3. */ 657# ifdef GETFSTYP /* SVR3. */
658 if (need_fs_type) 658 if (need_fs_type)
659 { 659 {
660 struct statfs fsd; 660 struct statfs fsd;
661 char typebuf[FSTYPSZ]; 661 char typebuf[FSTYPSZ];
662 662
663 if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1 663 if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1
664 && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1) 664 && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1)
665 { 665 {
666 me->me_type = xstrdup (typebuf); 666 me->me_type = xstrdup (typebuf);
667 me->me_type_malloced = 1; 667 me->me_type_malloced = 1;
668 } 668 }
669 } 669 }
670# endif 670# endif
671 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 671 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
672 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 672 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
673 673
674 /* Add to the linked list. */ 674 /* Add to the linked list. */
675 *mtail = me; 675 *mtail = me;
676 mtail = &me->me_next; 676 mtail = &me->me_next;
677 } 677 }
678 678
679 if (ferror (fp)) 679 if (ferror (fp))
680 { 680 {
681 /* The last fread() call must have failed. */ 681 /* The last fread() call must have failed. */
682 int saved_errno = errno; 682 int saved_errno = errno;
683 fclose (fp); 683 fclose (fp);
684 errno = saved_errno; 684 errno = saved_errno;
685 goto free_then_fail; 685 goto free_then_fail;
686 } 686 }
687 687
688 if (fclose (fp) == EOF) 688 if (fclose (fp) == EOF)
@@ -690,29 +690,29 @@ read_file_system_list (bool need_fs_type)
690 } 690 }
691#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */ 691#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */
692 692
693#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */ 693#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */
694 { 694 {
695 struct mntent **mnttbl = getmnttbl (), **ent; 695 struct mntent **mnttbl = getmnttbl (), **ent;
696 for (ent=mnttbl;*ent;ent++) 696 for (ent=mnttbl;*ent;ent++)
697 { 697 {
698 me = xmalloc (sizeof *me); 698 me = xmalloc (sizeof *me);
699 me->me_devname = xstrdup ( (*ent)->mt_resource); 699 me->me_devname = xstrdup ( (*ent)->mt_resource);
700 me->me_mountdir = xstrdup ( (*ent)->mt_directory); 700 me->me_mountdir = xstrdup ( (*ent)->mt_directory);
701 me->me_type = xstrdup ((*ent)->mt_fstype); 701 me->me_type = xstrdup ((*ent)->mt_fstype);
702 me->me_type_malloced = 1; 702 me->me_type_malloced = 1;
703 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); 703 me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
704 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 704 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
705 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ 705 me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
706 706
707 /* Add to the linked list. */ 707 /* Add to the linked list. */
708 *mtail = me; 708 *mtail = me;
709 mtail = &me->me_next; 709 mtail = &me->me_next;
710 } 710 }
711 endmnttbl (); 711 endmnttbl ();
712 } 712 }
713#endif 713#endif
714 714
715#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ 715#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
716 { 716 {
717 struct mnttab mnt; 717 struct mnttab mnt;
718 char *table = MNTTAB; 718 char *table = MNTTAB;
@@ -731,19 +731,19 @@ read_file_system_list (bool need_fs_type)
731 lockfd = open (MNTTAB_LOCK, O_RDONLY); 731 lockfd = open (MNTTAB_LOCK, O_RDONLY);
732 if (0 <= lockfd) 732 if (0 <= lockfd)
733 { 733 {
734 struct flock flock; 734 struct flock flock;
735 flock.l_type = F_RDLCK; 735 flock.l_type = F_RDLCK;
736 flock.l_whence = SEEK_SET; 736 flock.l_whence = SEEK_SET;
737 flock.l_start = 0; 737 flock.l_start = 0;
738 flock.l_len = 0; 738 flock.l_len = 0;
739 while (fcntl (lockfd, F_SETLKW, &flock) == -1) 739 while (fcntl (lockfd, F_SETLKW, &flock) == -1)
740 if (errno != EINTR) 740 if (errno != EINTR)
741 { 741 {
742 int saved_errno = errno; 742 int saved_errno = errno;
743 close (lockfd); 743 close (lockfd);
744 errno = saved_errno; 744 errno = saved_errno;
745 return NULL; 745 return NULL;
746 } 746 }
747 } 747 }
748 else if (errno != ENOENT) 748 else if (errno != ENOENT)
749 return NULL; 749 return NULL;
@@ -755,23 +755,23 @@ read_file_system_list (bool need_fs_type)
755 ret = errno; 755 ret = errno;
756 else 756 else
757 { 757 {
758 while ((ret = getmntent (fp, &mnt)) == 0) 758 while ((ret = getmntent (fp, &mnt)) == 0)
759 { 759 {
760 me = xmalloc (sizeof *me); 760 me = xmalloc (sizeof *me);
761 me->me_devname = xstrdup (mnt.mnt_special); 761 me->me_devname = xstrdup (mnt.mnt_special);
762 me->me_mountdir = xstrdup (mnt.mnt_mountp); 762 me->me_mountdir = xstrdup (mnt.mnt_mountp);
763 me->me_type = xstrdup (mnt.mnt_fstype); 763 me->me_type = xstrdup (mnt.mnt_fstype);
764 me->me_type_malloced = 1; 764 me->me_type_malloced = 1;
765 me->me_dummy = MNT_IGNORE (&mnt) != 0; 765 me->me_dummy = MNT_IGNORE (&mnt) != 0;
766 me->me_remote = ME_REMOTE (me->me_devname, me->me_type); 766 me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
767 me->me_dev = dev_from_mount_options (mnt.mnt_mntopts); 767 me->me_dev = dev_from_mount_options (mnt.mnt_mntopts);
768 768
769 /* Add to the linked list. */ 769 /* Add to the linked list. */
770 *mtail = me; 770 *mtail = me;
771 mtail = &me->me_next; 771 mtail = &me->me_next;
772 } 772 }
773 773
774 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1; 774 ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1;
775 } 775 }
776 776
777 if (0 <= lockfd && close (lockfd) != 0) 777 if (0 <= lockfd && close (lockfd) != 0)
@@ -779,13 +779,13 @@ read_file_system_list (bool need_fs_type)
779 779
780 if (0 <= ret) 780 if (0 <= ret)
781 { 781 {
782 errno = ret; 782 errno = ret;
783 goto free_then_fail; 783 goto free_then_fail;
784 } 784 }
785 } 785 }
786#endif /* MOUNTED_GETMNTENT2. */ 786#endif /* MOUNTED_GETMNTENT2. */
787 787
788#ifdef MOUNTED_VMOUNT /* AIX. */ 788#ifdef MOUNTED_VMOUNT /* AIX. */
789 { 789 {
790 int bufsize; 790 int bufsize;
791 char *entries, *thisent; 791 char *entries, *thisent;
@@ -802,53 +802,53 @@ read_file_system_list (bool need_fs_type)
802 n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); 802 n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries);
803 if (n_entries < 0) 803 if (n_entries < 0)
804 { 804 {
805 int saved_errno = errno; 805 int saved_errno = errno;
806 free (entries); 806 free (entries);
807 errno = saved_errno; 807 errno = saved_errno;
808 return NULL; 808 return NULL;
809 } 809 }
810 810
811 for (i = 0, thisent = entries; 811 for (i = 0, thisent = entries;
812 i < n_entries; 812 i < n_entries;
813 i++, thisent += vmp->vmt_length) 813 i++, thisent += vmp->vmt_length)
814 { 814 {
815 char *options, *ignore; 815 char *options, *ignore;
816 816
817 vmp = (struct vmount *) thisent; 817 vmp = (struct vmount *) thisent;
818 me = xmalloc (sizeof *me); 818 me = xmalloc (sizeof *me);
819 if (vmp->vmt_flags & MNT_REMOTE) 819 if (vmp->vmt_flags & MNT_REMOTE)
820 { 820 {
821 char *host, *dir; 821 char *host, *dir;
822 822
823 me->me_remote = 1; 823 me->me_remote = 1;
824 /* Prepend the remote dirname. */ 824 /* Prepend the remote dirname. */
825 host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; 825 host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off;
826 dir = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; 826 dir = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off;
827 me->me_devname = xmalloc (strlen (host) + strlen (dir) + 2); 827 me->me_devname = xmalloc (strlen (host) + strlen (dir) + 2);
828 strcpy (me->me_devname, host); 828 strcpy (me->me_devname, host);
829 strcat (me->me_devname, ":"); 829 strcat (me->me_devname, ":");
830 strcat (me->me_devname, dir); 830 strcat (me->me_devname, dir);
831 } 831 }
832 else 832 else
833 { 833 {
834 me->me_remote = 0; 834 me->me_remote = 0;
835 me->me_devname = xstrdup (thisent + 835 me->me_devname = xstrdup (thisent +
836 vmp->vmt_data[VMT_OBJECT].vmt_off); 836 vmp->vmt_data[VMT_OBJECT].vmt_off);
837 } 837 }
838 me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); 838 me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
839 me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype)); 839 me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
840 me->me_type_malloced = 1; 840 me->me_type_malloced = 1;
841 options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; 841 options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off;
842 ignore = strstr (options, "ignore"); 842 ignore = strstr (options, "ignore");
843 me->me_dummy = (ignore 843 me->me_dummy = (ignore
844 && (ignore == options || ignore[-1] == ',') 844 && (ignore == options || ignore[-1] == ',')
845 && (ignore[sizeof "ignore" - 1] == ',' 845 && (ignore[sizeof "ignore" - 1] == ','
846 || ignore[sizeof "ignore" - 1] == '\0')); 846 || ignore[sizeof "ignore" - 1] == '\0'));
847 me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */ 847 me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */
848 848
849 /* Add to the linked list. */ 849 /* Add to the linked list. */
850 *mtail = me; 850 *mtail = me;
851 mtail = &me->me_next; 851 mtail = &me->me_next;
852 } 852 }
853 free (entries); 853 free (entries);
854 } 854 }
@@ -865,13 +865,13 @@ read_file_system_list (bool need_fs_type)
865 865
866 while (mount_list) 866 while (mount_list)
867 { 867 {
868 me = mount_list->me_next; 868 me = mount_list->me_next;
869 free (mount_list->me_devname); 869 free (mount_list->me_devname);
870 free (mount_list->me_mountdir); 870 free (mount_list->me_mountdir);
871 if (mount_list->me_type_malloced) 871 if (mount_list->me_type_malloced)
872 free (mount_list->me_type); 872 free (mount_list->me_type);
873 free (mount_list); 873 free (mount_list);
874 mount_list = me; 874 mount_list = me;
875 } 875 }
876 876
877 errno = saved_errno; 877 errno = saved_errno;