summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-08-06 03:06:22 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-08-06 03:06:22 (GMT)
commitc63e656b5d887c99786787369d3d79b8f55333a0 (patch)
treef1eb3dbc829af60d4be323766884cfef080d2440
parentbf11fa1d0c68e4c19524ca7b5f0ab2f3a3e7a347 (diff)
downloadabcdisk-c63e656b5d887c99786787369d3d79b8f55333a0.zip
abcdisk-c63e656b5d887c99786787369d3d79b8f55333a0.tar.gz
abcdisk-c63e656b5d887c99786787369d3d79b8f55333a0.tar.bz2
abcdisk-c63e656b5d887c99786787369d3d79b8f55333a0.tar.xz
Fix bugs in code restructuring
-rw-r--r--Makefile2
-rw-r--r--abcwrite.c68
2 files changed, 41 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index 186a274..fa25b23 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC = cc
-CFLAGS = -W -Wall -Wno-sign-compare -O2 -g
+CFLAGS = -W -Wall -Wno-sign-compare -O0 -g
LDFLAGS =
ifneq (,$(findstring _NT,$(shell uname -s)))
O = obj
diff --git a/abcwrite.c b/abcwrite.c
index fb08343..7b2a769 100644
--- a/abcwrite.c
+++ b/abcwrite.c
@@ -37,12 +37,12 @@ struct disk {
*/
static void mark_used(struct disk *disk, unsigned int cluster)
{
- disk->bitmap[cluster >> 3] |= (1U << (cluster & 7));
+ disk->bitmap[cluster >> 3] |= (0x80 >> (cluster & 7));
}
static int is_used(struct disk *disk, unsigned int cluster)
{
- return (disk->bitmap[cluster >> 3] >> (cluster & 7)) & 1;
+ return !!(disk->bitmap[cluster >> 3] & (0x80 >> (cluster & 7)));
}
static struct disk *allocate_disk(const struct diskfmt *fmt)
@@ -66,8 +66,8 @@ static struct disk *allocate_disk(const struct diskfmt *fmt)
/* Create empty bitmap */
memset(disk->bitmap, 0, fmt->ntracks);
- memset(disk->bitmap+fmt->ntracks, 0xff, 0xe9-fmt->ntracks);
- memset(disk->bitmap+0xe9, 0x01, 16); /* MFD bitmap */
+ memset(disk->bitmap+fmt->ntracks, 0xff, 239-fmt->ntracks);
+ memset(disk->bitmap+239, 0x01, 16); /* MFD bitmap */
disk->bitmap[0xff] = 0x00;
/* Mark the first 32 sectors used */
@@ -119,8 +119,11 @@ static int get_cluster(struct disk *disk, unsigned int cluster_hint)
}
}
- if (bnc) /* We found *something* at least... */
+ if (bnc) {
+ /* We found *something* at least... */
+ mark_used(disk, best);
return best;
+ }
fprintf(stderr, "%s: output disk full\n", program);
exit(1);
@@ -256,7 +259,7 @@ create_file(struct directory *dir, const char *mangled_name,
int dirs, dirp; /* Directory (sector,position) */
unsigned char *dirent;
int blockno, cleft;
- unsigned char *header, *dp;
+ unsigned char *header, *hdata, *dp;
nblocks = (size+252)/253 + 1;
secperclust = 1 << disk->fmt->cluster_shift;
@@ -283,8 +286,10 @@ create_file(struct directory *dir, const char *mangled_name,
/* Allocate first cluster */
cluster = get_cluster(disk, clusters--);
- if (cluster < 0)
+ if (cluster < 0) {
+ fprintf(stderr, "get_cluster = %d\n", cluster);
return NULL;
+ }
dirent[0] = cluster >> 3;
dirent[1] = cluster << 5;
@@ -295,15 +300,15 @@ create_file(struct directory *dir, const char *mangled_name,
dp = header = disk->image + (cluster << (disk->fmt->cluster_shift+8));
cleft = secperclust - 1; /* Left in the first cluster */
- memset(header, 0, 256);
+ memset(hdata = header, 0, 256);
- *header++ = (dirp << 4) + dirs;
- *header++ = 0; /* Header = block 0 */
- *header++ = 0; /* Header = block 0 */
- *header++ = 0xFF;
+ *hdata++ = (dirp << 4) + dirs;
+ *hdata++ = 0; /* Header = block 0 */
+ *hdata++ = 0; /* Header = block 0 */
+ *hdata++ = 0xFF;
/* Starting extent has one cluster in it */
- header[0] = cluster >> 3;
- header[1] = (cluster << 5) + 0; /* Bits[4:0] = extend size minus one */
+ hdata[0] = cluster >> 3;
+ hdata[1] = (cluster << 5) + 0; /* Bits[4:0] = extend size minus one */
/* Actually copy the file */
blockno = 0;
@@ -317,17 +322,19 @@ create_file(struct directory *dir, const char *mangled_name,
cleft--;
} else {
cluster = get_cluster(disk, clusters--);
- if (cluster < 0)
+ if (cluster < 0) {
+ fprintf(stderr, "get_cluster = %d\n", cluster);
return NULL;
+ }
dp = disk->image + (cluster << (disk->fmt->cluster_shift+8));
cleft = secperclust - 1;
- if (cluster == ((header[0] << 3) + (header[1] >> 5) + 1) &&
- (header[1] & 31) < 31) {
- header[1]++;
+ if (cluster == ((hdata[0] << 3) + (hdata[1] >> 5) + 1) &&
+ (hdata[1] & 31) < 31) {
+ hdata[1]++;
} else {
- header += 2;
- header[0] = cluster >> 3;
- header[1] = (cluster << 5) + 0;
+ hdata += 2;
+ hdata[0] = cluster >> 3;
+ hdata[1] = (cluster << 5) + 0;
}
}
@@ -344,12 +351,12 @@ create_file(struct directory *dir, const char *mangled_name,
size -= nbytes;
}
- /* Terminate the header */
- header += 2;
- header[0] = 0xFF;
- header[1] = 0xFF;
+ /* Terminate the hdata */
+ hdata += 2;
+ hdata[0] = 0xFF;
+ hdata[1] = 0xFF;
- return 0;
+ return header;
}
/*
@@ -394,8 +401,10 @@ struct directory *make_ufd(struct directory *dir, const char *filename)
bitmap[1] = dirs_block >> 8;
header = create_file(dir, mangled_name, bitmap, 17*253, 1);
- if (!header)
+ if (!header) {
+ fprintf(stderr, "%s: header returns NULL\n", program);
return NULL;
+ }
if ((header[6] & header[7]) != 0xff) {
fprintf(stderr, "%s: discontiguous UFD (disk too fragmented)\n", program);
@@ -434,7 +443,10 @@ int get_files(struct directory *ufd, const char *dirpath)
}
if ( S_ISDIR(st.st_mode) ) {
subdir = make_ufd(ufd, filename);
- get_files(subdir, filename);
+ if (subdir)
+ get_files(subdir, filename);
+ else
+ fprintf(stderr, "%s: make_ufd(%s) failed\n", program, filename);
} else {
copy_file(ufd, filename);
}