summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorsbruno <sbruno@FreeBSD.org>2013-03-23 04:26:13 +0000
committersbruno <sbruno@FreeBSD.org>2013-03-23 04:26:13 +0000
commitee156374eead97ea0d36a374d0a9ccb6d2ed7e40 (patch)
tree0919d525762dd205d22121917dfe139e9308d76c /sbin
parent1bcec8f048d439f4090ca60786176dd52dbe87b1 (diff)
downloadFreeBSD-src-ee156374eead97ea0d36a374d0a9ccb6d2ed7e40.zip
FreeBSD-src-ee156374eead97ea0d36a374d0a9ccb6d2ed7e40.tar.gz
Revert svn r248625
Clang errors around printf could be trivially fixed, but the breakage in sbin/fsdb were to significant for this type of change. Submitter of this changeset has been notified and hopefully this can be restored soon.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fsck_ffs/fsck.h37
-rw-r--r--sbin/fsck_ffs/fsutil.c89
-rw-r--r--sbin/fsck_ffs/inode.c14
-rw-r--r--sbin/fsck_ffs/pass1.c39
-rw-r--r--sbin/fsck_ffs/pass5.c13
-rw-r--r--sbin/fsck_ffs/setup.c14
-rw-r--r--sbin/fsck_ffs/suj.c4
7 files changed, 56 insertions, 154 deletions
diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h
index 7b45d48..ef98fa2 100644
--- a/sbin/fsck_ffs/fsck.h
+++ b/sbin/fsck_ffs/fsck.h
@@ -198,6 +198,7 @@ struct timespec totalreadtime[BT_NUMBUFTYPES];
struct timespec startprog;
struct bufarea sblk; /* file system superblock */
+struct bufarea cgblk; /* cylinder group blocks */
struct bufarea *pdirbp; /* current directory contents */
struct bufarea *pbp; /* current inode block */
@@ -215,7 +216,9 @@ struct bufarea *pbp; /* current inode block */
} while (0)
#define sbdirty() dirty(&sblk)
+#define cgdirty() dirty(&cgblk)
#define sblock (*sblk.b_un.b_fs)
+#define cgrp (*cgblk.b_un.b_cg)
enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
ino_t cursnapshot;
@@ -358,37 +361,6 @@ struct ufs2_dinode ufs2_zino;
#define EEXIT 8 /* Standard error exit. */
-int flushentry(void);
-/*
- * Wrapper for malloc() that flushes the cylinder group cache to try
- * to get space.
- */
-static inline void*
-Malloc(int size)
-{
- void *retval;
-
- while ((retval = malloc(size)) == NULL)
- if (flushentry() == 0)
- break;
- return (retval);
-}
-
-/*
- * Wrapper for calloc() that flushes the cylinder group cache to try
- * to get space.
- */
-static inline void*
-Calloc(int cnt, int size)
-{
- void *retval;
-
- while ((retval = calloc(cnt, size)) == NULL)
- if (flushentry() == 0)
- break;
- return (retval);
-}
-
struct fstab;
@@ -406,7 +378,7 @@ void cacheino(union dinode *dp, ino_t inumber);
void catch(int);
void catchquit(int);
int changeino(ino_t dir, const char *name, ino_t newnum);
-int check_cgmagic(int cg, struct bufarea *cgbp);
+int check_cgmagic(int cg, struct cg *cgp);
int chkrange(ufs2_daddr_t blk, int cnt);
void ckfini(int markclean);
int ckinode(union dinode *dp, struct inodesc *);
@@ -426,7 +398,6 @@ void freeino(ino_t ino);
void freeinodebuf(void);
int ftypeok(union dinode *dp);
void getblk(struct bufarea *bp, ufs2_daddr_t blk, long size);
-struct bufarea *cgget(int cg);
struct bufarea *getdatablk(ufs2_daddr_t blkno, long size, int type);
struct inoinfo *getinoinfo(ino_t inumber);
union dinode *getnextinode(ino_t inumber, int rebuildcg);
diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c
index 10654ca..34cc29f 100644
--- a/sbin/fsck_ffs/fsutil.c
+++ b/sbin/fsck_ffs/fsutil.c
@@ -70,7 +70,6 @@ static struct timespec startpass, finishpass;
struct timeval slowio_starttime;
int slowio_delay_usec = 10000; /* Initial IO delay for background fsck */
int slowio_pollcnt;
-static struct bufarea cgblk; /* backup buffer for cylinder group blocks */
static TAILQ_HEAD(buflist, bufarea) bufhead; /* head of buffer cache list */
static int numbufs; /* size of buffer cache */
static char *buftype[BT_NUMBUFTYPES] = BT_NAMES;
@@ -164,7 +163,7 @@ bufinit(void)
char *bufp;
pbp = pdirbp = (struct bufarea *)0;
- bufp = Malloc((unsigned int)sblock.fs_bsize);
+ bufp = malloc((unsigned int)sblock.fs_bsize);
if (bufp == 0)
errx(EEXIT, "cannot allocate buffer pool");
cgblk.b_un.b_buf = bufp;
@@ -174,8 +173,8 @@ bufinit(void)
if (bufcnt < MINBUFS)
bufcnt = MINBUFS;
for (i = 0; i < bufcnt; i++) {
- bp = (struct bufarea *)Malloc(sizeof(struct bufarea));
- bufp = Malloc((unsigned int)sblock.fs_bsize);
+ bp = (struct bufarea *)malloc(sizeof(struct bufarea));
+ bufp = malloc((unsigned int)sblock.fs_bsize);
if (bp == NULL || bufp == NULL) {
if (i >= MINBUFS)
break;
@@ -194,57 +193,6 @@ bufinit(void)
}
/*
- * Manage cylinder group buffers.
- */
-static struct bufarea *cgbufs; /* header for cylinder group cache */
-static int flushtries; /* number of tries to reclaim memory */
-
-struct bufarea *
-cgget(int cg)
-{
- struct bufarea *cgbp;
- struct cg *cgp;
-
- if (cgbufs == NULL) {
- cgbufs = Calloc(sblock.fs_ncg, sizeof(struct bufarea));
- if (cgbufs == NULL)
- errx(EEXIT, "cannot allocate cylinder group buffers");
- }
- cgbp = &cgbufs[cg];
- if (cgbp->b_un.b_cg != NULL)
- return (cgbp);
- cgp = NULL;
- if (flushtries == 0)
- cgp = malloc((unsigned int)sblock.fs_cgsize);
- if (cgp == NULL) {
- getblk(&cgblk, cgtod(&sblock, cg), sblock.fs_cgsize);
- return (&cgblk);
- }
- cgbp->b_un.b_cg = cgp;
- initbarea(cgbp, BT_CYLGRP);
- getblk(cgbp, cgtod(&sblock, cg), sblock.fs_cgsize);
- return (cgbp);
-}
-
-/*
- * Attempt to flush a cylinder group cache entry.
- * Return whether the flush was successful.
- */
-int
-flushentry(void)
-{
- struct bufarea *cgbp;
-
- cgbp = &cgbufs[flushtries++];
- if (cgbp->b_un.b_cg == NULL)
- return (0);
- flush(fswritefd, cgbp);
- free(cgbp->b_un.b_buf);
- cgbp->b_un.b_buf = NULL;
- return (1);
-}
-
-/*
* Manage a cache of directory blocks.
*/
struct bufarea *
@@ -415,13 +363,6 @@ ckfini(int markclean)
}
if (numbufs != cnt)
errx(EEXIT, "panic: lost %d buffers", numbufs - cnt);
- for (cnt = 0; cnt < sblock.fs_ncg; cnt++) {
- if (cgbufs[cnt].b_un.b_cg == NULL)
- continue;
- flush(fswritefd, &cgbufs[cnt]);
- free(cgbufs[cnt].b_un.b_cg);
- }
- free(cgbufs);
pbp = pdirbp = (struct bufarea *)0;
if (cursnapshot == 0 && sblock.fs_clean != markclean) {
if ((sblock.fs_clean = markclean) != 0) {
@@ -507,8 +448,8 @@ static void printIOstats(void)
clock_gettime(CLOCK_REALTIME_PRECISE, &finishpass);
timespecsub(&finishpass, &startpass);
- printf("Running time: %d.%03ld msec\n",
- finishpass.tv_sec, finishpass.tv_nsec / 1000000);
+ msec = finishpass.tv_sec * 1000 + finishpass.tv_nsec / 1000000;
+ printf("Running time: %lld msec\n", msec);
printf("buffer reads by type:\n");
for (totalmsec = 0, i = 0; i < BT_NUMBUFTYPES; i++)
totalmsec += readtime[i].tv_sec * 1000 +
@@ -519,10 +460,9 @@ static void printIOstats(void)
if (readcnt[i] == 0)
continue;
msec = readtime[i].tv_sec * 1000 + readtime[i].tv_nsec / 1000000;
- printf("%21s:%8ld %2ld.%ld%% %4d.%03ld sec %2jd.%jd%%\n",
+ printf("%21s:%8ld %2ld.%ld%% %8lld msec %2lld.%lld%%\n",
buftype[i], readcnt[i], readcnt[i] * 100 / diskreads,
- (readcnt[i] * 1000 / diskreads) % 10,
- readtime[i].tv_sec, readtime[i].tv_nsec / 1000000,
+ (readcnt[i] * 1000 / diskreads) % 10, msec,
msec * 100 / totalmsec, (msec * 1000 / totalmsec) % 10);
}
printf("\n");
@@ -622,9 +562,8 @@ blerase(int fd, ufs2_daddr_t blk, long size)
* test fails, offer an option to rebuild the whole cylinder group.
*/
int
-check_cgmagic(int cg, struct bufarea *cgbp)
+check_cgmagic(int cg, struct cg *cgp)
{
- struct cg *cgp = cgbp->b_un.b_cg;
/*
* Extended cylinder group checks.
@@ -684,7 +623,7 @@ check_cgmagic(int cg, struct bufarea *cgbp)
cgp->cg_nextfreeoff = cgp->cg_clusteroff +
howmany(fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT);
}
- dirty(cgbp);
+ cgdirty();
return (0);
}
@@ -695,8 +634,7 @@ ufs2_daddr_t
allocblk(long frags)
{
int i, j, k, cg, baseblk;
- struct bufarea *cgbp;
- struct cg *cgp;
+ struct cg *cgp = &cgrp;
if (frags <= 0 || frags > sblock.fs_frag)
return (0);
@@ -712,9 +650,8 @@ allocblk(long frags)
continue;
}
cg = dtog(&sblock, i + j);
- cgbp = cgget(cg);
- cgp = cgbp->b_un.b_cg;
- if (!check_cgmagic(cg, cgbp))
+ getblk(&cgblk, cgtod(&sblock, cg), sblock.fs_cgsize);
+ if (!check_cgmagic(cg, cgp))
return (0);
baseblk = dtogd(&sblock, i + j);
for (k = 0; k < frags; k++) {
@@ -726,7 +663,7 @@ allocblk(long frags)
cgp->cg_cs.cs_nbfree--;
else
cgp->cg_cs.cs_nffree -= frags;
- dirty(cgbp);
+ cgdirty();
return (i + j);
}
}
diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c
index e8baf09..fd98575 100644
--- a/sbin/fsck_ffs/inode.c
+++ b/sbin/fsck_ffs/inode.c
@@ -423,7 +423,7 @@ setinodebuf(ino_t inum)
partialsize = inobufsize;
}
initbarea(&inobuf, BT_INODES);
- if ((inobuf.b_un.b_buf = Malloc((unsigned)inobufsize)) == NULL)
+ if ((inobuf.b_un.b_buf = malloc((unsigned)inobufsize)) == NULL)
errx(EEXIT, "cannot allocate space for inode buffer");
}
@@ -454,7 +454,7 @@ cacheino(union dinode *dp, ino_t inumber)
else
blks = howmany(DIP(dp, di_size), sblock.fs_bsize);
inp = (struct inoinfo *)
- Malloc(sizeof(*inp) + (blks - 1) * sizeof(ufs2_daddr_t));
+ malloc(sizeof(*inp) + (blks - 1) * sizeof(ufs2_daddr_t));
if (inp == NULL)
errx(EEXIT, "cannot increase directory list");
inpp = &inphead[inumber % dirhash];
@@ -657,8 +657,7 @@ allocino(ino_t request, int type)
{
ino_t ino;
union dinode *dp;
- struct bufarea *cgbp;
- struct cg *cgp;
+ struct cg *cgp = &cgrp;
int cg;
if (request == 0)
@@ -671,9 +670,8 @@ allocino(ino_t request, int type)
if (ino == maxino)
return (0);
cg = ino_to_cg(&sblock, ino);
- cgbp = cgget(cg);
- cgp = cgbp->b_un.b_cg;
- if (!check_cgmagic(cg, cgbp))
+ getblk(&cgblk, cgtod(&sblock, cg), sblock.fs_cgsize);
+ if (!check_cgmagic(cg, cgp))
return (0);
setbit(cg_inosused(cgp), ino % sblock.fs_ipg);
cgp->cg_cs.cs_nifree--;
@@ -689,7 +687,7 @@ allocino(ino_t request, int type)
default:
return (0);
}
- dirty(cgbp);
+ cgdirty();
dp = ginode(ino);
DIP_SET(dp, di_db[0], allocblk((long)1));
if (DIP(dp, di_db[0]) == 0) {
diff --git a/sbin/fsck_ffs/pass1.c b/sbin/fsck_ffs/pass1.c
index 3199541..08e84b9 100644
--- a/sbin/fsck_ffs/pass1.c
+++ b/sbin/fsck_ffs/pass1.c
@@ -61,8 +61,6 @@ pass1(void)
{
struct inostat *info;
struct inodesc idesc;
- struct bufarea *cgbp;
- struct cg *cgp;
ino_t inumber, inosused, mininos;
ufs2_daddr_t i, cgd;
u_int8_t *cp;
@@ -94,13 +92,12 @@ pass1(void)
for (c = 0; c < sblock.fs_ncg; c++) {
inumber = c * sblock.fs_ipg;
setinodebuf(inumber);
- cgbp = cgget(c);
- cgp = cgbp->b_un.b_cg;
+ getblk(&cgblk, cgtod(&sblock, c), sblock.fs_cgsize);
rebuildcg = 0;
- if (!check_cgmagic(c, cgbp))
+ if (!check_cgmagic(c, &cgrp))
rebuildcg = 1;
if (!rebuildcg && sblock.fs_magic == FS_UFS2_MAGIC) {
- inosused = cgp->cg_initediblk;
+ inosused = cgrp.cg_initediblk;
if (inosused > sblock.fs_ipg) {
pfatal(
"Too many initialized inodes (%ju > %d) in cylinder group %d\nReset to %d\n",
@@ -130,7 +127,7 @@ pass1(void)
* read only those inodes in from disk.
*/
if ((preen || inoopt) && usedsoftdep && !rebuildcg) {
- cp = &cg_inosused(cgp)[(inosused - 1) / CHAR_BIT];
+ cp = &cg_inosused(&cgrp)[(inosused - 1) / CHAR_BIT];
for ( ; inosused > 0; inosused -= CHAR_BIT, cp--) {
if (*cp == 0)
continue;
@@ -152,7 +149,7 @@ pass1(void)
inostathead[c].il_stat = 0;
continue;
}
- info = Calloc((unsigned)inosused, sizeof(struct inostat));
+ info = calloc((unsigned)inosused, sizeof(struct inostat));
if (info == NULL)
errx(EEXIT, "cannot alloc %u bytes for inoinfo",
(unsigned)(sizeof(struct inostat) * inosused));
@@ -172,7 +169,7 @@ pass1(void)
* valid number for this cylinder group.
*/
if (checkinode(inumber, &idesc, rebuildcg) == 0 &&
- i > cgp->cg_initediblk)
+ i > cgrp.cg_initediblk)
break;
}
/*
@@ -184,16 +181,16 @@ pass1(void)
mininos = roundup(inosused + INOPB(&sblock), INOPB(&sblock));
if (inoopt && !preen && !rebuildcg &&
sblock.fs_magic == FS_UFS2_MAGIC &&
- cgp->cg_initediblk > 2 * INOPB(&sblock) &&
- mininos < cgp->cg_initediblk) {
- i = cgp->cg_initediblk;
+ cgrp.cg_initediblk > 2 * INOPB(&sblock) &&
+ mininos < cgrp.cg_initediblk) {
+ i = cgrp.cg_initediblk;
if (mininos < 2 * INOPB(&sblock))
- cgp->cg_initediblk = 2 * INOPB(&sblock);
+ cgrp.cg_initediblk = 2 * INOPB(&sblock);
else
- cgp->cg_initediblk = mininos;
+ cgrp.cg_initediblk = mininos;
pwarn("CYLINDER GROUP %d: RESET FROM %ju TO %d %s\n",
- c, i, cgp->cg_initediblk, "VALID INODES");
- dirty(cgbp);
+ c, i, cgrp.cg_initediblk, "VALID INODES");
+ cgdirty();
}
if (inosused < sblock.fs_ipg)
continue;
@@ -202,11 +199,11 @@ pass1(void)
inosused = 0;
else
inosused = lastino - (c * sblock.fs_ipg);
- if (rebuildcg && inosused > cgp->cg_initediblk &&
+ if (rebuildcg && inosused > cgrp.cg_initediblk &&
sblock.fs_magic == FS_UFS2_MAGIC) {
- cgp->cg_initediblk = roundup(inosused, INOPB(&sblock));
+ cgrp.cg_initediblk = roundup(inosused, INOPB(&sblock));
pwarn("CYLINDER GROUP %d: FOUND %d VALID INODES\n", c,
- cgp->cg_initediblk);
+ cgrp.cg_initediblk);
}
/*
* If we were not able to determine in advance which inodes
@@ -222,7 +219,7 @@ pass1(void)
inostathead[c].il_stat = 0;
continue;
}
- info = Calloc((unsigned)inosused, sizeof(struct inostat));
+ info = calloc((unsigned)inosused, sizeof(struct inostat));
if (info == NULL)
errx(EEXIT, "cannot alloc %u bytes for inoinfo",
(unsigned)(sizeof(struct inostat) * inosused));
@@ -485,7 +482,7 @@ pass1check(struct inodesc *idesc)
}
return (STOP);
}
- new = (struct dups *)Malloc(sizeof(struct dups));
+ new = (struct dups *)malloc(sizeof(struct dups));
if (new == NULL) {
pfatal("DUP TABLE OVERFLOW.");
if (reply("CONTINUE") == 0) {
diff --git a/sbin/fsck_ffs/pass5.c b/sbin/fsck_ffs/pass5.c
index 146acec..b95df73 100644
--- a/sbin/fsck_ffs/pass5.c
+++ b/sbin/fsck_ffs/pass5.c
@@ -59,14 +59,14 @@ pass5(void)
int c, i, j, blk, frags, basesize, mapsize;
int inomapsize, blkmapsize;
struct fs *fs = &sblock;
+ struct cg *cg = &cgrp;
ufs2_daddr_t d, dbase, dmax, start;
int rewritecg = 0;
struct csum *cs;
struct csum_total cstotal;
struct inodesc idesc[3];
char buf[MAXBSIZE];
- struct cg *cg, *newcg = (struct cg *)buf;
- struct bufarea *cgbp;
+ struct cg *newcg = (struct cg *)buf;
inoinfo(WINO)->ino_state = USTATE;
memset(newcg, 0, (size_t)fs->fs_cgsize);
@@ -162,8 +162,7 @@ pass5(void)
c * 100 / sblock.fs_ncg);
got_sigalarm = 0;
}
- cgbp = cgget(c);
- cg = cgbp->b_un.b_cg;
+ getblk(&cgblk, cgtod(fs, c), fs->fs_cgsize);
if (!cg_chkmagic(cg))
pfatal("CG %d: BAD MAGIC NUMBER\n", c);
newcg->cg_time = cg->cg_time;
@@ -325,14 +324,14 @@ pass5(void)
}
if (rewritecg) {
memmove(cg, newcg, (size_t)fs->fs_cgsize);
- dirty(cgbp);
+ cgdirty();
continue;
}
if (cursnapshot == 0 &&
memcmp(newcg, cg, basesize) != 0 &&
dofix(&idesc[2], "SUMMARY INFORMATION BAD")) {
memmove(cg, newcg, (size_t)basesize);
- dirty(cgbp);
+ cgdirty();
}
if (bkgrdflag != 0 || usedsoftdep || debug)
update_maps(cg, newcg, bkgrdflag);
@@ -341,7 +340,7 @@ pass5(void)
dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) {
memmove(cg_inosused(cg), cg_inosused(newcg),
(size_t)mapsize);
- dirty(cgbp);
+ cgdirty();
}
}
if (cursnapshot == 0 &&
diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c
index 85e9548..32abeed 100644
--- a/sbin/fsck_ffs/setup.c
+++ b/sbin/fsck_ffs/setup.c
@@ -240,7 +240,7 @@ setup(char *dev)
* read in the summary info.
*/
asked = 0;
- sblock.fs_csp = Calloc(1, sblock.fs_cssize);
+ sblock.fs_csp = calloc(1, sblock.fs_cssize);
if (sblock.fs_csp == NULL) {
printf("cannot alloc %u bytes for cg summary info\n",
(unsigned)sblock.fs_cssize);
@@ -265,13 +265,13 @@ setup(char *dev)
* allocate and initialize the necessary maps
*/
bmapsize = roundup(howmany(maxfsblock, CHAR_BIT), sizeof(short));
- blockmap = Calloc((unsigned)bmapsize, sizeof (char));
+ blockmap = calloc((unsigned)bmapsize, sizeof (char));
if (blockmap == NULL) {
printf("cannot alloc %u bytes for blockmap\n",
(unsigned)bmapsize);
goto badsb;
}
- inostathead = Calloc((unsigned)(sblock.fs_ncg),
+ inostathead = calloc((unsigned)(sblock.fs_ncg),
sizeof(struct inostatlist));
if (inostathead == NULL) {
printf("cannot alloc %u bytes for inostathead\n",
@@ -282,9 +282,9 @@ setup(char *dev)
dirhash = numdirs;
inplast = 0;
listmax = numdirs + 10;
- inpsort = (struct inoinfo **)Calloc((unsigned)listmax,
+ inpsort = (struct inoinfo **)calloc((unsigned)listmax,
sizeof(struct inoinfo *));
- inphead = (struct inoinfo **)Calloc((unsigned)numdirs,
+ inphead = (struct inoinfo **)calloc((unsigned)numdirs,
sizeof(struct inoinfo *));
if (inpsort == NULL || inphead == NULL) {
printf("cannot alloc %ju bytes for inphead\n",
@@ -444,8 +444,8 @@ sblock_init(void)
lfdir = 0;
initbarea(&sblk, BT_SUPERBLK);
initbarea(&asblk, BT_SUPERBLK);
- sblk.b_un.b_buf = Malloc(SBLOCKSIZE);
- asblk.b_un.b_buf = Malloc(SBLOCKSIZE);
+ sblk.b_un.b_buf = malloc(SBLOCKSIZE);
+ asblk.b_un.b_buf = malloc(SBLOCKSIZE);
if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
errx(EEXIT, "cannot allocate space for superblock");
if ((lp = getdisklabel(NULL, fsreadfd)))
diff --git a/sbin/fsck_ffs/suj.c b/sbin/fsck_ffs/suj.c
index 5fca0f5..ae47487 100644
--- a/sbin/fsck_ffs/suj.c
+++ b/sbin/fsck_ffs/suj.c
@@ -161,7 +161,7 @@ errmalloc(size_t n)
{
void *a;
- a = Malloc(n);
+ a = malloc(n);
if (a == NULL)
err(EX_OSERR, "malloc(%zu)", n);
return (a);
@@ -194,7 +194,7 @@ opendisk(const char *devnam)
{
if (disk != NULL)
return;
- disk = Malloc(sizeof(*disk));
+ disk = malloc(sizeof(*disk));
if (disk == NULL)
err(EX_OSERR, "malloc(%zu)", sizeof(*disk));
if (ufs_disk_fillout(disk, devnam) == -1) {
OpenPOWER on IntegriCloud