4 * Copyright (c) 1997-2009 Erez Zadok
5 * Copyright (c) 1990 Jan-Simon Pendry
6 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7 * Copyright (c) 1990 The Regents of the University of California.
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgment:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * File: am-utils/amd/ops_udf.c
52 #endif /* HAVE_CONFIG_H */
56 /* forward definitions */
57 static char *udf_match(am_opts
*fo
);
58 static int udf_mount(am_node
*am
, mntfs
*mf
);
59 static int udf_umount(am_node
*am
, mntfs
*mf
);
71 amfs_error_lookup_child
,
72 amfs_error_mount_child
,
77 amfs_generic_find_srvr
,
78 0, /* udf_get_wchan */
79 FS_MKMNT
| FS_UBACKGROUND
| FS_AMQINFO
, /* nfs_fs_flags */
82 #endif /* HAVE_FS_AUTOFS */
85 #if defined(HAVE_UDF_ARGS_T_NOBODY_GID) || defined(HAVE_UDF_ARGS_T_NOBODY_UID)
87 a_num(const char *s
, const char *id_type
)
92 id
= strtol(s
, &ep
, 0);
93 if (*ep
|| s
== ep
|| id
< 0) {
94 plog(XLOG_ERROR
, "mount_udf: unknown %s: %s", id_type
, s
);
99 #endif /* defined(HAVE_UDF_ARGS_T_NOBODY_GID) || defined(HAVE_UDF_ARGS_T_NOBODY_UID) */
101 #if defined(HAVE_UDF_ARGS_T_NOBODY_GID)
103 a_gid(const char *s
, const char *id_type
)
107 if ((gr
= getgrnam(s
)) != NULL
)
109 return a_num(s
, id_type
);
111 #endif /* defined(HAVE_UDF_ARGS_T_NOBODY_GID) */
113 #if defined(HAVE_UDF_ARGS_T_NOBODY_UID)
115 a_uid(const char *s
, const char *id_type
)
119 if ((pw
= getpwnam(s
)) != NULL
)
121 return a_num(s
, id_type
);
123 #endif /* defined(HAVE_UDF_ARGS_T_NOBODY_UID) */
126 * UDF needs remote filesystem.
129 udf_match(am_opts
*fo
)
133 plog(XLOG_USER
, "udf: no source device specified");
136 dlog("UDF: mounting device \"%s\" on \"%s\"", fo
->opt_dev
, fo
->opt_fs
);
139 * Determine magic cookie to put in mtab
141 return strdup(fo
->opt_dev
);
145 mount_udf(char *mntdir
, char *fs_name
, char *opts
, int on_autofs
)
151 #if defined(HAVE_UDF_ARGS_T_NOBODY_UID) || defined(HAVE_UDF_ARGS_T_ANON_UID)
154 #endif /* defined(HAVE_UDF_ARGS_T_NOBODY_UID) || defined(HAVE_UDF_ARGS_T_ANON_UID) */
156 * Figure out the name of the file system type.
158 MTYPE_TYPE type
= MOUNT_TYPE_UDF
;
160 #if defined(HAVE_UDF_ARGS_T_NOBODY_UID) || defined(HAVE_UDF_ARGS_T_ANON_UID)
161 uid_nobody
= a_uid("nobody", "user");
162 if (uid_nobody
== 0) {
163 plog(XLOG_ERROR
, "mount_udf: invalid uid for nobody");
166 #endif /* defined(HAVE_UDF_ARGS_T_NOBODY_UID) || defined(HAVE_UDF_ARGS_T_ANON_UID) */
168 #if defined(HAVE_UDF_ARGS_T_NOBODY_GID) || defined(HAVE_UDF_ARGS_T_ANON_GID)
169 gid_nobody
= a_gid("nobody", "group");
170 if (gid_nobody
== 0) {
171 plog(XLOG_ERROR
, "mount_udf: invalid gid for nobody");
174 #endif /* defined(HAVE_UDF_ARGS_T_NOBODY_GID) || defined(HAVE_UDF_ARGS_T_ANON_GID) */
177 memset((voidp
) &udf_args
, 0, sizeof(udf_args
)); /* Paranoid */
180 * Fill in the mount structure
182 memset((voidp
)&mnt
, 0, sizeof(mnt
));
183 mnt
.mnt_dir
= mntdir
;
184 mnt
.mnt_fsname
= fs_name
;
185 mnt
.mnt_type
= MNTTAB_TYPE_UDF
;
188 flags
= compute_mount_flags(&mnt
);
190 #ifdef HAVE_UDF_ARGS_T_UDFMFLAGS
191 # if defined(MNT2_UDF_OPT_CLOSESESSION) && defined(MNTTAB_OPT_CLOSESESSION)
192 if (amu_hasmntopt(&mnt
, MNTTAB_OPT_CLOSESESSION
))
193 udf_args
.udfmflags
|= MNT2_UDF_OPT_CLOSESESSION
;
194 # endif /* defined(MNT2_UDF_OPT_CLOSESESSION) && defined(MNTTAB_OPT_CLOSESESSION) */
195 #endif /* HAVE_UDF_ARGS_T_UDFMFLAGS */
197 #ifdef HAVE_UDF_ARGS_T_NOBODY_UID
198 udf_args
.nobody_uid
= uid_nobody
;
199 #endif /* HAVE_UDF_ARGS_T_NOBODY_UID */
201 #ifdef HAVE_UDF_ARGS_T_NOBODY_GID
202 udf_args
.nobody_gid
= gid_nobody
;
203 #endif /* HAVE_UDF_ARGS_T_NOBODY_GID */
205 #ifdef HAVE_UDF_ARGS_T_ANON_UID
206 udf_args
.anon_uid
= uid_nobody
; /* default to nobody */
207 if ((str
= hasmntstr(&mnt
, MNTTAB_OPT_USER
)) != NULL
) {
208 udf_args
.anon_uid
= a_uid(str
, MNTTAB_OPT_USER
);
211 #endif /* HAVE_UDF_ARGS_T_ANON_UID */
213 #ifdef HAVE_UDF_ARGS_T_ANON_GID
214 udf_args
.anon_gid
= gid_nobody
; /* default to nobody */
215 if ((str
= hasmntstr(&mnt
, MNTTAB_OPT_GROUP
)) != NULL
) {
216 udf_args
.anon_gid
= a_gid(str
, MNTTAB_OPT_GROUP
);
219 #endif /* HAVE_UDF_ARGS_T_ANON_GID */
221 #ifdef HAVE_UDF_ARGS_T_GMTOFF
223 if ((str
= hasmntstr(&mnt
, MNTTAB_OPT_GMTOFF
)) != NULL
) {
224 udf_args
.gmtoff
= a_num(str
, MNTTAB_OPT_GMTOFF
);
227 #endif /* HAVE_UDF_ARGS_T_GMTOFF */
229 #ifdef HAVE_UDF_ARGS_T_SESSIONNR
230 udf_args
.sessionnr
= 0;
231 if ((str
= hasmntstr(&mnt
, MNTTAB_OPT_SESSIONNR
)) != NULL
) {
232 udf_args
.sessionnr
= a_num(str
, MNTTAB_OPT_SESSIONNR
);
235 #endif /* HAVE_UDF_ARGS_T_SESSIONNR */
237 #ifdef HAVE_UDF_ARGS_T_VERSION
238 # ifdef UDFMNT_VERSION
239 udf_args
.version
= UDFMNT_VERSION
;
240 # endif /* UDFMNT_VERSION */
241 #endif /* HAVE_UDF_ARGS_T_VERSION */
243 #ifdef HAVE_UFS_ARGS_T_FSPEC
244 udf_args
.fspec
= fs_name
;
245 #endif /* HAVE_UFS_ARGS_T_FSPEC */
248 * Call generic mount routine
250 return mount_fs(&mnt
, flags
, (caddr_t
)&udf_args
, 0, type
, 0, NULL
,
251 mnttab_file_name
, on_autofs
);
255 udf_mount(am_node
*am
, mntfs
*mf
)
260 on_autofs
= mf
->mf_flags
& MFF_ON_AUTOFS
;
261 error
= mount_udf(mf
->mf_mount
, mf
->mf_info
, mf
->mf_mopts
, on_autofs
);
264 plog(XLOG_ERROR
, "mount_udf: %m");
272 udf_umount(am_node
*am
, mntfs
*mf
)
276 unmount_flags
= (mf
->mf_flags
& MFF_ON_AUTOFS
) ? AMU_UMOUNT_AUTOFS
: 0;
277 return UMOUNT_FS(mf
->mf_mount
, mnttab_file_name
, unmount_flags
);