/* truncate a spase file * This program truncates a file at the point where it becomes sparse * CAUTION: * MANY DATABASE FILES ARE SPARSE BY DESIGN * USE ONLY ON THOSE FILES YOU **KNOW** SHOULD NOT BE SPARSE * * */ #include #include #include #include #include #include #include #include #define OS_FILE_HANDLE 0 #define NW_FILE_HANDLE 1 #define FALSE 0 #define TRUE 1 #define BYTE_BUFFER_SIZE 512 #define BIT_BUFFER_SIZE BYTE_BUFFER_SIZE*8 typedef int flag; int iVerbose=0; int iDebug=0; int iIgnore=0; int iTruncate=0; NWCONN_HANDLE ConnectionHandle; NWDIR_HANDLE DirectoryHandle; char PathName[256]; char DirPathName[256]; char strFileName[20]; int fhIn,fhOut; NWINT16 fileFlag=OS_FILE_HANDLE; DWORD dwOffset; NWNUM HowMuchToCopy; DWORD BlockSize; BYTE BitMap[512]; NWNUM BytesCopied; NWNUM NWFAR *pBytesCopied=&BytesCopied; flag fCopying; int ccode, i , iLB; long lFileSize; long lNumBits; static unsigned int BitMask[] = { 1,2,4,8,16,32,64,128 }; void DoFileArgs(char *UserPathName); void TruncateSparseFile(void); flag IsFileSparse(void); void Usage(void) { fprintf(stderr,"Usage:\n\ttsparse [-d] [-v] [-i] {file-list}\n"); fprintf(stderr,"\t\t-d : Debug program\n"); fprintf(stderr,"\t\t-v : verbose output\n"); fprintf(stderr,"\t\t-t : truncate sparse files\n"); fprintf(stderr,"\t\t-i : ignore errors in user input\n\n"); fprintf(stderr,"You MUST read the TSPARSE.TXT file that came with this program\n"); fprintf(stderr,"before using the '-t' option.\n"); exit(2); }; void main(int argc,char *argv[]) { int i; printf("[TSPARSE Version 1.10 Copyright (C) 1994 University of Salford]\n"); ccode=NWCallsInit(NULL,NULL); if (ccode) { fprintf(stderr,"NWCALLS Initialisation failed (0x%04x)\n",ccode); exit(1); }; for (i=1;i BIT_BUFFER_SIZE) lNumBits = BIT_BUFFER_SIZE; if (iDebug) fprintf(stderr,"check %ld bits\n",lNumBits); for(i=0;i