87 lines
1.6 KiB
C
87 lines
1.6 KiB
C
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#include "dosfs.h"
|
|
|
|
static void usage(void) __dead;
|
|
static int list_img(char *);
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
int ch, list_mode;
|
|
|
|
setprogname(argv[0]);
|
|
|
|
list_mode = 0;
|
|
while ((ch = getopt(argc, argv, "l")) != -1) {
|
|
switch (ch) {
|
|
case 'l':
|
|
list_mode = 1;
|
|
break;
|
|
case '?':
|
|
default:
|
|
usage();
|
|
/* NOTREACHED */
|
|
}
|
|
}
|
|
argc -= optind;
|
|
argv += optind;
|
|
|
|
if (argc != 1) {
|
|
usage();
|
|
/* NOTREACHED */
|
|
}
|
|
|
|
if (list_mode) {
|
|
return list_img(argv[0]);
|
|
}
|
|
|
|
/* TODO: rest of the owl */
|
|
fprintf(stderr, "not yet implemented :(\n");
|
|
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
static int
|
|
list_img(char *path)
|
|
{
|
|
dosfs_t img = { 0 };
|
|
dosfile_t *rootdir, *cur;
|
|
int res;
|
|
|
|
res = open_image(path, O_RDONLY, &img);
|
|
if (res != 0) {
|
|
fprintf(stderr, "err: couldn't open image (errno %d)\n", res);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
rootdir = dos_listdir(&img, img.root_loc);
|
|
if (rootdir == NULL) {
|
|
perror("couldn't read root dir");
|
|
close_image(&img);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
printf("OEM ID: %.8s\nDirectory listing:\n", img.ib.oem_id);
|
|
for (cur = rootdir; cur->next != NULL; cur = cur->next) {
|
|
printf(" %s.%s\n", cur->fname, cur->fext);
|
|
}
|
|
|
|
dos_freedir(rootdir);
|
|
rootdir = cur = NULL;
|
|
close_image(&img);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
static void
|
|
usage(void)
|
|
{
|
|
fprintf(stderr, "usage: %s [-l] image\n", getprogname());
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|