diff --git a/converters/fsio/dos11.c b/converters/fsio/dos11.c index 60581e3..96e44bb 100644 --- a/converters/fsio/dos11.c +++ b/converters/fsio/dos11.c @@ -40,45 +40,8 @@ #include "fsio.h" -/* - * Tables for the bitmap allocator - */ -uint16_t bits[16] = { - 0000001, 0000002, 0000004, 0000010, 0000020, 0000040, 0000100, 0000200, - 0000400, 0001000, 0002000, 0004000, 0010000, 0020000, 0040000, 0100000 -}; - -uint16_t lowbits[16] = { - 0000001, 0000003, 0000007, 0000017, 0000037, 0000077, 0000177, 0000377, - 0000777, 0001777, 0003777, 0007777, 0017777, 0037777, 0077777, 0177777 -}; - -uint16_t highbits[16] = { - 0100000, 0140000, 0160000, 0170000, 0174000, 0176000, 0177000, 0177400, - 0177600, 0177700, 0177740, 0177760, 0177770, 0177774, 0177776, 0177777 -}; - -/* - * Table of # of zeroes in each bye value. - */ -uint8_t zeroes[256] = { - 8, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4, - 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, - 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, - 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, - 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, - 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, - 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, - 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, - 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, - 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, - 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, - 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, - 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, - 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, - 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, - 4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0, -}; +extern uint16_t bits[], lowbits[], highbits[]; +extern uint8_t zeroes[]; /* * Table of "set" commands @@ -1277,10 +1240,11 @@ int dos11ReadBlock( void *buf ) { - void *buffer = buf == NULL ? mount->dos11data.buf : buf; + struct DOS11data *data = &mount->dos11data; + void *buffer = buf == NULL ? data->buf : buf; int status; - if (block >= mount->dos11data.blocks) { + if (block >= data->blocks) { ERROR("Attempt to read block (%u) outside file system \"%s\"\n", block, mount->name); return 0; @@ -1309,7 +1273,7 @@ int dos11ReadBlock( * * mount - pointer to a mounted file system descriptor * block - logical block # in the range 0 - N - * buf - buffer to receive data, if NULL use the mount + * buf - buffer to containing data, if NULL use the mount * point specific buffer * * Outputs: @@ -1327,10 +1291,11 @@ int dos11WriteBlock( void *buf ) { - void *buffer = buf == NULL ? mount->dos11data.buf : buf; + struct DOS11data *data = &mount->dos11data; + void *buffer = buf == NULL ? data->buf : buf; int status; - if (block >= mount->dos11data.blocks) { + if (block >= data->blocks) { ERROR("Attempt to write block (%u) outside file system \"%s\"\n", block, mount->name); return 0; @@ -2142,10 +2107,11 @@ static void *dos11OpenFileR( char *fname ) { + struct DOS11data *data = &mount->dos11data; struct dos11OpenFile *file; struct dos11FileSpec spec; - uint8_t user = mount->dos11data.user; - uint8_t group = mount->dos11data.group; + uint8_t user = data->user; + uint8_t group = data->group; if (dos11ParseFilespec(fname, &spec, user, group, DOS11_M_NONE) == 0) { fprintf(stderr, "Failed to parse filename \"%s\"\n", fname); @@ -2200,11 +2166,12 @@ static void *dos11OpenFileW( off_t size ) { + struct DOS11data *data = &mount->dos11data; struct dos11OpenFile *file; struct dos11FileSpec spec; unsigned long contig = (size + mount->blocksz - 1) / mount->blocksz; - uint8_t user = mount->dos11data.user; - uint8_t group = mount->dos11data.group; + uint8_t user = data->user; + uint8_t group = data->group; if (SWISSET('c') && (contig == 0)) { fprintf(stderr,"DOS-11 contiguous files must be at least 1 block\n"); diff --git a/converters/fsio/fsio-rt11.1 b/converters/fsio/fsio-rt11.1 index 923d9c7..2dce4a0 100644 --- a/converters/fsio/fsio-rt11.1 +++ b/converters/fsio/fsio-rt11.1 @@ -49,6 +49,12 @@ depending on the type of device specified: .br .RS .TP +\fIrk05\fP \- RK05 image (2.5MB, 4800 blocks) +.br +.TP +\fIrl01\fP \- RL01 image (5MB, 10240 blocks) +.br +.TP \fIrl02\fP \- RL02 image (10MB, 20480 blocks) .br .TP diff --git a/converters/fsio/fsio.c b/converters/fsio/fsio.c index 116a5c1..57017a4 100644 --- a/converters/fsio/fsio.c +++ b/converters/fsio/fsio.c @@ -356,6 +356,46 @@ struct mountedFS *mounts; struct FSdef *fileSystems = NULL; +/* + * Tables for use with bitmap allocators + */ +uint16_t bits[16] = { + 0000001, 0000002, 0000004, 0000010, 0000020, 0000040, 0000100, 0000200, + 0000400, 0001000, 0002000, 0004000, 0010000, 0020000, 0040000, 0100000 +}; + +uint16_t lowbits[16] = { + 0000001, 0000003, 0000007, 0000017, 0000037, 0000077, 0000177, 0000377, + 0000777, 0001777, 0003777, 0007777, 0017777, 0037777, 0077777, 0177777 +}; + +uint16_t highbits[16] = { + 0100000, 0140000, 0160000, 0170000, 0174000, 0176000, 0177000, 0177400, + 0177600, 0177700, 0177740, 0177760, 0177770, 0177774, 0177776, 0177777 +}; + +/* + * Table of # of zeroes in each byte value. + */ +uint8_t zeroes[256] = { + 8, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4, + 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, + 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, + 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, + 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, + 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, + 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, + 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, + 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, + 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, + 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, + 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, + 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, + 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, + 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, + 4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0, +}; + void FSioCommands(FILE *); static void FSioExecute(char *); @@ -1926,6 +1966,77 @@ void FSioCommands( #endif } +/*++ + * F S i o R e a d B l o b + * + * Read an arbitrary sized blob of binary data from the container file. The + * caller is responsible for making sure that the buffer has sufficient + * space for the blob. + * + * Inputs: + * + * mount - pointer to a mounted file system descriptor + * offset - offset in the container file to start the read + * size - size of the data to read (in bytes) + * buf - pointer to the buffer to receive the data + * + * Outputs: + * + * The buffer will be overwrittn by the contents of the blob from the + * container file system + * + * Returns: + * + * 1 if read was successful, 0 otherwise + * + --*/ +int FSioReadBlob( + struct mountedFS *mount, + off_t offset, + unsigned int size, + void *buf +) +{ + if (fseeko(mount->container, offset, SEEK_SET) == 0) + return fread(buf, size, 1, mount->container); + + return 0; +} + +/*++ + * F S i o W r i t e B l o b + * + * Write an arbitrary sized blob of binary to from the container file. + * + * Inputs: + * + * mount - pointer to a mounted file system descriptor + * offset - offset in the container file to start the write + * size - size of the data to write (in bytes) + * buf - pointer to the buffer with the data + * + * Outputs: + * + * None + * + * Returns: + * + * 1 if write was successful, 0 otherwise + * + --*/ +int FSioWriteBlob( + struct mountedFS *mount, + off_t offset, + unsigned int size, + void *buf +) +{ + if (fseeko(mount->container, offset, SEEK_SET) == 0) + return fwrite(buf, size, 1, mount->container); + + return 0; +} + /*++ * F S i o R e a d B l o c k * @@ -2049,7 +2160,7 @@ int FSioReadSector( * mount - pointer to a mounted file system descriptor * sector - logical sector # in the range 0 - N * size - size of each sector (in bytes) - * buf - pointer to the buffer to receive the data + * buf - pointer to the buffer with the data * * Outputs: * @@ -2057,7 +2168,7 @@ int FSioReadSector( * * Returns: * - * 1 if read was successful, 0 otherwise + * 1 if write was successful, 0 otherwise * --*/ int FSioWriteSector( diff --git a/converters/fsio/fsio.h b/converters/fsio/fsio.h index 02c86d5..c9f1d60 100644 --- a/converters/fsio/fsio.h +++ b/converters/fsio/fsio.h @@ -164,6 +164,8 @@ struct mountedFS { #define os8data FSdata._os8 }; +extern int FSioReadBlob(struct mountedFS *, off_t, unsigned int, void *); +extern int FSioWriteBlob(struct mountedFS *, off_t, unsigned int, void *); extern int FSioReadBlock(struct mountedFS *, unsigned int, void *); extern int FSioWriteBlock(struct mountedFS *, unsigned int, void *); extern int FSioReadSector(struct mountedFS *, unsigned int, unsigned int, void *); diff --git a/converters/fsio/os8.c b/converters/fsio/os8.c index bebcf33..8e705b7 100644 --- a/converters/fsio/os8.c +++ b/converters/fsio/os8.c @@ -1023,11 +1023,10 @@ static int os8CheckDirectory( ) { struct OS8data *data = &mount->os8data; - uint16_t i, entrysz, entries, extra, off = OS8_DH_SIZE; + uint16_t i, entrysz, entries, off = OS8_DH_SIZE; entrysz = OS8_DI_SIZE + (-os8SXT(le16toh(data->buf[OS8_DH_EXTRA]))); entries = os8Neg(le16toh(data->buf[OS8_DH_ENTRIES])); - extra = os8Neg(le16toh(data->buf[OS8_DH_EXTRA])); for (i = 0; i < entries; i++) if (os8Word(le16toh(data->buf[off + OS8_DI_FNAME1])) != 0) @@ -1116,11 +1115,11 @@ static int os8FindSpace( } } off += OS8_ED_SIZE; - } else { - blks = os8Neg(le16toh(data->buf[off + extra + OS8_DI_LENGTH])); - off += entrysz; - } - startblk += blks; + } else { + blks = os8Neg(le16toh(data->buf[off + extra + OS8_DI_LENGTH])); + off += entrysz; + } + startblk += blks; } dirblk = os8Word(le16toh(data->buf[OS8_DH_NEXT])); @@ -2991,7 +2990,7 @@ static size_t os8WriteFile( struct FSdef os8FS = { NULL, "os8", - "os8 PDP-8 OS/8 file system\n", + "os8 PDP-8 OS/8 file system (RX01, RX02 or RK05 disks)\n", FS_UNITVALID, OS8_BLOCKSIZE * sizeof(uint16_t), os8Mount, diff --git a/converters/fsio/rt11.c b/converters/fsio/rt11.c index fb105e9..94c1e48 100644 --- a/converters/fsio/rt11.c +++ b/converters/fsio/rt11.c @@ -45,6 +45,8 @@ static struct DiskSize { char *name; /* Disk name */ size_t size; /* Disk size */ } rt11DiskSize[] = { + { "rk05", RT11_RK05SZ * RT11_BLOCKSIZE }, + { "rl01", RT11_RL01SZ * RT11_BLOCKSIZE }, { "rl02", RT11_RL02SZ * RT11_BLOCKSIZE }, { "rx01", RT11_RX0xSZ * RT11_RX01SS }, { "rx02", RT11_RX0xSZ * RT11_RX02SS }, @@ -1483,7 +1485,7 @@ static int partitionType( * * mount - pointer to a mounted file system descriptor * unit - partition number - * blocks - return the actual size of the partition here + * maxblk - return maximum block # of the partition here * first - return first directory segment block # here * * Outputs: @@ -1502,7 +1504,7 @@ static int partitionType( static int validate( struct mountedFS *mount, uint8_t unit, - uint16_t *blocks, + uint16_t *maxblk, uint16_t *first ) { @@ -1561,6 +1563,8 @@ static int validate( ((RT11_DS_SIZE - off) >= entrysz)) { uint16_t status = le16toh(data->buf[off + RT11_DI_STATUS]); + position += le16toh(data->buf[off + RT11_DI_LENGTH]); + if ((status & RT11_E_MPTY) != 0) break; @@ -1571,8 +1575,6 @@ static int validate( if (((position + le16toh(data->buf[off + RT11_DI_LENGTH])) & 0xFFFF) < position) return RT11_NOPART; - position += le16toh(data->buf[off + RT11_DI_LENGTH]); - off += entrysz; } if (position > highest) @@ -1584,7 +1586,7 @@ static int validate( return RT11_NOPART; } while (dsseg != 0); - *blocks = highest; + *maxblk = highest - 1; return type; } @@ -1936,7 +1938,7 @@ static void rt11Umount( * * Returns: * - * Size of the container file in blocks of default file system size + * Size of the container file in bytes. * --*/ static size_t rt11Size(void) @@ -1970,7 +1972,7 @@ static size_t rt11Size(void) * * mount - pointer to a mounted file system descriptor * (not in the mounted file system list) - * size - the size (in blocks) of the file system + * size - the size (in bytes) of the file system * * Outputs: * @@ -2024,7 +2026,8 @@ static int rt11Newfs( /* * Remove possible first track */ - size = ((size * RT11_BLOCKSIZE) - mount->skip) / RT11_BLOCKSIZE; + size = (size - mount->skip) / RT11_BLOCKSIZE; + // size = ((size * RT11_BLOCKSIZE) - mount->skip) / RT11_BLOCKSIZE; /* * Mark partition 0 as valid @@ -2038,14 +2041,15 @@ static int rt11Newfs( /* * Build and write the Home Block. */ - memset(data->buf, 0, RT11_BLOCKSIZE); + memset(&data->buf[0], 0, RT11_BLOCKSIZE); data->buf[RT11_HB_PCS] = htole16(1); data->buf[RT11_HB_FIRST] = htole16(RT11_DSSTART); data->buf[RT11_HB_SYSVER] = htole16(RT11_SYSVER_V05); - strncpy((char *)&data->buf[RT11_HB_VOLID], RT11_VOLID, strlen(RT11_VOLID)); - strncpy((char *)&data->buf[RT11_HB_OWNER], RT11_OWNER, strlen(RT11_OWNER)); - strncpy((char *)&data->buf[RT11_HB_SYSID], RT11_SYSID, strlen(RT11_SYSID)); + + memcpy((char *)&data->buf[RT11_HB_VOLID], RT11_VOLID, strlen(RT11_VOLID)); + memcpy((char *)&data->buf[RT11_HB_OWNER], RT11_OWNER, strlen(RT11_OWNER)); + memcpy((char *)&data->buf[RT11_HB_SYSID], RT11_SYSID, strlen(RT11_SYSID)); for (i = 0; i < 255; i++) checksum += le16toh(data->buf[i]); diff --git a/converters/fsio/rt11.h b/converters/fsio/rt11.h index 6159576..378485a 100644 --- a/converters/fsio/rt11.h +++ b/converters/fsio/rt11.h @@ -191,6 +191,8 @@ #define RT11_MAXPARTSZ 0200000 /* Max partition size */ #define RT11_MINPARTSZ 0000010 /* Min partition size */ +#define RT11_RK05SZ 4800 /* Blocks on an RK05 drive */ +#define RT11_RL01SZ 10240 /* Blocks on an RL01 drive */ #define RT11_RL02SZ 20480 /* Blocks on an RL02 drive */ #define RT11_RX0xSZ 2002 /* Sectors on an RX01/RX02 */