INodeDirectory unprotectedSetQuota(String src, long nsQuota, long dsQuota)
                       throws FileNotFoundException, QuotaExceededException {
    // sanity check
    if ((nsQuota < 0 && nsQuota != FSConstants.QUOTA_DONT_SET &&
         nsQuota < FSConstants.QUOTA_RESET) ||
        (dsQuota < 0 && dsQuota != FSConstants.QUOTA_DONT_SET &&
          dsQuota < FSConstants.QUOTA_RESET)) {
      throw new IllegalArgumentException("Illegal value for nsQuota or " +
                                         "dsQuota : " + nsQuota + " and " +
                                         dsQuota);
    }

    String srcs = normalizePath(src);
    INode[] inodes = rootDir.getExistingPathINodes(src);
    INode targetNode = inodes[inodes.length-1];
    if (targetNode == null) {
      throw new FileNotFoundException("Directory does not exist: " + srcs);
    } else if (!targetNode.isDirectory()) {
      throw new FileNotFoundException("Cannot set quota on a file: " + srcs);
    } else { // a directory inode
      INodeDirectory dirNode = (INodeDirectory)targetNode;
      long oldNsQuota = dirNode.getNsQuota();
      long oldDsQuota = dirNode.getDsQuota();
      if (nsQuota == FSConstants.QUOTA_DONT_SET) {
        nsQuota = oldNsQuota;
      }
      if (dsQuota == FSConstants.QUOTA_DONT_SET) {
        dsQuota = oldDsQuota;
      }

      if (dirNode instanceof INodeDirectoryWithQuota) {
        // a directory with quota; so set the quota to the new value
        ((INodeDirectoryWithQuota)dirNode).setQuota(nsQuota, dsQuota);
      } else {
        // a non-quota directory; so replace it with a directory with quota
        INodeDirectoryWithQuota newNode =
          new INodeDirectoryWithQuota(nsQuota, dsQuota, dirNode);
        // non-root directory node; parent != null
        INodeDirectory parent = (INodeDirectory)inodes[inodes.length-2];
        dirNode = newNode;
        parent.replaceChild(newNode);
        
        // replace oldNode by newNode with the same id
        inodeMap.put(newNode);
      }
      return (oldNsQuota != nsQuota || oldDsQuota != dsQuota) ? dirNode : null;
    }
  }
INodeDirectory unprotectedSetQuota ( String src , long nsQuota , long dsQuota ) throws FileNotFoundException , QuotaExceededException { if ( ( nsQuota < 0 && nsQuota != FSConstants . QUOTA_DONT_SET && nsQuota < FSConstants . QUOTA_RESET ) || ( dsQuota < 0 && dsQuota != FSConstants . QUOTA_DONT_SET && dsQuota < FSConstants . QUOTA_RESET ) ) { throw new IllegalArgumentException ( "Illegal value for nsQuota or " + "dsQuota : " + nsQuota + " and " + dsQuota ) ; } String srcs = normalizePath ( src ) ; INode [ ] inodes = rootDir . getExistingPathINodes ( src ) ; INode targetNode = inodes [ inodes . length - 1 ] ; if ( targetNode == null ) { throw new FileNotFoundException ( "Directory does not exist: " + srcs ) ; } else if ( ! targetNode . isDirectory ( ) ) { throw new FileNotFoundException ( "Cannot set quota on a file: " + srcs ) ; } else { INodeDirectory dirNode = ( INodeDirectory ) targetNode ; long oldNsQuota = dirNode . getNsQuota ( ) ; long oldDsQuota = dirNode . getDsQuota ( ) ; if ( nsQuota == FSConstants . QUOTA_DONT_SET ) { nsQuota = oldNsQuota ; } if ( dsQuota == FSConstants . QUOTA_DONT_SET ) { dsQuota = oldDsQuota ; } if ( dirNode instanceof INodeDirectoryWithQuota ) { ( ( INodeDirectoryWithQuota ) dirNode ) . setQuota ( nsQuota , dsQuota ) ; } else { INodeDirectoryWithQuota newNode = new INodeDirectoryWithQuota ( nsQuota , dsQuota , dirNode ) ; INodeDirectory parent = ( INodeDirectory ) inodes [ inodes . length - 2 ] ; dirNode = newNode ; parent . replaceChild ( newNode ) ; inodeMap . put ( newNode ) ; } return ( oldNsQuota != nsQuota || oldDsQuota != dsQuota ) ? dirNode : null ; } }
See {@link ClientProtocol#setQuota(String, long, long)} for the contract.
Sets quota for for a directory.
@returns INodeDirectory if any of the quotas have changed. null other wise.
@throws FileNotFoundException if the path does not exist or is a file
@throws QuotaExceededException if the directory tree size is
greater than the given quota