1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 32*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #ifndef _SYS_VFS_H 36*7c478bd9Sstevel@tonic-gate #define _SYS_VFS_H 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/cred.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/statvfs.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/refstr.h> 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 48*7c478bd9Sstevel@tonic-gate extern "C" { 49*7c478bd9Sstevel@tonic-gate #endif 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate /* 52*7c478bd9Sstevel@tonic-gate * Data associated with mounted file systems. 53*7c478bd9Sstevel@tonic-gate */ 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate /* 56*7c478bd9Sstevel@tonic-gate * Operations vector. This is used internal to the kernel; file systems 57*7c478bd9Sstevel@tonic-gate * supply their list of operations via vfs_setfsops(). 58*7c478bd9Sstevel@tonic-gate */ 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate typedef struct vfsops vfsops_t; 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /* 63*7c478bd9Sstevel@tonic-gate * File system identifier. Should be unique (at least per machine). 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate typedef struct { 66*7c478bd9Sstevel@tonic-gate int val[2]; /* file system id type */ 67*7c478bd9Sstevel@tonic-gate } fsid_t; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate /* 70*7c478bd9Sstevel@tonic-gate * File identifier. Should be unique per filesystem on a single 71*7c478bd9Sstevel@tonic-gate * machine. This is typically called by a stateless file server 72*7c478bd9Sstevel@tonic-gate * in order to generate "file handles". 73*7c478bd9Sstevel@tonic-gate * 74*7c478bd9Sstevel@tonic-gate * Do not change the definition of struct fid ... fid_t without 75*7c478bd9Sstevel@tonic-gate * letting the CacheFS group know about it! They will have to do at 76*7c478bd9Sstevel@tonic-gate * least two things, in the same change that changes this structure: 77*7c478bd9Sstevel@tonic-gate * 1. change CFSVERSION in usr/src/uts/common/sys/fs/cachefs_fs.h 78*7c478bd9Sstevel@tonic-gate * 2. put the old version # in the canupgrade array 79*7c478bd9Sstevel@tonic-gate * in cachfs_upgrade() in usr/src/cmd/fs.d/cachefs/fsck/fsck.c 80*7c478bd9Sstevel@tonic-gate * This is necessary because CacheFS stores FIDs on disk. 81*7c478bd9Sstevel@tonic-gate * 82*7c478bd9Sstevel@tonic-gate * Many underlying file systems cast a struct fid into other 83*7c478bd9Sstevel@tonic-gate * file system dependent structures which may require 4 byte alignment. 84*7c478bd9Sstevel@tonic-gate * Because a fid starts with a short it may not be 4 byte aligned, the 85*7c478bd9Sstevel@tonic-gate * fid_pad will force the alignment. 86*7c478bd9Sstevel@tonic-gate */ 87*7c478bd9Sstevel@tonic-gate #define MAXFIDSZ 64 88*7c478bd9Sstevel@tonic-gate #define OLD_MAXFIDSZ 16 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate typedef struct fid { 91*7c478bd9Sstevel@tonic-gate union { 92*7c478bd9Sstevel@tonic-gate long fid_pad; 93*7c478bd9Sstevel@tonic-gate struct { 94*7c478bd9Sstevel@tonic-gate ushort_t len; /* length of data in bytes */ 95*7c478bd9Sstevel@tonic-gate char data[MAXFIDSZ]; /* data (variable len) */ 96*7c478bd9Sstevel@tonic-gate } _fid; 97*7c478bd9Sstevel@tonic-gate } un; 98*7c478bd9Sstevel@tonic-gate } fid_t; 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 101*7c478bd9Sstevel@tonic-gate /* 102*7c478bd9Sstevel@tonic-gate * Solaris 64 - use old-style cache format with 32-bit aligned fid for on-disk 103*7c478bd9Sstevel@tonic-gate * struct compatibility. 104*7c478bd9Sstevel@tonic-gate */ 105*7c478bd9Sstevel@tonic-gate typedef struct fid32 { 106*7c478bd9Sstevel@tonic-gate union { 107*7c478bd9Sstevel@tonic-gate int32_t fid_pad; 108*7c478bd9Sstevel@tonic-gate struct { 109*7c478bd9Sstevel@tonic-gate uint16_t len; /* length of data in bytes */ 110*7c478bd9Sstevel@tonic-gate char data[MAXFIDSZ]; /* data (variable len) */ 111*7c478bd9Sstevel@tonic-gate } _fid; 112*7c478bd9Sstevel@tonic-gate } un; 113*7c478bd9Sstevel@tonic-gate } fid32_t; 114*7c478bd9Sstevel@tonic-gate #else /* not _SYSCALL32 */ 115*7c478bd9Sstevel@tonic-gate #define fid32 fid 116*7c478bd9Sstevel@tonic-gate typedef fid_t fid32_t; 117*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate #define fid_len un._fid.len 120*7c478bd9Sstevel@tonic-gate #define fid_data un._fid.data 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate /* 123*7c478bd9Sstevel@tonic-gate * Structure defining a mount option for a filesystem. 124*7c478bd9Sstevel@tonic-gate * option names are found in mntent.h 125*7c478bd9Sstevel@tonic-gate */ 126*7c478bd9Sstevel@tonic-gate typedef struct mntopt { 127*7c478bd9Sstevel@tonic-gate char *mo_name; /* option name */ 128*7c478bd9Sstevel@tonic-gate char **mo_cancel; /* list of options cancelled by this one */ 129*7c478bd9Sstevel@tonic-gate char *mo_arg; /* argument string for this option */ 130*7c478bd9Sstevel@tonic-gate int mo_flags; /* flags for this mount option */ 131*7c478bd9Sstevel@tonic-gate void *mo_data; /* filesystem specific data */ 132*7c478bd9Sstevel@tonic-gate } mntopt_t; 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate /* 135*7c478bd9Sstevel@tonic-gate * Flags that apply to mount options 136*7c478bd9Sstevel@tonic-gate */ 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate #define MO_SET 0x01 /* option is set */ 139*7c478bd9Sstevel@tonic-gate #define MO_NODISPLAY 0x02 /* option not listed in mnttab */ 140*7c478bd9Sstevel@tonic-gate #define MO_HASVALUE 0x04 /* option takes a value */ 141*7c478bd9Sstevel@tonic-gate #define MO_IGNORE 0x08 /* option ignored by parser */ 142*7c478bd9Sstevel@tonic-gate #define MO_DEFAULT MO_SET /* option is on by default */ 143*7c478bd9Sstevel@tonic-gate #define MO_TAG 0x10 /* flags a tag set by user program */ 144*7c478bd9Sstevel@tonic-gate #define MO_EMPTY 0x20 /* empty space in option table */ 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate #define VFS_NOFORCEOPT 0x01 /* honor MO_IGNORE (don't set option) */ 147*7c478bd9Sstevel@tonic-gate #define VFS_DISPLAY 0x02 /* Turn off MO_NODISPLAY bit for opt */ 148*7c478bd9Sstevel@tonic-gate #define VFS_NODISPLAY 0x04 /* Turn on MO_NODISPLAY bit for opt */ 149*7c478bd9Sstevel@tonic-gate #define VFS_CREATEOPT 0x08 /* Create the opt if it's not there */ 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate /* 152*7c478bd9Sstevel@tonic-gate * Structure holding mount option strings for the mounted file system. 153*7c478bd9Sstevel@tonic-gate */ 154*7c478bd9Sstevel@tonic-gate typedef struct mntopts { 155*7c478bd9Sstevel@tonic-gate uint_t mo_count; /* number of entries in table */ 156*7c478bd9Sstevel@tonic-gate mntopt_t *mo_list; /* list of mount options */ 157*7c478bd9Sstevel@tonic-gate } mntopts_t; 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate /* 160*7c478bd9Sstevel@tonic-gate * Structure per mounted file system. Each mounted file system has 161*7c478bd9Sstevel@tonic-gate * an array of operations and an instance record. 162*7c478bd9Sstevel@tonic-gate * 163*7c478bd9Sstevel@tonic-gate * The file systems are kept on a doubly linked circular list headed by 164*7c478bd9Sstevel@tonic-gate * "rootvfs". 165*7c478bd9Sstevel@tonic-gate * File system implementations should not access this list; 166*7c478bd9Sstevel@tonic-gate * it's intended for use only in the kernel's vfs layer. 167*7c478bd9Sstevel@tonic-gate * 168*7c478bd9Sstevel@tonic-gate * Each zone also has its own list of mounts, containing filesystems mounted 169*7c478bd9Sstevel@tonic-gate * somewhere within the filesystem tree rooted at the zone's rootpath. The 170*7c478bd9Sstevel@tonic-gate * list is doubly linked to match the global list. 171*7c478bd9Sstevel@tonic-gate * 172*7c478bd9Sstevel@tonic-gate * mnttab locking: the in-kernel mnttab uses the vfs_mntpt, vfs_resource and 173*7c478bd9Sstevel@tonic-gate * vfs_mntopts fields in the vfs_t. mntpt and resource are refstr_ts that 174*7c478bd9Sstevel@tonic-gate * are set at mount time and can only be modified during a remount. 175*7c478bd9Sstevel@tonic-gate * It is safe to read these fields if you can prevent a remount on the vfs, 176*7c478bd9Sstevel@tonic-gate * or through the convenience funcs vfs_getmntpoint() and vfs_getresource(). 177*7c478bd9Sstevel@tonic-gate * The mntopts field may only be accessed through the provided convenience 178*7c478bd9Sstevel@tonic-gate * functions, as it is protected by the vfs list lock. Modifying a mount 179*7c478bd9Sstevel@tonic-gate * option requires grabbing the vfs list write lock, which can be a very 180*7c478bd9Sstevel@tonic-gate * high latency lock. 181*7c478bd9Sstevel@tonic-gate */ 182*7c478bd9Sstevel@tonic-gate struct zone; /* from zone.h */ 183*7c478bd9Sstevel@tonic-gate struct fem_head; /* from fem.h */ 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate typedef struct vfs { 186*7c478bd9Sstevel@tonic-gate struct vfs *vfs_next; /* next VFS in VFS list */ 187*7c478bd9Sstevel@tonic-gate struct vfs *vfs_prev; /* prev VFS in VFS list */ 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate /* vfs_op should not be used directly. Accessor functions are provided */ 190*7c478bd9Sstevel@tonic-gate vfsops_t *vfs_op; /* operations on VFS */ 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate struct vnode *vfs_vnodecovered; /* vnode mounted on */ 193*7c478bd9Sstevel@tonic-gate uint_t vfs_flag; /* flags */ 194*7c478bd9Sstevel@tonic-gate uint_t vfs_bsize; /* native block size */ 195*7c478bd9Sstevel@tonic-gate int vfs_fstype; /* file system type index */ 196*7c478bd9Sstevel@tonic-gate fsid_t vfs_fsid; /* file system id */ 197*7c478bd9Sstevel@tonic-gate void *vfs_data; /* private data */ 198*7c478bd9Sstevel@tonic-gate dev_t vfs_dev; /* device of mounted VFS */ 199*7c478bd9Sstevel@tonic-gate ulong_t vfs_bcount; /* I/O count (accounting) */ 200*7c478bd9Sstevel@tonic-gate struct vfs *vfs_list; /* sync list pointer */ 201*7c478bd9Sstevel@tonic-gate struct vfs *vfs_hash; /* hash list pointer */ 202*7c478bd9Sstevel@tonic-gate ksema_t vfs_reflock; /* mount/unmount/sync lock */ 203*7c478bd9Sstevel@tonic-gate uint_t vfs_count; /* vfs reference count */ 204*7c478bd9Sstevel@tonic-gate mntopts_t vfs_mntopts; /* options mounted with */ 205*7c478bd9Sstevel@tonic-gate refstr_t *vfs_resource; /* mounted resource name */ 206*7c478bd9Sstevel@tonic-gate refstr_t *vfs_mntpt; /* mount point name */ 207*7c478bd9Sstevel@tonic-gate time_t vfs_mtime; /* time we were mounted */ 208*7c478bd9Sstevel@tonic-gate struct fem_head *vfs_femhead; /* fs monitoring */ 209*7c478bd9Sstevel@tonic-gate /* 210*7c478bd9Sstevel@tonic-gate * Zones support. Note that the zone that "owns" the mount isn't 211*7c478bd9Sstevel@tonic-gate * necessarily the same as the zone in which the zone is visible. 212*7c478bd9Sstevel@tonic-gate * That is, vfs_zone and (vfs_zone_next|vfs_zone_prev) may refer to 213*7c478bd9Sstevel@tonic-gate * different zones. 214*7c478bd9Sstevel@tonic-gate */ 215*7c478bd9Sstevel@tonic-gate struct zone *vfs_zone; /* zone that owns the mount */ 216*7c478bd9Sstevel@tonic-gate struct vfs *vfs_zone_next; /* next VFS visible in zone */ 217*7c478bd9Sstevel@tonic-gate struct vfs *vfs_zone_prev; /* prev VFS visible in zone */ 218*7c478bd9Sstevel@tonic-gate } vfs_t; 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate /* 221*7c478bd9Sstevel@tonic-gate * VFS flags. 222*7c478bd9Sstevel@tonic-gate */ 223*7c478bd9Sstevel@tonic-gate #define VFS_RDONLY 0x01 /* read-only vfs */ 224*7c478bd9Sstevel@tonic-gate #define VFS_NOMNTTAB 0x02 /* vfs not seen in mnttab */ 225*7c478bd9Sstevel@tonic-gate #define VFS_NOSETUID 0x08 /* setuid disallowed */ 226*7c478bd9Sstevel@tonic-gate #define VFS_REMOUNT 0x10 /* modify mount options only */ 227*7c478bd9Sstevel@tonic-gate #define VFS_NOTRUNC 0x20 /* does not truncate long file names */ 228*7c478bd9Sstevel@tonic-gate #define VFS_UNLINKABLE 0x40 /* unlink(2) can be applied to root */ 229*7c478bd9Sstevel@tonic-gate #define VFS_PXFS 0x80 /* clustering: global fs proxy vfs */ 230*7c478bd9Sstevel@tonic-gate #define VFS_UNMOUNTED 0x100 /* file system has been unmounted */ 231*7c478bd9Sstevel@tonic-gate #define VFS_NBMAND 0x200 /* allow non-blocking mandatory locks */ 232*7c478bd9Sstevel@tonic-gate #define VFS_XATTR 0x400 /* fs supports extended attributes */ 233*7c478bd9Sstevel@tonic-gate #define VFS_NODEVICES 0x800 /* device-special files disallowed */ 234*7c478bd9Sstevel@tonic-gate #define VFS_NOEXEC 0x1000 /* executables disallowed */ 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate #define VFS_NORESOURCE "unspecified_resource" 237*7c478bd9Sstevel@tonic-gate #define VFS_NOMNTPT "unspecified_mountpoint" 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate /* 240*7c478bd9Sstevel@tonic-gate * Argument structure for mount(2). 241*7c478bd9Sstevel@tonic-gate * 242*7c478bd9Sstevel@tonic-gate * Flags are defined in <sys/mount.h>. 243*7c478bd9Sstevel@tonic-gate * 244*7c478bd9Sstevel@tonic-gate * Note that if the MS_SYSSPACE bit is set in flags, the pointer fields in 245*7c478bd9Sstevel@tonic-gate * this structure are to be interpreted as kernel addresses. File systems 246*7c478bd9Sstevel@tonic-gate * should be prepared for this possibility. 247*7c478bd9Sstevel@tonic-gate */ 248*7c478bd9Sstevel@tonic-gate struct mounta { 249*7c478bd9Sstevel@tonic-gate char *spec; 250*7c478bd9Sstevel@tonic-gate char *dir; 251*7c478bd9Sstevel@tonic-gate int flags; 252*7c478bd9Sstevel@tonic-gate char *fstype; 253*7c478bd9Sstevel@tonic-gate char *dataptr; 254*7c478bd9Sstevel@tonic-gate int datalen; 255*7c478bd9Sstevel@tonic-gate char *optptr; 256*7c478bd9Sstevel@tonic-gate int optlen; 257*7c478bd9Sstevel@tonic-gate }; 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate /* 260*7c478bd9Sstevel@tonic-gate * Reasons for calling the vfs_mountroot() operation. 261*7c478bd9Sstevel@tonic-gate */ 262*7c478bd9Sstevel@tonic-gate enum whymountroot { ROOT_INIT, ROOT_REMOUNT, ROOT_UNMOUNT}; 263*7c478bd9Sstevel@tonic-gate typedef enum whymountroot whymountroot_t; 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate /* 266*7c478bd9Sstevel@tonic-gate * Reasons for calling the VFS_VNSTATE(): 267*7c478bd9Sstevel@tonic-gate */ 268*7c478bd9Sstevel@tonic-gate enum vntrans { 269*7c478bd9Sstevel@tonic-gate VNTRANS_EXISTS, 270*7c478bd9Sstevel@tonic-gate VNTRANS_IDLED, 271*7c478bd9Sstevel@tonic-gate VNTRANS_RECLAIMED, 272*7c478bd9Sstevel@tonic-gate VNTRANS_DESTROYED 273*7c478bd9Sstevel@tonic-gate }; 274*7c478bd9Sstevel@tonic-gate typedef enum vntrans vntrans_t; 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate 279*7c478bd9Sstevel@tonic-gate /* 280*7c478bd9Sstevel@tonic-gate * Operations supported on virtual file system. 281*7c478bd9Sstevel@tonic-gate */ 282*7c478bd9Sstevel@tonic-gate struct vfsops { 283*7c478bd9Sstevel@tonic-gate int (*vfs_mount)(vfs_t *, vnode_t *, struct mounta *, cred_t *); 284*7c478bd9Sstevel@tonic-gate int (*vfs_unmount)(vfs_t *, int, cred_t *); 285*7c478bd9Sstevel@tonic-gate int (*vfs_root)(vfs_t *, vnode_t **); 286*7c478bd9Sstevel@tonic-gate int (*vfs_statvfs)(vfs_t *, statvfs64_t *); 287*7c478bd9Sstevel@tonic-gate int (*vfs_sync)(vfs_t *, short, cred_t *); 288*7c478bd9Sstevel@tonic-gate int (*vfs_vget)(vfs_t *, vnode_t **, fid_t *); 289*7c478bd9Sstevel@tonic-gate int (*vfs_mountroot)(vfs_t *, enum whymountroot); 290*7c478bd9Sstevel@tonic-gate int (*vfs_freevfs)(vfs_t *); 291*7c478bd9Sstevel@tonic-gate int (*vfs_vnstate)(vfs_t *, vnode_t *, vntrans_t); 292*7c478bd9Sstevel@tonic-gate }; 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate extern int fsop_mount(vfs_t *, vnode_t *, struct mounta *, cred_t *); 295*7c478bd9Sstevel@tonic-gate extern int fsop_unmount(vfs_t *, int, cred_t *); 296*7c478bd9Sstevel@tonic-gate extern int fsop_root(vfs_t *, vnode_t **); 297*7c478bd9Sstevel@tonic-gate extern int fsop_statfs(vfs_t *, statvfs64_t *); 298*7c478bd9Sstevel@tonic-gate extern int fsop_sync(vfs_t *, short, cred_t *); 299*7c478bd9Sstevel@tonic-gate extern int fsop_vget(vfs_t *, vnode_t **, fid_t *); 300*7c478bd9Sstevel@tonic-gate extern int fsop_mountroot(vfs_t *, enum whymountroot); 301*7c478bd9Sstevel@tonic-gate extern void fsop_freefs(vfs_t *); 302*7c478bd9Sstevel@tonic-gate extern int fsop_sync_by_kind(int, short, cred_t *); 303*7c478bd9Sstevel@tonic-gate extern int fsop_vnstate(vfs_t *, vnode_t *, vntrans_t); 304*7c478bd9Sstevel@tonic-gate 305*7c478bd9Sstevel@tonic-gate #define VFS_MOUNT(vfsp, mvp, uap, cr) fsop_mount(vfsp, mvp, uap, cr) 306*7c478bd9Sstevel@tonic-gate #define VFS_UNMOUNT(vfsp, flag, cr) fsop_unmount(vfsp, flag, cr) 307*7c478bd9Sstevel@tonic-gate #define VFS_ROOT(vfsp, vpp) fsop_root(vfsp, vpp) 308*7c478bd9Sstevel@tonic-gate #define VFS_STATVFS(vfsp, sp) fsop_statfs(vfsp, sp) 309*7c478bd9Sstevel@tonic-gate #define VFS_SYNC(vfsp, flag, cr) fsop_sync(vfsp, flag, cr) 310*7c478bd9Sstevel@tonic-gate #define VFS_VGET(vfsp, vpp, fidp) fsop_vget(vfsp, vpp, fidp) 311*7c478bd9Sstevel@tonic-gate #define VFS_MOUNTROOT(vfsp, init) fsop_mountroot(vfsp, init) 312*7c478bd9Sstevel@tonic-gate #define VFS_FREEVFS(vfsp) fsop_freefs(vfsp) 313*7c478bd9Sstevel@tonic-gate #define VFS_VNSTATE(vfsp, vn, ns) fsop_vnstate(vfsp, vn, ns) 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate #define VFSNAME_MOUNT "mount" 316*7c478bd9Sstevel@tonic-gate #define VFSNAME_UNMOUNT "unmount" 317*7c478bd9Sstevel@tonic-gate #define VFSNAME_ROOT "root" 318*7c478bd9Sstevel@tonic-gate #define VFSNAME_STATVFS "statvfs" 319*7c478bd9Sstevel@tonic-gate #define VFSNAME_SYNC "sync" 320*7c478bd9Sstevel@tonic-gate #define VFSNAME_VGET "vget" 321*7c478bd9Sstevel@tonic-gate #define VFSNAME_MOUNTROOT "mountroot" 322*7c478bd9Sstevel@tonic-gate #define VFSNAME_FREEVFS "freevfs" 323*7c478bd9Sstevel@tonic-gate #define VFSNAME_VNSTATE "vnstate" 324*7c478bd9Sstevel@tonic-gate /* 325*7c478bd9Sstevel@tonic-gate * Filesystem type switch table. 326*7c478bd9Sstevel@tonic-gate */ 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate typedef struct vfssw { 329*7c478bd9Sstevel@tonic-gate char *vsw_name; /* type name -- max len _ST_FSTYPSZ */ 330*7c478bd9Sstevel@tonic-gate int (*vsw_init) (int, char *); 331*7c478bd9Sstevel@tonic-gate /* init routine (for non-loadable fs only) */ 332*7c478bd9Sstevel@tonic-gate int vsw_flag; /* flags */ 333*7c478bd9Sstevel@tonic-gate mntopts_t vsw_optproto; /* mount options table prototype */ 334*7c478bd9Sstevel@tonic-gate uint_t vsw_count; /* count of references */ 335*7c478bd9Sstevel@tonic-gate kmutex_t vsw_lock; /* lock to protect vsw_count */ 336*7c478bd9Sstevel@tonic-gate vfsops_t vsw_vfsops; /* filesystem operations vector */ 337*7c478bd9Sstevel@tonic-gate } vfssw_t; 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate /* 340*7c478bd9Sstevel@tonic-gate * Filesystem type definition record. All file systems must export a record 341*7c478bd9Sstevel@tonic-gate * of this type through their modlfs structure. 342*7c478bd9Sstevel@tonic-gate */ 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate typedef struct vfsdef_v3 { 345*7c478bd9Sstevel@tonic-gate int def_version; /* structure version, must be first */ 346*7c478bd9Sstevel@tonic-gate char *name; /* filesystem type name */ 347*7c478bd9Sstevel@tonic-gate int (*init) (int, char *); /* init routine */ 348*7c478bd9Sstevel@tonic-gate int flags; /* filesystem flags */ 349*7c478bd9Sstevel@tonic-gate mntopts_t *optproto; /* mount options table prototype */ 350*7c478bd9Sstevel@tonic-gate } vfsdef_v3; 351*7c478bd9Sstevel@tonic-gate 352*7c478bd9Sstevel@tonic-gate typedef struct vfsdef_v3 vfsdef_t; 353*7c478bd9Sstevel@tonic-gate 354*7c478bd9Sstevel@tonic-gate enum { 355*7c478bd9Sstevel@tonic-gate VFSDEF_VERSION = 3 356*7c478bd9Sstevel@tonic-gate }; 357*7c478bd9Sstevel@tonic-gate 358*7c478bd9Sstevel@tonic-gate /* 359*7c478bd9Sstevel@tonic-gate * Generic operations vector types (used for vfs/vnode ops registration). 360*7c478bd9Sstevel@tonic-gate */ 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate extern int fs_default(); /* "default" function placeholder */ 363*7c478bd9Sstevel@tonic-gate extern int fs_error(); /* "error" function placeholder */ 364*7c478bd9Sstevel@tonic-gate 365*7c478bd9Sstevel@tonic-gate int fs_build_vector(void *vector, int *unused_ops, 366*7c478bd9Sstevel@tonic-gate const fs_operation_trans_def_t *translation, 367*7c478bd9Sstevel@tonic-gate const fs_operation_def_t *operations); 368*7c478bd9Sstevel@tonic-gate 369*7c478bd9Sstevel@tonic-gate /* 370*7c478bd9Sstevel@tonic-gate * flags for vfssw and vfsdef 371*7c478bd9Sstevel@tonic-gate */ 372*7c478bd9Sstevel@tonic-gate #define VSW_HASPROTO 0x01 /* struct has a mount options prototype */ 373*7c478bd9Sstevel@tonic-gate #define VSW_CANRWRO 0x02 /* file system can transition from rw to ro */ 374*7c478bd9Sstevel@tonic-gate #define VSW_CANREMOUNT 0x04 /* file system supports remounts */ 375*7c478bd9Sstevel@tonic-gate #define VSW_NOTZONESAFE 0x08 /* zone_enter(2) should fail for these files */ 376*7c478bd9Sstevel@tonic-gate #define VSW_VOLATILEDEV 0x10 /* vfs_dev can change each time fs is mounted */ 377*7c478bd9Sstevel@tonic-gate 378*7c478bd9Sstevel@tonic-gate #define VSW_INSTALLED 0x8000 /* this vsw is associated with a file system */ 379*7c478bd9Sstevel@tonic-gate 380*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 381*7c478bd9Sstevel@tonic-gate /* 382*7c478bd9Sstevel@tonic-gate * Public operations. 383*7c478bd9Sstevel@tonic-gate */ 384*7c478bd9Sstevel@tonic-gate struct umounta; 385*7c478bd9Sstevel@tonic-gate struct statvfsa; 386*7c478bd9Sstevel@tonic-gate struct fstatvfsa; 387*7c478bd9Sstevel@tonic-gate 388*7c478bd9Sstevel@tonic-gate int vfs_setfsops(int, const fs_operation_def_t *, vfsops_t **); 389*7c478bd9Sstevel@tonic-gate int vfs_makefsops(const fs_operation_def_t *, vfsops_t **); 390*7c478bd9Sstevel@tonic-gate void vfs_freevfsops(vfsops_t *); 391*7c478bd9Sstevel@tonic-gate int vfs_freevfsops_by_type(int); 392*7c478bd9Sstevel@tonic-gate void vfs_setops(vfs_t *, vfsops_t *); 393*7c478bd9Sstevel@tonic-gate vfsops_t *vfs_getops(vfs_t *vfsp); 394*7c478bd9Sstevel@tonic-gate int vfs_matchops(vfs_t *, vfsops_t *); 395*7c478bd9Sstevel@tonic-gate int vfs_can_sync(vfs_t *vfsp); 396*7c478bd9Sstevel@tonic-gate void vfs_init(vfs_t *vfsp, vfsops_t *, void *); 397*7c478bd9Sstevel@tonic-gate void vn_exists(vnode_t *); 398*7c478bd9Sstevel@tonic-gate void vn_idle(vnode_t *); 399*7c478bd9Sstevel@tonic-gate void vn_reclaim(vnode_t *); 400*7c478bd9Sstevel@tonic-gate void vn_invalid(vnode_t *); 401*7c478bd9Sstevel@tonic-gate 402*7c478bd9Sstevel@tonic-gate int rootconf(void); 403*7c478bd9Sstevel@tonic-gate int svm_rootconf(void); 404*7c478bd9Sstevel@tonic-gate int domount(char *, struct mounta *, vnode_t *, struct cred *, 405*7c478bd9Sstevel@tonic-gate struct vfs **); 406*7c478bd9Sstevel@tonic-gate int dounmount(struct vfs *, int, cred_t *); 407*7c478bd9Sstevel@tonic-gate int vfs_lock(struct vfs *); 408*7c478bd9Sstevel@tonic-gate int vfs_rlock(struct vfs *); 409*7c478bd9Sstevel@tonic-gate void vfs_lock_wait(struct vfs *); 410*7c478bd9Sstevel@tonic-gate void vfs_rlock_wait(struct vfs *); 411*7c478bd9Sstevel@tonic-gate void vfs_unlock(struct vfs *); 412*7c478bd9Sstevel@tonic-gate int vfs_lock_held(struct vfs *); 413*7c478bd9Sstevel@tonic-gate struct _kthread *vfs_lock_owner(struct vfs *); 414*7c478bd9Sstevel@tonic-gate void sync(void); 415*7c478bd9Sstevel@tonic-gate void vfs_sync(int); 416*7c478bd9Sstevel@tonic-gate void vfs_mountroot(void); 417*7c478bd9Sstevel@tonic-gate void vfs_add(vnode_t *, struct vfs *, int); 418*7c478bd9Sstevel@tonic-gate void vfs_remove(struct vfs *); 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate /* The following functions are not for general use by filesystems */ 421*7c478bd9Sstevel@tonic-gate 422*7c478bd9Sstevel@tonic-gate void vfs_createopttbl(mntopts_t *, const char *); 423*7c478bd9Sstevel@tonic-gate void vfs_copyopttbl(const mntopts_t *, mntopts_t *); 424*7c478bd9Sstevel@tonic-gate void vfs_mergeopttbl(const mntopts_t *, const mntopts_t *, mntopts_t *); 425*7c478bd9Sstevel@tonic-gate void vfs_freeopttbl(mntopts_t *); 426*7c478bd9Sstevel@tonic-gate void vfs_parsemntopts(mntopts_t *, char *, int); 427*7c478bd9Sstevel@tonic-gate int vfs_buildoptionstr(const mntopts_t *, char *, int); 428*7c478bd9Sstevel@tonic-gate struct mntopt *vfs_hasopt(const mntopts_t *, const char *); 429*7c478bd9Sstevel@tonic-gate void vfs_mnttab_modtimeupd(void); 430*7c478bd9Sstevel@tonic-gate 431*7c478bd9Sstevel@tonic-gate void vfs_clearmntopt(struct vfs *, const char *); 432*7c478bd9Sstevel@tonic-gate void vfs_setmntopt(struct vfs *, const char *, const char *, int); 433*7c478bd9Sstevel@tonic-gate void vfs_setresource(struct vfs *, const char *); 434*7c478bd9Sstevel@tonic-gate void vfs_setmntpoint(struct vfs *, const char *); 435*7c478bd9Sstevel@tonic-gate refstr_t *vfs_getresource(const struct vfs *); 436*7c478bd9Sstevel@tonic-gate refstr_t *vfs_getmntpoint(const struct vfs *); 437*7c478bd9Sstevel@tonic-gate int vfs_optionisset(const struct vfs *, const char *, char **); 438*7c478bd9Sstevel@tonic-gate int vfs_settag(uint_t, uint_t, const char *, const char *, cred_t *); 439*7c478bd9Sstevel@tonic-gate int vfs_clrtag(uint_t, uint_t, const char *, const char *, cred_t *); 440*7c478bd9Sstevel@tonic-gate void vfs_syncall(void); 441*7c478bd9Sstevel@tonic-gate void vfs_syncprogress(void); 442*7c478bd9Sstevel@tonic-gate void vfsinit(void); 443*7c478bd9Sstevel@tonic-gate void vfs_unmountall(void); 444*7c478bd9Sstevel@tonic-gate void vfs_make_fsid(fsid_t *, dev_t, int); 445*7c478bd9Sstevel@tonic-gate void vfs_addmip(dev_t, struct vfs *); 446*7c478bd9Sstevel@tonic-gate void vfs_delmip(struct vfs *); 447*7c478bd9Sstevel@tonic-gate int vfs_devismounted(dev_t); 448*7c478bd9Sstevel@tonic-gate int vfs_devmounting(dev_t, struct vfs *); 449*7c478bd9Sstevel@tonic-gate int vfs_opsinuse(vfsops_t *); 450*7c478bd9Sstevel@tonic-gate struct vfs *getvfs(fsid_t *); 451*7c478bd9Sstevel@tonic-gate struct vfs *vfs_dev2vfsp(dev_t); 452*7c478bd9Sstevel@tonic-gate struct vfs *vfs_mntpoint2vfsp(const char *); 453*7c478bd9Sstevel@tonic-gate struct vfssw *allocate_vfssw(char *); 454*7c478bd9Sstevel@tonic-gate struct vfssw *vfs_getvfssw(char *); 455*7c478bd9Sstevel@tonic-gate struct vfssw *vfs_getvfsswbyname(char *); 456*7c478bd9Sstevel@tonic-gate struct vfssw *vfs_getvfsswbyvfsops(vfsops_t *); 457*7c478bd9Sstevel@tonic-gate void vfs_refvfssw(struct vfssw *); 458*7c478bd9Sstevel@tonic-gate void vfs_unrefvfssw(struct vfssw *); 459*7c478bd9Sstevel@tonic-gate uint_t vf_to_stf(uint_t); 460*7c478bd9Sstevel@tonic-gate void vfs_mnttab_modtime(timespec_t *); 461*7c478bd9Sstevel@tonic-gate void vfs_mnttab_poll(timespec_t *, struct pollhead **); 462*7c478bd9Sstevel@tonic-gate 463*7c478bd9Sstevel@tonic-gate void vfs_list_lock(void); 464*7c478bd9Sstevel@tonic-gate void vfs_list_read_lock(void); 465*7c478bd9Sstevel@tonic-gate void vfs_list_unlock(void); 466*7c478bd9Sstevel@tonic-gate void vfs_list_add(struct vfs *); 467*7c478bd9Sstevel@tonic-gate void vfs_list_remove(struct vfs *); 468*7c478bd9Sstevel@tonic-gate void vfs_hold(vfs_t *vfsp); 469*7c478bd9Sstevel@tonic-gate void vfs_rele(vfs_t *vfsp); 470*7c478bd9Sstevel@tonic-gate void fs_freevfs(vfs_t *); 471*7c478bd9Sstevel@tonic-gate void vfs_root_redev(vfs_t *vfsp, dev_t ndev, int fstype); 472*7c478bd9Sstevel@tonic-gate 473*7c478bd9Sstevel@tonic-gate int vfs_zone_change_safe(vfs_t *); 474*7c478bd9Sstevel@tonic-gate 475*7c478bd9Sstevel@tonic-gate #define VFSHASH(maj, min) (((int)((maj)+(min))) & (vfshsz - 1)) 476*7c478bd9Sstevel@tonic-gate #define VFS_ON_LIST(vfsp) \ 477*7c478bd9Sstevel@tonic-gate ((vfsp)->vfs_next != (vfsp) && (vfsp)->vfs_next != NULL) 478*7c478bd9Sstevel@tonic-gate 479*7c478bd9Sstevel@tonic-gate /* 480*7c478bd9Sstevel@tonic-gate * Globals. 481*7c478bd9Sstevel@tonic-gate */ 482*7c478bd9Sstevel@tonic-gate 483*7c478bd9Sstevel@tonic-gate extern struct vfssw vfssw[]; /* table of filesystem types */ 484*7c478bd9Sstevel@tonic-gate extern krwlock_t vfssw_lock; 485*7c478bd9Sstevel@tonic-gate extern char rootfstype[]; /* name of root fstype */ 486*7c478bd9Sstevel@tonic-gate extern const int nfstype; /* # of elements in vfssw array */ 487*7c478bd9Sstevel@tonic-gate extern vfsops_t *EIO_vfsops; /* operations for vfs being torn-down */ 488*7c478bd9Sstevel@tonic-gate 489*7c478bd9Sstevel@tonic-gate extern int vfs_vnode_path; /* tunable to control paths in vnodes */ 490*7c478bd9Sstevel@tonic-gate 491*7c478bd9Sstevel@tonic-gate /* 492*7c478bd9Sstevel@tonic-gate * The following variables are private to the the kernel's vfs layer. File 493*7c478bd9Sstevel@tonic-gate * system implementations should not access them. 494*7c478bd9Sstevel@tonic-gate */ 495*7c478bd9Sstevel@tonic-gate extern struct vfs *rootvfs; /* ptr to root vfs structure */ 496*7c478bd9Sstevel@tonic-gate typedef struct { 497*7c478bd9Sstevel@tonic-gate struct vfs *rvfs_head; /* head vfs in chain */ 498*7c478bd9Sstevel@tonic-gate kmutex_t rvfs_lock; /* mutex protecting this chain */ 499*7c478bd9Sstevel@tonic-gate uint32_t rvfs_len; /* length of this chain */ 500*7c478bd9Sstevel@tonic-gate } rvfs_t; 501*7c478bd9Sstevel@tonic-gate extern rvfs_t *rvfs_list; 502*7c478bd9Sstevel@tonic-gate extern int vfshsz; /* # of elements in rvfs_head array */ 503*7c478bd9Sstevel@tonic-gate extern const mntopts_t vfs_mntopts; /* globally recognized options */ 504*7c478bd9Sstevel@tonic-gate 505*7c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 506*7c478bd9Sstevel@tonic-gate 507*7c478bd9Sstevel@tonic-gate #define VFS_HOLD(vfsp) { \ 508*7c478bd9Sstevel@tonic-gate vfs_hold(vfsp); \ 509*7c478bd9Sstevel@tonic-gate } 510*7c478bd9Sstevel@tonic-gate 511*7c478bd9Sstevel@tonic-gate #define VFS_RELE(vfsp) { \ 512*7c478bd9Sstevel@tonic-gate vfs_rele(vfsp); \ 513*7c478bd9Sstevel@tonic-gate } 514*7c478bd9Sstevel@tonic-gate 515*7c478bd9Sstevel@tonic-gate #define VFS_INIT(vfsp, op, data) vfs_init((vfsp), (op), (data)) 516*7c478bd9Sstevel@tonic-gate 517*7c478bd9Sstevel@tonic-gate #define _VFS_INIT(vfsp, op, data) { \ 518*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_count = 0; \ 519*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_next = vfsp; \ 520*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_prev = vfsp; \ 521*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_zone_next = vfsp; \ 522*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_zone_prev = vfsp; \ 523*7c478bd9Sstevel@tonic-gate vfs_setops((vfsp), (op)); \ 524*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_flag = 0; \ 525*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_data = (data); \ 526*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_resource = NULL; \ 527*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_mntpt = NULL; \ 528*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_mntopts.mo_count = 0; \ 529*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_mntopts.mo_list = NULL; \ 530*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_femhead = NULL; \ 531*7c478bd9Sstevel@tonic-gate (vfsp)->vfs_zone = NULL; \ 532*7c478bd9Sstevel@tonic-gate sema_init(&(vfsp)->vfs_reflock, 1, NULL, SEMA_DEFAULT, NULL); \ 533*7c478bd9Sstevel@tonic-gate } 534*7c478bd9Sstevel@tonic-gate 535*7c478bd9Sstevel@tonic-gate #define VFS_INSTALLED(vfsswp) (((vfsswp)->vsw_flag & VSW_INSTALLED) != 0) 536*7c478bd9Sstevel@tonic-gate #define ALLOCATED_VFSSW(vswp) ((vswp)->vsw_name[0] != '\0') 537*7c478bd9Sstevel@tonic-gate #define RLOCK_VFSSW() (rw_enter(&vfssw_lock, RW_READER)) 538*7c478bd9Sstevel@tonic-gate #define RUNLOCK_VFSSW() (rw_exit(&vfssw_lock)) 539*7c478bd9Sstevel@tonic-gate #define WLOCK_VFSSW() (rw_enter(&vfssw_lock, RW_WRITER)) 540*7c478bd9Sstevel@tonic-gate #define WUNLOCK_VFSSW() (rw_exit(&vfssw_lock)) 541*7c478bd9Sstevel@tonic-gate #define VFSSW_LOCKED() (RW_LOCK_HELD(&vfssw_lock)) 542*7c478bd9Sstevel@tonic-gate #define VFSSW_WRITE_LOCKED() (RW_WRITE_HELD(&vfssw_lock)) 543*7c478bd9Sstevel@tonic-gate /* 544*7c478bd9Sstevel@tonic-gate * VFS_SYNC flags. 545*7c478bd9Sstevel@tonic-gate */ 546*7c478bd9Sstevel@tonic-gate #define SYNC_ATTR 0x01 /* sync attributes only */ 547*7c478bd9Sstevel@tonic-gate #define SYNC_CLOSE 0x02 /* close open file */ 548*7c478bd9Sstevel@tonic-gate #define SYNC_ALL 0x04 /* force to sync all fs */ 549*7c478bd9Sstevel@tonic-gate 550*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 551*7c478bd9Sstevel@tonic-gate } 552*7c478bd9Sstevel@tonic-gate #endif 553*7c478bd9Sstevel@tonic-gate 554*7c478bd9Sstevel@tonic-gate #endif /* _SYS_VFS_H */ 555