summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-08-05 15:34:40 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-08-05 15:34:40 (GMT)
commit74d81744c4f71fa6b032598df5aaa0dae6cf7d0e (patch)
tree62bd18fec855ace9b052f06b3e43f0e7478fb415
parent86b4fb0c8f3a50c5aa4e99b78b5d62efa0a8408b (diff)
downloadabcdisk-74d81744c4f71fa6b032598df5aaa0dae6cf7d0e.zip
abcdisk-74d81744c4f71fa6b032598df5aaa0dae6cf7d0e.tar.gz
abcdisk-74d81744c4f71fa6b032598df5aaa0dae6cf7d0e.tar.bz2
abcdisk-74d81744c4f71fa6b032598df5aaa0dae6cf7d0e.tar.xz
Clean up problems up to and including copy_file()
-rw-r--r--Makefile2
-rw-r--r--abcwrite.c40
2 files changed, 16 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index a2ff504..7a252ea 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC = cc
-CFLAGS = -O -g
+CFLAGS = -W -Wall -O2 -g
LDFLAGS =
ifneq (,$(findstring _NT,$(shell uname -s)))
O = obj
diff --git a/abcwrite.c b/abcwrite.c
index f74aa90..654b8cc 100644
--- a/abcwrite.c
+++ b/abcwrite.c
@@ -14,10 +14,11 @@
#include <wchar.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include "util.h"
struct diskfmt {
const char *name;
- unsigned int ntracks; /* Total tracks (max 238) */
+ int ntracks; /* Total tracks (max 238) */
unsigned int track_shift; /* Size of a track in sectors (max 256) */
unsigned int cluster_shift; /* Size of a cluster (typically track/8) */
};
@@ -30,22 +31,11 @@ struct directory {
unsigned int block; /* UFD block pointer (0 for MFD) */
};
-/* Global bitmap */
-unsigned char *bitmap = image+(14*256);
-
-/* Master file directory */
-struct directory mfd = {
- image+(14*256), /* Directory entry "bitmap" */
- image+(16*256), /* Directory sectors */
- 0
-};
-
struct disk {
const struct diskfmt *fmt; /* Format descriptor */
unsigned char *image; /* Image of the disk */
unsigned char *bitmap; /* Pointer to the bitmap inside the disk */
- struct directory mfd;
- int nextblock; /* Next unassigned block number */
+ struct directory mfd; /* MFD directory descriptor */
};
/*
@@ -59,24 +49,24 @@ static void mark_used(struct disk *disk, unsigned int cluster)
static struct disk *allocate_disk(const struct diskfmt *fmt)
{
struct disk *disk = xmalloc(sizeof(struct disk));
- size_t size = (fmt->track * fmt->ntracks) << 8;
+ size_t size = (fmt->ntracks) << (fmt->track_shift + 8);
int i, starter;
memset(disk, 0, sizeof *disk);
disk->fmt = fmt;
- disk->image = xzalloc(size);
+ disk->image = xmalloc(size);
disk->bitmap = disk->image + 14*256;
disk->mfd.bitmap = disk->image + 14*256;
disk->mfd.dirsec = disk->image + 16*256;
- disk->nextblock = 32;
+ disk->mfd.block = 0; /* This is the MFD */
/* Post-formatting content? */
memset(disk->image, 0xe5, size);
/* Create empty bitmap */
- memset(disk->bitmap, 0, fmt->tracks);
- memset(disk->bitmap+fmt->tracks, 0xff, 0xe9-fmt->tracks);
+ memset(disk->bitmap, 0, fmt->ntracks);
+ memset(disk->bitmap+fmt->ntracks, 0xff, 0xe9-fmt->ntracks);
memset(disk->bitmap+0xe9, 0x01, 16); /* MFD bitmap */
disk->bitmap[0xff] = 0x00;
@@ -93,6 +83,8 @@ static struct disk *allocate_disk(const struct diskfmt *fmt)
memset(disk->image+(i << 8), 0x00, 16);
memset(disk->image+(i << 8)+16, 0xFF, 240);
}
+
+ return disk;
}
/*
@@ -100,10 +92,10 @@ static struct disk *allocate_disk(const struct diskfmt *fmt)
*/
static int get_cluster(struct disk *disk)
{
- int i, j;
+ int i;
unsigned char b;
- for (i = 0; i < disk->fmt->tracks; i++) {
+ for (i = 0; i < disk->fmt->ntracks; i++) {
if ((b = disk->bitmap[i]) != 0xff) {
i <<= 3;
while (b & 1) {
@@ -115,7 +107,7 @@ static int get_cluster(struct disk *disk)
}
}
- fprintf(stderr, "%s: output disk full\n", stderr);
+ fprintf(stderr, "%s: output disk full\n", program);
exit(1);
}
@@ -243,20 +235,18 @@ unsigned char *read_file(const char *filename, int *sizep)
int copy_file(const char *filename, struct disk *disk, struct directory *dir)
{
int size;
- int nblocks, nclust, cluster, secperclust;
+ int nblocks, cluster, secperclust;
char mangled_name[12];
int dirs, dirp; /* Directory (sector,position) */
unsigned char *dirent;
unsigned char *data, *src;
- int i;
- int blockno, cleft, block, bleft;
+ int blockno, cleft;
unsigned char *header, *dp;
data = src = read_file(filename, &size);
nblocks = (size+252)/253 + 1;
secperclust = 1 << disk->fmt->cluster_shift;
- nclust = (nblocks+secperclust-1) >> disk->fmt->cluster_shift;
mangle_name(mangled_name, filename);