From this answer, I see that something like:
bool
ref_same_file(int fd1, int fd2)
{
struct stat stat1, stat2;
if (!fstat(fd1, &stat1) && !fstat(fd1, &stat2))
return (stat1.st_dev == stat2.st_dev)
&& (stat1.st_ino == stat2.st_ino);
perror("fstat");
exit(errno);
}
could see if two file descriptors reference the same file. However, I am not totally clear on the st_dev
. Is this not the block device? Can a single block device not hold multiple file systems?
I see the POSIX spec states that it makes it uniquely identifiable, but I am wondering how this is possible.