1*8bae5d40Schristos /* $NetBSD: ops_ext.c,v 1.1.1.1 2015/01/17 16:34:15 christos Exp $ */
2*8bae5d40Schristos
3*8bae5d40Schristos /*
4*8bae5d40Schristos * Copyright (c) 1997-2014 Erez Zadok
5*8bae5d40Schristos * Copyright (c) 1990 Jan-Simon Pendry
6*8bae5d40Schristos * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7*8bae5d40Schristos * Copyright (c) 1990 The Regents of the University of California.
8*8bae5d40Schristos * All rights reserved.
9*8bae5d40Schristos *
10*8bae5d40Schristos * This code is derived from software contributed to Berkeley by
11*8bae5d40Schristos * Jan-Simon Pendry at Imperial College, London.
12*8bae5d40Schristos *
13*8bae5d40Schristos * Redistribution and use in source and binary forms, with or without
14*8bae5d40Schristos * modification, are permitted provided that the following conditions
15*8bae5d40Schristos * are met:
16*8bae5d40Schristos * 1. Redistributions of source code must retain the above copyright
17*8bae5d40Schristos * notice, this list of conditions and the following disclaimer.
18*8bae5d40Schristos * 2. Redistributions in binary form must reproduce the above copyright
19*8bae5d40Schristos * notice, this list of conditions and the following disclaimer in the
20*8bae5d40Schristos * documentation and/or other materials provided with the distribution.
21*8bae5d40Schristos * 3. Neither the name of the University nor the names of its contributors
22*8bae5d40Schristos * may be used to endorse or promote products derived from this software
23*8bae5d40Schristos * without specific prior written permission.
24*8bae5d40Schristos *
25*8bae5d40Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26*8bae5d40Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27*8bae5d40Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28*8bae5d40Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29*8bae5d40Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30*8bae5d40Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31*8bae5d40Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32*8bae5d40Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33*8bae5d40Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34*8bae5d40Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35*8bae5d40Schristos * SUCH DAMAGE.
36*8bae5d40Schristos *
37*8bae5d40Schristos *
38*8bae5d40Schristos * File: am-utils/amd/ops_ext.c
39*8bae5d40Schristos *
40*8bae5d40Schristos */
41*8bae5d40Schristos
42*8bae5d40Schristos /*
43*8bae5d40Schristos * Irix UN*X file system: EXT (Extended File System)
44*8bae5d40Schristos */
45*8bae5d40Schristos
46*8bae5d40Schristos #ifdef HAVE_CONFIG_H
47*8bae5d40Schristos # include <config.h>
48*8bae5d40Schristos #endif /* HAVE_CONFIG_H */
49*8bae5d40Schristos #include <am_defs.h>
50*8bae5d40Schristos #include <amd.h>
51*8bae5d40Schristos
52*8bae5d40Schristos /* forward declarations */
53*8bae5d40Schristos static char *ext_match(am_opts *fo);
54*8bae5d40Schristos static int ext2_mount(am_node *am, mntfs *mf);
55*8bae5d40Schristos static int ext3_mount(am_node *am, mntfs *mf);
56*8bae5d40Schristos static int ext4_mount(am_node *am, mntfs *mf);
57*8bae5d40Schristos static int ext_umount(am_node *am, mntfs *mf);
58*8bae5d40Schristos
59*8bae5d40Schristos /*
60*8bae5d40Schristos * Ops structure
61*8bae5d40Schristos */
62*8bae5d40Schristos am_ops ext2_ops =
63*8bae5d40Schristos {
64*8bae5d40Schristos "ext2",
65*8bae5d40Schristos ext_match,
66*8bae5d40Schristos 0, /* ext_init */
67*8bae5d40Schristos ext2_mount,
68*8bae5d40Schristos ext_umount,
69*8bae5d40Schristos amfs_error_lookup_child,
70*8bae5d40Schristos amfs_error_mount_child,
71*8bae5d40Schristos amfs_error_readdir,
72*8bae5d40Schristos 0, /* ext_readlink */
73*8bae5d40Schristos 0, /* ext_mounted */
74*8bae5d40Schristos 0, /* ext_umounted */
75*8bae5d40Schristos amfs_generic_find_srvr,
76*8bae5d40Schristos 0, /* ext_get_wchan */
77*8bae5d40Schristos FS_MKMNT | FS_NOTIMEOUT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
78*8bae5d40Schristos #ifdef HAVE_FS_AUTOFS
79*8bae5d40Schristos AUTOFS_EXT_FS_FLAGS,
80*8bae5d40Schristos #endif /* HAVE_FS_AUTOFS */
81*8bae5d40Schristos };
82*8bae5d40Schristos
83*8bae5d40Schristos am_ops ext3_ops =
84*8bae5d40Schristos {
85*8bae5d40Schristos "ext3",
86*8bae5d40Schristos ext_match,
87*8bae5d40Schristos 0, /* ext_init */
88*8bae5d40Schristos ext3_mount,
89*8bae5d40Schristos ext_umount,
90*8bae5d40Schristos amfs_error_lookup_child,
91*8bae5d40Schristos amfs_error_mount_child,
92*8bae5d40Schristos amfs_error_readdir,
93*8bae5d40Schristos 0, /* ext_readlink */
94*8bae5d40Schristos 0, /* ext_mounted */
95*8bae5d40Schristos 0, /* ext_umounted */
96*8bae5d40Schristos amfs_generic_find_srvr,
97*8bae5d40Schristos 0, /* ext_get_wchan */
98*8bae5d40Schristos FS_MKMNT | FS_NOTIMEOUT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
99*8bae5d40Schristos #ifdef HAVE_FS_AUTOFS
100*8bae5d40Schristos AUTOFS_EXT_FS_FLAGS,
101*8bae5d40Schristos #endif /* HAVE_FS_AUTOFS */
102*8bae5d40Schristos };
103*8bae5d40Schristos
104*8bae5d40Schristos am_ops ext4_ops =
105*8bae5d40Schristos {
106*8bae5d40Schristos "ext4",
107*8bae5d40Schristos ext_match,
108*8bae5d40Schristos 0, /* ext_init */
109*8bae5d40Schristos ext4_mount,
110*8bae5d40Schristos ext_umount,
111*8bae5d40Schristos amfs_error_lookup_child,
112*8bae5d40Schristos amfs_error_mount_child,
113*8bae5d40Schristos amfs_error_readdir,
114*8bae5d40Schristos 0, /* ext_readlink */
115*8bae5d40Schristos 0, /* ext_mounted */
116*8bae5d40Schristos 0, /* ext_umounted */
117*8bae5d40Schristos amfs_generic_find_srvr,
118*8bae5d40Schristos 0, /* ext_get_wchan */
119*8bae5d40Schristos FS_MKMNT | FS_NOTIMEOUT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
120*8bae5d40Schristos #ifdef HAVE_FS_AUTOFS
121*8bae5d40Schristos AUTOFS_EXT_FS_FLAGS,
122*8bae5d40Schristos #endif /* HAVE_FS_AUTOFS */
123*8bae5d40Schristos };
124*8bae5d40Schristos
125*8bae5d40Schristos /*
126*8bae5d40Schristos * EXT needs local filesystem and device.
127*8bae5d40Schristos */
128*8bae5d40Schristos static char *
ext_match(am_opts * fo)129*8bae5d40Schristos ext_match(am_opts *fo)
130*8bae5d40Schristos {
131*8bae5d40Schristos
132*8bae5d40Schristos if (!fo->opt_dev) {
133*8bae5d40Schristos plog(XLOG_USER, "ext: no device specified");
134*8bae5d40Schristos return 0;
135*8bae5d40Schristos }
136*8bae5d40Schristos
137*8bae5d40Schristos dlog("EXT: mounting device \"%s\" on \"%s\"", fo->opt_dev, fo->opt_fs);
138*8bae5d40Schristos
139*8bae5d40Schristos /*
140*8bae5d40Schristos * Determine magic cookie to put in mtab
141*8bae5d40Schristos */
142*8bae5d40Schristos return xstrdup(fo->opt_dev);
143*8bae5d40Schristos }
144*8bae5d40Schristos
145*8bae5d40Schristos
146*8bae5d40Schristos static int
mount_ext(char * mntdir,char * fs_name,char * opts,int on_autofs,char * mount_type,const char * mnttab_type)147*8bae5d40Schristos mount_ext(char *mntdir, char *fs_name, char *opts, int on_autofs, char *
148*8bae5d40Schristos mount_type, const char *mnttab_type)
149*8bae5d40Schristos {
150*8bae5d40Schristos ext_args_t ext_args;
151*8bae5d40Schristos mntent_t mnt;
152*8bae5d40Schristos int flags;
153*8bae5d40Schristos
154*8bae5d40Schristos /*
155*8bae5d40Schristos * Figure out the name of the file system type.
156*8bae5d40Schristos */
157*8bae5d40Schristos MTYPE_TYPE type = mount_type;
158*8bae5d40Schristos
159*8bae5d40Schristos memset((voidp) &ext_args, 0, sizeof(ext_args)); /* Paranoid */
160*8bae5d40Schristos
161*8bae5d40Schristos /*
162*8bae5d40Schristos * Fill in the mount structure
163*8bae5d40Schristos */
164*8bae5d40Schristos memset((voidp) &mnt, 0, sizeof(mnt));
165*8bae5d40Schristos mnt.mnt_dir = mntdir;
166*8bae5d40Schristos mnt.mnt_fsname = fs_name;
167*8bae5d40Schristos mnt.mnt_type = mnttab_type;
168*8bae5d40Schristos mnt.mnt_opts = opts;
169*8bae5d40Schristos
170*8bae5d40Schristos flags = compute_mount_flags(&mnt);
171*8bae5d40Schristos #ifdef HAVE_FS_AUTOFS
172*8bae5d40Schristos if (on_autofs)
173*8bae5d40Schristos flags |= autofs_compute_mount_flags(&mnt);
174*8bae5d40Schristos #endif /* HAVE_FS_AUTOFS */
175*8bae5d40Schristos
176*8bae5d40Schristos /*
177*8bae5d40Schristos * Call generic mount routine
178*8bae5d40Schristos */
179*8bae5d40Schristos return mount_fs(&mnt, flags, (caddr_t) &ext_args, 0, type, 0, NULL, mnttab_file_name, on_autofs);
180*8bae5d40Schristos }
181*8bae5d40Schristos
182*8bae5d40Schristos
183*8bae5d40Schristos static int
ext_mount(am_node * am,mntfs * mf,char * mount_type,const char * mnttab_type)184*8bae5d40Schristos ext_mount(am_node *am, mntfs *mf, char *mount_type,
185*8bae5d40Schristos const char *mnttab_type)
186*8bae5d40Schristos {
187*8bae5d40Schristos int on_autofs = mf->mf_flags & MFF_ON_AUTOFS;
188*8bae5d40Schristos int error;
189*8bae5d40Schristos
190*8bae5d40Schristos error = mount_ext(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs,
191*8bae5d40Schristos mount_type, mnttab_type);
192*8bae5d40Schristos if (error) {
193*8bae5d40Schristos errno = error;
194*8bae5d40Schristos plog(XLOG_ERROR, "mount_ext: %m");
195*8bae5d40Schristos return error;
196*8bae5d40Schristos }
197*8bae5d40Schristos
198*8bae5d40Schristos return 0;
199*8bae5d40Schristos }
200*8bae5d40Schristos
201*8bae5d40Schristos static int
ext2_mount(am_node * am,mntfs * mf)202*8bae5d40Schristos ext2_mount(am_node *am, mntfs *mf)
203*8bae5d40Schristos {
204*8bae5d40Schristos return ext_mount(am, mf, MOUNT_TYPE_EXT2, MNTTAB_TYPE_EXT2);
205*8bae5d40Schristos }
206*8bae5d40Schristos
207*8bae5d40Schristos static int
ext3_mount(am_node * am,mntfs * mf)208*8bae5d40Schristos ext3_mount(am_node *am, mntfs *mf)
209*8bae5d40Schristos {
210*8bae5d40Schristos return ext_mount(am, mf, MOUNT_TYPE_EXT3, MNTTAB_TYPE_EXT3);
211*8bae5d40Schristos }
212*8bae5d40Schristos
213*8bae5d40Schristos static int
ext4_mount(am_node * am,mntfs * mf)214*8bae5d40Schristos ext4_mount(am_node *am, mntfs *mf)
215*8bae5d40Schristos {
216*8bae5d40Schristos return ext_mount(am, mf, MOUNT_TYPE_EXT4, MNTTAB_TYPE_EXT4);
217*8bae5d40Schristos }
218*8bae5d40Schristos
219*8bae5d40Schristos static int
ext_umount(am_node * am,mntfs * mf)220*8bae5d40Schristos ext_umount(am_node *am, mntfs *mf)
221*8bae5d40Schristos {
222*8bae5d40Schristos int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0;
223*8bae5d40Schristos
224*8bae5d40Schristos return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags);
225*8bae5d40Schristos }
226