+/*
+ * Calculate number of inodes per group.
+ */
+long
+calcipg(cpg, bpcg, usedbp)
+ long cpg;
+ long bpcg;
+ off_t *usedbp;
+{
+ int i;
+ long ipg, new_ipg, ncg, ncyl;
+ off_t usedb;
+
+ /*
+ * Prepare to scale by fssize / (number of sectors in cylinder groups).
+ * Note that fssize is still in sectors, not filesystem blocks.
+ */
+ ncyl = howmany(fssize, secpercyl);
+ ncg = howmany(ncyl, cpg);
+ /*
+ * Iterate a few times to allow for ipg depending on itself.
+ */
+ ipg = 0;
+ for (i = 0; i < 10; i++) {
+ usedb = (sblock.fs_iblkno + ipg / INOPF(&sblock))
+ * NSPF(&sblock) * (off_t)sectorsize;
+ new_ipg = (cpg * (quad_t)bpcg - usedb) / density * fssize
+ / ncg / secpercyl / cpg;
+ new_ipg = roundup(new_ipg, INOPB(&sblock));
+ if (new_ipg == ipg)
+ break;
+ ipg = new_ipg;
+ }
+ *usedbp = usedb;
+ return (ipg);
+}
+