mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-06-30 12:29:38 +00:00
utils: dos33: whitespace cleanup
This commit is contained in:
parent
7458087e2d
commit
a2a9d6ef52
|
@ -1030,36 +1030,36 @@ keep_saving:
|
||||||
/* lock a file. fts=entry/track/sector */
|
/* lock a file. fts=entry/track/sector */
|
||||||
static int dos33_lock_file(int fd,int fts,int lock) {
|
static int dos33_lock_file(int fd,int fts,int lock) {
|
||||||
|
|
||||||
int catalog_file,catalog_track,catalog_sector;
|
int catalog_file,catalog_track,catalog_sector;
|
||||||
int file_type,result;
|
int file_type,result;
|
||||||
|
|
||||||
catalog_file=fts>>16;
|
catalog_file=fts>>16;
|
||||||
catalog_track=(fts>>8)&0xff;
|
catalog_track=(fts>>8)&0xff;
|
||||||
catalog_sector=(fts&0xff);
|
catalog_sector=(fts&0xff);
|
||||||
|
|
||||||
|
|
||||||
/* Read in Catalog Sector */
|
/* Read in Catalog Sector */
|
||||||
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
||||||
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
|
|
||||||
file_type=sector_buffer[CATALOG_FILE_LIST+
|
file_type=sector_buffer[CATALOG_FILE_LIST+
|
||||||
(catalog_file*CATALOG_ENTRY_SIZE)
|
(catalog_file*CATALOG_ENTRY_SIZE)
|
||||||
+FILE_TYPE];
|
+FILE_TYPE];
|
||||||
|
|
||||||
if (lock) file_type|=0x80;
|
if (lock) file_type|=0x80;
|
||||||
else file_type&=0x7f;
|
else file_type&=0x7f;
|
||||||
|
|
||||||
sector_buffer[CATALOG_FILE_LIST+
|
sector_buffer[CATALOG_FILE_LIST+
|
||||||
(catalog_file*CATALOG_ENTRY_SIZE)
|
(catalog_file*CATALOG_ENTRY_SIZE)
|
||||||
+FILE_TYPE]=file_type;
|
+FILE_TYPE]=file_type;
|
||||||
|
|
||||||
/* write back modified catalog sector */
|
/* write back modified catalog sector */
|
||||||
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
||||||
result=write(fd,sector_buffer,BYTES_PER_SECTOR);
|
result=write(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
|
|
||||||
if (result<0) fprintf(stderr,"Error on I/O\n");
|
if (result<0) fprintf(stderr,"Error on I/O\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1068,165 +1068,171 @@ static int dos33_lock_file(int fd,int fts,int lock) {
|
||||||
/* FIXME: validate the new filename is valid */
|
/* FIXME: validate the new filename is valid */
|
||||||
static int dos33_rename_file(int fd,int fts,char *new_name) {
|
static int dos33_rename_file(int fd,int fts,char *new_name) {
|
||||||
|
|
||||||
int catalog_file,catalog_track,catalog_sector;
|
int catalog_file,catalog_track,catalog_sector;
|
||||||
int x,result;
|
int x,result;
|
||||||
|
|
||||||
catalog_file=fts>>16;
|
catalog_file=fts>>16;
|
||||||
catalog_track=(fts>>8)&0xff;
|
catalog_track=(fts>>8)&0xff;
|
||||||
catalog_sector=(fts&0xff);
|
catalog_sector=(fts&0xff);
|
||||||
|
|
||||||
/* Read in Catalog Sector */
|
/* Read in Catalog Sector */
|
||||||
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
||||||
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
|
|
||||||
/* copy over filename */
|
/* copy over filename */
|
||||||
for(x=0;x<strlen(new_name);x++)
|
for(x=0;x<strlen(new_name);x++) {
|
||||||
sector_buffer[CATALOG_FILE_LIST+(catalog_file*CATALOG_ENTRY_SIZE)+
|
sector_buffer[CATALOG_FILE_LIST+
|
||||||
FILE_NAME+x]=new_name[x]^0x80;
|
(catalog_file*CATALOG_ENTRY_SIZE)+
|
||||||
|
FILE_NAME+x]=new_name[x]^0x80;
|
||||||
|
}
|
||||||
|
|
||||||
/* pad out the filename with spaces */
|
/* pad out the filename with spaces */
|
||||||
for(x=strlen(new_name);x<FILE_NAME_SIZE;x++)
|
for(x=strlen(new_name);x<FILE_NAME_SIZE;x++) {
|
||||||
sector_buffer[CATALOG_FILE_LIST+(catalog_file*CATALOG_ENTRY_SIZE)+
|
sector_buffer[CATALOG_FILE_LIST+
|
||||||
FILE_NAME+x]=' '^0x80;
|
(catalog_file*CATALOG_ENTRY_SIZE)+
|
||||||
|
FILE_NAME+x]=' '^0x80;
|
||||||
|
}
|
||||||
|
|
||||||
/* write back modified catalog sector */
|
/* write back modified catalog sector */
|
||||||
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
||||||
result=write(fd,sector_buffer,BYTES_PER_SECTOR);
|
result=write(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
|
|
||||||
if (result<0) fprintf(stderr,"Error on I/O\n");
|
if (result<0) {
|
||||||
|
fprintf(stderr,"Error on I/O\n");
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* undelete a file. fts=entry/track/sector */
|
/* undelete a file. fts=entry/track/sector */
|
||||||
/* FIXME: validate the new filename is valid */
|
/* FIXME: validate the new filename is valid */
|
||||||
static int dos33_undelete_file(int fd,int fts,char *new_name) {
|
static int dos33_undelete_file(int fd,int fts,char *new_name) {
|
||||||
|
|
||||||
int catalog_file,catalog_track,catalog_sector;
|
int catalog_file,catalog_track,catalog_sector;
|
||||||
char replacement_char;
|
char replacement_char;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
catalog_file=fts>>16;
|
catalog_file=fts>>16;
|
||||||
catalog_track=(fts>>8)&0xff;
|
catalog_track=(fts>>8)&0xff;
|
||||||
catalog_sector=(fts&0xff);
|
catalog_sector=(fts&0xff);
|
||||||
|
|
||||||
/* Read in Catalog Sector */
|
/* Read in Catalog Sector */
|
||||||
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
||||||
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
|
|
||||||
/* get the stored track value, and put it back */
|
/* get the stored track value, and put it back */
|
||||||
/* FIXME: should walk file to see if T/s valild */
|
/* FIXME: should walk file to see if T/s valild */
|
||||||
/* by setting the track value to FF which indicates deleted file */
|
/* by setting the track value to FF which indicates deleted file */
|
||||||
sector_buffer[CATALOG_FILE_LIST+(catalog_file*CATALOG_ENTRY_SIZE)]=
|
sector_buffer[CATALOG_FILE_LIST+(catalog_file*CATALOG_ENTRY_SIZE)]=
|
||||||
sector_buffer[CATALOG_FILE_LIST+(catalog_file*CATALOG_ENTRY_SIZE)+
|
sector_buffer[CATALOG_FILE_LIST+
|
||||||
FILE_NAME+29];
|
(catalog_file*CATALOG_ENTRY_SIZE)+
|
||||||
|
FILE_NAME+29];
|
||||||
|
|
||||||
/* restore file name if possible */
|
/* restore file name if possible */
|
||||||
|
replacement_char=0xa0;
|
||||||
|
if (strlen(new_name)>29) {
|
||||||
|
replacement_char=new_name[29]^0x80;
|
||||||
|
}
|
||||||
|
|
||||||
replacement_char=0xa0;
|
sector_buffer[CATALOG_FILE_LIST+(catalog_file*CATALOG_ENTRY_SIZE)+
|
||||||
if (strlen(new_name)>29) replacement_char=new_name[29]^0x80;
|
FILE_NAME+29]=replacement_char;
|
||||||
|
|
||||||
sector_buffer[CATALOG_FILE_LIST+(catalog_file*CATALOG_ENTRY_SIZE)+
|
/* write back modified catalog sector */
|
||||||
FILE_NAME+29]=replacement_char;
|
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
||||||
|
result=write(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
|
|
||||||
/* write back modified catalog sector */
|
if (result<0) fprintf(stderr,"Error on I/O\n");
|
||||||
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
|
||||||
result=write(fd,sector_buffer,BYTES_PER_SECTOR);
|
|
||||||
|
|
||||||
if (result<0) fprintf(stderr,"Error on I/O\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int dos33_delete_file(int fd,int fsl) {
|
static int dos33_delete_file(int fd,int fsl) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int catalog_track,catalog_sector,catalog_entry;
|
int catalog_track,catalog_sector,catalog_entry;
|
||||||
int ts_track,ts_sector;
|
int ts_track,ts_sector;
|
||||||
char file_type;
|
char file_type;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
/* unpack file/track/sector info */
|
/* unpack file/track/sector info */
|
||||||
catalog_entry=fsl>>16;
|
catalog_entry=fsl>>16;
|
||||||
catalog_track=(fsl>>8)&0xff;
|
catalog_track=(fsl>>8)&0xff;
|
||||||
catalog_sector=(fsl&0xff);
|
catalog_sector=(fsl&0xff);
|
||||||
|
|
||||||
/* Load in the catalog table for the file */
|
/* Load in the catalog table for the file */
|
||||||
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
||||||
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
|
|
||||||
file_type=sector_buffer[CATALOG_FILE_LIST+
|
file_type=sector_buffer[CATALOG_FILE_LIST+
|
||||||
(catalog_entry*CATALOG_ENTRY_SIZE)
|
(catalog_entry*CATALOG_ENTRY_SIZE)
|
||||||
+FILE_TYPE];
|
+FILE_TYPE];
|
||||||
if (file_type&0x80) {
|
|
||||||
fprintf(stderr,"File is locked! Unlock before deleting!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (file_type&0x80) {
|
||||||
|
fprintf(stderr,"File is locked! Unlock before deleting!\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
/* get pointer to t/s list */
|
/* get pointer to t/s list */
|
||||||
ts_track=sector_buffer[CATALOG_FILE_LIST+catalog_entry*CATALOG_ENTRY_SIZE+
|
ts_track=sector_buffer[CATALOG_FILE_LIST+
|
||||||
FILE_TS_LIST_T];
|
catalog_entry*CATALOG_ENTRY_SIZE+FILE_TS_LIST_T];
|
||||||
ts_sector=sector_buffer[CATALOG_FILE_LIST+catalog_entry*CATALOG_ENTRY_SIZE+
|
ts_sector=sector_buffer[CATALOG_FILE_LIST+
|
||||||
FILE_TS_LIST_S];
|
catalog_entry*CATALOG_ENTRY_SIZE+FILE_TS_LIST_S];
|
||||||
|
|
||||||
keep_deleting:
|
keep_deleting:
|
||||||
|
|
||||||
|
/* load in the t/s list info */
|
||||||
|
lseek(fd,DISK_OFFSET(ts_track,ts_sector),SEEK_SET);
|
||||||
|
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
|
|
||||||
|
/* Free each sector listed by t/s list */
|
||||||
|
for(i=0;i<TSL_MAX_NUMBER;i++) {
|
||||||
|
/* If t/s = 0/0 then no need to clear */
|
||||||
|
if ((sector_buffer[TSL_LIST+2*i]==0) &&
|
||||||
|
(sector_buffer[TSL_LIST+2*i+1]==0)) {
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dos33_free_sector(fd,sector_buffer[TSL_LIST+2*i],
|
||||||
|
sector_buffer[TSL_LIST+2*i+1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* load in the t/s list info */
|
/* free the t/s list */
|
||||||
lseek(fd,DISK_OFFSET(ts_track,ts_sector),SEEK_SET);
|
dos33_free_sector(fd,ts_track,ts_sector);
|
||||||
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
|
||||||
|
|
||||||
/* Free each sector listed by t/s list */
|
/* Point to next t/s list */
|
||||||
for(i=0;i<TSL_MAX_NUMBER;i++) {
|
ts_track=sector_buffer[TSL_NEXT_TRACK];
|
||||||
/* If t/s = 0/0 then no need to clear */
|
ts_sector=sector_buffer[TSL_NEXT_SECTOR];
|
||||||
if ((sector_buffer[TSL_LIST+2*i]==0) && (sector_buffer[TSL_LIST+2*i+1]==0)) {
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dos33_free_sector(fd,sector_buffer[TSL_LIST+2*i],sector_buffer[TSL_LIST+2*i+1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* free the t/s list */
|
/* If more tsl lists, keep looping */
|
||||||
dos33_free_sector(fd,ts_track,ts_sector);
|
if ((ts_track==0x0) && (ts_sector==0x0)) {
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
goto keep_deleting;
|
||||||
|
}
|
||||||
|
|
||||||
/* Point to next t/s list */
|
/* Erase file from catalog entry */
|
||||||
ts_track=sector_buffer[TSL_NEXT_TRACK];
|
|
||||||
ts_sector=sector_buffer[TSL_NEXT_SECTOR];
|
|
||||||
|
|
||||||
/* If more tsl lists, keep looping */
|
/* First reload proper catalog sector */
|
||||||
if ((ts_track==0x0) && (ts_sector==0x0)) {
|
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
||||||
}
|
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
else {
|
|
||||||
goto keep_deleting;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Erase file from catalog entry */
|
/* save track as last char of name, for undelete purposes */
|
||||||
|
sector_buffer[CATALOG_FILE_LIST+(catalog_entry*CATALOG_ENTRY_SIZE)+
|
||||||
|
(FILE_NAME+FILE_NAME_SIZE-1)]=
|
||||||
|
sector_buffer[CATALOG_FILE_LIST+(catalog_entry*CATALOG_ENTRY_SIZE)];
|
||||||
|
|
||||||
/* First reload proper catalog sector */
|
/* Actually delete the file */
|
||||||
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
/* by setting the track value to FF which indicates deleted file */
|
||||||
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
|
sector_buffer[CATALOG_FILE_LIST+(catalog_entry*CATALOG_ENTRY_SIZE)]=0xff;
|
||||||
|
|
||||||
/* save track as last char of name, for undelete purposes */
|
/* re seek to catalog position and write out changes */
|
||||||
sector_buffer[CATALOG_FILE_LIST+(catalog_entry*CATALOG_ENTRY_SIZE)+
|
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
||||||
(FILE_NAME+FILE_NAME_SIZE-1)]=
|
result=write(fd,sector_buffer,BYTES_PER_SECTOR);
|
||||||
sector_buffer[CATALOG_FILE_LIST+(catalog_entry*CATALOG_ENTRY_SIZE)];
|
|
||||||
|
|
||||||
/* Actually delete the file */
|
if (result<0) fprintf(stderr,"Error on I/O\n");
|
||||||
/* by setting the track value to FF which indicates deleted file */
|
|
||||||
sector_buffer[CATALOG_FILE_LIST+(catalog_entry*CATALOG_ENTRY_SIZE)]=0xff;
|
|
||||||
|
|
||||||
/* re seek to catalog position and write out changes */
|
return 0;
|
||||||
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
|
|
||||||
result=write(fd,sector_buffer,BYTES_PER_SECTOR);
|
|
||||||
|
|
||||||
if (result<0) fprintf(stderr,"Error on I/O\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dump_sector(void) {
|
static int dump_sector(void) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user