diff -urN ../vmscd-1.0/cache.c ./cache.c --- ../vmscd-1.0/cache.c 2000-01-01 19:19:52.000000000 +0100 +++ ./cache.c 2001-07-16 16:46:51.000000000 +0200 @@ -205,22 +205,23 @@ int lbn_count, void *buffer) { - int size; + size_t size; char *current = buffer; - int remain = lbn_count * ODS2_BLOCK_SIZE; + size_t remain = lbn_count * (size_t)ODS2_BLOCK_SIZE; trace ("cache.read_device: LBN %d, %d blocks\n", lbn, lbn_count); - if ((int) lseek (fd, lbn * ODS2_BLOCK_SIZE, SEEK_SET) < 0) { - error (err_flags | ERR_ERRNO, "error positioning to LBN %d\n", lbn); + if (lseek64 (fd, lbn * (off64_t)ODS2_BLOCK_SIZE, SEEK_SET) < 0) { + error (err_flags | ERR_ERRNO, "error %d positioning to LBN 0x%x/%d\n", errno, lbn * (off64_t)ODS2_BLOCK_SIZE, lbn); return -1; } while (remain > 0) { size = read (fd, current, remain); if (size < 0) { - error (err_flags | ERR_ERRNO, "error reading LBN %d\n", - lbn + (current - (char*)buffer) / ODS2_BLOCK_SIZE); + error (err_flags | ERR_ERRNO, "error %d reading LBN %d\n", + errno, + lbn + (current - (char*)buffer) / ODS2_BLOCK_SIZE); return -1; } else if (size == 0) { @@ -327,7 +328,7 @@ block_t *block; list_t *list; - trace ("cache.read_lbn: LBN %d, %d blocks, %s\n", lbn, lbn_count, + trace ("cache.read_lbn: LBN %d/0x%x, %d blocks, %s\n", lbn, lbn, lbn_count, usage == LBN_META ? "meta-data" : "data"); /* Determine which part of the cache to use */ diff -urN ../vmscd-1.0/copy.c ./copy.c --- ../vmscd-1.0/copy.c 2000-01-01 15:26:52.000000000 +0100 +++ ./copy.c 2001-07-18 14:12:15.000000000 +0200 @@ -39,6 +39,9 @@ #include "cache.h" #include "volume.h" #include "copy.h" +#include "dumpvolume.h" + +extern FILE * dumpfile; /* The prototype for mkdir(2) is missing from fcntl.h */ @@ -46,7 +49,7 @@ /* Blocking factor for file copy */ -#define COPY_BLOCK_FACTOR 10 +#define COPY_BLOCK_FACTOR 1 /* Text mode characters */ @@ -148,6 +151,8 @@ static void delete_file (int err_flags, copy_opt_t *opt, const char *path) { + fprintf (opt->out, "would delete %s\n", path); + return; if (remove (path) == 0) { if (opt->verbose) fprintf (opt->out, "deleting %s\n", path); @@ -511,9 +516,10 @@ char data [COPY_BLOCK_FACTOR * ODS2_BLOCK_SIZE]; trace ("copy.copy_binary_file: \"%s\"\n", src->name); + dump_file_t (src, 0); while (remain > 0) { - + trace ("copy.copy_binary_file: remain %d\n", remain); if (remain >= COPY_BLOCK_FACTOR * ODS2_BLOCK_SIZE) { vbn_count = COPY_BLOCK_FACTOR; size = vbn_count * ODS2_BLOCK_SIZE; @@ -594,8 +600,9 @@ if (dest == NULL) copy_text_file (err_flags, recattr, src, opt->out); - else if ((fp = fopen (dest, "w")) == NULL) - error (err_flags | ERR_ERRNO, "cannot create %s\n", dest); + else if ((fp = fopen (dest, "w")) == NULL) { + error (err_flags | ERR_ERRNO, "cannot create text file %s\n", dest); + } else { /* Copy the content of the file */ @@ -619,8 +626,9 @@ /* Copy the file in raw mode */ - if ((fd = creat (dest, 0666)) < 0) - error (err_flags | ERR_ERRNO, "cannot create %s\n", dest); + if ((fd = creat (dest, 0666)) < 0) { + error (err_flags | ERR_ERRNO, "cannot create raw file %s\n", dest); + } else { /* Copy the content of the file */ @@ -674,7 +682,27 @@ /* Create the new destination directory if it does not exist */ - exists = stat (dest, &st) == 0 && S_ISDIR (st.st_mode); + exists = stat (dest, &st) == 0; + + if (exists && !S_ISDIR (st.st_mode)) + { + char *newdest = (char *)malloc (strlen (dest) + 5); /* + ".nnn\0" */ + int i = 1; + if (newdest == 0) + abort(); + fprintf (dumpfile, "%s already exists as a file\n", dest); + while (i < 1000) + { + sprintf (newdest, "%s.%03d", dest, i); + if (rename (dest, newdest) == 0) + { + fprintf (stdout, "rename %s to %s\n", dest, newdest); + exists = 0; + break; + } + i = i + 1; + } + } if (opt->verbose) { if (exists) @@ -686,7 +714,6 @@ if (!exists && mkdir (dest, 0777) < 0) error (err_flags | ERR_ERRNO, "cannot create directory %s\n", dest); else { - /* Loop on all files in the directory */ while ((status = next_file (err_flags, dir, name, sizeof (name), diff -urN ../vmscd-1.0/dumpods2.c ./dumpods2.c --- ../vmscd-1.0/dumpods2.c 1970-01-01 01:00:00.000000000 +0100 +++ ./dumpods2.c 2001-07-18 12:33:48.000000000 +0200 @@ -0,0 +1,272 @@ +/* dumpods2.c */ + +#include +#include +#include +#include "ods2.h" +#include "utils.h" + +extern onoff_t debug_mode; + +extern void hexdump (const char *title, const void *ptr, int size, int offset); + +extern FILE *dumpfile; + +void dump_ods2_fid_t (const ods2_fid_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_fid_t", p, sizeof (ods2_fid_t), offset); + fprintf (dumpfile, "fid_w_num (File number) %d\n", p->fid_w_num); + fprintf (dumpfile, "fid_w_seq (File sequence number) %d\n", p->fid_w_seq); + fprintf (dumpfile, "fid_b_rvn (Byte form of RVN) %d\n", p->fid_b_rvn); + fprintf (dumpfile, "fid_b_nmx (File number extension) %d\n", p->fid_b_nmx); +} + +/*----------------------------------------------*/ + +void dump_ods2_home_block_t (const ods2_home_block_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_home_block_t", p, sizeof (ods2_home_block_t), offset); + fprintf (dumpfile, "hm2_l_homelbn (LBN of home (i.e., this) block) %d\n", p->hm2_l_homelbn); + fprintf (dumpfile, "hm2_l_alhomelbn (LBN of alternate home block) %d\n", p->hm2_l_alhomelbn); + fprintf (dumpfile, "hm2_l_altidxlbn (LBN of alternate index file header) %d\n", p->hm2_l_altidxlbn); + fprintf (dumpfile, "hm2_b_strucver (structure version number) %d\n", p->hm2_b_strucver); + fprintf (dumpfile, "hm2_b_struclev (main structure level) %d\n", p->hm2_b_struclev); + fprintf (dumpfile, "hm2_w_cluster (storage bitmap cluster factor) %d\n", p->hm2_w_cluster); + fprintf (dumpfile, "hm2_w_homevbn (VBN of home (i.e., this) block) %d\n", p->hm2_w_homevbn); + fprintf (dumpfile, "hm2_w_alhomevbn (VBN of alternate home block) %d\n", p->hm2_w_alhomevbn); + fprintf (dumpfile, "hm2_w_altidxvbn (VBN of alternate index file header) %d\n", p->hm2_w_altidxvbn); + fprintf (dumpfile, "hm2_w_ibmapvbn (VBN of index file bitmap) %d\n", p->hm2_w_ibmapvbn); + fprintf (dumpfile, "hm2_l_ibmaplbn (LBN of index file bitmap) %d\n", p->hm2_l_ibmaplbn); + fprintf (dumpfile, "hm2_l_maxfiles (maximum ! files on volume) %d\n", p->hm2_l_maxfiles); + fprintf (dumpfile, "hm2_w_ibmapsize (index file bitmap size, blocks) %d\n", p->hm2_w_ibmapsize); + fprintf (dumpfile, "hm2_w_resfiles (! reserved files on volume) %d\n", p->hm2_w_resfiles); + fprintf (dumpfile, "hm2_w_devtype (disk device type) %d\n", p->hm2_w_devtype); + fprintf (dumpfile, "hm2_w_rvn (relative volume number of this volume) %d\n", p->hm2_w_rvn); + fprintf (dumpfile, "hm2_w_setcount (count of volumes in set) %d\n", p->hm2_w_setcount); + fprintf (dumpfile, "hm2_w_volchar (volume characteristics) %d\n", p->hm2_w_volchar); + fprintf (dumpfile, "hm2_l_volowner (volume owner UIC) %d\n", p->hm2_l_volowner); + fprintf (dumpfile, "hm2_l_sec_mask (volume security mask) %d\n", p->hm2_l_sec_mask); + fprintf (dumpfile, "hm2_w_protect (volume protection) %d\n", p->hm2_w_protect); + fprintf (dumpfile, "hm2_w_fileprot (default file protection) %d\n", p->hm2_w_fileprot); + fprintf (dumpfile, "hm2_w_recprot (default file record protection) %d\n", p->hm2_w_recprot); + fprintf (dumpfile, "hm2_w_checksum1 (first checksum) %d\n", p->hm2_w_checksum1); + fprintf (dumpfile, "hm2_q_credate (volume creation date) %lld\n", ((unsigned long long)(p->hm2_q_credate.high) << 32) + ((unsigned long long)(p->hm2_q_credate.low))); + fprintf (dumpfile, "hm2_b_window (default window size) %d\n", p->hm2_b_window); + fprintf (dumpfile, "hm2_b_lru_lim (default LRU limit) %d\n", p->hm2_b_lru_lim); + fprintf (dumpfile, "hm2_w_extend (default file extend) %d\n", p->hm2_w_extend); + fprintf (dumpfile, "hm2_q_retainmin (minimum file retention period) %lld\n", ((unsigned long long)(p->hm2_q_retainmin.high) << 32) + ((unsigned long long)(p->hm2_q_retainmin.low))); + fprintf (dumpfile, "hm2_q_retainmax (maximum file retention period) %lld\n", ((unsigned long long)(p->hm2_q_retainmax.high) << 32) + ((unsigned long long)(p->hm2_q_retainmax.low))); + fprintf (dumpfile, "hm2_q_revdate (volume revision date) %lld\n", ((unsigned long long)(p->hm2_q_revdate.high) << 32) + ((unsigned long long)(p->hm2_q_revdate.low))); + fprintf (dumpfile, "hm2_r_min_class[20] (volume minimum security class) %02x...\n", p->hm2_r_min_class[0]); + fprintf (dumpfile, "hm2_r_max_class[20] (volume maximum security class) %02x...\n", p->hm2_r_max_class[0]); + fprintf (dumpfile, "hm2_w_filetab_fid (file lookup table FID) ods2_fid_t\n"); + dump_ods2_fid_t (&(p->hm2_w_filetab_fid), offset + offsetof (ods2_home_block_t, hm2_w_filetab_fid)); + fprintf (dumpfile, "hm2_w_lowstruclev (lowest struclev on volume) %d\n", p->hm2_w_lowstruclev); + fprintf (dumpfile, "hm2_w_highstruclev (highest struclev on volume) %d\n", p->hm2_w_highstruclev); + fprintf (dumpfile, "hm2_q_copydate %lld\n", ((unsigned long long)(p->hm2_q_copydate.high) << 32) + ((unsigned long long)(p->hm2_q_copydate.low))); + fprintf (dumpfile, "hm2_l_serialnum (pack serial number) %d\n", p->hm2_l_serialnum); + fprintf (dumpfile, "hm2_t_strucname[12] (structure (volume set name)) %02x...\n", p->hm2_t_strucname[0]); + fprintf (dumpfile, "hm2_t_volname[12] (volume name) %02x...\n", p->hm2_t_volname[0]); + fprintf (dumpfile, "hm2_t_ownername[12] (volume owner name) %02x...\n", p->hm2_t_ownername[0]); + fprintf (dumpfile, "hm2_t_format[12] (volume format type) %02x...\n", p->hm2_t_format[0]); + fprintf (dumpfile, "hm2_w_checksum2 (second checksum) %d\n", p->hm2_w_checksum2); +} + +/*----------------------------------------------*/ + +void dump_ods2_file_attr_t (const ods2_file_attr_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_file_attr_t", p, sizeof (ods2_file_attr_t), offset); + fprintf (dumpfile, "fat_v_rtype (record type) %d\n", p->fat_v_rtype); + fprintf (dumpfile, "fat_v_fileorg (file organization) %d\n", p->fat_v_fileorg); + fprintf (dumpfile, "fat_v_fortrancc (Fortran carriage control) %d\n", p->fat_v_fortrancc); + fprintf (dumpfile, "fat_v_impliedcc (implied carriage control) %d\n", p->fat_v_impliedcc); + fprintf (dumpfile, "fat_v_printcc (print file carriage control) %d\n", p->fat_v_printcc); + fprintf (dumpfile, "fat_v_nospan (no spanned records) %d\n", p->fat_v_nospan); + fprintf (dumpfile, "fat_v_msbrcw (Format of RCW (0=LSB, 1=MSB)) %d\n", p->fat_v_msbrcw); + fprintf (dumpfile, "fat_v_fill_1 (MBZ (or should be zero)) %d\n", p->fat_v_fill_1); + fprintf (dumpfile, "fat_w_rsize (record size in bytes) %d\n", p->fat_w_rsize); + fprintf (dumpfile, "fat_w_hiblkh (highest allocated VBN, high order word) %d\n", p->fat_w_hiblkh); + fprintf (dumpfile, "fat_w_hiblkl (highest allocated VBN, low order word) %d\n", p->fat_w_hiblkl); + fprintf (dumpfile, "fat_w_efblkh (end of file VBN, high order word) %d\n", p->fat_w_efblkh); + fprintf (dumpfile, "fat_w_efblkl (end of file VBN, low order word) %d\n", p->fat_w_efblkl); + fprintf (dumpfile, "fat_w_ffbyte (first free byte in EFBLK) %d\n", p->fat_w_ffbyte); + fprintf (dumpfile, "fat_b_bktsize (bucket size in blocks) %d\n", p->fat_b_bktsize); + fprintf (dumpfile, "fat_b_vfcsize (size in bytes of control for VFC) %d\n", p->fat_b_vfcsize); + fprintf (dumpfile, "fat_w_maxrec (maximum record size in bytes) %d\n", p->fat_w_maxrec); + fprintf (dumpfile, "fat_w_defext (default extend quantity) %d\n", p->fat_w_defext); + fprintf (dumpfile, "fat_w_gbc (global buffer count) %d\n", p->fat_w_gbc); + fprintf (dumpfile, "fat_w_versions (default version limit for directory file) %d\n", p->fat_w_versions); +} + +/*----------------------------------------------*/ + +void dump_ods2_file_header_t (const ods2_file_header_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_file_header_t", p, sizeof (ods2_file_header_t), offset); + fprintf (dumpfile, "fh2_b_idoffset (ident area offset in words) %d\n", p->fh2_b_idoffset); + fprintf (dumpfile, "fh2_b_mpoffset (map area offset in words) %d\n", p->fh2_b_mpoffset); + fprintf (dumpfile, "fh2_b_acoffset (access control list offset in words) %d\n", p->fh2_b_acoffset); + fprintf (dumpfile, "fh2_b_rsoffset (reserved area offset in words) %d\n", p->fh2_b_rsoffset); + fprintf (dumpfile, "fh2_w_seg_num (file segment number) %d\n", p->fh2_w_seg_num); + fprintf (dumpfile, "fh2_b_strucver (file structure version) %d\n", p->fh2_b_strucver); + fprintf (dumpfile, "fh2_b_struclev (principal file structure level) %d\n", p->fh2_b_struclev); + fprintf (dumpfile, "fh2_w_fid (file ID) ods2_fid_t\n"); dump_ods2_fid_t (&(p->fh2_w_fid), offset + offsetof (ods2_file_header_t, fh2_w_fid)); + fprintf (dumpfile, "fh2_w_ext_fid (extension file ID) ods2_fid_t\n"); dump_ods2_fid_t (&(p->fh2_w_ext_fid), offset + offsetof (ods2_file_header_t, fh2_w_ext_fid)); + fprintf (dumpfile, "fh2_w_recattr (file record attributes) ods2_file_attr_t\n"); dump_ods2_file_attr_t (&(p->fh2_w_recattr), offset + offsetof (ods2_file_header_t, fh2_w_recattr)); + fprintf (dumpfile, "fh2_l_filechar (file characteristics) %d\n", p->fh2_l_filechar); + fprintf (dumpfile, "fh2_w_recprot (record protection) %d\n", p->fh2_w_recprot); + fprintf (dumpfile, "fh2_b_map_inuse (number of map area words in use) %d\n", p->fh2_b_map_inuse); + fprintf (dumpfile, "fh2_b_acc_mode (least privileged access mode) %d\n", p->fh2_b_acc_mode); + fprintf (dumpfile, "fh2_l_fileowner (file owner UIC) %d\n", p->fh2_l_fileowner); + fprintf (dumpfile, "fh2_w_fileprot (file protection) %d\n", p->fh2_w_fileprot); + fprintf (dumpfile, "fh2_w_backlink (back link pointer) ods2_fid_t\n"); dump_ods2_fid_t (&(p->fh2_w_backlink), offset + offsetof (ods2_file_header_t, fh2_w_backlink)); + fprintf (dumpfile, "fh2_b_journal (journal control flags) %d\n", p->fh2_b_journal); + fprintf (dumpfile, "fh2_b_ru_active (If non-zero, has active recov units) %d\n", p->fh2_b_ru_active); + fprintf (dumpfile, "fh2_fill_3 (reserved) %d\n", p->fh2_fill_3); + fprintf (dumpfile, "fh2_l_highwater (high-water mark in file) %d\n", p->fh2_l_highwater); + fprintf (dumpfile, "fh2_fill_1[8] (reserved) %02x...\n", p->fh2_fill_1[0]); + fprintf (dumpfile, "fh2_r_class_prot[20] (security classification mask) %02x...\n", p->fh2_r_class_prot[0]); + fprintf (dumpfile, "fh2_w_checksum (file header checksum) %d\n", p->fh2_w_checksum); +} + +/*----------------------------------------------*/ + +void dump_ods2_file_header_ident_t (const ods2_file_header_ident_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_file_header_ident_t", p, sizeof (ods2_file_header_ident_t), offset); + fprintf (dumpfile, "fi2_t_filename[20] (file name, type, and version (ASCII)) %02x...\n", p->fi2_t_filename[0]); + fprintf (dumpfile, "fi2_w_revision (revision number (binary)) %d\n", p->fi2_w_revision); + fprintf (dumpfile, "fi2_q_credate %lld\n", ((unsigned long long)(p->fi2_q_credate.high) << 32) + ((unsigned long long)(p->fi2_q_credate.low))); + fprintf (dumpfile, "fi2_q_revdate %lld\n", ((unsigned long long)(p->fi2_q_revdate.high) << 32) + ((unsigned long long)(p->fi2_q_revdate.low))); + fprintf (dumpfile, "fi2_q_expdate %lld\n", ((unsigned long long)(p->fi2_q_expdate.high) << 32) + ((unsigned long long)(p->fi2_q_expdate.low))); + fprintf (dumpfile, "fi2_q_bakdate %lld\n", ((unsigned long long)(p->fi2_q_bakdate.high) << 32) + ((unsigned long long)(p->fi2_q_bakdate.low))); + fprintf (dumpfile, "fi2_t_filenamext[66] (extension file name area) %02x...\n", p->fi2_t_filenamext[0]); + fprintf (dumpfile, "fi2_t_userlabel[80] (optional user file label) %02x...\n", p->fi2_t_userlabel[0]); +} + +/*----------------------------------------------*/ + +void dump_ods2_fmap_placement_t (const ods2_fmap_placement_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_fmap_placement_t", p, sizeof (ods2_fmap_placement_t), offset); + fprintf (dumpfile, "fm2_v_exact (exact placement specified) %d\n", p->fm2_v_exact); + fprintf (dumpfile, "fm2_v_oncyl (on cylinder allocation desired) %d\n", p->fm2_v_oncyl); + fprintf (dumpfile, "fm2_v_fill %d\n", p->fm2_v_fill); + fprintf (dumpfile, "fm2_v_lbn (use LBN of next map pointer) %d\n", p->fm2_v_lbn); + fprintf (dumpfile, "fm2_v_rvn (place on specified RVN) %d\n", p->fm2_v_rvn); + fprintf (dumpfile, "fm2_v_format %d\n", p->fm2_v_format); +} + +/*----------------------------------------------*/ + +void dump_ods2_fmap1_t (const ods2_fmap1_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_fmap1_t", p, sizeof (ods2_fmap1_t), offset); + fprintf (dumpfile, "fm2_b_count1 (format 1 count field) %d\n", p->fm2_b_count1); + fprintf (dumpfile, "fm2_v_highlbn (high order LBN) %d\n", p->fm2_v_highlbn); + fprintf (dumpfile, "fm2_v_format %d\n", p->fm2_v_format); + fprintf (dumpfile, "fm2_w_lowlbn (format 1 low order LBN) %d\n", p->fm2_w_lowlbn); +} + +/*----------------------------------------------*/ + +void dump_ods2_fmap2_t (const ods2_fmap2_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_fmap2_t", p, sizeof (ods2_fmap2_t), offset); + fprintf (dumpfile, "fm2_v_count2 %d\n", p->fm2_v_count2); + fprintf (dumpfile, "fm2_v_format %d\n", p->fm2_v_format); + fprintf (dumpfile, "fm2_l_lbn2 %d\n", p->fm2_l_lbn2); +} + +/*----------------------------------------------*/ + +void dump_ods2_fmap3_t (const ods2_fmap3_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_fmap3_t", p, sizeof (ods2_fmap3_t), offset); + fprintf (dumpfile, "fm2_v_count2 %d\n", p->fm2_v_count2); + fprintf (dumpfile, "fm2_v_format %d\n", p->fm2_v_format); + fprintf (dumpfile, "fm2_w_lowcount %d\n", p->fm2_w_lowcount); + fprintf (dumpfile, "fm2_l_lbn3 %d\n", p->fm2_l_lbn3); +} + +/*----------------------------------------------*/ + +void dump_ods2_dir_t (const ods2_dir_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_dir_t", p, sizeof (ods2_dir_t), offset); + fprintf (dumpfile, "dir_w_size (size of directory record in bytes) %d\n", p->dir_w_size); + fprintf (dumpfile, "dir_w_verlimit (maximum number of versions) %d\n", p->dir_w_verlimit); + fprintf (dumpfile, "dir_v_type (directory entry type) %d\n", p->dir_v_type); + fprintf (dumpfile, "dir_v_fill_1 (reserved) %d\n", p->dir_v_fill_1); + fprintf (dumpfile, "dir_v_nextrec (another record of same name/type follows) %d\n", p->dir_v_nextrec); + fprintf (dumpfile, "dir_v_prevrec (another record of same name/type precedes) %d\n", p->dir_v_prevrec); + fprintf (dumpfile, "dir_b_namecount (byte count of name string) %d\n", p->dir_b_namecount); + fprintf (dumpfile, "dir_t_name[DIR_S_NAME] (file name/type) %02x...\n", p->dir_t_name[0]); +} + +/*----------------------------------------------*/ + +void dump_ods2_dirent_t (const ods2_dirent_t *p, int offset) +{ + if (!debug_mode) + return; + + if (p == 0) return; + hexdump ("ods2_dirent_t", p, sizeof (ods2_dirent_t), offset); + fprintf (dumpfile, "dir_w_version (version number) %d\n", p->dir_w_version); + fprintf (dumpfile, "dir_w_fid ods2_fid_t\n"); dump_ods2_fid_t(&(p->dir_w_fid), offset + offsetof (ods2_dirent_t, dir_w_fid)); +} + +/*----------------------------------------------*/ + +void dump_ods2_dirlink_t (const ods2_dirlink_t *p, int offset) +{ + if (!debug_mode) + return; + if (p == 0) return; + + hexdump ("ods2_dirlink_t", p, sizeof (ods2_dirlink_t), offset); + fprintf (dumpfile, "dir_b_linkcount (byte count of symbolic link name) %d\n", p->dir_b_linkcount); + fprintf (dumpfile, "dir_t_linkname[1] (symbolic link name) %02x...\n", p->dir_t_linkname[0]); +} diff -urN ../vmscd-1.0/dumpods2.h ./dumpods2.h --- ../vmscd-1.0/dumpods2.h 1970-01-01 01:00:00.000000000 +0100 +++ ./dumpods2.h 2001-07-17 13:41:13.000000000 +0200 @@ -0,0 +1,14 @@ +/* dumpods2.h */ +extern void dump_ods2_fid_t (const ods2_fid_t *p, int offset); +extern void dump_ods2_home_block_t (const ods2_home_block_t *p, int offset); +extern void dump_ods2_file_attr_t (const ods2_file_attr_t *p, int offset); +extern void dump_ods2_file_header_t (const ods2_file_header_t *p, int offset); +extern void dump_ods2_file_header_ident_t (const ods2_file_header_ident_t *p, int offset); +extern void dump_ods2_fmap_placement_t (const ods2_fmap_placement_t *p, int offset); +extern void dump_ods2_fmap1_t (const ods2_fmap1_t *p, int offset); +extern void dump_ods2_fmap2_t (const ods2_fmap2_t *p, int offset); +extern void dump_ods2_fmap3_t (const ods2_fmap3_t *p, int offset); +extern void dump_ods2_dir_t (const ods2_dir_t *p, int offset); +extern void dump_ods2_dirent_t (const ods2_dirent_t *p, int offset); +extern void dump_ods2_dirlink_t (const ods2_dirlink_t *p, int offset); + Binary files ../vmscd-1.0/dumpstruct.awk and ./dumpstruct.awk differ diff -urN ../vmscd-1.0/dumpvolume.c ./dumpvolume.c --- ../vmscd-1.0/dumpvolume.c 1970-01-01 01:00:00.000000000 +0100 +++ ./dumpvolume.c 2001-07-18 12:33:34.000000000 +0200 @@ -0,0 +1,93 @@ +/* dumpvolume.c */ + +#include +#include +#include +#include "ods2.h" +#include "dumpods2.h" +#include "utils.h" +#include "cache.h" +#include "volume.h" +#include "dumpvolume.h" + +extern onoff_t debug_mode; + +extern void hexdump (const char *title, const void *ptr, int size, int offset); + +extern FILE *dumpfile; + +void dump_retrieval_t (const retrieval_t *p, int offset) +{ + if (!debug_mode) + return; + if (p == 0) return; + fprintf (dumpfile, "retrieval_t:\n"); + fprintf (dumpfile, "vbn (Virtual block number in file, start at 1) %u\n", p->vbn); + fprintf (dumpfile, "lbn (Logical block number on disk, start at 0) %u\n", p->lbn); + fprintf (dumpfile, "count (Number of blocks in this extent) %d\n", p->count); +} + +/*----------------------------------------------*/ + +void dump_fid_t (const fid_t *p, int offset) +{ + if (!debug_mode) + return; + if (p == 0) return; + fprintf (dumpfile, "fid_t:\n"); + fprintf (dumpfile, "number (File number (header number)) %d\n", p->number); + fprintf (dumpfile, "sequence (Sequence number (usage count of header)) %d\n", p->sequence); + fprintf (dumpfile, "volume (Volume number in volume set (0 for CD-ROM)) %d\n", p->volume); +} + +/*----------------------------------------------*/ + +void dump_file_t (const file_t *p, int offset) +{ + int i; + + if (!debug_mode) + return; + if (p == 0) return; + fprintf (dumpfile, "file_t:\n"); + fprintf (dumpfile, "cache (LBN cache to cdrom device) %p\n", p->cache); + fprintf (dumpfile, "fid (File identification) fid_t\n"); dump_fid_t (&(p->fid), offset + offsetof (file_t, fid)); + fprintf (dumpfile, "*name (Name as present in header (mallocated)) %p\n", p->name); + fprintf (dumpfile, "version (Version as present in header) %d\n", p->version); + fprintf (dumpfile, "header (First (or only) header)\n"); dump_ods2_file_header_t (&(p->header), offset + offsetof (file_t, header)); + fprintf (dumpfile, "last_vbn (Last allocated VBN) %d\n", p->last_vbn); + fprintf (dumpfile, "last_data_vbn (Last VBN containing data) %d\n", p->last_data_vbn); + fprintf (dumpfile, "used_size (File size in bytes) %d\n", p->used_size); + fprintf (dumpfile, "map_count (Number of RP in map array) %d\n", p->map_count); + if (p->map != 0 && p->map_count > 0) + { + fprintf (dumpfile, "*map (Retrieval pointers (mallocated))\n"); + for (i = 0; i < p->map_count; i++) + { + fprintf (dumpfile, "%d: ", i); + dump_retrieval_t (p->map+i, offset + offsetof (file_t, map) + i*sizeof(retrieval_t)); + } + } + fprintf (dumpfile, "*buffer (Data buffer (mallocated)) %p\n", p->buffer); + fprintf (dumpfile, "vbn (VBN of current data block) %u\n", p->vbn); + fprintf (dumpfile, "*cur_byte (Next byte to read in the buffer) %p\n", p->cur_byte); + fprintf (dumpfile, "*last_byte (Last meaningful byte in buffer + 1) %p\n", p->last_byte); + fprintf (dumpfile, "*cur_record (Current record in buffer)\n"); dump_ods2_dir_t (p->cur_record, offset + offsetof (file_t, cur_record)); + fprintf (dumpfile, "*first_entry (First entry in current record)\n"); dump_ods2_dirent_t (p->first_entry, offset + offsetof (file_t, first_entry)); + fprintf (dumpfile, "*cur_entry (Current entry in current record)\n"); dump_ods2_dirent_t (p->cur_entry, offset + offsetof (file_t, cur_entry)); + fprintf (dumpfile, "*last_entry (Aftet last entry in current record)\n"); dump_ods2_dirent_t (p->last_entry, offset + offsetof (file_t, last_entry)); +} + +/*----------------------------------------------*/ + +void dump_volume_t (const volume_t *p, int offset) +{ + if (!debug_mode) + return; + if (p == 0) return; + fprintf (dumpfile, "volume_t:\n"); + fprintf (dumpfile, "cache (LBN cache to cdrom device) %p\n", p->cache); + fprintf (dumpfile, "home (Home block) %p ods2_home_block_t\n", &(p->home)); + fprintf (dumpfile, "*volname (Volume name (mallocated)) %s\n", p->volname); + fprintf (dumpfile, "*indexf (Description of INDEXF.SYS) %p file_t\n", p->indexf); +} diff -urN ../vmscd-1.0/dumpvolume.h ./dumpvolume.h --- ../vmscd-1.0/dumpvolume.h 1970-01-01 01:00:00.000000000 +0100 +++ ./dumpvolume.h 2001-07-18 10:17:37.000000000 +0200 @@ -0,0 +1,6 @@ +/* dumpvolume.h */ + +extern void dump_retrieval_t (const retrieval_t *p, int offset); +extern void dump_fid_t (const fid_t *p, int offset); +extern void dump_file_t (const file_t *p, int offset); +extern void dump_volume_t (const volume_t *p, int offset); diff -urN ../vmscd-1.0/Makefile ./Makefile --- ../vmscd-1.0/Makefile 2000-03-11 18:40:11.000000000 +0100 +++ ./Makefile 1970-01-01 01:00:00.000000000 +0100 @@ -1,87 +0,0 @@ -################################################################################ -# -# Copyright (c) 1999 by Thierry Lelegard -# -# This software is covered by the "GNU GENERAL PUBLIC LICENSE" (GPL), -# version 2, June 1991. See the file named COPYING for details. -# -# Project: VMSCD - OpenVMS CD-ROM Utility for Linux -# File: Makefile -# Author: Thierry Lelegard -# -# -# Abstract -# -------- -# This makefile rebuilds the VMSCD utilities. -# -# -# Modification History -# -------------------- -# 18 Dec 1999 - Thierry Lelegard (lelegard@club-internet.fr) -# Creation of the file. -# -# -################################################################################ - - -CFLAGS = -Wall -O2 -NPD = --no-print-directory -RPMROOT = tmp-build - -default: execs docs -execs: vmscd -docs: vmscd.ps vmscd.pdf vmscd.html -debug: - @${MAKE} ${MAKEFLAGS} ${NPD} CFLAGS="-Wall -g" execs docs -clean: - -rm -rf *.o *.tmp ${RPMROOT} *~ #*# .#* -cleanall: clean - -rm -f vmscd vmscd.ps vmscd.pdf vmscd.html vmscd-*.tar.gz vmscd-*.rpm - -# The target "install" copies the required files on the operating system -# to install vmscd system-wide. The normal installation process is to -# create the RPM package (target "distrib") and install it. - -install: vmscd - install -m 0755 -d ${ROOT}/usr/bin - install -m 0755 -s vmscd ${ROOT}/usr/bin/vmscd - install -m 0755 -d ${ROOT}/usr/man/man1 - install -m 0644 vmscd.1 ${ROOT}/usr/man/man1/vmscd.1 - -# The target "distrib" creates the distribution kits. -# The version number of the vmscd utility is automatically udated in -# the RPM configuration file vmscd.spec. - -distrib: vmscd - rm -rf ${RPMROOT} - mkdir ${RPMROOT} ${RPMROOT}/vmscd-`./vmscd -V` - sed -e 's/\(^%define version \).*/\1'`./vmscd -V`/ ${RPMROOT}/vmscd-`./vmscd -V`.spec - cp -p `ls | grep -v ${RPMROOT}` ${RPMROOT}/vmscd-`./vmscd -V`/ - (cd ${RPMROOT}/vmscd-`./vmscd -V` && make ${NPD} cleanall) - rm -f vmscd-`./vmscd -V`.tar.gz - (cd ${RPMROOT} && \ - tar cfz ../vmscd-`../vmscd -V`.tar.gz vmscd-`../vmscd -V`) - cp vmscd-`./vmscd -V`.tar.gz /usr/src/redhat/SOURCES - rpm -ba ${RPMROOT}/vmscd-`./vmscd -V`.spec - cp /usr/src/redhat/RPMS/i?86/vmscd-`./vmscd -V`-1.i?86.rpm . - cp /usr/src/redhat/SRPMS/vmscd-`./vmscd -V`-1.src.rpm . - -# The rest of the Makefile describes the dependencies and building -# of the vmscd executable and documentation files. - -cache.o: ods2.h utils.h cache.h -copy.o: ods2.h utils.h cache.h volume.h copy.h -list.o: ods2.h utils.h cache.h volume.h copy.h list.h -utils.o: utils.h -vmscd.o: ods2.h utils.h cache.h volume.h list.h copy.h version.h -volume.o: ods2.h utils.h cache.h volume.h - -vmscd: vmscd.o utils.o cache.o volume.o list.o copy.o - ${CC} ${CFLAGS} -o $@ $+ -lreadline -vmscd.ps: vmscd.1 - groff -man $+ >$@ -vmscd.pdf: vmscd.ps - ps2pdf $+ $@ -vmscd.html: vmscd.1 - man2html $+ >$@ diff -urN ../vmscd-1.0/ods2.h ./ods2.h --- ../vmscd-1.0/ods2.h 1999-12-31 16:04:39.000000000 +0100 +++ ./ods2.h 2001-07-17 14:57:10.000000000 +0200 @@ -46,7 +46,7 @@ #include -#define ODS2_BLOCK_SIZE 512 +#define ODS2_BLOCK_SIZE 512 #define ODS2_MAX_NAME_SIZE 86 #define ODS2_MAX_DIR_DEPTH 64 #define ODS2_MAX_PATH_SIZE ((ODS2_MAX_NAME_SIZE + 1) * ODS2_MAX_DIR_DEPTH) @@ -54,7 +54,7 @@ /* * Integer types (assume little-endian representation, Intel, Alpha) - */ + */ typedef unsigned char uint8; typedef signed char int8; @@ -78,8 +78,8 @@ uint16 fid_w_seq; /* File sequence number */ uint8 fid_b_rvn; /* Byte form of RVN */ uint8 fid_b_nmx; /* File number extension */ -} ods2_fid_t; - +} ods2_fid_t __attribute__ ((packed)); + /* Reserved files numbers (with seq = num) */ #define FID_C_INDEXF 1 /* Index file */ @@ -93,8 +93,8 @@ #define FID_C_BADLOG 9 /* Bad block log file */ #define FID_C_FREFIL 10 /* Free space file */ #define FID_C_MAXRESFIL 10 /* Maximum value of reserved files id */ - - + + /******************************************************************************* * * Module $HM2DEF : Home block definition @@ -134,22 +134,22 @@ uint64 hm2_q_retainmin; /* minimum file retention period */ uint64 hm2_q_retainmax; /* maximum file retention period */ uint64 hm2_q_revdate; /* volume revision date */ - char hm2_r_min_class [20]; /* volume minimum security class */ - char hm2_r_max_class [20]; /* volume maximum security class */ + char hm2_r_min_class[20]; /* volume minimum security class */ + char hm2_r_max_class[20]; /* volume maximum security class */ ods2_fid_t hm2_w_filetab_fid; /* file lookup table FID */ uint16 hm2_w_lowstruclev; /* lowest struclev on volume */ uint16 hm2_w_highstruclev; /* highest struclev on volume */ uint64 hm2_q_copydate __attribute__ ((packed)); /* volume copy date */ - char hm2__fill_1 [302]; /* spare */ + char hm2__fill_1[302]; /* spare */ uint32 hm2_l_serialnum; /* pack serial number */ - char hm2_t_strucname [12]; /* structure (volume set name) */ - char hm2_t_volname [12]; /* volume name */ - char hm2_t_ownername [12]; /* volume owner name */ - char hm2_t_format [12]; /* volume format type */ - char hm2_fill_2 [2]; /* spare */ + char hm2_t_strucname[12]; /* structure (volume set name) */ + char hm2_t_volname[12]; /* volume name */ + char hm2_t_ownername[12]; /* volume owner name */ + char hm2_t_format[12]; /* volume format type */ + char hm2_fill_2[2]; /* spare */ uint16 hm2_w_checksum2; /* second checksum */ -} ods2_home_block_t; - +} ods2_home_block_t __attribute__ ((packed)); + /* Flags values for field hm2_w_volchar */ #define HM2_M_READCHECK 0x01 @@ -158,7 +158,7 @@ #define HM2_M_NOHIGHWATER 0x08 #define HM2_M_CLASS_PROT 0x10 - + /******************************************************************************* * * Module $FATDEF : File attribute definition @@ -167,7 +167,7 @@ */ /* Record format (field fat_v_rtype) */ - + #define FAT_C_UNDEFINED 0 /* undefined record type */ #define FAT_C_FIXED 1 /* fixed record type */ #define FAT_C_VARIABLE 2 /* variable length */ @@ -184,7 +184,7 @@ #define FAT_C_DIRECT 3 /* direct organization */ /* Record attributes area as used by FCS and RMS */ - + typedef struct _fat { unsigned fat_v_rtype : 4; /* record type */ unsigned fat_v_fileorg : 4; /* file organization */ @@ -205,9 +205,9 @@ uint16 fat_w_maxrec; /* maximum record size in bytes */ uint16 fat_w_defext; /* default extend quantity */ uint16 fat_w_gbc; /* global buffer count */ - uint16 fat_w_fill_2 [4]; /* spare */ + uint16 fat_w_fill_2[4]; /* spare */ uint16 fat_w_versions; /* default version limit for directory file */ -} ods2_file_attr_t; +} ods2_file_attr_t __attribute__ ((packed)); /******************************************************************************* @@ -239,13 +239,13 @@ uint8 fh2_b_ru_active; /* If non-zero, has active recov units */ uint16 fh2_fill_3; /* reserved */ uint32 fh2_l_highwater; /* high-water mark in file */ - char fh2_fill_1 [8]; /* reserved */ - char fh2_r_class_prot [20]; /* security classification mask */ - char fh2_fill_2 [402]; /* rest of file header */ + char fh2_fill_1[8]; /* reserved */ + char fh2_r_class_prot[20]; /* security classification mask */ + char fh2_fill_2[402]; /* rest of file header */ uint16 fh2_w_checksum; /* file header checksum */ -} ods2_file_header_t; - - +} ods2_file_header_t __attribute__ ((packed)); + + /* Values for field fh2_l_filechar */ #define FH2_M_WASCONTIG 0x000001 @@ -295,7 +295,6 @@ #define FH2_C_LENGTH 80 /* length of header area */ #define FH2_C_SUBSET0_LENGTH 88 /* length of header area */ #define FH2_C_FULL_LENGTH 108 /* length of full header */ - /******************************************************************************* * @@ -305,17 +304,17 @@ */ typedef struct { - char fi2_t_filename [20]; /* file name, type, and version (ASCII) */ + char fi2_t_filename[20]; /* file name, type, and version (ASCII) */ uint16 fi2_w_revision; /* revision number (binary) */ uint64 fi2_q_credate __attribute__ ((packed)); /* creation date/time */ uint64 fi2_q_revdate __attribute__ ((packed)); /* revision date/time */ uint64 fi2_q_expdate __attribute__ ((packed)); /* expiration date/time */ uint64 fi2_q_bakdate __attribute__ ((packed)); /* backup date/time */ - char fi2_t_filenamext [66]; /* extension file name area */ - char fi2_t_userlabel [80]; /* optional user file label */ -} ods2_file_header_ident_t; + char fi2_t_filenamext[66]; /* extension file name area */ + char fi2_t_userlabel[80]; /* optional user file label */ +} ods2_file_header_ident_t __attribute__ ((packed)); + - /******************************************************************************* * * Module _FM2DEF : File header map area definition @@ -339,7 +338,7 @@ unsigned fm2_v_lbn : 1; /* use LBN of next map pointer */ unsigned fm2_v_rvn : 1; /* place on specified RVN */ unsigned fm2_v_format : 2; -} ods2_fmap_placement_t; +} ods2_fmap_placement_t __attribute__ ((packed)); /* Retrieval pointer format 1 */ @@ -348,15 +347,15 @@ unsigned fm2_v_highlbn : 6; /* high order LBN */ unsigned fm2_v_format : 2; uint16 fm2_w_lowlbn; /* format 1 low order LBN */ -} ods2_fmap1_t; +} ods2_fmap1_t __attribute__ ((packed)); /* Retrieval pointer format 2 */ typedef struct { - unsigned fm2_v_count2 : 14; - unsigned fm2_v_format : 2; + unsigned fm2_v_count2 : 14 __attribute__ ((packed)); + unsigned fm2_v_format : 2 __attribute__ ((packed)); uint32 fm2_l_lbn2 __attribute__ ((packed)); -} ods2_fmap2_t; +} ods2_fmap2_t __attribute__ ((packed)); /* Retrieval pointer format 3 */ @@ -365,8 +364,8 @@ unsigned fm2_v_format : 2; uint16 fm2_w_lowcount; uint32 fm2_l_lbn3; -} ods2_fmap3_t; - +} ods2_fmap3_t __attribute__ ((packed)); + /* Maximum number of retrieval pointers per file header */ #define ODS2_MAX_RP_PER_HEADER \ @@ -374,7 +373,7 @@ offsetof (ods2_file_header_t, fh2_l_highwater)) / \ sizeof (ods2_fmap_placement_t)) - + /******************************************************************************* * * Module $DIRDEF : Directory record definition. @@ -392,7 +391,7 @@ #define DIR_K_LENGTH 6 /* length of directory entry overhead */ #define DIR_C_LENGTH 6 /* length of directory entry overhead */ #define DIR_S_NAME 80 /* maximum length of name string */ - + typedef struct { uint16 dir_w_size; /* size of directory record in bytes */ uint16 dir_w_verlimit; /* maximum number of versions */ @@ -401,8 +400,8 @@ unsigned dir_v_nextrec : 1; /* another record of same name/type follows */ unsigned dir_v_prevrec : 1; /* another record of same name/type precedes */ uint8 dir_b_namecount; /* byte count of name string */ - char dir_t_name [DIR_S_NAME]; /* file name/type */ -} ods2_dir_t; + char dir_t_name[DIR_S_NAME]; /* file name/type */ +} ods2_dir_t __attribute__ ((packed)); /* Directory entry structure */ @@ -412,14 +411,14 @@ typedef struct { uint16 dir_w_version; /* version number */ ods2_fid_t dir_w_fid __attribute__ ((packed)); /* file ID */ -} ods2_dirent_t; +} ods2_dirent_t __attribute__ ((packed)); /* Symbolic name entry definition */ - + typedef struct { uint8 dir_b_linkcount; /* byte count of symbolic link name */ - char dir_t_linkname [1]; /* symbolic link name */ -} ods2_dirlink_t; - + char dir_t_linkname[1]; /* symbolic link name */ +} ods2_dirlink_t __attribute__ ((packed)); + #endif /* ODS2_H_LOADED */ diff -urN ../vmscd-1.0/utils.c ./utils.c --- ../vmscd-1.0/utils.c 2000-01-01 15:27:21.000000000 +0100 +++ ./utils.c 2001-07-18 12:37:44.000000000 +0200 @@ -45,8 +45,9 @@ /* Global variables set by init_utils */ static char appname [255] = ""; -static onoff_t debug_mode = OFF; +onoff_t debug_mode = OFF; +extern FILE *dumpfile; /******************************************************************************* * @@ -138,9 +139,9 @@ { if (debug_mode) { va_list ap; - fprintf (stderr, "#debug# "); + fprintf (dumpfile, "#debug# "); va_start (ap, format); - vfprintf (stderr, format, ap); + vfprintf (dumpfile, format, ap); va_end (ap); } } @@ -160,9 +161,9 @@ if ((err_flags & ERR_SILENT) == 0) { - fprintf (stderr, "%s: ", appname); + fprintf (dumpfile, "%s: ", appname); va_start (ap, format); - vfprintf (stderr, format, ap); + vfprintf (dumpfile, format, ap); va_end (ap); if (err_flags & ERR_ERRNO) { @@ -172,7 +173,10 @@ } if (err_flags & ERR_EXIT) + { + abort(); exit (EXIT_FAILURE); + } errno = err; } @@ -341,3 +345,34 @@ free (buffer); return NULL; } + + +void hexdump (const char *title, const void *data, int size, int offset) +{ + const unsigned char *line, *p, *cur = data, *end = cur + size; + int bytes_per_line = 16; + + if (!debug_mode) + return; + + fprintf (dumpfile, "=== %s ===\n", title); + for (line = cur; line < end; line += bytes_per_line) + { + fprintf (dumpfile, "%08X: ", line - (unsigned char*)data + offset); + for (p = line; p < line + bytes_per_line; p++) + { + if (p >= end) + fprintf (dumpfile, " "); + else + fprintf (dumpfile, "%02X", *p); +/* if ((p - line) % 4 == 0) */ + fprintf (dumpfile, " "); + } + fprintf (dumpfile, " "); + for (p = line; p < line + bytes_per_line; p++) + fputc (isprint (*p) ? *p : '.', dumpfile); + fputc ('\n', dumpfile); + } +} + + diff -urN ../vmscd-1.0/version.h ./version.h --- ../vmscd-1.0/version.h 1999-12-31 14:53:14.000000000 +0100 +++ ./version.h 2001-07-17 17:48:34.000000000 +0200 @@ -31,6 +31,6 @@ #define VERSION_H_LOADED 1 #define VMSCD_MAJOR_VERSION 1 -#define VMSCD_MINOR_VERSION 0 +#define VMSCD_MINOR_VERSION 1 #endif /* VERSION_H_LOADED */ diff -urN ../vmscd-1.0/vmscd.c ./vmscd.c --- ../vmscd-1.0/vmscd.c 2000-01-01 20:33:52.000000000 +0100 +++ ./vmscd.c 2001-07-18 12:53:23.000000000 +0200 @@ -44,6 +44,7 @@ #include "copy.h" #include "version.h" +FILE * dumpfile = 0; /******************************************************************************* * @@ -682,7 +683,9 @@ static int cmd_dump (int argc, char *argv[], vmscd_state_t *state) { - int c, len, start = -1, count = -1, version; + int c, len; + int start = -1; + int count = -1, version; file_t *file; fid_t fid; char data [ODS2_BLOCK_SIZE], name [ODS2_MAX_NAME_SIZE]; @@ -696,10 +699,10 @@ while ((c = getopt (argc, argv, "c:s:")) > 0) { switch (c) { case 'c': - count = atoi (optarg); + count = atol (optarg); break; case 's': - start = atoi (optarg); + start = atol (optarg); break; default: error (0, "invalid option -%c\n", optopt); @@ -1131,8 +1134,8 @@ int display_version_alone = 0; int display_stat = 0; onoff_t debug = OFF; - lbn_t data_cache_size = DEFAULT_DATA_CACHE_SIZE; - lbn_t meta_cache_size = DEFAULT_META_CACHE_SIZE; + int data_cache_size = DEFAULT_DATA_CACHE_SIZE; + int meta_cache_size = DEFAULT_META_CACHE_SIZE; /* * Decode the command line options, before the internal command. @@ -1164,6 +1167,7 @@ break; case 'D': debug = ON; + dumpfile = fopen ("dumpfile.dmp", "w+"); break; case 'V': display_version_alone = 1; @@ -1173,6 +1177,9 @@ } } + if (debug == OFF) + dumpfile = stderr; + /* * If "-v" or "-V", simply display the version and exit. */ @@ -1209,7 +1216,7 @@ * Open the cdrom device and initialize the cache. */ - if ((fd = open (cdrom, 0)) < 0) + if ((fd = open64 (cdrom, 0)) < 0) error (ERR_ERRNO | ERR_EXIT, "cannot open %s\n", cdrom); state.device = cdrom; @@ -1272,5 +1279,7 @@ close_volume (state.vol); delete_cache (state.cache); + if (dumpfile) fclose (dumpfile); + return EXIT_SUCCESS; } diff -urN ../vmscd-1.0/volume.c ./volume.c --- ../vmscd-1.0/volume.c 1999-12-31 16:28:44.000000000 +0100 +++ ./volume.c 2001-07-18 13:13:01.000000000 +0200 @@ -43,10 +43,11 @@ #include #include #include "ods2.h" +#include "dumpods2.h" #include "utils.h" #include "cache.h" #include "volume.h" - +#include "dumpvolume.h" /******************************************************************************* * @@ -189,6 +190,12 @@ const ods2_fmap2_t *fmap2; const ods2_fmap3_t *fmap3; + trace ("sizeof (ods2_fmap1_t) = %d\n", sizeof (ods2_fmap1_t)); + trace ("sizeof (ods2_fmap2_t) = %d\n", sizeof (ods2_fmap2_t)); + trace ("sizeof (ods2_fmap3_t) = %d\n", sizeof (ods2_fmap3_t)); + + dump_ods2_file_header_t (header, 0); + /* Locate the map area inside the file header */ fmap = (const char*) header + 2 * header->fh2_b_mpoffset; @@ -209,16 +216,18 @@ case FM2_C_PLACEMENT: fmap += sizeof (ods2_fmap_placement_t); +/* trace ("volume.get_retrieval: got FM2_C_PLACEMENT\n");*/ break; case FM2_C_FORMAT1: +trace ("fmap1\n"); dump_ods2_fmap1_t (fmap1, (void *)fmap - (void *)header); rp_buffer[rp_index].vbn = first_vbn; rp_buffer[rp_index].lbn = (unsigned int) fmap1->fm2_w_lowlbn + ((unsigned int) fmap1->fm2_v_highlbn << 16); rp_buffer[rp_index].count = fmap1->fm2_b_count1 + 1; - trace ("volume.get_retrieval: got FM2_C_FORMAT1 {%u,%u}\n", + trace ("volume.get_retrieval: got FM2_C_FORMAT1 {0x%08x,%u}\n", rp_buffer[rp_index].lbn, rp_buffer[rp_index].count); first_vbn += rp_buffer[rp_index].count; @@ -227,11 +236,12 @@ break; case FM2_C_FORMAT2: +trace ("fmap2\n"); dump_ods2_fmap2_t (fmap2, (void *)fmap - (void *)header); rp_buffer[rp_index].vbn = first_vbn; rp_buffer[rp_index].lbn = fmap2->fm2_l_lbn2; rp_buffer[rp_index].count = fmap2->fm2_v_count2 + 1; - trace ("volume.get_retrieval: got FM2_C_FORMAT2 {%u,%u}\n", + trace ("volume.get_retrieval: got FM2_C_FORMAT2 {0x%08x,%u}\n", rp_buffer[rp_index].lbn, rp_buffer[rp_index].count); first_vbn += rp_buffer[rp_index].count; @@ -240,19 +250,23 @@ break; case FM2_C_FORMAT3: +trace ("fmap3\n"); dump_ods2_fmap3_t (fmap3, (void *)fmap - (void *)header); rp_buffer[rp_index].vbn = first_vbn; rp_buffer[rp_index].lbn = fmap3->fm2_l_lbn3; rp_buffer[rp_index].count = (unsigned int) fmap3->fm2_w_lowcount + ((unsigned int) fmap3->fm2_v_count2 << 16) + 1; - trace ("volume.get_retrieval: got FM2_C_FORMAT3 {%u,%u}\n", + trace ("volume.get_retrieval: got FM2_C_FORMAT3 {0x%08x,%u}\n", rp_buffer[rp_index].lbn, rp_buffer[rp_index].count); first_vbn += rp_buffer[rp_index].count; rp_index++; fmap += sizeof (ods2_fmap3_t); break; + default: + trace ("volume.get_retrieval: got UNKNOWN %04x\n", fmap1->fm2_v_format); + break; } } @@ -362,11 +376,13 @@ if (fid->number == FID_C_INDEXF) { lbn = vol->home.hm2_l_ibmaplbn + vol->home.hm2_w_ibmapsize; + trace ("this is INDEXF.SYS, lbn %d\n", lbn); status = read_lbn (err_flags, vol->cache, lbn, 1, header, LBN_META); } else { vbn = vol->home.hm2_w_ibmapvbn + vol->home.hm2_w_ibmapsize + fid->number - 1; + trace ("this is not INDEXF.SYS, vbn %d\n", vbn); status = read_vbn (err_flags, vol->indexf, vbn, 1, header); } @@ -476,9 +492,11 @@ /* Get more retrieval pointers */ rp_count = get_retrieval (&header, vbn, rp, ODS2_MAX_RP_PER_HEADER); + vbn = rp[rp_count-1].vbn + rp[rp_count-1].count; + trace ("volume.open_file: rp_count %d, vbn %d\n", rp_count, vbn); map = utmalloc ((file->map_count + rp_count) * sizeof (retrieval_t)); memcpy (map + file->map_count, rp, rp_count * sizeof (retrieval_t)); - + if (file->map != NULL) { memcpy (map, file->map, file->map_count * sizeof (retrieval_t)); free (file->map); @@ -863,8 +881,6 @@ vbn_t last_vbn = 0; lbn_usage_t lbn_usage; - trace ("volume.read_vbn: VBN %d, %d blocks\n", vbn, vbn_count); - /* Locate the first VBN in the retrieval pointers */ for (rp = 0; rp < file->map_count && lbn == 0; rp++) { @@ -872,13 +888,18 @@ last_vbn = file->map[rp].vbn + file->map[rp].count - 1; /* Check if the VBN is in this extent */ if (file->map[rp].vbn <= vbn && vbn <= last_vbn) + { lbn = file->map[rp].lbn + vbn - file->map[rp].vbn; + } } /* Check if the VBN was found */ if (lbn == 0) { - error (err_flags, "VBN %d not found in file\n", vbn); + trace ("volume.read_vbn: VBN %d, %d blocks, map_count %d\n", vbn, vbn_count, file->map_count); + trace ("volume.read_vbn: last_vbn %d, rp %d\n", last_vbn, rp); + dump_file_t (file, 0); + error (err_flags, "%s: VBN %d not found in file\n", file->name, vbn); return -1; } @@ -907,16 +928,17 @@ /* Prepare to read in the next extent if more blocks are needed */ if ((vbn_count -= vbn_subcount) > 0) { + trace ("vbn_count %d, vbn_subcount %d\n", vbn_count, vbn_subcount); buffer = (char*)buffer + vbn_subcount * ODS2_BLOCK_SIZE; vbn += vbn_subcount; if (++rp >= file->map_count) { - error (err_flags, "attempt to read after end of file " - "(VBN %d)\n", vbn); + error (err_flags, "%s: attempt to read after end of file" + "(VBN %d)\n", file->name, vbn); return -1; } /* Check if there is no hole in the file */ if (file->map[rp].vbn != vbn) { - error (err_flags, "VBN %d is in a hole\n", vbn); + error (err_flags, "%s: VBN %d is (!= %d @ rp %d) in a hole\n", file->name, vbn, file->map[rp].vbn, rp); return -1; } /* Compute starting LBN and last VBN in next extent */