tunefs.c revision 105120
11558Srgrimes/* 21558Srgrimes * Copyright (c) 1983, 1993 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * Redistribution and use in source and binary forms, with or without 61558Srgrimes * modification, are permitted provided that the following conditions 71558Srgrimes * are met: 81558Srgrimes * 1. Redistributions of source code must retain the above copyright 91558Srgrimes * notice, this list of conditions and the following disclaimer. 101558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111558Srgrimes * notice, this list of conditions and the following disclaimer in the 121558Srgrimes * documentation and/or other materials provided with the distribution. 131558Srgrimes * 3. All advertising materials mentioning features or use of this software 141558Srgrimes * must display the following acknowledgement: 151558Srgrimes * This product includes software developed by the University of 161558Srgrimes * California, Berkeley and its contributors. 171558Srgrimes * 4. Neither the name of the University nor the names of its contributors 181558Srgrimes * may be used to endorse or promote products derived from this software 191558Srgrimes * without specific prior written permission. 201558Srgrimes * 211558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311558Srgrimes * SUCH DAMAGE. 321558Srgrimes */ 331558Srgrimes 341558Srgrimes#ifndef lint 3538040Scharnierstatic const char copyright[] = 361558Srgrimes"@(#) Copyright (c) 1983, 1993\n\ 371558Srgrimes The Regents of the University of California. All rights reserved.\n"; 381558Srgrimes#endif /* not lint */ 391558Srgrimes 401558Srgrimes#ifndef lint 4138040Scharnier#if 0 421558Srgrimesstatic char sccsid[] = "@(#)tunefs.c 8.2 (Berkeley) 4/19/94"; 4338040Scharnier#endif 4438040Scharnierstatic const char rcsid[] = 4550476Speter "$FreeBSD: head/sbin/tunefs/tunefs.c 105120 2002-10-14 19:52:12Z rwatson $"; 461558Srgrimes#endif /* not lint */ 471558Srgrimes 481558Srgrimes/* 49102231Strhodes * tunefs: change layout parameters to an existing file system. 501558Srgrimes */ 511558Srgrimes#include <sys/param.h> 5242873Sluoqi#include <sys/mount.h> 5396478Sphk#include <sys/disklabel.h> 541558Srgrimes#include <sys/stat.h> 551558Srgrimes 5698542Smckusick#include <ufs/ufs/ufsmount.h> 5798542Smckusick#include <ufs/ufs/dinode.h> 581558Srgrimes#include <ufs/ffs/fs.h> 591558Srgrimes 601558Srgrimes#include <err.h> 611558Srgrimes#include <fcntl.h> 621558Srgrimes#include <fstab.h> 6338040Scharnier#include <paths.h> 641558Srgrimes#include <stdio.h> 651558Srgrimes#include <stdlib.h> 6658047Ssheldonh#include <string.h> 671558Srgrimes#include <unistd.h> 681558Srgrimes 691558Srgrimes/* the optimization warning string template */ 701558Srgrimes#define OPTWARN "should optimize for %s with minfree %s %d%%" 711558Srgrimes 721558Srgrimesunion { 731558Srgrimes struct fs sb; 741558Srgrimes char pad[MAXBSIZE]; 751558Srgrimes} sbun; 761558Srgrimes#define sblock sbun.sb 771558Srgrimes 781558Srgrimesint fi; 791558Srgrimeslong dev_bsize = 1; 801558Srgrimes 8198542Smckusickvoid bwrite(ufs2_daddr_t, const char *, int); 8298542Smckusickint bread(ufs2_daddr_t, char *, int); 8392883Simpvoid getsb(struct fs *, const char *); 8492883Simpvoid putsb(struct fs *, const char *, int); 8592883Simpvoid usage(void); 8692883Simpvoid printfs(void); 871558Srgrimes 881558Srgrimesint 891558Srgrimesmain(argc, argv) 901558Srgrimes int argc; 911558Srgrimes char *argv[]; 921558Srgrimes{ 9379750Sdd char *special; 9479750Sdd const char *name; 951558Srgrimes struct stat st; 96105120Srwatson int Aflag = 0, active = 0, aflag = 0; 97105120Srwatson int eflag = 0, fflag = 0, lflag = 0, mflag = 0; 9875377Smckusick int nflag = 0, oflag = 0, pflag = 0, sflag = 0; 99103005Sphk int evalue = 0, fvalue = 0; 10075377Smckusick int mvalue = 0, ovalue = 0, svalue = 0; 101105120Srwatson char *avalue = NULL, *lvalue = NULL, *nvalue = NULL; 1021558Srgrimes struct fstab *fs; 10379750Sdd const char *chg[2]; 10479750Sdd char device[MAXPATHLEN]; 10542873Sluoqi struct ufs_args args; 10642873Sluoqi struct statfs stfs; 10769314Scharnier int found_arg, ch; 1081558Srgrimes 10969314Scharnier if (argc < 3) 11069314Scharnier usage(); 11169314Scharnier found_arg = 0; /* at least one arg is required */ 112105120Srwatson while ((ch = getopt(argc, argv, "a:Ae:f:l:m:n:o:ps:")) != -1) 11369314Scharnier switch (ch) { 114105120Srwatson case 'a': 115105120Srwatson found_arg = 1; 116105120Srwatson name = "ACLs"; 117105120Srwatson avalue = optarg; 118105120Srwatson if (strcmp(avalue, "enable") && strcmp(avalue, "disable")) { 119105120Srwatson errx(10, "bad %s (options are %s)", name, 120105120Srwatson "`enable' or `disable'"); 121105120Srwatson } 122105120Srwatson aflag = 1; 123105120Srwatson break; 12469314Scharnier case 'A': 12569314Scharnier found_arg = 1; 12669314Scharnier Aflag++; 12769314Scharnier break; 12869314Scharnier case 'e': 12969314Scharnier found_arg = 1; 13069314Scharnier name = "maximum blocks per file in a cylinder group"; 13169829Scharnier evalue = atoi(optarg); 13269829Scharnier if (evalue < 1) 13369314Scharnier errx(10, "%s must be >= 1 (was %s)", name, optarg); 13469829Scharnier eflag = 1; 13569314Scharnier break; 13675377Smckusick case 'f': 13775377Smckusick found_arg = 1; 13875377Smckusick name = "average file size"; 13975377Smckusick fvalue = atoi(optarg); 14075377Smckusick if (fvalue < 1) 14175377Smckusick errx(10, "%s must be >= 1 (was %s)", name, optarg); 14275377Smckusick fflag = 1; 14375377Smckusick break; 144105120Srwatson case 'l': 145105120Srwatson found_arg = 1; 146105120Srwatson name = "multilabel MAC file system"; 147105120Srwatson lvalue = optarg; 148105120Srwatson if (strcmp(lvalue, "enable") && strcmp(lvalue, "disable")) { 149105120Srwatson errx(10, "bad %s (options are %s)", name, 150105120Srwatson "`enable' or `disable'"); 151105120Srwatson } 152105120Srwatson lflag = 1; 153105120Srwatson break; 15469314Scharnier case 'm': 15569314Scharnier found_arg = 1; 15669314Scharnier name = "minimum percentage of free space"; 15769829Scharnier mvalue = atoi(optarg); 15869829Scharnier if (mvalue < 0 || mvalue > 99) 15969314Scharnier errx(10, "bad %s (%s)", name, optarg); 16069829Scharnier mflag = 1; 16169314Scharnier break; 16269314Scharnier case 'n': 16369314Scharnier found_arg = 1; 16469314Scharnier name = "soft updates"; 16569829Scharnier nvalue = optarg; 16669829Scharnier if (strcmp(nvalue, "enable") && strcmp(nvalue, "disable")) { 16769314Scharnier errx(10, "bad %s (options are %s)", 16869314Scharnier name, "`enable' or `disable'"); 16969314Scharnier } 17069829Scharnier nflag = 1; 17169314Scharnier break; 17269314Scharnier case 'o': 17369314Scharnier found_arg = 1; 17469314Scharnier name = "optimization preference"; 17569314Scharnier chg[FS_OPTSPACE] = "space"; 17669314Scharnier chg[FS_OPTTIME] = "time"; 17769314Scharnier if (strcmp(optarg, chg[FS_OPTSPACE]) == 0) 17869829Scharnier ovalue = FS_OPTSPACE; 17969314Scharnier else if (strcmp(optarg, chg[FS_OPTTIME]) == 0) 18069829Scharnier ovalue = FS_OPTTIME; 18169314Scharnier else 18269314Scharnier errx(10, "bad %s (options are `space' or `time')", 1831558Srgrimes name); 18469829Scharnier oflag = 1; 18569314Scharnier break; 18669314Scharnier case 'p': 18771790Sben found_arg = 1; 18869829Scharnier pflag = 1; 18969829Scharnier break; 19075377Smckusick case 's': 19175377Smckusick found_arg = 1; 19275377Smckusick name = "expected number of files per directory"; 19375377Smckusick svalue = atoi(optarg); 19475377Smckusick if (svalue < 1) 19575377Smckusick errx(10, "%s must be >= 1 (was %s)", name, optarg); 19675377Smckusick sflag = 1; 19775377Smckusick break; 19869314Scharnier default: 19969314Scharnier usage(); 20069314Scharnier } 20169314Scharnier argc -= optind; 20269314Scharnier argv += optind; 2031558Srgrimes 20469314Scharnier if (found_arg == 0 || argc != 1) 20569314Scharnier usage(); 20669314Scharnier 20769829Scharnier special = argv[0]; 20869829Scharnier fs = getfsfile(special); 20969829Scharnier if (fs) { 21069829Scharnier if (statfs(special, &stfs) == 0 && 21169829Scharnier strcmp(special, stfs.f_mntonname) == 0) { 21269829Scharnier active = 1; 21369829Scharnier } 21469829Scharnier special = fs->fs_spec; 21569829Scharnier } 21669829Scharnieragain: 21769829Scharnier if (stat(special, &st) < 0) { 21869829Scharnier if (*special != '/') { 21969829Scharnier if (*special == 'r') 22069829Scharnier special++; 22184166Siedowse (void)snprintf(device, sizeof(device), "%s%s", 22280277Skris _PATH_DEV, special); 22369829Scharnier special = device; 22469829Scharnier goto again; 22569829Scharnier } 22669829Scharnier err(1, "%s", special); 22769829Scharnier } 22884166Siedowse if (fs == NULL && (st.st_mode & S_IFMT) == S_IFDIR) 229102231Strhodes errx(10, "%s: unknown file system", special); 23069829Scharnier getsb(&sblock, special); 23169829Scharnier 23269829Scharnier if (pflag) { 23369829Scharnier printfs(); 23469829Scharnier exit(0); 23569829Scharnier } 236105120Srwatson if (aflag) { 237105120Srwatson name = "ACLs"; 238105120Srwatson if (strcmp(avalue, "enable") == 0) { 239105120Srwatson if (sblock.fs_flags & FS_ACLS) { 240105120Srwatson warnx("%s remains unchanged as enabled", name); 241105120Srwatson } else { 242105120Srwatson sblock.fs_flags |= FS_ACLS; 243105120Srwatson warnx("%s set", name); 244105120Srwatson } 245105120Srwatson } else if (strcmp(avalue, "disable") == 0) { 246105120Srwatson if ((~sblock.fs_flags & FS_ACLS) == 247105120Srwatson FS_ACLS) { 248105120Srwatson warnx("%s remains unchanged as disabled", 249105120Srwatson name); 250105120Srwatson } else { 251105120Srwatson sblock.fs_flags &= ~FS_ACLS; 252105120Srwatson warnx("%s set", name); 253105120Srwatson } 254105120Srwatson } 255105120Srwatson } 25669829Scharnier if (eflag) { 25769829Scharnier name = "maximum blocks per file in a cylinder group"; 25869829Scharnier if (sblock.fs_maxbpg == evalue) { 25969829Scharnier warnx("%s remains unchanged as %d", name, evalue); 26069829Scharnier } 26169829Scharnier else { 26269829Scharnier warnx("%s changes from %d to %d", 26369829Scharnier name, sblock.fs_maxbpg, evalue); 26469829Scharnier sblock.fs_maxbpg = evalue; 26569829Scharnier } 26669829Scharnier } 26775377Smckusick if (fflag) { 26875377Smckusick name = "average file size"; 26975377Smckusick if (sblock.fs_avgfilesize == fvalue) { 27075377Smckusick warnx("%s remains unchanged as %d", name, fvalue); 27175377Smckusick } 27275377Smckusick else { 27375377Smckusick warnx("%s changes from %d to %d", 27475377Smckusick name, sblock.fs_avgfilesize, fvalue); 27575377Smckusick sblock.fs_avgfilesize = fvalue; 27675377Smckusick } 27775377Smckusick } 278105120Srwatson if (lflag) { 279105120Srwatson name = "multilabel"; 280105120Srwatson if (strcmp(lvalue, "enable") == 0) { 281105120Srwatson if (sblock.fs_flags & FS_MULTILABEL) { 282105120Srwatson warnx("%s remains unchanged as enabled", name); 283105120Srwatson } else { 284105120Srwatson sblock.fs_flags |= FS_MULTILABEL; 285105120Srwatson warnx("%s set", name); 286105120Srwatson } 287105120Srwatson } else if (strcmp(lvalue, "disable") == 0) { 288105120Srwatson if ((~sblock.fs_flags & FS_MULTILABEL) == 289105120Srwatson FS_MULTILABEL) { 290105120Srwatson warnx("%s remains unchanged as disabled", 291105120Srwatson name); 292105120Srwatson } else { 293105120Srwatson sblock.fs_flags &= ~FS_MULTILABEL; 294105120Srwatson warnx("%s set", name); 295105120Srwatson } 296105120Srwatson } 297105120Srwatson } 29869829Scharnier if (mflag) { 29969829Scharnier name = "minimum percentage of free space"; 30069829Scharnier if (sblock.fs_minfree == mvalue) { 30169829Scharnier warnx("%s remains unchanged as %d%%", name, mvalue); 30269829Scharnier } 30369829Scharnier else { 30469829Scharnier warnx("%s changes from %d%% to %d%%", 30569829Scharnier name, sblock.fs_minfree, mvalue); 30669829Scharnier sblock.fs_minfree = mvalue; 30769829Scharnier if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE) 30869829Scharnier warnx(OPTWARN, "time", ">=", MINFREE); 30969829Scharnier if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME) 31069829Scharnier warnx(OPTWARN, "space", "<", MINFREE); 31169829Scharnier } 31269829Scharnier } 31369829Scharnier if (nflag) { 31469829Scharnier name = "soft updates"; 31569829Scharnier if (strcmp(nvalue, "enable") == 0) { 31675498Smckusick if (sblock.fs_flags & FS_DOSOFTDEP) { 31769829Scharnier warnx("%s remains unchanged as enabled", name); 31875498Smckusick } else if (sblock.fs_clean == 0) { 31975498Smckusick warnx("%s cannot be enabled until fsck is run", 32075498Smckusick name); 32169829Scharnier } else { 32269829Scharnier sblock.fs_flags |= FS_DOSOFTDEP; 32369829Scharnier warnx("%s set", name); 32469829Scharnier } 32569829Scharnier } else if (strcmp(nvalue, "disable") == 0) { 32669829Scharnier if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP) { 32769829Scharnier warnx("%s remains unchanged as disabled", name); 32869829Scharnier } else { 32969829Scharnier sblock.fs_flags &= ~FS_DOSOFTDEP; 33069829Scharnier warnx("%s cleared", name); 33169829Scharnier } 33269829Scharnier } 33369829Scharnier } 33469829Scharnier if (oflag) { 33569829Scharnier name = "optimization preference"; 33669829Scharnier chg[FS_OPTSPACE] = "space"; 33769829Scharnier chg[FS_OPTTIME] = "time"; 33869829Scharnier if (sblock.fs_optim == ovalue) { 33969829Scharnier warnx("%s remains unchanged as %s", name, chg[ovalue]); 34069829Scharnier } 34169829Scharnier else { 34269829Scharnier warnx("%s changes from %s to %s", 34369829Scharnier name, chg[sblock.fs_optim], chg[ovalue]); 34469829Scharnier sblock.fs_optim = ovalue; 34569829Scharnier if (sblock.fs_minfree >= MINFREE && 34669829Scharnier ovalue == FS_OPTSPACE) 34769829Scharnier warnx(OPTWARN, "time", ">=", MINFREE); 34869829Scharnier if (sblock.fs_minfree < MINFREE && 34969829Scharnier ovalue == FS_OPTTIME) 35069829Scharnier warnx(OPTWARN, "space", "<", MINFREE); 35169829Scharnier } 35269829Scharnier } 35375377Smckusick if (sflag) { 35475377Smckusick name = "expected number of files per directory"; 35575377Smckusick if (sblock.fs_avgfpdir == svalue) { 35675377Smckusick warnx("%s remains unchanged as %d", name, svalue); 35775377Smckusick } 35875377Smckusick else { 35975377Smckusick warnx("%s changes from %d to %d", 36075377Smckusick name, sblock.fs_avgfpdir, svalue); 36175377Smckusick sblock.fs_avgfpdir = svalue; 36275377Smckusick } 36375377Smckusick } 36469829Scharnier 36558047Ssheldonh putsb(&sblock, special, Aflag); 36642873Sluoqi if (active) { 36742873Sluoqi bzero(&args, sizeof(args)); 36842873Sluoqi if (mount("ufs", fs->fs_file, 36942873Sluoqi stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0) 37042873Sluoqi err(9, "%s: reload", special); 371102231Strhodes warnx("file system reloaded"); 37242873Sluoqi } 3731558Srgrimes exit(0); 3741558Srgrimes} 3751558Srgrimes 3761558Srgrimesvoid 3771558Srgrimesusage() 3781558Srgrimes{ 37938040Scharnier fprintf(stderr, "%s\n%s\n%s\n", 380105120Srwatson"usage: tunefs [-a enable | disable] [-A] [-e maxbpg] [-f avgfilesize]", 381105120Srwatson" [-l enable | disable] [-m minfree] [-n enable | disable]", 382105120Srwatson" [-o space | time] [-p] [-s avgfpdir] special | filesystem"); 3831558Srgrimes exit(2); 3841558Srgrimes} 3851558Srgrimes 38698542Smckusick/* 38798542Smckusick * Possible superblock locations ordered from most to least likely. 38898542Smckusick */ 38998542Smckusickstatic int sblock_try[] = SBLOCKSEARCH; 39098542Smckusickstatic ufs2_daddr_t sblockloc; 39198542Smckusick 3921558Srgrimesvoid 3931558Srgrimesgetsb(fs, file) 39479750Sdd struct fs *fs; 39579750Sdd const char *file; 3961558Srgrimes{ 39798542Smckusick int i; 3981558Srgrimes 39958047Ssheldonh fi = open(file, O_RDONLY); 4001558Srgrimes if (fi < 0) 4011558Srgrimes err(3, "cannot open %s", file); 40298542Smckusick for (i = 0; sblock_try[i] != -1; i++) { 40398542Smckusick if (bread(sblock_try[i], (char *)fs, SBLOCKSIZE)) 40498542Smckusick err(4, "%s: bad super block", file); 40598542Smckusick if ((fs->fs_magic == FS_UFS1_MAGIC || 40698542Smckusick (fs->fs_magic == FS_UFS2_MAGIC && 40798542Smckusick fs->fs_sblockloc == numfrags(fs, sblock_try[i]))) && 40898542Smckusick fs->fs_bsize <= MAXBSIZE && 40998542Smckusick fs->fs_bsize >= sizeof(struct fs)) 41098542Smckusick break; 41198542Smckusick } 41298542Smckusick if (sblock_try[i] == -1) 413102231Strhodes err(5, "Cannot find file system superblock"); 4141558Srgrimes dev_bsize = fs->fs_fsize / fsbtodb(fs, 1); 41598542Smckusick sblockloc = sblock_try[i] / dev_bsize; 4161558Srgrimes} 4171558Srgrimes 4181558Srgrimesvoid 41958047Ssheldonhputsb(fs, file, all) 42079750Sdd struct fs *fs; 42179750Sdd const char *file; 42258047Ssheldonh int all; 42358047Ssheldonh{ 42458047Ssheldonh int i; 42558047Ssheldonh 42658047Ssheldonh /* 42758047Ssheldonh * Re-open the device read-write. Use the read-only file 42858047Ssheldonh * descriptor as an interlock to prevent the device from 42958047Ssheldonh * being mounted while we are switching mode. 43058047Ssheldonh */ 43158047Ssheldonh i = fi; 43258047Ssheldonh fi = open(file, O_RDWR); 43358047Ssheldonh close(i); 43458047Ssheldonh if (fi < 0) 43558047Ssheldonh err(3, "cannot open %s", file); 43698542Smckusick bwrite(sblockloc, (const char *)fs, SBLOCKSIZE); 43758047Ssheldonh if (all) 43858047Ssheldonh for (i = 0; i < fs->fs_ncg; i++) 43958047Ssheldonh bwrite(fsbtodb(fs, cgsblock(fs, i)), 44098542Smckusick (const char *)fs, SBLOCKSIZE); 44158047Ssheldonh close(fi); 44258047Ssheldonh} 44358047Ssheldonh 44458047Ssheldonhvoid 4459315Sjoergprintfs() 4469315Sjoerg{ 44734266Sjulian warnx("soft updates: (-n) %s", 44834266Sjulian (sblock.fs_flags & FS_DOSOFTDEP)? "enabled" : "disabled"); 4499315Sjoerg warnx("maximum blocks per file in a cylinder group: (-e) %d", 4509315Sjoerg sblock.fs_maxbpg); 45175377Smckusick warnx("average file size: (-f) %d", 45275377Smckusick sblock.fs_avgfilesize); 45375377Smckusick warnx("average number of files in a directory: (-s) %d", 45475377Smckusick sblock.fs_avgfpdir); 4559315Sjoerg warnx("minimum percentage of free space: (-m) %d%%", 4569315Sjoerg sblock.fs_minfree); 4579315Sjoerg warnx("optimization preference: (-o) %s", 4589315Sjoerg sblock.fs_optim == FS_OPTSPACE ? "space" : "time"); 4599315Sjoerg if (sblock.fs_minfree >= MINFREE && 4609315Sjoerg sblock.fs_optim == FS_OPTSPACE) 4619315Sjoerg warnx(OPTWARN, "time", ">=", MINFREE); 4629315Sjoerg if (sblock.fs_minfree < MINFREE && 4639315Sjoerg sblock.fs_optim == FS_OPTTIME) 4649315Sjoerg warnx(OPTWARN, "space", "<", MINFREE); 4659315Sjoerg} 4669315Sjoerg 4679315Sjoergvoid 4681558Srgrimesbwrite(blk, buf, size) 46998542Smckusick ufs2_daddr_t blk; 47079750Sdd const char *buf; 4711558Srgrimes int size; 4721558Srgrimes{ 4731558Srgrimes 4741558Srgrimes if (lseek(fi, (off_t)blk * dev_bsize, SEEK_SET) < 0) 4751558Srgrimes err(6, "FS SEEK"); 4761558Srgrimes if (write(fi, buf, size) != size) 4771558Srgrimes err(7, "FS WRITE"); 4781558Srgrimes} 4791558Srgrimes 4801558Srgrimesint 4811558Srgrimesbread(bno, buf, cnt) 48298542Smckusick ufs2_daddr_t bno; 4831558Srgrimes char *buf; 4841558Srgrimes int cnt; 4851558Srgrimes{ 4861558Srgrimes int i; 4871558Srgrimes 4881558Srgrimes if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0) 4891558Srgrimes return(1); 4901558Srgrimes if ((i = read(fi, buf, cnt)) != cnt) { 4911558Srgrimes for(i=0; i<sblock.fs_bsize; i++) 4921558Srgrimes buf[i] = 0; 4931558Srgrimes return (1); 4941558Srgrimes } 4951558Srgrimes return (0); 4961558Srgrimes} 497