1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
14 */
15
16 #include <sys/types.h>
17 #include <sys/param.h>
18 #include <sys/t_lock.h>
19 #include <sys/errno.h>
20 #include <sys/cred.h>
21 #include <sys/user.h>
22 #include <sys/uio.h>
23 #include <sys/file.h>
24 #include <sys/pathname.h>
25 #include <sys/vfs.h>
26 #include <sys/vnode.h>
27 #include <sys/stat.h>
28 #include <sys/mode.h>
29 #include <sys/conf.h>
30 #include <sys/sysmacros.h>
31 #include <sys/cmn_err.h>
32 #include <sys/systm.h>
33 #include <sys/kmem.h>
34 #include <sys/debug.h>
35 #include <sys/acl.h>
36 #include <sys/nbmlock.h>
37 #include <sys/fcntl.h>
38 #include <sys/poll.h>
39
40 #include <errno.h>
41 #include <fcntl.h>
42 #include <unistd.h>
43
44 #include "vncache.h"
45
46 #define VFTBITS(feature) ((feature) & 0xFFFFFFFFLL)
47
48 static uint64_t vfs_features = VFSFT_XVATTR;
49
50 vnode_t *rootdir = NULL; /* pointer to root inode vnode. */
51
52 static struct vfs fake_rootvfs;
53 struct vfs *rootvfs = NULL;
54
55 int
56 fksmbsrv_vfs_init(void)
57 {
58 struct stat st;
59 int err, fd;
60 vnode_t *vp;
61 char *name = "/";
62
63 if (rootvfs == NULL) {
64 rootvfs = &fake_rootvfs;
65 rootvfs->vfs_mntpt = refstr_alloc(name);
66 rootvfs->vfs_fsid.val[0] = 1;
67 }
68
69 if (rootdir == NULL) {
70 if (lstat(name, &st) == -1)
71 return (errno);
72 fd = open(name, O_RDONLY, 0);
73 if (fd < 0) {
74 return (errno);
75 }
76 if (fstat(fd, &st) == -1) {
77 err = errno;
78 (void) close(fd);
79 return (err);
80 }
81 vp = vncache_enter(&st, NULL, "", fd);
82 /* extra hold for rootvp */
83 vn_hold(vp);
84 rootdir = vp;
85
86 /* VFS stuff in global zone struct. */
109 return (ret);
110 }
111
112 /* ARGSUSED */
113 struct vfs *
114 getvfs(fsid_t *fsid)
115 {
116 return (rootvfs);
117 }
118
119 vfsops_t *
120 vfs_getops(vfs_t *vfsp)
121 {
122 return (vfsp->vfs_op);
123 }
124
125 /* ARGSUSED */
126 struct vfssw *
127 vfs_getvfsswbyvfsops(vfsops_t *vfsops)
128 {
129 return (NULL);
130 }
131
132 /* ARGSUSED */
133 void
134 vfs_unrefvfssw(struct vfssw *vswp)
135 {
136 }
137
138 /* ARGSUSED */
139 int
140 fsop_root(vfs_t *vfsp, vnode_t **vpp)
141 {
142 vnode_t *vp;
143
144 if ((vp = rootdir) == NULL)
145 return (ENXIO);
146
147 vn_hold(vp);
148 *vpp = vp;
|
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
14 */
15
16 #include <sys/types.h>
17 #include <sys/param.h>
18 #include <sys/t_lock.h>
19 #include <sys/errno.h>
20 #include <sys/cred.h>
21 #include <sys/user.h>
22 #include <sys/uio.h>
23 #include <sys/file.h>
24 #include <sys/pathname.h>
25 #include <sys/vfs.h>
26 #include <sys/vnode.h>
27 #include <sys/stat.h>
28 #include <sys/mode.h>
29 #include <sys/conf.h>
30 #include <sys/sysmacros.h>
31 #include <sys/cmn_err.h>
32 #include <sys/systm.h>
33 #include <sys/kmem.h>
34 #include <sys/debug.h>
35 #include <sys/acl.h>
36 #include <sys/nbmlock.h>
37 #include <sys/fcntl.h>
38 #include <sys/poll.h>
39
40 #include <errno.h>
41 #include <fcntl.h>
42 #include <unistd.h>
43
44 #include "vncache.h"
45
46 #define VFTBITS(feature) ((feature) & 0xFFFFFFFFLL)
47
48 static uint64_t vfs_features = VFSFT_XVATTR;
49
50 vnode_t *rootdir = NULL; /* pointer to root inode vnode. */
51
52 static struct vfs fake_rootvfs;
53 static struct vfsops fake_vfsops;
54 struct vfs *rootvfs = NULL;
55 static struct vfssw fake_vfssw = {
56 .vsw_name = "fake" /* see smb_tree.c:smb_mtype[] */
57 };
58
59 int
60 fksmbsrv_vfs_init(void)
61 {
62 struct stat st;
63 int err, fd;
64 vnode_t *vp;
65 char *name = "/";
66
67 if (rootvfs == NULL) {
68 rootvfs = &fake_rootvfs;
69 rootvfs->vfs_mntpt = refstr_alloc(name);
70 rootvfs->vfs_fsid.val[0] = 1;
71 rootvfs->vfs_op = &fake_vfsops;
72 }
73
74 if (rootdir == NULL) {
75 if (lstat(name, &st) == -1)
76 return (errno);
77 fd = open(name, O_RDONLY, 0);
78 if (fd < 0) {
79 return (errno);
80 }
81 if (fstat(fd, &st) == -1) {
82 err = errno;
83 (void) close(fd);
84 return (err);
85 }
86 vp = vncache_enter(&st, NULL, "", fd);
87 /* extra hold for rootvp */
88 vn_hold(vp);
89 rootdir = vp;
90
91 /* VFS stuff in global zone struct. */
114 return (ret);
115 }
116
117 /* ARGSUSED */
118 struct vfs *
119 getvfs(fsid_t *fsid)
120 {
121 return (rootvfs);
122 }
123
124 vfsops_t *
125 vfs_getops(vfs_t *vfsp)
126 {
127 return (vfsp->vfs_op);
128 }
129
130 /* ARGSUSED */
131 struct vfssw *
132 vfs_getvfsswbyvfsops(vfsops_t *vfsops)
133 {
134 if (vfsops == &fake_vfsops)
135 return (&fake_vfssw);
136 return (NULL);
137 }
138
139 /* ARGSUSED */
140 void
141 vfs_unrefvfssw(struct vfssw *vswp)
142 {
143 }
144
145 /* ARGSUSED */
146 int
147 fsop_root(vfs_t *vfsp, vnode_t **vpp)
148 {
149 vnode_t *vp;
150
151 if ((vp = rootdir) == NULL)
152 return (ENXIO);
153
154 vn_hold(vp);
155 *vpp = vp;
|