code: public void removeLinkedFile(INodeHardLinkFile file) {
      // Remove the target file from the linkedFiles
      // Since the equal function in the INode only compares the name field, it would be safer to 
      // iterate the INodeHardLinkFile and compare the reference directly.
      for (int i = 0 ; i < linkedFiles.size(); i++) {
        // compare the reference !
        if (linkedFiles.get(i) == file) {
          // remove the file by index
          linkedFiles.remove(i);
          break;
        }
      }
  
      INodeFile newOwner = null;
      if (linkedFiles.size() == 1) {
        // revert the last INodeHardLinkFile to the regular INodeFile
        INodeHardLinkFile lastReferencedFile= linkedFiles.get(0);
        INodeFile inodeFile = new INodeFile(lastReferencedFile);
        lastReferencedFile.parent.replaceChild(inodeFile);
        
        // clear the linkedFiles
        linkedFiles.clear();
        // set the new owner
        newOwner = inodeFile;
      } else {
        if (file.getBlocks() != null && 
            file.getBlocks().length >0 && 
           (file.getBlocks()[0].getINode() == file)) {
          // need to find a new owner for all the block infos
          newOwner = linkedFiles.get(0);
        }    
      }
      if (newOwner != null) {
        for (BlockInfo blkInfo : file.getBlocks()) {
          blkInfo.setINode(newOwner);
        }
      }
    }
docs: Remove an INodeHardLinkFile from the linkedFiles.
  This function is not thread-safe. The caller is supposed to have a writeLock.
  
  @param file The INodeHardLinkFile to be removed