Commit | Line | Data |
---|---|---|
e1a31032 | 1 | /* |
e1a31032 KM |
2 | * Copyright (c) 1990 Jan-Simon Pendry |
3 | * Copyright (c) 1990 Imperial College of Science, Technology & Medicine | |
ad787160 C |
4 | * Copyright (c) 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | |
e1a31032 KM |
6 | * |
7 | * This code is derived from software contributed to Berkeley by | |
8 | * Jan-Simon Pendry at Imperial College, London. | |
9 | * | |
ad787160 C |
10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | |
15 | * 2. Redistributions in binary form must reproduce the above copyright | |
16 | * notice, this list of conditions and the following disclaimer in the | |
17 | * documentation and/or other materials provided with the distribution. | |
18 | * 3. All advertising materials mentioning features or use of this software | |
19 | * must display the following acknowledgement: | |
20 | * This product includes software developed by the University of | |
21 | * California, Berkeley and its contributors. | |
22 | * 4. Neither the name of the University nor the names of its contributors | |
23 | * may be used to endorse or promote products derived from this software | |
24 | * without specific prior written permission. | |
e1a31032 | 25 | * |
ad787160 C |
26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
36 | * SUCH DAMAGE. | |
37 | * | |
38 | * @(#)mtab_aix.c 8.1 (Berkeley) 6/6/93 | |
8d2991d5 | 39 | * |
332f0791 | 40 | * $Id: mtab_aix.c,v 5.2.2.1 1992/02/09 15:10:07 jsp beta $ |
8d2991d5 | 41 | * |
e1a31032 KM |
42 | */ |
43 | ||
44 | #include "am.h" | |
45 | ||
46 | #ifdef READ_MTAB_AIX3_STYLE | |
47 | ||
48 | #include <sys/mntctl.h> | |
49 | #include <sys/vmount.h> | |
50 | ||
51 | static struct mntent *mnt_dup(mp) | |
52 | struct vmount *mp; | |
53 | { | |
54 | struct mntent *new_mp = ALLOC(mntent); | |
55 | ||
56 | char *ty; | |
57 | new_mp->mnt_fsname = strdup(vmt2dataptr(mp, VMT_OBJECT)); | |
58 | new_mp->mnt_dir = strdup(vmt2dataptr(mp, VMT_STUB)); | |
59 | new_mp->mnt_opts = strdup(vmt2dataptr(mp, VMT_ARGS)); | |
60 | switch (mp->vmt_gfstype) { | |
61 | case MNT_JFS: ty = MTAB_TYPE_UFS; break; | |
2f619045 JSP |
62 | case MNT_NFS: |
63 | ty = MTAB_TYPE_NFS; | |
64 | new_mp->mnt_fsname = str3cat(new_mp->mnt_fsname, | |
65 | vmt2dataptr(mp, VMT_HOSTNAME), | |
66 | ":", new_mp->mnt_fsname); | |
67 | break; | |
e1a31032 KM |
68 | default: ty = "unknown"; break; |
69 | } | |
70 | new_mp->mnt_type = strdup(ty); | |
71 | new_mp->mnt_passno = mp->vmt_vfsnumber; | |
72 | new_mp->mnt_freq = 0; | |
73 | ||
74 | return new_mp; | |
75 | } | |
76 | ||
77 | /* | |
78 | * Read a mount table into memory | |
79 | */ | |
80 | mntlist *read_mtab(fs) | |
81 | char *fs; | |
82 | { | |
83 | mntlist **mpp, *mhp; | |
84 | ||
85 | int i; | |
86 | char *mntinfo = 0, *cp; | |
87 | struct vmount *vp; | |
88 | int ret; | |
89 | ||
90 | /* | |
91 | * First figure out size of mount table | |
92 | * and allocate space for a copy... | |
93 | * Then get mount table for real. | |
94 | */ | |
95 | ret = mntctl(MCTL_QUERY, sizeof(i), &i); | |
96 | if (ret == 0) { | |
97 | mntinfo = xmalloc(i); | |
98 | ret = mntctl(MCTL_QUERY, i, mntinfo); | |
99 | } | |
100 | ||
101 | if (ret <= 0) { | |
102 | plog(XLOG_ERROR, "mntctl: %m"); | |
103 | goto out; | |
104 | } | |
105 | #ifdef DEBUG | |
106 | /*dlog("mntctl returns %d structures", ret);*/ | |
107 | #endif /* DEBUG */ | |
108 | ||
109 | mpp = &mhp; | |
110 | for (i = 0, cp = mntinfo; i < ret; i++, cp += vp->vmt_length) { | |
111 | vp = (struct vmount *) cp; | |
112 | ||
113 | /* | |
114 | * Allocate a new slot | |
115 | */ | |
116 | *mpp = ALLOC(mntlist); | |
117 | ||
118 | /* | |
119 | * Copy the data returned by mntctl | |
120 | */ | |
121 | (*mpp)->mnt = mnt_dup(vp); | |
122 | ||
123 | /* | |
124 | * Move to next pointer | |
125 | */ | |
126 | mpp = &(*mpp)->mnext; | |
127 | } | |
128 | ||
129 | *mpp = 0; | |
130 | ||
131 | out: | |
132 | if (mntinfo) | |
133 | free(mntinfo); | |
134 | return mhp; | |
135 | } | |
136 | ||
137 | #endif /* READ_MTAB_AIX3_STYLE */ |