Exemplo n.º 1
0
  protected static void writeToINode(INode node) {
    int blockID = node.getIndex() / (Constants.BLOCK_SIZE / Constants.INODE_SIZE);
    int inodeOffset = node.getIndex() % (Constants.BLOCK_SIZE / Constants.INODE_SIZE);
    byte[] dataToWrite = new byte[Constants.BLOCK_SIZE];
    byte[] fileMetadata = node.getMetadata();

    DBuffer buffer = _cache.getBlock(blockID);
    buffer.read(dataToWrite, 0, Constants.BLOCK_SIZE);
    for (int k = 0; k < fileMetadata.length; k++)
      dataToWrite[inodeOffset * Constants.INODE_SIZE + k] = fileMetadata[k];

    buffer.write(dataToWrite, 0, Constants.BLOCK_SIZE);
    _cache.releaseBlock(buffer);
  }
Exemplo n.º 2
0
  public static synchronized boolean format() {
    for (INode i : _inodes) {
      i.write.lock();
    }
    Arrays.fill(_usedBlocks, false);
    inodeIsUsed();

    for (INode i : _inodes) {
      i.clearContent();
      i.setUsed(false);
      writeToINode(i);
      i.write.unlock();
    }
    return true;
  }