summaryrefslogtreecommitdiff
path: root/usr/src/lib/smbclnt/libfksmbfs/common/fake_modconf.c
blob: d5482f9cc51b302efb375105a2f9975d5a6c4b46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */
/*
 * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
 */

#include <sys/types.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/vfs.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/cmn_err.h>
#include <sys/debug.h>

#if 0 // XXX

#include <sys/user.h>
#include <sys/vm.h>
#include <sys/conf.h>
#include <sys/class.h>
#include <sys/systm.h>
#include <sys/modctl.h>
#include <sys/exec.h>
#include <sys/exechdr.h>
#include <sys/devops.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/hwconf.h>
#include <sys/ddi_impldefs.h>
#include <sys/autoconf.h>
#include <sys/disp.h>
#include <sys/kmem.h>
#include <sys/instance.h>
#include <sys/modhash.h>
#include <sys/dacf.h>
#include <ipp/ipp.h>
#include <sys/strsubr.h>
#include <sys/kcpc.h>
#include <sys/brand.h>
#include <sys/cpc_pcbe.h>
#include <sys/kstat.h>
#include <sys/socketvar.h>
#include <sys/kiconv.h>

#endif // XXX

#include <libfksmbfs.h>

/*
 * Install a filesystem.
 */
/*ARGSUSED1*/
int
fake_installfs(vfsdef_t *def)
{
	struct vfssw *vswp;
	char *fsname = def->name;
	int fstype;	/* index into vfssw[] and vsanchor_fstype[] */
	int allocated;
	int err;

	if (def->def_version != VFSDEF_VERSION) {
		cmn_err(CE_WARN, "file system '%s' version mismatch", fsname);
		return (ENXIO);
	}

	allocated = 0;

	WLOCK_VFSSW();
	if ((vswp = vfs_getvfsswbyname(fsname)) == NULL) {
		if ((vswp = allocate_vfssw(fsname)) == NULL) {
			WUNLOCK_VFSSW();
			/*
			 * See 1095689.  If this message appears, then
			 * we either need to make the vfssw table bigger
			 * statically, or make it grow dynamically.
			 */
			cmn_err(CE_WARN, "no room for '%s' in vfssw!", fsname);
			return (ENXIO);
		}
		allocated = 1;
	}
	ASSERT(vswp != NULL);

	fstype = vswp - vfssw;	/* Pointer arithmetic to get the fstype */

	/* Turn on everything by default *except* VSW_STATS */
	vswp->vsw_flag = def->flags & ~(VSW_STATS);

	if (def->flags & VSW_HASPROTO) {
		vfs_mergeopttbl(&vfs_mntopts, def->optproto,
		    &vswp->vsw_optproto);
	} else {
		vfs_copyopttbl(&vfs_mntopts, &vswp->vsw_optproto);
	}

	if (def->flags & VSW_CANRWRO) {
		/*
		 * This obviously implies VSW_CANREMOUNT.
		 */
		vswp->vsw_flag |= VSW_CANREMOUNT;
	}

	/* vopstats ... */

	if (def->init == NULL)
		err = EFAULT;
	else
		err = (*(def->init))(fstype, fsname);

	if (err != 0) {
		if (allocated) {
			kmem_free(vswp->vsw_name, strlen(vswp->vsw_name)+1);
			vswp->vsw_name = "";
		}
		vswp->vsw_flag = 0;
		vswp->vsw_init = NULL;
	}

	vfs_unrefvfssw(vswp);
	WUNLOCK_VFSSW();

	/* ... vopstats */

	return (err);
}

int fake_removefs_allowed = 1;

/*
 * Remove a filesystem
 */
int
fake_removefs(vfsdef_t *def)
{
	struct vfssw *vswp;

	if (fake_removefs_allowed == 0)
		return (EBUSY);

	WLOCK_VFSSW();
	if ((vswp = vfs_getvfsswbyname(def->name)) == NULL) {
		WUNLOCK_VFSSW();
		cmn_err(CE_WARN, "fake_removefs: %s not in vfssw",
			def->name);
		return (EINVAL);
	}
	if (vswp->vsw_count != 1) {
		vfs_unrefvfssw(vswp);
		WUNLOCK_VFSSW();
		return (EBUSY);
	}

	/*
	 * A mounted filesystem could still have vsw_count = 0
	 * so we must check whether anyone is actually using our ops
	 */
	if (vfs_opsinuse(&vswp->vsw_vfsops)) {
		vfs_unrefvfssw(vswp);
		WUNLOCK_VFSSW();
		return (EBUSY);
	}

	vfs_freeopttbl(&vswp->vsw_optproto);
	vswp->vsw_optproto.mo_count = 0;

	vswp->vsw_flag = 0;
	vswp->vsw_init = NULL;
	vfs_unrefvfssw(vswp);
	WUNLOCK_VFSSW();
	return (0);
}