Betrifft Win32 API und NT Native API
Download unter:
assarbad.net/stuff/!export/hardlink.ace
assarbad.net/stuff/!export/hardlink.rar
assarbad.net/stuff/!export/hardlink.zip
Der Code ist wahlweise unter
BSDL oder
LGPL zu benutzen!
LGPL wurde nur als Option angegeben um die Benutzung in unserem DP-Projekt
DoubleKiller zu ermöglichen
Hiho,
ich habe die CreateHardLink API, welche mit Windows 2000 offiziell eingeführt wurde, komplett nachempfunden (in Delphi).
Will heißen, auch wenn der Code nicht identisch ist, macht er dennoch das Gleiche (wenn auch nicht das Selbe). Wohlgemerkt alle Fehlerrückgaben, die bei der orginalen Windows 2000 API zurückgegeben werden, sind identisch. Auch die Annahme von Parametern und Verarbeitung entspricht dem Original. Bei einigen Punkten habe ich einfach eine Native API genommen statt "per Hand" zu kopieren.
Es gelten die gleichen Einschränkungen und Features von CreateHardLinkW() in der Kernel32.dll in Windows 2000 wie CreateHardLinkW() in meiner Unit.
Einzig ein Kompilerschalter definiert ob die Funktion mit oder ohne STDCALL läuft. Standard ist ohne ... ich gehe davon aus, daß meine Funktionen nur unter Delphi und BCB benutzt werden.
Es werden keine Backup/Restore-Privilegien benötigt, wie bei der Methode mit den Backup-Streams ... daher komplett kompatibel mit der in Windows 2000 eingeführten gleichnamigen Funktion.
Außerdem ist die Funktion komplett kompatibel mit NT4 aufwärts (und NTFS). Ich habe eine ANSI und eine Unicode-Version implementiert. Würde man eine EXPORT-Klausel einfügen, könnte man die DLL auf jedem der aktuellen NT-Systeme (NT4/2K/XP/2K3) benutzen. Informationen zu Hardlinks gibts hier (von MS selbst im PSDK formuliert):
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
| Any directory entry for a file, whether created with CreateFile or CreateHardLink, is a hard link to the associated file. Additional hard links, created with the CreateHardLink function, allow you to have multiple directory entries for a file, that is, multiple hard links to the same file. These may be different names in the same directory, or they may be the same (or different) names in different directories. However, all hard links to a file must be on the same volume. Because hard links are just directory entries for a file, whenever an application modifies a file through any hard link, all applications using any other hard link to the file see the changes. Also, all of the directory entries are updated if the file changes. For example, if the file's size changes, all of the hard links to the file will show the new size. The security descriptor belongs to the file to which the hard link points. The link itself, being merely a directory entry, has no security descriptor. Thus, if you change the security descriptor of any hard link, you're actually changing the underlying file's security descriptor. All hard links that point to the file will thus allow the newly specified access. There is no way to give a file different security descriptors on a per-hard-link basis. This function does not modify the security descriptor of the file to be linked to, even if security descriptor information is passed in the lpSecurityAttributes parameter. Use DeleteFile to delete hard links. You can delete them in any order regardless of the order in which they were created. Flags, attributes, access, and sharing as specified in CreateFile operate on a per-file basis. That is, if you open a file with no sharing allowed, another application cannot share the file by creating a new hard link to the file.
CreateHardLink does not work over the network redirector.
Note that when you create a hard link on NTFS, the file attribute information in the directory entry is refreshed only when the file is opened or when GetFileInformationByHandle is called with the handle of the file of interest. |