3

We need to implement a method that accepts a path prefix, and an inode number. The method needs to return the name of the file that has the inode value, or return null if such a file does not exist.

String getFilePathByInode(String pathPrefix, long inode)

One naive way that I can think of is to walk through the files under the directory and examine the inode info of each file. Is there a better way to do this? Thanks!

yuyang
  • 1,511
  • 2
  • 15
  • 40

1 Answers1

1

This is a non-trivial task, even in C, since an inode can appear in multiple places in the filesystem due to hard links. You would, therefore, need to traverse the entire filesystem. This premise of the question, therefore, is a bad idea to begin with.

200_success
  • 7,286
  • 1
  • 43
  • 74
  • we only need to check if there is a file under a given path that matches the inode info. – yuyang Sep 10 '15 at 06:38
  • 1
    That doesn't reduce the complexity of the problem. Path→inode is a simple lookup. However, filesystems are just not designed to support inode→path lookups. – 200_success Sep 10 '15 at 06:40