/* * Main driver program for EXT2 Filesystem Analysis. * Written by Michael Rywalt - 2569 * Operating System Concepts */ #include "../Common/file.h" int main(int argc, char **argv) { void *pFileSystem; tsSuperBlock *pSuperBlock; tsInode *pInode; tsDirEntry *pDirEntry; int iBlockSize; printf("\n************** EXT2 Root Print by MGR **************\n"); if(argc > 1) { /* Allocate the filesystem into memory. */ pFileSystem = LoadFileSystem(argv[1]); pSuperBlock = (tsSuperBlock*)((char*)pFileSystem + SUPERBLOCK_OFFSET); /* Make sure the file has actually been loaded. */ if(pFileSystem == NULL) { printf("Error: Filesystem not found, or too small.\n"); return EXIT_FAILURE; } /* Verify that we're looking at a real EXT2 filesystem. */ if(!VerifyFSMagicNumber(pSuperBlock)) { FreeFileSystem(pFileSystem); printf("Hmm... Doesn't appear to be an EXT2 filesystem. Corrupted maybe?\n"); return EXIT_FAILURE; } /* Get the block size for this file system. */ iBlockSize = GetFSBlockSize(pSuperBlock); printf("FS Type: EXT2\nBlock Size = %d\n", iBlockSize); /* Get root directory inode table. The first inode is 0, the second is 1 (in my case, I start at 0). */ pInode = GetInode(1, pFileSystem); /* Print the directory entries out to the screen along with file types. */ PrintDirectoryListing(pInode, pFileSystem); /* We're done, so free up the memory we've used. */ FreeFileSystem((void*)pFileSystem); } else { printf("Usage: %s \n", argv[0]); } return EXIT_SUCCESS; }