mkfs: first working version

It can create a basic filesystem of arbitrary size.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
2019-06-09 15:48:07 +08:00
parent ab97abe22a
commit f68f8215b7
5 changed files with 141 additions and 46 deletions

37
tests/mkfs-simple.c Normal file
View File

@ -0,0 +1,37 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include "fat12.h"
static int make_image(const char *name, uint32_t size) {
int fd = open(name, O_WRONLY | O_CREAT, 0777);
if (-1 == fd) {
fprintf(stderr, "couldn't open %s: %s\n", name, strerror(errno));
return 1;
}
if (-1 == fat12_mkfs(fd, size)) {
fprintf(stderr, "couldn't make fat12 on %s: %s\n", name, strerror(errno));
close(fd);
return 1;
}
close(fd);
return 0;
}
int main(int argc, char **argv) {
int ret = 0;
ret += make_image("fat12-1300k.img", 1300 * 1024);
// ret += make_image("fat12-1800k.img", 1800 * 1024);
// ret += make_image("fat12-128k.img", 128 * 1024);
ret += make_image("fat12-16M.img", 16 * 1024 * 1024);
return ret;
}