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 2003 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 #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * lockfs 31*7c478bd9Sstevel@tonic-gate * user interface to lockfs functionality 32*7c478bd9Sstevel@tonic-gate */ 33*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 34*7c478bd9Sstevel@tonic-gate #include <stdio.h> 35*7c478bd9Sstevel@tonic-gate #include <string.h> 36*7c478bd9Sstevel@tonic-gate #include <unistd.h> 37*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/mnttab.h> 40*7c478bd9Sstevel@tonic-gate #include <errno.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/lockfs.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/filio.h> 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #define bzero(s, n) memset(s, 0, n); 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate /* 47*7c478bd9Sstevel@tonic-gate * command line processing 48*7c478bd9Sstevel@tonic-gate */ 49*7c478bd9Sstevel@tonic-gate extern char *optarg; 50*7c478bd9Sstevel@tonic-gate extern int optind; 51*7c478bd9Sstevel@tonic-gate extern int opterr; 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate extern void exit(); 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate static void exitusage(); 56*7c478bd9Sstevel@tonic-gate static void printstatusline(); 57*7c478bd9Sstevel@tonic-gate static void printstatus(); 58*7c478bd9Sstevel@tonic-gate static void flushfs(); 59*7c478bd9Sstevel@tonic-gate static void lockfs(); 60*7c478bd9Sstevel@tonic-gate static void getmntnames(); 61*7c478bd9Sstevel@tonic-gate static void getcmdnames(); 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate /* 64*7c478bd9Sstevel@tonic-gate * -a = all 65*7c478bd9Sstevel@tonic-gate * -v = verbose 66*7c478bd9Sstevel@tonic-gate */ 67*7c478bd9Sstevel@tonic-gate int all = 0; 68*7c478bd9Sstevel@tonic-gate int verbose = 0; 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* 71*7c478bd9Sstevel@tonic-gate * exitstatus 72*7c478bd9Sstevel@tonic-gate * 0 all ok 73*7c478bd9Sstevel@tonic-gate * 1 internal error 74*7c478bd9Sstevel@tonic-gate * 2 system call error 75*7c478bd9Sstevel@tonic-gate */ 76*7c478bd9Sstevel@tonic-gate int exitstatus = 0; 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate /* 79*7c478bd9Sstevel@tonic-gate * list of filenames 80*7c478bd9Sstevel@tonic-gate */ 81*7c478bd9Sstevel@tonic-gate struct filename { 82*7c478bd9Sstevel@tonic-gate struct filename *fn_next; 83*7c478bd9Sstevel@tonic-gate char *fn_name; 84*7c478bd9Sstevel@tonic-gate }; 85*7c478bd9Sstevel@tonic-gate struct filename *fnanchor = 0; 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /* 88*7c478bd9Sstevel@tonic-gate * default request is `file system lock status' 89*7c478bd9Sstevel@tonic-gate * default lock type is `unlock' 90*7c478bd9Sstevel@tonic-gate * -wnduhfe changes them 91*7c478bd9Sstevel@tonic-gate */ 92*7c478bd9Sstevel@tonic-gate int request = _FIOLFSS; 93*7c478bd9Sstevel@tonic-gate u_short lock = LOCKFS_ULOCK; 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate /* 96*7c478bd9Sstevel@tonic-gate * default comment is null 97*7c478bd9Sstevel@tonic-gate * -c changes it 98*7c478bd9Sstevel@tonic-gate */ 99*7c478bd9Sstevel@tonic-gate caddr_t comment = 0; 100*7c478bd9Sstevel@tonic-gate u_long comlen = 0; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* 103*7c478bd9Sstevel@tonic-gate * for prettyprint 104*7c478bd9Sstevel@tonic-gate */ 105*7c478bd9Sstevel@tonic-gate int firsttime = 0; 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate /* 108*7c478bd9Sstevel@tonic-gate * no unlocks printed 109*7c478bd9Sstevel@tonic-gate */ 110*7c478bd9Sstevel@tonic-gate int no_unlocks_printed = 0; 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate /* 113*7c478bd9Sstevel@tonic-gate * file system was modified during hlock/wlock/elock 114*7c478bd9Sstevel@tonic-gate */ 115*7c478bd9Sstevel@tonic-gate #define LOCKWARN(FN, S) \ 116*7c478bd9Sstevel@tonic-gate { \ 117*7c478bd9Sstevel@tonic-gate if (verbose) \ 118*7c478bd9Sstevel@tonic-gate printf("WARNING: %s was modified while %s locked\n", FN, S); \ 119*7c478bd9Sstevel@tonic-gate exitstatus = 2; \ 120*7c478bd9Sstevel@tonic-gate } 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate /* 123*7c478bd9Sstevel@tonic-gate * forward reference 124*7c478bd9Sstevel@tonic-gate */ 125*7c478bd9Sstevel@tonic-gate char *malloc(); 126*7c478bd9Sstevel@tonic-gate 127*7c478bd9Sstevel@tonic-gate void 128*7c478bd9Sstevel@tonic-gate main(argc, argv) 129*7c478bd9Sstevel@tonic-gate int argc; 130*7c478bd9Sstevel@tonic-gate char **argv; 131*7c478bd9Sstevel@tonic-gate { 132*7c478bd9Sstevel@tonic-gate int c; 133*7c478bd9Sstevel@tonic-gate struct filename *fnp; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate exitstatus = 0; 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate /* 138*7c478bd9Sstevel@tonic-gate * process command line 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate opterr = 0; 141*7c478bd9Sstevel@tonic-gate optarg = 0; 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "vfwnduheac:")) != -1) 144*7c478bd9Sstevel@tonic-gate switch (c) { 145*7c478bd9Sstevel@tonic-gate case 'v': 146*7c478bd9Sstevel@tonic-gate verbose = 1; 147*7c478bd9Sstevel@tonic-gate break; 148*7c478bd9Sstevel@tonic-gate case 'f': 149*7c478bd9Sstevel@tonic-gate request = _FIOFFS; 150*7c478bd9Sstevel@tonic-gate break; 151*7c478bd9Sstevel@tonic-gate case 'w': 152*7c478bd9Sstevel@tonic-gate lock = LOCKFS_WLOCK; 153*7c478bd9Sstevel@tonic-gate request = _FIOLFS; 154*7c478bd9Sstevel@tonic-gate break; 155*7c478bd9Sstevel@tonic-gate case 'n': 156*7c478bd9Sstevel@tonic-gate lock = LOCKFS_NLOCK; 157*7c478bd9Sstevel@tonic-gate request = _FIOLFS; 158*7c478bd9Sstevel@tonic-gate break; 159*7c478bd9Sstevel@tonic-gate case 'd': 160*7c478bd9Sstevel@tonic-gate lock = LOCKFS_DLOCK; 161*7c478bd9Sstevel@tonic-gate request = _FIOLFS; 162*7c478bd9Sstevel@tonic-gate break; 163*7c478bd9Sstevel@tonic-gate case 'h': 164*7c478bd9Sstevel@tonic-gate lock = LOCKFS_HLOCK; 165*7c478bd9Sstevel@tonic-gate request = _FIOLFS; 166*7c478bd9Sstevel@tonic-gate break; 167*7c478bd9Sstevel@tonic-gate case 'e': 168*7c478bd9Sstevel@tonic-gate lock = LOCKFS_ELOCK; 169*7c478bd9Sstevel@tonic-gate request = _FIOLFS; 170*7c478bd9Sstevel@tonic-gate break; 171*7c478bd9Sstevel@tonic-gate case 'u': 172*7c478bd9Sstevel@tonic-gate lock = LOCKFS_ULOCK; 173*7c478bd9Sstevel@tonic-gate request = _FIOLFS; 174*7c478bd9Sstevel@tonic-gate break; 175*7c478bd9Sstevel@tonic-gate case 'a': 176*7c478bd9Sstevel@tonic-gate all = 1; 177*7c478bd9Sstevel@tonic-gate break; 178*7c478bd9Sstevel@tonic-gate case 'c': 179*7c478bd9Sstevel@tonic-gate comment = optarg; 180*7c478bd9Sstevel@tonic-gate comlen = strlen(optarg)+1; 181*7c478bd9Sstevel@tonic-gate request = _FIOLFS; 182*7c478bd9Sstevel@tonic-gate break; 183*7c478bd9Sstevel@tonic-gate default: 184*7c478bd9Sstevel@tonic-gate exitusage(); 185*7c478bd9Sstevel@tonic-gate break; 186*7c478bd9Sstevel@tonic-gate } 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate if (argc == 1) { 189*7c478bd9Sstevel@tonic-gate no_unlocks_printed = 1; 190*7c478bd9Sstevel@tonic-gate all = 1; 191*7c478bd9Sstevel@tonic-gate } 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate if (all) 194*7c478bd9Sstevel@tonic-gate /* 195*7c478bd9Sstevel@tonic-gate * use /etc/mtab 196*7c478bd9Sstevel@tonic-gate */ 197*7c478bd9Sstevel@tonic-gate getmntnames(); 198*7c478bd9Sstevel@tonic-gate else 199*7c478bd9Sstevel@tonic-gate /* 200*7c478bd9Sstevel@tonic-gate * use command line 201*7c478bd9Sstevel@tonic-gate */ 202*7c478bd9Sstevel@tonic-gate getcmdnames(argc, argv, optind); 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate /* 205*7c478bd9Sstevel@tonic-gate * for each filename, doit 206*7c478bd9Sstevel@tonic-gate */ 207*7c478bd9Sstevel@tonic-gate for (fnp = fnanchor; fnp; fnp = fnp->fn_next) { 208*7c478bd9Sstevel@tonic-gate switch (request) { 209*7c478bd9Sstevel@tonic-gate case _FIOLFSS: 210*7c478bd9Sstevel@tonic-gate printstatus(fnp->fn_name); 211*7c478bd9Sstevel@tonic-gate break; 212*7c478bd9Sstevel@tonic-gate case _FIOLFS: 213*7c478bd9Sstevel@tonic-gate lockfs(fnp->fn_name); 214*7c478bd9Sstevel@tonic-gate break; 215*7c478bd9Sstevel@tonic-gate case _FIOFFS: 216*7c478bd9Sstevel@tonic-gate flushfs(fnp->fn_name); 217*7c478bd9Sstevel@tonic-gate break; 218*7c478bd9Sstevel@tonic-gate default: 219*7c478bd9Sstevel@tonic-gate break; 220*7c478bd9Sstevel@tonic-gate } 221*7c478bd9Sstevel@tonic-gate } 222*7c478bd9Sstevel@tonic-gate 223*7c478bd9Sstevel@tonic-gate /* 224*7c478bd9Sstevel@tonic-gate * all done 225*7c478bd9Sstevel@tonic-gate */ 226*7c478bd9Sstevel@tonic-gate exit(exitstatus); 227*7c478bd9Sstevel@tonic-gate } 228*7c478bd9Sstevel@tonic-gate /* 229*7c478bd9Sstevel@tonic-gate * exitusage 230*7c478bd9Sstevel@tonic-gate * bad command line, give hint 231*7c478bd9Sstevel@tonic-gate */ 232*7c478bd9Sstevel@tonic-gate void 233*7c478bd9Sstevel@tonic-gate exitusage() 234*7c478bd9Sstevel@tonic-gate { 235*7c478bd9Sstevel@tonic-gate printf("usage: lockfs [-dfhnuw] [-c string] [-a] [file system ...]\n"); 236*7c478bd9Sstevel@tonic-gate exit(1); 237*7c478bd9Sstevel@tonic-gate } 238*7c478bd9Sstevel@tonic-gate /* 239*7c478bd9Sstevel@tonic-gate * printstatusline 240*7c478bd9Sstevel@tonic-gate * prettyprint the status line 241*7c478bd9Sstevel@tonic-gate */ 242*7c478bd9Sstevel@tonic-gate void 243*7c478bd9Sstevel@tonic-gate printstatusline(fn, locktype, comment) 244*7c478bd9Sstevel@tonic-gate char *fn; 245*7c478bd9Sstevel@tonic-gate char *locktype; 246*7c478bd9Sstevel@tonic-gate char *comment; 247*7c478bd9Sstevel@tonic-gate { 248*7c478bd9Sstevel@tonic-gate if (firsttime++ == 0) 249*7c478bd9Sstevel@tonic-gate printf("%-20s %-10s %s\n", "Filesystem", "Locktype", "Comment"); 250*7c478bd9Sstevel@tonic-gate printf("%-20s %-10s %s\n", fn, locktype, comment); 251*7c478bd9Sstevel@tonic-gate } 252*7c478bd9Sstevel@tonic-gate /* 253*7c478bd9Sstevel@tonic-gate * printstatus 254*7c478bd9Sstevel@tonic-gate * get and prettyprint file system lock status 255*7c478bd9Sstevel@tonic-gate */ 256*7c478bd9Sstevel@tonic-gate void 257*7c478bd9Sstevel@tonic-gate printstatus(fn) 258*7c478bd9Sstevel@tonic-gate char *fn; 259*7c478bd9Sstevel@tonic-gate { 260*7c478bd9Sstevel@tonic-gate int fd; 261*7c478bd9Sstevel@tonic-gate int fsmod = 0; 262*7c478bd9Sstevel@tonic-gate char *locktype; 263*7c478bd9Sstevel@tonic-gate char commentbuffer[LOCKFS_MAXCOMMENTLEN+1]; 264*7c478bd9Sstevel@tonic-gate struct lockfs lf; 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate fd = open64(fn, O_RDONLY); 267*7c478bd9Sstevel@tonic-gate if (fd == -1) { 268*7c478bd9Sstevel@tonic-gate if (errno == EIO) 269*7c478bd9Sstevel@tonic-gate printstatusline(fn, "EIO", "May be hard locked"); 270*7c478bd9Sstevel@tonic-gate else 271*7c478bd9Sstevel@tonic-gate perror(fn); 272*7c478bd9Sstevel@tonic-gate exitstatus = 2; 273*7c478bd9Sstevel@tonic-gate return; 274*7c478bd9Sstevel@tonic-gate } 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate bzero((caddr_t)&lf, sizeof (struct lockfs)); 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate lf.lf_flags = LOCKFS_MOD; 279*7c478bd9Sstevel@tonic-gate lf.lf_comlen = LOCKFS_MAXCOMMENTLEN; 280*7c478bd9Sstevel@tonic-gate lf.lf_comment = commentbuffer; 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate if (ioctl(fd, _FIOLFSS, &lf) == -1) { 283*7c478bd9Sstevel@tonic-gate perror(fn); 284*7c478bd9Sstevel@tonic-gate close(fd); 285*7c478bd9Sstevel@tonic-gate exitstatus = 2; 286*7c478bd9Sstevel@tonic-gate return; 287*7c478bd9Sstevel@tonic-gate } 288*7c478bd9Sstevel@tonic-gate switch (lf.lf_lock) { 289*7c478bd9Sstevel@tonic-gate case LOCKFS_ULOCK: 290*7c478bd9Sstevel@tonic-gate if (no_unlocks_printed) 291*7c478bd9Sstevel@tonic-gate goto out; 292*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_BUSY(&lf)) 293*7c478bd9Sstevel@tonic-gate locktype = "(unlock)"; 294*7c478bd9Sstevel@tonic-gate else 295*7c478bd9Sstevel@tonic-gate locktype = "unlock"; 296*7c478bd9Sstevel@tonic-gate break; 297*7c478bd9Sstevel@tonic-gate case LOCKFS_WLOCK: 298*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_BUSY(&lf)) 299*7c478bd9Sstevel@tonic-gate locktype = "(write)"; 300*7c478bd9Sstevel@tonic-gate else { 301*7c478bd9Sstevel@tonic-gate locktype = "write"; 302*7c478bd9Sstevel@tonic-gate fsmod = LOCKFS_IS_MOD(&lf); 303*7c478bd9Sstevel@tonic-gate } 304*7c478bd9Sstevel@tonic-gate break; 305*7c478bd9Sstevel@tonic-gate case LOCKFS_NLOCK: 306*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_BUSY(&lf)) 307*7c478bd9Sstevel@tonic-gate locktype = "(name)"; 308*7c478bd9Sstevel@tonic-gate else 309*7c478bd9Sstevel@tonic-gate locktype = "name"; 310*7c478bd9Sstevel@tonic-gate break; 311*7c478bd9Sstevel@tonic-gate case LOCKFS_DLOCK: 312*7c478bd9Sstevel@tonic-gate locktype = "delete"; 313*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_BUSY(&lf)) 314*7c478bd9Sstevel@tonic-gate locktype = "(delete)"; 315*7c478bd9Sstevel@tonic-gate else 316*7c478bd9Sstevel@tonic-gate locktype = "delete"; 317*7c478bd9Sstevel@tonic-gate break; 318*7c478bd9Sstevel@tonic-gate case LOCKFS_HLOCK: 319*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_BUSY(&lf)) 320*7c478bd9Sstevel@tonic-gate locktype = "(hard)"; 321*7c478bd9Sstevel@tonic-gate else { 322*7c478bd9Sstevel@tonic-gate locktype = "hard"; 323*7c478bd9Sstevel@tonic-gate fsmod = LOCKFS_IS_MOD(&lf); 324*7c478bd9Sstevel@tonic-gate } 325*7c478bd9Sstevel@tonic-gate break; 326*7c478bd9Sstevel@tonic-gate case LOCKFS_ELOCK: 327*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_BUSY(&lf)) 328*7c478bd9Sstevel@tonic-gate locktype = "(error)"; 329*7c478bd9Sstevel@tonic-gate else { 330*7c478bd9Sstevel@tonic-gate locktype = "error"; 331*7c478bd9Sstevel@tonic-gate fsmod = LOCKFS_IS_MOD(&lf); 332*7c478bd9Sstevel@tonic-gate } 333*7c478bd9Sstevel@tonic-gate break; 334*7c478bd9Sstevel@tonic-gate default: 335*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_BUSY(&lf)) 336*7c478bd9Sstevel@tonic-gate locktype = "(unknown)"; 337*7c478bd9Sstevel@tonic-gate else 338*7c478bd9Sstevel@tonic-gate locktype = "unknown"; 339*7c478bd9Sstevel@tonic-gate break; 340*7c478bd9Sstevel@tonic-gate } 341*7c478bd9Sstevel@tonic-gate lf.lf_comment[lf.lf_comlen] = '\0'; 342*7c478bd9Sstevel@tonic-gate printstatusline(fn, locktype, lf.lf_comment); 343*7c478bd9Sstevel@tonic-gate if (fsmod) 344*7c478bd9Sstevel@tonic-gate LOCKWARN(fn, locktype); 345*7c478bd9Sstevel@tonic-gate out: 346*7c478bd9Sstevel@tonic-gate close(fd); 347*7c478bd9Sstevel@tonic-gate } 348*7c478bd9Sstevel@tonic-gate /* 349*7c478bd9Sstevel@tonic-gate * flushfs 350*7c478bd9Sstevel@tonic-gate * push and invalidate at least the data that is *currently* dirty 351*7c478bd9Sstevel@tonic-gate */ 352*7c478bd9Sstevel@tonic-gate void 353*7c478bd9Sstevel@tonic-gate flushfs(fn) 354*7c478bd9Sstevel@tonic-gate char *fn; 355*7c478bd9Sstevel@tonic-gate { 356*7c478bd9Sstevel@tonic-gate int fd; 357*7c478bd9Sstevel@tonic-gate 358*7c478bd9Sstevel@tonic-gate fd = open64(fn, O_RDONLY); 359*7c478bd9Sstevel@tonic-gate if (fd == -1) { 360*7c478bd9Sstevel@tonic-gate perror(fn); 361*7c478bd9Sstevel@tonic-gate exitstatus = 2; 362*7c478bd9Sstevel@tonic-gate return; 363*7c478bd9Sstevel@tonic-gate } 364*7c478bd9Sstevel@tonic-gate 365*7c478bd9Sstevel@tonic-gate if (ioctl(fd, _FIOFFS, NULL) == -1) { 366*7c478bd9Sstevel@tonic-gate perror(fn); 367*7c478bd9Sstevel@tonic-gate close(fd); 368*7c478bd9Sstevel@tonic-gate exitstatus = 2; 369*7c478bd9Sstevel@tonic-gate return; 370*7c478bd9Sstevel@tonic-gate } 371*7c478bd9Sstevel@tonic-gate close(fd); 372*7c478bd9Sstevel@tonic-gate } 373*7c478bd9Sstevel@tonic-gate /* 374*7c478bd9Sstevel@tonic-gate * lockfs 375*7c478bd9Sstevel@tonic-gate * lock the file system 376*7c478bd9Sstevel@tonic-gate */ 377*7c478bd9Sstevel@tonic-gate void 378*7c478bd9Sstevel@tonic-gate lockfs(fn) 379*7c478bd9Sstevel@tonic-gate char *fn; 380*7c478bd9Sstevel@tonic-gate { 381*7c478bd9Sstevel@tonic-gate int fd; 382*7c478bd9Sstevel@tonic-gate struct lockfs lf; 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate fd = open64(fn, O_RDONLY); 385*7c478bd9Sstevel@tonic-gate if (fd == -1) { 386*7c478bd9Sstevel@tonic-gate perror(fn); 387*7c478bd9Sstevel@tonic-gate exitstatus = 2; 388*7c478bd9Sstevel@tonic-gate return; 389*7c478bd9Sstevel@tonic-gate } 390*7c478bd9Sstevel@tonic-gate 391*7c478bd9Sstevel@tonic-gate bzero((caddr_t)&lf, sizeof (struct lockfs)); 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate lf.lf_flags = LOCKFS_MOD; 394*7c478bd9Sstevel@tonic-gate if (ioctl(fd, _FIOLFSS, &lf) == -1) { 395*7c478bd9Sstevel@tonic-gate perror(fn); 396*7c478bd9Sstevel@tonic-gate close(fd); 397*7c478bd9Sstevel@tonic-gate exitstatus = 2; 398*7c478bd9Sstevel@tonic-gate return; 399*7c478bd9Sstevel@tonic-gate } 400*7c478bd9Sstevel@tonic-gate 401*7c478bd9Sstevel@tonic-gate if (!LOCKFS_IS_BUSY(&lf) && LOCKFS_IS_MOD(&lf)) { 402*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_HLOCK(&lf)) 403*7c478bd9Sstevel@tonic-gate LOCKWARN(fn, "hard"); 404*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_ELOCK(&lf)) 405*7c478bd9Sstevel@tonic-gate LOCKWARN(fn, "error"); 406*7c478bd9Sstevel@tonic-gate if (LOCKFS_IS_WLOCK(&lf)) 407*7c478bd9Sstevel@tonic-gate LOCKWARN(fn, "write"); 408*7c478bd9Sstevel@tonic-gate } 409*7c478bd9Sstevel@tonic-gate 410*7c478bd9Sstevel@tonic-gate lf.lf_lock = lock; 411*7c478bd9Sstevel@tonic-gate lf.lf_flags = 0; 412*7c478bd9Sstevel@tonic-gate lf.lf_key = lf.lf_key; 413*7c478bd9Sstevel@tonic-gate lf.lf_comment = comment; 414*7c478bd9Sstevel@tonic-gate lf.lf_comlen = (comment) ? strlen(comment)+1 : 0; 415*7c478bd9Sstevel@tonic-gate 416*7c478bd9Sstevel@tonic-gate if (ioctl(fd, _FIOLFS, &lf) == -1) { 417*7c478bd9Sstevel@tonic-gate perror(fn); 418*7c478bd9Sstevel@tonic-gate close(fd); 419*7c478bd9Sstevel@tonic-gate exitstatus = 2; 420*7c478bd9Sstevel@tonic-gate return; 421*7c478bd9Sstevel@tonic-gate } 422*7c478bd9Sstevel@tonic-gate close(fd); 423*7c478bd9Sstevel@tonic-gate } 424*7c478bd9Sstevel@tonic-gate /* 425*7c478bd9Sstevel@tonic-gate * getmntnames 426*7c478bd9Sstevel@tonic-gate * file names from /etc/mtab 427*7c478bd9Sstevel@tonic-gate */ 428*7c478bd9Sstevel@tonic-gate void 429*7c478bd9Sstevel@tonic-gate getmntnames() 430*7c478bd9Sstevel@tonic-gate { 431*7c478bd9Sstevel@tonic-gate int fnlen; 432*7c478bd9Sstevel@tonic-gate struct filename *fnp; 433*7c478bd9Sstevel@tonic-gate struct filename *fnpc; 434*7c478bd9Sstevel@tonic-gate FILE *mnttab; 435*7c478bd9Sstevel@tonic-gate struct mnttab mnt, *mntp = &mnt; 436*7c478bd9Sstevel@tonic-gate 437*7c478bd9Sstevel@tonic-gate fnpc = fnanchor; 438*7c478bd9Sstevel@tonic-gate 439*7c478bd9Sstevel@tonic-gate if ((mnttab = fopen(MNTTAB, "r")) == NULL) { 440*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Can't open %s\n", MNTTAB); 441*7c478bd9Sstevel@tonic-gate perror(MNTTAB); 442*7c478bd9Sstevel@tonic-gate exit(32); 443*7c478bd9Sstevel@tonic-gate } 444*7c478bd9Sstevel@tonic-gate while ((getmntent(mnttab, mntp)) == 0) { 445*7c478bd9Sstevel@tonic-gate if (strcmp(mntp->mnt_fstype, MNTTYPE_UFS) != 0) 446*7c478bd9Sstevel@tonic-gate continue; 447*7c478bd9Sstevel@tonic-gate fnlen = strlen(mntp->mnt_mountp) + 1; 448*7c478bd9Sstevel@tonic-gate fnp = (struct filename *)malloc(sizeof (struct filename)); 449*7c478bd9Sstevel@tonic-gate fnp->fn_name = malloc((u_int)fnlen); 450*7c478bd9Sstevel@tonic-gate strcpy(fnp->fn_name, mntp->mnt_mountp); 451*7c478bd9Sstevel@tonic-gate fnp->fn_next = NULL; 452*7c478bd9Sstevel@tonic-gate if (fnpc) 453*7c478bd9Sstevel@tonic-gate fnpc->fn_next = fnp; 454*7c478bd9Sstevel@tonic-gate else 455*7c478bd9Sstevel@tonic-gate fnanchor = fnp; 456*7c478bd9Sstevel@tonic-gate fnpc = fnp; 457*7c478bd9Sstevel@tonic-gate } 458*7c478bd9Sstevel@tonic-gate fclose(mnttab); 459*7c478bd9Sstevel@tonic-gate } 460*7c478bd9Sstevel@tonic-gate /* 461*7c478bd9Sstevel@tonic-gate * getcmdnames 462*7c478bd9Sstevel@tonic-gate * file names from command line 463*7c478bd9Sstevel@tonic-gate */ 464*7c478bd9Sstevel@tonic-gate void 465*7c478bd9Sstevel@tonic-gate getcmdnames(argc, argv, i) 466*7c478bd9Sstevel@tonic-gate int argc; 467*7c478bd9Sstevel@tonic-gate char **argv; 468*7c478bd9Sstevel@tonic-gate int i; 469*7c478bd9Sstevel@tonic-gate { 470*7c478bd9Sstevel@tonic-gate struct filename *fnp; 471*7c478bd9Sstevel@tonic-gate struct filename *fnpc; 472*7c478bd9Sstevel@tonic-gate 473*7c478bd9Sstevel@tonic-gate for (fnpc = fnanchor; i < argc; ++i) { 474*7c478bd9Sstevel@tonic-gate fnp = (struct filename *)malloc(sizeof (struct filename)); 475*7c478bd9Sstevel@tonic-gate fnp->fn_name = *(argv+i); 476*7c478bd9Sstevel@tonic-gate fnp->fn_next = NULL; 477*7c478bd9Sstevel@tonic-gate if (fnpc) 478*7c478bd9Sstevel@tonic-gate fnpc->fn_next = fnp; 479*7c478bd9Sstevel@tonic-gate else 480*7c478bd9Sstevel@tonic-gate fnanchor = fnp; 481*7c478bd9Sstevel@tonic-gate fnpc = fnp; 482*7c478bd9Sstevel@tonic-gate } 483*7c478bd9Sstevel@tonic-gate } 484