From b2e684247bd53d8b63b21991bc310f4435cf1cae Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 3 Aug 2021 20:40:45 -0400 Subject: [PATCH] prodos: add DELETE support seems to work --- utils/prodos-utils/prodos.c | 206 ++++++++++++++++++++++++------------ 1 file changed, 136 insertions(+), 70 deletions(-) diff --git a/utils/prodos-utils/prodos.c b/utils/prodos-utils/prodos.c index 450b7a4c..3ede3197 100644 --- a/utils/prodos-utils/prodos.c +++ b/utils/prodos-utils/prodos.c @@ -44,6 +44,8 @@ static int prodos_lookup_file(struct voldir_t *voldir, voldir_buffer+4+file*PRODOS_FILE_DESC_LEN, &file_entry); + if (file_entry.storage_type==PRODOS_FILE_DELETED) continue; + /* FIXME: case insensitive? */ if (!strncmp(filename,(char *)file_entry.file_name,15)) { return (voldir_block<<8)|file; @@ -701,93 +703,157 @@ static int prodos_rename_file(struct voldir_t *voldir, static int prodos_delete_file(struct voldir_t *voldir,char *apple_filename) { -#if 0 - - int i; - int catalog_track,catalog_sector,catalog_entry; - int ts_track,ts_sector; - char file_type; - int result; - unsigned char catalog_buffer[PRODOS_BYTES_PER_BLOCK]; - - /* unpack file/track/sector info */ - catalog_entry=fsl>>16; - catalog_track=(fsl>>8)&0xff; - catalog_sector=(fsl&0xff); + unsigned char data_buffer[PRODOS_BYTES_PER_BLOCK]; + unsigned char index_block[PRODOS_BYTES_PER_BLOCK]; + unsigned char master_index_block[PRODOS_BYTES_PER_BLOCK]; + int result,chunk,chunk_block,index,blocks_left,read_blocks,mblock; + struct file_entry_t file; + int inode; - /* Load in the catalog table for the file */ - lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET); - result=read(fd,catalog_buffer,PRODOS_BYTES_PER_BLOCK); + /* get the voldir/entry for file */ + inode=prodos_lookup_file(voldir,apple_filename); - file_type=catalog_buffer[CATALOG_FILE_LIST+ - (catalog_entry*CATALOG_ENTRY_SIZE) - +FILE_TYPE]; - - if (file_type&0x80) { - fprintf(stderr,"File is locked! Unlock before deleting!\n"); - exit(1); + if (inode<0) { + fprintf(stderr,"Error! %s not found!\n", + apple_filename); + return -1; } - /* get pointer to t/s list */ - ts_track=catalog_buffer[CATALOG_FILE_LIST+ - catalog_entry*CATALOG_ENTRY_SIZE+FILE_TS_LIST_T]; - ts_sector=catalog_buffer[CATALOG_FILE_LIST+ - catalog_entry*CATALOG_ENTRY_SIZE+FILE_TS_LIST_S]; + result=prodos_read_block(voldir,data_buffer,inode>>8); -keep_deleting: - - /* load in the t/s list info */ - lseek(fd,DISK_OFFSET(ts_track,ts_sector),SEEK_SET); - result=read(fd,catalog_buffer,PRODOS_BYTES_PER_BLOCK); - - /* Free each sector listed by t/s list */ - for(i=0;i>8); + + /* update file count */ + if (debug) printf("Updating file count...\n"); + voldir->file_count--; + prodos_sync_voldir(voldir); - if (result<0) fprintf(stderr,"Error on I/O\n"); -#endif return 0; }