mirror of
https://github.com/deater/dos33fsprogs.git
synced 2025-02-23 20:29:15 +00:00
prodos: fix bug when findind free block
meant that SAVE was not working quite right also added a bunch of debugging messages
This commit is contained in:
parent
628513d1c1
commit
62f80a60fc
@ -27,6 +27,8 @@ static int prodos_lookup_file(struct voldir_t *voldir,
|
|||||||
unsigned char voldir_buffer[PRODOS_BYTES_PER_BLOCK];
|
unsigned char voldir_buffer[PRODOS_BYTES_PER_BLOCK];
|
||||||
int result,file;
|
int result,file;
|
||||||
|
|
||||||
|
if (debug) printf("\t*** Looking for %s in block $%X\n",filename,subdir_block);
|
||||||
|
|
||||||
voldir_block=subdir_block;
|
voldir_block=subdir_block;
|
||||||
voldir_offset=1; /* skip the header */
|
voldir_offset=1; /* skip the header */
|
||||||
|
|
||||||
@ -44,13 +46,21 @@ static int prodos_lookup_file(struct voldir_t *voldir,
|
|||||||
file<voldir->entries_per_block;file++) {
|
file<voldir->entries_per_block;file++) {
|
||||||
|
|
||||||
prodos_populate_filedesc(
|
prodos_populate_filedesc(
|
||||||
voldir_buffer+4+file*PRODOS_FILE_DESC_LEN,
|
voldir_buffer+4+(file*PRODOS_FILE_DESC_LEN),
|
||||||
&file_entry);
|
&file_entry);
|
||||||
|
|
||||||
if (file_entry.storage_type==PRODOS_FILE_DELETED) continue;
|
if (file_entry.storage_type==PRODOS_FILE_DELETED) continue;
|
||||||
|
|
||||||
|
|
||||||
|
if (debug) printf("\tTrying $%X = %s\n",
|
||||||
|
(voldir_block<<8)|file,
|
||||||
|
file_entry.file_name);
|
||||||
|
|
||||||
/* FIXME: case insensitive? */
|
/* FIXME: case insensitive? */
|
||||||
if (!strncmp(filename,(char *)file_entry.file_name,15)) {
|
if (!strncmp(filename,(char *)file_entry.file_name,15)) {
|
||||||
|
if (debug) printf("*** MATCH: %s = %s at inode $%X\n",
|
||||||
|
filename,file_entry.file_name,
|
||||||
|
(voldir_block<<8)|file);
|
||||||
return (voldir_block<<8)|file;
|
return (voldir_block<<8)|file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,6 +372,7 @@ static int prodos_add_file(struct voldir_t *voldir,
|
|||||||
/* allocate index */
|
/* allocate index */
|
||||||
index=prodos_allocate_block(voldir);
|
index=prodos_allocate_block(voldir);
|
||||||
key_block=index;
|
key_block=index;
|
||||||
|
if (debug) printf("**** ALLOCATING SAPLING key_block=$%X\n",key_block);
|
||||||
|
|
||||||
memset(index_buffer,0,PRODOS_BYTES_PER_BLOCK);
|
memset(index_buffer,0,PRODOS_BYTES_PER_BLOCK);
|
||||||
|
|
||||||
@ -442,7 +453,12 @@ static int prodos_add_file(struct voldir_t *voldir,
|
|||||||
file.version=0;
|
file.version=0;
|
||||||
file.min_version=0;
|
file.min_version=0;
|
||||||
file.access=0xe3; // 0x21?
|
file.access=0xe3; // 0x21?
|
||||||
file.aux_type=0;
|
if (file.file_type==PRODOS_TYPE_BIN) {
|
||||||
|
file.aux_type=address;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
file.aux_type=0;
|
||||||
|
}
|
||||||
file.last_mod=prodos_time(time(NULL));
|
file.last_mod=prodos_time(time(NULL));
|
||||||
file.header_pointer=dir_block;
|
file.header_pointer=dir_block;
|
||||||
|
|
||||||
@ -787,9 +803,11 @@ static int prodos_delete_file(struct voldir_t *voldir,
|
|||||||
struct file_entry_t file;
|
struct file_entry_t file;
|
||||||
int inode;
|
int inode;
|
||||||
|
|
||||||
|
if (debug) printf("*** DELETING FILE %s\n",apple_filename);
|
||||||
|
|
||||||
/* get the voldir/entry for file */
|
/* get the voldir/entry for file */
|
||||||
inode=prodos_lookup_file(voldir,dir_block,apple_filename);
|
inode=prodos_lookup_file(voldir,dir_block,apple_filename);
|
||||||
|
if (debug) printf("\t*** Found inode $%X for file %s\n",inode,apple_filename);
|
||||||
|
|
||||||
if (inode<0) {
|
if (inode<0) {
|
||||||
fprintf(stderr,"Error! %s not found!\n",
|
fprintf(stderr,"Error! %s not found!\n",
|
||||||
@ -804,6 +822,9 @@ static int prodos_delete_file(struct voldir_t *voldir,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (debug) printf("*** PERMANENTLY DELETING %s (inode: $%X)\n",
|
||||||
|
file.file_name,inode);
|
||||||
|
|
||||||
/******************************/
|
/******************************/
|
||||||
/* delete all the file blocks */
|
/* delete all the file blocks */
|
||||||
/******************************/
|
/******************************/
|
||||||
@ -811,7 +832,7 @@ static int prodos_delete_file(struct voldir_t *voldir,
|
|||||||
switch(file.storage_type) {
|
switch(file.storage_type) {
|
||||||
case PRODOS_FILE_SEEDLING:
|
case PRODOS_FILE_SEEDLING:
|
||||||
/* Just a single block */
|
/* Just a single block */
|
||||||
if (debug) fprintf(stderr,"Deleting block $%x\n",
|
if (debug) fprintf(stderr,"*** SEEDLING Deleting block $%x\n",
|
||||||
file.key_pointer);
|
file.key_pointer);
|
||||||
|
|
||||||
result=prodos_free_block(voldir,file.key_pointer);
|
result=prodos_free_block(voldir,file.key_pointer);
|
||||||
@ -824,8 +845,8 @@ static int prodos_delete_file(struct voldir_t *voldir,
|
|||||||
/* Index block points to up to 256 blocks */
|
/* Index block points to up to 256 blocks */
|
||||||
/* Addresses are stored low-byte (256 bytes) then hi-byte */
|
/* Addresses are stored low-byte (256 bytes) then hi-byte */
|
||||||
/* Address of zero means file hole, all zeros */
|
/* Address of zero means file hole, all zeros */
|
||||||
if (debug) fprintf(stderr,"Freeing index "
|
if (debug) printf("*** SAPLING "
|
||||||
"block $%x\n",
|
"Freeing index block $%x\n",
|
||||||
file.key_pointer);
|
file.key_pointer);
|
||||||
result=prodos_read_block(voldir,index_block,
|
result=prodos_read_block(voldir,index_block,
|
||||||
file.key_pointer);
|
file.key_pointer);
|
||||||
@ -858,8 +879,8 @@ static int prodos_delete_file(struct voldir_t *voldir,
|
|||||||
|
|
||||||
blocks_left=file.blocks_used;
|
blocks_left=file.blocks_used;
|
||||||
|
|
||||||
if (debug) fprintf(stderr,"Deleting master index "
|
if (debug) fprintf(stderr,"*** TREE: "
|
||||||
"block $%x\n",
|
"Deleting master index block $%x\n",
|
||||||
file.key_pointer);
|
file.key_pointer);
|
||||||
result=prodos_read_block(voldir,master_index_block,
|
result=prodos_read_block(voldir,master_index_block,
|
||||||
file.key_pointer);
|
file.key_pointer);
|
||||||
@ -915,9 +936,12 @@ static int prodos_delete_file(struct voldir_t *voldir,
|
|||||||
|
|
||||||
/* should we clear it out? */
|
/* should we clear it out? */
|
||||||
/* makes undelete harder */
|
/* makes undelete harder */
|
||||||
|
/* ProDOS 1.0.1 clears filename but leaves rest */
|
||||||
// memset(&file,0,sizeof(struct file_entry_t));
|
// memset(&file,0,sizeof(struct file_entry_t));
|
||||||
|
|
||||||
file.storage_type=PRODOS_FILE_DELETED;
|
file.storage_type=PRODOS_FILE_DELETED;
|
||||||
|
file.name_length=0;
|
||||||
|
memset(file.file_name,0,PRODOS_FILENAME_LEN);
|
||||||
|
|
||||||
/* copy in new data */
|
/* copy in new data */
|
||||||
prodos_writeout_filedesc(voldir,&file,
|
prodos_writeout_filedesc(voldir,&file,
|
||||||
|
@ -340,10 +340,13 @@ int prodos_dump(struct voldir_t *voldir) {
|
|||||||
PRODOS_FILE_DESC_LEN);
|
PRODOS_FILE_DESC_LEN);
|
||||||
prodos_populate_filedesc(file_desc,&file_entry);
|
prodos_populate_filedesc(file_desc,&file_entry);
|
||||||
|
|
||||||
if (file_entry.storage_type==PRODOS_FILE_DELETED) continue;
|
// if (file_entry.storage_type==PRODOS_FILE_DELETED) continue;
|
||||||
|
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
printf("FILE %d: %s\n",file,file_entry.file_name);
|
printf("FILE $%x: %s\n",
|
||||||
|
(catalog_block<<8)|file,
|
||||||
|
file_entry.file_name);
|
||||||
|
printf("\tFilename len: %d\n",file_entry.name_length);
|
||||||
printf("\t($%X): ",file_entry.storage_type);
|
printf("\t($%X): ",file_entry.storage_type);
|
||||||
prodos_print_storage_type(file_entry.storage_type);
|
prodos_print_storage_type(file_entry.storage_type);
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ int prodos_read_block(struct voldir_t *voldir,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (voldir->interleave==PRODOS_INTERLEAVE_DOS33) {
|
else if (voldir->interleave==PRODOS_INTERLEAVE_DOS33) {
|
||||||
if (debug) printf("Using DOS33 interleave, finding block $%X\n",blocknum);
|
if (debug) printf("\tUsing DOS33 interleave, finding block $%X\n",blocknum);
|
||||||
track=(blocknum>>3);
|
track=(blocknum>>3);
|
||||||
sector1=dos_interleave[(blocknum&0x7)*2];
|
sector1=dos_interleave[(blocknum&0x7)*2];
|
||||||
sector2=dos_interleave[(blocknum&0x7)*2+1];
|
sector2=dos_interleave[(blocknum&0x7)*2+1];
|
||||||
if (debug) printf("Remapping block $%X to T%d S%d and T%d S%d\n",
|
if (debug) printf("\tRemapping block $%X to T%d S%d and T%d S%d\n",
|
||||||
blocknum,track,sector1,track,sector2);
|
blocknum,track,sector1,track,sector2);
|
||||||
|
|
||||||
if (debug) printf("Seeking to %x\n",((track<<4)+sector1)*256);
|
if (debug) printf("\tSeeking to %x\n",((track<<4)+sector1)*256);
|
||||||
lseek(voldir->fd,voldir->image_offset+
|
lseek(voldir->fd,voldir->image_offset+
|
||||||
((track<<4)+sector1)*256,SEEK_SET);
|
((track<<4)+sector1)*256,SEEK_SET);
|
||||||
result=read(voldir->fd,block,PRODOS_BYTES_PER_BLOCK/2);
|
result=read(voldir->fd,block,PRODOS_BYTES_PER_BLOCK/2);
|
||||||
@ -59,7 +59,7 @@ int prodos_read_block(struct voldir_t *voldir,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) printf("Seeking to %x\n",((track<<4)+sector2)*256);
|
if (debug) printf("\tSeeking to %x\n",((track<<4)+sector2)*256);
|
||||||
lseek(voldir->fd,voldir->image_offset+
|
lseek(voldir->fd,voldir->image_offset+
|
||||||
((track<<4)+sector2)*256,SEEK_SET);
|
((track<<4)+sector2)*256,SEEK_SET);
|
||||||
result=read(voldir->fd,block+256,PRODOS_BYTES_PER_BLOCK/2);
|
result=read(voldir->fd,block+256,PRODOS_BYTES_PER_BLOCK/2);
|
||||||
@ -101,14 +101,14 @@ int prodos_write_block(struct voldir_t *voldir,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (voldir->interleave==PRODOS_INTERLEAVE_DOS33) {
|
else if (voldir->interleave==PRODOS_INTERLEAVE_DOS33) {
|
||||||
if (debug) printf("Using DOS33 interleave, finding block $%X\n",blocknum);
|
if (debug) printf("\tUsing DOS33 interleave, finding block $%X\n",blocknum);
|
||||||
track=(blocknum>>3);
|
track=(blocknum>>3);
|
||||||
sector1=dos_interleave[(blocknum&0x7)*2];
|
sector1=dos_interleave[(blocknum&0x7)*2];
|
||||||
sector2=dos_interleave[(blocknum&0x7)*2+1];
|
sector2=dos_interleave[(blocknum&0x7)*2+1];
|
||||||
if (debug) printf("Remapping block $%X to T%d S%d and T%d S%d\n",
|
if (debug) printf("\tRemapping block $%X to T%d S%d and T%d S%d\n",
|
||||||
blocknum,track,sector1,track,sector2);
|
blocknum,track,sector1,track,sector2);
|
||||||
|
|
||||||
if (debug) printf("Seeking to %x\n",((track<<4)+sector1)*256);
|
if (debug) printf("\tSeeking to %x\n",((track<<4)+sector1)*256);
|
||||||
lseek(voldir->fd,voldir->image_offset+
|
lseek(voldir->fd,voldir->image_offset+
|
||||||
((track<<4)+sector1)*256,SEEK_SET);
|
((track<<4)+sector1)*256,SEEK_SET);
|
||||||
result=write(voldir->fd,block,PRODOS_BYTES_PER_BLOCK/2);
|
result=write(voldir->fd,block,PRODOS_BYTES_PER_BLOCK/2);
|
||||||
@ -119,7 +119,7 @@ int prodos_write_block(struct voldir_t *voldir,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) printf("Seeking to %x\n",((track<<4)+sector2)*256);
|
if (debug) printf("\tSeeking to %x\n",((track<<4)+sector2)*256);
|
||||||
lseek(voldir->fd,voldir->image_offset+
|
lseek(voldir->fd,voldir->image_offset+
|
||||||
((track<<4)+sector2)*256,SEEK_SET);
|
((track<<4)+sector2)*256,SEEK_SET);
|
||||||
result=write(voldir->fd,block+256,PRODOS_BYTES_PER_BLOCK/2);
|
result=write(voldir->fd,block+256,PRODOS_BYTES_PER_BLOCK/2);
|
||||||
|
@ -208,11 +208,15 @@ int prodos_voldir_find_free_block(struct voldir_t *voldir) {
|
|||||||
for(i=0;i<(512/16);i++) {
|
for(i=0;i<(512/16);i++) {
|
||||||
result=find_first_one(temp_block[i*2]);
|
result=find_first_one(temp_block[i*2]);
|
||||||
if (result>=0) {
|
if (result>=0) {
|
||||||
return (k<<4)+result;
|
if (debug) printf("Found free block %x\n",
|
||||||
|
(k<<12)+(i<<4)+result);
|
||||||
|
return (k<<12)+(i<<4)+result;
|
||||||
}
|
}
|
||||||
result=find_first_one(temp_block[(1+i*2)]);
|
result=find_first_one(temp_block[(1+i*2)]);
|
||||||
if (result>=0) {
|
if (result>=0) {
|
||||||
return (k<<4)+result+8;
|
if (debug) printf("Found free block %x\n",
|
||||||
|
(k<<12)+(i<<4)+result+8);
|
||||||
|
return (k<<12)+(i<<4)+result+8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user