2019-06-09 12:32:53 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2019-06-10 14:29:21 +00:00
|
|
|
static int list_directory(void *data, const struct fat12_dirent *dirent) {
|
|
|
|
printf("%d %d %x %d %d %s\n", dirent->ctime, dirent->mtime, dirent->file_attributes, dirent->size, dirent->first_cluster, dirent->filename);
|
|
|
|
}
|
|
|
|
|
2019-06-09 12:32:53 +00:00
|
|
|
int main(int argc, char **argv) {
|
2019-06-10 14:29:21 +00:00
|
|
|
// const char *img_name = "build/fat12-1800k.img";
|
|
|
|
const char *img_name = "disk-image";
|
2019-06-09 12:32:53 +00:00
|
|
|
int ret = 0;
|
|
|
|
int fd;
|
|
|
|
struct fat12_partition *part = fat12_alloc();
|
|
|
|
|
2019-06-10 14:29:21 +00:00
|
|
|
// ret = make_image(img_name, 1800 * 1024);
|
|
|
|
// if (ret == -1) {
|
|
|
|
// return 1;
|
|
|
|
// }
|
2019-06-09 12:32:53 +00:00
|
|
|
|
|
|
|
if (-1 == fat12_open(part, img_name)) {
|
|
|
|
fprintf(stderr, "couldn't open fat12 on %s: %s\n", img_name, strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-06-10 14:29:21 +00:00
|
|
|
fat12_ls_foreach(part, 0, NULL, list_directory);
|
|
|
|
|
2019-06-09 12:32:53 +00:00
|
|
|
fat12_close(part);
|
|
|
|
fat12_free(&part);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|