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