Package org.jnode.fs

Examples of org.jnode.fs.FileSystemException


        throws FileSystemException, IOException {
        final long blockCount = getSizeInBlocks();
        final int indirectCount = getIndirectCount();
        long allocatedBlocks = i;
        if (i != blockCount) {
            throw new FileSystemException("Trying to register block " + i +
                " (counts from 0), when INode contains only " + blockCount + " blocks");
        }

        log.debug("registering block #" + blockNr);

        setDirty(true);

        //the direct blocks (0; 11)
        if (i < 12) {
            Ext2Utils.set32(data, 40 + (int) i * 4, blockNr);
            return;
        }

        //see the indirect blocks (12; indirectCount-1)
        i -= 12;
        if (i < indirectCount) {
            long indirectBlockNr;
            //the 12th index points to the indirect block
            if (i == 0) {
                //need to reserve the indirect block itself, as this is the
                //first time it is used
                indirectBlockNr = findFreeBlock(allocatedBlocks++);
                Ext2Utils.set32(data, 40 + 12 * 4, indirectBlockNr);

                //log.debug("reserved indirect block: "+indirectBlockNr);

                //need to blank the block so that e2fsck does not complain
                byte[] zeroes = new byte[fs.getBlockSize()]; //blank the block
                Arrays.fill(zeroes, 0, fs.getBlockSize(), (byte) 0);
                fs.writeBlock(indirectBlockNr, zeroes, false);
            } else {
                //the indirect block has already been used
                indirectBlockNr = Ext2Utils.get32(data, 40 + 12 * 4);
            }

            indirectWrite(indirectBlockNr, i, allocatedBlocks, blockNr, 1);

            return;
        }

        //see the double indirect blocks (indirectCount; doubleIndirectCount-1)
        i -= indirectCount;
        final int doubleIndirectCount = indirectCount * indirectCount;
        if (i < doubleIndirectCount) {
            long doubleIndirectBlockNr;
            //the 13th index points to the double indirect block
            if (i == 0) {
                //need to reserve the double indirect block itself
                doubleIndirectBlockNr = findFreeBlock(allocatedBlocks++);
                Ext2Utils.set32(data, 40 + 13 * 4, doubleIndirectBlockNr);

                //log.debug("reserved double indirect block:
                // "+doubleIndirectBlockNr);

                //need to blank the block so that e2fsck does not complain
                byte[] zeroes = new byte[fs.getBlockSize()]; //blank the block
                Arrays.fill(zeroes, 0, fs.getBlockSize(), (byte) 0);
                fs.writeBlock(doubleIndirectBlockNr, zeroes, false);
            } else {
                doubleIndirectBlockNr = Ext2Utils.get32(data, 40 + 13 * 4);
            }

            indirectWrite(doubleIndirectBlockNr, i, allocatedBlocks, blockNr, 2);

            return;
        }

        //see the triple indirect blocks (doubleIndirectCount;
        // tripleIndirectCount-1)
        final int tripleIndirectCount = indirectCount * indirectCount * indirectCount;
        i -= doubleIndirectCount;
        if (i < tripleIndirectCount) {
            long tripleIndirectBlockNr;
            //the 14th index points to the triple indirect block
            if (i == 0) {
                //need to reserve the triple indirect block itself
                tripleIndirectBlockNr = findFreeBlock(allocatedBlocks++);
                Ext2Utils.set32(data, 40 + 13 * 4, tripleIndirectBlockNr);

                //log.debug("reserved triple indirect block:
                // "+tripleIndirectBlockNr);

                //need to blank the block so that e2fsck does not complain
                byte[] zeroes = new byte[fs.getBlockSize()]; //blank the block
                Arrays.fill(zeroes, 0, fs.getBlockSize(), (byte) 0);
                fs.writeBlock(tripleIndirectBlockNr, zeroes, false);
            } else {
                tripleIndirectBlockNr = Ext2Utils.get32(data, 40 + 14 * 4);
            }

            indirectWrite(tripleIndirectBlockNr, i, allocatedBlocks, blockNr, 3);
            return;
        }

        //shouldn't get here
        throw new FileSystemException("Internal FS exception: getDataBlockIndex(i=" + i + ")");
    }
View Full Code Here


            if (catalogClumpBlocks == 0) {
                clumpSize = getBTreeClumpSize(blockSize, catalogNodeSize, sectorCount, true);
            } else {
                clumpSize = clumpSizeCalculation(catalogClumpBlocks);
                if (clumpSize % catalogNodeSize != 0) {
                    throw new FileSystemException("clump size is not a multiple of node size");
                }
            }
            catalogClumpSize = (int) clumpSize;
            if (extentClumpBlocks == 0) {
                clumpSize = getBTreeClumpSize(blockSize, extentNodeSize, sectorCount, false);
            } else {
                clumpSize = clumpSizeCalculation(extentClumpBlocks);
            }
            extentClumpSize = (int) clumpSize;

            if (attributeClumpBlocks == 0) {
                clumpSize = 0;
            } else {
                clumpSize = clumpSizeCalculation(attributeClumpBlocks);
                if (clumpSize % attributeNodeSize != 0) {
                    throw new FileSystemException(
                        "clump size is not a multiple of attribute node size");
                }
            }
            attributeClumpSize = (int) clumpSize;

            long totalBlocks = this.getBlockCount();
            long minClumpSize = this.getBlockCount() >> 3;
            if ((totalBlocks & 7) == 0) {
                ++minClumpSize;
            }
            if (bitmapClumpBlocks == 0) {
                clumpSize = minClumpSize;
            } else {
                clumpSize = clumpSizeCalculation(bitmapClumpBlocks);
                if (clumpSize < minClumpSize) {
                    throw new FileSystemException("bitmap clump size is too small.");
                }
            }
            allocationClumpSize = (int) clumpSize;
        } catch (ApiNotFoundException e) {
            throw new FileSystemException("Unable initialize default values.", e);
        }
    }
View Full Code Here

            System.arraycopy(data, getOffset(), newData, 0, getNameLen() + 8);
            setOffset(0);
            setFileOffset(beginning);
            data = newData;
        } else {
            throw new FileSystemException("The directory record does not fit into the block!");
        }
        log.debug("expandRecord(): newLength: " + getRecLen());
    }
View Full Code Here

     * @return
     */
    private int clumpSizeCalculation(long clumpBlocks) throws FileSystemException {
        long clumpSize = clumpBlocks * blockSize;
        if ((clumpSize & 0XFFFFFFFF00000000L) == 0) {
            throw new FileSystemException("Too many blocks (" + clumpBlocks + ") for clump size (" +
                clumpSize + ").");
        }
        return (int) clumpSize;
    }
View Full Code Here

     */
    private byte[] getINodeTableBlock(int blockNo) throws FileSystemException, IOException {
        if (blockNo < blockCount)
            return fs.getBlock(firstBlock + blockNo);
        else
            throw new FileSystemException("Trying to get block #" + blockNo +
                    "of an inode table that only has " + blockCount + " blocks");
    }
View Full Code Here

    private void writeINodeTableBlock(byte[] data, int blockNo)
        throws FileSystemException, IOException {
        if (blockNo < blockCount)
            fs.writeBlock(firstBlock + blockNo, data, false);
        else
            throw new FileSystemException("Trying to write block #" + blockNo +
                    "of an inode table that only has " + blockCount + " blocks");
    }
View Full Code Here

        super(device, readOnly, type);

        try {
            volume = new ISO9660Volume(getFSApi());
        } catch (IOException e) {
            throw new FileSystemException(e);
        } catch (ApiNotFoundException ex) {
            throw new FileSystemException("Need FSBlockDeviceAPI for ISO9660 filesystem");
        }
    }
View Full Code Here

            final FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
            FatFileSystemType type = fSS.getFileSystemType(FatFileSystemType.ID);
            return type.create(device, false); // not readOnly !
        } catch (IOException ioe) {
            throw new FileSystemException("Formating problem", ioe);
        } catch (ApiNotFoundException e) {
            throw new FileSystemException("Formating problem", e);
        } catch (NameNotFoundException e) {
            throw new FileSystemException("Formating problem", e);
        }
    }
View Full Code Here

        try {
            // initialize the NTFE volume
            volume = new NTFSVolume(getApi());
        } catch (IOException e) {
            throw new FileSystemException(e);
        }
    }
View Full Code Here

        ByteBuffer mdbData = ByteBuffer.allocate(MasterDirectoryBlock.LENGTH);

        try {
            device.getAPI(BlockDeviceAPI.class).read(0x400, mdbData);
        } catch (ApiNotFoundException e) {
            throw new FileSystemException("Failed to find the block device API", e);
        } catch (IOException e) {
            throw new FileSystemException("Error reading HFS wrapper MDB", e);
        }

        MasterDirectoryBlock mdb = new MasterDirectoryBlock(mdbData.array());

        // Calculate the offset and length of the embedded HFS+ file system
        long offset = mdb.getAllocationBlockStart() * 512 +
            mdb.getEmbeddedVolumeStartBlock() * mdb.getAllocationBlockSize();
        long length = mdb.getEmbeddedVolumeBlockCount() * mdb.getAllocationBlockSize();

        MappedBlockDeviceSupport subDevice;
        try {
            // Take a sub-section of the device to pass down to the HFS+ code
            subDevice = new MappedBlockDeviceSupport(device, offset, length);
        } catch (IOException e) {
            throw new FileSystemException("Error creating sub-device for HFS+", e);
        }

        HfsPlusFileSystem fs = new HfsPlusFileSystem(subDevice, readOnly, this);
        fs.read();
        return fs;
View Full Code Here

TOP

Related Classes of org.jnode.fs.FileSystemException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.