#include #include #include #include "block.h" #include "fs.h" int checksuper(SuperBlock *super) { if(super->magic != SUPERMAGIC){ werrstr("bad magic"); return -1; } if(super->block_size != 4096 || (1<block_shift) != super->block_size){ werrstr("bad block size"); return -1; } return 0; } int getsuper(int fd, SuperBlock *super) { uchar buf[1024]; SuperBlock *s; memset(buf, 0, sizeof buf); if(blockread(fd, buf, sizeof buf, 1, 0) != 1) return -1; s = (SuperBlock*)buf; super->magic = GBIT64((uchar*)&s->magic); super->log_start = GBIT64((uchar*)&s->log_start); super->log_end = GBIT64((uchar*)&s->log_end); return 0; } int putsuper(int fd, SuperBlock *super) { uchar buf[1024]; SuperBlock *s; memset(buf, 0, sizeof buf); s = (SuperBlock*)buf; memcpy(s->label, super->label, sizeof super->label); PBIT64((uchar*)&s->magic, super->magic); PBIT32((uchar*)&s->block_size, super->block_size); PBIT32((uchar*)&s->block_shift, super->block_shift); PBIT64((uchar*)&s->num_blocks, super->num_blocks); PBIT64((uchar*)&s->used_blocks, super->used_blocks); PBIT32((uchar*)&s->log_run.ag, super->log_run.ag); PBIT16((uchar*)&s->log_run.start, super->log_run.start); PBIT16((uchar*)&s->log_run.len, super->log_run.len); PBIT64((uchar*)&s->log_start, super->log_start); PBIT64((uchar*)&s->log_end, super->log_end); if(blockwrite(fd, buf, sizeof buf, 1, 0) != 1) return -1; return 0; }