fat12: add ls_callback function

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
2019-06-10 22:29:21 +08:00
parent c4c5f706b0
commit 03e268f710
3 changed files with 90 additions and 5 deletions

View File

@ -25,22 +25,29 @@ static int make_image(const char *name, uint32_t size) {
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 = "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;
}
// 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);