Lines Matching defs:fs
82 #include <ufs/ffs/fs.h>
93 static ufs_daddr_t ffs_alloccgblk(struct fs *, struct cg *, ufs_daddr_t);
97 static void ffs_fserr(struct fs *, u_int, char *);
101 static ufs_daddr_t ffs_mapsearch(struct fs *, struct cg *, ufs_daddr_t, int);
103 (struct fs *fs, struct cg *cgp, ufs_daddr_t blkno, int cnt);
131 register struct fs *fs;
136 fs = ip->i_fs;
138 if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) {
139 printf("dev = 0x%x, bsize = %d, size = %d, fs = %s\n",
140 ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
146 if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
148 if (suser(cred, NULL) && freespace(fs, fs->fs_minfree) <= 0)
155 if (bpref >= fs->fs_size)
158 cg = ino_to_cg(fs, ip->i_number);
160 cg = dtog(fs, bpref);
176 ffs_fserr(fs, kauth_cred_getuid(cred), "file system full");
177 uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
197 register struct fs *fs;
204 fs = ip->i_fs;
206 if ((u_int)osize > fs->fs_bsize || fragoff(fs, osize) != 0 ||
207 (u_int)nsize > fs->fs_bsize || fragoff(fs, nsize) != 0) {
209 "dev = 0x%x, bsize = %d, osize = %d, nsize = %d, fs = %s\n",
210 ip->i_dev, fs->fs_bsize, osize, nsize, fs->fs_fsmnt);
216 if (suser(cred, NULL) != 0 && freespace(fs, fs->fs_minfree) <= 0)
219 printf("dev = 0x%x, bsize = %d, bprev = %d, fs = %s\n",
220 ip->i_dev, fs->fs_bsize, bprev, fs->fs_fsmnt);
242 cg = dtog(fs, bprev);
244 if ((ufs_daddr_t)buf_blkno(bp) != fsbtodb(fs, bno))
257 if (bpref >= fs->fs_size)
259 switch ((int)fs->fs_optim) {
269 if (fs->fs_minfree < 5 ||
270 fs->fs_cstotal.cs_nffree >
271 fs->fs_dsize * fs->fs_minfree / (2 * 100))
274 fs->fs_fsmnt);
275 fs->fs_optim = FS_OPTTIME;
288 request = fs->fs_bsize;
289 if (fs->fs_cstotal.cs_nffree <
290 fs->fs_dsize * (fs->fs_minfree - 2) / 100)
293 fs->fs_fsmnt);
294 fs->fs_optim = FS_OPTSPACE;
297 printf("dev = 0x%x, optim = %d, fs = %s\n",
298 ip->i_dev, fs->fs_optim, fs->fs_fsmnt);
305 buf_setblkno(bp, (daddr64_t)((unsigned)fsbtodb(fs, bno)));
308 ffs_blkfree(ip, bno + numfrags(fs, nsize),
329 ffs_fserr(fs, kauth_cred_getuid(cred), "file system full");
330 uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
378 register struct fs *fs;
386 fs = pip->i_fs;
387 if (fs->fs_cstotal.cs_nifree == 0)
394 if (ipref >= fs->fs_ncg * fs->fs_ipg)
396 cg = ino_to_cg(fs, ipref);
402 if (fs->fs_contigdirs[cg] < 255)
403 fs->fs_contigdirs[cg]++;
405 if (fs->fs_contigdirs[cg] > 0)
406 fs->fs_contigdirs[cg]--;
420 printf("mode = 0%o, inum = %d, fs = %s\n",
421 ip->i_mode, ip->i_number, fs->fs_fsmnt);
426 fs->fs_fsmnt, ino, ip->i_blocks);
439 ffs_fserr(fs, kauth_cred_getuid(cred), "out of inodes");
440 uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt);
458 register struct fs *fs;
465 fs = pip->i_fs;
466 avgifree = fs->fs_cstotal.cs_nifree / fs->fs_ncg;
467 avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
468 avgndir = fs->fs_cstotal.cs_ndir / fs->fs_ncg;
475 prefcg = random() % fs->fs_ncg;
477 prefcg = arc4random() % fs->fs_ncg;
480 minndir = fs->fs_ipg;
481 for (cg = prefcg; cg < fs->fs_ncg; cg++)
482 if (fs->fs_cs(fs, cg).cs_ndir < minndir &&
483 fs->fs_cs(fs, cg).cs_nifree >= avgifree &&
484 fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
486 minndir = fs->fs_cs(fs, cg).cs_ndir;
489 if (fs->fs_cs(fs, cg).cs_ndir < minndir &&
490 fs->fs_cs(fs, cg).cs_nifree >= avgifree &&
491 fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
493 minndir = fs->fs_cs(fs, cg).cs_ndir;
495 return ((ino_t)(fs->fs_ipg * mincg));
502 maxndir = min(avgndir + fs->fs_ipg / 16, fs->fs_ipg);
503 minifree = avgifree - fs->fs_ipg / 4;
506 minbfree = avgbfree - fs->fs_fpg / fs->fs_frag / 4;
509 cgsize = fs->fs_fsize * fs->fs_fpg;
510 dirsize = fs->fs_avgfilesize * fs->fs_avgfpdir;
511 curdirsize = avgndir ? (cgsize - avgbfree * fs->fs_bsize) / avgndir : 0;
515 if (fs->fs_avgfpdir > 0)
517 fs->fs_ipg / fs->fs_avgfpdir);
526 prefcg = ino_to_cg(fs, pip->i_number);
527 for (cg = prefcg; cg < fs->fs_ncg; cg++)
528 if (fs->fs_cs(fs, cg).cs_ndir < maxndir &&
529 fs->fs_cs(fs, cg).cs_nifree >= minifree &&
530 fs->fs_cs(fs, cg).cs_nbfree >= minbfree) {
531 if (fs->fs_contigdirs[cg] < maxcontigdirs)
532 return ((ino_t)(fs->fs_ipg * cg));
535 if (fs->fs_cs(fs, cg).cs_ndir < maxndir &&
536 fs->fs_cs(fs, cg).cs_nifree >= minifree &&
537 fs->fs_cs(fs, cg).cs_nbfree >= minbfree) {
538 if (fs->fs_contigdirs[cg] < maxcontigdirs)
539 return ((ino_t)(fs->fs_ipg * cg));
544 for (cg = prefcg; cg < fs->fs_ncg; cg++)
545 if (fs->fs_cs(fs, cg).cs_nifree >= avgifree)
546 return ((ino_t)(fs->fs_ipg * cg));
548 if (fs->fs_cs(fs, cg).cs_nifree >= avgifree)
550 return ((ino_t)(fs->fs_ipg * cg));
586 register struct fs *fs;
597 fs = ip->i_fs;
607 if (indx % fs->fs_maxbpg == 0 || prev == 0)
609 if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0)
613 cg = ino_to_cg(fs, ip->i_number);
614 return (fs->fs_fpg * cg + fs->fs_frag);
626 ino_to_cg(fs, ip->i_number) + lbn / fs->fs_maxbpg;
629 startcg = dtog(fs, prev) + 1;
631 startcg = dtog(fs, bap[indx - 1]) + 1;
633 startcg %= fs->fs_ncg;
634 avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
635 for (cg = startcg; cg < fs->fs_ncg; cg++)
636 if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
637 fs->fs_cgrotor = cg;
638 return (fs->fs_fpg * cg + fs->fs_frag);
641 if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
642 fs->fs_cgrotor = cg;
643 return (fs->fs_fpg * cg + fs->fs_frag);
655 nextblk = prev + fs->fs_frag;
656 if (indx < fs->fs_maxcontig) {
660 prev = OSSwapInt32(bap[indx - fs->fs_maxcontig]);
662 prev = bap[indx - fs->fs_maxcontig];
663 if (prev + blkstofrags(fs, fs->fs_maxcontig) != nextblk)
667 nextblk = bap[indx - 1] + fs->fs_frag;
668 if (indx < fs->fs_maxcontig || bap[indx - fs->fs_maxcontig] +
669 blkstofrags(fs, fs->fs_maxcontig) != nextblk)
674 if (fs->fs_rotdelay != 0)
681 nextblk += roundup(fs->fs_rotdelay * fs->fs_rps * fs->fs_nsect /
682 (NSPF(fs) * 1000), fs->fs_frag);
703 register struct fs *fs;
707 fs = ip->i_fs;
717 for (i = 1; i < fs->fs_ncg; i *= 2) {
719 if (cg >= fs->fs_ncg)
720 cg -= fs->fs_ncg;
730 cg = (icg + 2) % fs->fs_ncg;
731 for (i = 2; i < fs->fs_ncg; i++) {
736 if (cg == fs->fs_ncg)
755 register struct fs *fs;
768 fs = ip->i_fs;
769 if (fs->fs_cs(fs, cg).cs_nffree < numfrags(fs, nsize - osize))
771 frags = numfrags(fs, nsize); /* number of fragments needed */
772 bbase = fragnum(fs, bprev); /* offset in a frag (it is mod fragsize */
773 if (bbase > fragnum(fs, (bprev + frags - 1))) {
778 error = (int)buf_bread(ip->i_devvp, (daddr64_t)((unsigned)fsbtodb(fs, cgtod(fs, cg))),
779 (int)fs->fs_cgsize, NOCRED, &bp);
787 byte_swap_cgin(cgp, fs);
794 byte_swap_cgout(cgp,fs);
801 bno = dtogd(fs, bprev);
802 for (i = numfrags(fs, osize); i < frags; i++)
806 byte_swap_cgout(cgp,fs);
817 for (i = frags; i < fs->fs_frag - bbase; i++)
820 cgp->cg_frsum[i - numfrags(fs, osize)]--;
823 for (i = numfrags(fs, osize); i < frags; i++) {
826 fs->fs_cstotal.cs_nffree--;
827 fs->fs_cs(fs, cg).cs_nffree--;
829 fs->fs_fmod = 1;
832 byte_swap_cgout(cgp,fs);
851 register struct fs *fs;
863 fs = ip->i_fs;
864 if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize)
866 error = (int)buf_bread(ip->i_devvp, (daddr64_t)((unsigned)fsbtodb(fs, cgtod(fs, cg))),
867 (int)fs->fs_cgsize, NOCRED, &bp);
875 byte_swap_cgin(cgp,fs);
878 (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) {
881 byte_swap_cgout(cgp,fs);
888 if (size == fs->fs_bsize) {
889 bno = ffs_alloccgblk(fs, cgp, bpref);
892 byte_swap_cgout(cgp,fs);
902 frags = numfrags(fs, size);
903 for (allocsiz = frags; allocsiz < fs->fs_frag; allocsiz++)
906 if (allocsiz == fs->fs_frag) {
914 byte_swap_cgout(cgp,fs);
919 bno = ffs_alloccgblk(fs, cgp, bpref);
920 bpref = dtogd(fs, bno);
921 for (i = frags; i < fs->fs_frag; i++)
923 i = fs->fs_frag - frags;
925 fs->fs_cstotal.cs_nffree += i;
926 fs->fs_cs(fs, cg).cs_nffree += i;
927 fs->fs_fmod = 1;
931 byte_swap_cgout(cgp,fs);
936 bno = ffs_mapsearch(fs, cgp, bpref, allocsiz);
940 byte_swap_cgout(cgp,fs);
948 fs->fs_cstotal.cs_nffree -= frags;
949 fs->fs_cs(fs, cg).cs_nffree -= frags;
950 fs->fs_fmod = 1;
956 byte_swap_cgout(cgp,fs);
959 return (cg * fs->fs_fpg + bno);
974 ffs_alloccgblk(fs, cgp, bpref)
975 register struct fs *fs;
984 if (bpref == 0 || dtog(fs, bpref) != cgp->cg_cgx) {
988 bpref = blknum(fs, bpref);
989 bpref = dtogd(fs, bpref);
993 if (ffs_isblock(fs, cg_blksfree(cgp), fragstoblks(fs, bpref))) {
997 if (fs->fs_nrpos <= 1 || fs->fs_cpc == 0) {
1011 cylno = cbtocylno(fs, bpref);
1019 cylbp = cg_blks(fs, cgp, cylno);
1020 pos = cbtorpos(fs, bpref);
1021 for (i = pos; i < fs->fs_nrpos; i++)
1024 if (i == fs->fs_nrpos)
1033 pos = cylno % fs->fs_cpc;
1034 bno = (cylno - pos) * fs->fs_spc / NSPB(fs);
1035 if (fs_postbl(fs, pos)[i] == -1) {
1036 printf("pos = %d, i = %d, fs = %s\n",
1037 pos, i, fs->fs_fsmnt);
1040 for (i = fs_postbl(fs, pos)[i];; ) {
1041 if (ffs_isblock(fs, cg_blksfree(cgp), bno + i)) {
1042 bno = blkstofrags(fs, (bno + i));
1045 delta = fs_rotbl(fs)[i];
1047 delta + i > fragstoblks(fs, fs->fs_fpg))
1051 printf("pos = %d, i = %d, fs = %s\n", pos, i, fs->fs_fsmnt);
1059 bno = ffs_mapsearch(fs, cgp, bpref, (int)fs->fs_frag);
1064 blkno = fragstoblks(fs, bno);
1065 ffs_clrblock(fs, cg_blksfree(cgp), (long)blkno);
1066 ffs_clusteracct(fs, cgp, blkno, -1);
1068 fs->fs_cstotal.cs_nbfree--;
1069 fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--;
1070 cylno = cbtocylno(fs, bno);
1071 cg_blks(fs, cgp, cylno)[cbtorpos(fs, bno)]--;
1073 fs->fs_fmod = 1;
1074 return (cgp->cg_cgx * fs->fs_fpg + bno);
1091 register struct fs *fs;
1103 fs = ip->i_fs;
1104 if (fs->fs_maxcluster[cg] < len)
1106 if (buf_bread(ip->i_devvp, (daddr64_t)((unsigned)fsbtodb(fs, cgtod(fs, cg))), (int)fs->fs_cgsize,
1112 byte_swap_cgin(cgp,fs);
1117 byte_swap_cgout(cgp,fs);
1126 for (i = len; i <= fs->fs_contigsumsize; i++)
1129 if (i > fs->fs_contigsumsize) {
1141 fs->fs_maxcluster[cg] = i;
1144 byte_swap_cgout(cgp,fs);
1159 if (dtog(fs, bpref) != cg)
1162 bpref = fragstoblks(fs, dtogd(fs, blknum(fs, bpref)));
1184 byte_swap_cgout(cgp,fs);
1192 if (!ffs_isblock(fs, cg_blksfree(cgp), got - run + i))
1194 bno = cg * fs->fs_fpg + blkstofrags(fs, got - run + 1);
1195 if (dtog(fs, bno) != cg)
1197 len = blkstofrags(fs, len);
1198 for (i = 0; i < len; i += fs->fs_frag)
1199 if ((got = ffs_alloccgblk(fs, cgp, bno + i)) != bno + i)
1203 byte_swap_cgout(cgp,fs);
1229 register struct fs *fs;
1240 fs = ip->i_fs;
1241 if (fs->fs_cs(fs, cg).cs_nifree == 0)
1243 error = (int)buf_bread(ip->i_devvp, (daddr64_t)((unsigned)fsbtodb(fs, cgtod(fs, cg))),
1244 (int)fs->fs_cgsize, NOCRED, &bp);
1252 byte_swap_cgin(cgp,fs);
1257 byte_swap_cgout(cgp,fs);
1266 ipref %= fs->fs_ipg;
1271 len = howmany(fs->fs_ipg - cgp->cg_irotor, NBBY);
1278 printf("cg = %d, irotor = %d, fs = %s\n",
1279 cg, cgp->cg_irotor, fs->fs_fsmnt);
1293 printf("fs = %s\n", fs->fs_fsmnt);
1299 fs->fs_cstotal.cs_nifree--;
1300 fs->fs_cs(fs, cg).cs_nifree--;
1301 fs->fs_fmod = 1;
1304 fs->fs_cstotal.cs_ndir++;
1305 fs->fs_cs(fs, cg).cs_ndir++;
1309 byte_swap_cgout(cgp,fs);
1312 return (cg * fs->fs_ipg + ipref);
1328 register struct fs *fs;
1340 fs = ip->i_fs;
1341 if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) {
1342 printf("dev = 0x%x, bsize = %d, size = %d, fs = %s\n",
1343 ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
1346 cg = dtog(fs, bno);
1347 if ((u_int)bno >= fs->fs_size) {
1349 ffs_fserr(fs, ip->i_uid, "bad block");
1352 error = (int)buf_bread(ip->i_devvp, (daddr64_t)((unsigned)fsbtodb(fs, cgtod(fs, cg))),
1353 (int)fs->fs_cgsize, NOCRED, &bp);
1361 byte_swap_cgin(cgp,fs);
1366 byte_swap_cgout(cgp,fs);
1373 bno = dtogd(fs, bno);
1374 if (size == fs->fs_bsize) {
1375 blkno = fragstoblks(fs, bno);
1376 if (ffs_isblock(fs, cg_blksfree(cgp), blkno)) {
1377 printf("dev = 0x%x, block = %d, fs = %s\n",
1378 ip->i_dev, bno, fs->fs_fsmnt);
1381 ffs_setblock(fs, cg_blksfree(cgp), blkno);
1382 ffs_clusteracct(fs, cgp, blkno, 1);
1384 fs->fs_cstotal.cs_nbfree++;
1385 fs->fs_cs(fs, cg).cs_nbfree++;
1386 i = cbtocylno(fs, bno);
1387 cg_blks(fs, cgp, i)[cbtorpos(fs, bno)]++;
1390 bbase = bno - fragnum(fs, bno);
1394 blk = blkmap(fs, cg_blksfree(cgp), bbase);
1395 ffs_fragacct(fs, blk, cgp->cg_frsum, -1);
1399 frags = numfrags(fs, size);
1402 printf("dev = 0x%x, block = %d, fs = %s\n",
1403 ip->i_dev, bno + i, fs->fs_fsmnt);
1409 fs->fs_cstotal.cs_nffree += i;
1410 fs->fs_cs(fs, cg).cs_nffree += i;
1414 blk = blkmap(fs, cg_blksfree(cgp), bbase);
1415 ffs_fragacct(fs, blk, cgp->cg_frsum, 1);
1419 blkno = fragstoblks(fs, bbase);
1420 if (ffs_isblock(fs, cg_blksfree(cgp), blkno)) {
1421 cgp->cg_cs.cs_nffree -= fs->fs_frag;
1422 fs->fs_cstotal.cs_nffree -= fs->fs_frag;
1423 fs->fs_cs(fs, cg).cs_nffree -= fs->fs_frag;
1424 ffs_clusteracct(fs, cgp, blkno, 1);
1426 fs->fs_cstotal.cs_nbfree++;
1427 fs->fs_cs(fs, cg).cs_nbfree++;
1428 i = cbtocylno(fs, bbase);
1429 cg_blks(fs, cgp, i)[cbtorpos(fs, bbase)]++;
1433 fs->fs_fmod = 1;
1436 byte_swap_cgout(cgp,fs);
1451 struct fs *fs;
1461 fs = ip->i_fs;
1462 if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) {
1463 printf("bsize = %d, size = %d, fs = %s\n",
1464 fs->fs_bsize, size, fs->fs_fsmnt);
1467 if ((u_int)bno >= fs->fs_size)
1469 error = (int)buf_bread(ip->i_devvp, (daddr64_t)((unsigned)fsbtodb(fs, cgtod(fs, dtog(fs, bno)))),
1470 (int)fs->fs_cgsize, NOCRED, &bp);
1478 byte_swap_cgin(cgp,fs);
1483 byte_swap_cgout(cgp,fs);
1488 bno = dtogd(fs, bno);
1489 if (size == fs->fs_bsize) {
1490 free = ffs_isblock(fs, cg_blksfree(cgp), fragstoblks(fs, bno));
1492 frags = numfrags(fs, size);
1501 byte_swap_cgout(cgp,fs);
1516 register struct fs *fs;
1528 fs = pip->i_fs;
1529 if ((u_int)ino >= fs->fs_ipg * fs->fs_ncg)
1530 panic("ifree: range: dev = 0x%x, ino = %d, fs = %s\n",
1531 pip->i_dev, ino, fs->fs_fsmnt);
1532 cg = ino_to_cg(fs, ino);
1533 error = (int)buf_bread(pip->i_devvp, (daddr64_t)((unsigned)fsbtodb(fs, cgtod(fs, cg))),
1534 (int)fs->fs_cgsize, NOCRED, &bp);
1542 byte_swap_cgin(cgp,fs);
1547 byte_swap_cgout(cgp,fs);
1554 ino %= fs->fs_ipg;
1556 printf("dev = 0x%x, ino = %d, fs = %s\n",
1557 pip->i_dev, ino, fs->fs_fsmnt);
1558 if (fs->fs_ronly == 0)
1565 fs->fs_cstotal.cs_nifree++;
1566 fs->fs_cs(fs, cg).cs_nifree++;
1569 fs->fs_cstotal.cs_ndir--;
1570 fs->fs_cs(fs, cg).cs_ndir--;
1572 fs->fs_fmod = 1;
1575 byte_swap_cgout(cgp,fs);
1588 ffs_mapsearch(fs, cgp, bpref, allocsiz)
1589 register struct fs *fs;
1603 start = dtogd(fs, bpref) / NBBY;
1606 len = howmany(fs->fs_fpg, NBBY) - start;
1608 (u_char *)fragtbl[fs->fs_frag],
1609 (u_char)(1 << (allocsiz - 1 + (fs->fs_frag % NBBY))));
1614 (u_char *)fragtbl[fs->fs_frag],
1615 (u_char)(1 << (allocsiz - 1 + (fs->fs_frag % NBBY))));
1617 printf("start = %d, len = %d, fs = %s\n",
1618 start, len, fs->fs_fsmnt);
1629 for (i = bno + NBBY; bno < i; bno += fs->fs_frag) {
1630 blk = blkmap(fs, cg_blksfree(cgp), bno);
1634 for (pos = 0; pos <= fs->fs_frag - allocsiz; pos++) {
1641 printf("bno = %d, fs = %s\n", bno, fs->fs_fsmnt);
1652 ffs_clusteracct(struct fs *fs, struct cg *cgp, ufs_daddr_t blkno, int cnt)
1659 if (fs->fs_contigsumsize <= 0)
1674 end = start + fs->fs_contigsumsize;
1695 end = start - fs->fs_contigsumsize;
1717 if (i > fs->fs_contigsumsize)
1718 i = fs->fs_contigsumsize;
1727 lp = &sump[fs->fs_contigsumsize];
1728 for (i = fs->fs_contigsumsize; i > 0; i--)
1731 fs->fs_maxcluster[cgp->cg_cgx] = i;
1738 * fs: error message
1741 ffs_fserr(fs, uid, cp)
1742 struct fs *fs;
1747 log(LOG_ERR, "uid %d on %s: %s\n", uid, fs->fs_fsmnt, cp);