Example #1
0
/*
 * Insert the journal file into the ROOTINO directory.  We always extend the
 * last frag
 */
static int
journal_insertfile(ino_t ino)
{
	struct ufs1_dinode *dp1;
	struct ufs2_dinode *dp2;
	void *ip;
	ufs2_daddr_t nblk;
	ufs2_daddr_t blk;
	ufs_lbn_t lbn;
	int size;
	int mode;
	int off;

	if (getino(&disk, &ip, ROOTINO, &mode) != 0) {
		warn("Failed to get root inode");
		sbdirty();
		return (-1);
	}
	dp2 = ip;
	dp1 = ip;
	blk = 0;
	size = 0;
	nblk = journal_balloc();
	if (nblk <= 0)
		return (-1);
	/*
	 * For simplicity sake we aways extend the ROOTINO into a new
	 * directory block rather than searching for space and inserting
	 * into an existing block.  However, if the rootino has frags
	 * have to free them and extend the block.
	 */
	if (sblock.fs_magic == FS_UFS1_MAGIC) {
		lbn = lblkno(&sblock, dp1->di_size);
		off = blkoff(&sblock, dp1->di_size);
		blk = dp1->di_db[lbn];
		size = sblksize(&sblock, (off_t)dp1->di_size, lbn);
	} else {
		lbn = lblkno(&sblock, dp2->di_size);
		off = blkoff(&sblock, dp2->di_size);
		blk = dp2->di_db[lbn];
		size = sblksize(&sblock, (off_t)dp2->di_size, lbn);
	}
	if (off != 0) {
		if (dir_extend(blk, nblk, off, ino) == -1)
			return (-1);
	} else {
		blk = 0;
		if (dir_insert(nblk, 0, ino) == -1)
			return (-1);
	}
	if (sblock.fs_magic == FS_UFS1_MAGIC) {
		dp1->di_blocks += (sblock.fs_bsize - size) / DEV_BSIZE;
		dp1->di_db[lbn] = nblk;
		dp1->di_size = lblktosize(&sblock, lbn+1);
	} else {
		dp2->di_blocks += (sblock.fs_bsize - size) / DEV_BSIZE;
		dp2->di_db[lbn] = nblk;
		dp2->di_size = lblktosize(&sblock, lbn+1);
	}
	if (putino(&disk) < 0) {
		warn("Failed to write root inode");
		return (-1);
	}
	if (cgwrite(&disk) < 0) {
		warn("Failed to write updated cg");
		sbdirty();
		return (-1);
	}
	if (blk) {
		if (cgbfree(&disk, blk, size) < 0) {
			warn("Failed to write cg");
			return (-1);
		}
	}

	return (0);
}
Example #2
0
static int journal_insertfile( ino_t ino ) {
	struct ufs1_dinode *dp1;
	struct ufs2_dinode *dp2;
	void *ip;
	ufs2_daddr_t nblk;
	ufs2_daddr_t blk;
	ufs_lbn_t lbn;
	int size;
	int mode;
	int off;
	if ( getino( &disk, &ip, ROOTINO, &mode ) != 0 ) {
		warn( "Failed to get root inode" );
		sbdirty();
		return ( -1 );
	}
	dp2 = ip;
	dp1 = ip;
	blk = 0;
	size = 0;
	nblk = journal_balloc();
	if ( nblk <= 0 ) return ( -1 );
	if ( sblock.fs_magic == FS_UFS1_MAGIC ) {
		lbn = lblkno( &sblock, dp1->di_size );
		off = blkoff( &sblock, dp1->di_size );
		blk = dp1->di_db[lbn];
		size = sblksize( &sblock, (off_t) dp1->di_size, lbn );
	} else {
		lbn = lblkno( &sblock, dp2->di_size );
		off = blkoff( &sblock, dp2->di_size );
		blk = dp2->di_db[lbn];
		size = sblksize( &sblock, (off_t) dp2->di_size, lbn );
	}
	if ( off != 0 ) {
		if ( dir_extend( blk, nblk, off, ino ) == -1 ) return ( -1 );
	} else {
		blk = 0;
		if ( dir_insert( nblk, 0, ino ) == -1 ) return ( -1 );
	}
	if ( sblock.fs_magic == FS_UFS1_MAGIC ) {
		dp1->di_blocks += ( sblock.fs_bsize - size ) / DEV_BSIZE;
		dp1->di_db[lbn] = nblk;
		dp1->di_size = lblktosize( &sblock, lbn + 1 );
	} else {
		dp2->di_blocks += ( sblock.fs_bsize - size ) / DEV_BSIZE;
		dp2->di_db[lbn] = nblk;
		dp2->di_size = lblktosize( &sblock, lbn + 1 );
	}
	if ( putino( &disk ) < 0 ) {
		warn( "Failed to write root inode" );
		return ( -1 );
	}
	if ( cgwrite( &disk ) < 0 ) {
		warn( "Failed to write updated cg" );
		sbdirty();
		return ( -1 );
	}
	if ( blk ) {
		if ( cgbfree( &disk, blk, size ) < 0 ) {
			warn( "Failed to write cg" );
			return ( -1 );
		}
	}
	return ( 0 );
}