1*6d07b400Sbouyer /* $NetBSD: pass3.c,v 1.7 2009/10/19 18:41:08 bouyer Exp $ */
2bf07c871Sagc
3bf07c871Sagc /*
4bf07c871Sagc * Copyright (c) 1980, 1986, 1993
5bf07c871Sagc * The Regents of the University of California. All rights reserved.
6bf07c871Sagc *
7bf07c871Sagc * Redistribution and use in source and binary forms, with or without
8bf07c871Sagc * modification, are permitted provided that the following conditions
9bf07c871Sagc * are met:
10bf07c871Sagc * 1. Redistributions of source code must retain the above copyright
11bf07c871Sagc * notice, this list of conditions and the following disclaimer.
12bf07c871Sagc * 2. Redistributions in binary form must reproduce the above copyright
13bf07c871Sagc * notice, this list of conditions and the following disclaimer in the
14bf07c871Sagc * documentation and/or other materials provided with the distribution.
15bf07c871Sagc * 3. Neither the name of the University nor the names of its contributors
16bf07c871Sagc * may be used to endorse or promote products derived from this software
17bf07c871Sagc * without specific prior written permission.
18bf07c871Sagc *
19bf07c871Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20bf07c871Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21bf07c871Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22bf07c871Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23bf07c871Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24bf07c871Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25bf07c871Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26bf07c871Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27bf07c871Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28bf07c871Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29bf07c871Sagc * SUCH DAMAGE.
30bf07c871Sagc */
318f7c2b37Sbouyer
328f7c2b37Sbouyer /*
338f7c2b37Sbouyer * Copyright (c) 1997 Manuel Bouyer.
348f7c2b37Sbouyer *
358f7c2b37Sbouyer * Redistribution and use in source and binary forms, with or without
368f7c2b37Sbouyer * modification, are permitted provided that the following conditions
378f7c2b37Sbouyer * are met:
388f7c2b37Sbouyer * 1. Redistributions of source code must retain the above copyright
398f7c2b37Sbouyer * notice, this list of conditions and the following disclaimer.
408f7c2b37Sbouyer * 2. Redistributions in binary form must reproduce the above copyright
418f7c2b37Sbouyer * notice, this list of conditions and the following disclaimer in the
428f7c2b37Sbouyer * documentation and/or other materials provided with the distribution.
438f7c2b37Sbouyer *
442f853da9Sbouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
452f853da9Sbouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
462f853da9Sbouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
472f853da9Sbouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
482f853da9Sbouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
492f853da9Sbouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
502f853da9Sbouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
512f853da9Sbouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
522f853da9Sbouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
532f853da9Sbouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
548f7c2b37Sbouyer */
558f7c2b37Sbouyer
564b836889Slukem #include <sys/cdefs.h>
578f7c2b37Sbouyer #ifndef lint
588f7c2b37Sbouyer #if 0
598f7c2b37Sbouyer static char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93";
608f7c2b37Sbouyer #else
61*6d07b400Sbouyer __RCSID("$NetBSD: pass3.c,v 1.7 2009/10/19 18:41:08 bouyer Exp $");
628f7c2b37Sbouyer #endif
638f7c2b37Sbouyer #endif /* not lint */
648f7c2b37Sbouyer
658f7c2b37Sbouyer #include <sys/param.h>
668f7c2b37Sbouyer #include <sys/time.h>
678f7c2b37Sbouyer #include <ufs/ext2fs/ext2fs_dinode.h>
688f7c2b37Sbouyer #include <ufs/ext2fs/ext2fs.h>
698f7c2b37Sbouyer #include "fsck.h"
708f7c2b37Sbouyer #include "extern.h"
718f7c2b37Sbouyer
728f7c2b37Sbouyer void
pass3(void)73ccde05f0Sxtraeme pass3(void)
748f7c2b37Sbouyer {
754b836889Slukem struct inoinfo **inpp, *inp;
768f7c2b37Sbouyer ino_t orphan;
778f7c2b37Sbouyer int loopcnt;
788f7c2b37Sbouyer
798f7c2b37Sbouyer for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--) {
808f7c2b37Sbouyer inp = *inpp;
818f7c2b37Sbouyer if (inp->i_number == EXT2_ROOTINO ||
828f7c2b37Sbouyer !(inp->i_parent == 0 || statemap[inp->i_number] == DSTATE))
838f7c2b37Sbouyer continue;
848f7c2b37Sbouyer if (statemap[inp->i_number] == DCLEAR)
858f7c2b37Sbouyer continue;
868f7c2b37Sbouyer for (loopcnt = 0; ; loopcnt++) {
878f7c2b37Sbouyer orphan = inp->i_number;
888f7c2b37Sbouyer if (inp->i_parent == 0 ||
898f7c2b37Sbouyer statemap[inp->i_parent] != DSTATE ||
908f7c2b37Sbouyer loopcnt > numdirs)
918f7c2b37Sbouyer break;
928f7c2b37Sbouyer inp = getinoinfo(inp->i_parent);
938f7c2b37Sbouyer }
948f7c2b37Sbouyer (void)linkup(orphan, inp->i_dotdot);
958f7c2b37Sbouyer inp->i_parent = inp->i_dotdot = lfdir;
968f7c2b37Sbouyer lncntp[lfdir]--;
978f7c2b37Sbouyer statemap[orphan] = DFOUND;
988f7c2b37Sbouyer propagate();
998f7c2b37Sbouyer }
1008f7c2b37Sbouyer }
101