Check and report error returns from sbput(3) calls.
Convert to using cgput(3) for writing cylinder groups. Check and report error returns from cgput(3). Submitted by: Bruce Evans <bde@freebsd.org>
This commit is contained in:
parent
190bc94a67
commit
8bd0b5ce0a
@ -101,7 +101,6 @@ static void iput(union dinode *, ino_t);
|
||||
static int makedir(struct direct *, int);
|
||||
static void setblock(struct fs *, unsigned char *, int);
|
||||
static void wtfs(ufs2_daddr_t, int, char *);
|
||||
static void cgckhash(struct cg *);
|
||||
static u_int32_t newfs_random(void);
|
||||
|
||||
void
|
||||
@ -520,24 +519,27 @@ mkfs(struct partition *pp, char *fsys)
|
||||
* Wipe out old UFS1 superblock(s) if necessary.
|
||||
*/
|
||||
if (!Nflag && Oflag != 1 && realsectorsize <= SBLOCK_UFS1) {
|
||||
i = bread(&disk, part_ofs + SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE);
|
||||
i = bread(&disk, part_ofs + SBLOCK_UFS1 / disk.d_bsize, chdummy,
|
||||
SBLOCKSIZE);
|
||||
if (i == -1)
|
||||
err(1, "can't read old UFS1 superblock: %s", disk.d_error);
|
||||
err(1, "can't read old UFS1 superblock: %s",
|
||||
disk.d_error);
|
||||
|
||||
if (fsdummy.fs_magic == FS_UFS1_MAGIC) {
|
||||
fsdummy.fs_magic = 0;
|
||||
bwrite(&disk, part_ofs + SBLOCK_UFS1 / disk.d_bsize,
|
||||
chdummy, SBLOCKSIZE);
|
||||
for (cg = 0; cg < fsdummy.fs_ncg; cg++) {
|
||||
if (fsbtodb(&fsdummy, cgsblock(&fsdummy, cg)) > fssize)
|
||||
if (fsbtodb(&fsdummy, cgsblock(&fsdummy, cg)) >
|
||||
fssize)
|
||||
break;
|
||||
bwrite(&disk, part_ofs + fsbtodb(&fsdummy,
|
||||
cgsblock(&fsdummy, cg)), chdummy, SBLOCKSIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Nflag)
|
||||
sbput(disk.d_fd, &disk.d_fs, 0);
|
||||
if (!Nflag && sbput(disk.d_fd, &disk.d_fs, 0) != 0)
|
||||
err(1, "sbput: %s", disk.d_error);
|
||||
if (Xflag == 1) {
|
||||
printf("** Exiting on Xflag 1\n");
|
||||
exit(0);
|
||||
@ -555,10 +557,9 @@ mkfs(struct partition *pp, char *fsys)
|
||||
i = 0;
|
||||
width = charsperline();
|
||||
/*
|
||||
* Allocate space for cylinder group map and
|
||||
* two sets of inode blocks.
|
||||
* Allocate space for two sets of inode blocks.
|
||||
*/
|
||||
iobufsize = 3 * sblock.fs_bsize;
|
||||
iobufsize = 2 * sblock.fs_bsize;
|
||||
if ((iobuf = calloc(1, iobufsize)) == 0) {
|
||||
printf("Cannot allocate I/O buffer\n");
|
||||
exit(38);
|
||||
@ -604,7 +605,8 @@ mkfs(struct partition *pp, char *fsys)
|
||||
* Reference the summary information so it will also be written.
|
||||
*/
|
||||
sblock.fs_csp = fscs;
|
||||
sbput(disk.d_fd, &disk.d_fs, 0);
|
||||
if (sbput(disk.d_fd, &disk.d_fs, 0) != 0)
|
||||
err(1, "sbput: %s", disk.d_error);
|
||||
/*
|
||||
* For UFS1 filesystems with a blocksize of 64K, the first
|
||||
* alternate superblock resides at the location used for
|
||||
@ -788,7 +790,6 @@ initcg(int cylno, time_t utime)
|
||||
}
|
||||
}
|
||||
*cs = acg.cg_cs;
|
||||
cgckhash(&acg);
|
||||
/*
|
||||
* Write out the duplicate super block. Then write the cylinder
|
||||
* group map and two blocks worth of inodes in a single write.
|
||||
@ -796,11 +797,12 @@ initcg(int cylno, time_t utime)
|
||||
savedactualloc = sblock.fs_sblockactualloc;
|
||||
sblock.fs_sblockactualloc =
|
||||
dbtob(fsbtodb(&sblock, cgsblock(&sblock, cylno)));
|
||||
sbput(disk.d_fd, &disk.d_fs, 0);
|
||||
if (sbput(disk.d_fd, &disk.d_fs, 0) != 0)
|
||||
err(1, "sbput: %s", disk.d_error);
|
||||
sblock.fs_sblockactualloc = savedactualloc;
|
||||
if (cgput(&disk, &acg) != 0)
|
||||
err(1, "initcg: cgput: %s", disk.d_error);
|
||||
start = 0;
|
||||
bcopy((char *)&acg, &iobuf[start], sblock.fs_cgsize);
|
||||
start += sblock.fs_bsize;
|
||||
dp1 = (struct ufs1_dinode *)(&iobuf[start]);
|
||||
dp2 = (struct ufs2_dinode *)(&iobuf[start]);
|
||||
for (i = 0; i < acg.cg_initediblk; i++) {
|
||||
@ -812,7 +814,7 @@ initcg(int cylno, time_t utime)
|
||||
dp2++;
|
||||
}
|
||||
}
|
||||
wtfs(fsbtodb(&sblock, cgtod(&sblock, cylno)), iobufsize, iobuf);
|
||||
wtfs(fsbtodb(&sblock, cgimin(&sblock, cylno)), iobufsize, iobuf);
|
||||
/*
|
||||
* For the old file system, we have to initialize all the inodes.
|
||||
*/
|
||||
@ -1008,10 +1010,8 @@ alloc(int size, int mode)
|
||||
for (i = frag; i < sblock.fs_frag; i++)
|
||||
setbit(cg_blksfree(&acg), d + i);
|
||||
}
|
||||
/* XXX cgwrite(&disk, 0)??? */
|
||||
cgckhash(&acg);
|
||||
wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
|
||||
(char *)&acg);
|
||||
if (cgput(&disk, &acg) != 0)
|
||||
err(1, "alloc: cgput: %s", disk.d_error);
|
||||
return ((ufs2_daddr_t)d);
|
||||
}
|
||||
|
||||
@ -1031,9 +1031,8 @@ iput(union dinode *ip, ino_t ino)
|
||||
}
|
||||
acg.cg_cs.cs_nifree--;
|
||||
setbit(cg_inosused(&acg), ino);
|
||||
cgckhash(&acg);
|
||||
wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
|
||||
(char *)&acg);
|
||||
if (cgput(&disk, &acg) != 0)
|
||||
err(1, "iput: cgput: %s", disk.d_error);
|
||||
sblock.fs_cstotal.cs_nifree--;
|
||||
fscs[0].cs_nifree--;
|
||||
if (ino >= (unsigned long)sblock.fs_ipg * sblock.fs_ncg) {
|
||||
@ -1064,20 +1063,6 @@ wtfs(ufs2_daddr_t bno, int size, char *bf)
|
||||
err(36, "wtfs: %d bytes at sector %jd", size, (intmax_t)bno);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the check-hash of the cylinder group.
|
||||
*/
|
||||
static void
|
||||
cgckhash(cgp)
|
||||
struct cg *cgp;
|
||||
{
|
||||
|
||||
if ((sblock.fs_metackhash & CK_CYLGRP) == 0)
|
||||
return;
|
||||
cgp->cg_ckhash = 0;
|
||||
cgp->cg_ckhash = calculate_crc32c(~0L, (void *)cgp, sblock.fs_cgsize);
|
||||
}
|
||||
|
||||
/*
|
||||
* check if a block is available
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user