Deleted Added
full compact
dir.c (2603) dir.c (7585)
1/*
2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
1/*
2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93";
35static const char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 6/5/93";
36#endif /* not lint */
37
38#include <sys/param.h>
39#include <sys/time.h>
40#include <ufs/ufs/dinode.h>
41#include <ufs/ufs/dir.h>
42#include <ufs/ffs/fs.h>
36#endif /* not lint */
37
38#include <sys/param.h>
39#include <sys/time.h>
40#include <ufs/ufs/dinode.h>
41#include <ufs/ufs/dir.h>
42#include <ufs/ffs/fs.h>
43#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45#include "fsck.h"
46
47char *lfname = "lost+found";
48int lfmode = 01777;
49struct dirtemplate emptydir = { 0, DIRBLKSIZ };
50struct dirtemplate dirhead = {
51 0, 12, DT_DIR, 1, ".",
52 0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
53};
54struct odirtemplate odirhead = {
55 0, 12, 1, ".",
56 0, DIRBLKSIZ - 12, 2, ".."
57};
58
44#include <stdlib.h>
45#include <string.h>
46#include "fsck.h"
47
48char *lfname = "lost+found";
49int lfmode = 01777;
50struct dirtemplate emptydir = { 0, DIRBLKSIZ };
51struct dirtemplate dirhead = {
52 0, 12, DT_DIR, 1, ".",
53 0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
54};
55struct odirtemplate odirhead = {
56 0, 12, 1, ".",
57 0, DIRBLKSIZ - 12, 2, ".."
58};
59
59struct direct *fsck_readdir();
60struct bufarea *getdirblk();
61
60
61static int chgino __P((struct inodesc *idesc));
62static int dircheck __P((struct inodesc *idesc, struct direct *dp));
63static int expanddir __P((struct dinode *dp, char *name));
64static void freedir __P((ino_t ino, ino_t parent));
65static struct direct * fsck_readdir __P((struct inodesc *idesc));
66static struct bufarea * getdirblk __P((daddr_t blkno, long size));
67static int lftempname __P((char *bufp, ino_t ino));
68static int mkentry __P((struct inodesc *idesc));
69
62/*
63 * Propagate connected state through the tree.
64 */
70/*
71 * Propagate connected state through the tree.
72 */
73void
65propagate()
66{
67 register struct inoinfo **inpp, *inp;
68 struct inoinfo **inpend;
69 long change;
70
71 inpend = &inpsort[inplast];
72 do {

--- 9 unchanged lines hidden (view full) ---

82 }
83 }
84 } while (change > 0);
85}
86
87/*
88 * Scan each entry in a directory block.
89 */
74propagate()
75{
76 register struct inoinfo **inpp, *inp;
77 struct inoinfo **inpend;
78 long change;
79
80 inpend = &inpsort[inplast];
81 do {

--- 9 unchanged lines hidden (view full) ---

91 }
92 }
93 } while (change > 0);
94}
95
96/*
97 * Scan each entry in a directory block.
98 */
99int
90dirscan(idesc)
91 register struct inodesc *idesc;
92{
93 register struct direct *dp;
94 register struct bufarea *bp;
95 int dsize, n;
96 long blksiz;
97 char dbuf[DIRBLKSIZ];

--- 103 unchanged lines hidden (view full) ---

201 }
202 return (dp);
203}
204
205/*
206 * Verify that a directory entry is valid.
207 * This is a superset of the checks made in the kernel.
208 */
100dirscan(idesc)
101 register struct inodesc *idesc;
102{
103 register struct direct *dp;
104 register struct bufarea *bp;
105 int dsize, n;
106 long blksiz;
107 char dbuf[DIRBLKSIZ];

--- 103 unchanged lines hidden (view full) ---

211 }
212 return (dp);
213}
214
215/*
216 * Verify that a directory entry is valid.
217 * This is a superset of the checks made in the kernel.
218 */
219int
209dircheck(idesc, dp)
210 struct inodesc *idesc;
211 register struct direct *dp;
212{
213 register int size;
214 register char *cp;
215 u_char namlen, type;
216 int spaceleft;

--- 26 unchanged lines hidden (view full) ---

243 if (*cp == 0 || (*cp++ == '/'))
244 return (0);
245 if (*cp == 0)
246 return (1);
247 }
248 return (0);
249}
250
220dircheck(idesc, dp)
221 struct inodesc *idesc;
222 register struct direct *dp;
223{
224 register int size;
225 register char *cp;
226 u_char namlen, type;
227 int spaceleft;

--- 26 unchanged lines hidden (view full) ---

254 if (*cp == 0 || (*cp++ == '/'))
255 return (0);
256 if (*cp == 0)
257 return (1);
258 }
259 return (0);
260}
261
262void
251direrror(ino, errmesg)
252 ino_t ino;
253 char *errmesg;
254{
255
256 fileerror(ino, ino, errmesg);
257}
258
263direrror(ino, errmesg)
264 ino_t ino;
265 char *errmesg;
266{
267
268 fileerror(ino, ino, errmesg);
269}
270
271void
259fileerror(cwd, ino, errmesg)
260 ino_t cwd, ino;
261 char *errmesg;
262{
263 register struct dinode *dp;
264 char pathbuf[MAXPATHLEN + 1];
265
266 pwarn("%s ", errmesg);

--- 7 unchanged lines hidden (view full) ---

274 dp = ginode(ino);
275 if (ftypeok(dp))
276 pfatal("%s=%s\n",
277 (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf);
278 else
279 pfatal("NAME=%s\n", pathbuf);
280}
281
272fileerror(cwd, ino, errmesg)
273 ino_t cwd, ino;
274 char *errmesg;
275{
276 register struct dinode *dp;
277 char pathbuf[MAXPATHLEN + 1];
278
279 pwarn("%s ", errmesg);

--- 7 unchanged lines hidden (view full) ---

287 dp = ginode(ino);
288 if (ftypeok(dp))
289 pfatal("%s=%s\n",
290 (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf);
291 else
292 pfatal("NAME=%s\n", pathbuf);
293}
294
295void
282adjust(idesc, lcnt)
283 register struct inodesc *idesc;
284 short lcnt;
285{
286 register struct dinode *dp;
287
288 dp = ginode(idesc->id_number);
289 if (dp->di_nlink == lcnt) {

--- 14 unchanged lines hidden (view full) ---

304 }
305 if (preen || reply("ADJUST") == 1) {
306 dp->di_nlink -= lcnt;
307 inodirty();
308 }
309 }
310}
311
296adjust(idesc, lcnt)
297 register struct inodesc *idesc;
298 short lcnt;
299{
300 register struct dinode *dp;
301
302 dp = ginode(idesc->id_number);
303 if (dp->di_nlink == lcnt) {

--- 14 unchanged lines hidden (view full) ---

318 }
319 if (preen || reply("ADJUST") == 1) {
320 dp->di_nlink -= lcnt;
321 inodirty();
322 }
323 }
324}
325
326int
312mkentry(idesc)
313 struct inodesc *idesc;
314{
315 register struct direct *dirp = idesc->id_dirp;
316 struct direct newent;
317 int newlen, oldlen;
318
319 newent.d_namlen = strlen(idesc->id_name);

--- 20 unchanged lines hidden (view full) ---

340 dirp->d_namlen = newent.d_namlen;
341# endif
342 }
343 dirp->d_reclen = newent.d_reclen;
344 bcopy(idesc->id_name, dirp->d_name, (size_t)newent.d_namlen + 1);
345 return (ALTERED|STOP);
346}
347
327mkentry(idesc)
328 struct inodesc *idesc;
329{
330 register struct direct *dirp = idesc->id_dirp;
331 struct direct newent;
332 int newlen, oldlen;
333
334 newent.d_namlen = strlen(idesc->id_name);

--- 20 unchanged lines hidden (view full) ---

355 dirp->d_namlen = newent.d_namlen;
356# endif
357 }
358 dirp->d_reclen = newent.d_reclen;
359 bcopy(idesc->id_name, dirp->d_name, (size_t)newent.d_namlen + 1);
360 return (ALTERED|STOP);
361}
362
363int
348chgino(idesc)
349 struct inodesc *idesc;
350{
351 register struct direct *dirp = idesc->id_dirp;
352
353 if (bcmp(dirp->d_name, idesc->id_name, (int)dirp->d_namlen + 1))
354 return (KEEPON);
355 dirp->d_ino = idesc->id_parent;
356 if (newinofmt)
357 dirp->d_type = typemap[idesc->id_parent];
358 else
359 dirp->d_type = 0;
360 return (ALTERED|STOP);
361}
362
364chgino(idesc)
365 struct inodesc *idesc;
366{
367 register struct direct *dirp = idesc->id_dirp;
368
369 if (bcmp(dirp->d_name, idesc->id_name, (int)dirp->d_namlen + 1))
370 return (KEEPON);
371 dirp->d_ino = idesc->id_parent;
372 if (newinofmt)
373 dirp->d_type = typemap[idesc->id_parent];
374 else
375 dirp->d_type = 0;
376 return (ALTERED|STOP);
377}
378
379int
363linkup(orphan, parentdir)
364 ino_t orphan;
365 ino_t parentdir;
366{
367 register struct dinode *dp;
368 int lostdir;
369 ino_t oldlfdir;
370 struct inodesc idesc;
371 char tempname[BUFSIZ];
380linkup(orphan, parentdir)
381 ino_t orphan;
382 ino_t parentdir;
383{
384 register struct dinode *dp;
385 int lostdir;
386 ino_t oldlfdir;
387 struct inodesc idesc;
388 char tempname[BUFSIZ];
372 extern int pass4check();
373
374 bzero((char *)&idesc, sizeof(struct inodesc));
375 dp = ginode(orphan);
376 lostdir = (dp->di_mode & IFMT) == IFDIR;
377 pwarn("UNREF %s ", lostdir ? "DIR" : "FILE");
378 pinode(orphan);
379 if (preen && dp->di_size == 0)
380 return (0);

--- 81 unchanged lines hidden (view full) ---

462 printf("\n");
463 }
464 return (1);
465}
466
467/*
468 * fix an entry in a directory.
469 */
389
390 bzero((char *)&idesc, sizeof(struct inodesc));
391 dp = ginode(orphan);
392 lostdir = (dp->di_mode & IFMT) == IFDIR;
393 pwarn("UNREF %s ", lostdir ? "DIR" : "FILE");
394 pinode(orphan);
395 if (preen && dp->di_size == 0)
396 return (0);

--- 81 unchanged lines hidden (view full) ---

478 printf("\n");
479 }
480 return (1);
481}
482
483/*
484 * fix an entry in a directory.
485 */
486int
470changeino(dir, name, newnum)
471 ino_t dir;
472 char *name;
473 ino_t newnum;
474{
475 struct inodesc idesc;
476
477 bzero((char *)&idesc, sizeof(struct inodesc));

--- 4 unchanged lines hidden (view full) ---

482 idesc.id_name = name;
483 idesc.id_parent = newnum; /* new value for name */
484 return (ckinode(ginode(dir), &idesc));
485}
486
487/*
488 * make an entry in a directory
489 */
487changeino(dir, name, newnum)
488 ino_t dir;
489 char *name;
490 ino_t newnum;
491{
492 struct inodesc idesc;
493
494 bzero((char *)&idesc, sizeof(struct inodesc));

--- 4 unchanged lines hidden (view full) ---

499 idesc.id_name = name;
500 idesc.id_parent = newnum; /* new value for name */
501 return (ckinode(ginode(dir), &idesc));
502}
503
504/*
505 * make an entry in a directory
506 */
507int
490makeentry(parent, ino, name)
491 ino_t parent, ino;
492 char *name;
493{
494 struct dinode *dp;
495 struct inodesc idesc;
496 char pathbuf[MAXPATHLEN + 1];
497

--- 19 unchanged lines hidden (view full) ---

517 if (expanddir(dp, pathbuf) == 0)
518 return (0);
519 return (ckinode(dp, &idesc) & ALTERED);
520}
521
522/*
523 * Attempt to expand the size of a directory
524 */
508makeentry(parent, ino, name)
509 ino_t parent, ino;
510 char *name;
511{
512 struct dinode *dp;
513 struct inodesc idesc;
514 char pathbuf[MAXPATHLEN + 1];
515

--- 19 unchanged lines hidden (view full) ---

535 if (expanddir(dp, pathbuf) == 0)
536 return (0);
537 return (ckinode(dp, &idesc) & ALTERED);
538}
539
540/*
541 * Attempt to expand the size of a directory
542 */
543int
525expanddir(dp, name)
526 register struct dinode *dp;
527 char *name;
528{
529 daddr_t lastbn, newblk;
530 register struct bufarea *bp;
531 char *cp, firstblk[DIRBLKSIZ];
532

--- 40 unchanged lines hidden (view full) ---

573 dp->di_blocks -= btodb(sblock.fs_bsize);
574 freeblk(newblk, sblock.fs_frag);
575 return (0);
576}
577
578/*
579 * allocate a new directory
580 */
544expanddir(dp, name)
545 register struct dinode *dp;
546 char *name;
547{
548 daddr_t lastbn, newblk;
549 register struct bufarea *bp;
550 char *cp, firstblk[DIRBLKSIZ];
551

--- 40 unchanged lines hidden (view full) ---

592 dp->di_blocks -= btodb(sblock.fs_bsize);
593 freeblk(newblk, sblock.fs_frag);
594 return (0);
595}
596
597/*
598 * allocate a new directory
599 */
600int
581allocdir(parent, request, mode)
582 ino_t parent, request;
583 int mode;
584{
585 ino_t ino;
586 char *cp;
587 struct dinode *dp;
588 register struct bufarea *bp;

--- 39 unchanged lines hidden (view full) ---

628 dp->di_nlink++;
629 inodirty();
630 return (ino);
631}
632
633/*
634 * free a directory inode
635 */
601allocdir(parent, request, mode)
602 ino_t parent, request;
603 int mode;
604{
605 ino_t ino;
606 char *cp;
607 struct dinode *dp;
608 register struct bufarea *bp;

--- 39 unchanged lines hidden (view full) ---

648 dp->di_nlink++;
649 inodirty();
650 return (ino);
651}
652
653/*
654 * free a directory inode
655 */
656static void
636freedir(ino, parent)
637 ino_t ino, parent;
638{
639 struct dinode *dp;
640
641 if (ino != parent) {
642 dp = ginode(parent);
643 dp->di_nlink--;
644 inodirty();
645 }
646 freeino(ino);
647}
648
649/*
650 * generate a temporary name for the lost+found directory.
651 */
657freedir(ino, parent)
658 ino_t ino, parent;
659{
660 struct dinode *dp;
661
662 if (ino != parent) {
663 dp = ginode(parent);
664 dp->di_nlink--;
665 inodirty();
666 }
667 freeino(ino);
668}
669
670/*
671 * generate a temporary name for the lost+found directory.
672 */
673int
652lftempname(bufp, ino)
653 char *bufp;
654 ino_t ino;
655{
656 register ino_t in;
657 register char *cp;
658 int namlen;
659

--- 29 unchanged lines hidden ---
674lftempname(bufp, ino)
675 char *bufp;
676 ino_t ino;
677{
678 register ino_t in;
679 register char *cp;
680 int namlen;
681

--- 29 unchanged lines hidden ---