public int getFileSize(CpmFile file) { int size = 0; FCB fcb = new FCB( ); for (int i = 0; i < file.GetFCBCount( ); i++) { readFCB(file.GetFCBAt(i), fcb); int ex = (fcb.getEX( ) & 0x1f) & ~dpb.exm; int record = fcb.getRC( ) & 0xff; size = ex * 128 + ((dpb.exm & fcb.getEX( )) + 1) * 128 - (128 - record); //System.out.println("name "+file.name+" ext "+ex+" record "+record); } return(size); }
public void putFile(int user, String name, Stream ist) { FCB fcb = new FCB( ); int i, j; int entry; int blockCount = 0; int record = 0; CpmFile file = searchFile(user, name); if (file != null) { throw new Exception(name + " Already exist"); } file = new CpmFile(dpb, user, name); fcb.Clear( ); fcb.SetUser(user); fcb.SetFileName(name); fcb.SetEX(0); fcb.SetRC(0); entry = allocateFCB( ); files.Add(file); // Write empty directory writeFCB(entry, fcb); file.AddFCB(entry); for ( ; ;) { int byteCount = ist.Read(block, 0, getBlockSize( )); if (byteCount <= 0) { break; } //System.out.println("Writing "+byteCount+" bytes"); int recordCount = (byteCount + 127) / 128; while (recordCount > 0) { if (blockCount >= getFCBBlockCount( )) { entry = allocateFCB( ); fcb.ClearBlocks( ); fcb.SetRC(0); fcb.SetEX(fcb.getEX( ) + 1); //fcb[12] = (byte)(fcb[12]+getRecordForFCB()/128); writeFCB(entry, fcb); file.AddFCB(entry); blockCount = 0; } int blockNo = allocateBlock( ); //System.out.print("block "+blockNo+" at "+blockCount); putFCBBlock(fcb, blockCount++, blockNo); if (recordCount > dpb.blm + 1) { record = dpb.blm + 1; } else { record = recordCount; } recordCount -= record; record += fcb.getRC( ); record &= 0xff; if (record > 128) { fcb.SetEX(fcb.getEX( ) + 1); if (record > 128) { record -= 128; } } fcb.SetRC(record); //System.out.print(" ex "+fcb[12]+" rc "+(fcb[15] & 0xff)+" "); writeFCB(entry, fcb); file.AddBlock(blockNo); writeBlock(blockNo, block); } } }
public void mount( ) { FCB fcb = new FCB( ); disk.mount( ); // Mark all block as not used for (int i = 0; i < blockUsed.Length; i++) { blockUsed[i] = false; } // Mark directory block as used for (int i = 0; i < 8; i++) { if ((dpb.alloc0 & (1 << (7 - i))) != 0) { blockUsed[i] = true; } if ((dpb.alloc1 & (1 << (7 - i))) != 0) { blockUsed[8 + i] = true; } } files = new ArrayList(); for (int i = 0; i <= dpb.drm; i++) { readFCB(i, fcb); if (fcb.getDeleted( )) { directoryUsed[i] = false; continue; } int user = fcb.getUser( ); int ext = fcb.getEX( ); int record = fcb.getRC( ); directoryUsed[i] = true; // Skip not valid user if (user > 31) { continue; } // Mark directory entry used directoryUsed[i] = true; String fileName = fcb.getFileName( ); CpmFile file = searchFile(user, fileName); if (file == null) { file = new CpmFile(dpb, user, fileName); files.Add(file); } file.AddFCB(i); // Read block number from FCB for (int j = 0; j < getFCBBlockCount( ); j++) { int b = getFCBBlock(fcb, j); if (b == 0) { break; } blockUsed[b] = true; file.AddBlock(b); } } }
public void putFile(int user, String name, Stream ist) { FCB fcb = new FCB( ); int i, j; int entry; int blockCount = 0; int record = 0; CpmFile file = searchFile(user, name); if ( file != null ) throw new Exception(name + " Already exist"); file = new CpmFile(dpb, user, name); fcb.Clear( ); fcb.SetUser(user); fcb.SetFileName(name); fcb.SetEX(0); fcb.SetRC(0); entry = allocateFCB( ); files.Add(file); // Write empty directory writeFCB(entry, fcb); file.AddFCB(entry); for ( ; ; ) { int byteCount = ist.Read(block, 0, getBlockSize( )); if ( byteCount <= 0 ) break; //System.out.println("Writing "+byteCount+" bytes"); int recordCount = ( byteCount + 127 ) / 128; while ( recordCount > 0 ) { if ( blockCount >= getFCBBlockCount( ) ) { entry = allocateFCB( ); fcb.ClearBlocks( ); fcb.SetRC(0); fcb.SetEX(fcb.getEX( ) + 1); //fcb[12] = (byte)(fcb[12]+getRecordForFCB()/128); writeFCB(entry, fcb); file.AddFCB(entry); blockCount = 0; } int blockNo = allocateBlock( ); //System.out.print("block "+blockNo+" at "+blockCount); putFCBBlock(fcb, blockCount++, blockNo); if ( recordCount > dpb.blm + 1 ) record = dpb.blm + 1; else record = recordCount; recordCount -= record; record += fcb.getRC( ); record &= 0xff; if ( record > 128 ) { fcb.SetEX(fcb.getEX( ) + 1); if ( record > 128 ) record -= 128; } fcb.SetRC(record); //System.out.print(" ex "+fcb[12]+" rc "+(fcb[15] & 0xff)+" "); writeFCB(entry, fcb); file.AddBlock(blockNo); writeBlock(blockNo, block); } } }
public void mount( ) { FCB fcb = new FCB( ); disk.mount( ); // Mark all block as not used for ( int i = 0; i < blockUsed.Length; i++ ) blockUsed[i] = false; // Mark directory block as used for ( int i = 0; i < 8; i++ ) { if ( ( dpb.alloc0 & ( 1 << ( 7 - i ) ) ) != 0 ) blockUsed[i] = true; if ( ( dpb.alloc1 & ( 1 << ( 7 - i ) ) ) != 0 ) blockUsed[8 + i] = true; } files = new ArrayList(); for ( int i = 0; i <= dpb.drm; i++ ) { readFCB(i, fcb); if ( fcb.getDeleted( ) ) { directoryUsed[i] = false; continue; } int user = fcb.getUser( ); int ext = fcb.getEX( ); int record = fcb.getRC( ); directoryUsed[i] = true; // Skip not valid user if ( user > 31 ) { continue; } // Mark directory entry used directoryUsed[i] = true; String fileName = fcb.getFileName( ); CpmFile file = searchFile(user, fileName); if ( file == null ) { file = new CpmFile(dpb, user, fileName); files.Add(file); } file.AddFCB(i); // Read block number from FCB for ( int j = 0; j < getFCBBlockCount( ); j++ ) { int b = getFCBBlock(fcb, j); if ( b == 0 ) break; blockUsed[b] = true; file.AddBlock(b); } } }
public int getFileSize(CpmFile file) { int size = 0; FCB fcb = new FCB( ); for ( int i = 0; i < file.GetFCBCount( ); i++ ) { readFCB(file.GetFCBAt(i), fcb); int ex = ( fcb.getEX( ) & 0x1f ) & ~dpb.exm; int record = fcb.getRC( ) & 0xff; size = ex * 128 + ( ( dpb.exm & fcb.getEX( ) ) + 1 ) * 128 - ( 128 - record ); //System.out.println("name "+file.name+" ext "+ex+" record "+record); } return size; }