fsck.h revision 355d6bb5e62a215a9bcf820ac85c1fc62bed2f3f
/* Copyright (c) 1984, 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.
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _FSCK_FSCK_H
#define _FSCK_FSCK_H
#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdarg.h>
#include <search.h>
#ifndef BUFSIZ
#define BUFSIZ MAXPATHLEN
#endif
/*
* Inode states in statemap[].
*/
/* flags OR'd into the above */
/*
*
* DUNFOUND === (state == DSTATE || state == DZLINK)
* INCLEAR is irrelevant to the determination of
* connectedness, so it's not included in this test.
*
* DVALID === (state == DSTATE || state == DZLINK || state == DFOUND)
*/
== (state))
/*
* buffer cache structure.
*/
struct bufarea {
int b_size;
int b_errs;
int b_flags;
int b_cnt; /* reference cnt */
union {
char *b_buf; /* buffer space */
} b_un;
char b_dirty;
};
#define B_INUSE 1
/*
* inodesc.id_fix values. See inode.c for a description of their usage.
*/
enum fixstate {
};
/*
* Tells truncino() whether or not to attempt to update the parent
* directory's link count. Also, TI_NODUP flags when we're discarding
* fragments that are beyond the original end of the file, and so
* should not be considered duplicate-claim candidates.
*/
/*
* Modes for ckinode() and ckinode_common().
*
* CKI_TRAVERSE is the common case, and requests a traditional
* traversal of blocks or directory entries.
*
* CKI_TRUNCATE indicates that we're truncating the file, and that any
* block indices beyond the end of the target length should be cleared
* after the callback has returned (i.e., this is a superset of
* CKI_TRAVERSE). idesc->id_truncto is the first logical block number
* to clear. If it is less than zero, then the traversal will be
* equivalent to a simple CKI_TRAVERSE.
*/
/*
* The general definition of an ino_t is an unsigned quantity.
* However, the on-disk version is an int32_t, which is signed.
* Since we really want to be able to detect wrapped-around
* inode numbers and such, we'll use something that's compatible
* with what's on disk since that's the only context that really
* matters. If an int32_t is found not to be sufficiently large,
* this will make it much easier to change later.
*
* Note that there is one unsigned inode field in the on-disk
* inode, ic_oeftflag. Since all other inode fields are signed,
* no legitimate inode number can be put into ic_oeftflag that
* would overflow into the high bit. Essentially, it should
* actually be declared as int32_t just like all the others, and
* we're going to pretend that it was.
*
* None of the routines that we use in ufs_subr.c do anything with
* inode numbers. If that changes, then great care will be needed
* to deal with the differences in definition of ino_t and fsck_ino_t.
* Lint is your friend.
*/
typedef int32_t fsck_ino_t;
/*
* See the full discussion of the interactions between struct inodesc
* and ckinode() in inode.c
*/
struct inodesc {
/* function to be applied to blocks of inode */
/* also used for extra (*id_func) parameter */
/* and return values */
int id_numfrags; /* number of frags contained in block */
/* zero but shouldn't be, -1 for no holes */
char id_type; /* type of descriptor, DATA or ADDR */
};
/* file types (0 is reserved for catching bugs) */
/*
* OR'd flags for find_dup_ref()'s mode argument
*/
/*
* Cache data structures
*/
struct inoinfo {
};
/*
* Inode cache
*/
/*
* ACL cache
*/
/*
* Tree of directories we haven't reconnected or cleared. Any
* dir inode that linkup() fails on gets added, any that clri()
* succeeds on gets removed. If there are any left at the end of
* pass four, then we have a user-forced corrupt filesystem, and
* need to set iscorrupt.
*
* Elements are fsck_ino_t instances (not pointers).
*/
void *limbo_dirs;
/*
* Number of directories we actually found in the filesystem,
* as opposed to how many the superblock claims there are.
*/
/*
* shadowclients and shadowclientinfo are structures for keeping track of
* shadow inodes that exist, and which regular inodes use them (i.e. are
* their clients).
*/
struct shadowclients {
int nclients; /* how many inodes in the array are in use (valid) */
};
struct shadowclientinfo {
int totalClients; /* how many inodes total refer to this */
};
struct shadowclientinfo *shadowclientinfo;
struct shadowclientinfo *attrclientinfo;
/*
* In ufs_inode.h ifdef _KERNEL, this is defined as `/@/'. However,
* to avoid all sorts of potential confusion (you can't actually use
* `foo/@/bar' to get to an attribute), we use something that doesn't
* look quite so much like a simple pathname.
*/
#define XATTR_DIR_NAME " <xattr> "
/*
* granularity -- how many client inodes do we make space for at a time
* initialized in setup.c;
*/
extern int maxshadowclients;
/*
* Initialized global variables.
*/
/*
* Unitialized globals.
*/
char *devname; /* name of device being checked */
int secsize; /* actual disk sector size */
char nflag; /* assume a no response */
char yflag; /* assume a yes response */
int debug; /* output debugging info */
int rflag; /* check raw file systems */
int roflag; /* do normal checks but don't update disk */
int fflag; /* check regardless of clean flag (force) */
int mflag; /* sanity check only */
int verbose; /* be chatty */
char preen; /* just fix normal inconsistencies */
char mountedfs; /* checking mounted device */
int exitstat; /* exit status (see EX* defines below) */
char hotroot; /* checking root device */
char rerun; /* rerun fsck. Only used in non-preen mode */
int interrupted; /* 1 => exit EXSIGNAL on exit */
char havesb; /* superblock has been read */
int fsmodified; /* 1 => write done to file system */
int fsreadfd; /* file descriptor for reading file system */
int fswritefd; /* file descriptor for writing file system */
int iscorrupt; /* known to be corrupt/inconsistent */
/* -1 means mark clean so user can mount+fix */
int isdirty; /* 1 => write pending to file system */
int islog; /* logging file system */
int islogok; /* log is okay */
int errorlocked; /* set => mounted fs has been error-locked */
/* implies fflag "force check flag" */
char *elock_combuf; /* error lock comment buffer */
char *elock_mountp; /* mount point; used to unlock error-lock */
int pid; /* fsck's process id (put in lockfs comment) */
int mountfd; /* fd of mount point */
char *mount_point; /* if mounted, this is where */
char *blockmap; /* ptr to primary blk allocation map */
short *lncntp; /* ptr to link count table */
int overflowed_lf; /* tried to wrap lost & found's link count */
int reattached_dir; /* reconnected at least one directory */
int broke_dir_link; /* broke at least one directory hardlink */
#define clearinode(dp) { \
}
#define STOP 0x01
#define SKIP 0x02
#define KEEPON 0x04
#define ALTERED 0x08
#define FOUND 0x10
/*
* Support relatively easy debugging of lncntp[] updates. This can't
* be a function, because of the (_op) step. Normally, we just do that.
*/
/*
* See if the net link count for an inode has gone outside
* what can be represented on disk. Returning text as NULL
* indicates no.
*
* Remember that link counts are effectively inverted, so
* underflow and overflow are reversed as well.
*
* This check should be done before modifying the actual link
* count.
*/
text = "UNDERFLOW"; \
text = "OVERFLOW"; \
}
/*
* If LINK_RANGE() indicated a problem, this is the boiler-plate
* for dealing with it. Usage is:
*
* LINK_RANGE(text, current, offset);
* if (text != NULL) {
* LINK_CLEAR(text, ino, mode, idp);
* if (statemap[ino] == USTATE)
* ...inode was cleared...
* }
*
* Note that clri() will set iscorrupt if the user elects not to
* clear the problem inode, so the filesystem won't get reported
* as clean when it shouldn't be.
*/
pfatal(""); \
init_inodesc((idp)); \
}
/*
* the lost+found directory. If the user decides not to do the
* clri(), then flag that we've hit this problem and refuse to do
* the reconnect.
*/
lfdir = 0; \
return (rval); \
} else { \
overflowed_lf++; \
} \
} \
}
lfdir = 0; \
return; \
} else { \
overflowed_lf++; \
} \
} \
}
/*
* Values for mounted() and mountedfs.
*/
#define M_NOMNT 0 /* filesystem is not mounted */
#define EXOKAY 0 /* file system is unmounted and ok */
/*
* Values for clri()'s `verbose' and `corrupting' arguments (third
* and fourth, respectively).
*/
#define CLRI_QUIET 1
#define CLRI_VERBOSE 2
#define CLRI_NOP_OK 1
#define CLRI_NOP_CORRUPT 2
/*
* Filesystems that are `magical' - if they exist in vfstab,
* then they have to be mounted for the system to have gotten
* far enough to be able to run fsck. Thus, don't get all
* bent out of shape if we're asked to check it and it is mounted.
* Actual initialization of the array is in main.c
*/
enum magic {
MAGIC_NONE = 0,
MAGIC_ROOT = 1,
MAGIC_USR = 2,
MAGIC_VAR = 3,
MAGIC_LIMIT = 4
};
extern char *magic_fs[];
/*
* Paths needed by calcsb().
*/
void add_orphan_dir(fsck_ino_t);
void bufinit(void);
void catch(int);
void catchquit(int);
void cgflush(void);
int cgisdirty(void);
void ckfini(void);
void clearattrref(fsck_ino_t);
int do_errorlock(int);
void free_dup_state(void);
void freeino(fsck_ino_t, int);
void freeinodebuf(void);
struct dinode *getnextrefresh(void);
int have_dups(void);
void init_inodesc(struct inodesc *);
int ino_t_cmp(const void *, const void *);
int inocached(fsck_ino_t);
void inocleanup(void);
void inodirty(void);
int is_errorlocked(caddr_t);
void pass1(void);
void pass1b(void);
int pass1check(struct inodesc *);
void pass2a(void);
void pass2b(void);
void pass3a(void);
void pass3b(void);
int pass3bcheck(struct inodesc *);
void pass4(void);
int pass4check(struct inodesc *);
void pass5(void);
void pinode(fsck_ino_t);
void printclean(void);
void propagate(void);
struct shadowclientinfo **);
void remove_orphan_dir(fsck_ino_t);
int report_dups(int);
void resetinodebuf(void);
void unbufinit(void);
int updateclean(void);
void write_altsb(int);
/*
* Functions from the kernel sources (ufs_subr.c, etc).
*/
#ifdef __cplusplus
}
#endif
#endif /* _FSCK_FSCK_H */