#ifndef DK4FILEIT_H_INCLUDED /** Protection against multiple inclusions. */ #define DK4FILEIT_H_INCLUDED 1 /** @file dk4fileit.h File information data type. The dk4_file_info_t data type and related functions allow to properly identify a path name as symbolic link on both non-Windows and Windows systems. On non-Windows systems calls to stat() and lstat() are used to retrieve the information. On Windows systems calls to GetFileAttributes(), CreateFile()/GetFileInformationByHandle() and FindFirstFile() are used. As the involved data types are Windows-specific the windows.h header file is pulled in by this header. The Windows functions to retrieve information about files differ: - GetFileAttributes() returns a DWORD containing bits for file attributes only. - From CreateFile()/GetFileInformationByHandle() we can receive very detailed information. - From FindFirstFile() we can retrieve some of the information also provided by CreateFile()/GetFileInformationByHandle(), but number of links, volume serial number, and file index are not available. Unfortunately the functions behave differently: While FindFirstFile() succeeds for c:/pagefile.sys and other files in the root directory, GetFileAttributes() and CreateFile()/GetFileInformationByHandle() fail in non-privileged processes. Some forum messages state that FindFirstFile() is significantly faster than CreateFile()/GetFileInformationByHandle(), at least for files on servers. When called for a symbolic link, FindFirstFile() always returns information about the link. For CreateFile()/GetFileInformationByHandle() one can choose whether to obtain information about the or about the target. So the dk4fileinfo() function attempts GetFileAttributes() and CreateFile()/GetFileInformationByHandle() first to obtain detailed information. If these functions fail, the FindFirstFile() function is used. If only FindFirstFile() returned successfully, the resio component is set to a non-zero value to indicate that only restricted information (without number of links, volume serial number, and file index) is available. */ #include "dk4conf.h" #if DK4_ON_WINDOWS #ifndef WINDOWS_H_INCLUDED #include #define WINDOWS_H_INCLUDED 1 #endif #endif #include "dk4statt.h" /** File information contents found. */ enum { /** Information about the link from lstat(). */ DK4_FILE_INFO_CONTENTS_DATA_LINK = 1, /** Information about the link target from stat(). */ DK4_FILE_INFO_CONTENTS_DATA_TARGET = 2 }; /** Choose timestamp to convert to text. */ enum { /** Creation time. */ DK4_FILE_INFO_TIME_CREATE = 1, /** Modification time. */ DK4_FILE_INFO_TIME_MODIFY , /** Last access time. */ DK4_FILE_INFO_TIME_ACCESS }; /** File information data type. */ typedef struct { int contents; /**< The available contents. */ #if DK4_ON_WINDOWS BY_HANDLE_FILE_INFORMATION linfo; /**< Information about link. */ BY_HANDLE_FILE_INFORMATION tinfo; /**< Information about target. */ DWORD fattr; /**< Link file attributes. */ DWORD rppnt; /**< Link reparse point tag. */ DWORD resio; /**< Flag: Restricted information. */ #else dk4_stat_t lstb; /**< Buffer for lstat(). */ dk4_stat_t tstb; /**< Buffer for stat(). */ #endif } dk4_file_info_t; #endif