Ejemplo n.º 1
0
static int listdir(struct fsw_posix_volume *vol, char *path, int level)
{
    struct fsw_posix_dir *dir;
    struct dirent *dent;
    int i;
    char subpath[4096];

    dir = fsw_posix_opendir(vol, path);
    if (dir == NULL) {
        fprintf(stderr, "opendir(%s) call failed.\n", path);
        return 1;
    }
    while ((dent = fsw_posix_readdir(dir)) != NULL) {
        for (i = 0; i < level*2; i++)
            fputc(' ', stderr);
        fprintf(stderr, "%d  %s\n", dent->d_type, dent->d_name);

        if (dent->d_type == DT_DIR) {
            snprintf(subpath, 4095, "%s%s/", path, dent->d_name);
            listdir(vol, subpath, level + 1);
        }
    }

    fsw_posix_closedir(dir);

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    struct fsw_posix_volume *vol;
    struct fsw_posix_dir *dir;
    struct dirent *dent;
    
    if (argc != 2) {
        printf("Usage: lsroot <file/device>\n");
        return 1;
    }
    
    //vol = fsw_posix_mount(argv[1], &FSW_FSTYPE_TABLE_NAME(ext2));
    //vol = fsw_posix_mount(argv[1], &FSW_FSTYPE_TABLE_NAME(reiserfs));
    vol = fsw_posix_mount(argv[1], &FSW_FSTYPE_TABLE_NAME(iso9660));
    if (vol == NULL) {
        printf("Mounting failed.\n");
        return 1;
    }
    //dir = fsw_posix_opendir(vol, "/drivers/net/");
    dir = fsw_posix_opendir(vol, "/");
    if (dir == NULL) {
        printf("opendir call failed.\n");
        return 1;
    }
    while ((dent = fsw_posix_readdir(dir)) != NULL) {
        printf("- %s\n", dent->d_name);
    }
    fsw_posix_closedir(dir);
    fsw_posix_unmount(vol);
    
    return 0;
}