10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*3898Srsb * Common Development and Distribution License (the "License"). 6*3898Srsb * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*3898Srsb * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/param.h> 300Sstevel@tonic-gate #include <sys/time.h> 310Sstevel@tonic-gate #include <sys/cred.h> 320Sstevel@tonic-gate #include <sys/vfs.h> 33*3898Srsb #include <sys/vfs_opreg.h> 340Sstevel@tonic-gate #include <sys/gfs.h> 350Sstevel@tonic-gate #include <sys/vnode.h> 360Sstevel@tonic-gate #include <sys/systm.h> 370Sstevel@tonic-gate #include <sys/errno.h> 380Sstevel@tonic-gate #include <sys/sysmacros.h> 390Sstevel@tonic-gate #include <fs/fs_subr.h> 400Sstevel@tonic-gate #include <sys/contract.h> 410Sstevel@tonic-gate #include <sys/contract_impl.h> 420Sstevel@tonic-gate #include <sys/ctfs.h> 430Sstevel@tonic-gate #include <sys/ctfs_impl.h> 440Sstevel@tonic-gate #include <sys/file.h> 450Sstevel@tonic-gate #include <sys/pathname.h> 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * CTFS routines for the /system/contract/all vnode. 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate 510Sstevel@tonic-gate static int ctfs_adir_do_readdir(vnode_t *, struct dirent64 *, int *, offset_t *, 520Sstevel@tonic-gate offset_t *, void *); 530Sstevel@tonic-gate static int ctfs_adir_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *); 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * ctfs_create_adirnode 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate /* ARGSUSED */ 590Sstevel@tonic-gate vnode_t * 600Sstevel@tonic-gate ctfs_create_adirnode(vnode_t *pvp) 610Sstevel@tonic-gate { 620Sstevel@tonic-gate vnode_t *vp = gfs_dir_create(sizeof (ctfs_adirnode_t), pvp, 630Sstevel@tonic-gate ctfs_ops_adir, NULL, NULL, CTFS_NAME_MAX, ctfs_adir_do_readdir, 640Sstevel@tonic-gate ctfs_adir_do_lookup); 650Sstevel@tonic-gate 660Sstevel@tonic-gate return (vp); 670Sstevel@tonic-gate } 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * ctfs_adir_getattr - VOP_GETATTR entry point 710Sstevel@tonic-gate */ 720Sstevel@tonic-gate /* ARGSUSED */ 730Sstevel@tonic-gate static int 740Sstevel@tonic-gate ctfs_adir_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr) 750Sstevel@tonic-gate { 760Sstevel@tonic-gate int i, total; 770Sstevel@tonic-gate 780Sstevel@tonic-gate vap->va_type = VDIR; 790Sstevel@tonic-gate vap->va_mode = 0555; 800Sstevel@tonic-gate for (i = 0, total = 0; i < ct_ntypes; i++) 810Sstevel@tonic-gate total += contract_type_count(ct_types[i]); 820Sstevel@tonic-gate vap->va_nlink = 2; 830Sstevel@tonic-gate vap->va_size = 2 + total; 840Sstevel@tonic-gate vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime; 850Sstevel@tonic-gate vap->va_ctime.tv_nsec = 0; 860Sstevel@tonic-gate vap->va_mtime = vap->va_atime = vap->va_ctime; 870Sstevel@tonic-gate ctfs_common_getattr(vp, vap); 880Sstevel@tonic-gate 890Sstevel@tonic-gate return (0); 900Sstevel@tonic-gate } 910Sstevel@tonic-gate 920Sstevel@tonic-gate static int 930Sstevel@tonic-gate ctfs_adir_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop) 940Sstevel@tonic-gate { 950Sstevel@tonic-gate int i; 960Sstevel@tonic-gate contract_t *ct; 970Sstevel@tonic-gate 980Sstevel@tonic-gate i = stoi((char **)&nm); 990Sstevel@tonic-gate if (*nm != '\0') 1000Sstevel@tonic-gate return (ENOENT); 1010Sstevel@tonic-gate 102789Sahrens ct = contract_ptr(i, VTOZONE(vp)->zone_uniqid); 1030Sstevel@tonic-gate if (ct == NULL) 1040Sstevel@tonic-gate return (ENOENT); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate *vpp = ctfs_create_symnode(vp, ct); 1070Sstevel@tonic-gate *inop = CTFS_INO_CT_LINK(ct->ct_id); 1080Sstevel@tonic-gate contract_rele(ct); 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate return (0); 1110Sstevel@tonic-gate } 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* ARGSUSED */ 1140Sstevel@tonic-gate static int 1150Sstevel@tonic-gate ctfs_adir_do_readdir(vnode_t *vp, struct dirent64 *dp, int *eofp, 1160Sstevel@tonic-gate offset_t *offp, offset_t *nextp, void *unused) 1170Sstevel@tonic-gate { 1180Sstevel@tonic-gate uint64_t zuniqid; 1190Sstevel@tonic-gate ctid_t next; 1200Sstevel@tonic-gate 121789Sahrens zuniqid = VTOZONE(vp)->zone_uniqid; 1220Sstevel@tonic-gate next = contract_lookup(zuniqid, *offp); 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate if (next == -1) { 1250Sstevel@tonic-gate *eofp = 1; 1260Sstevel@tonic-gate return (0); 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate dp->d_ino = CTFS_INO_CT_LINK(next); 1300Sstevel@tonic-gate numtos(next, dp->d_name); 1310Sstevel@tonic-gate *offp = next; 1320Sstevel@tonic-gate *nextp = next + 1; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate return (0); 1350Sstevel@tonic-gate } 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_adir[] = { 138*3898Srsb { VOPNAME_OPEN, { .vop_open = ctfs_open } }, 139*3898Srsb { VOPNAME_CLOSE, { .vop_close = ctfs_close } }, 140*3898Srsb { VOPNAME_IOCTL, { .error = fs_inval } }, 141*3898Srsb { VOPNAME_GETATTR, { .vop_getattr = ctfs_adir_getattr } }, 142*3898Srsb { VOPNAME_ACCESS, { .vop_access = ctfs_access_dir } }, 143*3898Srsb { VOPNAME_READDIR, { .vop_readdir = gfs_vop_readdir } }, 144*3898Srsb { VOPNAME_LOOKUP, { .vop_lookup = gfs_vop_lookup } }, 145*3898Srsb { VOPNAME_SEEK, { .vop_seek = fs_seek } }, 146*3898Srsb { VOPNAME_INACTIVE, { .vop_inactive = gfs_vop_inactive } }, 1470Sstevel@tonic-gate { NULL, NULL } 1480Sstevel@tonic-gate }; 149