Deleted Added
full compact
dir.c (86514) dir.c (92806)
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

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

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static const char sccsid[] = "@(#)dir.c 8.8 (Berkeley) 4/28/95";
37#endif
38static const char rcsid[] =
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

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

31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static const char sccsid[] = "@(#)dir.c 8.8 (Berkeley) 4/28/95";
37#endif
38static const char rcsid[] =
39 "$FreeBSD: head/sbin/fsck_ffs/dir.c 86514 2001-11-17 23:48:21Z iedowse $";
39 "$FreeBSD: head/sbin/fsck_ffs/dir.c 92806 2002-03-20 17:55:10Z obrien $";
40#endif /* not lint */
41
42#include <sys/param.h>
43#include <sys/time.h>
44#include <sys/sysctl.h>
45
46#include <ufs/ufs/dinode.h>
47#include <ufs/ufs/dir.h>

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

77static int mkentry __P((struct inodesc *));
78
79/*
80 * Propagate connected state through the tree.
81 */
82void
83propagate()
84{
40#endif /* not lint */
41
42#include <sys/param.h>
43#include <sys/time.h>
44#include <sys/sysctl.h>
45
46#include <ufs/ufs/dinode.h>
47#include <ufs/ufs/dir.h>

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

77static int mkentry __P((struct inodesc *));
78
79/*
80 * Propagate connected state through the tree.
81 */
82void
83propagate()
84{
85 register struct inoinfo **inpp, *inp;
85 struct inoinfo **inpp, *inp;
86 struct inoinfo **inpend;
87 long change;
88
89 inpend = &inpsort[inplast];
90 do {
91 change = 0;
92 for (inpp = inpsort; inpp < inpend; inpp++) {
93 inp = *inpp;

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

102 } while (change > 0);
103}
104
105/*
106 * Scan each entry in a directory block.
107 */
108int
109dirscan(idesc)
86 struct inoinfo **inpend;
87 long change;
88
89 inpend = &inpsort[inplast];
90 do {
91 change = 0;
92 for (inpp = inpsort; inpp < inpend; inpp++) {
93 inp = *inpp;

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

102 } while (change > 0);
103}
104
105/*
106 * Scan each entry in a directory block.
107 */
108int
109dirscan(idesc)
110 register struct inodesc *idesc;
110 struct inodesc *idesc;
111{
111{
112 register struct direct *dp;
113 register struct bufarea *bp;
112 struct direct *dp;
113 struct bufarea *bp;
114 u_int dsize, n;
115 long blksiz;
116 char dbuf[DIRBLKSIZ];
117
118 if (idesc->id_type != DATA)
119 errx(EEXIT, "wrong type to dirscan %d", idesc->id_type);
120 if (idesc->id_entryno == 0 &&
121 (idesc->id_filesize & (DIRBLKSIZ - 1)) != 0)

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

166 return (idesc->id_filesize > 0 ? KEEPON : STOP);
167}
168
169/*
170 * get next entry in a directory.
171 */
172static struct direct *
173fsck_readdir(idesc)
114 u_int dsize, n;
115 long blksiz;
116 char dbuf[DIRBLKSIZ];
117
118 if (idesc->id_type != DATA)
119 errx(EEXIT, "wrong type to dirscan %d", idesc->id_type);
120 if (idesc->id_entryno == 0 &&
121 (idesc->id_filesize & (DIRBLKSIZ - 1)) != 0)

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

166 return (idesc->id_filesize > 0 ? KEEPON : STOP);
167}
168
169/*
170 * get next entry in a directory.
171 */
172static struct direct *
173fsck_readdir(idesc)
174 register struct inodesc *idesc;
174 struct inodesc *idesc;
175{
175{
176 register struct direct *dp, *ndp;
177 register struct bufarea *bp;
176 struct direct *dp, *ndp;
177 struct bufarea *bp;
178 long size, blksiz, fix, dploc;
179
180 blksiz = idesc->id_numfrags * sblock.fs_fsize;
181 bp = getdirblk(idesc->id_blkno, blksiz);
182 if (idesc->id_loc % DIRBLKSIZ == 0 && idesc->id_filesize > 0 &&
183 idesc->id_loc < blksiz) {
184 dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
185 if (dircheck(idesc, dp))

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

229
230/*
231 * Verify that a directory entry is valid.
232 * This is a superset of the checks made in the kernel.
233 */
234static int
235dircheck(idesc, dp)
236 struct inodesc *idesc;
178 long size, blksiz, fix, dploc;
179
180 blksiz = idesc->id_numfrags * sblock.fs_fsize;
181 bp = getdirblk(idesc->id_blkno, blksiz);
182 if (idesc->id_loc % DIRBLKSIZ == 0 && idesc->id_filesize > 0 &&
183 idesc->id_loc < blksiz) {
184 dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
185 if (dircheck(idesc, dp))

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

229
230/*
231 * Verify that a directory entry is valid.
232 * This is a superset of the checks made in the kernel.
233 */
234static int
235dircheck(idesc, dp)
236 struct inodesc *idesc;
237 register struct direct *dp;
237 struct direct *dp;
238{
238{
239 register int size;
240 register char *cp;
239 int size;
240 char *cp;
241 u_char namlen, type;
242 int spaceleft;
243
244 spaceleft = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
245 if (dp->d_reclen == 0 ||
246 dp->d_reclen > spaceleft ||
247 (dp->d_reclen & 0x3) != 0)
248 goto bad;

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

289 fileerror(ino, ino, errmesg);
290}
291
292void
293fileerror(cwd, ino, errmesg)
294 ino_t cwd, ino;
295 char *errmesg;
296{
241 u_char namlen, type;
242 int spaceleft;
243
244 spaceleft = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
245 if (dp->d_reclen == 0 ||
246 dp->d_reclen > spaceleft ||
247 (dp->d_reclen & 0x3) != 0)
248 goto bad;

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

289 fileerror(ino, ino, errmesg);
290}
291
292void
293fileerror(cwd, ino, errmesg)
294 ino_t cwd, ino;
295 char *errmesg;
296{
297 register struct dinode *dp;
297 struct dinode *dp;
298 char pathbuf[MAXPATHLEN + 1];
299
300 pwarn("%s ", errmesg);
301 pinode(ino);
302 printf("\n");
303 getpathname(pathbuf, cwd, ino);
304 if (ino < ROOTINO || ino > maxino) {
305 pfatal("NAME=%s\n", pathbuf);

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

310 pfatal("%s=%s\n",
311 (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf);
312 else
313 pfatal("NAME=%s\n", pathbuf);
314}
315
316void
317adjust(idesc, lcnt)
298 char pathbuf[MAXPATHLEN + 1];
299
300 pwarn("%s ", errmesg);
301 pinode(ino);
302 printf("\n");
303 getpathname(pathbuf, cwd, ino);
304 if (ino < ROOTINO || ino > maxino) {
305 pfatal("NAME=%s\n", pathbuf);

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

310 pfatal("%s=%s\n",
311 (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf);
312 else
313 pfatal("NAME=%s\n", pathbuf);
314}
315
316void
317adjust(idesc, lcnt)
318 register struct inodesc *idesc;
318 struct inodesc *idesc;
319 int lcnt;
320{
321 struct dinode *dp;
322 int saveresolved;
323
324 dp = ginode(idesc->id_number);
325 if (dp->di_nlink == lcnt) {
326 /*

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

382 }
383 }
384}
385
386static int
387mkentry(idesc)
388 struct inodesc *idesc;
389{
319 int lcnt;
320{
321 struct dinode *dp;
322 int saveresolved;
323
324 dp = ginode(idesc->id_number);
325 if (dp->di_nlink == lcnt) {
326 /*

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

382 }
383 }
384}
385
386static int
387mkentry(idesc)
388 struct inodesc *idesc;
389{
390 register struct direct *dirp = idesc->id_dirp;
390 struct direct *dirp = idesc->id_dirp;
391 struct direct newent;
392 int newlen, oldlen;
393
394 newent.d_namlen = strlen(idesc->id_name);
395 newlen = DIRSIZ(0, &newent);
396 if (dirp->d_ino != 0)
397 oldlen = DIRSIZ(0, dirp);
398 else

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

427# endif
428 return (ALTERED|STOP);
429}
430
431static int
432chgino(idesc)
433 struct inodesc *idesc;
434{
391 struct direct newent;
392 int newlen, oldlen;
393
394 newent.d_namlen = strlen(idesc->id_name);
395 newlen = DIRSIZ(0, &newent);
396 if (dirp->d_ino != 0)
397 oldlen = DIRSIZ(0, dirp);
398 else

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

427# endif
428 return (ALTERED|STOP);
429}
430
431static int
432chgino(idesc)
433 struct inodesc *idesc;
434{
435 register struct direct *dirp = idesc->id_dirp;
435 struct direct *dirp = idesc->id_dirp;
436
437 if (memcmp(dirp->d_name, idesc->id_name, (int)dirp->d_namlen + 1))
438 return (KEEPON);
439 dirp->d_ino = idesc->id_parent;
440 if (newinofmt)
441 dirp->d_type = inoinfo(idesc->id_parent)->ino_type;
442 else
443 dirp->d_type = 0;
444 return (ALTERED|STOP);
445}
446
447int
448linkup(orphan, parentdir, name)
449 ino_t orphan;
450 ino_t parentdir;
451 char *name;
452{
436
437 if (memcmp(dirp->d_name, idesc->id_name, (int)dirp->d_namlen + 1))
438 return (KEEPON);
439 dirp->d_ino = idesc->id_parent;
440 if (newinofmt)
441 dirp->d_type = inoinfo(idesc->id_parent)->ino_type;
442 else
443 dirp->d_type = 0;
444 return (ALTERED|STOP);
445}
446
447int
448linkup(orphan, parentdir, name)
449 ino_t orphan;
450 ino_t parentdir;
451 char *name;
452{
453 register struct dinode *dp;
453 struct dinode *dp;
454 int lostdir;
455 ino_t oldlfdir;
456 struct inodesc idesc;
457 char tempname[BUFSIZ];
458
459 memset(&idesc, 0, sizeof(struct inodesc));
460 dp = ginode(orphan);
461 lostdir = (dp->di_mode & IFMT) == IFDIR;

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

620 return (ckinode(dp, &idesc) & ALTERED);
621}
622
623/*
624 * Attempt to expand the size of a directory
625 */
626static int
627expanddir(dp, name)
454 int lostdir;
455 ino_t oldlfdir;
456 struct inodesc idesc;
457 char tempname[BUFSIZ];
458
459 memset(&idesc, 0, sizeof(struct inodesc));
460 dp = ginode(orphan);
461 lostdir = (dp->di_mode & IFMT) == IFDIR;

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

620 return (ckinode(dp, &idesc) & ALTERED);
621}
622
623/*
624 * Attempt to expand the size of a directory
625 */
626static int
627expanddir(dp, name)
628 register struct dinode *dp;
628 struct dinode *dp;
629 char *name;
630{
631 ufs_daddr_t lastbn, newblk;
629 char *name;
630{
631 ufs_daddr_t lastbn, newblk;
632 register struct bufarea *bp;
632 struct bufarea *bp;
633 char *cp, firstblk[DIRBLKSIZ];
634
635 lastbn = lblkno(&sblock, dp->di_size);
636 if (lastbn >= NDADDR - 1 || dp->di_db[lastbn] == 0 || dp->di_size == 0)
637 return (0);
638 if ((newblk = allocblk(sblock.fs_frag)) == 0)
639 return (0);
640 dp->di_db[lastbn + 1] = dp->di_db[lastbn];

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

758/*
759 * generate a temporary name for the lost+found directory.
760 */
761static int
762lftempname(bufp, ino)
763 char *bufp;
764 ino_t ino;
765{
633 char *cp, firstblk[DIRBLKSIZ];
634
635 lastbn = lblkno(&sblock, dp->di_size);
636 if (lastbn >= NDADDR - 1 || dp->di_db[lastbn] == 0 || dp->di_size == 0)
637 return (0);
638 if ((newblk = allocblk(sblock.fs_frag)) == 0)
639 return (0);
640 dp->di_db[lastbn + 1] = dp->di_db[lastbn];

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

758/*
759 * generate a temporary name for the lost+found directory.
760 */
761static int
762lftempname(bufp, ino)
763 char *bufp;
764 ino_t ino;
765{
766 register ino_t in;
767 register char *cp;
766 ino_t in;
767 char *cp;
768 int namlen;
769
770 cp = bufp + 2;
771 for (in = maxino; in > 0; in /= 10)
772 cp++;
773 *--cp = 0;
774 namlen = cp - bufp;
775 in = ino;

--- 23 unchanged lines hidden ---
768 int namlen;
769
770 cp = bufp + 2;
771 for (in = maxino; in > 0; in /= 10)
772 cp++;
773 *--cp = 0;
774 namlen = cp - bufp;
775 in = ino;

--- 23 unchanged lines hidden ---