The code I'm using works fine however when i get to my while loop to search the directory i cant seem to find the file based on its inode. I check to see what it is in terminal (ls -i) and then choose desired inode to pass as an argument to my program.
Ive narrowed down the issue down to the following two pieces of code but cant figure out where i messed up.
Code:
ino_t inodeNum = strtol(argv[1], &endPtr, 10);
Code:
//traverse directory looking for file with matching inode
while((dirStream = readdir(dirPtr)) != NULL && cont == 0)
{
printf(" Searching. \n");
if(dirStream->d_ino == inodeNum)
{
//copy the file name
strncpy(fileName, dirStream->d_name, fileBuff);
//close directory
closedir(dirPtr);
//exit loop
cont = 666;
}
if((dirStream = readdir(dirPtr)) == NULL)
{
printf(" Error finding file with matching inode.\n");
printf(" Failed to remove directory\n");
return 0;
}
}
there are thee items in the directory so when it searches it loops 3 times before displaying the error messages once NULL is reached.