/* RETURN VALUES: 0 - success. -ENOSPC - insufficient disk resources. -EIO - i/o error.  */
static int diAllocAG(struct inomap *, int, bool, struct inode *)
/* RETURN VALUES: 0 - success. -ENOSPC - insufficient disk resources. -EIO - i/o error.  */
static int diAllocAG(struct inomap *, int, bool, struct inode *)
{
	int rc, addext, numfree, numinos;
	numfree = imap->im_agctl[agno].numfree;
	numinos = imap->im_agctl[agno].numinos;
	if (numfree > numinos) {
		jfs_error(ip->i_sb, "diAllocAG: numfree > numinos");
		return -EIO;
	}
	if (dir)
		addext = (numfree < 64 ||
			  (numfree < 256
			   && ((numfree * 100) / numinos) <= 20));
	else
		addext = (numfree == 0);
	if (addext) {
		if ((rc = diAllocExt(imap, agno, ip)) != -ENOSPC)
			return (rc);
	}
	return (diAllocIno(imap, agno, ip));
}