1

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?

Gregg
  • 13

1 Answers1

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.)

  • Indeed; it's easily demonstrated that it's easy to delete (remove from a directory) an open file. There is still a reference to the inode from the process holding the inode open, which prevents the file from being removed from the file system so that the data can still be accessed. Note however that 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:58
  • Thanks for your support, and for pointing out that vi 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