Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /*- |
2 | * Copyright (c) 1980, 1989, 1993 | |
3 | * The Regents of the University of California. All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 4. Neither the name of the University nor the names of its contributors | |
14 | * may be used to endorse or promote products derived from this software | |
15 | * without specific prior written permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
27 | * SUCH DAMAGE. | |
28 | */ | |
29 | ||
30 | #include <afsconfig.h> | |
31 | #include <afs/param.h> | |
32 | ||
33 | #include <roken.h> | |
34 | ||
35 | #if defined(AFS_DARWIN_ENV) | |
36 | /* | |
37 | * Reworked from FreeBSD umount | |
38 | */ | |
39 | ||
40 | #include <sys/mount.h> | |
41 | #include <fstab.h> | |
42 | ||
43 | size_t | |
44 | mntinfo(struct statfs **mntbuffer) | |
45 | { | |
46 | static struct statfs *origbuf; | |
47 | size_t bufsize; | |
48 | int mntsize; | |
49 | ||
50 | mntsize = getfsstat(NULL, 0, MNT_NOWAIT); | |
51 | if (mntsize <= 0) | |
52 | return (0); | |
53 | bufsize = (mntsize + 1) * sizeof(struct statfs); | |
54 | if ((origbuf = malloc(bufsize)) == NULL) | |
55 | err(1, "malloc"); | |
56 | mntsize = getfsstat(origbuf, (long)bufsize, MNT_NOWAIT); | |
57 | *mntbuffer = origbuf; | |
58 | return (mntsize); | |
59 | } | |
60 | ||
61 | static struct statfs *mntbuf = NULL; | |
62 | static struct statfs *mntent; | |
63 | static int mntcnt; | |
64 | static struct fstab fstabent; | |
65 | ||
66 | struct fstab * | |
67 | getfsent(void) | |
68 | { | |
69 | if (((!mntbuf) && !setfsent()) || mntcnt == 0) | |
70 | return (NULL); | |
71 | fstabent.fs_file = mntent->f_mntonname; | |
72 | fstabent.fs_freq = fstabent.fs_passno = 0; | |
73 | fstabent.fs_mntops = mntent->f_fstypename; | |
74 | fstabent.fs_spec = mntent->f_mntfromname; | |
75 | if (mntent->f_flags & MNT_RDONLY) | |
76 | fstabent.fs_type = FSTAB_RO; | |
77 | else | |
78 | fstabent.fs_type = FSTAB_RW; | |
79 | fstabent.fs_vfstype = mntent->f_fstypename; | |
80 | ||
81 | mntent++; | |
82 | mntcnt--; | |
83 | return &fstabent; | |
84 | } | |
85 | ||
86 | int | |
87 | setfsent(void) | |
88 | { | |
89 | if (mntbuf) | |
90 | free(mntbuf); | |
91 | mntbuf = NULL; | |
92 | mntent = 0; | |
93 | if ((mntcnt = mntinfo(&mntbuf)) <= 0) { | |
94 | err(1, "setfsent"); | |
95 | return 0; | |
96 | } | |
97 | mntent = mntbuf; | |
98 | return 1; | |
99 | } | |
100 | ||
101 | void | |
102 | endfsent(void) | |
103 | { | |
104 | if (mntbuf) | |
105 | free(mntbuf); | |
106 | mntbuf = NULL; | |
107 | mntent = 0; | |
108 | mntcnt = 0; | |
109 | } | |
110 | #endif |