summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/imgtool/modules/ti990hd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/imgtool/modules/ti990hd.cpp')
-rw-r--r--src/tools/imgtool/modules/ti990hd.cpp145
1 files changed, 65 insertions, 80 deletions
diff --git a/src/tools/imgtool/modules/ti990hd.cpp b/src/tools/imgtool/modules/ti990hd.cpp
index 8edaeaf3fb6..a78589ff5aa 100644
--- a/src/tools/imgtool/modules/ti990hd.cpp
+++ b/src/tools/imgtool/modules/ti990hd.cpp
@@ -8,12 +8,15 @@
Raphael Nabet, 2003
*/
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <limits.h>
#include "imgtool.h"
+#include "opresolv.h"
+
+#include <climits>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
/* Max sector length is bytes. Generally 256, except for a few older disk
units which use 288-byte-long sectors, and SCSI units which generally use
standard 512-byte-long sectors. */
@@ -96,7 +99,7 @@ enum
Track 1 Sector 0 through N-2: optional disk program image loader
Track 1 Sector N-1: copy of Track 0 Sector 0
Track 1 Sector N: copy of Track 0 Sector 1
- Last cylinder has disagnostic information (reported as .S$DIAG)
+ Last cylinder has diagnostic information (reported as .S$DIAG)
Remaining sectors are used for fdr and data.
*/
@@ -214,7 +217,7 @@ struct ti990_fdr
UINT16BE hkc; /* hask key count: the number of file descriptor records that are present in the directory that hashed to this record number */
UINT16BE hkv; /* hask key value: the result of the hash algorithm for the file name actually covered in this record */
char fnm[8]; /* file name */
- uint8_t rsv[2]; /* reserved */
+ uint8_t rsv[2]; /* reserved */
UINT16BE fl1; /* flags word 1 */
UINT16BE flg; /* flags word 2 */
UINT16BE prs; /* physical record size */
@@ -227,31 +230,31 @@ struct ti990_fdr
UINT32BE eom; /* end of medium record number */
UINT32BE bkm; /* end of medium block number */
UINT16BE ofm; /* end of medium offset / */
- /* prelog number for KIF */
+ /* prelog number for KIF */
UINT32BE fbq; /* free block queue head */
UINT16BE btr; /* B-tree roots block # */
UINT32BE ebq; /* empty block queue head */
UINT16BE kdr; /* key descriptions record # */
- uint8_t ud[6]; /* last update date */
- uint8_t cd[6]; /* creation date */
- uint8_t apb; /* ADU's per block */
- uint8_t bpa; /* blocks per ADU */
- UINT16BE mrs; /* minimumu KIF record size */
- uint8_t sat[64]; /* secondary allocation table: 16 2-word entries. The first word of an entry contains the size, in ADUs, of the secondary allocation. The second word contains the starting ADU of the allocation. */
+ uint8_t ud[6]; /* last update date */
+ uint8_t cd[6]; /* creation date */
+ uint8_t apb; /* ADU's per block */
+ uint8_t bpa; /* blocks per ADU */
+ UINT16BE mrs; /* minimum KIF record size */
+ uint8_t sat[64]; /* secondary allocation table: 16 2-word entries. The first word of an entry contains the size, in ADUs, of the secondary allocation. The second word contains the starting ADU of the allocation. */
/* bytes >86 to >100 are optional */
- uint8_t res[10]; /* reserved: seem to be actually meaningful (at least under DX10 3.6.x) */
+ uint8_t res[10]; /* reserved: seem to be actually meaningful (at least under DX10 3.6.x) */
char uid[8]; /* user id of file creator */
UINT16BE psa; /* public security attribute */
ti990_ace ace[9]; /* 9 access control entries */
- uint8_t fil[2]; /* not used */
+ uint8_t fil[2]; /* not used */
};
/*
ADR record: variant of FDR for Aliases
The fields marked here with *** are in the ADR template to maintain
- compatability with the FDR template.
+ compatibility with the FDR template.
*/
struct ti990_adr
{
@@ -284,19 +287,19 @@ struct ti990_cdr
UINT16BE fill00; /* reserved */
UINT16BE fill01; /* reserved */
UINT16BE fdf; /* flags (same as fdr.flg) */
- uint8_t flg; /* channel flzgs */
- uint8_t iid; /* owner task installed ID */
- uint8_t typ; /* default resource type */
- uint8_t tf; /* resource type flags */
+ uint8_t flg; /* channel flzgs */
+ uint8_t iid; /* owner task installed ID */
+ uint8_t typ; /* default resource type */
+ uint8_t tf; /* resource type flags */
UINT16BE mxl; /* maximum message length */
- uint8_t fill04[6]; /* reserved (and, no, I don't know where fill02 and fill03 have gone) */
+ uint8_t fill04[6]; /* reserved (and, no, I don't know where fill02 and fill03 have gone) */
UINT16BE rna; /* record number of next CDR or ADR */
UINT16BE raf; /* record # of actual FDR */
- uint8_t fill05[110]; /* reserved */
+ uint8_t fill05[110]; /* reserved */
char uid[8]; /* user ID of channel creator */
UINT16BE psa; /* public security attribute */
- uint8_t scg[94]; /* "SDT with 9 control groups" (whatever it means - and, no, 94 is not dividable by 9) */
- uint8_t fill06[8]; /* reserved */
+ uint8_t scg[94]; /* "SDT with 9 control groups" (whatever it means - and, no, 94 is not dividable by 9) */
+ uint8_t fill06[8]; /* reserved */
};
/*
@@ -321,19 +324,18 @@ union directory_entry
*/
struct tifile_header
{
- char tifiles[8]; /* always '\7TIFILES' */
- uint8_t secsused_MSB; /* file length in sectors (big-endian) */
- uint8_t secsused_LSB;
- uint8_t flags; /* see enum above */
- uint8_t recspersec; /* records per sector */
- uint8_t eof; /* current position of eof in last sector (0->255)*/
- uint8_t reclen; /* bytes per record ([1,255] 0->256) */
- uint8_t fixrecs_MSB; /* file length in records (big-endian) */
- uint8_t fixrecs_LSB;
- uint8_t res[128-16]; /* reserved */
+ char tifiles[8]; /* always '\7TIFILES' */
+ uint8_t secsused_MSB; /* file length in sectors (big-endian) */
+ uint8_t secsused_LSB;
+ uint8_t flags; /* see enum above */
+ uint8_t recspersec; /* records per sector */
+ uint8_t eof; /* current position of eof in last sector (0->255)*/
+ uint8_t reclen; /* bytes per record ([1,255] 0->256) */
+ uint8_t fixrecs_MSB; /* file length in records (big-endian) */
+ uint8_t fixrecs_LSB;
+ uint8_t res[128-16]; /* reserved */
};
-
/*
catalog entry (used for in-memory catalog)
*/
@@ -398,11 +400,9 @@ static imgtoolerr_t ti990_image_beginenum(imgtool::directory &enumeration, const
static imgtoolerr_t ti990_image_nextenum(imgtool::directory &enumeration, imgtool_dirent &ent);
static void ti990_image_closeenum(imgtool::directory &enumeration);
static imgtoolerr_t ti990_image_freespace(imgtool::partition &partition, uint64_t *size);
-#ifdef UNUSED_FUNCTION
-static imgtoolerr_t ti990_image_readfile(imgtool::partition &partition, const char *fpath, imgtool::stream *destf);
-static imgtoolerr_t ti990_image_writefile(imgtool::partition &partition, const char *fpath, imgtool::stream *sourcef, util::option_resolution *writeoptions);
-static imgtoolerr_t ti990_image_deletefile(imgtool::partition &partition, const char *fpath);
-#endif
+[[maybe_unused]] static imgtoolerr_t ti990_image_readfile(imgtool::partition &partition, const char *fpath, imgtool::stream *destf);
+[[maybe_unused]] static imgtoolerr_t ti990_image_writefile(imgtool::partition &partition, const char *fpath, imgtool::stream *sourcef, util::option_resolution *writeoptions);
+[[maybe_unused]] static imgtoolerr_t ti990_image_deletefile(imgtool::partition &partition, const char *fpath);
static imgtoolerr_t ti990_image_create(imgtool::image &image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions);
enum
@@ -452,11 +452,10 @@ void ti990_get_info(const imgtool_class *imgclass, uint32_t state, union imgtool
}
}
-#ifdef UNUSED_FUNCTION
/*
Convert a C string to a 8-character file name (padded with spaces if necessary)
*/
-static void str_to_fname(char dst[8], const char *src)
+[[maybe_unused]] static void str_to_fname(char dst[8], const char *src)
{
int i;
@@ -478,7 +477,6 @@ static void str_to_fname(char dst[8], const char *src)
i++;
}
}
-#endif
/*
Convert a 8-character file name to a C string (removing trailing spaces if necessary)
@@ -555,7 +553,6 @@ static int read_sector_physical_len(imgtool::stream &file_handle, const ti990_ph
return 0;
}
-#ifdef UNUSED_FUNCTION
/*
Read one sector from a disk image
@@ -564,11 +561,10 @@ static int read_sector_physical_len(imgtool::stream &file_handle, const ti990_ph
geometry: disk geometry (sectors per track, tracks per side, sides)
dest: pointer to a destination buffer of geometry->bytes_per_sector bytes
*/
-static int read_sector_physical(imgtool::stream *file_handle, const ti990_phys_sec_address *address, const ti990_geometry *geometry, void *dest)
+[[maybe_unused]] static int read_sector_physical(imgtool::stream &file_handle, const ti990_phys_sec_address *address, const ti990_geometry *geometry, void *dest)
{
return read_sector_physical_len(file_handle, address, geometry, dest, geometry->bytes_per_sector);
}
-#endif
/*
Write one sector to a disk image
@@ -606,7 +602,6 @@ static int write_sector_physical_len(imgtool::stream &file_handle, const ti990_p
return 0;
}
-#ifdef UNUSED_FUNCTION
/*
Write one sector to a disk image
@@ -615,11 +610,10 @@ static int write_sector_physical_len(imgtool::stream &file_handle, const ti990_p
geometry: disk geometry (sectors per track, tracks per side, sides)
dest: pointer to a source buffer of geometry->bytes_per_sector bytes
*/
-static int write_sector_physical(imgtool::stream *file_handle, const ti990_phys_sec_address *address, const ti990_geometry *geometry, const void *src)
+[[maybe_unused]] static int write_sector_physical(imgtool::stream &file_handle, const ti990_phys_sec_address *address, const ti990_geometry *geometry, const void *src)
{
return write_sector_physical_len(file_handle, address, geometry, src, geometry->bytes_per_sector);
}
-#endif
/*
Convert logical sector address to physical sector address
@@ -651,7 +645,6 @@ static int read_sector_logical_len(imgtool::stream &file_handle, int secnum, con
return read_sector_physical_len(file_handle, &address, geometry, dest, len);
}
-#ifdef UNUSED_FUNCTION
/*
Read one sector from a disk image
@@ -660,11 +653,10 @@ static int read_sector_logical_len(imgtool::stream &file_handle, int secnum, con
geometry: disk geometry (sectors per track, tracks per side, sides)
dest: pointer to a destination buffer of geometry->bytes_per_sector bytes
*/
-static int read_sector_logical(imgtool::stream *file_handle, int secnum, const ti990_geometry *geometry, void *dest)
+[[maybe_unused]] static int read_sector_logical(imgtool::stream &file_handle, int secnum, const ti990_geometry *geometry, void *dest)
{
return read_sector_logical_len(file_handle, secnum, geometry, dest, geometry->bytes_per_sector);
}
-#endif
/*
Write one sector to a disk image
@@ -703,7 +695,6 @@ static int write_sector_logical(imgtool::stream &file_handle, int secnum, const
#pragma mark CATALOG FILE ROUTINES
#endif
-#ifdef UNUSED_FUNCTION
/*
Find the catalog entry and fdr record associated with a file name
@@ -715,7 +706,7 @@ static int write_sector_logical(imgtool::stream &file_handle, int secnum, const
out_parent_fdr_secnum: on output, sector offset of the fdr for the parent
directory fdr (-1 if root) (may be NULL)
*/
-static int find_fdr(ti990_image *image, const char fpath[MAX_PATH_LEN+1], int *catalog_index, int *out_fdr_secnum, int *out_parent_fdr_secnum)
+static imgtoolerr_t find_fdr(ti990_image *image, const char fpath[MAX_PATH_LEN+1], int *catalog_index, int *out_fdr_secnum, int *out_parent_fdr_secnum)
{
int fdr_secnum = -1, parent_fdr_secnum;
int i;
@@ -737,7 +728,7 @@ static int find_fdr(ti990_image *image, const char fpath[MAX_PATH_LEN+1], int *c
do
{
/* read directory header */
- reply = read_sector_logical_len(image->file_handle, base, & image->geometry, &dor, sizeof(dor));
+ reply = read_sector_logical_len(*image->file_handle, base, & image->geometry, &dor, sizeof(dor));
if (reply)
return IMGTOOLERR_READERROR;
@@ -765,7 +756,7 @@ static int find_fdr(ti990_image *image, const char fpath[MAX_PATH_LEN+1], int *c
i = hash_key;
while (1)
{
- reply = read_sector_logical_len(image->file_handle, base + i, & image->geometry,
+ reply = read_sector_logical_len(*image->file_handle, base + i, & image->geometry,
& xdr, 0x86);
if (reply)
return IMGTOOLERR_READERROR;
@@ -800,7 +791,7 @@ static int find_fdr(ti990_image *image, const char fpath[MAX_PATH_LEN+1], int *c
if (flag & fdr_flg_ali)
{
/* read original fdr */
- reply = read_sector_logical_len(image->file_handle, base + get_UINT16BE(xdr.adr.raf),
+ reply = read_sector_logical_len(*image->file_handle, base + get_UINT16BE(xdr.adr.raf),
& image->geometry, & xdr, 0x86);
flag = get_UINT16BE(xdr.fdr.flg);
@@ -835,9 +826,8 @@ static int find_fdr(ti990_image *image, const char fpath[MAX_PATH_LEN+1], int *c
if (out_parent_fdr_secnum)
*out_parent_fdr_secnum = parent_fdr_secnum;
- return 0;
+ return IMGTOOLERR_SUCCESS;
}
-#endif
#if 0
/*
@@ -1251,7 +1241,7 @@ static imgtoolerr_t ti990_image_nextenum(imgtool::directory &enumeration, imgtoo
else
{
#if 0
- fname_to_str(ent.filename, iter->xdr[iter->level].fdr.fnm, ARRAY_LENGTH(ent.filename));
+ fname_to_str(ent.filename, iter->xdr[iter->level].fdr.fnm, std::size(ent.filename));
#else
{
int i;
@@ -1261,11 +1251,11 @@ static imgtoolerr_t ti990_image_nextenum(imgtool::directory &enumeration, imgtoo
for (i=0; i<iter->level; i++)
{
fname_to_str(buf, iter->xdr[i].fdr.fnm, 9);
- strncat(ent.filename, buf, ARRAY_LENGTH(ent.filename) - 1);
- strncat(ent.filename, ".", ARRAY_LENGTH(ent.filename) - 1);
+ strncat(ent.filename, buf, std::size(ent.filename) - 1);
+ strncat(ent.filename, ".", std::size(ent.filename) - 1);
}
fname_to_str(buf, iter->xdr[iter->level].fdr.fnm, 9);
- strncat(ent.filename, buf, ARRAY_LENGTH(ent.filename) - 1);
+ strncat(ent.filename, buf, std::size(ent.filename) - 1);
}
#endif
@@ -1273,7 +1263,7 @@ static imgtoolerr_t ti990_image_nextenum(imgtool::directory &enumeration, imgtoo
flag = get_UINT16BE(iter->xdr[iter->level].fdr.flg);
if (flag & fdr_flg_cdr)
{
- snprintf(ent.attr, ARRAY_LENGTH(ent.attr), "CHANNEL");
+ snprintf(ent.attr, std::size(ent.attr), "CHANNEL");
ent.filesize = 0;
}
@@ -1291,7 +1281,7 @@ static imgtoolerr_t ti990_image_nextenum(imgtool::directory &enumeration, imgtoo
fname_to_str(buf, target_fdr.fnm, 9);
- snprintf(ent.attr, ARRAY_LENGTH(ent.attr), "ALIAS OF %s", buf);
+ snprintf(ent.attr, std::size(ent.attr), "ALIAS OF %s", buf);
ent.filesize = 0;
}
@@ -1341,7 +1331,7 @@ static imgtoolerr_t ti990_image_nextenum(imgtool::directory &enumeration, imgtoo
}
break;
}
- snprintf(ent.attr, ARRAY_LENGTH(ent.attr),
+ snprintf(ent.attr, std::size(ent.attr),
"%s %c %s%s%s%s%s", fmt, (flag & fdr_flg_all) ? 'N' : 'C', type,
(flag & fdr_flg_blb) ? "" : " BLK",
(flag & fdr_flg_tmp) ? " TMP" : "",
@@ -1455,14 +1445,12 @@ static imgtoolerr_t ti990_image_freespace(imgtool::partition &partition, uint64_
return IMGTOOLERR_SUCCESS;
}
-#ifdef UNUSED_FUNCTION
/*
Extract a file from a ti990_image.
*/
static imgtoolerr_t ti990_image_readfile(imgtool::partition &partition, const char *fpath, imgtool::stream *destf)
{
- imgtool::image *img = &partition->image();
- ti990_image *image = get_ti990_image(img);
+ ti990_image *image = get_ti990_image(partition.image());
int catalog_index, fdr_secnum, parent_fdr_secnum;
imgtoolerr_t reply;
@@ -1473,7 +1461,7 @@ static imgtoolerr_t ti990_image_readfile(imgtool::partition &partition, const ch
/* ... */
- return 0;
+ return IMGTOOLERR_SUCCESS;
#if 0
ti99_image *image = (ti99_image*) img;
@@ -1549,7 +1537,7 @@ static imgtoolerr_t ti990_image_readfile(imgtool::partition &partition, const ch
lnks_index++;
}
- return 0;
+ return IMGTOOLERR_SUCCESS;
#endif
}
@@ -1558,8 +1546,7 @@ static imgtoolerr_t ti990_image_readfile(imgtool::partition &partition, const ch
*/
static imgtoolerr_t ti990_image_writefile(imgtool::partition &partition, const char *fpath, imgtool::stream *sourcef, util::option_resolution *writeoptions)
{
- imgtool::image *img = &partition->image();
- ti990_image *image = get_ti990_image(img);
+ ti990_image *image = get_ti990_image(partition.image());
int catalog_index, fdr_secnum, parent_fdr_secnum;
imgtoolerr_t reply;
@@ -1571,7 +1558,7 @@ static imgtoolerr_t ti990_image_writefile(imgtool::partition &partition, const c
/* ... */
- return 0;
+ return IMGTOOLERR_SUCCESS;
#if 0
ti99_image *image = (ti99_image*) img;
@@ -1673,7 +1660,7 @@ static imgtoolerr_t ti990_image_writefile(imgtool::partition &partition, const c
if (write_sector_logical(image->file_handle, 0, & image->geometry, &image->sec0))
return IMGTOOLERR_WRITEERROR;
- return 0;
+ return IMGTOOLERR_SUCCESS;
#endif
}
@@ -1682,8 +1669,7 @@ static imgtoolerr_t ti990_image_writefile(imgtool::partition &partition, const c
*/
static imgtoolerr_t ti990_image_deletefile(imgtool::partition &partition, const char *fpath)
{
- imgtool::image *img = &partition->image();
- ti990_image *image = get_ti990_image(img);
+ ti990_image *image = get_ti990_image(partition.image());
int catalog_index, fdr_secnum, parent_fdr_secnum;
imgtoolerr_t reply;
@@ -1694,7 +1680,7 @@ static imgtoolerr_t ti990_image_deletefile(imgtool::partition &partition, const
/* ... */
- return 0;
+ return IMGTOOLERR_SUCCESS;
#if 0
ti99_image *image = (ti99_image*) img;
@@ -1762,10 +1748,9 @@ static imgtoolerr_t ti990_image_deletefile(imgtool::partition &partition, const
if (write_sector_logical(image->file_handle, 0, & image->geometry, &image->sec0))
return IMGTOOLERR_WRITEERROR;
- return 0;
+ return IMGTOOLERR_SUCCESS;
#endif
}
-#endif
/*
Create a blank ti990_image.