1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1999,2000 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _FSCK_PCFS_H 28*0Sstevel@tonic-gate #define _FSCK_PCFS_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate /* 33*0Sstevel@tonic-gate * Structures used by the pcfs file system checker. 34*0Sstevel@tonic-gate */ 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #ifdef __cplusplus 37*0Sstevel@tonic-gate extern "C" { 38*0Sstevel@tonic-gate #endif 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #include <sys/types.h> 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate /* 43*0Sstevel@tonic-gate * The root directory of FAT12/16 file systems doesn't sit in 44*0Sstevel@tonic-gate * a cluster. 45*0Sstevel@tonic-gate */ 46*0Sstevel@tonic-gate #define FAKE_ROOTDIR_CLUST -1 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate /* 49*0Sstevel@tonic-gate * The first available cluster number for a FAT fs is always the same, 2. 50*0Sstevel@tonic-gate */ 51*0Sstevel@tonic-gate #define FIRST_CLUSTER 2 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate #define RETURN_ON_OPEN_FAILURE 0 54*0Sstevel@tonic-gate #define EXIT_ON_OPEN_FAILURE 1 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate #define NO_FAT_IN_SUMMARY 0 57*0Sstevel@tonic-gate #define INCLUDE_FAT_IN_SUMMARY 1 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate #define RDCLUST_DONT_CACHE 0 60*0Sstevel@tonic-gate #define RDCLUST_DO_CACHE 1 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate /* 63*0Sstevel@tonic-gate * Return values for sanityCheckSize() 64*0Sstevel@tonic-gate */ 65*0Sstevel@tonic-gate #define SIZE_MATCHED 0 66*0Sstevel@tonic-gate #define TRUNCATED 1 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate #define RDCLUST_MAX_RETRY 3 69*0Sstevel@tonic-gate #define RDCLUST_GOOD 0 70*0Sstevel@tonic-gate #define RDCLUST_FAIL -1 71*0Sstevel@tonic-gate #define RDCLUST_MEMERR -2 72*0Sstevel@tonic-gate #define RDCLUST_BADINPUT -3 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate typedef union clustDataTypes { 75*0Sstevel@tonic-gate struct pcdir *dirp; 76*0Sstevel@tonic-gate uchar_t *bytes; 77*0Sstevel@tonic-gate } ClusterContents; 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate struct cached { 80*0Sstevel@tonic-gate int32_t clusterNum; 81*0Sstevel@tonic-gate ClusterContents clusterData; 82*0Sstevel@tonic-gate short modified; 83*0Sstevel@tonic-gate struct cached *next; 84*0Sstevel@tonic-gate }; 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate typedef struct cached CachedCluster; 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate struct nameinfo { 89*0Sstevel@tonic-gate char *fullName; 90*0Sstevel@tonic-gate int references; 91*0Sstevel@tonic-gate }; 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate /* 94*0Sstevel@tonic-gate * This structure is shared between all structures belonging to 95*0Sstevel@tonic-gate * a single file. The refcnt is a 24 bit integer, that should be 96*0Sstevel@tonic-gate * sufficient for 4GB files, even when someone uses 256 byte clusters 97*0Sstevel@tonic-gate * (4K is the typical cluster size, 512 bytes is probably the minimum) 98*0Sstevel@tonic-gate * The inefficiency of using a bit field is compensated by the memory 99*0Sstevel@tonic-gate * savings and prevented paging on large filesystems. 100*0Sstevel@tonic-gate */ 101*0Sstevel@tonic-gate struct clinfo { 102*0Sstevel@tonic-gate struct pcdir *dirent; 103*0Sstevel@tonic-gate union { 104*0Sstevel@tonic-gate struct clinfo *_nextfree; 105*0Sstevel@tonic-gate struct pcdir *_longent; 106*0Sstevel@tonic-gate } _unionelem; 107*0Sstevel@tonic-gate int32_t longEntStartClust; 108*0Sstevel@tonic-gate int refcnt:24; 109*0Sstevel@tonic-gate uint_t flags:8; 110*0Sstevel@tonic-gate uchar_t *saved; 111*0Sstevel@tonic-gate struct nameinfo *path; 112*0Sstevel@tonic-gate }; 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate /* 115*0Sstevel@tonic-gate * #define dirent conflicts with other dirent uses, so we used the 116*0Sstevel@tonic-gate * second element instead of the first one one as union for the free 117*0Sstevel@tonic-gate * list 118*0Sstevel@tonic-gate */ 119*0Sstevel@tonic-gate #define longent _unionelem._longent 120*0Sstevel@tonic-gate #define nextfree _unionelem._nextfree 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate typedef struct clinfo ClusterInfo; 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate /* 125*0Sstevel@tonic-gate * Return values for allocInUse 126*0Sstevel@tonic-gate */ 127*0Sstevel@tonic-gate #define CLINFO_PREVIOUSLY_ALLOCED 1 128*0Sstevel@tonic-gate #define CLINFO_NEWLY_ALLOCED 0 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate #define CLINFO_BAD 0x1 131*0Sstevel@tonic-gate #define CLINFO_ORPHAN 0x2 132*0Sstevel@tonic-gate #define CLINFO_HIDDEN 0x4 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate /* 135*0Sstevel@tonic-gate * Traversal operations for wandering the file system metadata 136*0Sstevel@tonic-gate */ 137*0Sstevel@tonic-gate #define PCFS_NO_SUBDIRS 0 138*0Sstevel@tonic-gate #define PCFS_VISIT_SUBDIRS 1 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate #define PCFS_TRAVERSE_ALL 1 /* visit all nodes */ 141*0Sstevel@tonic-gate #define PCFS_FIND_ATTR 2 /* search for matching attribute */ 142*0Sstevel@tonic-gate #define PCFS_FIND_STATUS 3 /* search for same status */ 143*0Sstevel@tonic-gate #define PCFS_FIND_CHKS 4 /* find FILENNNN.CHK files */ 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate /* 146*0Sstevel@tonic-gate * Booleans for markInUse, whether or not file is marked hidden. 147*0Sstevel@tonic-gate */ 148*0Sstevel@tonic-gate #define VISIBLE 0 149*0Sstevel@tonic-gate #define HIDDEN 1 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate /* 152*0Sstevel@tonic-gate * Indices for various parts of the FILEnnnn.CHK name 153*0Sstevel@tonic-gate */ 154*0Sstevel@tonic-gate #define CHKNAME_F 0 155*0Sstevel@tonic-gate #define CHKNAME_I 1 156*0Sstevel@tonic-gate #define CHKNAME_L 2 157*0Sstevel@tonic-gate #define CHKNAME_E 3 158*0Sstevel@tonic-gate #define CHKNAME_THOUSANDS 4 159*0Sstevel@tonic-gate #define CHKNAME_HUNDREDS 5 160*0Sstevel@tonic-gate #define CHKNAME_TENS 6 161*0Sstevel@tonic-gate #define CHKNAME_ONES 7 162*0Sstevel@tonic-gate #define CHKNAME_C 0 163*0Sstevel@tonic-gate #define CHKNAME_H 1 164*0Sstevel@tonic-gate #define CHKNAME_K 2 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate /* 167*0Sstevel@tonic-gate * Largest value that will fit into our lost+found naming scheme of 168*0Sstevel@tonic-gate * FILEnnnn.CHK. 169*0Sstevel@tonic-gate */ 170*0Sstevel@tonic-gate #define MAXCHKVAL 9999 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate /* 173*0Sstevel@tonic-gate * Function prototypes 174*0Sstevel@tonic-gate */ 175*0Sstevel@tonic-gate extern struct pcdir *addRootDirEnt(int fd, struct pcdir *copyme); 176*0Sstevel@tonic-gate extern struct pcdir *newDirEnt(struct pcdir *copyme); 177*0Sstevel@tonic-gate extern int32_t extractStartCluster(struct pcdir *dp); 178*0Sstevel@tonic-gate extern int32_t findImpactedCluster(struct pcdir *modified); 179*0Sstevel@tonic-gate extern int32_t readFATEntry(int32_t currentCluster); 180*0Sstevel@tonic-gate extern uint32_t extractSize(struct pcdir *dp); 181*0Sstevel@tonic-gate extern int32_t nextInChain(int32_t currentCluster); 182*0Sstevel@tonic-gate extern char *nextAvailableCHKName(int *chosen); 183*0Sstevel@tonic-gate extern void truncChainWithBadCluster(int fd, struct pcdir *dp, 184*0Sstevel@tonic-gate int32_t startCluster); 185*0Sstevel@tonic-gate extern void mountSanityCheckFails(void); 186*0Sstevel@tonic-gate extern void markClusterModified(int32_t clusterNum); 187*0Sstevel@tonic-gate extern void scanAndFixMetadata(int fd); 188*0Sstevel@tonic-gate extern void updateDirEnt_Start(struct pcdir *dp, int32_t newStart); 189*0Sstevel@tonic-gate extern void addEntryToCHKList(int chkNumber); 190*0Sstevel@tonic-gate extern void createCHKNameList(int fd); 191*0Sstevel@tonic-gate extern void updateDirEnt_Name(struct pcdir *dp, char *newName); 192*0Sstevel@tonic-gate extern void updateDirEnt_Size(struct pcdir *dp, uint32_t newSize); 193*0Sstevel@tonic-gate extern void getRootDirectory(int fd); 194*0Sstevel@tonic-gate extern void writeClusterMods(int fd); 195*0Sstevel@tonic-gate extern void writeRootDirMods(int fd); 196*0Sstevel@tonic-gate extern void traverseFromRoot(int fd, int depth, int descend, int operation, 197*0Sstevel@tonic-gate char matchRequired, struct pcdir **found, int32_t *lastDirCluster, 198*0Sstevel@tonic-gate struct pcdir **dirEnd, char *recordPath, int *pathLen); 199*0Sstevel@tonic-gate extern void findBadClusters(int fd); 200*0Sstevel@tonic-gate extern void markFreeInFAT(int32_t clusterNum); 201*0Sstevel@tonic-gate extern void markLastInFAT(int32_t clusterNum); 202*0Sstevel@tonic-gate extern void writeFATEntry(int32_t currentCluster, int32_t value); 203*0Sstevel@tonic-gate extern void markBadInFAT(int32_t clusterNum); 204*0Sstevel@tonic-gate extern void printSummary(FILE *outDest); 205*0Sstevel@tonic-gate extern void squirrelPath(struct nameinfo *pathInfo, int32_t clusterNum); 206*0Sstevel@tonic-gate extern void usingCHKName(void *nameCookie); 207*0Sstevel@tonic-gate extern void writeFATMods(int fd); 208*0Sstevel@tonic-gate extern void traverseDir(int fd, int32_t startAt, int depth, int descend, 209*0Sstevel@tonic-gate int operation, char matchRequired, struct pcdir **found, 210*0Sstevel@tonic-gate int32_t *lastDirCluster, struct pcdir **dirEnd, char *recordPath, 211*0Sstevel@tonic-gate int *pathLen); 212*0Sstevel@tonic-gate extern void splitChain(int fd, struct pcdir *dp, int32_t problemCluster, 213*0Sstevel@tonic-gate struct pcdir **newdp, int32_t *orphanStart); 214*0Sstevel@tonic-gate extern void preenBail(char *outString); 215*0Sstevel@tonic-gate extern void readBPB(int fd); 216*0Sstevel@tonic-gate extern void getFAT(int fd); 217*0Sstevel@tonic-gate extern int checkFAT32CleanBit(int fd); 218*0Sstevel@tonic-gate extern int reservedInFAT(int32_t clusterNum); 219*0Sstevel@tonic-gate extern int isMarkedBad(int32_t clusterNum); 220*0Sstevel@tonic-gate extern int readCluster(int fd, int32_t clusterNum, uchar_t **data, 221*0Sstevel@tonic-gate int32_t *datasize, int shouldCache); 222*0Sstevel@tonic-gate extern int freeInFAT(int32_t clusterNum); 223*0Sstevel@tonic-gate extern int lastInFAT(int32_t clusterNum); 224*0Sstevel@tonic-gate extern int markInUse(int fd, int32_t clusterNum, struct pcdir *referencer, 225*0Sstevel@tonic-gate struct pcdir *longRef, int32_t longStartCluster, int isHidden, 226*0Sstevel@tonic-gate ClusterInfo **template); 227*0Sstevel@tonic-gate extern int badInFAT(int32_t clusterNum); 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate #ifdef __cplusplus 230*0Sstevel@tonic-gate } 231*0Sstevel@tonic-gate #endif 232*0Sstevel@tonic-gate 233*0Sstevel@tonic-gate #endif /* _FSCK_PCFS_H */ 234