From d90715f3cf771633a2adb0faae6f75418c6dd53b Mon Sep 17 00:00:00 2001 From: "Michael I. Bushnell" Date: Sat, 15 Oct 1994 01:09:10 +0000 Subject: Formerly utilities.c.~6~ --- ufs-fsck/utilities.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'ufs-fsck') diff --git a/ufs-fsck/utilities.c b/ufs-fsck/utilities.c index 4780ac8a..db603831 100644 --- a/ufs-fsck/utilities.c +++ b/ufs-fsck/utilities.c @@ -46,16 +46,24 @@ writeblock (daddr_t addr, void *buf, size_t size) fsmodified = 1; } +/* Last filesystem fragment that we read an inode from */ +static char *lastifrag; +static daddr_t lastifragaddr; + /* Read inode number INO into DINODE. */ void getinode (ino_t ino, struct dinode *di) { daddr_t iblk; - char buf[sblock->fs_fsize]; + if (!lastifrag) + lastifrag = malloc (sblock->fs_fsize); + iblk = ino_to_fsba (sblock, ino); - readblock (fsbtodb (sblock, iblk), buf, sblock->fs_fsize); - bcopy (buf + ino_to_fsbo (sblock, ino), di, sizeof (struct dinode)); + if (iblk != lastifragaddr) + readblock (fsbtodb (sblock, iblk), lastifrag, sblock->fs_fsize); + lastifragaddr = iblk; + bcopy (lastifrag + ino_to_fsbo (sblock, ino), di, sizeof (struct dinode)); } /* Write inode number INO from DINODE. */ @@ -63,12 +71,13 @@ void write_inode (ino_t ino, struct dinode *di) { daddr_t iblk; - char buf[sblock->fs_fsize]; iblk = ino_to_fsba (sblock, ino); - readblock (fsbtodb (sblock, iblk), buf, sblock->fs_fsize); - bcopy (di, buf + ino_to_fsbo (sblock, ino), sizeof (struct dinode)); - writeblock (fsbtodb (sblock, iblk), buf, sblock->fs_fsize); + if (iblk != lastifragaddr) + readblock (fsbtodb (sblock, iblk), lastifrag, sblock->fs_fsize); + lastifragaddr = iblk; + bcopy (di, lastifrag + ino_to_fsbo (sblock, ino), sizeof (struct dinode)); + writeblock (fsbtodb (sblock, iblk), lastifrag, sblock->fs_fsize); } /* Clear inode number INO and zero DI. */ -- cgit v1.2.3