venus: Remove dedebug
[openafs.git] / src / vfsck / dir.c
1 /*
2  * Copyright (c) 1980, 1986 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17
18 #include <afsconfig.h>
19 #include <afs/param.h>
20
21 #ifdef AFS_HPUX_ENV
22 /* We need the old directory type headers (included below), so don't include
23  * the normal dirent.h, or it will conflict. */
24 # undef HAVE_DIRENT_H
25 # include <sys/inode.h>
26 # define        LONGFILENAMES   1
27 # include <sys/sysmacros.h>
28 # include <sys/ino.h>
29 # define        DIRSIZ_MACRO
30 # ifdef HAVE_USR_OLD_USR_INCLUDE_NDIR_H
31 #  include </usr/old/usr/include/ndir.h>
32 # else
33 #  include <ndir.h>
34 # endif
35 #endif
36
37 #include <roken.h>
38
39 #include <ctype.h>
40
41 #define VICE                    /* allow us to put our changes in at will */
42
43 #ifdef AFS_VFSINCL_ENV
44 #define VFS
45 #include <sys/vnode.h>
46 #ifdef    AFS_SUN5_ENV
47 #include <sys/fs/ufs_inode.h>
48 #include <sys/fs/ufs_fs.h>
49 #define _KERNEL
50 #include <sys/fs/ufs_fsdir.h>
51 #undef _KERNEL
52 #else
53 #include <ufs/inode.h>
54 #include <ufs/fs.h>
55 #define KERNEL
56 #include <ufs/fsdir.h>
57 #undef KERNEL
58 #endif
59
60 #else /* AFS_VFSINCL_ENV */
61 #include <sys/inode.h>
62 #ifndef AFS_HPUX_ENV
63 #define KERNEL
64 #include <sys/dir.h>
65 #undef KERNEL
66 #endif
67 #include <sys/fs.h>
68 #endif /* AFS_VFSINCL_ENV */
69
70 #ifdef AFS_SUN_ENV
71 #ifdef  AFS_SUN5_ENV
72 #include <sys/mnttab.h>
73 #include <sys/mntent.h>
74 #else
75 #include <mntent.h>
76 #endif
77 #endif
78 #include "fsck.h"
79
80
81 #ifdef  AFS_HPUX_ENV
82 struct dirtemplate_lfn {
83     afs_uint32 dot_ino;
84     short dot_reclen;
85     short dot_namlen;
86     char dot_name[4];           /* must be multiple of 4 */
87     afs_uint32 dotdot_ino;
88     short dotdot_reclen;
89     short dotdot_namlen;
90     char dotdot_name[4];        /* ditto */
91 };
92 #define dirtemplate dirtemplate_lfn
93 #endif
94
95 #define MINDIRSIZE      (sizeof (struct dirtemplate))
96
97 char *endpathname = &pathname[BUFSIZ - 2];
98 char *lfname = "lost+found";
99 int lfmode = 01777;
100 struct dirtemplate emptydir = { 0, DIRBLKSIZ };
101 struct dirtemplate dirhead = { 0, 12, 1, ".", 0, DIRBLKSIZ - 12, 2, ".." };
102
103 struct direct *fsck_readdir();
104 struct bufarea *getdirblk();
105
106 descend(parentino, inumber)
107      struct inodesc *parentino;
108      ino_t inumber;
109 {
110     struct dinode *dp;
111     struct inodesc curino;
112
113     memset(&curino, 0, sizeof(struct inodesc));
114     if (statemap[inumber] != DSTATE)
115         errexit("BAD INODE %d TO DESCEND", statemap[inumber]);
116 #if defined(ACLS) && defined(AFS_HPUX_ENV)
117     /*
118      * keep any continuation inode information
119      */
120     if (statemap[inumber] & HASCINODE)
121         statemap[inumber] = HASCINODE | DFOUND;
122     else
123         statemap[inumber] = DFOUND;
124 #else /* no ACLS */
125     statemap[inumber] = DFOUND;
126 #endif /* ACLS */
127     dp = ginode(inumber);
128     if (dp->di_size == 0) {
129         direrror(inumber, "ZERO LENGTH DIRECTORY");
130         if (reply("REMOVE") == 1)
131 #if defined(ACLS) && defined(AFS_HPUX_ENV)
132             /*
133              * keep any continuation inode information
134              */
135             if (statemap[inumber] & HASCINODE)
136                 statemap[inumber] = HASCINODE | DCLEAR;
137             else
138                 statemap[inumber] = DCLEAR;
139 #else /* no ACLS */
140             statemap[inumber] = DCLEAR;
141 #endif /* ACLS */
142         return;
143     }
144     if (dp->di_size < MINDIRSIZE) {
145         direrror(inumber, "DIRECTORY TOO SHORT");
146         dp->di_size = MINDIRSIZE;
147         if (reply("FIX") == 1)
148             inodirty();
149     }
150 #if     !defined(AFS_HPUX_ENV)
151     /* For remaining 4.2 systems.  We shouldn't convert
152      * dir size, since Unix 4.2 kernels won't maintain this, and we'll have a
153      * lot of spurious directory conversions scaring people */
154     if ((dp->di_size & (DIRBLKSIZ - 1)) != 0) {
155         pwarn("DIRECTORY %s: LENGTH %d NOT MULTIPLE OF %d", pathname,
156               dp->di_size, DIRBLKSIZ);
157         dp->di_size = roundup(dp->di_size, DIRBLKSIZ);
158         if (preen)
159             printf(" (ADJUSTED)\n");
160         if (preen || reply("ADJUST") == 1)
161             inodirty();
162     }
163 #endif
164     curino.id_type = DATA;
165     curino.id_func = parentino->id_func;
166     curino.id_parent = parentino->id_number;
167     curino.id_number = inumber;
168     (void)ckinode(dp, &curino);
169     if (curino.id_entryno < 2) {
170         direrror(inumber, "NULL DIRECTORY");
171         if (reply("REMOVE") == 1)
172             statemap[inumber] = DCLEAR;
173     }
174 }
175
176 dirscan(idesc)
177      struct inodesc *idesc;
178 {
179     struct direct *dp;
180     struct bufarea *bp;
181     int dsize, n;
182     long blksiz;
183     char dbuf[DIRBLKSIZ];
184
185     if (idesc->id_type != DATA)
186         errexit("wrong type to dirscan %d\n", idesc->id_type);
187     if (idesc->id_entryno == 0 && (idesc->id_filesize & (DIRBLKSIZ - 1)) != 0)
188         idesc->id_filesize = roundup(idesc->id_filesize, DIRBLKSIZ);
189     blksiz = idesc->id_numfrags * sblock.fs_fsize;
190
191     if (chkrange(idesc->id_blkno, idesc->id_numfrags)) {
192         idesc->id_filesize -= blksiz;
193         return (SKIP);
194     }
195     idesc->id_loc = 0;
196     for (dp = fsck_readdir(idesc); dp != NULL; dp = fsck_readdir(idesc)) {
197         dsize = dp->d_reclen;
198         memcpy(dbuf, (char *)dp, dsize);
199         idesc->id_dirp = (struct direct *)dbuf;
200         if ((n = (*idesc->id_func) (idesc)) & ALTERED) {
201             bp = getdirblk(idesc->id_blkno, blksiz);
202             memcpy((char *)dp, dbuf, dsize);
203             dirty(bp);
204             sbdirty();
205         }
206         if (n & STOP)
207             return (n);
208     }
209     return (idesc->id_filesize > 0 ? KEEPON : STOP);
210 }
211
212 /*
213  * get next entry in a directory.
214  */
215 struct direct *
216 fsck_readdir(idesc)
217      struct inodesc *idesc;
218 {
219     struct direct *dp, *ndp;
220     struct bufarea *bp;
221     long size, blksiz;
222
223     blksiz = idesc->id_numfrags * sblock.fs_fsize;
224     bp = getdirblk(idesc->id_blkno, blksiz);
225     if (idesc->id_loc % DIRBLKSIZ == 0 && idesc->id_filesize > 0
226         && idesc->id_loc < blksiz) {
227         dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
228         if (dircheck(idesc, dp)) {
229             goto dpok;
230         }
231         idesc->id_loc += DIRBLKSIZ;
232         idesc->id_filesize -= DIRBLKSIZ;
233         dp->d_reclen = DIRBLKSIZ;
234         dp->d_ino = 0;
235         dp->d_namlen = 0;
236         dp->d_name[0] = '\0';
237         if (dofix(idesc, "DIRECTORY CORRUPTED"))
238             dirty(bp);
239         return (dp);
240     }
241   dpok:
242     if (idesc->id_filesize <= 0 || idesc->id_loc >= blksiz)
243         return NULL;
244     dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
245     idesc->id_loc += dp->d_reclen;
246     idesc->id_filesize -= dp->d_reclen;
247     if ((idesc->id_loc % DIRBLKSIZ) == 0)
248         return (dp);
249     ndp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
250     if (idesc->id_loc < blksiz && idesc->id_filesize > 0
251         && dircheck(idesc, ndp) == 0) {
252         size = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
253         dp->d_reclen += size;
254         idesc->id_loc += size;
255         idesc->id_filesize -= size;
256         if (dofix(idesc, "DIRECTORY CORRUPTED"))
257             dirty(bp);
258     }
259     return (dp);
260 }
261
262 /*
263  * Verify that a directory entry is valid.
264  * This is a superset of the checks made in the kernel.
265  */
266 dircheck(idesc, dp)
267      struct inodesc *idesc;
268      struct direct *dp;
269 {
270     int size;
271     char *cp;
272     int spaceleft;
273
274     size = DIRSIZ(dp);
275     spaceleft = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
276     if (dp->d_ino < maxino && dp->d_reclen != 0 && dp->d_reclen <= spaceleft
277         && (dp->d_reclen & 0x3) == 0 && dp->d_reclen >= size
278         && idesc->id_filesize >= size && dp->d_namlen <= MAXNAMLEN) {
279         if (dp->d_ino == 0)
280             return (1);
281         for (cp = dp->d_name, size = 0; size < dp->d_namlen; size++)
282 #if     defined(Next) || defined(AFS_SUN5_ENV)
283             if (*cp == 0)
284                 return (0);
285             else
286                 ++cp;
287 #else
288             if (*cp == 0 || (*cp++ & 0200)) {
289                 return (0);
290             }
291 #endif
292         if (*cp == 0)
293             return (1);
294     }
295     return (0);
296 }
297
298 direrror(ino, errmesg)
299      ino_t ino;
300      char *errmesg;
301 {
302     struct dinode *dp;
303
304     pwarn("%s ", errmesg);
305     pinode(ino);
306     printf("\n");
307     if (ino < ROOTINO || ino > maxino) {
308         pfatal("NAME=%s\n", pathname);
309         return;
310     }
311     dp = ginode(ino);
312     if (ftypeok(dp))
313         pfatal("%s=%s\n", (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE",
314                pathname);
315     else
316         pfatal("NAME=%s\n", pathname);
317 }
318
319 adjust(idesc, lcnt)
320      struct inodesc *idesc;
321      short lcnt;
322 {
323     struct dinode *dp;
324
325     dp = ginode(idesc->id_number);
326     if (dp->di_nlink == lcnt) {
327         if (linkup(idesc->id_number, (ino_t) 0) == 0)
328             clri(idesc, "UNREF", 0);
329     } else {
330         pwarn("LINK COUNT %s",
331               (lfdir == idesc->id_number) ? lfname : ((dp->di_mode & IFMT) ==
332                                                       IFDIR ? "DIR" :
333                                                       "FILE"));
334         pinode(idesc->id_number);
335         printf(" COUNT %d SHOULD BE %d", dp->di_nlink, dp->di_nlink - lcnt);
336         if (preen) {
337             if (lcnt < 0) {
338                 printf("\n");
339                 pfatal("LINK COUNT INCREASING");
340             }
341             printf(" (ADJUSTED)\n");
342         }
343         if (preen || reply("ADJUST") == 1) {
344             dp->di_nlink -= lcnt;
345             inodirty();
346         }
347     }
348 }
349
350 mkentry(idesc)
351      struct inodesc *idesc;
352 {
353     struct direct *dirp = idesc->id_dirp;
354     struct direct newent;
355     int newlen, oldlen;
356
357     newent.d_namlen = 11;
358     newlen = DIRSIZ(&newent);
359     if (dirp->d_ino != 0)
360         oldlen = DIRSIZ(dirp);
361     else
362         oldlen = 0;
363     if (dirp->d_reclen - oldlen < newlen)
364         return (KEEPON);
365     newent.d_reclen = dirp->d_reclen - oldlen;
366     dirp->d_reclen = oldlen;
367     dirp = (struct direct *)(((char *)dirp) + oldlen);
368     dirp->d_ino = idesc->id_parent;     /* ino to be entered is in id_parent */
369     dirp->d_reclen = newent.d_reclen;
370     dirp->d_namlen = strlen(idesc->id_name);
371     memcpy(dirp->d_name, idesc->id_name, (int)dirp->d_namlen + 1);
372     return (ALTERED | STOP);
373 }
374
375 chgino(idesc)
376      struct inodesc *idesc;
377 {
378     struct direct *dirp = idesc->id_dirp;
379
380     if (memcmp(dirp->d_name, idesc->id_name, (int)dirp->d_namlen + 1))
381         return (KEEPON);
382     dirp->d_ino = idesc->id_parent;
383     return (ALTERED | STOP);
384 }
385
386 linkup(orphan, parentdir)
387      ino_t orphan;
388      ino_t parentdir;
389 {
390     struct dinode *dp;
391     int lostdir, len;
392     ino_t oldlfdir;
393     struct inodesc idesc;
394     char tempname[BUFSIZ];
395     extern int pass4check();
396
397     memset(&idesc, 0, sizeof(struct inodesc));
398     dp = ginode(orphan);
399     lostdir = (dp->di_mode & IFMT) == IFDIR;
400     pwarn("UNREF %s ", lostdir ? "DIR" : "FILE");
401     pinode(orphan);
402     if (preen && dp->di_size == 0)
403         return (0);
404     if (preen)
405         printf(" (RECONNECTED)\n");
406     else if (reply("RECONNECT") == 0)
407         return (0);
408     pathp = pathname;
409     *pathp++ = '/';
410     *pathp = '\0';
411     if (lfdir == 0) {
412         dp = ginode(ROOTINO);
413         idesc.id_name = lfname;
414         idesc.id_type = DATA;
415         idesc.id_func = findino;
416         idesc.id_number = ROOTINO;
417         if ((ckinode(dp, &idesc) & FOUND) != 0) {
418             lfdir = idesc.id_parent;
419         } else {
420             pwarn("NO lost+found DIRECTORY");
421             if (preen || reply("CREATE")) {
422                 lfdir = allocdir(ROOTINO, (ino_t) 0, lfmode);
423                 if (lfdir != 0) {
424                     if (makeentry(ROOTINO, lfdir, lfname) != 0) {
425                         if (preen)
426                             printf(" (CREATED)\n");
427                     } else {
428                         freedir(lfdir, ROOTINO);
429                         lfdir = 0;
430                         if (preen)
431                             printf("\n");
432                     }
433                 }
434             }
435         }
436         if (lfdir == 0) {
437             pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY");
438             printf("\n\n");
439             return (0);
440         }
441     }
442     dp = ginode(lfdir);
443     if ((dp->di_mode & IFMT) != IFDIR) {
444         pfatal("lost+found IS NOT A DIRECTORY");
445         if (reply("REALLOCATE") == 0)
446             return (0);
447         oldlfdir = lfdir;
448         if ((lfdir = allocdir(ROOTINO, (ino_t) 0, lfmode)) == 0) {
449             pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n");
450             return (0);
451         }
452         idesc.id_type = DATA;
453         idesc.id_func = chgino;
454         idesc.id_number = ROOTINO;
455         idesc.id_parent = lfdir;        /* new inumber for lost+found */
456         idesc.id_name = lfname;
457         if ((ckinode(ginode(ROOTINO), &idesc) & ALTERED) == 0) {
458             pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n");
459             return (0);
460         }
461         inodirty();
462         idesc.id_type = ADDR;
463         idesc.id_func = pass4check;
464         idesc.id_number = oldlfdir;
465         adjust(&idesc, lncntp[oldlfdir] + 1);
466         lncntp[oldlfdir] = 0;
467         dp = ginode(lfdir);
468     }
469     if (statemap[lfdir] != DFOUND) {
470         pfatal("SORRY. NO lost+found DIRECTORY\n\n");
471         return (0);
472     }
473     len = strlen(lfname);
474     memcpy(pathp, lfname, len + 1);
475     pathp += len;
476     len = lftempname(tempname, orphan);
477     if (makeentry(lfdir, orphan, tempname) == 0) {
478         pfatal("SORRY. NO SPACE IN lost+found DIRECTORY");
479         printf("\n\n");
480         return (0);
481     }
482     lncntp[orphan]--;
483     *pathp++ = '/';
484     memcpy(pathp, tempname, len + 1);
485     pathp += len;
486     if (lostdir) {
487         dp = ginode(orphan);
488         idesc.id_type = DATA;
489         idesc.id_func = chgino;
490         idesc.id_number = orphan;
491         idesc.id_fix = DONTKNOW;
492         idesc.id_name = "..";
493         idesc.id_parent = lfdir;        /* new value for ".." */
494         (void)ckinode(dp, &idesc);
495         dp = ginode(lfdir);
496         dp->di_nlink++;
497         inodirty();
498         lncntp[lfdir]++;
499         pwarn("DIR I=%u CONNECTED. ", orphan);
500         printf("PARENT WAS I=%u\n", parentdir);
501         if (preen == 0)
502             printf("\n");
503     }
504     return (1);
505 }
506
507 /*
508  * make an entry in a directory
509  */
510 makeentry(parent, ino, name)
511      ino_t parent, ino;
512      char *name;
513 {
514     struct dinode *dp;
515     struct inodesc idesc;
516
517     if (parent < ROOTINO || parent >= maxino || ino < ROOTINO
518         || ino >= maxino)
519         return (0);
520     memset(&idesc, 0, sizeof(struct inodesc));
521     idesc.id_type = DATA;
522     idesc.id_func = mkentry;
523     idesc.id_number = parent;
524     idesc.id_parent = ino;      /* this is the inode to enter */
525     idesc.id_fix = DONTKNOW;
526     idesc.id_name = name;
527     dp = ginode(parent);
528     if (dp->di_size % DIRBLKSIZ) {
529         dp->di_size = roundup(dp->di_size, DIRBLKSIZ);
530         inodirty();
531     }
532     if ((ckinode(dp, &idesc) & ALTERED) != 0)
533         return (1);
534     if (expanddir(dp) == 0)
535         return (0);
536     return (ckinode(dp, &idesc) & ALTERED);
537 }
538
539 /*
540  * Attempt to expand the size of a directory
541  */
542 expanddir(dp)
543      struct dinode *dp;
544 {
545     daddr_t lastbn, newblk;
546     struct bufarea *bp;
547     char *cp, firstblk[DIRBLKSIZ];
548
549     lastbn = lblkno(&sblock, dp->di_size);
550     if (lastbn >= NDADDR - 1)
551         return (0);
552     if ((newblk = allocblk(sblock.fs_frag)) == 0)
553         return (0);
554     dp->di_db[lastbn + 1] = dp->di_db[lastbn];
555     dp->di_db[lastbn] = newblk;
556     dp->di_size += (UOFF_T) sblock.fs_bsize;
557     dp->di_blocks += btodb(sblock.fs_bsize);
558     bp = getdirblk(dp->di_db[lastbn + 1], dblksize(&sblock, dp, lastbn + 1));
559     if (bp->b_errs)
560         goto bad;
561     memcpy(firstblk, bp->b_un.b_buf, DIRBLKSIZ);
562     bp = getdirblk(newblk, sblock.fs_bsize);
563     if (bp->b_errs)
564         goto bad;
565     memcpy(bp->b_un.b_buf, firstblk, DIRBLKSIZ);
566     for (cp = &bp->b_un.b_buf[DIRBLKSIZ];
567          cp < &bp->b_un.b_buf[sblock.fs_bsize]; cp += DIRBLKSIZ)
568         memcpy(cp, (char *)&emptydir, sizeof emptydir);
569     dirty(bp);
570     bp = getdirblk(dp->di_db[lastbn + 1], dblksize(&sblock, dp, lastbn + 1));
571     if (bp->b_errs)
572         goto bad;
573     memcpy(bp->b_un.b_buf, (char *)&emptydir, sizeof emptydir);
574     pwarn("NO SPACE LEFT IN %s", pathname);
575     if (preen)
576         printf(" (EXPANDED)\n");
577     else if (reply("EXPAND") == 0)
578         goto bad;
579     dirty(bp);
580     inodirty();
581     return (1);
582   bad:
583     dp->di_db[lastbn] = dp->di_db[lastbn + 1];
584     dp->di_db[lastbn + 1] = 0;
585     dp->di_size -= (UOFF_T) sblock.fs_bsize;
586     dp->di_blocks -= btodb(sblock.fs_bsize);
587     freeblk(newblk, sblock.fs_frag);
588     return (0);
589 }
590
591 /*
592  * allocate a new directory
593  */
594 allocdir(parent, request, mode)
595      ino_t parent, request;
596      int mode;
597 {
598     ino_t ino;
599     char *cp;
600     struct dinode *dp;
601     struct bufarea *bp;
602
603     ino = allocino(request, IFDIR | mode);
604     dirhead.dot_ino = ino;
605     dirhead.dotdot_ino = parent;
606     dp = ginode(ino);
607     bp = getdirblk(dp->di_db[0], sblock.fs_fsize);
608     if (bp->b_errs) {
609         freeino(ino);
610         return (0);
611     }
612     memcpy(bp->b_un.b_buf, (char *)&dirhead, sizeof dirhead);
613     for (cp = &bp->b_un.b_buf[DIRBLKSIZ];
614          cp < &bp->b_un.b_buf[sblock.fs_fsize]; cp += DIRBLKSIZ)
615         memcpy(cp, (char *)&emptydir, sizeof emptydir);
616     dirty(bp);
617     dp->di_nlink = 2;
618     inodirty();
619 #ifdef  AFS_SUN5_ENVX
620     if (!inocached(ino)) {
621         if (debug)
622             printf("inode %d added to directory cache\n", ino);
623         cacheino(dp, ino);
624     } else {
625         /*
626          * re-using an old directory inode
627          */
628         inp = getinoinfo(ino);
629         inp->i_isize = dp->di_size;
630         inp->i_numblks = dp->di_blocks * sizeof(daddr_t);
631         inp->i_parent = parent;
632         memcpy((char *)&inp->i_blks[0], (char *)&dp->di_db[0],
633                (int)inp->i_numblks);
634     }
635 #endif
636     if (ino == ROOTINO) {
637         lncntp[ino] = dp->di_nlink;
638         return (ino);
639     }
640     if (statemap[parent] != DSTATE && statemap[parent] != DFOUND) {
641         freeino(ino);
642         return (0);
643     }
644     statemap[ino] = statemap[parent];
645     if (statemap[ino] == DSTATE) {
646         lncntp[ino] = dp->di_nlink;
647         lncntp[parent]++;
648     }
649     dp = ginode(parent);
650     dp->di_nlink++;
651     inodirty();
652     return (ino);
653 }
654
655 /*
656  * free a directory inode
657  */
658 freedir(ino, parent)
659      ino_t ino, parent;
660 {
661     struct dinode *dp;
662
663     if (ino != parent) {
664         dp = ginode(parent);
665         dp->di_nlink--;
666         inodirty();
667     }
668     freeino(ino);
669 }
670
671 /*
672  * generate a temporary name for the lost+found directory.
673  */
674 lftempname(bufp, ino)
675      char *bufp;
676      ino_t ino;
677 {
678     ino_t in;
679     char *cp;
680     int namlen;
681
682     cp = bufp + 2;
683     for (in = maxino; in > 0; in /= 10)
684         cp++;
685     *--cp = 0;
686     namlen = cp - bufp;
687     in = ino;
688     while (cp > bufp) {
689         *--cp = (in % 10) + '0';
690         in /= 10;
691     }
692     *cp = '#';
693     return (namlen);
694 }
695
696 /*
697  * Get a directory block.
698  * Insure that it is held until another is requested.
699  */
700 struct bufarea *
701 getdirblk(blkno, size)
702      daddr_t blkno;
703      long size;
704 {
705     if (mlk_pbp != 0)
706         mlk_pbp->b_flags &= ~B_INUSE;
707     mlk_pbp = getdatablk(blkno, size);
708     return (mlk_pbp);
709 }