- /*
- * Both address and size must be
- * positive, or the protocol has broken down.
- */
- if (addr <= 0 || size <= 0)
- goto badrmfree;
- /*
- * Locate the piece of the map which starts after the
- * returned space (or the end of the map).
- */
- firstbp = bp = (struct mapent *)(mp + 1);
- for (; bp->m_addr <= addr && bp->m_size != 0; bp++)
- continue;
- /*
- * If the piece on the left abuts us,
- * then we should combine with it.
- */
- if (bp > firstbp && (bp-1)->m_addr+(bp-1)->m_size >= addr) {
- /*
- * Check no overlap (internal error).
- */
- if ((bp-1)->m_addr+(bp-1)->m_size > addr)
- goto badrmfree;
- /*
- * Add into piece on the left by increasing its size.
- */
- (bp-1)->m_size += size;
- /*
- * If the combined piece abuts the piece on
- * the right now, compress it in also,
- * by shifting the remaining pieces of the map over.
- */
- if (bp->m_addr && addr+size >= bp->m_addr) {
- if (addr+size > bp->m_addr)
- goto badrmfree;
- (bp-1)->m_size += bp->m_size;
- while (bp->m_size) {
- bp++;
- (bp-1)->m_addr = bp->m_addr;
- (bp-1)->m_size = bp->m_size;
- }
- }
- goto done;
- }
- /*
- * Don't abut on the left, check for abutting on
- * the right.
- */
- if (addr+size >= bp->m_addr && bp->m_size) {
- if (addr+size > bp->m_addr)
- goto badrmfree;
- bp->m_addr -= size;
- bp->m_size += size;
- goto done;
- }
- /*
- * Don't abut at all. Make a new entry
- * and check for map overflow.
- */
- do {
- t = bp->m_addr;
- bp->m_addr = addr;
- addr = t;
- t = bp->m_size;
- bp->m_size = size;
- bp++;
- } while (size = t);
- /*
- * Segment at bp is to be the delimiter;
- * If there is not room for it
- * then the table is too full
- * and we must discard something.
- */
- if (bp+1 > mp->m_limit) {
- /*
- * Back bp up to last available segment.
- * which contains a segment already and must
- * be made into the delimiter.
- * Discard second to last entry,
- * since it is presumably smaller than the last
- * and move the last entry back one.
- */
- bp--;
+ /*
+ * Both address and size must be
+ * positive, or the protocol has broken down.
+ */
+ if (addr <= 0 || size <= 0)
+ goto badrmfree;
+ /*
+ * Locate the piece of the map which starts after the
+ * returned space (or the end of the map).
+ */
+ firstbp = bp = (struct mapent *)(mp + 1);
+ for (; bp->m_addr <= addr && bp->m_size != 0; bp++)
+ continue;
+ /*
+ * If the piece on the left abuts us,
+ * then we should combine with it.
+ */
+ if (bp > firstbp && (bp-1)->m_addr+(bp-1)->m_size >= addr) {
+ /*
+ * Check no overlap (internal error).
+ */
+ if ((bp-1)->m_addr+(bp-1)->m_size > addr)
+ goto badrmfree;
+ /*
+ * Add into piece on the left by increasing its size.
+ */
+ (bp-1)->m_size += size;
+ /*
+ * If the combined piece abuts the piece on
+ * the right now, compress it in also,
+ * by shifting the remaining pieces of the map over.
+ */
+ if (bp->m_addr && addr+size >= bp->m_addr) {
+ if (addr+size > bp->m_addr)
+ goto badrmfree;
+ (bp-1)->m_size += bp->m_size;
+ while (bp->m_size) {
+ bp++;
+ (bp-1)->m_addr = bp->m_addr;
+ (bp-1)->m_size = bp->m_size;
+ }
+ }
+ goto done;
+ }
+ /*
+ * Don't abut on the left, check for abutting on
+ * the right.
+ */
+ if (addr+size >= bp->m_addr && bp->m_size) {
+ if (addr+size > bp->m_addr)
+ goto badrmfree;
+ bp->m_addr -= size;
+ bp->m_size += size;
+ goto done;
+ }
+ /*
+ * Don't abut at all. Make a new entry
+ * and check for map overflow.
+ */
+ do {
+ t = bp->m_addr;
+ bp->m_addr = addr;
+ addr = t;
+ t = bp->m_size;
+ bp->m_size = size;
+ bp++;
+ } while (size = t);
+ /*
+ * Segment at bp is to be the delimiter;
+ * If there is not room for it
+ * then the table is too full
+ * and we must discard something.
+ */
+ if (bp+1 > mp->m_limit) {
+ /*
+ * Back bp up to last available segment.
+ * which contains a segment already and must
+ * be made into the delimiter.
+ * Discard second to last entry,
+ * since it is presumably smaller than the last
+ * and move the last entry back one.
+ */
+ bp--;
+ overflow[((bp-1)->m_addr % dmmax) / nswdev] +=
+ (bp-1)->m_size;