static unsigned my_write( int hdl, void *buff, unsigned len ) { unsigned sent; if( _dos_write( hdl, buff, len, &sent ) != 0 ) return( -1 ); return( sent ); }
/* Copies one file to another (both specified by path). Dynamically * allocates memory for the file buffer. Returns TRUE if successful, * or FALSE if unsuccessful. This function uses _dos_ functions only; * standard C functions are not used. */ BOOL fastcopy( HANDLE hfSrcParm, HANDLE hfDstParm ) { char _far *buf = NULL; unsigned segbuf, count; /* Attempt to dynamically allocate all of memory (0xffff paragraphs). * This will fail, but will return the amount actually available * in segbuf. Then allocate this amount. */ if (_dos_allocmem( 0xffff, &segbuf ) ) { count = segbuf; if(_dos_allocmem( count, &segbuf ) ) return FALSE; } FP_SEG( buf ) = segbuf; /* Read and write until there is nothing left. */ while( count ) { /* Read and write input. */ if( (_dos_read( hfSrcParm, buf, count, &count )) ){ _dos_freemem( segbuf ); return FALSE; } if( (_dos_write( hfDstParm, buf, count, &count )) ){ _dos_freemem( segbuf ); return FALSE; } } /* Free memory. */ _dos_freemem( segbuf ); return TRUE; }
int write(int fd, const void *buf, unsigned count) { unsigned bytes; int result = _dos_write(fd, buf, count, &bytes); return (result == 0 ? bytes : -1); }
void putstring( char __far *str ) { unsigned bytes; extern unsigned _dos_write( int handle, void __far *buffer, unsigned count, unsigned *bytes ); while( *str ) { _dos_write( 1, str, 1, &bytes ); ++str; } }
/* Truncate a FIAD file at secsused. */ int trunc(int handle, word len) { struct tifile *ff=&tifiles[handle]; unsigned temp; lseek(ff->doshandle,len*256L+128,SEEK_SET); _dos_write(ff->doshandle,0l,0,&temp); return 1; }
int main( int argc, const char** argv ) { char buffer[BUF_SIZE]; int src_handle, dst_handle; unsigned int value, red, written; puts("SIMPLE FILE COPIER\n"); if( argc != 3 ) { printf( "TYPE COPIER <SRC_FILE> <DST_FILE>" ); return 1; } printf( "%s -> %s", argv[1], argv[2] ); src_handle = open16l( argv[1], O_RDONLY_16L ); if ( src_handle < 0 ) { printf( "\n%s: %s", argv[1], strerror( -src_handle ) ); return 2; } dst_handle = open16l( argv[2], O_CREAT_TRUNC_16L ); if ( dst_handle < 0 ) { _dos_close( src_handle ); printf( "\n%s: %s", argv[2], strerror( -dst_handle ) ); return 2; } do { value = _dos_read( src_handle, buffer, sizeof( buffer ), &red ); if( value != 0 ) printf( ": ERROR reading file" ); if( value == 0 && red > 0 ) { value = _dos_write( dst_handle, buffer, red, &written ); if( value != 0 || written < red ) printf( ": ERROR writing file" ); } } while( value == 0 && red > 0 ); _dos_close( src_handle ); _dos_close( dst_handle ); return 0; }
int main( void ) { dword FarFreeMemoryAtStart=(unsigned long)farcoreleft(); printf("\n\n Reliable file system" "\n by" "\n Jarda & Dvorka" "\n" "\n Compiled at %s, %s\n", __DATE__, __TIME__ ); printf( " Starting with far heap: %luB \n", FarFreeMemoryAtStart ); randomize(); //- work with file system - #ifdef CREATE_EVERYTHING_NEW InitializeSimulation( TRUE, TRUE ); // create everything new FSCreatMasterBoot( 0x80, 512, 1 ); FSCreatMasterBoot( 0x81, 512, 1 ); FSCreatMasterBoot( 0x82, 512, 1 ); // data stripe FSCreatPartition( 0x80, 1, 0, 500, ACTIVE_PARTITION ); // parity stripe FSCreatPartition( 0x80, 2, 501, 1023, NONACTIVE_PARTITION ); // data stripe FSCreatPartition( 0x81, 1, 0, 500, ACTIVE_PARTITION ); // swap party FSCreatPartition( 0x81, 2, 501, 1023, NONACTIVE_PARTITION ); // data stripe FSCreatPartition( 0x82, 1, 0, 500, ACTIVE_PARTITION ); // swap party FSCreatPartition( 0x82, 2, 501, 1023, NONACTIVE_PARTITION ); // format parties FSFormat( 0x80, 1, RFS_DATA ); FSFormat( 0x80, 2, RFS_DATA ); FSFormat( 0x81, 1, RFS_DATA ); FSFormat( 0x81, 2, RFS_SWAP ); FSFormat( 0x82, 1, RFS_DATA ); FSFormat( 0x82, 2, RFS_SWAP ); #else InitializeSimulation(); // only init handles,... #endif // init file system ( inside init of cache ) FSOpenFileSystem( SWAP_ON, CACHE_ON, 10000lu ); #ifdef CACHE_TEST; word PackageID=0, GetNumber=0, i; dword Logical, Free; void far *Buffer=farmalloc(10*512); if( !Buffer ) exit(0); // allocates && creates package ( 0x81 or 1 - it has same effect ) CacheManAllocateSector( 0x81, 1, 0, 1, Logical, GetNumber, PackageID, FPACK_CREAT ); word j; word Number; // PackageID set in previous function for( i=1; i<=5; i++ ) { // allocate allocates < logical, logical+6 > CacheManAllocateSector( 1, 1, 0lu, 7, Logical, GetNumber, PackageID, FPACK_ADD ); printf("\n Get number: %u", GetNumber ); // init buffer for save for( j=0; j<10*512; j++ ) ((byte far * )Buffer)[j]=0xCC; if( random(5) ) // probably add CacheManSaveSector( 1, 1, Logical, 7, PackageID, FPACK_ADD, Buffer ); else CacheManSaveSector( 1, 1, Logical, 7, PackageID, FPACK_CREAT, Buffer ); // load what's written from cache ( something ) // Number=(word)random(7) + 1u; Number=7; CacheManLoadSector( 1, 1, Logical, Number, PackageID, FPACK_ADD, Buffer ); if( !random(10) ) // probably not commit { if( random(2) ) CacheManCommitPackage( PackageID, FPACK_NOTHING ); // commit else { CacheManCommitPackage( PackageID, FPACK_DELETE ); // commit && del pack // create new PackID because in alloc and save used! CacheManAllocateSector( 1, 1, 0lu, 7, Logical, GetNumber, PackageID, FPACK_CREAT ); printf("\n Get number: %u", GetNumber ); } } // print free space on device GetPartyFreeSpace( 0x81, 1, Free ); GetPartyFreeSpace( 0x81, 2, Free ); printf("\n\n ----->"); } farfree(Buffer); // UndoAlfLog( 0x81, 1, "TEST.ALF" ); // RecoverUsingCml( "TEST.CML" ); // RollbackOkaLog( 1, 1, "11TEST.OKA" ); // RecoverParty( 1, 1 ); #endif #ifdef CACHE_EXAMPLE; int Handle; word PackageID, GetNumber=0, i, j, bytes; dword Previous=0, Logical1, Logical2, Logical; #define BUFFER_SIZE 512 void far *Buffer=farmalloc(BUFFER_SIZE); if( !Buffer ) { printf("All1 Error..");exit(0); } void far *BufferOut=farmalloc(BUFFER_SIZE); if( !BufferOut ) { printf("All2 Error..");exit(0); } // now read some nice data to buffer if ((Handle = open("input.txt", O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD )) == -1) { printf("Error.."); return ERR_FS_FATAL_ERROR; } if( _dos_read( Handle, Buffer, BUFFER_SIZE, &bytes) != 0 ) { printf("Error.."); return ERR_FS_FATAL_ERROR; } close(Handle); // --- begin work ------------------------------------------------ //* for(i=0; i<512; i++ ) ((byte far *)Buffer)[i]=0xAA; CacheManAllocateSector( 1, 1, 0, 1, Logical1, GetNumber, PackageID, FPACK_CREAT ); CacheManSaveSector( 1, 1, Logical1, 1u, PackageID, FPACK_ADD, Buffer ); for(i=0; i<512; i++ ) ((byte far *)Buffer)[i]=0xBB; CacheManAllocateSector( 1, 1, 0, 1, Logical2, GetNumber, PackageID, FPACK_ADD ); CacheManSaveSector( 1, 1, Logical2, 1u, PackageID, FPACK_ADD, Buffer ); //*/ CacheManCompleteCommit( FPACK_DELETE ); //* for(i=0; i<512; i++ ) ((byte far *)BufferOut)[i]=0xEE; CacheManLoadSector( 1, 1, Logical1, 1u, PackageID, FPACK_CREAT, BufferOut ); if ((Handle = open("AA", O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD )) == -1) { printf("Error.."); return ERR_FS_FATAL_ERROR; } if( _dos_write( Handle, BufferOut, BUFFER_SIZE, &bytes) != 0 ) { printf("Error.."); return ERR_FS_FATAL_ERROR; } close(Handle); // --- for(i=0; i<512; i++ ) ((byte far *)BufferOut)[i]=0xEE; CacheManLoadSector( 1, 1, Logical2, 1u, PackageID, FPACK_ADD, BufferOut ); if ((Handle = open("BB", O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD )) == -1) { printf("Error.."); return ERR_FS_FATAL_ERROR; } if( _dos_write( Handle, BufferOut, BUFFER_SIZE, &bytes) != 0 ) { printf("Error.."); return ERR_FS_FATAL_ERROR; } close(Handle); //*/ // --- end work ------------------------------------------------ // save buffer content ------------------------------------------------ if ((Handle = open("output2.txt", O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD )) == -1) { printf("Error.."); return ERR_FS_FATAL_ERROR; } if( _dos_write( Handle, BufferOut, BUFFER_SIZE, &bytes) != 0 ) { printf("Error.."); return ERR_FS_FATAL_ERROR; } close(Handle); farfree(Buffer); farfree(BufferOut); #endif #ifdef STRIP_EXAMPLE #define BUFFER_SIZE 512 #define SECTOR 31 byte far *Buffer=(byte far *)farmalloc(BUFFER_SIZE); if( !Buffer ) { printf("All1 Error..");exit(0); } printf("\n\n\n Test: "); ReadLogicalSector( 1, SECTOR, Buffer, 1 ); Buffer[0]=0xAB; CLASSICWriteLogicalSector( 1, SECTOR, Buffer, 1 ); ReadLogicalSector( 1, SECTOR, Buffer, 1 ); ReadLogicalSector( 1, SECTOR, Buffer, 1 ); farfree(Buffer); #endif FSShutdownFileSystem(); // contains complete commit //------------------------- printf("\n\n Memory statistic:"); if( FarFreeMemoryAtStart!=((unsigned long) farcoreleft())) { printf("\n Deallocation ERROR:"); Beep(); Beep(); Beep(); } else Beep(); printf( "\n Far free at start: %lu" "\n and now : %lu" "\n\n" , FarFreeMemoryAtStart, ((unsigned long) farcoreleft()) ); printf("\n Bye! \n\n"); return 0; }
void TOutputDevice::writeBytes( void *buffer, ushort len ) { unsigned temp; _dos_write( encoder, buffer, len, &temp ); }