Exemple #1
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);
                }
            }
        }
Exemple #2
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);
                }

            }
        }