48 lines
1.0 KiB
C
48 lines
1.0 KiB
C
|
#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) {
|
||
|
const char *img_name = "build/fat12-1800k.img";
|
||
|
int ret = 0;
|
||
|
int fd;
|
||
|
struct fat12_partition *part = fat12_alloc();
|
||
|
|
||
|
ret = make_image(img_name, 1800 * 1024);
|
||
|
if (ret == -1) {
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
if (-1 == fat12_open(part, img_name)) {
|
||
|
fprintf(stderr, "couldn't open fat12 on %s: %s\n", img_name, strerror(errno));
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
fat12_close(part);
|
||
|
fat12_free(&part);
|
||
|
|
||
|
return 0;
|
||
|
}
|