diff options
Diffstat (limited to 'lib/mountlist.c')
-rw-r--r-- | lib/mountlist.c | 114 |
1 files changed, 49 insertions, 65 deletions
diff --git a/lib/mountlist.c b/lib/mountlist.c index 631be312..70d4edb2 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c | |||
@@ -1,5 +1,7 @@ | |||
1 | /* mountlist.c -- return a list of mounted filesystems | 1 | /* mountlist.c -- return a list of mounted file systems |
2 | Copyright (C) 1991, 1992, 1997-2004 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 1991, 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, | ||
4 | 2004, 2005 Free Software Foundation, Inc. | ||
3 | 5 | ||
4 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -13,39 +15,29 @@ | |||
13 | 15 | ||
14 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software Foundation, | 17 | along with this program; if not, write to the Free Software Foundation, |
16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
17 | 19 | ||
18 | #if HAVE_CONFIG_H | 20 | #ifdef HAVE_CONFIG_H |
19 | # include <config.h> | 21 | # include <config.h> |
20 | #endif | 22 | #endif |
21 | 23 | ||
24 | #include "mountlist.h" | ||
25 | |||
22 | #include <stdio.h> | 26 | #include <stdio.h> |
23 | #include <sys/types.h> | ||
24 | #include <stdlib.h> | 27 | #include <stdlib.h> |
25 | #include <string.h> | 28 | #include <string.h> |
26 | 29 | ||
27 | #include "xalloc.h" | 30 | #include "xalloc.h" |
28 | 31 | ||
29 | #ifndef SIZE_MAX | ||
30 | # define SIZE_MAX ((size_t) -1) | ||
31 | #endif | ||
32 | |||
33 | #ifndef strstr | 32 | #ifndef strstr |
34 | char *strstr (); | 33 | char *strstr (); |
35 | #endif | 34 | #endif |
36 | 35 | ||
37 | #include <errno.h> | 36 | #include <errno.h> |
38 | #ifndef errno | ||
39 | extern int errno; | ||
40 | #endif | ||
41 | 37 | ||
42 | #ifdef HAVE_FCNTL_H | 38 | #include <fcntl.h> |
43 | # include <fcntl.h> | ||
44 | #endif | ||
45 | 39 | ||
46 | #ifdef HAVE_UNISTD_H | 40 | #include <unistd.h> |
47 | # include <unistd.h> | ||
48 | #endif | ||
49 | 41 | ||
50 | #if HAVE_SYS_PARAM_H | 42 | #if HAVE_SYS_PARAM_H |
51 | # include <sys/param.h> | 43 | # include <sys/param.h> |
@@ -140,42 +132,39 @@ extern int errno; | |||
140 | # define MNT_IGNORE(M) 0 | 132 | # define MNT_IGNORE(M) 0 |
141 | #endif | 133 | #endif |
142 | 134 | ||
143 | #include "mountlist.h" | 135 | #if USE_UNLOCKED_IO |
144 | #include "unlocked-io.h" | 136 | # include "unlocked-io.h" |
137 | #endif | ||
145 | 138 | ||
146 | #ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ | 139 | #ifndef SIZE_MAX |
147 | /* Return the value of the hexadecimal number represented by CP. | 140 | # define SIZE_MAX ((size_t) -1) |
148 | No prefix (like '0x') or suffix (like 'h') is expected to be | 141 | #endif |
149 | part of CP. */ | ||
150 | /* FIXME: this can overflow */ | ||
151 | 142 | ||
152 | static int | 143 | #ifndef ME_DUMMY |
153 | xatoi (char *cp) | 144 | # define ME_DUMMY(Fs_name, Fs_type) \ |
154 | { | 145 | (strcmp (Fs_type, "autofs") == 0 \ |
155 | int val; | 146 | || strcmp (Fs_type, "none") == 0 \ |
147 | || strcmp (Fs_type, "proc") == 0 \ | ||
148 | || strcmp (Fs_type, "subfs") == 0 \ | ||
149 | /* for Irix 6.5 */ \ | ||
150 | || strcmp (Fs_type, "ignore") == 0) | ||
151 | #endif | ||
156 | 152 | ||
157 | val = 0; | 153 | #ifndef ME_REMOTE |
158 | while (*cp) | 154 | /* A file system is `remote' if its Fs_name contains a `:' |
159 | { | 155 | or if (it is of type smbfs and its Fs_name starts with `//'). */ |
160 | if (*cp >= 'a' && *cp <= 'f') | 156 | # define ME_REMOTE(Fs_name, Fs_type) \ |
161 | val = val * 16 + *cp - 'a' + 10; | 157 | (strchr (Fs_name, ':') != 0 \ |
162 | else if (*cp >= 'A' && *cp <= 'F') | 158 | || ((Fs_name)[0] == '/' \ |
163 | val = val * 16 + *cp - 'A' + 10; | 159 | && (Fs_name)[1] == '/' \ |
164 | else if (*cp >= '0' && *cp <= '9') | 160 | && strcmp (Fs_type, "smbfs") == 0)) |
165 | val = val * 16 + *cp - '0'; | 161 | #endif |
166 | else | ||
167 | break; | ||
168 | cp++; | ||
169 | } | ||
170 | return val; | ||
171 | } | ||
172 | #endif /* MOUNTED_GETMNTENT1. */ | ||
173 | 162 | ||
174 | #if MOUNTED_GETMNTINFO | 163 | #if MOUNTED_GETMNTINFO |
175 | 164 | ||
176 | # if ! HAVE_F_FSTYPENAME_IN_STATFS | 165 | # if ! HAVE_F_FSTYPENAME_IN_STATFS |
177 | static char * | 166 | static char * |
178 | fstype_to_string (short t) | 167 | fstype_to_string (short int t) |
179 | { | 168 | { |
180 | switch (t) | 169 | switch (t) |
181 | { | 170 | { |
@@ -296,13 +285,13 @@ fstype_to_string (int t) | |||
296 | } | 285 | } |
297 | #endif /* MOUNTED_VMOUNT */ | 286 | #endif /* MOUNTED_VMOUNT */ |
298 | 287 | ||
299 | /* Return a list of the currently mounted filesystems, or NULL on error. | 288 | /* Return a list of the currently mounted file systems, or NULL on error. |
300 | Add each entry to the tail of the list so that they stay in order. | 289 | Add each entry to the tail of the list so that they stay in order. |
301 | If NEED_FS_TYPE is nonzero, ensure that the filesystem type fields in | 290 | If NEED_FS_TYPE is true, ensure that the file system type fields in |
302 | the returned list are valid. Otherwise, they might not be. */ | 291 | the returned list are valid. Otherwise, they might not be. */ |
303 | 292 | ||
304 | struct mount_entry * | 293 | struct mount_entry * |
305 | read_filesystem_list (int need_fs_type) | 294 | read_file_system_list (bool need_fs_type) |
306 | { | 295 | { |
307 | struct mount_entry *mount_list; | 296 | struct mount_entry *mount_list; |
308 | struct mount_entry *me; | 297 | struct mount_entry *me; |
@@ -360,12 +349,7 @@ read_filesystem_list (int need_fs_type) | |||
360 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 349 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
361 | devopt = strstr (mnt->mnt_opts, "dev="); | 350 | devopt = strstr (mnt->mnt_opts, "dev="); |
362 | if (devopt) | 351 | if (devopt) |
363 | { | 352 | me->me_dev = strtoul (devopt + 4, NULL, 16); |
364 | if (devopt[4] == '0' && (devopt[5] == 'x' || devopt[5] == 'X')) | ||
365 | me->me_dev = xatoi (devopt + 6); | ||
366 | else | ||
367 | me->me_dev = xatoi (devopt + 4); | ||
368 | } | ||
369 | else | 353 | else |
370 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 354 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ |
371 | 355 | ||
@@ -438,14 +422,14 @@ read_filesystem_list (int need_fs_type) | |||
438 | #if defined MOUNTED_FS_STAT_DEV /* BeOS */ | 422 | #if defined MOUNTED_FS_STAT_DEV /* BeOS */ |
439 | { | 423 | { |
440 | /* The next_dev() and fs_stat_dev() system calls give the list of | 424 | /* The next_dev() and fs_stat_dev() system calls give the list of |
441 | all filesystems, including the information returned by statvfs() | 425 | all file systems, including the information returned by statvfs() |
442 | (fs type, total blocks, free blocks etc.), but without the mount | 426 | (fs type, total blocks, free blocks etc.), but without the mount |
443 | point. But on BeOS all filesystems except / are mounted in the | 427 | point. But on BeOS all file systems except / are mounted in the |
444 | rootfs, directly under /. | 428 | rootfs, directly under /. |
445 | The directory name of the mount point is often, but not always, | 429 | The directory name of the mount point is often, but not always, |
446 | identical to the volume name of the device. | 430 | identical to the volume name of the device. |
447 | We therefore get the list of subdirectories of /, and the list | 431 | We therefore get the list of subdirectories of /, and the list |
448 | of all filesystems, and match the two lists. */ | 432 | of all file systems, and match the two lists. */ |
449 | 433 | ||
450 | DIR *dirp; | 434 | DIR *dirp; |
451 | struct rootdir_entry | 435 | struct rootdir_entry |
@@ -744,12 +728,12 @@ read_filesystem_list (int need_fs_type) | |||
744 | int n_entries; | 728 | int n_entries; |
745 | int i; | 729 | int i; |
746 | 730 | ||
747 | /* Ask how many bytes to allocate for the mounted filesystem info. */ | 731 | /* Ask how many bytes to allocate for the mounted file system info. */ |
748 | if (mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize) != 0) | 732 | if (mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize) != 0) |
749 | return NULL; | 733 | return NULL; |
750 | entries = xmalloc (bufsize); | 734 | entries = xmalloc (bufsize); |
751 | 735 | ||
752 | /* Get the list of mounted filesystems. */ | 736 | /* Get the list of mounted file systems. */ |
753 | n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); | 737 | n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); |
754 | if (n_entries < 0) | 738 | if (n_entries < 0) |
755 | { | 739 | { |
@@ -769,16 +753,16 @@ read_filesystem_list (int need_fs_type) | |||
769 | me = xmalloc (sizeof *me); | 753 | me = xmalloc (sizeof *me); |
770 | if (vmp->vmt_flags & MNT_REMOTE) | 754 | if (vmp->vmt_flags & MNT_REMOTE) |
771 | { | 755 | { |
772 | char *host, *path; | 756 | char *host, *dir; |
773 | 757 | ||
774 | me->me_remote = 1; | 758 | me->me_remote = 1; |
775 | /* Prepend the remote pathname. */ | 759 | /* Prepend the remote dirname. */ |
776 | host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; | 760 | host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; |
777 | path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; | 761 | dir = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; |
778 | me->me_devname = xmalloc (strlen (host) + strlen (path) + 2); | 762 | me->me_devname = xmalloc (strlen (host) + strlen (dir) + 2); |
779 | strcpy (me->me_devname, host); | 763 | strcpy (me->me_devname, host); |
780 | strcat (me->me_devname, ":"); | 764 | strcat (me->me_devname, ":"); |
781 | strcat (me->me_devname, path); | 765 | strcat (me->me_devname, dir); |
782 | } | 766 | } |
783 | else | 767 | else |
784 | { | 768 | { |