I'm not quite sure what you are looking for. However, maybe this will help:
I created an NTFS symbolic file link with (data.raw is just a normal file):
mklink c:\idelme\data2.raw c:\idelme\data.raw
From there, I was able to see that it was a symbolic link with:
#include <windows.h>
#include <stdio.h>
void TestMe(const char *name)
{
printf("name: %s\n", name);
DWORD d = GetFileAttributes(name);
printf("%x %d\n", d, d & FILE_ATTRIBUTE_REPARSE_POINT);
WIN32_FIND_DATA ffd;
HANDLE h = FindFirstFile(name, &ffd);
printf("%x\n\n", ffd.dwReserved0);
CloseHandle(h);
}
int main()
{
TestMe("C:\\idelme\\data.raw");
TestMe("C:\\idelme\\data2.raw");
}
Data.raw does not have the FILE_ATTRIBUTE_REPARSE_POINT attribute set.
Similarly, ffd.dwReserved0 is 0.
Data2.raw DOES have the FILE_ATTRIBUTE_REPARSE_POINT attribute. And
ffd.dwReserved0 shows IO_REPARSE_TAG_SYMLINK.
FWIW.
dw
On 1/14/2015 9:33 AM, Greg Jung wrote:
Hi Folks,
I've been trying to program a recognition of NTFS symbolic link
files; What I;ve gleaned
from MSDN procedures don't seem to work. Below are coded three methods
1) (untested) open file and call GetFileInformationByHandleEx. I
can't get winbase.h header definitions recognized
2) GetFileAttributes() works ok for Junctions doesn't recognize
symlink files
3) FindFirstEx . same result as 2)
There must be a way, since cygwin 'ls -a' and msys2 'ls -a' commands
will show links.
in the calling routine, I modify result of stat() with system calls:
#ifdef _WIN32
int addlink = 0;
fstat_win32(filename.c_str(), addlink);
int actStat = stat(filename.c_str(), &statStruct);
if( addlink != 0) cout << " addlink came back " << endl;
statStruct.st_mode |= addlink;
#else
int actStat = lstat( testDir.c_str(), &statStruct);
#endif
where fstat_win32 now has a graveyard full of attempts: ( When a
directory link is encountered, however, the test succeeeds.)
void fstat_win32(const string& filepath, int& st_mode)
{
DWORD dwattrib, reparsetag;
DString st;
st=filepath;
#if 1
//
// This method has not been tested: it will not compile -
GetFileInformationByHandleEx
// does not get through from the winbase.h header
//
HANDLEhFile;
BOOL success;
DWORD fattrib[2];
hFile = CreateFile( (TCHAR *)st.c_str(),
FILE_GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
FILE_FLAG_OPEN_REPARSE_POINT,
0);
if (hFile == INVALID_HANDLE_VALUE) {
CloseHandle(hFile);
cout << " stat_win32: could not open " + st << endl;
return;
}
else {
success = GetFileInformationByHandleEx(hFile,
FileAttributeTagInfo,
&fattrib,
sizeof(fattrib));
dwattrib = fattrib[0];
reparsetag = fattrib[1];
}
CloseHandle(hFile);
// dwattrib = GetFileAttributes( (TCHAR *)st.c_str()); // This
doesn't work to find symlinks
if( (dwattrib & FILE_ATTRIBUTE_REPARSE_POINT) != 0 ) {
st_mode |= S_IFLNK;
cout << " fstat_win32: symbolic link detected and flagged!! "
<< filepath ;
}
else st_mode=0;
#elif 0
DWORD dwlen;
HANDLEhFind;
BOOLfoundnext;
WIN32_FIND_DATA FindFileData;
// This doesn't work to find symlinks
hFind = FindFirstFileEx( (TCHAR *) st.c_str(),
FindExInfoStandard,
&FindFileData,
FindExSearchNameMatch, NULL, 0);
if (hFind == INVALID_HANDLE_VALUE)
return;
dwattrib = FindFileData.dwFileAttributes;
if( (dwattrib & FILE_ATTRIBUTE_REPARSE_POINT) != 0 ) {
st_mode |= S_IFLNK;
cout << " fstat_win32: symbolic link detected and flagged!! "
<< filepath ;
dwattrib = FindFileData.dwReserved0;
// IO_REPARSE_TAG_SYMLINK _MOUNT_POINT etc.
}
FindClose(hFind);
#endif
return;
}
------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public