2008-04-12 21:19:32 +00:00
|
|
|
/*
|
|
|
|
*
|
2013-09-05 12:39:22 +00:00
|
|
|
* (c) 2005 Laurent Vivier <Laurent@Vivier.EU>
|
2008-04-12 21:19:32 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
2011-12-18 13:38:58 +00:00
|
|
|
#include <linux/fs.h>
|
2013-09-04 16:10:46 +00:00
|
|
|
#include <ext2fs/ext2_fs.h>
|
2008-04-12 21:19:32 +00:00
|
|
|
#include <libext2.h>
|
|
|
|
|
|
|
|
#include "device.h"
|
|
|
|
|
2008-04-20 16:35:55 +00:00
|
|
|
static void list(stream_VOLUME *volume, char *path)
|
2008-04-12 21:19:32 +00:00
|
|
|
{
|
2008-04-20 16:35:55 +00:00
|
|
|
stream_DIR *dir;
|
2008-04-12 21:19:32 +00:00
|
|
|
struct ext2_dir_entry_2 *entry;
|
|
|
|
|
|
|
|
dir = ext2_opendir(volume, path);
|
|
|
|
if (dir == NULL)
|
|
|
|
return;
|
|
|
|
while ((entry = ext2_readdir(dir)) != NULL)
|
|
|
|
{
|
|
|
|
if (entry->file_type == EXT2_FT_DIR)
|
|
|
|
printf("%s/\n", entry->name);
|
|
|
|
else
|
|
|
|
printf("%s\n", entry->name);
|
|
|
|
}
|
|
|
|
ext2_closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
device_io_t device;
|
2008-04-20 16:35:55 +00:00
|
|
|
stream_VOLUME *volume;
|
2008-04-12 21:19:32 +00:00
|
|
|
int arg = 1;
|
|
|
|
|
|
|
|
device_sector_size = 512;
|
|
|
|
if (argc <= 1) {
|
|
|
|
fprintf(stderr, "You must specify a device to open\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
device.data = (void*)device_open(argv[arg++], O_RDONLY);
|
|
|
|
device.read_sector = (stream_read_sector_t)device_read_sector;
|
|
|
|
device.close = (stream_close_t)device_close;
|
|
|
|
device.get_blocksize = (stream_get_blocksize_t)device_get_blocksize;
|
|
|
|
|
|
|
|
volume = ext2_mount(&device);
|
|
|
|
if (volume == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (argc > arg)
|
|
|
|
path = argv[arg];
|
|
|
|
else
|
|
|
|
path = "/";
|
|
|
|
|
|
|
|
list(volume, path);
|
|
|
|
|
|
|
|
ext2_umount(volume);
|
|
|
|
|
|
|
|
device_close(device.data);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|