views:

111

answers:

2

I have a difference between files size and used disk space (total file size is even more than disk size). I suppose because there are many hard links exist (to WinSxS components) in Windows 7/Vista. But how can I programmatically distinguish hard links from real files in Windows 7?

+4  A: 

You can't, because all files are hard links. No. Really. A file is just a hard link to a data chunk -- a listing in a directory. (Perhaps you mean symlinks? You can distinguish those...)

Use the builtin methods Windows provides for calculating used space instead.

EDIT: Reference (emphasis mine)

The link itself is only a directory entry, and does not have a security descriptor. Therefore, when you change the security descriptor of a hard link, you a change the security descriptor of the underlying file, and all hard links that point to the file allow the newly specified access.

Billy ONeal
Thanks. But what are the "builtin methods for calculating used space"? Is it possible to get a real files (data chunks) size on disk?
SKINDER
+1  A: 

You can't distinguish hard links from "real files". The directory entry for a "real file" is just another hard link. Perhaps you meant a symbolic link.

POSIX has a stat function (called _stat in Windows) that can detect multiple links to the same file, which will have the same "inode" number.

dan04
Note that `_stat` and friends are MSVC specific ... I don't believe MinGW provides this facility. +1 to answer though.
Billy ONeal