示例#1
0
/*
 * Get file system statistics.
 */
int
ext2fs_statvfs(struct mount *mp, struct statvfs *sbp)
{
	struct ufsmount *ump;
	struct m_ext2fs *fs;
	uint32_t overhead, overhead_per_group, ngdb;
	int i, ngroups;

	ump = VFSTOUFS(mp);
	fs = ump->um_e2fs;
	if (fs->e2fs.e2fs_magic != E2FS_MAGIC)
		panic("ext2fs_statvfs");

	/*
	 * Compute the overhead (FS structures)
	 */
	overhead_per_group =
	    1 /* block bitmap */ +
	    1 /* inode bitmap */ +
	    fs->e2fs_itpg;
	overhead = fs->e2fs.e2fs_first_dblock +
	    fs->e2fs_ncg * overhead_per_group;
	if (EXT2F_HAS_COMPAT_FEATURE(fs, EXT2F_COMPAT_SPARSESUPER2)) {
		/*
		 * Superblock and group descriptions is in group zero,
		 * then optionally 0, 1 or 2 extra copies.
		 */
		ngroups = 1
			+ (fs->e2fs.e4fs_backup_bgs[0] ? 1 : 0)
			+ (fs->e2fs.e4fs_backup_bgs[1] ? 1 : 0);
	} else if (EXT2F_HAS_ROCOMPAT_FEATURE(fs, EXT2F_ROCOMPAT_SPARSESUPER)) {
		for (i = 0, ngroups = 0; i < fs->e2fs_ncg; i++) {
			if (cg_has_sb(i))
				ngroups++;
		}
	} else {
		ngroups = fs->e2fs_ncg;
	}
	ngdb = fs->e2fs_ngdb;
	if (EXT2F_HAS_COMPAT_FEATURE(fs, EXT2F_COMPAT_RESIZE))
		ngdb += fs->e2fs.e2fs_reserved_ngdb;
	overhead += ngroups * (1 /* superblock */ + ngdb);

	sbp->f_bsize = fs->e2fs_bsize;
	sbp->f_frsize = MINBSIZE << fs->e2fs.e2fs_fsize;
	sbp->f_iosize = fs->e2fs_bsize;
	sbp->f_blocks = fs->e2fs.e2fs_bcount - overhead;
	sbp->f_bfree = fs->e2fs.e2fs_fbcount;
	sbp->f_bresvd = fs->e2fs.e2fs_rbcount;
	if (sbp->f_bfree > sbp->f_bresvd)
		sbp->f_bavail = sbp->f_bfree - sbp->f_bresvd;
	else
		sbp->f_bavail = 0;
	sbp->f_files =  fs->e2fs.e2fs_icount;
	sbp->f_ffree = fs->e2fs.e2fs_ficount;
	sbp->f_favail = fs->e2fs.e2fs_ficount;
	sbp->f_fresvd = 0;
	copy_statvfs_info(sbp, mp);
	return 0;
}
示例#2
0
int
ext2fs_setsize(struct inode *ip, uint64_t size)
{
	if ((ip->i_e2fs_mode & IFMT) == IFREG ||
	    ip->i_e2fs_mode == 0) {
		ip->i_din.e2fs_din->e2di_size_high = size >> 32;
		if (size >= 0x80000000U) {
			struct m_ext2fs *fs = ip->i_e2fs;

			if (fs->e2fs.e2fs_rev <= E2FS_REV0) {
				/* Linux automagically upgrades to REV1 here! */
				return EFBIG;
			}
			if (!EXT2F_HAS_ROCOMPAT_FEATURE(fs,
			    EXT2F_ROCOMPAT_LARGEFILE)) {
				fs->e2fs.e2fs_features_rocompat |=
				    EXT2F_ROCOMPAT_LARGEFILE;
				fs->e2fs_fmod = 1;
			}
		}
	} else if (size >= 0x80000000U)