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

@@ -37,7 +37,6 @@
#include "support.h"
#include "kern/sfs.h"
#ifdef HOST
#include <netinet/in.h> // for arpa/inet.h
@@ -66,175 +65,155 @@ static char freemapbuf[MAXFREEMAPBLOCKS * SFS_BLOCKSIZE];
/*
* Assert that the on-disk data structures are correctly sized.
*/
static
void
check(void)
{
assert(sizeof(struct sfs_superblock)==SFS_BLOCKSIZE);
assert(sizeof(struct sfs_dinode)==SFS_BLOCKSIZE);
assert(SFS_BLOCKSIZE % sizeof(struct sfs_direntry) == 0);
static void check(void) {
assert(sizeof(struct sfs_superblock) == SFS_BLOCKSIZE);
assert(sizeof(struct sfs_dinode) == SFS_BLOCKSIZE);
assert(SFS_BLOCKSIZE % sizeof(struct sfs_direntry) == 0);
}
/*
* Mark a block allocated.
*/
static
void
allocblock(uint32_t block)
{
uint32_t mapbyte = block/CHAR_BIT;
unsigned char mask = (1<<(block % CHAR_BIT));
static void allocblock(uint32_t block) {
uint32_t mapbyte = block / CHAR_BIT;
unsigned char mask = (1 << (block % CHAR_BIT));
assert((freemapbuf[mapbyte] & mask) == 0);
freemapbuf[mapbyte] |= mask;
assert((freemapbuf[mapbyte] & mask) == 0);
freemapbuf[mapbyte] |= mask;
}
/*
* Initialize the free block bitmap.
*/
static
void
initfreemap(uint32_t fsblocks)
{
uint32_t freemapbits = SFS_FREEMAPBITS(fsblocks);
uint32_t freemapblocks = SFS_FREEMAPBLOCKS(fsblocks);
uint32_t i;
static void initfreemap(uint32_t fsblocks) {
uint32_t freemapbits = SFS_FREEMAPBITS(fsblocks);
uint32_t freemapblocks = SFS_FREEMAPBLOCKS(fsblocks);
uint32_t i;
if (freemapblocks > MAXFREEMAPBLOCKS) {
errx(1, "Filesystem too large -- "
"increase MAXFREEMAPBLOCKS and recompile");
}
if (freemapblocks > MAXFREEMAPBLOCKS) {
errx(1, "Filesystem too large -- "
"increase MAXFREEMAPBLOCKS and recompile");
}
/* mark the superblock and root inode in use */
allocblock(SFS_SUPER_BLOCK);
allocblock(SFS_ROOTDIR_INO);
/* mark the superblock and root inode in use */
allocblock(SFS_SUPER_BLOCK);
allocblock(SFS_ROOTDIR_INO);
/* the freemap blocks must be in use */
for (i=0; i<freemapblocks; i++) {
allocblock(SFS_FREEMAP_START + i);
}
/* the freemap blocks must be in use */
for (i = 0; i < freemapblocks; i++) {
allocblock(SFS_FREEMAP_START + i);
}
/* all blocks in the freemap but past the volume end are "in use" */
for (i=fsblocks; i<freemapbits; i++) {
allocblock(i);
}
/* all blocks in the freemap but past the volume end are "in use" */
for (i = fsblocks; i < freemapbits; i++) {
allocblock(i);
}
}
/*
* Initialize and write out the superblock.
*/
static
void
writesuper(const char *volname, uint32_t nblocks)
{
struct sfs_superblock sb;
static void writesuper(const char *volname, uint32_t nblocks) {
struct sfs_superblock sb;
/* The cast is required on some outdated host systems. */
bzero((void *)&sb, sizeof(sb));
/* The cast is required on some outdated host systems. */
bzero((void *)&sb, sizeof(sb));
if (strlen(volname) >= SFS_VOLNAME_SIZE) {
errx(1, "Volume name %s too long", volname);
}
if (strlen(volname) >= SFS_VOLNAME_SIZE) {
errx(1, "Volume name %s too long", volname);
}
/* Initialize the superblock structure */
sb.sb_magic = SWAP32(SFS_MAGIC);
sb.sb_nblocks = SWAP32(nblocks);
strcpy(sb.sb_volname, volname);
/* Initialize the superblock structure */
sb.sb_magic = SWAP32(SFS_MAGIC);
sb.sb_nblocks = SWAP32(nblocks);
strcpy(sb.sb_volname, volname);
/* and write it out. */
diskwrite(&sb, SFS_SUPER_BLOCK);
/* and write it out. */
diskwrite(&sb, SFS_SUPER_BLOCK);
}
/*
* Write out the free block bitmap.
*/
static
void
writefreemap(uint32_t fsblocks)
{
uint32_t freemapblocks;
char *ptr;
uint32_t i;
static void writefreemap(uint32_t fsblocks) {
uint32_t freemapblocks;
char *ptr;
uint32_t i;
/* Write out each of the blocks in the free block bitmap. */
freemapblocks = SFS_FREEMAPBLOCKS(fsblocks);
for (i=0; i<freemapblocks; i++) {
ptr = freemapbuf + i*SFS_BLOCKSIZE;
diskwrite(ptr, SFS_FREEMAP_START+i);
}
/* Write out each of the blocks in the free block bitmap. */
freemapblocks = SFS_FREEMAPBLOCKS(fsblocks);
for (i = 0; i < freemapblocks; i++) {
ptr = freemapbuf + i * SFS_BLOCKSIZE;
diskwrite(ptr, SFS_FREEMAP_START + i);
}
}
/*
* Write out the root directory inode.
*/
static
void
writerootdir(void)
{
struct sfs_dinode sfi;
static void writerootdir(void) {
struct sfs_dinode sfi;
/* Initialize the dinode */
bzero((void *)&sfi, sizeof(sfi));
sfi.sfi_size = SWAP32(0);
sfi.sfi_type = SWAP16(SFS_TYPE_DIR);
sfi.sfi_linkcount = SWAP16(1);
/* Initialize the dinode */
bzero((void *)&sfi, sizeof(sfi));
sfi.sfi_size = SWAP32(0);
sfi.sfi_type = SWAP16(SFS_TYPE_DIR);
sfi.sfi_linkcount = SWAP16(1);
/* Write it out */
diskwrite(&sfi, SFS_ROOTDIR_INO);
/* Write it out */
diskwrite(&sfi, SFS_ROOTDIR_INO);
}
/*
* Main.
*/
int
main(int argc, char **argv)
{
uint32_t size, blocksize;
char *volname, *s;
int main(int argc, char **argv) {
uint32_t size, blocksize;
char *volname, *s;
#ifdef HOST
hostcompat_init(argc, argv);
hostcompat_init(argc, argv);
#endif
if (argc!=3) {
errx(1, "Usage: mksfs device/diskfile volume-name");
}
if (argc != 3) {
errx(1, "Usage: mksfs device/diskfile volume-name");
}
check();
check();
volname = argv[2];
volname = argv[2];
/* Remove one trailing colon from volname, if present */
s = strchr(volname, ':');
if (s != NULL) {
if (strlen(s)!=1) {
errx(1, "Illegal volume name %s", volname);
}
*s = 0;
}
/* Remove one trailing colon from volname, if present */
s = strchr(volname, ':');
if (s != NULL) {
if (strlen(s) != 1) {
errx(1, "Illegal volume name %s", volname);
}
*s = 0;
}
/* Don't allow slashes */
s = strchr(volname, '/');
if (s != NULL) {
errx(1, "Illegal volume name %s", volname);
}
/* Don't allow slashes */
s = strchr(volname, '/');
if (s != NULL) {
errx(1, "Illegal volume name %s", volname);
}
opendisk(argv[1]);
blocksize = diskblocksize();
opendisk(argv[1]);
blocksize = diskblocksize();
if (blocksize!=SFS_BLOCKSIZE) {
errx(1, "Device has wrong blocksize %u (should be %u)\n",
blocksize, SFS_BLOCKSIZE);
}
size = diskblocks();
if (blocksize != SFS_BLOCKSIZE) {
errx(1, "Device has wrong blocksize %u (should be %u)\n", blocksize,
SFS_BLOCKSIZE);
}
size = diskblocks();
/* Write out the on-disk structures */
initfreemap(size);
writesuper(volname, size);
writefreemap(size);
writerootdir();
/* Write out the on-disk structures */
initfreemap(size);
writesuper(volname, size);
writefreemap(size);
writerootdir();
closedisk();
closedisk();
return 0;
return 0;
}