static imgtoolerr_t vzdos_diskimage_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) { vz_iterator *iter = (vz_iterator *) imgtool_directory_extrabytes(enumeration); if (iter->eof == 1 || iter->index > MAX_DIRENTS) { ent->eof = 1; } else { const char *type; int ret, len; vzdos_dirent dirent; ret = vzdos_get_dirent(imgtool_directory_image(enumeration), iter->index - 1, &dirent); if (ret == IMGTOOLERR_FILENOTFOUND) { iter->eof = 1; ent->eof = 1; return IMGTOOLERR_SUCCESS; } if (ret == IMGTOOLERR_CORRUPTFILE) ent->corrupt = 1; /* kill trailing spaces */ for (len = 7; len > 0; len--) { if (dirent.fname[len] != 0x20) { break; } } memcpy(ent->filename, &dirent.fname, len + 1); ent->filesize = dirent.end_address - dirent.start_address; switch (dirent.ftype) { case 0x01: type = "Deleted"; break; case 'T': type = "Basic"; break; case 'B': type = "Binary"; break; case 'D': type = "Data"; break; case 'F': type = "Quickwrite"; break; case 'A': type = "Assembler"; break; case 'S': type = "Diskops"; break; case 'W': type = "Wordpro"; break; default: type = "Unknown"; } snprintf(ent->attr, ARRAY_LENGTH(ent->attr), "%s", type); iter->index++; } return IMGTOOLERR_SUCCESS; }
static imgtoolerr_t os9_diskimage_beginenum(imgtool_directory *enumeration, const char *path) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; struct os9_direnum *os9enum; imgtool_image *image; image = imgtool_directory_image(enumeration); os9enum = os9_get_dirinfo(enumeration); err = os9_lookup_path(image, path, CREATE_NONE, &os9enum->dir_info, NULL, NULL, NULL); if (err) goto done; /* this had better be a directory */ if (!os9enum->dir_info.directory) { err = IMGTOOLERR_CORRUPTIMAGE; goto done; } done: return err; }
static imgtoolerr_t datapack_next_enum(imgtool_directory *enumeration, imgtool_dirent *ent) { imgtool_image *image = imgtool_directory_image(enumeration); psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image); psion_iter *iter = (psion_iter*)imgtool_directory_extrabytes(enumeration); UINT8 data = 0; if (!pack->pack_index[iter->index].name_rec) { ent->eof = 1; return IMGTOOLERR_SUCCESS; } memcpy(ent->filename, pack->pack_index[iter->index].filename, 8); sprintf(ent->attr, "Type: %02x ID: %02x", pack->pack_index[iter->index].type, pack->pack_index[iter->index].id); if (pack->pack_index[iter->index].data_rec) { stream_seek(pack->stream, pack->pack_index[iter->index].data_rec + 2, SEEK_SET); ent->filesize = get_long_rec_size(pack->stream); } // seek all file's records if (pack->pack_index[iter->index].id >= 0x90) { stream_seek(pack->stream, 0x10, SEEK_SET); while (seek_next_record(pack->stream, pack->pack_index[iter->index].id)) { stream_read(pack->stream, &data, 1); stream_seek(pack->stream, data + 1, SEEK_CUR); ent->filesize +=data; } } iter->index++; return IMGTOOLERR_SUCCESS; }
static imgtoolerr_t os9_diskimage_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) { struct os9_direnum *os9enum; UINT32 lsn, index; imgtoolerr_t err; UINT8 dir_entry[32]; char filename[29]; struct os9_fileinfo file_info; imgtool_image *image; image = imgtool_directory_image(enumeration); os9enum = os9_get_dirinfo(enumeration); do { /* check for EOF */ if (os9enum->index >= os9enum->dir_info.file_size) { ent->eof = 1; return IMGTOOLERR_SUCCESS; } /* locate the LSN and offset for this directory entry */ index = os9enum->index; lsn = os9_lookup_lsn(image, &os9enum->dir_info, &index); /* read the directory entry out of the lSN */ err = os9_read_lsn(image, lsn, index, dir_entry, sizeof(dir_entry)); if (err) return err; if (dir_entry[0]) { /* read the file or directory name */ pick_string(dir_entry, 0, 28, filename); /* we have certain expectations of the directory contents; the * first directory entry should be "..", the second ".", and * subsequent entries should never be "." or ".." */ switch(os9enum->index) { case 0: if (strcmp(filename, "..")) imgtool_warn("First entry in directory should be \"..\" and not \"%s\"", filename); break; case 32: if (strcmp(filename, ".")) imgtool_warn("Second entry in directory should be \".\" and not \"%s\"", filename); break; default: if (!strcmp(filename, ".") || !strcmp(filename, "..")) imgtool_warn("Directory entry %d should not be \"%s\"", index / 32, filename); break; } /* if the filename is ".", the file should point to the current directory */ if (!strcmp(filename, ".") && (pick_integer_be(dir_entry, 29, 3) != os9enum->dir_info.lsn)) { imgtool_warn("Directory \".\" does not point back to same directory"); } } else { /* no more directory entries */ filename[0] = '\0'; } /* move on to the next directory entry */ os9enum->index += 32; } while(!filename[0] || !strcmp(filename, ".") || !strcmp(filename, "..")); /* read file attributes */ lsn = pick_integer_be(dir_entry, 29, 3); err = os9_decode_file_header(imgtool_directory_image(enumeration), lsn, &file_info); if (err) return err; /* fill out imgtool_dirent structure */ snprintf(ent->filename, ARRAY_LENGTH(ent->filename), "%s", filename); snprintf(ent->attr, ARRAY_LENGTH(ent->attr), "%c%c%c%c%c%c%c%c", file_info.directory ? 'd' : '-', file_info.non_sharable ? 's' : '-', file_info.public_execute ? 'x' : '-', file_info.public_write ? 'w' : '-', file_info.public_read ? 'r' : '-', file_info.user_execute ? 'x' : '-', file_info.user_write ? 'w' : '-', file_info.user_read ? 'r' : '-'); ent->directory = file_info.directory; ent->corrupt = (dir_entry[28] != 0); ent->filesize = file_info.file_size; return IMGTOOLERR_SUCCESS; }
static imgtoolerr_t rsdos_diskimage_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) { floperr_t ferr; imgtoolerr_t err; size_t filesize; struct rsdos_direnum *rsenum; struct rsdos_dirent rsent; char fname[13]; imgtool_image *image; image = imgtool_directory_image(enumeration); rsenum = (struct rsdos_direnum *) imgtool_directory_extrabytes(enumeration); /* Did we hit the end of file before? */ if (rsenum->eof) goto eof; do { if (rsenum->index >= MAX_DIRENTS) goto eof; ferr = get_rsdos_dirent(image, rsenum->index++, &rsent); if (ferr) return imgtool_floppy_error(ferr); } while(rsent.fname[0] == '\0'); /* Now are we at the eof point? */ if (rsent.fname[0] == -1) { rsenum->eof = 1; eof: ent->eof = 1; } else { /* Not the end of file */ err = process_rsdos_file(&rsent, image, NULL, &filesize); if (err) return err; if (filesize == ((size_t) -1)) { /* corrupt! */ ent->filesize = 0; ent->corrupt = 1; } else { ent->filesize = filesize; ent->corrupt = 0; } ent->eof = 0; get_dirent_fname(fname, &rsent); snprintf(ent->filename, ARRAY_LENGTH(ent->filename), "%s", fname); snprintf(ent->attr, ARRAY_LENGTH(ent->attr), "%d %c", (int) rsent.ftype, (char) (rsent.asciiflag + 'B')); } return IMGTOOLERR_SUCCESS; }