Lines Matching +full:cluster +full:- +full:mode

1 /*-
7 /*-
8 * SPDX-License-Identifier: BSD-3-Clause
109 fs = ip->i_e2fs; in ext2_alloc()
110 ump = ip->i_ump; in ext2_alloc()
113 if ((u_int)size > fs->e2fs_bsize || blkoff(fs, size) != 0) { in ext2_alloc()
114 vn_printf(ip->i_devvp, "bsize = %lu, size = %d, fs = %s\n", in ext2_alloc()
115 (long unsigned int)fs->e2fs_bsize, size, fs->e2fs_fsmnt); in ext2_alloc()
121 if (size == fs->e2fs_bsize && fs->e2fs_fbcount == 0) in ext2_alloc()
123 if (cred->cr_uid != 0 && in ext2_alloc()
124 fs->e2fs_fbcount < fs->e2fs_rbcount) in ext2_alloc()
126 if (bpref >= fs->e2fs_bcount) in ext2_alloc()
129 cg = ino_to_cg(fs, ip->i_number); in ext2_alloc()
132 bno = (daddr_t)ext2_hashalloc(ip, cg, bpref, fs->e2fs_bsize, in ext2_alloc()
136 ip->i_next_alloc_block = lbn; in ext2_alloc()
137 ip->i_next_alloc_goal = bno; in ext2_alloc()
139 ip->i_blocks += btodb(fs->e2fs_bsize); in ext2_alloc()
140 ip->i_flag |= IN_CHANGE | IN_UPDATE; in ext2_alloc()
159 fs = ip->i_e2fs; in ext2_alloc_meta()
161 EXT2_LOCK(ip->i_ump); in ext2_alloc_meta()
162 blk = ext2_hashalloc(ip, ino_to_cg(fs, ip->i_number), 0, fs->e2fs_bsize, in ext2_alloc_meta()
165 EXT2_UNLOCK(ip->i_ump); in ext2_alloc_meta()
218 vp = ap->a_vp; in ext2_reallocblks()
220 fs = ip->i_e2fs; in ext2_reallocblks()
221 ump = ip->i_ump; in ext2_reallocblks()
223 if (fs->e2fs_contigsumsize <= 0 || ip->i_flag & IN_E4EXTENTS) in ext2_reallocblks()
226 buflist = ap->a_buflist; in ext2_reallocblks()
227 len = buflist->bs_nchildren; in ext2_reallocblks()
228 start_lbn = buflist->bs_children[0]->b_lblkno; in ext2_reallocblks()
229 end_lbn = start_lbn + len - 1; in ext2_reallocblks()
232 if (buflist->bs_children[i]->b_lblkno != start_lbn + i) in ext2_reallocblks()
233 panic("ext2_reallocblks: non-cluster"); in ext2_reallocblks()
236 * If the cluster crosses the boundary for the first indirect in ext2_reallocblks()
252 if (dtog(fs, dbtofsb(fs, buflist->bs_children[0]->b_blkno)) != in ext2_reallocblks()
253 dtog(fs, dbtofsb(fs, buflist->bs_children[len - 1]->b_blkno))) in ext2_reallocblks()
262 sbap = &ip->i_db[0]; in ext2_reallocblks()
265 idp = &start_ap[start_lvl - 1]; in ext2_reallocblks()
266 if (bread(vp, idp->in_lbn, (int)fs->e2fs_bsize, NOCRED, &sbp)) { in ext2_reallocblks()
270 sbap = (u_int *)sbp->b_data; in ext2_reallocblks()
271 soff = idp->in_off; in ext2_reallocblks()
277 if (end_lvl == 0 || (idp = &end_ap[end_lvl - 1])->in_off + 1 >= len) { in ext2_reallocblks()
281 if (start_ap[start_lvl - 1].in_lbn == idp->in_lbn) in ext2_reallocblks()
284 ssize = len - (idp->in_off + 1); in ext2_reallocblks()
285 if (bread(vp, idp->in_lbn, (int)fs->e2fs_bsize, NOCRED, &ebp)) in ext2_reallocblks()
287 ebap = (u_int *)ebp->b_data; in ext2_reallocblks()
290 * Find the preferred location for the cluster. in ext2_reallocblks()
310 ip->i_number, start_lbn, end_lbn); in ext2_reallocblks()
312 for (bap = &sbap[soff], i = 0; i < len; i++, blkno += fs->e2fs_fpb) { in ext2_reallocblks()
315 soff = -i; in ext2_reallocblks()
318 if (buflist->bs_children[i]->b_blkno != fsbtodb(fs, *bap)) in ext2_reallocblks()
333 * been written. The flag should be set when the cluster is in ext2_reallocblks()
338 if (sbap != &ip->i_db[0]) { in ext2_reallocblks()
344 ip->i_flag |= IN_CHANGE | IN_UPDATE; in ext2_reallocblks()
357 for (blkno = newblk, i = 0; i < len; i++, blkno += fs->e2fs_fpb) { in ext2_reallocblks()
358 ext2_blkfree(ip, dbtofsb(fs, buflist->bs_children[i]->b_blkno), in ext2_reallocblks()
359 fs->e2fs_bsize); in ext2_reallocblks()
360 buflist->bs_children[i]->b_blkno = fsbtodb(fs, blkno); in ext2_reallocblks()
369 if (sbap != &ip->i_db[0]) in ext2_reallocblks()
379 ext2_valloc(struct vnode *pvp, int mode, struct ucred *cred, struct vnode **vpp) in ext2_valloc() argument
393 fs = pip->i_e2fs; in ext2_valloc()
394 ump = pip->i_ump; in ext2_valloc()
397 if (fs->e2fs_ficount == 0) in ext2_valloc()
404 if ((mode & IFMT) == IFDIR) { in ext2_valloc()
406 if (fs->e2fs_contigdirs[cg] < 255) in ext2_valloc()
407 fs->e2fs_contigdirs[cg]++; in ext2_valloc()
409 cg = ino_to_cg(fs, pip->i_number); in ext2_valloc()
410 if (fs->e2fs_contigdirs[cg] > 0) in ext2_valloc()
411 fs->e2fs_contigdirs[cg]--; in ext2_valloc()
413 ipref = cg * fs->e2fs_ipg + 1; in ext2_valloc()
414 ino = (ino_t)ext2_hashalloc(pip, cg, (long)ipref, mode, ext2_nodealloccg); in ext2_valloc()
419 error = vfs_hash_get(ump->um_mountp, ino, LK_EXCLUSIVE, td, vpp, NULL, NULL); in ext2_valloc()
427 if ((error = getnewvnode("ext2fs", ump->um_mountp, &ext2_vnodeops, &vp)) != 0) { in ext2_valloc()
432 lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL); in ext2_valloc()
433 vp->v_data = ip; in ext2_valloc()
434 ip->i_vnode = vp; in ext2_valloc()
435 ip->i_e2fs = fs = ump->um_e2fs; in ext2_valloc()
436 ip->i_ump = ump; in ext2_valloc()
437 ip->i_number = ino; in ext2_valloc()
438 ip->i_block_group = ino_to_cg(fs, ino); in ext2_valloc()
439 ip->i_next_alloc_block = 0; in ext2_valloc()
440 ip->i_next_alloc_goal = 0; in ext2_valloc()
442 error = insmntque(vp, ump->um_mountp); in ext2_valloc()
455 if ((error = ext2_vinit(ump->um_mountp, &ext2_fifoops, &vp)) != 0) { in ext2_valloc()
463 && (S_ISREG(mode) || S_ISDIR(mode))) in ext2_valloc()
466 memset(ip->i_data, 0, sizeof(ip->i_data)); in ext2_valloc()
473 ip->i_gen = arc4random(); in ext2_valloc()
474 } while (ip->i_gen == 0); in ext2_valloc()
477 ip->i_birthtime = ts.tv_sec; in ext2_valloc()
478 ip->i_birthnsec = ts.tv_nsec; in ext2_valloc()
492 * 64-bit compatible getters and setters for struct ext2_gd from ext2fs.h
498 return (((uint64_t)(le32toh(gd->ext4bgd_b_bitmap_hi)) << 32) | in e2fs_gd_get_b_bitmap()
499 le32toh(gd->ext2bgd_b_bitmap)); in e2fs_gd_get_b_bitmap()
506 return (((uint64_t)(le32toh(gd->ext4bgd_i_bitmap_hi)) << 32) | in e2fs_gd_get_i_bitmap()
507 le32toh(gd->ext2bgd_i_bitmap)); in e2fs_gd_get_i_bitmap()
514 return (((uint64_t)(le32toh(gd->ext4bgd_i_tables_hi)) << 32) | in e2fs_gd_get_i_tables()
515 le32toh(gd->ext2bgd_i_tables)); in e2fs_gd_get_i_tables()
522 return (((uint32_t)(le16toh(gd->ext4bgd_nbfree_hi)) << 16) | in e2fs_gd_get_nbfree()
523 le16toh(gd->ext2bgd_nbfree)); in e2fs_gd_get_nbfree()
530 gd->ext2bgd_nbfree = htole16(val & 0xffff); in e2fs_gd_set_nbfree()
531 gd->ext4bgd_nbfree_hi = htole16(val >> 16); in e2fs_gd_set_nbfree()
538 return (((uint32_t)(le16toh(gd->ext4bgd_nifree_hi)) << 16) | in e2fs_gd_get_nifree()
539 le16toh(gd->ext2bgd_nifree)); in e2fs_gd_get_nifree()
546 gd->ext2bgd_nifree = htole16(val & 0xffff); in e2fs_gd_set_nifree()
547 gd->ext4bgd_nifree_hi = htole16(val >> 16); in e2fs_gd_set_nifree()
554 return (((uint32_t)(le16toh(gd->ext4bgd_ndirs_hi)) << 16) | in e2fs_gd_get_ndirs()
555 le16toh(gd->ext2bgd_ndirs)); in e2fs_gd_get_ndirs()
562 gd->ext2bgd_ndirs = htole16(val & 0xffff); in e2fs_gd_set_ndirs()
563 gd->ext4bgd_ndirs_hi = htole16(val >> 16); in e2fs_gd_set_ndirs()
569 return ((uint32_t)(le16toh(gd->ext4bgd_i_unused_hi) << 16) | in e2fs_gd_get_i_unused()
570 le16toh(gd->ext4bgd_i_unused)); in e2fs_gd_get_i_unused()
577 gd->ext4bgd_i_unused = htole16(val & 0xffff); in e2fs_gd_set_i_unused()
578 gd->ext4bgd_i_unused_hi = htole16(val >> 16); in e2fs_gd_set_i_unused()
606 mtx_assert(EXT2_MTX(pip->i_ump), MA_OWNED); in ext2_dirpref()
607 fs = pip->i_e2fs; in ext2_dirpref()
609 avgifree = fs->e2fs_ficount / fs->e2fs_gcount; in ext2_dirpref()
610 avgbfree = fs->e2fs_fbcount / fs->e2fs_gcount; in ext2_dirpref()
611 avgndir = fs->e2fs_total_dir / fs->e2fs_gcount; in ext2_dirpref()
617 if (ITOV(pip)->v_vflag & VV_ROOT) { in ext2_dirpref()
618 prefcg = arc4random() % fs->e2fs_gcount; in ext2_dirpref()
620 minndir = fs->e2fs_ipg; in ext2_dirpref()
621 for (cg = prefcg; cg < fs->e2fs_gcount; cg++) in ext2_dirpref()
622 if (e2fs_gd_get_ndirs(&fs->e2fs_gd[cg]) < minndir && in ext2_dirpref()
623 e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) >= avgifree && in ext2_dirpref()
624 e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) >= avgbfree) { in ext2_dirpref()
626 minndir = e2fs_gd_get_ndirs(&fs->e2fs_gd[cg]); in ext2_dirpref()
629 if (e2fs_gd_get_ndirs(&fs->e2fs_gd[cg]) < minndir && in ext2_dirpref()
630 e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) >= avgifree && in ext2_dirpref()
631 e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) >= avgbfree) { in ext2_dirpref()
633 minndir = e2fs_gd_get_ndirs(&fs->e2fs_gd[cg]); in ext2_dirpref()
641 maxndir = min(avgndir + fs->e2fs_ipg / 16, fs->e2fs_ipg); in ext2_dirpref()
642 minifree = avgifree - avgifree / 4; in ext2_dirpref()
645 minbfree = avgbfree - avgbfree / 4; in ext2_dirpref()
648 cgsize = fs->e2fs_fsize * fs->e2fs_fpg; in ext2_dirpref()
651 (cgsize - avgbfree * fs->e2fs_bsize) / avgndir : 0; in ext2_dirpref()
654 maxcontigdirs = min((avgbfree * fs->e2fs_bsize) / dirsize, 255); in ext2_dirpref()
655 maxcontigdirs = min(maxcontigdirs, fs->e2fs_ipg / AFPDIR); in ext2_dirpref()
664 prefcg = ino_to_cg(fs, pip->i_number); in ext2_dirpref()
665 for (cg = prefcg; cg < fs->e2fs_gcount; cg++) in ext2_dirpref()
666 if (e2fs_gd_get_ndirs(&fs->e2fs_gd[cg]) < maxndir && in ext2_dirpref()
667 e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) >= minifree && in ext2_dirpref()
668 e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) >= minbfree) { in ext2_dirpref()
669 if (fs->e2fs_contigdirs[cg] < maxcontigdirs) in ext2_dirpref()
673 if (e2fs_gd_get_ndirs(&fs->e2fs_gd[cg]) < maxndir && in ext2_dirpref()
674 e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) >= minifree && in ext2_dirpref()
675 e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) >= minbfree) { in ext2_dirpref()
676 if (fs->e2fs_contigdirs[cg] < maxcontigdirs) in ext2_dirpref()
682 for (cg = prefcg; cg < fs->e2fs_gcount; cg++) in ext2_dirpref()
683 if (e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) >= avgifree) in ext2_dirpref()
686 if (e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) >= avgifree) in ext2_dirpref()
711 fs = ip->i_e2fs; in ext2_blkpref()
713 mtx_assert(EXT2_MTX(ip->i_ump), MA_OWNED); in ext2_blkpref()
719 if (ip->i_next_alloc_block == lbn && ip->i_next_alloc_goal != 0) in ext2_blkpref()
720 return ip->i_next_alloc_goal; in ext2_blkpref()
727 for (tmp = indx - 1; tmp >= 0; tmp--) in ext2_blkpref()
736 (e2fs_daddr_t)(ip->i_block_group * in ext2_blkpref()
737 EXT2_BLOCKS_PER_GROUP(fs)) + le32toh(fs->e2fs->e2fs_first_dblock)); in ext2_blkpref()
756 mtx_assert(EXT2_MTX(ip->i_ump), MA_OWNED); in ext2_hashalloc()
757 fs = ip->i_e2fs; in ext2_hashalloc()
767 for (i = 1; i < fs->e2fs_gcount; i *= 2) { in ext2_hashalloc()
769 if (cg >= fs->e2fs_gcount) in ext2_hashalloc()
770 cg -= fs->e2fs_gcount; in ext2_hashalloc()
780 cg = (icg + 2) % fs->e2fs_gcount; in ext2_hashalloc()
781 for (i = 2; i < fs->e2fs_gcount; i++) { in ext2_hashalloc()
786 if (cg == fs->e2fs_gcount) in ext2_hashalloc()
800 return (le32toh(fs->e2fs->e3fs_first_meta_bg)); in ext2_cg_number_gdb_nometa()
802 return ((fs->e2fs_gcount + EXT2_DESCS_PER_BLOCK(fs) - 1) / in ext2_cg_number_gdb_nometa()
814 last = first + EXT2_DESCS_PER_BLOCK(fs) - 1; in ext2_cg_number_gdb_meta()
827 first_meta_bg = le32toh(fs->e2fs->e3fs_first_meta_bg); in ext2_cg_number_gdb()
845 cg < le32toh(fs->e2fs->e3fs_first_meta_bg) * in ext2_number_base_meta_blocks()
849 number += le16toh(fs->e2fs->e2fs_reserved_ngdb); in ext2_number_base_meta_blocks()
869 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3); in ext2_mark_bitmap_end()
876 return ((block - le32toh(fs->e2fs->e2fs_first_dblock)) / in ext2_get_group_number()
877 fs->e2fs_bsize); in ext2_get_group_number()
893 if (!(le16toh(fs->e2fs_gd[cg].ext4bgd_flags) & EXT2_BG_BLOCK_UNINIT)) in ext2_cg_block_bitmap_init()
896 memset(bp->b_data, 0, fs->e2fs_bsize); in ext2_cg_block_bitmap_init()
899 if ((bit_max >> 3) >= fs->e2fs_bsize) in ext2_cg_block_bitmap_init()
903 setbit(bp->b_data, bit); in ext2_cg_block_bitmap_init()
905 start = (uint64_t)cg * fs->e2fs_bpg + in ext2_cg_block_bitmap_init()
906 le32toh(fs->e2fs->e2fs_first_dblock); in ext2_cg_block_bitmap_init()
909 tmp = e2fs_gd_get_b_bitmap(&fs->e2fs_gd[cg]); in ext2_cg_block_bitmap_init()
912 setbit(bp->b_data, tmp - start); in ext2_cg_block_bitmap_init()
914 tmp = e2fs_gd_get_i_bitmap(&fs->e2fs_gd[cg]); in ext2_cg_block_bitmap_init()
917 setbit(bp->b_data, tmp - start); in ext2_cg_block_bitmap_init()
919 tmp = e2fs_gd_get_i_tables(&fs->e2fs_gd[cg]); in ext2_cg_block_bitmap_init()
920 inodes_per_block = fs->e2fs_bsize/EXT2_INODE_SIZE(fs); in ext2_cg_block_bitmap_init()
921 while( tmp < e2fs_gd_get_i_tables(&fs->e2fs_gd[cg]) + in ext2_cg_block_bitmap_init()
922 fs->e2fs_ipg / inodes_per_block ) { in ext2_cg_block_bitmap_init()
925 setbit(bp->b_data, tmp - start); in ext2_cg_block_bitmap_init()
934 ext2_mark_bitmap_end(fs->e2fs_bpg, fs->e2fs_bsize * 8, in ext2_cg_block_bitmap_init()
935 bp->b_data); in ext2_cg_block_bitmap_init()
938 fs->e2fs_gd[cg].ext4bgd_flags = htole16(le16toh( in ext2_cg_block_bitmap_init()
939 fs->e2fs_gd[cg].ext4bgd_flags) & ~EXT2_BG_BLOCK_UNINIT); in ext2_cg_block_bitmap_init()
961 gd = &fs->e2fs_gd[cg]; in ext2_b_bitmap_validate()
962 max_bit = fs->e2fs_fpg; in ext2_b_bitmap_validate()
963 group_first_block = ((uint64_t)cg) * fs->e2fs_fpg + in ext2_b_bitmap_validate()
964 le32toh(fs->e2fs->e2fs_first_dblock); in ext2_b_bitmap_validate()
967 offset = e2fs_gd_get_b_bitmap(gd) - group_first_block; in ext2_b_bitmap_validate()
968 if (offset >= max_bit || !isset(bp->b_data, offset)) { in ext2_b_bitmap_validate()
975 offset = e2fs_gd_get_i_bitmap(gd) - group_first_block; in ext2_b_bitmap_validate()
976 if (offset >= max_bit || !isset(bp->b_data, offset)) { in ext2_b_bitmap_validate()
983 offset = e2fs_gd_get_i_tables(gd) - group_first_block; in ext2_b_bitmap_validate()
984 if (offset >= max_bit || offset + fs->e2fs_itpg >= max_bit) { in ext2_b_bitmap_validate()
1009 fs = ip->i_e2fs; in ext2_alloccg()
1010 ump = ip->i_ump; in ext2_alloccg()
1011 if (e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) == 0) in ext2_alloccg()
1015 error = bread(ip->i_devvp, fsbtodb(fs, in ext2_alloccg()
1016 e2fs_gd_get_b_bitmap(&fs->e2fs_gd[cg])), in ext2_alloccg()
1017 (int)fs->e2fs_bsize, NOCRED, &bp); in ext2_alloccg()
1041 if (e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) == 0) in ext2_alloccg()
1044 bbp = (char *)bp->b_data; in ext2_alloccg()
1068 end = howmany(fs->e2fs_fpg, NBBY); in ext2_alloccg()
1081 runlen = NBBY - bit; in ext2_alloccg()
1091 bit = ffs(bbp[loc]) - 1; in ext2_alloccg()
1100 runlen = NBBY - bit; in ext2_alloccg()
1123 cg, (intmax_t)bno, fs->e2fs_fsmnt); in ext2_alloccg()
1129 ext2_clusteracct(fs, bbp, cg, bno, -1); in ext2_alloccg()
1130 fs->e2fs_fbcount--; in ext2_alloccg()
1131 e2fs_gd_set_nbfree(&fs->e2fs_gd[cg], in ext2_alloccg()
1132 e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) - 1); in ext2_alloccg()
1133 fs->e2fs_fmod = 1; in ext2_alloccg()
1137 return (((uint64_t)cg) * fs->e2fs_fpg + in ext2_alloccg()
1138 le32toh(fs->e2fs->e2fs_first_dblock) + bno); in ext2_alloccg()
1147 * Determine whether a cluster can be allocated.
1160 fs = ip->i_e2fs; in ext2_clusteralloc()
1161 ump = ip->i_ump; in ext2_clusteralloc()
1163 if (fs->e2fs_maxcluster[cg] < len) in ext2_clusteralloc()
1167 error = bread(ip->i_devvp, in ext2_clusteralloc()
1168 fsbtodb(fs, e2fs_gd_get_b_bitmap(&fs->e2fs_gd[cg])), in ext2_clusteralloc()
1169 (int)fs->e2fs_bsize, NOCRED, &bp); in ext2_clusteralloc()
1173 bbp = (char *)bp->b_data; in ext2_clusteralloc()
1176 * Check to see if a cluster of the needed size (or bigger) is in ext2_clusteralloc()
1179 lp = &fs->e2fs_clustersum[cg].cs_sum[len]; in ext2_clusteralloc()
1180 for (i = len; i <= fs->e2fs_contigsumsize; i++) in ext2_clusteralloc()
1183 if (i > fs->e2fs_contigsumsize) { in ext2_clusteralloc()
1185 * Update the cluster summary information to reflect in ext2_clusteralloc()
1186 * the true maximum-sized cluster so that future cluster in ext2_clusteralloc()
1188 * to find no cluster. in ext2_clusteralloc()
1190 lp = &fs->e2fs_clustersum[cg].cs_sum[len - 1]; in ext2_clusteralloc()
1191 for (i = len - 1; i > 0; i--) in ext2_clusteralloc()
1192 if (*lp-- > 0) in ext2_clusteralloc()
1194 fs->e2fs_maxcluster[cg] = i; in ext2_clusteralloc()
1199 /* Search the bitmap to find a big enough cluster like in FFS. */ in ext2_clusteralloc()
1206 for (run = 0, got = bpref; got < fs->e2fs_fpg; got++) { in ext2_clusteralloc()
1214 if ((got & (NBBY - 1)) != (NBBY - 1)) in ext2_clusteralloc()
1222 if (got >= fs->e2fs_fpg) in ext2_clusteralloc()
1225 /* Allocate the cluster that we found. */ in ext2_clusteralloc()
1227 if (!isclr(bbp, got - run + i)) in ext2_clusteralloc()
1230 bno = got - run + 1; in ext2_clusteralloc()
1231 if (bno >= fs->e2fs_fpg) in ext2_clusteralloc()
1235 for (i = 0; i < len; i += fs->e2fs_fpb) { in ext2_clusteralloc()
1237 ext2_clusteracct(fs, bbp, cg, bno + i, -1); in ext2_clusteralloc()
1238 fs->e2fs_fbcount--; in ext2_clusteralloc()
1239 e2fs_gd_set_nbfree(&fs->e2fs_gd[cg], in ext2_clusteralloc()
1240 e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) - 1); in ext2_clusteralloc()
1242 fs->e2fs_fmod = 1; in ext2_clusteralloc()
1246 return (cg * fs->e2fs_fpg + le32toh(fs->e2fs->e2fs_first_dblock) in ext2_clusteralloc()
1263 fs = ip->i_e2fs; in ext2_zero_inode_table()
1265 if (le16toh(fs->e2fs_gd[cg].ext4bgd_flags) & EXT2_BG_INODE_ZEROED) in ext2_zero_inode_table()
1268 all_blks = le16toh(fs->e2fs->e2fs_inode_size) * fs->e2fs_ipg / in ext2_zero_inode_table()
1269 fs->e2fs_bsize; in ext2_zero_inode_table()
1271 used_blks = howmany(fs->e2fs_ipg - in ext2_zero_inode_table()
1272 e2fs_gd_get_i_unused(&fs->e2fs_gd[cg]), in ext2_zero_inode_table()
1273 fs->e2fs_bsize / EXT2_INODE_SIZE(fs)); in ext2_zero_inode_table()
1275 for (i = 0; i < all_blks - used_blks; i++) { in ext2_zero_inode_table()
1276 bp = getblk(ip->i_devvp, fsbtodb(fs, in ext2_zero_inode_table()
1277 e2fs_gd_get_i_tables(&fs->e2fs_gd[cg]) + used_blks + i), in ext2_zero_inode_table()
1278 fs->e2fs_bsize, 0, 0, 0); in ext2_zero_inode_table()
1282 vfs_bio_bzero_buf(bp, 0, fs->e2fs_bsize); in ext2_zero_inode_table()
1286 fs->e2fs_gd[cg].ext4bgd_flags = htole16(le16toh( in ext2_zero_inode_table()
1287 fs->e2fs_gd[cg].ext4bgd_flags) | EXT2_BG_INODE_ZEROED); in ext2_zero_inode_table()
1308 ext2_nodealloccg(struct inode *ip, int cg, daddr_t ipref, int mode) in ext2_nodealloccg() argument
1316 ipref--; /* to avoid a lot of (ipref -1) */ in ext2_nodealloccg()
1317 if (ipref == -1) in ext2_nodealloccg()
1319 fs = ip->i_e2fs; in ext2_nodealloccg()
1320 ump = ip->i_ump; in ext2_nodealloccg()
1321 if (e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) == 0) in ext2_nodealloccg()
1324 error = bread(ip->i_devvp, fsbtodb(fs, in ext2_nodealloccg()
1325 e2fs_gd_get_i_bitmap(&fs->e2fs_gd[cg])), in ext2_nodealloccg()
1326 (int)fs->e2fs_bsize, NOCRED, &bp); in ext2_nodealloccg()
1333 if (le16toh(fs->e2fs_gd[cg].ext4bgd_flags) & in ext2_nodealloccg()
1335 ibytes = fs->e2fs_ipg / 8; in ext2_nodealloccg()
1336 memset(bp->b_data, 0, ibytes - 1); in ext2_nodealloccg()
1337 ext2_fix_bitmap_tail(bp->b_data, ibytes, in ext2_nodealloccg()
1338 fs->e2fs_bsize - 1); in ext2_nodealloccg()
1339 fs->e2fs_gd[cg].ext4bgd_flags = htole16(le16toh( in ext2_nodealloccg()
1340 fs->e2fs_gd[cg].ext4bgd_flags) & in ext2_nodealloccg()
1357 if (e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) == 0) { in ext2_nodealloccg()
1359 * Another thread allocated the last i-node in this in ext2_nodealloccg()
1366 ibp = (char *)bp->b_data; in ext2_nodealloccg()
1368 ipref %= fs->e2fs_ipg; in ext2_nodealloccg()
1373 len = howmany(fs->e2fs_ipg - ipref, NBBY); in ext2_nodealloccg()
1382 fs->e2fs_fsmnt); in ext2_nodealloccg()
1388 ipref = (loc - ibp) * NBBY + ffs(~*loc) - 1; in ext2_nodealloccg()
1392 e2fs_gd_set_nifree(&fs->e2fs_gd[cg], in ext2_nodealloccg()
1393 e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) - 1); in ext2_nodealloccg()
1396 ifree = fs->e2fs_ipg - e2fs_gd_get_i_unused(&fs->e2fs_gd[cg]); in ext2_nodealloccg()
1398 e2fs_gd_set_i_unused(&fs->e2fs_gd[cg], in ext2_nodealloccg()
1399 fs->e2fs_ipg - (ipref + 1)); in ext2_nodealloccg()
1401 fs->e2fs_ficount--; in ext2_nodealloccg()
1402 fs->e2fs_fmod = 1; in ext2_nodealloccg()
1403 if ((mode & IFMT) == IFDIR) { in ext2_nodealloccg()
1404 e2fs_gd_set_ndirs(&fs->e2fs_gd[cg], in ext2_nodealloccg()
1405 e2fs_gd_get_ndirs(&fs->e2fs_gd[cg]) + 1); in ext2_nodealloccg()
1406 fs->e2fs_total_dir++; in ext2_nodealloccg()
1411 return ((uint64_t)cg * fs->e2fs_ipg + ipref + 1); in ext2_nodealloccg()
1427 fs = ip->i_e2fs; in ext2_blkfree()
1428 ump = ip->i_ump; in ext2_blkfree()
1430 if (bno >= fs->e2fs_bcount) { in ext2_blkfree()
1432 ip->i_number, bno); in ext2_blkfree()
1435 error = bread(ip->i_devvp, in ext2_blkfree()
1436 fsbtodb(fs, e2fs_gd_get_b_bitmap(&fs->e2fs_gd[cg])), in ext2_blkfree()
1437 (int)fs->e2fs_bsize, NOCRED, &bp); in ext2_blkfree()
1441 bbp = (char *)bp->b_data; in ext2_blkfree()
1445 (long long)bno, fs->e2fs_fsmnt); in ext2_blkfree()
1450 fs->e2fs_fbcount++; in ext2_blkfree()
1451 e2fs_gd_set_nbfree(&fs->e2fs_gd[cg], in ext2_blkfree()
1452 e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) + 1); in ext2_blkfree()
1453 fs->e2fs_fmod = 1; in ext2_blkfree()
1464 ext2_vfree(struct vnode *pvp, ino_t ino, int mode) in ext2_vfree() argument
1474 fs = pip->i_e2fs; in ext2_vfree()
1475 ump = pip->i_ump; in ext2_vfree()
1476 if ((u_int)ino > fs->e2fs_ipg * fs->e2fs_gcount) in ext2_vfree()
1478 pip->i_devvp, (uintmax_t)ino, fs->e2fs_fsmnt); in ext2_vfree()
1481 error = bread(pip->i_devvp, in ext2_vfree()
1482 fsbtodb(fs, e2fs_gd_get_i_bitmap(&fs->e2fs_gd[cg])), in ext2_vfree()
1483 (int)fs->e2fs_bsize, NOCRED, &bp); in ext2_vfree()
1487 ibp = (char *)bp->b_data; in ext2_vfree()
1488 ino = (ino - 1) % fs->e2fs_ipg; in ext2_vfree()
1491 fs->e2fs_fsmnt, ino); in ext2_vfree()
1492 if (fs->e2fs_ronly == 0) in ext2_vfree()
1497 fs->e2fs_ficount++; in ext2_vfree()
1498 e2fs_gd_set_nifree(&fs->e2fs_gd[cg], in ext2_vfree()
1499 e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) + 1); in ext2_vfree()
1500 if ((mode & IFMT) == IFDIR) { in ext2_vfree()
1501 e2fs_gd_set_ndirs(&fs->e2fs_gd[cg], in ext2_vfree()
1502 e2fs_gd_get_ndirs(&fs->e2fs_gd[cg]) - 1); in ext2_vfree()
1503 fs->e2fs_total_dir--; in ext2_vfree()
1505 fs->e2fs_fmod = 1; in ext2_vfree()
1532 len = howmany(fs->e2fs_fpg, NBBY) - start; in ext2_mapsearch()
1540 "fs=%s", start, len, fs->e2fs_fsmnt); in ext2_mapsearch()
1544 return ((loc - bbp) * NBBY + ffs(~*loc) - 1); in ext2_mapsearch()
1556 if (cg == le32toh(fs->e2fs->e4fs_backup_bgs[0]) || in ext2_cg_has_sb()
1557 cg == le32toh(fs->e2fs->e4fs_backup_bgs[1])) in ext2_cg_has_sb()