xref: /original-bsd/usr.sbin/amd/amd/ufs_ops.c (revision 898c7514)
1 /*
2  * Copyright (c) 1990 Jan-Simon Pendry
3  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Jan-Simon Pendry at Imperial College, London.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	@(#)ufs_ops.c	8.2 (Berkeley) 05/10/95
13  *
14  * $Id: ufs_ops.c,v 5.2.2.1 1992/02/09 15:09:08 jsp beta $
15  *
16  */
17 
18 #include "am.h"
19 
20 #ifdef HAS_UFS
21 
22 #include <sys/stat.h>
23 #ifdef NFS_3
24 typedef nfs_fh fhandle_t;
25 #endif /* NFS_3 */
26 
27 #include <sys/mount.h>
28 
29 #ifdef UFS_HDR
30 #include UFS_HDR
31 #endif /* UFS_HDR */
32 
33 /*
34  * UN*X file system
35  */
36 
37 /*
38  * UFS needs local filesystem and device.
39  */
40 static char *ufs_match P((am_opts *fo));
41 static char *ufs_match(fo)
42 am_opts *fo;
43 {
44 	if (!fo->opt_dev) {
45 		plog(XLOG_USER, "ufs: no device specified");
46 		return 0;
47 	}
48 
49 #ifdef DEBUG
50 	dlog("UFS: mounting device \"%s\" on \"%s\"",
51 		fo->opt_dev, fo->opt_fs);
52 #endif /* DEBUG */
53 
54 	/*
55 	 * Determine magic cookie to put in mtab
56 	 */
57 	return strdup(fo->opt_dev);
58 }
59 
60 static mount_ufs(dir, fs_name, opts)
61 char *dir;
62 char *fs_name;
63 char *opts;
64 {
65 	struct ufs_args ufs_args;
66 	struct mntent mnt;
67 	int flags;
68 
69 	/*
70 	 * Figure out the name of the file system type.
71 	 */
72 #ifdef M_NEWTYPE
73 	char *type = MOUNT_TYPE_UFS;
74 #else
75 	int type = MOUNT_TYPE_UFS;
76 #endif /* M_NEWTYPE */
77 
78 	bzero((voidp) &ufs_args, sizeof(ufs_args));	/* Paranoid */
79 
80 	/*
81 	 * Fill in the mount structure
82 	 */
83 	mnt.mnt_dir = dir;
84 	mnt.mnt_fsname = fs_name;
85 	mnt.mnt_type = MTAB_TYPE_UFS;
86 	mnt.mnt_opts = opts;
87 	mnt.mnt_freq = 1;
88 	mnt.mnt_passno = 2;
89 
90 	flags = compute_mount_flags(&mnt);
91 
92 #ifdef ULTRIX_HACK
93 	ufs_args.ufs_flags = flags;
94 	ufs_args.ufs_pgthresh = 64; /* 64K - XXX */
95 	flags &= M_RDONLY;
96 #else
97 	ufs_args.fspec = fs_name;
98 #endif /* ULTRIX_HACK */
99 
100 	/*
101 	 * Call generic mount routine
102 	 */
103 	return mount_fs(&mnt, flags, (caddr_t) &ufs_args, 0, type);
104 }
105 
106 /*ARGSUSED*/
107 static int ufs_fmount(mf)
108 mntfs *mf;
109 {
110 	int error;
111 
112 	error = mount_ufs(mf->mf_mount, mf->mf_info, mf->mf_mopts);
113 	if (error) {
114 		errno = error;
115 		plog(XLOG_ERROR, "mount_ufs: %m");
116 		return error;
117 	}
118 
119 	return 0;
120 }
121 
122 static int ufs_fumount(mf)
123 mntfs *mf;
124 {
125 	return UMOUNT_FS(mf->mf_mount);
126 }
127 
128 /*
129  * Ops structure
130  */
131 am_ops ufs_ops = {
132 	"ufs",
133 	ufs_match,
134 	0, /* ufs_init */
135 	auto_fmount,
136 	ufs_fmount,
137 	auto_fumount,
138 	ufs_fumount,
139 	efs_lookuppn,
140 	efs_readdir,
141 	0, /* ufs_readlink */
142 	0, /* ufs_mounted */
143 	0, /* ufs_umounted */
144 	find_afs_srvr,
145 #ifdef FLUSH_KERNEL_NAME_CACHE
146 	FS_MKMNT|FS_NOTIMEOUT|FS_UBACKGROUND|FS_AMQINFO
147 #else /* FLUSH_KERNEL_NAME_CACHE */
148 	FS_MKMNT|FS_NOTIMEOUT|FS_UBACKGROUND|FS_AMQINFO
149 #endif /* FLUSH_KERNEL_NAME_CACHE */
150 };
151 
152 #endif /* HAS_UFS */
153