1 /* Copyright 2017-present Facebook, Inc. 2 * Licensed under the Apache License, Version 2.0 */ 3 #pragma once 4 #include "watchman_system.h" 5 #include <sys/stat.h> 6 7 namespace watchman { 8 9 #ifdef _WIN32 10 using mode_t = int; 11 using dev_t = int; 12 using gid_t = int; 13 using uid_t = int; 14 using ino_t = unsigned int; 15 using nlink_t = unsigned int; 16 #endif 17 18 struct FileInformation { 19 // On POSIX systems, the complete mode information. 20 // On Windows, this is lossy wrt. symlink information, 21 // so it is preferable to use isSymlink() rather than 22 // S_ISLNK() on the mode value. 23 mode_t mode{0}; 24 off_t size{0}; 25 26 // On Windows systems, these fields are approximated 27 // from cheaply available information in a way that is 28 // consistent with msvcrt which is widely used by many 29 // native win32 applications (including python). 30 uid_t uid{0}; 31 gid_t gid{0}; 32 ino_t ino{0}; 33 dev_t dev{0}; 34 nlink_t nlink{0}; 35 36 #ifdef _WIN32 37 uint32_t fileAttributes{0}; 38 #endif 39 40 struct timespec atime { 41 0, 0 42 }; 43 struct timespec mtime { 44 0, 0 45 }; 46 struct timespec ctime { 47 0, 0 48 }; 49 50 // Returns true if this file information references 51 // a symlink, false otherwise. 52 bool isSymlink() const; 53 54 // Returns true if this file information references 55 // a directory, false otherwise. 56 bool isDir() const; 57 58 // Returns true if this file information references 59 // a regular file, false otherwise. 60 bool isFile() const; 61 62 #ifndef _WIN32 63 explicit FileInformation(const struct stat& st); 64 #else 65 // Partially initialize the common fields. 66 // There are a number of different forms of windows specific data 67 // types that hold the rest of the information and we don't want 68 // to pollute the headers with them, so those are populated 69 // externally by the APIs declared elsewhere in this header file. 70 explicit FileInformation(uint32_t dwFileAttributes); 71 #endif 72 FileInformation() = default; 73 }; 74 } 75