Package org.jnode.fs

Examples of org.jnode.fs.FileSystemException


     * @param preferredBlockBroup first try to allocate the inode in this block group
     * @return the INode
     */
    protected INode createINode(int preferredBlockBroup, int fileFormat, int accessRights, int uid, int gid)
        throws FileSystemException, IOException {
        if (preferredBlockBroup >= superblock.getBlocksCount()) throw new FileSystemException("Block group "
            + preferredBlockBroup + " does not exist");

        int groupNr = preferredBlockBroup;
        // first check the preferred block group, if it has any free inodes
        INodeReservation res = findFreeINode(groupNr);

        // if no free inode has been found in the preferred block group, then
        // try the others
        if (!res.isSuccessful()) {
            for (groupNr = 0; groupNr < superblock.getBlockGroupNr(); groupNr++) {
                res = findFreeINode(groupNr);
                if (res.isSuccessful()) {
                    break;
                }
            }
        }

        if (!res.isSuccessful()) throw new FileSystemException("No free inodes found!");

        // a free inode has been found: create the inode and write it into the
        // inode table
        INodeTable iNodeTable = iNodeTables[preferredBlockBroup];
        // byte[] iNodeData = new byte[INode.INODE_LENGTH];
        int iNodeNr = res.getINodeNr((int) superblock.getINodesPerGroup());
        INode iNode = new INode(this, new INodeDescriptor(iNodeTable, iNodeNr, groupNr, res.getIndex()));
        iNode.create(fileFormat, accessRights, uid, gid);
        // trigger a write to disk
        iNode.update();

        log.debug("** NEW INODE ALLOCATED: inode number: " + iNode.getINodeNr());

        // put the inode into the cache
        synchronized (inodeCache) {
            Integer key = Integer.valueOf(iNodeNr);
            if (inodeCache.containsKey(key)) throw new FileSystemException(
                "Newly allocated inode is already in the inode cache!?");
            else inodeCache.put(key, iNode);
        }

        return iNode;
View Full Code Here


     * @param blockNr
     * @throws FileSystemException
     * @throws IOException
     */
    public void freeBlock(long blockNr) throws FileSystemException, IOException {
        if (blockNr < 0 || blockNr >= superblock.getBlocksCount()) throw new FileSystemException(
            "Attempt to free nonexisting block (" + blockNr + ")");

        int group = translateToGroup(blockNr);
        int index = translateToIndex(blockNr);
        GroupDescriptor gdesc = groupDescriptors[group];

        /*
         * Throw an exception if an attempt is made to free up a filesystem metadata block (the beginning of each block
         * group is filesystem metadata): superblock copy (if present) block bitmap inode bitmap inode table Free blocks
         * begin after the inode table.
         */
        long iNodeTableBlock = groupDescriptors[group].getInodeTable();
        long firstNonMetadataBlock = iNodeTableBlock + INodeTable.getSizeInBlocks(this);

        if (blockNr < firstNonMetadataBlock) throw new FileSystemException(
            "Attempt to free a filesystem metadata block!");

        // synchronize to the blockCache to avoid flushing the block between
        // reading it
        // and synchronizing to it
View Full Code Here

        super(device, readOnly, type);

        try {
            fat = Fat.create(getApi());
        } catch (IOException ex) {
            throw new FileSystemException(ex);
        } catch (Exception e) {
            throw new FileSystemException(e);
        }

        cp = CodePage.forName(codePageName);
    }
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.