📄 rmfsapi.c
字号:
absoluteOff = offset + fileTab[i].offset; } else if (whence == PCSL_FILE_SEEK_END) { absoluteOff = offset + fileTab[i].size; } fileTab[fileIndex].offset = absoluteOff; return absoluteOff;}/** * FUNCTION: rmfsFileSize() * TYPE: public operation * OVERVIEW: quiry the size of the file. * * * INTERFACE: * parameters: identifier: file descriptor * * * returns: >=0 file size; success; < 0 failure * */jint rmfsFileSize(jint identifier){ int i; int fileIndex = 0; /* Search the File Open Table to find the matched record */#ifdef TRACE_DEBUG printf("rmfsFileSize: identifer: %d \n", identifier);#endif for (i = 0; i < MAX_OPEN_FILE_NUM; i++) { if (fileTab[i].handle == identifier) { fileIndex = i; break; } } if (i >= MAX_OPEN_FILE_NUM) { return -1; } return fileTab[fileIndex].size;}/** * FUNCTION: rmfsTruncate() * TYPE: public operation * OVERVIEW: truncate the size of an open file in storage. * * * INTERFACE: * parameters: identifier: file descriptor * size: new file size * * * returns: >=0 file size; success; < 0 failure * */jint rmfsTruncate(jint identifier, jint size){ int i; int fileIndex = 0; short nameID; jint fileSize = 0; RMFS_BOOLEAN freeSucceedBlock = RMFS_FALSE; /* Search the File Open Table to find the matched record */#ifdef TRACE_DEBUG printf("rmfsTruncate: identifer: %d size: %d\n", identifier, size);#endif for (i = 0; i < MAX_OPEN_FILE_NUM; i++) { if (fileTab[i].handle == identifier) { fileIndex = i; break; } } if (i >= MAX_OPEN_FILE_NUM) { return -1; } nameID = fileTab[fileIndex].nameID; for (i = 0; i < MAX_DATABLOCK_NUMBER; i++) { if (rmfsDataBlockHdrArray[i].identifier == nameID) { if (freeSucceedBlock == RMFS_TRUE) { rmfsFreeDataBlock(i); continue; } fileSize += rmfsDataBlockHdrArray[i].dataSize; if (((unsigned int)(fileSize - size) > sizeof(_RmfsBlockHdr)) || ((rmfsDataBlockHdrArray[i].size - (unsigned int)rmfsDataBlockHdrArray[i].dataSize) >= sizeof(_RmfsBlockHdr))) { rmfsSplitBlock(i, size - (fileSize - rmfsDataBlockHdrArray[i].dataSize)); } if (fileSize >= size) { freeSucceedBlock = RMFS_TRUE; } } } return 0;}/** * FUNCTION: rmfsFileExist() * TYPE: public operation * OVERVIEW: check if the file exist in RMFS storage. * * * INTERFACE: * parameters: filename: file nmae * status: indicator if the file exists. * * * returns: none * */void rmfsFileExist(const char *filename, jint *status){ uchar nameID = 0;#ifdef TRACE_DEBUG printf("rmfsFileExist: filename: %s \n", filename);#endif if (((searchNameTabByString(filename, &nameID)) < 0) || (nameID == 0)) { *status = 0; return; } else if (nameID > 0) { *status = 1; return; } else { *status = -1; return; } return;}/** * FUNCTION: rmfsFileExist() * TYPE: public operation * OVERVIEW: check if the DIR exist in RMFS storage. * * * INTERFACE: * parameters: filename: file nmae * status: indicator if the file exists. * * * returns: none * */void rmfsDirExist(char *dirname, jint *status){ uchar nameID = 0;#ifdef TRACE_DEBUG printf("rmfsDirExist: dirname: %s \n", dirname);#endif if (((searchNameTabByString(dirname, &nameID)) < 0) || (nameID == 0)) { *status = 0; return; } else if (nameID > 0) { *status = 1; return; } else { *status = -1; return; } return;}/** * FUNCTION: rmfsOpendir() * TYPE: public operation * OVERVIEW: opens and returns a directory stream for reading the directory whose file name is dirname. * Note: This function isn't ready in this phase. A workaround is used to meet AMS requirements. * * INTERFACE: * parameters: dirname: DIR name * * returns: DIR DIR stream. * */DIR* rmfsOpendir(const char *dirname){#ifdef TRACE_DEBUG printf("rmfsOpendir: dirname: %s \n", dirname);#endif return (DIR*) dirname;}/** * FUNCTION: rmfsClosedir() * TYPE: public operation * OVERVIEW: closes the directory stream dirstream. * Note: This function isn't ready in this phase. A workaround is used to meet AMS requirements. * * * INTERFACE: * parameters: dirname: DIR name * * returns: >=0 success; < 0 failure * */jint rmfsClosedir(char *dirname){#ifdef TRACE_DEBUG printf("rmfsClosedir: dirname: %s \n", dirname);#endif return 0;}/** * FUNCTION: rmfsRename() * TYPE: public operation * OVERVIEW: updates the filename from old filename to new file name. * * * INTERFACE: * parameters: oldFilename: old file name * newFilename: new file name * * * returns: >=0 file size; success; < 0 failure * */jint rmfsRename(const char *oldFilename, const char *newFilename){ uchar nameID = 0; uchar newFileID; jint fileSize; jint nameTabAddr; _RmfsNameTabHdr nameRecord;#ifdef TRACE_DEBUG printf("rmfsRename: oldFilename: %s newFilename: %s\n", oldFilename, newFilename);#endif /* check for null and empty strings */ if(newFilename == NULL) { return -1; }; if(strlen(newFilename) == 0) { return -1; }; if (((nameTabAddr = searchNameTabByString(oldFilename, &nameID)) < 0) || (nameID == 0)) { return -1; } else { ReadDataFromStorage(&nameRecord, nameTabAddr, sizeof(_RmfsNameTabHdr)); if((newFileID = rmfsNewNameTable(newFilename)) == 0) { return -1; }; if (((nameTabAddr = searchNameTabByString(newFilename, &nameID)) < 0) || (nameID == 0)) { return -1; } else { nameID = nameRecord.identifier; fileSize = nameRecord.size; ReadDataFromStorage(&nameRecord, nameTabAddr, sizeof(_RmfsNameTabHdr)); nameRecord.identifier = nameID; nameRecord.size = fileSize; WriteDataToStorage(&nameRecord, nameTabAddr, sizeof(_RmfsNameTabHdr)); delNameTabByString(oldFilename); } } return 0;}/** * FUNCTION: rmfsFileEof() * TYPE: public operation * OVERVIEW: Check if the file reaches the end. * * * INTERFACE: * parameters: identifier: file descriptor * * returns: >=0 file size; success; < 0 failure * */jint rmfsFileEof(jint handle){ if (fileTab[handle].size == fileTab[handle].offset) { return 1; } else { return 0; }}/** * FUNCTION: rmfsFileStartWith() * TYPE: public operation * OVERVIEW: search the file whose filename starts with input string. * * * INTERFACE: * parameters: filename: input string * * * returns: == NULL no matched file; otherwise: Full filename of the matched item. * */char *rmfsFileStartWith(const char *filename){ uchar nameID; char *fullFilename = NULL; jint nameAddress;#ifdef TRACE_DEBUG printf("rmfsFileStartWith: filename: %s \n", filename);#endif nameAddress = searchNameTabStartWith(filename, &nameID); if ((nameAddress > 0) && (nameID > 0)) { fullFilename = (char *) (nameAddress + sizeof(_RmfsNameTabHdr));#ifdef TRACE_DEBUG printf("Return Full Filename %s \n", fullFilename);#endif return fullFilename; } else { return NULL; }}/** * FUNCTION: rmfsGetUsedSpace() * TYPE: public operation * OVERVIEW: Get the used space size in RMFS * INTERFACE: * None * * returns: the byte numer was used * */int rmfsGetUsedSpace(){ return getUsedSpace(); }/** * FUNCTION: rmfsGetFreeSpace() * TYPE: public operation * OVERVIEW: Get the free space size in RMFS * INTERFACE: * None * * returns: the byte numer was used * */int rmfsGetFreeSpace(){ return getFreeSpace();}/** * FUNCTION: rmfsMkdir() * TYPE: public operation * OVERVIEW: create a Dir in the rmfs File System * INTERFACE: * None * * returns: >=0 Success, -1 failure * */int rmfsMkdir(){ return 0;}/** * FUNCTION: rmfsRmdir() * TYPE: public operation * OVERVIEW: delete a existed Dir in the rmfs File System * INTERFACE: * None * * returns: >=0 Success, -1 failure * */int rmfsRmdir(){ return 0;}#ifdef __cplusplus}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -