Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private void writeFCB(int dir, FCB fcb)
        {
            int offset = dir * 32;
            int sector = offset / 128;

            offset = offset % 128;

            readSector(sector, fcbBuffer);

            for (int i = 0; i < 32; i++)
            {
                fcbBuffer[offset + i] = fcb.getBytes( )[i];
            }

            writeSector(sector, fcbBuffer);
        }
Esempio n. 3
0
        public void deleteFile(int user, String name)
        {
            CpmFile file = searchFileException(user, name);

            for ( int i = 0; i < file.GetBlockCount( ); i++ ) {
                //System.out.println("Free block "+file.getBlockAt(i));
                blockUsed[file.GetBlockAt(i)] = false;
            }

            FCB fcb = new FCB( );

            for ( int i = 0; i < file.GetFCBCount( ); i++ ) {
                int entry = file.GetFCBAt(i);
                //System.out.println("free FCB "+entry);
                readFCB(entry, fcb);
                fcb.SetDeleted( );
                writeFCB(entry, fcb);
                directoryUsed[entry] = false;
            }

            files.Remove(file);
        }
Esempio n. 4
0
        public void deleteFile(int user, String name)
        {
            CpmFile file = searchFileException(user, name);

            for (int i = 0; i < file.GetBlockCount( ); i++)
            {
                //System.out.println("Free block "+file.getBlockAt(i));
                blockUsed[file.GetBlockAt(i)] = false;
            }

            FCB fcb = new FCB( );

            for (int i = 0; i < file.GetFCBCount( ); i++)
            {
                int entry = file.GetFCBAt(i);
                //System.out.println("free FCB "+entry);
                readFCB(entry, fcb);
                fcb.SetDeleted( );
                writeFCB(entry, fcb);
                directoryUsed[entry] = false;
            }

            files.Remove(file);
        }
Esempio n. 5
0
        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);
                }
            }
        }
Esempio n. 6
0
        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);
                }
            }
        }
Esempio n. 7
0
        private void writeFCB(int dir, FCB fcb)
        {
            int offset = dir * 32;
            int sector = offset / 128;
            offset = offset % 128;

            readSector(sector, fcbBuffer);

            for ( int i = 0; i < 32; i++ )
                fcbBuffer[offset + i] = fcb.getBytes( )[i];

            writeSector(sector, fcbBuffer);
        }
Esempio n. 8
0
        private void readFCB(int dir, FCB fcb)
        {
            int offset = dir * 32;
            int sector = offset / 128;
            offset = offset % 128;

            readSector(sector, fcbBuffer);

            fcb.setBuffer(fcbBuffer, offset);
        }
Esempio n. 9
0
 private void putFCBBlock(FCB fcb, int n, int block)
 {
     if ( getFCBBlockLength( ) == 1 )
         fcb.setBlockByte(n, block);
     else {
         fcb.setBlockWord(n, block);
     }
 }
Esempio n. 10
0
 private int getFCBBlock(FCB fcb, int block)
 {
     if ( getFCBBlockLength( ) == 1 )
         return fcb.getBlockByte(block);
     else
         return fcb.getBlockWord(block);
 }
Esempio n. 11
0
        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);
                }

            }
        }
Esempio n. 12
0
        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);
                }
            }
        }
Esempio n. 13
0
        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;
        }