15 #include <sys/mount.h>
28 #include <sys/types.h>
37 # define TC_TRACE_FILE_OPERATIONS
39 static void TraceFileOperation (
int fileHandle,
FilePath filePath,
bool write,
uint64 length,
int64 position = -1)
41 string path = filePath;
42 if (path.empty() || path.find (
"truecrypt_aux_mnt") != string::npos)
46 s << path <<
": " << (write ?
"W " :
"R ") << (position == -1 ? lseek (fileHandle, 0, SEEK_CUR) : position) <<
" (" << length <<
")";
102 #elif defined (TC_MACOSX)
107 #elif defined (TC_FREEBSD)
110 return (
uint32) sectorSize;
112 #elif defined (TC_SOLARIS)
113 struct dk_minfo mediaInfo;
115 return mediaInfo.dki_lbsize;
118 # error GetDeviceSectorSize()
130 TextReader tr (
"/sys/block/" +
string (
Path.ToHostDriveOfPartition().ToBaseName()) +
"/" +
string (
Path.ToBaseName()) +
"/start");
136 #elif defined (TC_MACOSX)
139 # define DKIOCGETBASE _IOR('d', 73, uint64)
145 #elif defined (TC_SOLARIS)
147 struct extpart_info partInfo;
152 throw NotImplemented (
SRC_POS);
162 if (
Path.IsBlockDevice() ||
Path.IsCharacterDevice())
169 return blockCount * blockSize;
177 off_t current = lseek (
FileHandle, 0, SEEK_CUR);
188 int sysFlags = O_LARGEFILE;
196 sysFlags |= O_CREAT | O_TRUNC | O_RDWR;
200 sysFlags |= O_CREAT | O_TRUNC | O_WRONLY;
204 sysFlags |= O_RDONLY;
208 sysFlags |= O_WRONLY;
219 if ((flags & File::PreserveTimestamps) && path.
IsFile())
221 struct stat statData;
227 FileHandle = open (
string (path).c_str(), sysFlags, S_IRUSR | S_IWUSR);
230 #if 0 // File locking is disabled to avoid remote filesystem locking issues
234 memset (&fl, 0,
sizeof (fl));
235 fl.l_whence = SEEK_SET;
254 fl.l_type = (mode ==
OpenRead ? F_RDLCK : F_WRLCK);
255 if (fcntl (
FileHandle, F_GETLK, &fl) != -1 && fl.l_type != F_UNLCK)
285 #ifdef TC_TRACE_FILE_OPERATIONS
298 #ifdef TC_TRACE_FILE_OPERATIONS
301 ssize_t bytesRead = pread (
FileHandle, buffer, buffer.
Size(), position);
319 if (
Path.IsBlockDevice() ||
Path.IsCharacterDevice())
333 #ifdef TC_TRACE_FILE_OPERATIONS
343 #ifdef TC_TRACE_FILE_OPERATIONS