Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <sys/stat.h>
- #include <dirent.h>
- #include <stdint.h>
- void searchDir(char *dirname, int stepsIn);
- int filesAllocatedSpace(int size, int blockSize);
- long long int allocatedSpace = 0;
- long long int usedSpace = 0;
- int main() {
- printf("file i-node example\n"); // CHANGE THIS STUFF
- char *directoryLocation;
- directoryLocation = (char*)malloc(256*sizeof(directoryLocation));
- strcpy(directoryLocation, "./");
- searchDir(directoryLocation, 0);
- return 1;
- }
- int filesAllocatedSpace(int size, int blockSize) {
- int SpaceAlocated = 0;
- do {
- SpaceAlocated += blockSize
- } while (size > SpaceAlocated)
- return SpaceAlocated;
- }
- void searchDir(char *dirname,int stepsIn)
- {
- DIR *currentDirectory;
- struct dirent *fileEntry;
- char *locationToPassIn, *directoryLocation;
- locationToPassIn = (char*)malloc(256*sizeof(locationToPassIn));
- directoryLocation = (char*)malloc(256*sizeof(directoryLocation));
- struct stat fileStats;
- strcpy(directoryLocation, dirname);
- currentDirectory = opendir(directoryLocation);
- if (currentDirectory != NULL)
- {
- while ((fileEntry = readdir(currentDirectory)) != NULL)
- {
- if((strncmp(fileEntry->d_name, "..", 2) != 0) && (strncmp(fileEntry->d_name, ".", 1) != 0))
- {
- strcpy(locationToPassIn, fileEntry->d_name);
- stat(locationToPassIn, &fileStats);
- switch(IS_REG(fileStats.)
- {
- case DT_REG: // FILE
- allocatedSpace += fileAllocatedSpace(fileStats.st_size,SUPERBLOCK.block_size);
- usedSpace += fileStats.st_size;
- printf("<file name>: %s <inode>: %ld <size>: %ld and <unused space>: %ld\n", fileEntry->d_name,fileEntry->d_ino, fileStats.st_size, ((fileStats.st_blksize*fileStats.st_blocks) - fileStats.st_size));
- break;
- case DT_DIR: // DIRECTORY
- allocatedSpace += fileAllocatedSpace(fileStats.st_size,SUPERBLOCK.block_size);
- usedSpace += fileStats.st_size;
- printf("<Folder name>: %s <inode>: %ld <size>: %ld and <unused space>: %ld\n", fileEntry->d_name,fileEntry->d_ino, fileStats.st_size,((fileStats.st_blksize*fileStats.st_blocks) - fileStats.st_size));
- strcpy(directoryLocation,dirname);
- strcat(directoryLocation, "/");
- strcat(directoryLocation,fileEntry->d_name);
- searchDir(directoryLocation, stepsIn+1);
- break;
- }
- }
- }
- }
- closedir(currentDirectory);
- return;
- }
Add Comment
Please, Sign In to add comment