dir.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#define _KERNEL
#include "fsck.h"
char *lfname = "lost+found";
int lfmode = 01700;
struct direct *fsck_readdir();
/*
* Propagate connected state through the tree.
*/
{
int change;
do {
change = 0;
continue;
change++;
}
}
} while (change > 0);
}
/*
* Scan each entry in a directory block.
*/
{
int dsize, n;
int blksiz;
if (idesc->id_entryno == 0 &&
return (SKIP);
}
/*
* If we were just passed a corrupt directory entry with
* d_reclen > DIRBLKSIZ so we don't bcopy() all over our stack.
* This directory gets cleaned up later.
*/
dsize);
sbdirty();
}
if (n & STOP)
return (n);
}
}
/*
* Get current entry in a directory (and peek at the next entry).
*/
struct direct *
{
int dofixret;
/*
* Sanity check id_filesize and id_loc fields.
*/
return (NULL);
/*
* Check the current entry in the directory.
*/
/*
* If we are in here, then either the current directory
* entry is bad or the next directory entry is bad.
*/
/*
* Find the amount of space left to the end of the
* directory block for either directory entry.
*/
/*
* Advance to the end of the directory block.
*/
/*
* Ask the question before we fix the in-core directory
* block because dofix() may reuse the buffer.
*/
/*
* This is the current directory entry and since it is
* corrupt we cannot trust the rest of the directory
* block so change the current directory entry to
* contain nothing and encompass the rest of the block.
*/
}
/*
* This is the next directory entry, i.e., we got here
* via a "goto next_is_bad". This directory entry is
* corrupt. The current directory entry is okay so, if we
* are in fix mode, extend just its record size to encompass
* the rest of the block.
*/
else if (dofixret) {
}
/*
* If the user said to fix the directory corruption, then
* mark the block as dirty. Otherwise, our "repairs" only
* apply to the in-core copy so we don't hand back trash
* to the caller.
*
* Note: It is possible that saying "no" to a change in
* one part of the I/O buffer and "yes" to a later change
* in the same I/O buffer may still flush the change to
* which we said "no". This is the pathalogical case and
* no fix is planned at this time.
*/
if (dofixret)
return (dp);
}
/*
* The current directory entry checked out so advance past it.
*/
/*
* If we are not at the directory block boundary, then peek
* at the next directory entry and if it is bad we can add
* its space to the current directory entry (compression).
* Again, we sanity check the id_loc and id_filesize fields
* since we modified them above.
*/
goto next_is_bad;
}
return (dp);
}
/*
* Verify that a directory entry is valid.
* This is a superset of the checks made in the kernel.
*/
{
int size;
char *cp;
int spaceleft;
return (1);
return (0);
if (*cp == 0)
return (1);
}
return (0);
}
char *errmesg;
{
}
char *errmesg;
{
printf("\n");
return;
}
pfatal("%s=%s\n",
else
}
short lcnt;
{
return;
}
}
pwarn("LINK COUNT %s",
printf(" COUNT %d SHOULD BE %d",
if (preen) {
if (lcnt < 0) {
printf("\n");
pwarn("LINK COUNT INCREASING");
else
pfatal("LINK COUNT INCREASING");
}
printf(" (ADJUSTED)\n");
}
inodirty();
}
}
}
{
else
oldlen = 0;
return (KEEPON);
}
{
return (KEEPON);
}
{
int lostdir;
int lostshadow;
int lostattrdir;
extern int pass4check();
/*
* reclaim thread will remove this dir at mount
*/
if (lostdir &&
return (0);
}
return (0);
if (preen)
printf(" (RECONNECTED)\n");
else
if (reply("RECONNECT") == 0)
return (0);
if (lfdir == 0) {
} else {
pwarn("NO lost+found DIRECTORY");
if (lfdir != 0) {
lfname) != 0) {
if (preen)
printf(" (CREATED)\n");
} else {
lfdir = 0;
if (preen)
printf("\n");
}
}
}
}
if (lfdir == 0) {
pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY");
printf("\n\n");
return (0);
}
} else { /* lost+found already created */
}
pfatal("lost+found IS NOT A DIRECTORY");
if (reply("REALLOCATE") == 0)
return (0);
pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n");
return (0);
}
pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n");
return (0);
}
inodirty();
}
pfatal("SORRY. NO lost+found DIRECTORY\n\n");
return (0);
}
pfatal("SORRY. NO SPACE IN lost+found DIRECTORY");
printf("\n\n");
return (0);
}
if (lostdir) {
/*
* If we were half-detached, don't try to get
* inode 0 later on.
*/
if (parentdir == 0)
parentdir = -1;
inodirty();
}
if (preen == 0)
printf("\n");
}
return (1);
}
/*
* fix an entry in a directory.
*/
char *name;
{
}
/*
* make an entry in a directory
*/
char *name;
{
return (0);
inodirty();
}
return (1);
return (0);
}
/*
* Attempt to expand the size of a directory
*/
char *name;
{
char *cp;
int bc, n, f;
int allocIndir;
int frag2blks = 0;
int lffragsz = 0;
int c = 0;
return (0);
/*
* Check that none of the direct block addresses for
* the directory are bogus.
*/
return (0);
}
/*
* Determine our data block allocation needs. We always need to
* allocate at least one data block. We may need a second, the
* indirect block itself.
*/
allocIndir = 0;
nxtibn = -1;
/*
* Still in direct blocks. Check for the unlikely
* case where the last block is a frag rather than
* a full block. This would only happen if someone had
* created a file in lost+found, and then that caused
* the dynamic directory shrinking capabilities of ufs
* to kick in.
*/
}
/*
* Only go one level of indirection
*/
if (nxtibn >= n)
return (0);
if (nxtibn == 0)
allocIndir++;
}
/*
* Allocate all the new blocks we need.
*/
goto bail;
c++;
if (allocIndir) {
goto bail;
c++;
}
/*
* Take care of the block that will hold new directory entries.
* This one is always allocated.
*/
goto bail;
if (lffragsz) {
goto bail;
} else {
}
/*
* If we allocated the indirect block, zero it out. Otherwise
* read it in if we're using one.
*/
if (allocIndir) {
goto bail;
} else if (nxtibn >= 0) {
/* Check that the indirect block pointer looks okay */
goto bail;
goto bail;
goto bail;
}
}
if (preen)
printf(" (EXPANDED)\n");
else if (reply("EXPAND") == 0)
goto bail;
/*
* Now that everything we need is gathered up, we
* do the final assignments
*/
if (lffragsz) {
inodirty();
return (1);
}
if (allocIndir) {
}
inodirty();
if (nxtibn < 0) {
/*
* Still in direct blocks
*/
} else {
/*
* Last indirect is always going to point at the
* new directory buffer
*/
if (allocIndir)
}
return (1);
bail:
for (f = 0; f < c; f++)
return (0);
}
/*
* allocate a new directory
*/
int mode;
{
char *cp;
if (ino == 0)
return (0);
return (0);
}
inodirty();
if (debug)
printf("inode %d added to directory cache\n",
ino);
} else {
/*
* re-using an old directory inode
*/
}
if (ino == UFSROOTINO) {
return (ino);
}
return (0);
}
}
inodirty();
return (ino);
}
/*
* free a directory inode
*/
{
inodirty();
}
}
/*
* generate a temporary name for the lost+found directory.
*/
char *bufp;
{
char *cp;
int namlen;
cp++;
*--cp = 0;
in /= 10;
}
*cp = '#';
return (namlen);
}
/*
* Get a directory block.
* Insure that it is held until another is requested.
*/
struct bufarea *
int size;
{
if (pdirbp != 0) {
}
return (pdirbp);
}