diff --git a/sys/fs/pseudofs/pseudofs.c b/sys/fs/pseudofs/pseudofs.c index f7ecaab187a5..6bb69a7c6c5f 100644 --- a/sys/fs/pseudofs/pseudofs.c +++ b/sys/fs/pseudofs/pseudofs.c @@ -392,4 +392,4 @@ static moduledata_t pseudofs_data = { NULL }; DECLARE_MODULE(pseudofs, pseudofs_data, SI_SUB_EXEC, SI_ORDER_FIRST); -MODULE_VERSION(pseudofs, 3); +MODULE_VERSION(pseudofs, 1); diff --git a/sys/fs/pseudofs/pseudofs.h b/sys/fs/pseudofs/pseudofs.h index b21d9b630730..2432748fe4f0 100644 --- a/sys/fs/pseudofs/pseudofs.h +++ b/sys/fs/pseudofs/pseudofs.h @@ -132,6 +132,15 @@ typedef int (*pfs_vis_t)(PFS_VIS_ARGS); int name(PFS_IOCTL_ARGS); typedef int (*pfs_ioctl_t)(PFS_IOCTL_ARGS); +/* + * Last-close callback + */ +#define PFS_CLOSE_ARGS \ + struct thread *td, struct proc *p, struct pfs_node *pn +#define PFS_CLOSE_PROTO(name) \ + int name(PFS_CLOSE_ARGS); +typedef int (*pfs_close_t)(PFS_CLOSE_ARGS); + /* * pfs_info: describes a pseudofs instance */ @@ -160,6 +169,7 @@ struct pfs_node { #define pn_func u1._pn_func #define pn_nodes u1._pn_nodes pfs_ioctl_t pn_ioctl; + pfs_close_t pn_close; pfs_attr_t pn_attr; pfs_vis_t pn_vis; void *pn_data; @@ -245,6 +255,6 @@ static struct vfsops name##_vfsops = { \ }; \ VFS_SET(name##_vfsops, name, VFCF_SYNTHETIC); \ MODULE_VERSION(name, version); \ -MODULE_DEPEND(name, pseudofs, 3, 3, 3); +MODULE_DEPEND(name, pseudofs, 1, 1, 1); #endif diff --git a/sys/fs/pseudofs/pseudofs_vnops.c b/sys/fs/pseudofs/pseudofs_vnops.c index 91614d67072a..1152c116b2d9 100644 --- a/sys/fs/pseudofs/pseudofs_vnops.c +++ b/sys/fs/pseudofs/pseudofs_vnops.c @@ -121,7 +121,32 @@ pfs_access(struct vop_access_args *va) static int pfs_close(struct vop_close_args *va) { - PFS_RETURN (0); + struct vnode *vn = va->a_vp; + struct pfs_vdata *pvd = (struct pfs_vdata *)vn->v_data; + struct pfs_node *pn = pvd->pvd_pn; + struct proc *proc; + int error; + + PFS_TRACE((pn->pn_name)); + + /* + * Do nothing unless this is the last close and the node has a + * last-close handler. + */ + if (vn->v_usecount > 1 || pn->pn_close == NULL) + PFS_RETURN (0); + + if (pvd->pvd_pid != NO_PID) + proc = pfind(pvd->pvd_pid); + else + proc = NULL; + + error = (pn->pn_close)(va->a_td, proc, pn); + + if (proc != NULL) + PROC_UNLOCK(proc); + + PFS_RETURN (error); } /*