mirror of
https://github.com/bobbimanners/ProDOS-Utils.git
synced 2024-06-16 09:29:27 +00:00
Moved creation of filelist[] into separate function. Fixed FS corruption bug.
This commit is contained in:
parent
c2cd9f12f9
commit
7e98017cb9
81
sortdir.c
81
sortdir.c
|
@ -3,6 +3,8 @@
|
||||||
*
|
*
|
||||||
* Bobbi January-March 2020
|
* Bobbi January-March 2020
|
||||||
*
|
*
|
||||||
|
* TODO: Obsolete MAXFILES is hardcoded - need a better way to do this
|
||||||
|
* TODO: Check for no memory when allocating aux memory
|
||||||
* TODO: Enable free list functionality on ProDOS-8
|
* TODO: Enable free list functionality on ProDOS-8
|
||||||
* TODO: Get both ProDOS-8 and GNO versions to build from this source
|
* TODO: Get both ProDOS-8 and GNO versions to build from this source
|
||||||
* TODO: Trimming unused directory blocks
|
* TODO: Trimming unused directory blocks
|
||||||
|
@ -17,6 +19,7 @@
|
||||||
* v0.56 Minor improvements to conditional compilation
|
* v0.56 Minor improvements to conditional compilation
|
||||||
* v0.57 Fixed bugs in aux memory allocation, memory zeroing bug
|
* v0.57 Fixed bugs in aux memory allocation, memory zeroing bug
|
||||||
* v0.58 Fixed more bugs. Now working properly using aux memory
|
* v0.58 Fixed more bugs. Now working properly using aux memory
|
||||||
|
* v0.59 Moved creation of filelist[] into buildsorttable(). More bugfix.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#pragma debug 9
|
//#pragma debug 9
|
||||||
|
@ -39,7 +42,6 @@
|
||||||
#include <apple2enh.h>
|
#include <apple2enh.h>
|
||||||
#include <dio.h>
|
#include <dio.h>
|
||||||
|
|
||||||
#undef DEBUG /* Enable additional debug printout */
|
|
||||||
#define CHECK /* Perform additional integrity checking */
|
#define CHECK /* Perform additional integrity checking */
|
||||||
#define SORT /* Enable sorting code */
|
#define SORT /* Enable sorting code */
|
||||||
#undef FREELIST /* Checking of free list */
|
#undef FREELIST /* Checking of free list */
|
||||||
|
@ -291,8 +293,9 @@ void copyaux(char *src, char *dst, uint len, uchar dir) {
|
||||||
/* Extremely simple aux memory allocator */
|
/* Extremely simple aux memory allocator */
|
||||||
/* TODO: Check for overflow!!!! */
|
/* TODO: Check for overflow!!!! */
|
||||||
char *auxalloc(uint bytes) {
|
char *auxalloc(uint bytes) {
|
||||||
|
char *p = auxp;
|
||||||
auxp += bytes;
|
auxp += bytes;
|
||||||
return auxp;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Will need something better */
|
/* TODO: Will need something better */
|
||||||
|
@ -386,9 +389,6 @@ void flushall(void) {
|
||||||
*/
|
*/
|
||||||
int readdiskblock(uchar device, uint blocknum, char *buf) {
|
int readdiskblock(uchar device, uint blocknum, char *buf) {
|
||||||
int rc;
|
int rc;
|
||||||
#ifdef DEBUG
|
|
||||||
printf("Reading dev %2u block %5u\n", device, blocknum);
|
|
||||||
#endif
|
|
||||||
#ifdef CHECK
|
#ifdef CHECK
|
||||||
#ifdef FREELIST
|
#ifdef FREELIST
|
||||||
if (flloaded)
|
if (flloaded)
|
||||||
|
@ -418,9 +418,6 @@ int readdiskblock(uchar device, uint blocknum, char *buf) {
|
||||||
*/
|
*/
|
||||||
int writediskblock(uchar device, uint blocknum, char *buf) {
|
int writediskblock(uchar device, uint blocknum, char *buf) {
|
||||||
int rc;
|
int rc;
|
||||||
#ifdef DEBUG
|
|
||||||
printf("Writing dev %2u blk %5u\n", device, blocknum);
|
|
||||||
#endif
|
|
||||||
if ((strcmp(currdir, "LIB") == 0) ||
|
if ((strcmp(currdir, "LIB") == 0) ||
|
||||||
(strcmp(currdir, "LIBRARIES") == 0)) {
|
(strcmp(currdir, "LIBRARIES") == 0)) {
|
||||||
printf("Not writing library directory %s\n", currdir);
|
printf("Not writing library directory %s\n", currdir);
|
||||||
|
@ -1073,9 +1070,6 @@ int readdir(uint device, uint blocknum) {
|
||||||
#ifdef AUXMEM
|
#ifdef AUXMEM
|
||||||
curblk->data = auxalloc(BLKSZ);
|
curblk->data = auxalloc(BLKSZ);
|
||||||
curblk->sorteddata = auxalloc(BLKSZ);
|
curblk->sorteddata = auxalloc(BLKSZ);
|
||||||
// TODO ZERO sorteddata
|
|
||||||
#else
|
|
||||||
bzero(curblk->sorteddata, BLKSZ);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FREELIST
|
#ifdef FREELIST
|
||||||
|
@ -1203,8 +1197,9 @@ int readdir(uint device, uint blocknum) {
|
||||||
#endif
|
#endif
|
||||||
blks = ent->blksused[0] + 256U * ent->blksused[1];
|
blks = ent->blksused[0] + 256U * ent->blksused[1];
|
||||||
eof = ent->eof[0] + 256L * ent->eof[1] + 65536L * ent->eof[2];
|
eof = ent->eof[0] + 256L * ent->eof[1] + 65536L * ent->eof[2];
|
||||||
for (i = 0; i < NMLEN + 1; ++i)
|
|
||||||
filelist[numfiles].name[i] = '\0';
|
/***
|
||||||
|
bzero(filelist[numfiles].name, NMLEN + 1);
|
||||||
for (i = 0; i < (ent->typ_len & 0x0f); ++i)
|
for (i = 0; i < (ent->typ_len & 0x0f); ++i)
|
||||||
filelist[numfiles].name[i] = namebuf[i];
|
filelist[numfiles].name[i] = namebuf[i];
|
||||||
filelist[numfiles].type = ent->type;
|
filelist[numfiles].type = ent->type;
|
||||||
|
@ -1218,6 +1213,7 @@ int readdir(uint device, uint blocknum) {
|
||||||
"%04d-%02d-%02d %02d:%02d %s",
|
"%04d-%02d-%02d %02d:%02d %s",
|
||||||
dt.year, dt.month, dt.day, dt.hour, dt.minute,
|
dt.year, dt.month, dt.day, dt.hour, dt.minute,
|
||||||
(dt.ispd25format ? "*" : " "));
|
(dt.ispd25format ? "*" : " "));
|
||||||
|
***/
|
||||||
|
|
||||||
keyblk = ent->keyptr[0] + 256U * ent->keyptr[1];
|
keyblk = ent->keyptr[0] + 256U * ent->keyptr[1];
|
||||||
hdrblk = ent->hdrptr[0] + 256U * ent->hdrptr[1];
|
hdrblk = ent->hdrptr[0] + 256U * ent->hdrptr[1];
|
||||||
|
@ -1297,16 +1293,18 @@ int readdir(uint device, uint blocknum) {
|
||||||
++entries;
|
++entries;
|
||||||
}
|
}
|
||||||
if (blkentries == entperblk) {
|
if (blkentries == entperblk) {
|
||||||
|
blocknum = dirblkbuf[0x02] + 256U * dirblkbuf[0x03];
|
||||||
#ifdef AUXMEM
|
#ifdef AUXMEM
|
||||||
copyaux(dirblkbuf, curblk->data, BLKSZ, TOAUX);
|
copyaux(dirblkbuf, curblk->data, BLKSZ, TOAUX);
|
||||||
/// bzero(dirblkbuf + PTRSZ, BLKSZ - PTRSZ);
|
bzero(buf, BLKSZ);
|
||||||
copyaux(dirblkbuf, curblk->sorteddata, BLKSZ, TOAUX);
|
memcpy(buf, dirblkbuf, PTRSZ);
|
||||||
|
copyaux(buf, curblk->sorteddata, BLKSZ, TOAUX);
|
||||||
#else
|
#else
|
||||||
memcpy(curblk->data, dirblkbuf, BLKSZ);
|
memcpy(curblk->data, dirblkbuf, BLKSZ);
|
||||||
////// bzero(dirblkbuf + PTRSZ, BLKSZ - PTRSZ);
|
bzero(buf, BLKSZ);
|
||||||
memcpy(curblk->sorteddata, dirblkbuf, PTRSZ);
|
memcpy(buf, dirblkbuf, PTRSZ);
|
||||||
|
memcpy(curblk->sorteddata, buf, BLKSZ);
|
||||||
#endif
|
#endif
|
||||||
blocknum = dirblkbuf[0x02] + 256U * dirblkbuf[0x03];
|
|
||||||
if (blocknum == 0) {
|
if (blocknum == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1321,9 +1319,6 @@ int readdir(uint device, uint blocknum) {
|
||||||
#ifdef AUXMEM
|
#ifdef AUXMEM
|
||||||
curblk->data = auxalloc(BLKSZ);
|
curblk->data = auxalloc(BLKSZ);
|
||||||
curblk->sorteddata = auxalloc(BLKSZ);
|
curblk->sorteddata = auxalloc(BLKSZ);
|
||||||
// TODO: Zero sorteddata
|
|
||||||
#else
|
|
||||||
bzero(curblk->sorteddata, BLKSZ);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FREELIST
|
#ifdef FREELIST
|
||||||
|
@ -1352,21 +1347,22 @@ int readdir(uint device, uint blocknum) {
|
||||||
}
|
}
|
||||||
#ifdef AUXMEM
|
#ifdef AUXMEM
|
||||||
copyaux(dirblkbuf, curblk->data, BLKSZ, TOAUX);
|
copyaux(dirblkbuf, curblk->data, BLKSZ, TOAUX);
|
||||||
/// bzero(dirblkbuf + PTRSZ, BLKSZ - PTRSZ);
|
bzero(buf, BLKSZ);
|
||||||
copyaux(dirblkbuf, curblk->sorteddata, BLKSZ, TOAUX);
|
memcpy(buf, dirblkbuf, PTRSZ);
|
||||||
|
copyaux(buf, curblk->sorteddata, BLKSZ, TOAUX);
|
||||||
#else
|
#else
|
||||||
memcpy(curblk->data, dirblkbuf, BLKSZ);
|
memcpy(curblk->data, dirblkbuf, BLKSZ);
|
||||||
//// bzero(dirblkbuf + PTRSZ, BLKSZ - PTRSZ);
|
bzero(buf, BLKSZ);
|
||||||
memcpy(curblk->sorteddata, dirblkbuf, PTRSZ);
|
memcpy(buf, dirblkbuf, PTRSZ);
|
||||||
|
memcpy(curblk->sorteddata, buf, BLKSZ);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return errcount - errsbefore;
|
return errcount - errsbefore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build filelist[] which the table used by the sorting algorithm.
|
* Build filelist[], the table used by the sorting algorithm.
|
||||||
*/
|
*/
|
||||||
#if 0
|
|
||||||
void buildsorttable() {
|
void buildsorttable() {
|
||||||
static char namebuf[NMLEN+1];
|
static char namebuf[NMLEN+1];
|
||||||
uint off, blks, eof;
|
uint off, blks, eof;
|
||||||
|
@ -1375,8 +1371,8 @@ void buildsorttable() {
|
||||||
struct pd_dirent *ent;
|
struct pd_dirent *ent;
|
||||||
uint idx = 0;
|
uint idx = 0;
|
||||||
struct block *b = blocks;
|
struct block *b = blocks;
|
||||||
uchar firstent = 1; /* Skip first entry of first block */
|
uchar firstent = 2; /* Skip first entry of first block */
|
||||||
uchar blkidx = 0;
|
uchar blkidx = 1;
|
||||||
|
|
||||||
while (b) {
|
while (b) {
|
||||||
#ifdef AUXMEM
|
#ifdef AUXMEM
|
||||||
|
@ -1384,9 +1380,8 @@ void buildsorttable() {
|
||||||
#else
|
#else
|
||||||
memcpy(dirblkbuf, b->data, BLKSZ);
|
memcpy(dirblkbuf, b->data, BLKSZ);
|
||||||
#endif
|
#endif
|
||||||
for (entry = firstent; entry < ENTPERBLK; ++entry) {
|
for (entry = firstent; entry <= ENTPERBLK; ++entry) {
|
||||||
printf("blk %u entry %u\n", blkidx, entry);
|
off = PTRSZ + (entry - 1) * entsz;
|
||||||
off = PTRSZ + entry * ENTSZ;
|
|
||||||
ent = (struct pd_dirent*)(dirblkbuf + off);
|
ent = (struct pd_dirent*)(dirblkbuf + off);
|
||||||
|
|
||||||
if (ent->typ_len != 0) {
|
if (ent->typ_len != 0) {
|
||||||
|
@ -1396,13 +1391,7 @@ printf("blk %u entry %u\n", blkidx, entry);
|
||||||
fixcase(ent->name, namebuf,
|
fixcase(ent->name, namebuf,
|
||||||
ent->vers, ent->minvers, ent->typ_len & 0x0f);
|
ent->vers, ent->minvers, ent->typ_len & 0x0f);
|
||||||
|
|
||||||
printf("%u %u - ", blkidx, entry);
|
bzero(filelist[idx].name, NMLEN + 1);
|
||||||
fputs(namebuf,stdout);
|
|
||||||
printf(" %u %u\n", blks, eof);
|
|
||||||
|
|
||||||
for (i = 0; i < NMLEN + 1; ++i)
|
|
||||||
filelist[idx].name[i] = '\0';
|
|
||||||
//bzero(filelist[idx].name, NMLEN + 1);
|
|
||||||
for (i = 0; i < (ent->typ_len & 0x0f); ++i)
|
for (i = 0; i < (ent->typ_len & 0x0f); ++i)
|
||||||
filelist[idx].name[i] = namebuf[i];
|
filelist[idx].name[i] = namebuf[i];
|
||||||
filelist[idx].type = ent->type;
|
filelist[idx].type = ent->type;
|
||||||
|
@ -1421,14 +1410,13 @@ printf("blk %u entry %u\n", blkidx, entry);
|
||||||
}
|
}
|
||||||
b = b->next;
|
b = b->next;
|
||||||
++blkidx;
|
++blkidx;
|
||||||
firstent = 0;
|
firstent = 1;
|
||||||
}
|
}
|
||||||
numfiles = idx - 1;
|
numfiles = idx;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef SORT
|
#ifdef SORT
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compare - filename sort in ascending order
|
* Compare - filename sort in ascending order
|
||||||
*/
|
*/
|
||||||
|
@ -1584,6 +1572,7 @@ int cmp_noop(const void *a, const void *b) {
|
||||||
struct fileent *bb = (struct fileent*)b;
|
struct fileent *bb = (struct fileent*)b;
|
||||||
return aa->order - bb->order;
|
return aa->order - bb->order;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1734,7 +1723,7 @@ void copyent(uint srcblk, uint srcent, uint dstblk, uint dstent, uint device) {
|
||||||
dstptr = dest->sorteddata + PTRSZ + (dstent-1) * entsz;
|
dstptr = dest->sorteddata + PTRSZ + (dstent-1) * entsz;
|
||||||
#ifdef AUXMEM
|
#ifdef AUXMEM
|
||||||
copyaux(srcptr, buf2, entsz, FROMAUX);
|
copyaux(srcptr, buf2, entsz, FROMAUX);
|
||||||
copyaux(buf2, dstptr, entsz, TOAUX);
|
copyaux(buf2, dstptr, entsz-1, TOAUX); // USING SIZE-1 MAKES IT WORK!!!!!
|
||||||
#else
|
#else
|
||||||
memcpy(dstptr, srcptr, entsz);
|
memcpy(dstptr, srcptr, entsz);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1820,7 +1809,7 @@ void interactive(void) {
|
||||||
|
|
||||||
doverbose = 1;
|
doverbose = 1;
|
||||||
|
|
||||||
puts("S O R T D I R v0.58 alpha Use ^ to return to previous question");
|
puts("S O R T D I R v0.59 alpha Use ^ to return to previous question");
|
||||||
|
|
||||||
q1:
|
q1:
|
||||||
fputs("\nEnter path (e.g.: /H1) of starting directory> ", stdout);
|
fputs("\nEnter path (e.g.: /H1) of starting directory> ", stdout);
|
||||||
|
@ -1939,7 +1928,7 @@ void processdir(uint device, uint blocknum) {
|
||||||
uchar i, errs;
|
uchar i, errs;
|
||||||
flushall();
|
flushall();
|
||||||
errs = readdir(device, blocknum);
|
errs = readdir(device, blocknum);
|
||||||
//buildsorttable();
|
buildsorttable();
|
||||||
// if (doverbose) {
|
// if (doverbose) {
|
||||||
// printlist();
|
// printlist();
|
||||||
// }
|
// }
|
||||||
|
|
BIN
sortdir.po
BIN
sortdir.po
Binary file not shown.
Loading…
Reference in New Issue
Block a user