2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1980, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 static const char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95";
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include <sys/param.h>
41 #include <sys/stdint.h>
42 #include <sys/sysctl.h>
44 #include <ufs/ufs/dinode.h>
45 #include <ufs/ufs/dir.h>
46 #include <ufs/ffs/fs.h>
56 struct bufarea *icachebp; /* inode cache buffer */
58 static int iblock(struct inodesc *, off_t isize, int type);
59 static ufs2_daddr_t indir_blkatoff(ufs2_daddr_t, ino_t, ufs_lbn_t, ufs_lbn_t,
63 ckinode(union dinode *dp, struct inodesc *idesc)
65 off_t remsize, sizepb;
71 char pathbuf[MAXPATHLEN + 1];
73 if (idesc->id_fix != IGNORE)
74 idesc->id_fix = DONTKNOW;
77 idesc->id_lballoc = -1;
79 idesc->id_entryno = 0;
80 idesc->id_filesize = DIP(dp, di_size);
81 mode = DIP(dp, di_mode) & IFMT;
82 if (mode == IFBLK || mode == IFCHR || (mode == IFLNK &&
83 DIP(dp, di_size) < (unsigned)sblock.fs_maxsymlinklen))
85 if (sblock.fs_magic == FS_UFS1_MAGIC)
89 ndb = howmany(DIP(&dino, di_size), sblock.fs_bsize);
90 for (i = 0; i < UFS_NDADDR; i++) {
93 (offset = blkoff(&sblock, DIP(&dino, di_size))) != 0)
95 numfrags(&sblock, fragroundup(&sblock, offset));
97 idesc->id_numfrags = sblock.fs_frag;
98 if (DIP(&dino, di_db[i]) == 0) {
99 if (idesc->id_type == DATA && ndb >= 0) {
100 /* An empty block in a directory XXX */
101 getpathname(pathbuf, idesc->id_number,
103 pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
105 if (reply("ADJUST LENGTH") == 1) {
106 ginode(idesc->id_number, &ip);
107 DIP_SET(ip.i_dp, di_size,
108 i * sblock.fs_bsize);
110 "YOU MUST RERUN FSCK AFTERWARDS\n");
118 idesc->id_blkno = DIP(&dino, di_db[i]);
119 if (idesc->id_type != DATA)
120 ret = (*idesc->id_func)(idesc);
122 ret = dirscan(idesc);
126 idesc->id_numfrags = sblock.fs_frag;
127 remsize = DIP(&dino, di_size) - sblock.fs_bsize * UFS_NDADDR;
128 sizepb = sblock.fs_bsize;
129 for (i = 0; i < UFS_NIADDR; i++) {
130 sizepb *= NINDIR(&sblock);
131 idesc->id_level = i + 1;
132 if (DIP(&dino, di_ib[i])) {
133 idesc->id_blkno = DIP(&dino, di_ib[i]);
134 ret = iblock(idesc, remsize, BT_LEVEL1 + i);
137 } else if (remsize > 0) {
138 idesc->id_lbn += sizepb / sblock.fs_bsize;
139 if (idesc->id_type == DATA) {
140 /* An empty block in a directory XXX */
141 getpathname(pathbuf, idesc->id_number,
143 pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
145 if (reply("ADJUST LENGTH") == 1) {
146 ginode(idesc->id_number, &ip);
147 DIP_SET(ip.i_dp, di_size,
148 DIP(ip.i_dp, di_size) - remsize);
151 "YOU MUST RERUN FSCK AFTERWARDS\n");
165 iblock(struct inodesc *idesc, off_t isize, int type)
169 int i, n, (*func)(struct inodesc *), nif;
172 char pathbuf[MAXPATHLEN + 1];
174 if (idesc->id_type != DATA) {
175 func = idesc->id_func;
176 if (((n = (*func)(idesc)) & KEEPON) == 0)
180 bp = getdatablk(idesc->id_blkno, sblock.fs_bsize, type);
181 if (bp->b_errs != 0) {
187 for (sizepb = sblock.fs_bsize, i = 0; i < idesc->id_level; i++)
188 sizepb *= NINDIR(&sblock);
189 if (howmany(isize, sizepb) > NINDIR(&sblock))
190 nif = NINDIR(&sblock);
192 nif = howmany(isize, sizepb);
193 if (idesc->id_func == pass1check && nif < NINDIR(&sblock)) {
194 for (i = nif; i < NINDIR(&sblock); i++) {
195 if (IBLK(bp, i) == 0)
197 (void)sprintf(buf, "PARTIALLY TRUNCATED INODE I=%lu",
198 (u_long)idesc->id_number);
201 } else if (dofix(idesc, buf)) {
206 flush(fswritefd, bp);
208 for (i = 0; i < nif; i++) {
210 idesc->id_blkno = IBLK(bp, i);
212 if (idesc->id_level == 0) {
216 n = iblock(idesc, isize, type);
224 idesc->id_lbn += sizepb / sblock.fs_bsize;
225 if (idesc->id_type == DATA && isize > 0) {
226 /* An empty block in a directory XXX */
227 getpathname(pathbuf, idesc->id_number,
229 pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
231 if (reply("ADJUST LENGTH") == 1) {
232 ginode(idesc->id_number, &ip);
233 DIP_SET(ip.i_dp, di_size,
234 DIP(ip.i_dp, di_size) - isize);
237 "YOU MUST RERUN FSCK AFTERWARDS\n");
252 * Finds the disk block address at the specified lbn within the inode
253 * specified by dp. This follows the whole tree and honors di_size and
254 * di_extsize so it is a true test of reachability. The lbn may be
255 * negative if an extattr or indirect block is requested.
258 ino_blkatoff(union dinode *dp, ino_t ino, ufs_lbn_t lbn, int *frags,
259 struct bufarea **bpp)
268 * Handle extattr blocks first.
270 if (lbn < 0 && lbn >= -UFS_NXADDR) {
272 if (lbn > lblkno(&sblock, dp->dp2.di_extsize - 1))
274 *frags = numfrags(&sblock,
275 sblksize(&sblock, dp->dp2.di_extsize, lbn));
276 return (dp->dp2.di_extb[lbn]);
279 * Now direct and indirect.
281 if (DIP(dp, di_mode) == IFLNK &&
282 DIP(dp, di_size) < sblock.fs_maxsymlinklen)
284 if (lbn >= 0 && lbn < UFS_NDADDR) {
285 *frags = numfrags(&sblock,
286 sblksize(&sblock, DIP(dp, di_size), lbn));
287 return (DIP(dp, di_db[lbn]));
289 *frags = sblock.fs_frag;
291 for (i = 0, tmpval = NINDIR(&sblock), cur = UFS_NDADDR; i < UFS_NIADDR;
292 i++, tmpval *= NINDIR(&sblock), cur = next) {
295 return (DIP(dp, di_ib[i]));
297 * Determine whether the lbn in question is within this tree.
299 if (lbn < 0 && -lbn >= next)
301 if (lbn > 0 && lbn >= next)
303 return (indir_blkatoff(DIP(dp, di_ib[i]), ino, -cur - i, lbn,
306 pfatal("lbn %jd not in ino %ju\n", lbn, (uintmax_t)ino);
311 * Fetch an indirect block to find the block at a given lbn. The lbn
312 * may be negative to fetch a specific indirect block pointer or positive
313 * to fetch a specific block.
316 indir_blkatoff(ufs2_daddr_t blk, ino_t ino, ufs_lbn_t cur, ufs_lbn_t lbn,
317 struct bufarea **bpp)
326 level = lbn_level(cur);
328 pfatal("Invalid indir lbn %jd in ino %ju\n",
329 lbn, (uintmax_t)ino);
330 if (level == 0 && lbn < 0)
331 pfatal("Invalid lbn %jd in ino %ju\n",
332 lbn, (uintmax_t)ino);
334 base = -(cur + level);
335 for (i = level; i > 0; i--)
336 lbnadd *= NINDIR(&sblock);
338 i = (lbn - base) / lbnadd;
340 i = (-lbn - base) / lbnadd;
341 if (i < 0 || i >= NINDIR(&sblock)) {
342 pfatal("Invalid indirect index %d produced by lbn %jd "
343 "in ino %ju\n", i, lbn, (uintmax_t)ino);
347 cur = base + (i * lbnadd);
349 cur = -(base + (i * lbnadd)) - (level - 1);
350 bp = getdatablk(blk, sblock.fs_bsize, BT_LEVEL1 + level);
362 pfatal("Invalid lbn %jd at level 0 for ino %ju\n", lbn,
364 return (indir_blkatoff(blk, ino, cur, lbn, bpp));
368 * Check that a block in a legal block number.
369 * Return 0 if in range, 1 if out of range.
372 chkrange(ufs2_daddr_t blk, int cnt)
376 if (cnt <= 0 || blk <= 0 || blk > maxfsblock ||
377 cnt - 1 > maxfsblock - blk)
379 if (cnt > sblock.fs_frag ||
380 fragnum(&sblock, blk) + cnt > sblock.fs_frag) {
382 printf("bad size: blk %ld, offset %i, size %d\n",
383 (long)blk, (int)fragnum(&sblock, blk), cnt);
386 c = dtog(&sblock, blk);
387 if (blk < cgdmin(&sblock, c)) {
388 if ((blk + cnt) > cgsblock(&sblock, c)) {
390 printf("blk %ld < cgdmin %ld;",
391 (long)blk, (long)cgdmin(&sblock, c));
392 printf(" blk + cnt %ld > cgsbase %ld\n",
394 (long)cgsblock(&sblock, c));
399 if ((blk + cnt) > cgbase(&sblock, c+1)) {
401 printf("blk %ld >= cgdmin %ld;",
402 (long)blk, (long)cgdmin(&sblock, c));
403 printf(" blk + cnt %ld > sblock.fs_fpg %ld\n",
404 (long)(blk + cnt), (long)sblock.fs_fpg);
413 * General purpose interface for reading inodes.
416 ginode(ino_t inumber, struct inode *ip)
420 if (inumber < UFS_ROOTINO || inumber > maxino)
421 errx(EEXIT, "bad inode number %ju to ginode",
423 ip->i_number = inumber;
424 if (icachebp != NULL &&
425 inumber >= icachebp->b_index &&
426 inumber < icachebp->b_index + INOPB(&sblock)) {
427 /* take an additional reference for the returned inode */
428 icachebp->b_refcnt++;
430 iblk = ino_to_fsba(&sblock, inumber);
431 /* release our cache-hold reference on old icachebp */
432 if (icachebp != NULL)
434 icachebp = getdatablk(iblk, sblock.fs_bsize, BT_INODES);
435 if (icachebp->b_errs != 0) {
441 /* take a cache-hold reference on new icachebp */
442 icachebp->b_refcnt++;
443 icachebp->b_index = rounddown(inumber, INOPB(&sblock));
446 if (sblock.fs_magic == FS_UFS1_MAGIC) {
447 ip->i_dp = (union dinode *)
448 &icachebp->b_un.b_dinode1[inumber % INOPB(&sblock)];
451 ip->i_dp = (union dinode *)
452 &icachebp->b_un.b_dinode2[inumber % INOPB(&sblock)];
453 if (ffs_verify_dinode_ckhash(&sblock, (struct ufs2_dinode *)ip->i_dp)) {
454 pwarn("INODE CHECK-HASH FAILED");
456 if (preen || reply("FIX") != 0) {
458 printf(" (FIXED)\n");
459 ffs_update_dinode_ckhash(&sblock,
460 (struct ufs2_dinode *)ip->i_dp);
467 * Release a held inode.
470 irelse(struct inode *ip)
473 if (ip->i_bp->b_refcnt <= 0)
474 pfatal("irelse: releasing unreferenced ino %ju\n",
475 (uintmax_t) ip->i_number);
480 * Special purpose version of ginode used to optimize first pass
481 * over all the inodes in numerical order.
483 static ino_t nextino, lastinum, lastvalidinum;
484 static long readcount, readpercg, fullcnt, inobufsize, partialcnt, partialsize;
485 static struct bufarea inobuf;
488 getnextinode(ino_t inumber, int rebuildcg)
493 ufs2_daddr_t ndb, blk;
496 static caddr_t nextinop;
498 if (inumber != nextino++ || inumber > lastvalidinum)
499 errx(EEXIT, "bad inode number %ju to nextinode",
501 if (inumber >= lastinum) {
503 blk = ino_to_fsba(&sblock, lastinum);
504 if (readcount % readpercg == 0) {
506 lastinum += partialcnt;
512 * Flush old contents in case they have been updated.
513 * If getblk encounters an error, it will already have zeroed
514 * out the buffer, so we do not need to do so here.
516 flush(fswritefd, &inobuf);
517 getblk(&inobuf, blk, size);
518 nextinop = inobuf.b_un.b_buf;
520 dp = (union dinode *)nextinop;
521 if (sblock.fs_magic == FS_UFS1_MAGIC)
522 nextinop += sizeof(struct ufs1_dinode);
524 nextinop += sizeof(struct ufs2_dinode);
525 if ((ckhashadd & CK_INODE) != 0) {
526 ffs_update_dinode_ckhash(&sblock, (struct ufs2_dinode *)dp);
529 if (ffs_verify_dinode_ckhash(&sblock, (struct ufs2_dinode *)dp) != 0) {
530 pwarn("INODE CHECK-HASH FAILED");
533 ip.i_number = inumber;
535 if (preen || reply("FIX") != 0) {
537 printf(" (FIXED)\n");
538 ffs_update_dinode_ckhash(&sblock,
539 (struct ufs2_dinode *)dp);
543 if (rebuildcg && (char *)dp == inobuf.b_un.b_buf) {
545 * Try to determine if we have reached the end of the
548 mode = DIP(dp, di_mode) & IFMT;
550 if (memcmp(dp->dp2.di_db, zino.dp2.di_db,
551 UFS_NDADDR * sizeof(ufs2_daddr_t)) ||
552 memcmp(dp->dp2.di_ib, zino.dp2.di_ib,
553 UFS_NIADDR * sizeof(ufs2_daddr_t)) ||
554 dp->dp2.di_mode || dp->dp2.di_size)
560 ndb = howmany(DIP(dp, di_size), sblock.fs_bsize);
563 if (mode == IFBLK || mode == IFCHR)
567 * Fake ndb value so direct/indirect block checks below
568 * will detect any garbage after symlink string.
570 if (DIP(dp, di_size) < (off_t)sblock.fs_maxsymlinklen) {
571 ndb = howmany(DIP(dp, di_size),
572 sizeof(ufs2_daddr_t));
573 if (ndb > UFS_NDADDR) {
574 j = ndb - UFS_NDADDR;
575 for (ndb = 1; j > 1; j--)
576 ndb *= NINDIR(&sblock);
581 for (j = ndb; ndb < UFS_NDADDR && j < UFS_NDADDR; j++)
582 if (DIP(dp, di_db[j]) != 0)
584 for (j = 0, ndb -= UFS_NDADDR; ndb > 0; j++)
585 ndb /= NINDIR(&sblock);
586 for (; j < UFS_NIADDR; j++)
587 if (DIP(dp, di_ib[j]) != 0)
594 setinodebuf(int cg, ino_t inosused)
598 inum = cg * sblock.fs_ipg;
599 lastvalidinum = inum + inosused - 1;
603 /* Flush old contents in case they have been updated */
604 flush(fswritefd, &inobuf);
606 if (inobuf.b_un.b_buf == NULL) {
607 inobufsize = blkroundup(&sblock,
608 MAX(INOBUFSIZE, sblock.fs_bsize));
609 initbarea(&inobuf, BT_INODES);
610 if ((inobuf.b_un.b_buf = Malloc((unsigned)inobufsize)) == NULL)
611 errx(EEXIT, "cannot allocate space for inode buffer");
613 fullcnt = inobufsize / ((sblock.fs_magic == FS_UFS1_MAGIC) ?
614 sizeof(struct ufs1_dinode) : sizeof(struct ufs2_dinode));
615 readpercg = inosused / fullcnt;
616 partialcnt = inosused % fullcnt;
617 partialsize = fragroundup(&sblock,
618 partialcnt * ((sblock.fs_magic == FS_UFS1_MAGIC) ?
619 sizeof(struct ufs1_dinode) : sizeof(struct ufs2_dinode)));
620 if (partialcnt != 0) {
623 partialcnt = fullcnt;
624 partialsize = inobufsize;
629 freeblock(struct inodesc *idesc)
636 blkno = idesc->id_blkno;
637 for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
638 if (chkrange(blkno, 1)) {
640 } else if (testbmap(blkno)) {
641 for (dlp = duplist; dlp; dlp = dlp->next) {
642 if (dlp->dup != blkno)
644 dlp->dup = duplist->dup;
646 duplist = duplist->next;
664 * Flush old contents in case they have been updated.
666 flush(fswritefd, &inobuf);
667 if (inobuf.b_un.b_buf != NULL)
668 free((char *)inobuf.b_un.b_buf);
669 inobuf.b_un.b_buf = NULL;
673 * Routines to maintain information about directory inodes.
674 * This is built during the first pass and used during the
675 * second and third passes.
677 * Enter inodes into the cache.
680 cacheino(union dinode *dp, ino_t inumber)
682 struct inoinfo *inp, **inpp;
685 if (howmany(DIP(dp, di_size), sblock.fs_bsize) > UFS_NDADDR)
686 blks = UFS_NDADDR + UFS_NIADDR;
687 else if (DIP(dp, di_size) > 0)
688 blks = howmany(DIP(dp, di_size), sblock.fs_bsize);
691 inp = (struct inoinfo *)
692 Malloc(sizeof(*inp) + (blks - 1) * sizeof(ufs2_daddr_t));
694 errx(EEXIT, "cannot increase directory list");
695 inpp = &inphead[inumber % dirhash];
696 inp->i_nexthash = *inpp;
698 inp->i_parent = inumber == UFS_ROOTINO ? UFS_ROOTINO : (ino_t)0;
699 inp->i_dotdot = (ino_t)0;
700 inp->i_number = inumber;
701 inp->i_isize = DIP(dp, di_size);
702 inp->i_numblks = blks;
703 for (i = 0; i < MIN(blks, UFS_NDADDR); i++)
704 inp->i_blks[i] = DIP(dp, di_db[i]);
705 if (blks > UFS_NDADDR)
706 for (i = 0; i < UFS_NIADDR; i++)
707 inp->i_blks[UFS_NDADDR + i] = DIP(dp, di_ib[i]);
708 if (inplast == listmax) {
710 inpsort = (struct inoinfo **)reallocarray((char *)inpsort,
711 listmax, sizeof(struct inoinfo *));
713 errx(EEXIT, "cannot increase directory list");
715 inpsort[inplast++] = inp;
719 * Look up an inode cache structure.
722 getinoinfo(ino_t inumber)
726 for (inp = inphead[inumber % dirhash]; inp; inp = inp->i_nexthash) {
727 if (inp->i_number != inumber)
731 errx(EEXIT, "cannot find inode %ju", (uintmax_t)inumber);
732 return ((struct inoinfo *)0);
736 * Clean up all the inode cache structure.
741 struct inoinfo **inpp;
745 for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--)
746 free((char *)(*inpp));
747 free((char *)inphead);
748 free((char *)inpsort);
749 inphead = inpsort = NULL;
753 inodirty(struct inode *ip)
756 if (sblock.fs_magic == FS_UFS2_MAGIC)
757 ffs_update_dinode_ckhash(&sblock,
758 (struct ufs2_dinode *)ip->i_dp);
763 clri(struct inodesc *idesc, const char *type, int flag)
768 ginode(idesc->id_number, &ip);
772 (DIP(dp, di_mode) & IFMT) == IFDIR ? "DIR" : "FILE");
776 if (preen || reply("CLEAR") == 1) {
778 printf(" (CLEARED)\n");
780 if (bkgrdflag == 0) {
781 (void)ckinode(dp, idesc);
782 inoinfo(idesc->id_number)->ino_state = USTATE;
786 cmd.value = idesc->id_number;
787 cmd.size = -DIP(dp, di_nlink);
789 printf("adjrefcnt ino %ld amt %lld\n",
790 (long)cmd.value, (long long)cmd.size);
791 if (sysctl(adjrefcnt, MIBSIZE, 0, 0,
792 &cmd, sizeof cmd) == -1)
793 rwerror("ADJUST INODE", cmd.value);
800 findname(struct inodesc *idesc)
802 struct direct *dirp = idesc->id_dirp;
804 if (dirp->d_ino != idesc->id_parent || idesc->id_entryno < 2) {
808 memmove(idesc->id_name, dirp->d_name, (size_t)dirp->d_namlen + 1);
813 findino(struct inodesc *idesc)
815 struct direct *dirp = idesc->id_dirp;
817 if (dirp->d_ino == 0)
819 if (strcmp(dirp->d_name, idesc->id_name) == 0 &&
820 dirp->d_ino >= UFS_ROOTINO && dirp->d_ino <= maxino) {
821 idesc->id_parent = dirp->d_ino;
828 clearentry(struct inodesc *idesc)
830 struct direct *dirp = idesc->id_dirp;
832 if (dirp->d_ino != idesc->id_parent || idesc->id_entryno < 2) {
837 return (STOP|FOUND|ALTERED);
841 prtinode(struct inode *ip)
849 printf(" I=%lu ", (u_long)ip->i_number);
850 if (ip->i_number < UFS_ROOTINO || ip->i_number > maxino)
853 if ((pw = getpwuid((int)DIP(dp, di_uid))) != NULL)
854 printf("%s ", pw->pw_name);
856 printf("%u ", (unsigned)DIP(dp, di_uid));
857 printf("MODE=%o\n", DIP(dp, di_mode));
859 printf("%s: ", cdevname);
860 printf("SIZE=%ju ", (uintmax_t)DIP(dp, di_size));
861 t = DIP(dp, di_mtime);
863 printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]);
867 blkerror(ino_t ino, const char *type, ufs2_daddr_t blk)
870 pfatal("%jd %s I=%ju", (intmax_t)blk, type, (uintmax_t)ino);
872 switch (inoinfo(ino)->ino_state) {
876 inoinfo(ino)->ino_state = FCLEAR;
881 inoinfo(ino)->ino_state = DCLEAR;
889 errx(EEXIT, "BAD STATE %d TO BLKERR", inoinfo(ino)->ino_state);
895 * allocate an unused inode
898 allocino(ino_t request, int type)
903 struct bufarea *cgbp;
909 request = UFS_ROOTINO;
911 } else if (inoinfo(request)->ino_state != USTATE)
914 for (ino = request; ino < maxino; ino++)
915 if (inoinfo(ino)->ino_state == USTATE)
919 cg = ino_to_cg(&sblock, ino);
921 cgp = cgbp->b_un.b_cg;
922 if (!check_cgmagic(cg, cgbp, 0)) {
925 request = (cg + 1) * sblock.fs_ipg;
928 setbit(cg_inosused(cgp), ino % sblock.fs_ipg);
929 cgp->cg_cs.cs_nifree--;
930 switch (type & IFMT) {
932 inoinfo(ino)->ino_state = DSTATE;
933 cgp->cg_cs.cs_ndir++;
937 inoinfo(ino)->ino_state = FSTATE;
945 DIP_SET(dp, di_db[0], allocblk((long)1));
946 if (DIP(dp, di_db[0]) == 0) {
947 inoinfo(ino)->ino_state = USTATE;
951 DIP_SET(dp, di_mode, type);
952 DIP_SET(dp, di_flags, 0);
953 DIP_SET(dp, di_atime, time(NULL));
954 DIP_SET(dp, di_ctime, DIP(dp, di_atime));
955 DIP_SET(dp, di_mtime, DIP(dp, di_ctime));
956 DIP_SET(dp, di_mtimensec, 0);
957 DIP_SET(dp, di_ctimensec, 0);
958 DIP_SET(dp, di_atimensec, 0);
959 DIP_SET(dp, di_size, sblock.fs_fsize);
960 DIP_SET(dp, di_blocks, btodb(sblock.fs_fsize));
964 inoinfo(ino)->ino_type = IFTODT(type);
969 * deallocate an inode
974 struct inodesc idesc;
978 memset(&idesc, 0, sizeof(struct inodesc));
979 idesc.id_type = inoinfo(ino)->ino_idtype;
980 idesc.id_func = freeblock;
981 idesc.id_number = ino;
984 (void)ckinode(dp, &idesc);
988 inoinfo(ino)->ino_state = USTATE;