pseudofs.c (95953) | pseudofs.c (97940) |
---|---|
1/*- 2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * | 1/*- 2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * |
28 * $FreeBSD: head/sys/fs/pseudofs/pseudofs.c 95953 2002-05-02 20:25:55Z mux $ | 28 * $FreeBSD: head/sys/fs/pseudofs/pseudofs.c 97940 2002-06-06 16:59:24Z des $ |
29 */ 30 31#include <sys/param.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/lock.h> 35#include <sys/malloc.h> 36#include <sys/module.h> --- 27 unchanged lines hidden (view full) --- 64 KASSERT(parent->pn_info != NULL, 65 ("%s(): parent has no pn_info", __func__)); 66 KASSERT(parent->pn_type == pfstype_dir || 67 parent->pn_type == pfstype_procdir || 68 parent->pn_type == pfstype_root, 69 ("%s(): parent is not a directory", __func__)); 70 71 /* XXX should check for duplicate names etc. */ | 29 */ 30 31#include <sys/param.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/lock.h> 35#include <sys/malloc.h> 36#include <sys/module.h> --- 27 unchanged lines hidden (view full) --- 64 KASSERT(parent->pn_info != NULL, 65 ("%s(): parent has no pn_info", __func__)); 66 KASSERT(parent->pn_type == pfstype_dir || 67 parent->pn_type == pfstype_procdir || 68 parent->pn_type == pfstype_root, 69 ("%s(): parent is not a directory", __func__)); 70 71 /* XXX should check for duplicate names etc. */ |
72 | 72 |
73 mtx_lock(&parent->pn_info->pi_mutex); 74 node->pn_info = parent->pn_info; 75 node->pn_parent = parent; 76 node->pn_next = parent->pn_nodes; 77 parent->pn_nodes = node; 78 mtx_unlock(&parent->pn_info->pi_mutex); | 73 mtx_lock(&parent->pn_info->pi_mutex); 74 node->pn_info = parent->pn_info; 75 node->pn_parent = parent; 76 node->pn_next = parent->pn_nodes; 77 parent->pn_nodes = node; 78 mtx_unlock(&parent->pn_info->pi_mutex); |
79 | 79 |
80 return (0); 81} 82 83/* 84 * Add . and .. to a directory 85 */ 86static int 87_pfs_fixup_dir(struct pfs_node *parent) 88{ 89 struct pfs_node *dir; | 80 return (0); 81} 82 83/* 84 * Add . and .. to a directory 85 */ 86static int 87_pfs_fixup_dir(struct pfs_node *parent) 88{ 89 struct pfs_node *dir; |
90 | 90 |
91 MALLOC(dir, struct pfs_node *, sizeof *dir, 92 M_PFSNODES, M_WAITOK|M_ZERO); 93 dir->pn_name[0] = '.'; 94 dir->pn_type = pfstype_this; | 91 MALLOC(dir, struct pfs_node *, sizeof *dir, 92 M_PFSNODES, M_WAITOK|M_ZERO); 93 dir->pn_name[0] = '.'; 94 dir->pn_type = pfstype_this; |
95 | 95 |
96 if (_pfs_add_node(parent, dir) != 0) { 97 FREE(dir, M_PFSNODES); 98 return (-1); 99 } | 96 if (_pfs_add_node(parent, dir) != 0) { 97 FREE(dir, M_PFSNODES); 98 return (-1); 99 } |
100 | 100 |
101 MALLOC(dir, struct pfs_node *, sizeof *dir, 102 M_PFSNODES, M_WAITOK|M_ZERO); 103 dir->pn_name[0] = dir->pn_name[1] = '.'; 104 dir->pn_type = pfstype_parent; | 101 MALLOC(dir, struct pfs_node *, sizeof *dir, 102 M_PFSNODES, M_WAITOK|M_ZERO); 103 dir->pn_name[0] = dir->pn_name[1] = '.'; 104 dir->pn_type = pfstype_parent; |
105 | 105 |
106 if (_pfs_add_node(parent, dir) != 0) { 107 FREE(dir, M_PFSNODES); 108 return (-1); 109 } 110 111 return (0); 112} 113 --- 21 unchanged lines hidden (view full) --- 135 FREE(dir, M_PFSNODES); 136 return (NULL); 137 } 138 139 if (_pfs_fixup_dir(dir) != 0) { 140 pfs_destroy(dir); 141 return (NULL); 142 } | 106 if (_pfs_add_node(parent, dir) != 0) { 107 FREE(dir, M_PFSNODES); 108 return (-1); 109 } 110 111 return (0); 112} 113 --- 21 unchanged lines hidden (view full) --- 135 FREE(dir, M_PFSNODES); 136 return (NULL); 137 } 138 139 if (_pfs_fixup_dir(dir) != 0) { 140 pfs_destroy(dir); 141 return (NULL); 142 } |
143 | 143 |
144 return (dir); 145} 146 147/* 148 * Create a file 149 */ 150struct pfs_node * 151pfs_create_file(struct pfs_node *parent, char *name, pfs_fill_t fill, | 144 return (dir); 145} 146 147/* 148 * Create a file 149 */ 150struct pfs_node * 151pfs_create_file(struct pfs_node *parent, char *name, pfs_fill_t fill, |
152 pfs_attr_t attr, pfs_vis_t vis, int flags) | 152 pfs_attr_t attr, pfs_vis_t vis, int flags) |
153{ 154 struct pfs_node *node; 155 156 KASSERT(strlen(name) < PFS_NAMELEN, 157 ("%s(): node name is too long", __func__)); 158 159 MALLOC(node, struct pfs_node *, sizeof *node, 160 M_PFSNODES, M_WAITOK|M_ZERO); 161 strcpy(node->pn_name, name); 162 node->pn_type = pfstype_file; 163 node->pn_func = fill; 164 node->pn_attr = attr; 165 node->pn_vis = vis; 166 node->pn_flags = flags; 167 168 if (_pfs_add_node(parent, node) != 0) { 169 FREE(node, M_PFSNODES); 170 return (NULL); 171 } | 153{ 154 struct pfs_node *node; 155 156 KASSERT(strlen(name) < PFS_NAMELEN, 157 ("%s(): node name is too long", __func__)); 158 159 MALLOC(node, struct pfs_node *, sizeof *node, 160 M_PFSNODES, M_WAITOK|M_ZERO); 161 strcpy(node->pn_name, name); 162 node->pn_type = pfstype_file; 163 node->pn_func = fill; 164 node->pn_attr = attr; 165 node->pn_vis = vis; 166 node->pn_flags = flags; 167 168 if (_pfs_add_node(parent, node) != 0) { 169 FREE(node, M_PFSNODES); 170 return (NULL); 171 } |
172 | 172 |
173 return (node); 174} 175 176/* 177 * Create a symlink 178 */ 179struct pfs_node * 180pfs_create_link(struct pfs_node *parent, char *name, pfs_fill_t fill, | 173 return (node); 174} 175 176/* 177 * Create a symlink 178 */ 179struct pfs_node * 180pfs_create_link(struct pfs_node *parent, char *name, pfs_fill_t fill, |
181 pfs_attr_t attr, pfs_vis_t vis, int flags) | 181 pfs_attr_t attr, pfs_vis_t vis, int flags) |
182{ 183 struct pfs_node *node; 184 185 node = pfs_create_file(parent, name, fill, attr, vis, flags); 186 if (node == NULL) 187 return (NULL); 188 node->pn_type = pfstype_symlink; 189 return (node); 190} 191 192/* 193 * Destroy a node or a tree of nodes 194 */ 195int 196pfs_destroy(struct pfs_node *node) 197{ 198 struct pfs_node *parent, *rover; | 182{ 183 struct pfs_node *node; 184 185 node = pfs_create_file(parent, name, fill, attr, vis, flags); 186 if (node == NULL) 187 return (NULL); 188 node->pn_type = pfstype_symlink; 189 return (node); 190} 191 192/* 193 * Destroy a node or a tree of nodes 194 */ 195int 196pfs_destroy(struct pfs_node *node) 197{ 198 struct pfs_node *parent, *rover; |
199 | 199 |
200 KASSERT(node != NULL, 201 ("%s(): node is NULL", __func__)); 202 KASSERT(node->pn_info != NULL, 203 ("%s(): node has no pn_info", __func__)); 204 205 /* destroy children */ 206 if (node->pn_type == pfstype_dir || 207 node->pn_type == pfstype_procdir || --- 31 unchanged lines hidden (view full) --- 239/* 240 * Mount a pseudofs instance 241 */ 242int 243pfs_mount(struct pfs_info *pi, struct mount *mp, struct nameidata *ndp, 244 struct thread *td) 245{ 246 struct statfs *sbp; | 200 KASSERT(node != NULL, 201 ("%s(): node is NULL", __func__)); 202 KASSERT(node->pn_info != NULL, 203 ("%s(): node has no pn_info", __func__)); 204 205 /* destroy children */ 206 if (node->pn_type == pfstype_dir || 207 node->pn_type == pfstype_procdir || --- 31 unchanged lines hidden (view full) --- 239/* 240 * Mount a pseudofs instance 241 */ 242int 243pfs_mount(struct pfs_info *pi, struct mount *mp, struct nameidata *ndp, 244 struct thread *td) 245{ 246 struct statfs *sbp; |
247 | 247 |
248 if (mp->mnt_flag & MNT_UPDATE) 249 return (EOPNOTSUPP); | 248 if (mp->mnt_flag & MNT_UPDATE) 249 return (EOPNOTSUPP); |
250 | 250 |
251 mp->mnt_flag |= MNT_LOCAL; 252 mp->mnt_data = (qaddr_t)pi; 253 vfs_getnewfsid(mp); 254 255 sbp = &mp->mnt_stat; 256 bcopy(pi->pi_name, sbp->f_mntfromname, sizeof pi->pi_name); 257 sbp->f_bsize = PAGE_SIZE; 258 sbp->f_iosize = PAGE_SIZE; --- 13 unchanged lines hidden (view full) --- 272pfs_unmount(struct mount *mp, int mntflags, struct thread *td) 273{ 274 struct pfs_info *pi; 275 int error; 276 277 pi = (struct pfs_info *)mp->mnt_data; 278 279 /* XXX do stuff with pi... */ | 251 mp->mnt_flag |= MNT_LOCAL; 252 mp->mnt_data = (qaddr_t)pi; 253 vfs_getnewfsid(mp); 254 255 sbp = &mp->mnt_stat; 256 bcopy(pi->pi_name, sbp->f_mntfromname, sizeof pi->pi_name); 257 sbp->f_bsize = PAGE_SIZE; 258 sbp->f_iosize = PAGE_SIZE; --- 13 unchanged lines hidden (view full) --- 272pfs_unmount(struct mount *mp, int mntflags, struct thread *td) 273{ 274 struct pfs_info *pi; 275 int error; 276 277 pi = (struct pfs_info *)mp->mnt_data; 278 279 /* XXX do stuff with pi... */ |
280 | 280 |
281 error = vflush(mp, 0, (mntflags & MNT_FORCE) ? FORCECLOSE : 0); 282 return (error); 283} 284 285/* 286 * Return a root vnode 287 */ 288int --- 20 unchanged lines hidden (view full) --- 309 */ 310int 311pfs_init(struct pfs_info *pi, struct vfsconf *vfc) 312{ 313 struct pfs_node *root; 314 int error; 315 316 mtx_init(&pi->pi_mutex, "pseudofs", NULL, MTX_DEF); | 281 error = vflush(mp, 0, (mntflags & MNT_FORCE) ? FORCECLOSE : 0); 282 return (error); 283} 284 285/* 286 * Return a root vnode 287 */ 288int --- 20 unchanged lines hidden (view full) --- 309 */ 310int 311pfs_init(struct pfs_info *pi, struct vfsconf *vfc) 312{ 313 struct pfs_node *root; 314 int error; 315 316 mtx_init(&pi->pi_mutex, "pseudofs", NULL, MTX_DEF); |
317 | 317 |
318 /* set up the root diretory */ 319 MALLOC(root, struct pfs_node *, sizeof *root, 320 M_PFSNODES, M_WAITOK|M_ZERO); 321 root->pn_type = pfstype_root; 322 root->pn_name[0] = '/'; 323 root->pn_info = pi; 324 if (_pfs_fixup_dir(root) != 0) { 325 FREE(root, M_PFSNODES); --- 4 unchanged lines hidden (view full) --- 330 /* construct file hierarchy */ 331 error = (pi->pi_init)(pi, vfc); 332 if (error) { 333 pfs_destroy(root); 334 pi->pi_root = NULL; 335 mtx_destroy(&pi->pi_mutex); 336 return (error); 337 } | 318 /* set up the root diretory */ 319 MALLOC(root, struct pfs_node *, sizeof *root, 320 M_PFSNODES, M_WAITOK|M_ZERO); 321 root->pn_type = pfstype_root; 322 root->pn_name[0] = '/'; 323 root->pn_info = pi; 324 if (_pfs_fixup_dir(root) != 0) { 325 FREE(root, M_PFSNODES); --- 4 unchanged lines hidden (view full) --- 330 /* construct file hierarchy */ 331 error = (pi->pi_init)(pi, vfc); 332 if (error) { 333 pfs_destroy(root); 334 pi->pi_root = NULL; 335 mtx_destroy(&pi->pi_mutex); 336 return (error); 337 } |
338 | 338 |
339 pfs_fileno_init(pi); 340 if (bootverbose) 341 printf("%s registered\n", pi->pi_name); 342 return (0); 343} 344 345/* 346 * Destroy a pseudofs instance 347 */ 348int 349pfs_uninit(struct pfs_info *pi, struct vfsconf *vfc) 350{ 351 int error; | 339 pfs_fileno_init(pi); 340 if (bootverbose) 341 printf("%s registered\n", pi->pi_name); 342 return (0); 343} 344 345/* 346 * Destroy a pseudofs instance 347 */ 348int 349pfs_uninit(struct pfs_info *pi, struct vfsconf *vfc) 350{ 351 int error; |
352 | 352 |
353 pfs_fileno_uninit(pi); 354 pfs_destroy(pi->pi_root); 355 pi->pi_root = NULL; 356 mtx_destroy(&pi->pi_mutex); 357 if (bootverbose) 358 printf("%s unregistered\n", pi->pi_name); 359 error = (pi->pi_uninit)(pi, vfc); 360 return (error); --- 35 unchanged lines hidden --- | 353 pfs_fileno_uninit(pi); 354 pfs_destroy(pi->pi_root); 355 pi->pi_root = NULL; 356 mtx_destroy(&pi->pi_mutex); 357 if (bootverbose) 358 printf("%s unregistered\n", pi->pi_name); 359 error = (pi->pi_uninit)(pi, vfc); 360 return (error); --- 35 unchanged lines hidden --- |