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

@@ -47,10 +47,10 @@
* FUTURE: should count the number of blocks allocated to this inode
*/
struct inodeinfo {
uint32_t ino;
uint32_t linkcount; /* files only */
int visited; /* dirs only */
int type;
uint32_t ino;
uint32_t linkcount; /* files only */
int visited; /* dirs only */
int type;
};
/* Table of inodes found. */
@@ -66,61 +66,53 @@ static int inodes_sorted = 0;
/*
* Add an entry to the inode table, realloc'ing it if needed.
*/
static
void
inode_addtable(uint32_t ino, int type)
{
unsigned newmax;
static void inode_addtable(uint32_t ino, int type) {
unsigned newmax;
assert(ninodes <= maxinodes);
if (ninodes == maxinodes) {
newmax = maxinodes ? maxinodes * 2 : 4;
inodes = dorealloc(inodes, maxinodes * sizeof(inodes[0]),
newmax * sizeof(inodes[0]));
maxinodes = newmax;
}
inodes[ninodes].ino = ino;
inodes[ninodes].linkcount = 0;
inodes[ninodes].visited = 0;
inodes[ninodes].type = type;
ninodes++;
inodes_sorted = 0;
assert(ninodes <= maxinodes);
if (ninodes == maxinodes) {
newmax = maxinodes ? maxinodes * 2 : 4;
inodes = dorealloc(inodes, maxinodes * sizeof(inodes[0]),
newmax * sizeof(inodes[0]));
maxinodes = newmax;
}
inodes[ninodes].ino = ino;
inodes[ninodes].linkcount = 0;
inodes[ninodes].visited = 0;
inodes[ninodes].type = type;
ninodes++;
inodes_sorted = 0;
}
/*
* Compare function for inodes.
*/
static
int
inode_compare(const void *av, const void *bv)
{
const struct inodeinfo *a = av;
const struct inodeinfo *b = bv;
static int inode_compare(const void *av, const void *bv) {
const struct inodeinfo *a = av;
const struct inodeinfo *b = bv;
if (a->ino < b->ino) {
return -1;
}
if (a->ino > b->ino) {
return 1;
}
/*
* There should be no duplicates in the table! But C99 makes
* no guarantees about whether the implementation of qsort can
* ask us to compare an element to itself. Assert that this is
* what happened.
*/
assert(av == bv);
return 0;
if (a->ino < b->ino) {
return -1;
}
if (a->ino > b->ino) {
return 1;
}
/*
* There should be no duplicates in the table! But C99 makes
* no guarantees about whether the implementation of qsort can
* ask us to compare an element to itself. Assert that this is
* what happened.
*/
assert(av == bv);
return 0;
}
/*
* After pass1, we sort the inode table for faster access.
*/
void
inode_sorttable(void)
{
qsort(inodes, ninodes, sizeof(inodes[0]), inode_compare);
inodes_sorted = 1;
void inode_sorttable(void) {
qsort(inodes, ninodes, sizeof(inodes[0]), inode_compare);
inodes_sorted = 1;
}
/*
@@ -132,35 +124,30 @@ inode_sorttable(void)
* pass2.c, we'll need to be able to ask if an inode number is valid
* and names a directory.)
*/
static
struct inodeinfo *
inode_find(uint32_t ino)
{
unsigned min, max, i;
static struct inodeinfo *inode_find(uint32_t ino) {
unsigned min, max, i;
assert(inodes_sorted);
assert(ninodes > 0);
assert(inodes_sorted);
assert(ninodes > 0);
min = 0;
max = ninodes;
while (1) {
assert(min <= max);
if (min == max) {
errx(EXIT_UNRECOV, "FATAL: inode %u wasn't found in my inode table", ino);
}
i = min + (max - min)/2;
if (inodes[i].ino < ino) {
min = i + 1;
}
else if (inodes[i].ino > ino) {
max = i;
}
else {
assert(inodes[i].ino == ino);
return &inodes[i];
}
}
/* NOTREACHED */
min = 0;
max = ninodes;
while (1) {
assert(min <= max);
if (min == max) {
errx(EXIT_UNRECOV, "FATAL: inode %u wasn't found in my inode table", ino);
}
i = min + (max - min) / 2;
if (inodes[i].ino < ino) {
min = i + 1;
} else if (inodes[i].ino > ino) {
max = i;
} else {
assert(inodes[i].ino == ino);
return &inodes[i];
}
}
/* NOTREACHED */
}
////////////////////////////////////////////////////////////
@@ -173,22 +160,20 @@ inode_find(uint32_t ino)
* after all inodes have been added. In the FUTURE this could be
* changed to a better data structure.
*/
int
inode_add(uint32_t ino, int type)
{
unsigned i;
int inode_add(uint32_t ino, int type) {
unsigned i;
for (i=0; i<ninodes; i++) {
if (inodes[i].ino==ino) {
assert(inodes[i].linkcount == 0);
assert(inodes[i].type == type);
return 1;
}
}
for (i = 0; i < ninodes; i++) {
if (inodes[i].ino == ino) {
assert(inodes[i].linkcount == 0);
assert(inodes[i].type == type);
return 1;
}
}
inode_addtable(ino, type);
inode_addtable(ino, type);
return 0;
return 0;
}
/*
@@ -198,19 +183,17 @@ inode_add(uint32_t ino, int type)
* Note that there is no way to clear the visited flag for now because
* it's only used once (by pass2).
*/
int
inode_visitdir(uint32_t ino)
{
struct inodeinfo *inf;
int inode_visitdir(uint32_t ino) {
struct inodeinfo *inf;
inf = inode_find(ino);
assert(inf->type == SFS_TYPE_DIR);
assert(inf->linkcount == 0);
if (inf->visited) {
return 1;
}
inf->visited = 1;
return 0;
inf = inode_find(ino);
assert(inf->type == SFS_TYPE_DIR);
assert(inf->linkcount == 0);
if (inf->visited) {
return 1;
}
inf->visited = 1;
return 0;
}
/*
@@ -218,49 +201,43 @@ inode_visitdir(uint32_t ino)
* does. (And that, in turn, is because the link count of a directory
* is a local property.)
*/
void
inode_addlink(uint32_t ino)
{
struct inodeinfo *inf;
void inode_addlink(uint32_t ino) {
struct inodeinfo *inf;
inf = inode_find(ino);
assert(inf->type == SFS_TYPE_FILE);
assert(inf->visited == 0);
inf->linkcount++;
inf = inode_find(ino);
assert(inf->type == SFS_TYPE_FILE);
assert(inf->visited == 0);
inf->linkcount++;
}
/*
* Correct link counts. This is effectively pass3. (FUTURE: change the
* name accordingly.)
*/
void
inode_adjust_filelinks(void)
{
struct sfs_dinode sfi;
unsigned i;
void inode_adjust_filelinks(void) {
struct sfs_dinode sfi;
unsigned i;
for (i=0; i<ninodes; i++) {
if (inodes[i].type == SFS_TYPE_DIR) {
/* directory */
continue;
}
assert(inodes[i].type == SFS_TYPE_FILE);
for (i = 0; i < ninodes; i++) {
if (inodes[i].type == SFS_TYPE_DIR) {
/* directory */
continue;
}
assert(inodes[i].type == SFS_TYPE_FILE);
/* because we've seen it, there must be at least one link */
assert(inodes[i].linkcount > 0);
/* because we've seen it, there must be at least one link */
assert(inodes[i].linkcount > 0);
sfs_readinode(inodes[i].ino, &sfi);
assert(sfi.sfi_type == SFS_TYPE_FILE);
sfs_readinode(inodes[i].ino, &sfi);
assert(sfi.sfi_type == SFS_TYPE_FILE);
if (sfi.sfi_linkcount != inodes[i].linkcount) {
warnx("File %lu link count %lu should be %lu (fixed)",
(unsigned long) inodes[i].ino,
(unsigned long) sfi.sfi_linkcount,
(unsigned long) inodes[i].linkcount);
sfi.sfi_linkcount = inodes[i].linkcount;
setbadness(EXIT_RECOV);
sfs_writeinode(inodes[i].ino, &sfi);
}
}
if (sfi.sfi_linkcount != inodes[i].linkcount) {
warnx("File %lu link count %lu should be %lu (fixed)",
(unsigned long)inodes[i].ino, (unsigned long)sfi.sfi_linkcount,
(unsigned long)inodes[i].linkcount);
sfi.sfi_linkcount = inodes[i].linkcount;
setbadness(EXIT_RECOV);
sfs_writeinode(inodes[i].ino, &sfi);
}
}
}