How can I access the inode file on Linux

Is there any user API or third-party kernel module that can help access the inode file on Linux?

I am trying to implement something like:

int read_file_by_ino(int ino, int pos, int size, char* buf); int write_file_by_ino(int ino, int pos, int size, const char* buf); int readdir_by_ino(...); int stat_by_ino(...); ... 

It is assumed that the program will run as root, so it is not required to verify access rights.

+4
source share
3 answers

I found a question related to a similar topic here .

To summarize, check these commands:

  • find /path/to/mountpoint -inum <inode number>
  • sudo debugfs -R 'ncheck 393094' /dev/sdaX 2>/dev/null

Hope this helps you explore further.

+2
source

Not sure if I understood your problem correctly, but:
You can start with the "/" directory and continue recursively (or any cycle, for that matter) with the children. Compare the inode value with strcut stat.ino_t . Once you find it, open the path / file.

+1
source

I don't know if there is an easier way or not, but you can do it with bash. with ls -i you can also see inodes,

 $ ls -i 11147622 file.txt 

the first column is the index number, the hit command shows the inodes in the current directory

 $ ls -i | awk {'print $1'} 

so you need to check inodes from / all its subdirectories until you find it

 ls -iR / 

it shows all subdirectories and there are files with inode number

now you must start with / and use the awk or cut command to have the first column (the inode number is in the first column) and then compare it with the inode you want to find.

0
source

Source: https://habr.com/ru/post/1245347/


All Articles