Explanation of Inodes / path

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Explanation of Inodes / path
# 1  
Old 06-21-2018
Explanation of Inodes / path

Hello,
I have the solution for this but unfortunately the tutor was too fast to understand the steps.

To get the the block 407, 635 and 321. The inode number would be 9, 34 and 6

Now my question is how I get to the file "testfile"?

tutor solution was : root/tmp/ida/testfile

I dont understand the steps how it comes to this solution.

http://i.epvpimg.com/fG9ieab.png
# 2  
Old 06-21-2018
If you look at testfile in block 635, the inode number of its directory (.) is 34, which is is ida's directory (see block 407). The directory "ida" is in the directory with inode number 9 (again look at the entry with the dot), which is the directory "tmp"..
# 3  
Old 06-21-2018
Your tutor is correct (mostly).

In Unix filesystems all data files are made up of allocated blocks of disk but also all directories are also 'files'.

If the operating system needs to read the file:

Code:
/tmp/ida/testfile

it would go to inode 1 (well actually inode 2 on most operating systems because inode 1 is the bad block table), look up which block the root directory index is located on, and go to that block and look for 'tmp's inode number. It now knows that the 'tmp' directory inode is 9.

It goes to inode 9 and reads that the 'tmp' directory index starts at block 407. It goes to block 407, reads the index looking for 'ida' and then knows that 'ida's inode number is 34.

It goes to inode 34 and reads that the 'ida' directory index starts at block 635. It goes to block 635, reads the index looking for 'testfile' and then knows that 'testfile's inode number is 76.

It goes to inode 76 and reads the starting block number for testfile and it can now go to that block and start reading testfile's actual data content.

Additionally, if the O/S wanted to read /home then in the root directory index it would find that /home inode number is 6. Going to inode 6 is would read that /home directory index starts at block 321.

See your updated graphic attached.

Hope that helps. If you still don't get it, post back your questions.
Explanation of Inodes / path-filesystem-001jpg

Last edited by hicksd8; 06-21-2018 at 01:17 PM..
# 4  
Old 06-21-2018
Hey thanks for the replys so far.

I think I understood a part of the explanation.



Absolute path for otto 53 would be:

Code:
root/home/otto

The reason for this is that the block 321 starts at inode 6 which we also have listed in our root directory. so there is no long way.

Same goes for oswald inode 19:

Code:
root/tmp/oswald

If this is correct so far then the edited screenshot with description helped me so much too understand it.

The last question would be just how do I do it with a relative path?
I know that the absolute path starts from the root and the relative path to the current working directory. But how I find the current working directory? Should I just pick one of those blocks?

Code:
../tmp/ida/testfile

might be this correct?
# 5  
Old 06-22-2018
You can search for files or directories using /usr/bin/find command
Sample:
Code:
$ /usr/bin/find -maxdepth 1 -inum 4222124650820299
.
$ /usr/bin/find -maxdepth 1 -inum 4222124650820299 -exec /bin/ls -lid {} \;
4222124650820299 drwx------+ 1 murugesandins TES 0 Jun 21 09:06 .
$ /bin/ls -lid .
4222124650820299 drwx------+ 1 murugesandins TES 0 Jun 21 09:06 .
$ # Commented line
$ # Following command used to take more time and errors are redirected to /dev/null
$ /usr/bin/find -inum 4222124650820299 -exec /bin/ls -lid {} \; 2>/dev/null
4222124650820299 drwx------+ 1 murugesandins TES 0 Jun 21 09:06 .
$ cd /root/tmp
$ /usr/bin/find ./ -type f -inum 2814749767312557 -exec /bin/ls -lid {} \;
2814749767312557 -rw-r--r--+ 1 murugesandins TES 0 Jun 22 16:11 ./ida/testfile

# 6  
Old 06-22-2018
When you want to walk an absolute pathname starting from the process' root directory, a C program can use rootdir = opendir("/"); to open a directory stream to read the root directory and it can use currentdir = opendir("."); to open a directory stream to read the current working directory.

If you want the pathname of the current working directory in a process, a C program can use the getcwd() function to get an absolute pathname of the current working directory:
Code:
#include <unistd.h>
#include <limits.h>
#include <stdio.h>

char buf[PATHMAX];
char *p;

int
main() {
	p = getcwd(buf, PATHMAX);
	if(p != NULL) {
		printf("The current working directory is \"%s\".", buf);
	} else {
		perror("getcwd() failed:");
	}
}

# 7  
Old 06-22-2018
Code:
// Written comment for new employees/joinees  and for me too :) => Better initialize
#include <string.h>    // strerror
#include <sys/errno.h> // errno
#include <unistd.h>    // getcwd
#include <stdio.h>     // printf
// PATH_LENGTH variaes on OS
// Change PATH_LENGTH based on macro, OS and requirement
// Example: What is the longest file path that Windows can handle? - Super User
// Written CYGWIN_NT since .exe can run outside bash.exe or sh.exe or mksh.exe or ...
// => gecwd error => Numerical result out of range
// getcwd will fail when length varies above expected lenth at windows
#ifdef CYGWIN_NT
        #define PATH_LENGTH 195
#else
        #define PATH_LENGTH 256
#endif
char cwd[PATH_LENGTH] = {};
char *PWD = NULL;
int main()
{
        PWD = getcwd(cwd, PATH_LENGTH);
        // value != variable to remove initialization by typewriting mistakes
        // Example: if( p = NULL )
        if( NULL != PWD )
        {
                printf("The current working directory is \"%s\"\n", cwd);
        }
        else
        {
                printf( "getcwd() failed.\n%s\n", strerror(errno));
                return 1;
        }
        return 0;
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help with Inodes please

How can i trace Inode structure and modify it in UNIX kernel? We want to change the inode structure in the sense that we want to add a new field to the inode data structure. So we want to know how and where to trace inode (7 Replies)
Discussion started by: Group_Inode
7 Replies

2. Solaris

/var: out of inodes

Dear Forum, Please help me i have SUNW,Sun-Fire-V240 with sun solaris 8,if i check inode in /var like below: # df -F ufs -o i Filesystem iused ifree %iused Mounted on /dev/md/dsk/d0 62354 310638 17% / /dev/md/dsk/d3 372992 0 100% /var... (2 Replies)
Discussion started by: fredginting
2 Replies

3. Filesystems, Disks and Memory

inodes

Hi, sorry to have written in other language i think i could do that. I would to know A file system use inodes indexed allocation as a method of allocating space. In the inode blocks are 10 references to direct, 1 indirect reference to a single block, 1 block indirect reference to a reference to... (1 Reply)
Discussion started by: maryprin
1 Replies

4. Solaris

Increasing inodes

Hi , Can someone help me to increase "inode" in solaris 9? Thanks in advance, Gowtham (8 Replies)
Discussion started by: gowthamakanthan
8 Replies

5. Solaris

Number of used inodes..?

Hello Experts How can i know Number of used and free inodes in a file system? thanx in advance.. (3 Replies)
Discussion started by: younus_syed
3 Replies

6. Linux

Inodes

Any good sites, tutorials that explain Inodes clearly and completely ? (3 Replies)
Discussion started by: nitin09
3 Replies

7. UNIX for Dummies Questions & Answers

inodes

how is the location of inodes in the physical disk. are they sequential like: bootblock|superblock|inode1|inode2| ....| datablock1|datablock2|datablock3 or are they distributed among data blocks like: bootblock|superblock|inode1|datablock1|inode2|datablock2|datablock3|inode3 |datablock4 (3 Replies)
Discussion started by: gfhgfnhhn
3 Replies

8. Solaris

inodes

hi i need to find all the files that r linked to the current file as i need to delete the file as well as few of its links :confused: thnx in advance (1 Reply)
Discussion started by: livemyway
1 Replies

9. Solaris

inodes???

Does anyone know what command I can run to check how many inodes are in use on a specific filesystem. On Data General servers I used to run the df -k command to check the status of the inodes for all file system.s (1 Reply)
Discussion started by: soliberus
1 Replies

10. Filesystems, Disks and Memory

INodes...

Could someone please explain to me the concept of INodes? Colour me a DOS/MacOS junkie, but I don't quite understand. Is there any relation to clusters, or physical distro.? ty. (3 Replies)
Discussion started by: boris888
3 Replies
Login or Register to Ask a Question