linux - Difference between a Hard Link and its Program in C -


i'm writing program similar disk usage utility on linux, , i'm having trouble when comes hard links.

i have program running, , determines whether program has hard links. use stat() on file determine this.

if (st.st_nlink > 1) 

when run this, both link , program linked return, disk usage utility report program , not hard link.

how tell difference between program , hard link(s) in linux using c?

first, why handle differently program , data files multiple hard links?

then, matters not name or number (notice hard links add name file), inode. "file" (i.e. inode) having more 1 hard links, names pointing same inode of equal rights (there no "main" name, names pointing same inode equivalent).

so after calling stat(2) syscall want use both st_dev , st_ino fields. uniquely identify file, inode.

hence, files st.st_nlink>1 you'll add (st_dev,st_ino) pair hashtable or set container.

in c++ use std::set<std::pair<dev_t,ino_t> > in c have make such container.

nb: file (e.g. inode) have 0 names (e.g. if unlink(2) syscall has been called after open(2)), how temporary files made.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -