clang-format

This commit is contained in:
2024-09-10 13:03:02 -04:00
parent 53c617d779
commit d66450e427
381 changed files with 28864 additions and 34170 deletions

View File

@@ -27,8 +27,8 @@
* SUCH DAMAGE.
*/
#include <sys/types.h> /* for CHAR_BIT */
#include <limits.h> /* also for CHAR_BIT */
#include <sys/types.h> /* for CHAR_BIT */
#include <limits.h> /* also for CHAR_BIT */
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
@@ -52,69 +52,62 @@ static uint8_t *tofreedata;
* called after the superblock is loaded so we can ask how big the
* volume is.
*/
void
freemap_setup(void)
{
size_t i, mapbytes;
uint32_t fsblocks, mapblocks;
void freemap_setup(void) {
size_t i, mapbytes;
uint32_t fsblocks, mapblocks;
fsblocks = sb_totalblocks();
mapblocks = sb_freemapblocks();
mapbytes = mapblocks * SFS_BLOCKSIZE;
fsblocks = sb_totalblocks();
mapblocks = sb_freemapblocks();
mapbytes = mapblocks * SFS_BLOCKSIZE;
freemapdata = domalloc(mapbytes * sizeof(uint8_t));
tofreedata = domalloc(mapbytes * sizeof(uint8_t));
for (i=0; i<mapbytes; i++) {
freemapdata[i] = tofreedata[i] = 0;
}
freemapdata = domalloc(mapbytes * sizeof(uint8_t));
tofreedata = domalloc(mapbytes * sizeof(uint8_t));
for (i = 0; i < mapbytes; i++) {
freemapdata[i] = tofreedata[i] = 0;
}
/* Mark off what's in the freemap but past the volume end. */
for (i=fsblocks; i < mapblocks*SFS_BITSPERBLOCK; i++) {
freemap_blockinuse(i, B_PASTEND, 0);
}
/* Mark off what's in the freemap but past the volume end. */
for (i = fsblocks; i < mapblocks * SFS_BITSPERBLOCK; i++) {
freemap_blockinuse(i, B_PASTEND, 0);
}
/* Mark the superblock block and the freemap blocks in use */
freemap_blockinuse(SFS_SUPER_BLOCK, B_SUPERBLOCK, 0);
for (i=0; i < mapblocks; i++) {
freemap_blockinuse(SFS_FREEMAP_START+i, B_FREEMAPBLOCK, i);
}
/* Mark the superblock block and the freemap blocks in use */
freemap_blockinuse(SFS_SUPER_BLOCK, B_SUPERBLOCK, 0);
for (i = 0; i < mapblocks; i++) {
freemap_blockinuse(SFS_FREEMAP_START + i, B_FREEMAPBLOCK, i);
}
}
/*
* Return a string for a blockusage; used for printing errors.
*/
static
const char *
blockusagestr(blockusage_t how, uint32_t howdesc)
{
static char rv[256];
switch (how) {
case B_SUPERBLOCK:
return "superblock";
case B_FREEMAPBLOCK:
snprintf(rv, sizeof(rv), "freemap block %lu",
(unsigned long) howdesc);
break;
case B_INODE:
snprintf(rv, sizeof(rv), "inode %lu",
(unsigned long) howdesc);
break;
case B_IBLOCK:
snprintf(rv, sizeof(rv), "indirect block of inode %lu",
(unsigned long) howdesc);
break;
case B_DIRDATA:
snprintf(rv, sizeof(rv), "directory data from inode %lu",
(unsigned long) howdesc);
break;
case B_DATA:
snprintf(rv, sizeof(rv), "file data from inode %lu",
(unsigned long) howdesc);
break;
case B_PASTEND:
return "past the end of the fs";
}
return rv;
static const char *blockusagestr(blockusage_t how, uint32_t howdesc) {
static char rv[256];
switch (how) {
case B_SUPERBLOCK:
return "superblock";
case B_FREEMAPBLOCK:
snprintf(rv, sizeof(rv), "freemap block %lu", (unsigned long)howdesc);
break;
case B_INODE:
snprintf(rv, sizeof(rv), "inode %lu", (unsigned long)howdesc);
break;
case B_IBLOCK:
snprintf(rv, sizeof(rv), "indirect block of inode %lu",
(unsigned long)howdesc);
break;
case B_DIRDATA:
snprintf(rv, sizeof(rv), "directory data from inode %lu",
(unsigned long)howdesc);
break;
case B_DATA:
snprintf(rv, sizeof(rv), "file data from inode %lu",
(unsigned long)howdesc);
break;
case B_PASTEND:
return "past the end of the fs";
}
return rv;
}
/*
@@ -123,28 +116,26 @@ blockusagestr(blockusage_t how, uint32_t howdesc)
*
* FUTURE: this should not produce unrecoverable errors.
*/
void
freemap_blockinuse(uint32_t block, blockusage_t how, uint32_t howdesc)
{
unsigned index = block/8;
uint8_t mask = ((uint8_t)1)<<(block%8);
void freemap_blockinuse(uint32_t block, blockusage_t how, uint32_t howdesc) {
unsigned index = block / 8;
uint8_t mask = ((uint8_t)1) << (block % 8);
if (tofreedata[index] & mask) {
/* really using the block, don't free it */
tofreedata[index] &= ~mask;
}
if (tofreedata[index] & mask) {
/* really using the block, don't free it */
tofreedata[index] &= ~mask;
}
if (freemapdata[index] & mask) {
warnx("Block %lu (used as %s) already in use! (NOT FIXED)",
(unsigned long) block, blockusagestr(how, howdesc));
setbadness(EXIT_UNRECOV);
}
if (freemapdata[index] & mask) {
warnx("Block %lu (used as %s) already in use! (NOT FIXED)",
(unsigned long)block, blockusagestr(how, howdesc));
setbadness(EXIT_UNRECOV);
}
freemapdata[index] |= mask;
freemapdata[index] |= mask;
if (how != B_PASTEND) {
blocksinuse++;
}
if (how != B_PASTEND) {
blocksinuse++;
}
}
/*
@@ -158,37 +149,33 @@ freemap_blockinuse(uint32_t block, blockusage_t how, uint32_t howdesc)
* original usage to be something we are dropping, e.g. if a truncate
* (to a nonzero length > INOMAX_D) got partially completed.
*/
void
freemap_blockfree(uint32_t block)
{
unsigned index = block/8;
uint8_t mask = ((uint8_t)1)<<(block%8);
void freemap_blockfree(uint32_t block) {
unsigned index = block / 8;
uint8_t mask = ((uint8_t)1) << (block % 8);
if (tofreedata[index] & mask) {
/* already marked to free once, ignore */
return;
}
if (freemapdata[index] & mask) {
/* block is used elsewhere, ignore */
return;
}
tofreedata[index] |= mask;
if (tofreedata[index] & mask) {
/* already marked to free once, ignore */
return;
}
if (freemapdata[index] & mask) {
/* block is used elsewhere, ignore */
return;
}
tofreedata[index] |= mask;
}
/*
* Count the number of bits set.
*/
static
int
countbits(uint8_t val)
{
uint8_t x;
int ct=0;
static int countbits(uint8_t val) {
uint8_t x;
int ct = 0;
for (x=1; x; x<<=1) {
if (val & x) ct++;
}
return ct;
for (x = 1; x; x <<= 1) {
if (val & x)
ct++;
}
return ct;
}
/*
@@ -198,21 +185,18 @@ countbits(uint8_t val)
* byte offset within that block; VAL is the byte value; WHAT is a
* string indicating what happened.
*/
static
void
reportfreemap(uint32_t mapblock, uint32_t byte, uint8_t val, const char *what)
{
uint8_t x, y;
uint32_t blocknum;
static void reportfreemap(uint32_t mapblock, uint32_t byte, uint8_t val,
const char *what) {
uint8_t x, y;
uint32_t blocknum;
for (x=1, y=0; x; x<<=1, y++) {
if (val & x) {
blocknum = mapblock*SFS_BITSPERBLOCK +
byte*CHAR_BIT + y;
warnx("Block %lu erroneously shown %s in freemap",
(unsigned long) blocknum, what);
}
}
for (x = 1, y = 0; x; x <<= 1, y++) {
if (val & x) {
blocknum = mapblock * SFS_BITSPERBLOCK + byte * CHAR_BIT + y;
warnx("Block %lu erroneously shown %s in freemap",
(unsigned long)blocknum, what);
}
}
}
/*
@@ -221,90 +205,84 @@ reportfreemap(uint32_t mapblock, uint32_t byte, uint8_t val, const char *what)
* This is called after (at the end of) pass 1, when we've recursively
* found all the reachable blocks and marked them.
*/
void
freemap_check(void)
{
uint8_t actual[SFS_BLOCKSIZE], *expected, *tofree, tmp;
uint32_t alloccount=0, freecount=0, i, j;
int bchanged;
uint32_t bitblocks;
void freemap_check(void) {
uint8_t actual[SFS_BLOCKSIZE], *expected, *tofree, tmp;
uint32_t alloccount = 0, freecount = 0, i, j;
int bchanged;
uint32_t bitblocks;
bitblocks = sb_freemapblocks();
bitblocks = sb_freemapblocks();
for (i=0; i<bitblocks; i++) {
sfs_readfreemapblock(i, actual);
expected = freemapdata + i*SFS_BLOCKSIZE;
tofree = tofreedata + i*SFS_BLOCKSIZE;
bchanged = 0;
for (i = 0; i < bitblocks; i++) {
sfs_readfreemapblock(i, actual);
expected = freemapdata + i * SFS_BLOCKSIZE;
tofree = tofreedata + i * SFS_BLOCKSIZE;
bchanged = 0;
for (j=0; j<SFS_BLOCKSIZE; j++) {
/* we shouldn't have blocks marked both ways */
assert((expected[j] & tofree[j])==0);
for (j = 0; j < SFS_BLOCKSIZE; j++) {
/* we shouldn't have blocks marked both ways */
assert((expected[j] & tofree[j]) == 0);
/* what's there is what should be there */
if (actual[j] == expected[j]) {
continue;
}
/* what's there is what should be there */
if (actual[j] == expected[j]) {
continue;
}
/* what's there is what should be there modulo frees */
if (actual[j] == (expected[j] | tofree[j])) {
actual[j] = expected[j];
bchanged = 1;
continue;
}
/* what's there is what should be there modulo frees */
if (actual[j] == (expected[j] | tofree[j])) {
actual[j] = expected[j];
bchanged = 1;
continue;
}
/* oops, it doesn't match... */
/* oops, it doesn't match... */
/* free the ones we're freeing (don't report these) */
actual[j] &= ~tofree[j];
/* free the ones we're freeing (don't report these) */
actual[j] &= ~tofree[j];
/* are we short any? */
if ((actual[j] & expected[j]) != expected[j]) {
tmp = expected[j] & ~actual[j];
alloccount += countbits(tmp);
if (tmp != 0) {
reportfreemap(i, j, tmp, "free");
}
}
/* are we short any? */
if ((actual[j] & expected[j]) != expected[j]) {
tmp = expected[j] & ~actual[j];
alloccount += countbits(tmp);
if (tmp != 0) {
reportfreemap(i, j, tmp, "free");
}
}
/* do we have any extra? */
if ((actual[j] & expected[j]) != actual[j]) {
tmp = actual[j] & ~expected[j];
freecount += countbits(tmp);
if (tmp != 0) {
reportfreemap(i, j, tmp, "allocated");
}
}
/* do we have any extra? */
if ((actual[j] & expected[j]) != actual[j]) {
tmp = actual[j] & ~expected[j];
freecount += countbits(tmp);
if (tmp != 0) {
reportfreemap(i, j, tmp, "allocated");
}
}
/* set it to what it should be */
actual[j] = expected[j];
bchanged = 1;
}
/* set it to what it should be */
actual[j] = expected[j];
bchanged = 1;
}
/* write the block back if necessary */
if (bchanged) {
sfs_writefreemapblock(i, actual);
}
}
/* write the block back if necessary */
if (bchanged) {
sfs_writefreemapblock(i, actual);
}
}
if (alloccount > 0) {
warnx("%lu blocks erroneously shown free in freemap (fixed)",
(unsigned long) alloccount);
setbadness(EXIT_RECOV);
}
if (freecount > 0) {
warnx("%lu blocks erroneously shown used in freemap (fixed)",
(unsigned long) freecount);
setbadness(EXIT_RECOV);
}
if (alloccount > 0) {
warnx("%lu blocks erroneously shown free in freemap (fixed)",
(unsigned long)alloccount);
setbadness(EXIT_RECOV);
}
if (freecount > 0) {
warnx("%lu blocks erroneously shown used in freemap (fixed)",
(unsigned long)freecount);
setbadness(EXIT_RECOV);
}
}
/*
* Return the total number of blocks in use, which we count during
* pass 1.
*/
unsigned long
freemap_blocksused(void)
{
return blocksinuse;
}
unsigned long freemap_blocksused(void) { return blocksinuse; }