10 BY_HANDLE_FILE_INFORMATION bhi;
118 #ifndef FILE_SUPPORTS_HARD_LINKS 119 #define FILE_SUPPORTS_HARD_LINKS 0x00400000 124 HANDLE hToken, hTarget;
125 TOKEN_PRIVILEGES tp = { 1, { 0,0,0 }};
126 DWORD error = 0, volFlg;
127 BOOL ok =
false, prvOk;
131 error = ERROR_FILE_EXISTS;
134 #if 1 // N.B: Flag declared in XP (but not implemented before Win7 ?). 139 error = ERROR_CALL_NOT_IMPLEMENTED;
153 OPEN_EXISTING, 0, NULL
160 TCHAR szLinkName[ MAX_PATH ];
161 DWORD ccLinkName = GetFullPathName( LinkName, MAX_PATH, szLinkName, NULL );
170 if (LinkVol != TargetVol)
172 error = ERROR_NOT_SAME_DEVICE;
177 #define wzLinkName szLinkName 179 WCHAR wzLinkName[ MAX_PATH ];
181 MultiByteToWideChar( CP_ACP, 0, szLinkName,-1, wzLinkName, MAX_PATH );
183 DWORD cbLinkName = (ccLinkName+1) *
sizeof(WCHAR);
184 PVOID pBkupCtx = NULL;
189 ZeroMemory( &sid,
sizeof(WIN32_STREAM_ID) );
190 sid.dwStreamId = BACKUP_LINK;
191 sid.Size.u.LowPart = cbLinkName;
193 DWORD cbWr, cbStreamHdr = FIELD_OFFSET( WIN32_STREAM_ID, cStreamName );
195 ok = BackupWrite( hTarget,
196 (
PBYTE)&sid, cbStreamHdr, &cbWr,
false,
false,
207 ok = BackupWrite( hTarget,
208 (
PBYTE)wzLinkName, cbLinkName, &cbWr,
false,
false,
211 if (!ok) error = GetLastError();
215 BOOL bkOk = BackupWrite( hTarget, NULL, 0, &cbWr,
true,
false, &pBkupCtx );
217 if (ok && !bkOk) { ok = bkOk; error = GetLastError(); }
221 CloseHandle( hTarget );
224 if (hToken) CloseHandle( hToken );
227 if (!ok && error) SetLastError( error );
232 #if (WINVER >= 0x0600) // FindFirstFileNameW requires Vista. 245 WSTR pwzLink = wzLink;
249 #define wzFile FileName 250 #else // We need two char conversion buffers, since the APIs are W only. 259 wcsncpyz( wzLink, wzFile, ccDrv+1 );
261 else if (GetFullPathNameW( wzFile, MAX_PATH, wzLink, NULL ))
263 wzLink[0] = towupper( wzLink[0] );
264 pwzSep = wcschr( wzLink,
COLON );
271 DWORD ccLink = MAX_PATH - ccDrv;
272 HANDLE hFind =
CheckHandle( FindFirstFileNameW( wzFile, 0, &ccLink, pwzLink ));
277 bool proceed = Action( wzLink, usrData );
279 WideCharToMultiByte( CP_ACP, 0, wzLink, -1, pzLink, MAX_PATH, NULL, NULL );
280 bool proceed = Action( pzLink, usrData );
282 ccLink = MAX_PATH - ccDrv;
283 if (!proceed || !FindNextFileNameW( hFind, &ccLink, pwzLink ))
295 #endif//(WINVER >= 0x0600)
bool(__stdcall * PFnEnumHardLinks)(CSTR PathName, PVOID usrData)
HANDLE CheckHandle(HANDLE Hnd)
bool FileExist(CSTR PathName)
#define FILE_WRITE_ATTRIB_EA
bool _CreateHardLink(CSTR LinkName, CSTR TargetName)
wchar_t *__fastcall wcsncpyz(register wchar_t *Dst, register const wchar_t *Src, size_t Count)
WSTR mem_WDupAStr(ACSTR AStr, UINT CodePg=CP_ACP, UINT ccExtra=0)
HANDLE FindCloseEx(HANDLE hFind)
bool GetFileInformationByName(CSTR FileName, LPBY_HANDLE_FILE_INFORMATION pInfo)
DWORD __GetHandleVolumeId(HANDLE hObj)
DWORD __GetVolumeFlags(CSTR PathName)
ASTR mem_AllocAStr(WORD nChar)
BOOL(WINAPI *SysImgList::Shell_GetImageLists)(HIMAGELIST *pimlLarge
#define FILE_SUPPORTS_HARD_LINKS
void * mem_Free(void *pBlk)
WSTR mem_AllocWStr(WORD nChar)
bool RestorePrivilege(HANDLE hToken, PTOKEN_PRIVILEGES pSaved)
See EnablePrivilege(()
bool __forceinline bool_cast(BOOL B52)
#define BITS_SET(bits, x)
__inline bool __ChkOkGetErr(BOOL Ok, PDWORD pErr)
INT_PTR CharIndex(const chrType *Buffer, const chrType *Inside)
UINT GetHardLinkCount(CSTR FileName)
bool __EnableProcPrivilege(IN CSTR Privilege, OUT LUID_AND_ATTRIBUTES *pPrv, OUT HANDLE *pToken)
DWORD __GetVolumeId(CSTR PathName)
UINT EnumerateHardLinks(CSTR FileName, PFnEnumHardLinks Action, PVOID usrData)