Sean Cross
aa387e176d
On real hardwareit will use memory-mapped io. Rework pang-io so that it more closely aligns with this paradigm. Signed-off-by: Sean Cross <sean@xobs.io>
56 lines
1.4 KiB
C
56 lines
1.4 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"
|
|
#include "io.h"
|
|
|
|
static int make_image(const char *name, uint32_t size) {
|
|
|
|
struct pang_io *io = pang_open(name);
|
|
if (!io) {
|
|
fprintf(stderr, "couldn't open %s: %s\n", name, strerror(errno));
|
|
return 1;
|
|
}
|
|
|
|
if (-1 == fat12_mkfs(io, size)) {
|
|
fprintf(stderr, "couldn't make fat12 on %s: %s\n", name, strerror(errno));
|
|
pang_close(&io);
|
|
return 1;
|
|
}
|
|
pang_close(&io);
|
|
return 0;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
// const char *img_name = "build/fat12-1800k.img";
|
|
const char *img_name = "disk-image";
|
|
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_ls_foreach(part, 0, NULL, list_directory);
|
|
|
|
fat12_close(part);
|
|
fat12_free(&part);
|
|
|
|
return 0;
|
|
} |