📄 truncate.c
字号:
/*************************************************************
File Name: truncate.C *
**************************************************************
Programmer: Huang Giun-Haur
Last Modified Date: 1999/06/15
Compiler : Gnu Cross-compiler
Platform : X86 protection mode
Usage :
int rename(const char *oldname, const char *newname)
*************************************************************/
/*************************************************************
Header Files
**************************************************************/
#include <sys/syscall.h>
//#include "../../RDebug/include/RDebug.h"
#include "../../FileSys/include/FileSys.h"
#include "../include/fat1x.h"
#include "../include/cluster.h"
#ifdef FAT_ID
/* init.c */
extern unsigned long FATBytesPerCluster[];
extern unsigned char FATType[];
extern int FATDirSemaphoreID;
extern unsigned short FATEndOfChain[];
/* fat1x.c */
extern struct FAT_FILE **FATHandleTable;
/*************************************************************
Function : FAT_truncate
Description:
cut a file to the given size
Input:
fHandle - the file handle of the target file
size - the new size of the file in bytes
Output:
0 SUCCESS
-1 FAILURE
**************************************************************/
int FAT_truncate(int fHandle, unsigned long size)
{
unsigned short nThCluster;
unsigned short traceCluster;
unsigned short actualCluster;
unsigned short freeCluster;
short drive;
#ifdef FAT1X_DEBUG
SprintStringLn("[FAT_truncate]");
#endif
FATErrno = 0;
if (InitFAT == FALSE)
{
FATErrno = ERROR_FILE_SYSTEM_NOT_INIT;
return -1;
}
if ((fHandle < 0) || (fHandle >= MAX_OPEN_FILE) || (FATHandleTable[fHandle] == NULL))
{
FATErrno = ERROR_INVALID_HANDLE;
return -1;
}
if (FATHandleTable[fHandle]->deviceID != FAT_ID)
{
FATErrno = ERROR_INVALID_DEVICE;
return -1;
}
if ( (FATHandleTable[fHandle]->fileFlag & O_RDWR) == 0)
{
FATErrno = ERROR_FILE_FLAG;
return -1;
}
sc_waitSemaphore(FATDirSemaphoreID);
/**** added by chilong 02/05/2002 ****/
if (size == 0)
{
FATHandleTable[fHandle]->dirEntry.fsize = 0;
FATHandleTable[fHandle]->fpos = 0;
FAT_clear_fat_cluster_chain(fHandle);
FATHandleTable[fHandle]->dirEntry.startCluster = 0;
FAT_update_file_info(FATHandleTable[fHandle]); //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -