1*26d0c865Sguenther /* $OpenBSD: ufs_ops.c,v 1.10 2014/10/26 03:28:41 guenther Exp $ */
2608f9123Sniklas
3df930be7Sderaadt /*
4df930be7Sderaadt * Copyright (c) 1990 Jan-Simon Pendry
5df930be7Sderaadt * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
6df930be7Sderaadt * Copyright (c) 1990, 1993
7df930be7Sderaadt * The Regents of the University of California. All rights reserved.
8df930be7Sderaadt *
9df930be7Sderaadt * This code is derived from software contributed to Berkeley by
10df930be7Sderaadt * Jan-Simon Pendry at Imperial College, London.
11df930be7Sderaadt *
12df930be7Sderaadt * Redistribution and use in source and binary forms, with or without
13df930be7Sderaadt * modification, are permitted provided that the following conditions
14df930be7Sderaadt * are met:
15df930be7Sderaadt * 1. Redistributions of source code must retain the above copyright
16df930be7Sderaadt * notice, this list of conditions and the following disclaimer.
17df930be7Sderaadt * 2. Redistributions in binary form must reproduce the above copyright
18df930be7Sderaadt * notice, this list of conditions and the following disclaimer in the
19df930be7Sderaadt * documentation and/or other materials provided with the distribution.
2029295d1cSmillert * 3. Neither the name of the University nor the names of its contributors
21df930be7Sderaadt * may be used to endorse or promote products derived from this software
22df930be7Sderaadt * without specific prior written permission.
23df930be7Sderaadt *
24df930be7Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25df930be7Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26df930be7Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27df930be7Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28df930be7Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29df930be7Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30df930be7Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31df930be7Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32df930be7Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33df930be7Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34df930be7Sderaadt * SUCH DAMAGE.
35df930be7Sderaadt *
36df930be7Sderaadt * from: @(#)ufs_ops.c 8.1 (Berkeley) 6/6/93
37df930be7Sderaadt */
38df930be7Sderaadt
39df930be7Sderaadt #include "am.h"
40df930be7Sderaadt
41df930be7Sderaadt #ifdef HAS_UFS
42df930be7Sderaadt
43df930be7Sderaadt #include <sys/stat.h>
44df930be7Sderaadt
45df930be7Sderaadt /*
46df930be7Sderaadt * UN*X file system
47df930be7Sderaadt */
48df930be7Sderaadt
49df930be7Sderaadt /*
50df930be7Sderaadt * UFS needs local filesystem and device.
51df930be7Sderaadt */
529ad2d6d5Spvalchev static char *
ufs_match(am_opts * fo)539ad2d6d5Spvalchev ufs_match(am_opts *fo)
54df930be7Sderaadt {
55df930be7Sderaadt if (!fo->opt_dev) {
56df930be7Sderaadt plog(XLOG_USER, "ufs: no device specified");
57df930be7Sderaadt return 0;
58df930be7Sderaadt }
59df930be7Sderaadt
60df930be7Sderaadt #ifdef DEBUG
61df930be7Sderaadt dlog("UFS: mounting device \"%s\" on \"%s\"",
62df930be7Sderaadt fo->opt_dev, fo->opt_fs);
63df930be7Sderaadt #endif /* DEBUG */
64df930be7Sderaadt
65df930be7Sderaadt /*
66df930be7Sderaadt * Determine magic cookie to put in mtab
67df930be7Sderaadt */
68df930be7Sderaadt return strdup(fo->opt_dev);
69df930be7Sderaadt }
70df930be7Sderaadt
717f4e61d8Sderaadt static int
mount_ufs(char * dir,char * fs_name,char * opts)729ad2d6d5Spvalchev mount_ufs(char *dir, char *fs_name, char *opts)
73df930be7Sderaadt {
74df930be7Sderaadt struct ufs_args ufs_args;
75df930be7Sderaadt struct mntent mnt;
76df930be7Sderaadt int flags;
77df930be7Sderaadt
78df930be7Sderaadt /*
79df930be7Sderaadt * Figure out the name of the file system type.
80df930be7Sderaadt */
8129db5df3Sguenther const char *type = MOUNT_FFS;
82df930be7Sderaadt
83*26d0c865Sguenther bzero(&ufs_args, sizeof(ufs_args)); /* Paranoid */
84df930be7Sderaadt
85df930be7Sderaadt /*
86df930be7Sderaadt * Fill in the mount structure
87df930be7Sderaadt */
88df930be7Sderaadt mnt.mnt_dir = dir;
89df930be7Sderaadt mnt.mnt_fsname = fs_name;
9029db5df3Sguenther mnt.mnt_type = "ffs";
91df930be7Sderaadt mnt.mnt_opts = opts;
92df930be7Sderaadt mnt.mnt_freq = 1;
93df930be7Sderaadt mnt.mnt_passno = 2;
94df930be7Sderaadt
95df930be7Sderaadt flags = compute_mount_flags(&mnt);
96df930be7Sderaadt
97df930be7Sderaadt ufs_args.fspec = fs_name;
98df930be7Sderaadt
99df930be7Sderaadt /*
100df930be7Sderaadt * Call generic mount routine
101df930be7Sderaadt */
102df930be7Sderaadt return mount_fs(&mnt, flags, (caddr_t) &ufs_args, 0, type);
103df930be7Sderaadt }
104df930be7Sderaadt
1059ad2d6d5Spvalchev static int
ufs_fmount(mntfs * mf)1069ad2d6d5Spvalchev ufs_fmount(mntfs *mf)
107df930be7Sderaadt {
108df930be7Sderaadt int error;
109df930be7Sderaadt
110df930be7Sderaadt error = mount_ufs(mf->mf_mount, mf->mf_info, mf->mf_mopts);
111df930be7Sderaadt if (error) {
112df930be7Sderaadt errno = error;
113df930be7Sderaadt plog(XLOG_ERROR, "mount_ufs: %m");
114df930be7Sderaadt return error;
115df930be7Sderaadt }
116df930be7Sderaadt
117df930be7Sderaadt return 0;
118df930be7Sderaadt }
119df930be7Sderaadt
1209ad2d6d5Spvalchev static int
ufs_fumount(mntfs * mf)1219ad2d6d5Spvalchev ufs_fumount(mntfs *mf)
122df930be7Sderaadt {
12329db5df3Sguenther return umount_fs(mf->mf_mount);
124df930be7Sderaadt }
125df930be7Sderaadt
126df930be7Sderaadt /*
127df930be7Sderaadt * Ops structure
128df930be7Sderaadt */
129df930be7Sderaadt am_ops ufs_ops = {
130df930be7Sderaadt "ufs",
131df930be7Sderaadt ufs_match,
132df930be7Sderaadt 0, /* ufs_init */
133df930be7Sderaadt auto_fmount,
134df930be7Sderaadt ufs_fmount,
135df930be7Sderaadt auto_fumount,
136df930be7Sderaadt ufs_fumount,
137df930be7Sderaadt efs_lookuppn,
138df930be7Sderaadt efs_readdir,
139df930be7Sderaadt 0, /* ufs_readlink */
140df930be7Sderaadt 0, /* ufs_mounted */
141df930be7Sderaadt 0, /* ufs_umounted */
142df930be7Sderaadt find_afs_srvr,
143df930be7Sderaadt #ifdef FLUSH_KERNEL_NAME_CACHE
144df930be7Sderaadt FS_MKMNT|FS_NOTIMEOUT|FS_UBACKGROUND|FS_AMQINFO
145df930be7Sderaadt #else /* FLUSH_KERNEL_NAME_CACHE */
146df930be7Sderaadt FS_MKMNT|FS_NOTIMEOUT|FS_UBACKGROUND|FS_AMQINFO
147df930be7Sderaadt #endif /* FLUSH_KERNEL_NAME_CACHE */
148df930be7Sderaadt };
149df930be7Sderaadt
150df930be7Sderaadt #endif /* HAS_UFS */
151