From d750094ed1a04b250cc0c9b6ab3b17bb61ddd7e6 Mon Sep 17 00:00:00 2001 From: Ryan Brooks Date: Fri, 12 Mar 2021 15:28:47 -0600 Subject: [PATCH] Fixed implicit declarations --- proj3-clean.c | 163 ++++++++++++++++++++++++++------------------------ 1 file changed, 85 insertions(+), 78 deletions(-) diff --git a/proj3-clean.c b/proj3-clean.c index edacc98..b7ee506 100644 --- a/proj3-clean.c +++ b/proj3-clean.c @@ -217,6 +217,7 @@ int firstClusterSector(struct BS_BPB *bs) { return Partition_LBA_Begin + bs->BPB_RsvdSecCnt + (bs->BPB_NumFATs * bs->BPB_SecPerClus); } + //----------------OPEN FILE/DIRECTORY TABLES----------------- /* create a new file to be put in the file descriptor table @@ -637,6 +638,18 @@ uint32_t byteOffsetofDirectoryEntry(struct BS_BPB * bs, uint32_t clusterNum, int return (dataAddress + offset); } + +/* description: feed this a cluster that's a member of a chain and this + * sets your environment variable "io_writeCluster" to the last in that + * chain. The thinking is this is where you'll write in order to grow + * that file. before writing to cluster check with FAT_findNextOpenEntry() + * to see if there's space or you need to extend the chain using FAT_extendClusterChain() + */ +int FAT_setIoWriteCluster(struct BS_BPB * bs, uint32_t clusterChainMember) { + environment.io_writeCluster = getLastClusterInChain(bs, clusterChainMember); + return 0; +} + /* This is the workhorse. It is used for ls, cd, filesearching. * Directory Functionality: * It is used to perform cd, which you use by setting . if is set it uses @@ -897,77 +910,26 @@ int FAT_freeClusterChain(struct BS_BPB * bs, uint32_t firstClusterOfChain){ } -/* description: feed this a cluster that's a member of a chain and this - * sets your environment variable "io_writeCluster" to the last in that - * chain. The thinking is this is where you'll write in order to grow - * that file. before writing to cluster check with FAT_findNextOpenEntry() - * to see if there's space or you need to extend the chain using FAT_extendClusterChain() - */ -int FAT_setIoWriteCluster(struct BS_BPB * bs, uint32_t clusterChainMember) { - environment.io_writeCluster = getLastClusterInChain(bs, clusterChainMember); - return 0; -} - -/* description: this will write a new entry to . if that cluster - * is full it grows the cluster chain and write the entry in the first spot - * of the new cluster. if is set this automatically writes both - * '.' and '..' to offsets 0 and 1 of - * - */ -int writeFileEntry(struct BS_BPB * bs, struct DIR_ENTRY * entry, uint32_t destinationCluster, bool isDotEntries) { - int dataAddress; - int freshCluster; - FILE* f = fopen(environment.imageName, "r+"); - checkForFileError(f); - if(isDotEntries == FALSE) { - if((dataAddress = FAT_findNextOpenEntry(bs, destinationCluster)) != -1) {//-1 means current cluster is at capacity - fseek(f, dataAddress, 0); - fwrite (entry , 1 , sizeof(struct DIR_ENTRY) , f ); - } else { - freshCluster = FAT_extendClusterChain(bs, destinationCluster); - dataAddress = FAT_findNextOpenEntry(bs, freshCluster); - fseek(f, dataAddress, 0); - fwrite (entry , 1 , sizeof(struct DIR_ENTRY) , f ); - } - } else { - struct DIR_ENTRY dotEntry; - struct DIR_ENTRY dotDotEntry; - makeSpecialDirEntries(&dotEntry, &dotDotEntry, destinationCluster, environment.pwd_cluster); - //seek to first spot in new dir cluster chin and write the '.' entry - dataAddress = byteOffsetofDirectoryEntry(bs, destinationCluster, 0); - fseek(f, dataAddress, 0); - fwrite (&dotEntry , 1 , sizeof(struct DIR_ENTRY) , f ); - //seek to second spot in new dir cluster chin and write the '..' entry - dataAddress = byteOffsetofDirectoryEntry(bs, destinationCluster, 1); - fseek(f, dataAddress, 0); - fwrite (&dotDotEntry , 1 , sizeof(struct DIR_ENTRY) , f ); - } - fclose(f); - return 0; -} - - - /* description: takes a directory entry and all the necesary info - and populates the entry with the info in a correct format for - insertion into a disk. + and populates the entry with the info in a correct format for + insertion into a disk. */ int createEntry(struct DIR_ENTRY * entry, - const char * filename, - const char * ext, - int isDir, - uint32_t firstCluster, - uint32_t filesize, + const char * filename, + const char * ext, + int isDir, + uint32_t firstCluster, + uint32_t filesize, bool emptyAfterThis, bool emptyDirectory) { //set the same no matter the entry entry->r1 = 0; - entry->r2 = 0; - entry->crtTime = 0; - entry->crtDate = 0; - entry->accessDate = 0; - entry->lastWrTime = 0; - entry->lastWrDate = 0; + entry->r2 = 0; + entry->crtTime = 0; + entry->crtDate = 0; + entry->accessDate = 0; + entry->lastWrTime = 0; + entry->lastWrDate = 0; if(emptyAfterThis == FALSE && emptyDirectory == FALSE) { //if both are false int x; @@ -990,10 +952,10 @@ int createEntry(struct DIR_ENTRY * entry, if(isDir == TRUE) { entry->fileSize = 0; entry->attributes = ATTR_DIRECTORY; - } else { + } else { entry->fileSize = filesize; entry->attributes = ATTR_ARCHIVE; - } + } return 0; //stops execution so we don't flow out into empty entry config code below } else if(emptyAfterThis == TRUE) { //if this isn't true, then the other must be @@ -1010,29 +972,74 @@ int createEntry(struct DIR_ENTRY * entry, for(x = 1; x < 11; x++) entry->filename[x] = 0x00; - entry->loCluster[0] = 0x00; + entry->loCluster[0] = 0x00; entry->loCluster[1] = 0x00; entry->hiCluster[0] = 0x00; entry->hiCluster[1] = 0x00; - entry->attributes = 0x00; - entry->fileSize = 0; - + entry->attributes = 0x00; + entry->fileSize = 0; + return 0; } -/* description: take two entries and cluster info and populates them with - * '.' and '..' entriy information. The entries are ready for writing to + + +/* description: take two entries and cluster info and populates them with + * '.' and '..' entriy information. The entries are ready for writing to * the disk after this. helper function for mkdir() */ int makeSpecialDirEntries(struct DIR_ENTRY * dot, - struct DIR_ENTRY * dotDot, - uint32_t newlyAllocatedCluster, - uint32_t pwdCluster ) { - createEntry(dot, ".", "", TRUE, newlyAllocatedCluster, 0, FALSE, FALSE); - createEntry(dotDot, "..", "", TRUE, pwdCluster, 0, FALSE, FALSE); - return 0; + struct DIR_ENTRY * dotDot, + uint32_t newlyAllocatedCluster, + uint32_t pwdCluster ) { + createEntry(dot, ".", "", TRUE, newlyAllocatedCluster, 0, FALSE, FALSE); + createEntry(dotDot, "..", "", TRUE, pwdCluster, 0, FALSE, FALSE); + return 0; +} + +/* description: this will write a new entry to . if that cluster + * is full it grows the cluster chain and write the entry in the first spot + * of the new cluster. if is set this automatically writes both + * '.' and '..' to offsets 0 and 1 of + * + */ +int writeFileEntry(struct BS_BPB * bs, struct DIR_ENTRY * entry, uint32_t destinationCluster, bool isDotEntries) { + int dataAddress; + int freshCluster; + FILE* f = fopen(environment.imageName, "r+"); + checkForFileError(f); + if(isDotEntries == FALSE) { + if((dataAddress = FAT_findNextOpenEntry(bs, destinationCluster)) != -1) {//-1 means current cluster is at capacity + fseek(f, dataAddress, 0); + fwrite (entry , 1 , sizeof(struct DIR_ENTRY) , f ); + } else { + freshCluster = FAT_extendClusterChain(bs, destinationCluster); + dataAddress = FAT_findNextOpenEntry(bs, freshCluster); + fseek(f, dataAddress, 0); + fwrite (entry , 1 , sizeof(struct DIR_ENTRY) , f ); + } + } else { + struct DIR_ENTRY dotEntry; + struct DIR_ENTRY dotDotEntry; + makeSpecialDirEntries(&dotEntry, &dotDotEntry, destinationCluster, environment.pwd_cluster); + //seek to first spot in new dir cluster chin and write the '.' entry + dataAddress = byteOffsetofDirectoryEntry(bs, destinationCluster, 0); + fseek(f, dataAddress, 0); + fwrite (&dotEntry , 1 , sizeof(struct DIR_ENTRY) , f ); + //seek to second spot in new dir cluster chin and write the '..' entry + dataAddress = byteOffsetofDirectoryEntry(bs, destinationCluster, 1); + fseek(f, dataAddress, 0); + fwrite (&dotDotEntry , 1 , sizeof(struct DIR_ENTRY) , f ); + } + fclose(f); + return 0; } + + + + + /* returns offset of the entry, in the pwd * if found return the offset, if not return -1 */