/* * file.h - Header file for file analysis tools. * Author: Michael Rywalt * Operating System Concepts */ #ifndef _FILE_H_ #define _FILE_H_ /* Necessary includes. */ #include #include #include /* Useful definitions. */ #define BOOL int #define TRUE 1 #define FALSE 0 /* Create types associated with the ext2 filesystem. */ typedef struct ext2_super_block tsSuperBlock; typedef struct ext2_group_desc tsGroupDescriptor; typedef struct ext2_inode tsInode; typedef struct ext2_dir_entry_2 tsDirEntry; /* Functions prototypes and exports. */ /* Loads filesystem into memory. */ tsSuperBlock *LoadFileSystem(char *szFileName); /* Frees memory allocated from LoadFileSystem. */ void FreeFileSystem(tsSuperBlock *pFileSystem); /* Gets the filesystem block size. */ int GetFSBlockSize(const tsSuperBlock *pSuperBlock); /* Convert a block number into a block pointer. */ void *BlockNumToPointer(int iBlockNum, const void *pFileSystem); /* Find the start of the Inode table. */ tsInode *FindInodeTableStart(const void *pFileSystem); /* Gets the next Inode in the Inode table. */ tsInode *GetNextInode(const tsInode *pInode, void *pFileSystem); /* Gets an Inode by its number. */ tsInode *GetInode(int iInodeNum, void *pFileSystem); /* Verifies that this is an EXT2 filesystem. */ BOOL VerifyFSMagicNumber(tsSuperBlock *pSuperBlock); /* Gets the datablock for an Inode. */ void *GetDataBlock(const tsInode *pInode, const void *pFileSystem); /* Prints the directory listing. */ void PrintDirectoryListing(const tsInode *pInode, const void *pFileSystem); /* Print a file type from a directory listing. */ void PrintFileType(const tsDirEntry *pDirEntry); /* Gets the start of the group descriptors block. */ tsGroupDescriptor *FindGroupDescriptorStart(const void *pFileSystem); /* Gets an inode by directory entry name. */ tsInode *GetMatchingInode(char *szName, tsInode *pCurDirInode, void *pFileSystem); /* Creates a hard link to a in that directory. */ BOOL InsertHardLink(char *szFileSysName, char *szLinkName, tsInode *pInode, void *pFileSystem); /* Saves the filesystem allocated by LoadFileSystem back to disk. */ BOOL SaveModifiedFileSystemData(char *szFileName, void *pData, int iLengthToWrite); /* Returns the size of a file. */ int GetFileSize(char *szFileName); #endif /* _FILE_H_ */