+}
+
+static void
+lfs_writeckp(fs, sp)
+ LFS *fs;
+ SEGMENT *sp;
+{
+ BUF *bp;
+ FINFO *fip;
+ INODE *ip;
+ SEGUSE *sup;
+ daddr_t *lbp;
+ int bytes_needed, i;
+ void *xp;
+
+printf("lfs_writeckp\n");
+ /*
+ * This will write the dirty ifile blocks, but not the segusage
+ * table nor the ifile inode.
+ */
+ sp = lfs_writefile(sp, fs, fs->lfs_ivnode, 1);
+
+ /*
+ * Make sure that the segment usage table and the ifile inode will
+ * fit in this segment. If they won't, put them in the next segment
+ */
+ bytes_needed = fs->lfs_segtabsz << fs->lfs_bshift;
+ if (sp->ninodes % INOPB(fs) == 0)
+ bytes_needed += fs->lfs_bsize;
+
+ if (sp->seg_bytes_left < bytes_needed) {
+ lfs_writeseg(fs, sp);
+ sp = lfs_newseg(fs);
+ } else if (sp->sum_bytes_left < (fs->lfs_segtabsz * sizeof(daddr_t)))
+ lfs_newsum(fs, sp);
+
+#ifdef DEBUG
+ if (sp->seg_bytes_left < bytes_needed)
+ panic("lfs_writeckp: unable to write checkpoint");
+#endif
+
+ /*
+ * Now, update the segment usage information and the ifile inode and
+ * and write it out
+ */
+
+ sup = fs->lfs_segtab + sp->seg_number;
+ sup->su_nbytes = (fs->lfs_segmask + 1) - sp->seg_bytes_left +
+ bytes_needed;
+ sup->su_lastmod = time.tv_sec;
+ sup->su_flags = SEGUSE_DIRTY;
+
+ /* Get buffers for the segusage table and write it out */
+ ip = VTOI(fs->lfs_ivnode);
+ fip = sp->fip;
+ lbp = &fip->fi_blocks[fip->fi_nblocks];
+ for (xp = fs->lfs_segtab, i = 0; i < fs->lfs_segtabsz;
+ i++, xp += fs->lfs_bsize, lbp++) {
+ bp = lfs_newbuf(fs, sp->saddr, fs->lfs_bsize);
+ *sp->cbpp++ = bp;
+ bcopy(xp, bp->b_un.b_words, fs->lfs_bsize);
+ ip->i_din.di_db[i] = sp->saddr;
+ sp->saddr += (1 << fs->lfs_fsbtodb);
+ *lbp = i;
+ fip->fi_nblocks++;
+ }
+ sp = lfs_writeinode(fs, sp, fs->lfs_ivnode);
+ lfs_writeseg(fs, sp);
+ lfs_writesuper(fs, sp);