I had an interview, where the interviewer asked what operations raise the link count of a file, besides ln and its underlying syscall, I didn't know. He stated that opening a file will increase the link count by one to prevent deletion of an opened file. I did not agree that he is correct, why would vi need the temp .swp files then? Is he correct? What operations can raise a file's link count other than ln?
Asked
Active
Viewed 1,680 times
1 Answers
0
He's wrong.
The only thing that increases a file's link count is the link
system call.
(Or editing the raw file system with a hex editor.)

Scott - Слава Україні
- 10,519
vi
reads the file but doesn't keep it open. It's also trivial to show that the link count isn't increased when editing it... The interviewer is clearly confused. – wurtel Mar 11 '15 at 10:58vi
doesn't edit files in place, but modifies them only when you tell it to save (write). Yeah, the interviewer seems to have link count confused with in-memory inode reference count. – Scott - Слава Україні Mar 11 '15 at 17:13