Lines Matching refs:fs
56 #include <ufs/ffs/fs.h>
69 static int32_t ffs_mapsearch(struct fs *, struct cg *, daddr_t, int);
94 struct fs *fs = ip->i_fs;
99 if (size > fs->fs_bsize || fragoff(fs, size) != 0) {
101 fs->fs_bsize, size);
103 if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
105 if (bpref >= fs->fs_size)
108 cg = ino_to_cg(fs, ip->i_number);
110 cg = dtog(fs, bpref);
154 struct fs *fs;
158 fs = ip->i_fs;
159 if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) {
160 if (lbn < NDADDR + NINDIR(fs)) {
161 cg = ino_to_cg(fs, ip->i_number);
162 return (fs->fs_fpg * cg + fs->fs_frag);
170 ino_to_cg(fs, ip->i_number) + lbn / fs->fs_maxbpg;
172 startcg = dtog(fs,
173 ufs_rw32(bap[indx - 1], UFS_FSNEEDSWAP(fs)) + 1);
174 startcg %= fs->fs_ncg;
175 avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
176 for (cg = startcg; cg < fs->fs_ncg; cg++)
177 if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree)
178 return (fs->fs_fpg * cg + fs->fs_frag);
180 if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree)
181 return (fs->fs_fpg * cg + fs->fs_frag);
187 return ufs_rw32(bap[indx - 1], UFS_FSNEEDSWAP(fs)) + fs->fs_frag;
193 struct fs *fs;
197 fs = ip->i_fs;
198 if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) {
199 if (lbn < NDADDR + NINDIR(fs)) {
200 cg = ino_to_cg(fs, ip->i_number);
201 return (fs->fs_fpg * cg + fs->fs_frag);
209 ino_to_cg(fs, ip->i_number) + lbn / fs->fs_maxbpg;
211 startcg = dtog(fs,
212 ufs_rw64(bap[indx - 1], UFS_FSNEEDSWAP(fs)) + 1);
213 startcg %= fs->fs_ncg;
214 avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
215 for (cg = startcg; cg < fs->fs_ncg; cg++)
216 if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
217 return (fs->fs_fpg * cg + fs->fs_frag);
220 if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
221 return (fs->fs_fpg * cg + fs->fs_frag);
228 return ufs_rw64(bap[indx - 1], UFS_FSNEEDSWAP(fs)) + fs->fs_frag;
246 struct fs *fs;
250 fs = ip->i_fs;
260 for (i = 1; i < fs->fs_ncg; i *= 2) {
262 if (cg >= fs->fs_ncg)
263 cg -= fs->fs_ncg;
273 cg = (icg + 2) % fs->fs_ncg;
274 for (i = 2; i < fs->fs_ncg; i++) {
279 if (cg == fs->fs_ncg)
298 struct fs *fs = ip->i_fs;
299 const int needswap = UFS_FSNEEDSWAP(fs);
301 if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize)
303 error = bread(ip->i_fd, ip->i_fs, fsbtodb(fs, cgtod(fs, cg)),
304 (int)fs->fs_cgsize, &bp);
311 (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) {
315 if (size == fs->fs_bsize) {
325 frags = numfrags(fs, size);
326 for (allocsiz = frags; allocsiz < fs->fs_frag; allocsiz++)
329 if (allocsiz == fs->fs_frag) {
339 bpref = dtogd(fs, bno);
340 for (i = frags; i < fs->fs_frag; i++)
342 i = fs->fs_frag - frags;
344 fs->fs_cstotal.cs_nffree += i;
345 fs->fs_cs(fs, cg).cs_nffree += i;
346 fs->fs_fmod = 1;
351 bno = ffs_mapsearch(fs, cgp, bpref, allocsiz);
355 fs->fs_cstotal.cs_nffree -= frags;
356 fs->fs_cs(fs, cg).cs_nffree -= frags;
357 fs->fs_fmod = 1;
361 blkno = cg * fs->fs_fpg + bno;
383 struct fs *fs = ip->i_fs;
384 const int needswap = UFS_FSNEEDSWAP(fs);
389 if (bpref == 0 || (uint32_t)dtog(fs, bpref) != ufs_rw32(cgp->cg_cgx, needswap)) {
392 bpref = blknum(fs, bpref);
393 bno = dtogd(fs, bpref);
397 if (ffs_isblock(fs, blksfree_swap, fragstoblks(fs, bno)))
403 bno = ffs_mapsearch(fs, cgp, bpref, (int)fs->fs_frag);
408 blkno = fragstoblks(fs, bno);
409 ffs_clrblock(fs, blksfree_swap, (long)blkno);
410 ffs_clusteracct(fs, cgp, blkno, -1);
412 fs->fs_cstotal.cs_nbfree--;
413 fs->fs_cs(fs, ufs_rw32(cgp->cg_cgx, needswap)).cs_nbfree--;
414 fs->fs_fmod = 1;
415 blkno = ufs_rw32(cgp->cg_cgx, needswap) * fs->fs_fpg + bno;
433 struct fs *fs = ip->i_fs;
434 const int needswap = UFS_FSNEEDSWAP(fs);
436 if (size > fs->fs_bsize || fragoff(fs, size) != 0 ||
437 fragnum(fs, bno) + numfrags(fs, size) > fs->fs_frag) {
439 (long long)bno, fs->fs_bsize, size);
441 cg = dtog(fs, bno);
442 if (bno >= fs->fs_size) {
447 error = bread(ip->i_fd, ip->i_fs, fsbtodb(fs, cgtod(fs, cg)),
448 (int)fs->fs_cgsize, &bp);
458 cgbno = dtogd(fs, bno);
459 if (size == fs->fs_bsize) {
460 fragno = fragstoblks(fs, cgbno);
461 if (!ffs_isfreeblock(fs, cg_blksfree_swap(cgp, needswap), fragno)) {
465 ffs_setblock(fs, cg_blksfree_swap(cgp, needswap), fragno);
466 ffs_clusteracct(fs, cgp, fragno, 1);
468 fs->fs_cstotal.cs_nbfree++;
469 fs->fs_cs(fs, cg).cs_nbfree++;
471 bbase = cgbno - fragnum(fs, cgbno);
475 blk = blkmap(fs, cg_blksfree_swap(cgp, needswap), bbase);
476 ffs_fragacct_swap(fs, blk, cgp->cg_frsum, -1, needswap);
480 frags = numfrags(fs, size);
489 fs->fs_cstotal.cs_nffree += i;
490 fs->fs_cs(fs, cg).cs_nffree += i;
494 blk = blkmap(fs, cg_blksfree_swap(cgp, needswap), bbase);
495 ffs_fragacct_swap(fs, blk, cgp->cg_frsum, 1, needswap);
499 fragno = fragstoblks(fs, bbase);
500 if (ffs_isblock(fs, cg_blksfree_swap(cgp, needswap), fragno)) {
501 ufs_add32(cgp->cg_cs.cs_nffree, -fs->fs_frag, needswap);
502 fs->fs_cstotal.cs_nffree -= fs->fs_frag;
503 fs->fs_cs(fs, cg).cs_nffree -= fs->fs_frag;
504 ffs_clusteracct(fs, cgp, fragno, 1);
506 fs->fs_cstotal.cs_nbfree++;
507 fs->fs_cs(fs, cg).cs_nbfree++;
510 fs->fs_fmod = 1;
532 ffs_mapsearch(struct fs *fs, struct cg *cgp, daddr_t bpref, int allocsiz)
538 const int needswap = UFS_FSNEEDSWAP(fs);
545 start = dtogd(fs, bpref) / NBBY;
548 len = howmany(fs->fs_fpg, NBBY) - start;
553 (const u_char *)fragtbl[fs->fs_frag],
554 (1 << (allocsiz - 1 + (fs->fs_frag % NBBY))));
560 (const u_char *)fragtbl[fs->fs_frag],
561 (1 << (allocsiz - 1 + (fs->fs_frag % NBBY))));
577 for (i = bno + NBBY; bno < i; bno += fs->fs_frag) {
578 blk = blkmap(fs, cg_blksfree_swap(cgp, needswap), bno);
582 for (pos = 0; pos <= fs->fs_frag - allocsiz; pos++) {
599 ffs_clusteracct(struct fs *fs, struct cg *cgp, int32_t blkno, int cnt)
605 const int needswap = UFS_FSNEEDSWAP(fs);
607 if (fs->fs_contigsumsize <= 0)
622 end = start + fs->fs_contigsumsize;
643 end = start - fs->fs_contigsumsize;
665 if (i > fs->fs_contigsumsize)
666 i = fs->fs_contigsumsize;
676 lp = &sump[fs->fs_contigsumsize];
677 for (i = fs->fs_contigsumsize; i > 0; i--)
680 fs->fs_maxcluster[ufs_rw32(cgp->cg_cgx, needswap)] = i;