NTFileSystemAdapter.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /* Copyright (C) 2014-2019 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using Utilities;
  11. namespace SMBLibrary
  12. {
  13. public partial class NTFileSystemAdapter : INTFileStore
  14. {
  15. private const int BytesPerSector = 512;
  16. private const int ClusterSize = 4096;
  17. private IFileSystem m_fileSystem;
  18. public event EventHandler<LogEntry> LogEntryAdded;
  19. public NTFileSystemAdapter(IFileSystem fileSystem)
  20. {
  21. m_fileSystem = fileSystem;
  22. }
  23. public NTStatus CreateFile(out object handle, out FileStatus fileStatus, string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext)
  24. {
  25. handle = null;
  26. fileStatus = FileStatus.FILE_DOES_NOT_EXIST;
  27. FileAccess createAccess = NTFileStoreHelper.ToCreateFileAccess(desiredAccess, createDisposition);
  28. bool requestedWriteAccess = (createAccess & FileAccess.Write) > 0;
  29. bool forceDirectory = (createOptions & CreateOptions.FILE_DIRECTORY_FILE) > 0;
  30. bool forceFile = (createOptions & CreateOptions.FILE_NON_DIRECTORY_FILE) > 0;
  31. if (forceDirectory & (createDisposition != CreateDisposition.FILE_CREATE &&
  32. createDisposition != CreateDisposition.FILE_OPEN &&
  33. createDisposition != CreateDisposition.FILE_OPEN_IF &&
  34. createDisposition != CreateDisposition.FILE_SUPERSEDE))
  35. {
  36. return NTStatus.STATUS_INVALID_PARAMETER;
  37. }
  38. // Windows will try to access named streams (alternate data streams) regardless of the FILE_NAMED_STREAMS flag, we need to prevent this behaviour.
  39. if (!m_fileSystem.SupportsNamedStreams && path.Contains(":"))
  40. {
  41. // Windows Server 2003 will return STATUS_OBJECT_NAME_NOT_FOUND
  42. return NTStatus.STATUS_NO_SUCH_FILE;
  43. }
  44. FileSystemEntry entry = null;
  45. try
  46. {
  47. entry = m_fileSystem.GetEntry(path);
  48. }
  49. catch (FileNotFoundException)
  50. {
  51. }
  52. catch (DirectoryNotFoundException)
  53. {
  54. }
  55. catch (Exception ex)
  56. {
  57. if (ex is IOException || ex is UnauthorizedAccessException)
  58. {
  59. NTStatus status = ToNTStatus(ex);
  60. Log(Severity.Verbose, "CreateFile: Error retrieving '{0}'. {1}.", path, status);
  61. return status;
  62. }
  63. else
  64. {
  65. throw;
  66. }
  67. }
  68. if (createDisposition == CreateDisposition.FILE_OPEN)
  69. {
  70. if (entry == null)
  71. {
  72. return NTStatus.STATUS_NO_SUCH_FILE;
  73. }
  74. fileStatus = FileStatus.FILE_EXISTS;
  75. if (entry.IsDirectory && forceFile)
  76. {
  77. return NTStatus.STATUS_FILE_IS_A_DIRECTORY;
  78. }
  79. if (!entry.IsDirectory && forceDirectory)
  80. {
  81. return NTStatus.STATUS_OBJECT_PATH_INVALID;
  82. }
  83. }
  84. else if (createDisposition == CreateDisposition.FILE_CREATE)
  85. {
  86. if (entry != null)
  87. {
  88. // File already exists, fail the request
  89. Log(Severity.Verbose, "CreateFile: File '{0}' already exists.", path);
  90. fileStatus = FileStatus.FILE_EXISTS;
  91. return NTStatus.STATUS_OBJECT_NAME_COLLISION;
  92. }
  93. if (!requestedWriteAccess)
  94. {
  95. return NTStatus.STATUS_ACCESS_DENIED;
  96. }
  97. try
  98. {
  99. if (forceDirectory)
  100. {
  101. Log(Severity.Information, "CreateFile: Creating directory '{0}'", path);
  102. entry = m_fileSystem.CreateDirectory(path);
  103. }
  104. else
  105. {
  106. Log(Severity.Information, "CreateFile: Creating file '{0}'", path);
  107. entry = m_fileSystem.CreateFile(path);
  108. }
  109. }
  110. catch (Exception ex)
  111. {
  112. if (ex is IOException || ex is UnauthorizedAccessException)
  113. {
  114. NTStatus status = ToNTStatus(ex);
  115. Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
  116. return status;
  117. }
  118. else
  119. {
  120. throw;
  121. }
  122. }
  123. fileStatus = FileStatus.FILE_CREATED;
  124. }
  125. else if (createDisposition == CreateDisposition.FILE_OPEN_IF ||
  126. createDisposition == CreateDisposition.FILE_OVERWRITE ||
  127. createDisposition == CreateDisposition.FILE_OVERWRITE_IF ||
  128. createDisposition == CreateDisposition.FILE_SUPERSEDE)
  129. {
  130. if (entry == null)
  131. {
  132. if (createDisposition == CreateDisposition.FILE_OVERWRITE)
  133. {
  134. return NTStatus.STATUS_OBJECT_PATH_NOT_FOUND;
  135. }
  136. if (!requestedWriteAccess)
  137. {
  138. return NTStatus.STATUS_ACCESS_DENIED;
  139. }
  140. try
  141. {
  142. if (forceDirectory)
  143. {
  144. Log(Severity.Information, "CreateFile: Creating directory '{0}'", path);
  145. entry = m_fileSystem.CreateDirectory(path);
  146. }
  147. else
  148. {
  149. Log(Severity.Information, "CreateFile: Creating file '{0}'", path);
  150. entry = m_fileSystem.CreateFile(path);
  151. }
  152. }
  153. catch (Exception ex)
  154. {
  155. if (ex is IOException || ex is UnauthorizedAccessException)
  156. {
  157. NTStatus status = ToNTStatus(ex);
  158. Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
  159. return status;
  160. }
  161. else
  162. {
  163. throw;
  164. }
  165. }
  166. fileStatus = FileStatus.FILE_CREATED;
  167. }
  168. else
  169. {
  170. fileStatus = FileStatus.FILE_EXISTS;
  171. if (createDisposition == CreateDisposition.FILE_OPEN_IF)
  172. {
  173. if (entry.IsDirectory && forceFile)
  174. {
  175. return NTStatus.STATUS_FILE_IS_A_DIRECTORY;
  176. }
  177. if (!entry.IsDirectory && forceDirectory)
  178. {
  179. return NTStatus.STATUS_OBJECT_PATH_INVALID;
  180. }
  181. }
  182. else
  183. {
  184. if (!requestedWriteAccess)
  185. {
  186. return NTStatus.STATUS_ACCESS_DENIED;
  187. }
  188. if (createDisposition == CreateDisposition.FILE_OVERWRITE ||
  189. createDisposition == CreateDisposition.FILE_OVERWRITE_IF)
  190. {
  191. // Truncate the file
  192. try
  193. {
  194. Stream temp = m_fileSystem.OpenFile(path, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite, FileOptions.None);
  195. temp.Close();
  196. }
  197. catch (Exception ex)
  198. {
  199. if (ex is IOException || ex is UnauthorizedAccessException)
  200. {
  201. NTStatus status = ToNTStatus(ex);
  202. Log(Severity.Verbose, "CreateFile: Error truncating '{0}'. {1}.", path, status);
  203. return status;
  204. }
  205. else
  206. {
  207. throw;
  208. }
  209. }
  210. fileStatus = FileStatus.FILE_OVERWRITTEN;
  211. }
  212. else if (createDisposition == CreateDisposition.FILE_SUPERSEDE)
  213. {
  214. // Delete the old file
  215. try
  216. {
  217. m_fileSystem.Delete(path);
  218. }
  219. catch (Exception ex)
  220. {
  221. if (ex is IOException || ex is UnauthorizedAccessException)
  222. {
  223. NTStatus status = ToNTStatus(ex);
  224. Log(Severity.Verbose, "CreateFile: Error deleting '{0}'. {1}.", path, status);
  225. return status;
  226. }
  227. else
  228. {
  229. throw;
  230. }
  231. }
  232. try
  233. {
  234. if (forceDirectory)
  235. {
  236. Log(Severity.Information, "CreateFile: Creating directory '{0}'", path);
  237. entry = m_fileSystem.CreateDirectory(path);
  238. }
  239. else
  240. {
  241. Log(Severity.Information, "CreateFile: Creating file '{0}'", path);
  242. entry = m_fileSystem.CreateFile(path);
  243. }
  244. }
  245. catch (Exception ex)
  246. {
  247. if (ex is IOException || ex is UnauthorizedAccessException)
  248. {
  249. NTStatus status = ToNTStatus(ex);
  250. Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
  251. return status;
  252. }
  253. else
  254. {
  255. throw;
  256. }
  257. }
  258. fileStatus = FileStatus.FILE_SUPERSEDED;
  259. }
  260. }
  261. }
  262. }
  263. else
  264. {
  265. return NTStatus.STATUS_INVALID_PARAMETER;
  266. }
  267. FileAccess fileAccess = NTFileStoreHelper.ToFileAccess(desiredAccess);
  268. Stream stream;
  269. if (fileAccess == (FileAccess)0 || entry.IsDirectory)
  270. {
  271. stream = null;
  272. }
  273. else
  274. {
  275. // Note that SetFileInformationByHandle/FILE_DISPOSITION_INFO has no effect if the handle was opened with FILE_DELETE_ON_CLOSE.
  276. NTStatus openStatus = OpenFileStream(out stream, path, fileAccess, shareAccess, createOptions);
  277. if (openStatus != NTStatus.STATUS_SUCCESS)
  278. {
  279. return openStatus;
  280. }
  281. }
  282. bool deleteOnClose = (createOptions & CreateOptions.FILE_DELETE_ON_CLOSE) > 0;
  283. handle = new FileHandle(path, entry.IsDirectory, stream, deleteOnClose);
  284. if (fileStatus != FileStatus.FILE_CREATED &&
  285. fileStatus != FileStatus.FILE_OVERWRITTEN &&
  286. fileStatus != FileStatus.FILE_SUPERSEDED)
  287. {
  288. fileStatus = FileStatus.FILE_OPENED;
  289. }
  290. return NTStatus.STATUS_SUCCESS;
  291. }
  292. private NTStatus OpenFileStream(out Stream stream, string path, FileAccess fileAccess, ShareAccess shareAccess, CreateOptions openOptions)
  293. {
  294. stream = null;
  295. FileShare fileShare = NTFileStoreHelper.ToFileShare(shareAccess);
  296. FileOptions fileOptions = ToFileOptions(openOptions);
  297. string fileShareString = fileShare.ToString().Replace(", ", "|");
  298. string fileOptionsString = ToFileOptionsString(fileOptions);
  299. try
  300. {
  301. stream = m_fileSystem.OpenFile(path, FileMode.Open, fileAccess, fileShare, fileOptions);
  302. }
  303. catch (Exception ex)
  304. {
  305. if (ex is IOException || ex is UnauthorizedAccessException)
  306. {
  307. NTStatus status = ToNTStatus(ex);
  308. Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status);
  309. return status;
  310. }
  311. else
  312. {
  313. throw;
  314. }
  315. }
  316. Log(Severity.Information, "OpenFileStream: Opened '{0}', Access={1}, Share={2}, FileOptions={3}", path, fileAccess, fileShareString, fileOptionsString);
  317. return NTStatus.STATUS_SUCCESS;
  318. }
  319. public NTStatus CloseFile(object handle)
  320. {
  321. FileHandle fileHandle = (FileHandle)handle;
  322. if (fileHandle.Stream != null)
  323. {
  324. Log(Severity.Verbose, "CloseFile: Closing '{0}'.", fileHandle.Path);
  325. fileHandle.Stream.Close();
  326. }
  327. // If the file / directory was created with FILE_DELETE_ON_CLOSE but was not opened (with FileOptions.DeleteOnClose), we should delete it now.
  328. if (fileHandle.Stream == null && fileHandle.DeleteOnClose)
  329. {
  330. try
  331. {
  332. m_fileSystem.Delete(fileHandle.Path);
  333. Log(Severity.Verbose, "CloseFile: Deleted '{0}'.", fileHandle.Path);
  334. }
  335. catch
  336. {
  337. Log(Severity.Verbose, "CloseFile: Error deleting '{0}'.", fileHandle.Path);
  338. }
  339. }
  340. return NTStatus.STATUS_SUCCESS;
  341. }
  342. public NTStatus ReadFile(out byte[] data, object handle, long offset, int maxCount)
  343. {
  344. data = null;
  345. FileHandle fileHandle = (FileHandle)handle;
  346. string path = fileHandle.Path;
  347. Stream stream = fileHandle.Stream;
  348. if (stream == null || !stream.CanRead)
  349. {
  350. Log(Severity.Verbose, "ReadFile: Cannot read '{0}', Invalid Operation.", path);
  351. return NTStatus.STATUS_ACCESS_DENIED;
  352. }
  353. if (offset >= stream.Length)
  354. {
  355. Log(Severity.Verbose, "ReadFile: Cannot read from '{0}', offset {1} is out of range.", path, offset);
  356. return NTStatus.STATUS_END_OF_FILE;
  357. }
  358. int bytesRead;
  359. try
  360. {
  361. stream.Seek(offset, SeekOrigin.Begin);
  362. data = new byte[maxCount];
  363. bytesRead = stream.Read(data, 0, maxCount);
  364. }
  365. catch (Exception ex)
  366. {
  367. if (ex is IOException || ex is UnauthorizedAccessException)
  368. {
  369. NTStatus status = ToNTStatus(ex);
  370. Log(Severity.Verbose, "ReadFile: Cannot read '{0}'. {1}.", path, status);
  371. return status;
  372. }
  373. else
  374. {
  375. throw;
  376. }
  377. }
  378. if (bytesRead < maxCount)
  379. {
  380. // EOF, we must trim the response data array
  381. data = ByteReader.ReadBytes(data, 0, bytesRead);
  382. }
  383. return NTStatus.STATUS_SUCCESS;
  384. }
  385. public NTStatus WriteFile(out int numberOfBytesWritten, object handle, long offset, byte[] data)
  386. {
  387. numberOfBytesWritten = 0;
  388. FileHandle fileHandle = (FileHandle)handle;
  389. string path = fileHandle.Path;
  390. Stream stream = fileHandle.Stream;
  391. if (stream == null || !stream.CanWrite)
  392. {
  393. Log(Severity.Verbose, "WriteFile: Cannot write '{0}'. Invalid Operation.", path);
  394. return NTStatus.STATUS_ACCESS_DENIED;
  395. }
  396. try
  397. {
  398. stream.Seek(offset, SeekOrigin.Begin);
  399. stream.Write(data, 0, data.Length);
  400. }
  401. catch (Exception ex)
  402. {
  403. if (ex is IOException || ex is UnauthorizedAccessException)
  404. {
  405. NTStatus status = ToNTStatus(ex);
  406. Log(Severity.Verbose, "WriteFile: Cannot write '{0}'. {1}.", path, status);
  407. return status;
  408. }
  409. else
  410. {
  411. throw;
  412. }
  413. }
  414. numberOfBytesWritten = data.Length;
  415. return NTStatus.STATUS_SUCCESS;
  416. }
  417. public NTStatus FlushFileBuffers(object handle)
  418. {
  419. FileHandle fileHandle = (FileHandle)handle;
  420. if (fileHandle.Stream != null)
  421. {
  422. fileHandle.Stream.Flush();
  423. }
  424. return NTStatus.STATUS_SUCCESS;
  425. }
  426. public NTStatus LockFile(object handle, long byteOffset, long length, bool exclusiveLock)
  427. {
  428. return NTStatus.STATUS_NOT_SUPPORTED;
  429. }
  430. public NTStatus UnlockFile(object handle, long byteOffset, long length)
  431. {
  432. return NTStatus.STATUS_NOT_SUPPORTED;
  433. }
  434. public NTStatus GetSecurityInformation(out SecurityDescriptor result, object handle, SecurityInformation securityInformation)
  435. {
  436. result = null;
  437. return NTStatus.STATUS_NOT_SUPPORTED;
  438. }
  439. public NTStatus SetSecurityInformation(object handle, SecurityInformation securityInformation, SecurityDescriptor securityDescriptor)
  440. {
  441. return NTStatus.STATUS_NOT_SUPPORTED;
  442. }
  443. public NTStatus NotifyChange(out object ioRequest, object handle, NotifyChangeFilter completionFilter, bool watchTree, int outputBufferSize, OnNotifyChangeCompleted onNotifyChangeCompleted, object context)
  444. {
  445. ioRequest = null;
  446. return NTStatus.STATUS_NOT_SUPPORTED;
  447. }
  448. public NTStatus Cancel(object ioRequest)
  449. {
  450. return NTStatus.STATUS_NOT_SUPPORTED;
  451. }
  452. public NTStatus DeviceIOControl(object handle, uint ctlCode, byte[] input, out byte[] output, int maxOutputLength)
  453. {
  454. output = null;
  455. return NTStatus.STATUS_NOT_SUPPORTED;
  456. }
  457. public void Log(Severity severity, string message)
  458. {
  459. // To be thread-safe we must capture the delegate reference first
  460. EventHandler<LogEntry> handler = LogEntryAdded;
  461. if (handler != null)
  462. {
  463. handler(this, new LogEntry(DateTime.Now, severity, "NT FileSystem Adapter", message));
  464. }
  465. }
  466. public void Log(Severity severity, string message, params object[] args)
  467. {
  468. Log(severity, String.Format(message, args));
  469. }
  470. /// <param name="exception">IFileSystem exception</param>
  471. private static NTStatus ToNTStatus(Exception exception)
  472. {
  473. if (exception is DirectoryNotFoundException)
  474. {
  475. return NTStatus.STATUS_OBJECT_PATH_NOT_FOUND;
  476. }
  477. else if (exception is FileNotFoundException)
  478. {
  479. return NTStatus.STATUS_OBJECT_PATH_NOT_FOUND;
  480. }
  481. else if (exception is IOException)
  482. {
  483. ushort errorCode = IOExceptionHelper.GetWin32ErrorCode((IOException)exception);
  484. if (errorCode == (ushort)Win32Error.ERROR_SHARING_VIOLATION)
  485. {
  486. return NTStatus.STATUS_SHARING_VIOLATION;
  487. }
  488. else if (errorCode == (ushort)Win32Error.ERROR_DISK_FULL)
  489. {
  490. return NTStatus.STATUS_DISK_FULL;
  491. }
  492. else if (errorCode == (ushort)Win32Error.ERROR_INVALID_NAME)
  493. {
  494. return NTStatus.STATUS_OBJECT_NAME_INVALID;
  495. }
  496. else if (errorCode == (ushort)Win32Error.ERROR_DIR_NOT_EMPTY)
  497. {
  498. // If a user tries to rename folder1 to folder2 when folder2 already exists, Windows 7 will offer to merge folder1 into folder2.
  499. // In such case, Windows 7 will delete folder 1 and will expect STATUS_DIRECTORY_NOT_EMPTY if there are files to merge.
  500. return NTStatus.STATUS_DIRECTORY_NOT_EMPTY;
  501. }
  502. else if (errorCode == (ushort)Win32Error.ERROR_BAD_PATHNAME)
  503. {
  504. return NTStatus.STATUS_OBJECT_PATH_INVALID;
  505. }
  506. else if (errorCode == (ushort)Win32Error.ERROR_ALREADY_EXISTS)
  507. {
  508. // According to [MS-FSCC], FileRenameInformation MUST return STATUS_OBJECT_NAME_COLLISION when the specified name already exists and ReplaceIfExists is zero.
  509. return NTStatus.STATUS_OBJECT_NAME_COLLISION;
  510. }
  511. else
  512. {
  513. return NTStatus.STATUS_DATA_ERROR;
  514. }
  515. }
  516. else if (exception is UnauthorizedAccessException)
  517. {
  518. return NTStatus.STATUS_ACCESS_DENIED;
  519. }
  520. else
  521. {
  522. return NTStatus.STATUS_DATA_ERROR;
  523. }
  524. }
  525. private static FileOptions ToFileOptions(CreateOptions createOptions)
  526. {
  527. const FileOptions FILE_FLAG_OPEN_REPARSE_POINT = (FileOptions)0x00200000;
  528. const FileOptions FILE_FLAG_NO_BUFFERING = (FileOptions)0x20000000;
  529. FileOptions result = FileOptions.None;
  530. if ((createOptions & CreateOptions.FILE_OPEN_REPARSE_POINT) > 0)
  531. {
  532. result |= FILE_FLAG_OPEN_REPARSE_POINT;
  533. }
  534. if ((createOptions & CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING) > 0)
  535. {
  536. result |= FILE_FLAG_NO_BUFFERING;
  537. }
  538. if ((createOptions & CreateOptions.FILE_RANDOM_ACCESS) > 0)
  539. {
  540. result |= FileOptions.RandomAccess;
  541. }
  542. if ((createOptions & CreateOptions.FILE_SEQUENTIAL_ONLY) > 0)
  543. {
  544. result |= FileOptions.SequentialScan;
  545. }
  546. if ((createOptions & CreateOptions.FILE_WRITE_THROUGH) > 0)
  547. {
  548. result |= FileOptions.WriteThrough;
  549. }
  550. if ((createOptions & CreateOptions.FILE_DELETE_ON_CLOSE) > 0)
  551. {
  552. result |= FileOptions.DeleteOnClose;
  553. }
  554. return result;
  555. }
  556. private static string ToFileOptionsString(FileOptions options)
  557. {
  558. string result = String.Empty;
  559. const FileOptions FILE_FLAG_OPEN_REPARSE_POINT = (FileOptions)0x00200000;
  560. const FileOptions FILE_FLAG_NO_BUFFERING = (FileOptions)0x20000000;
  561. if ((options & FILE_FLAG_OPEN_REPARSE_POINT) > 0)
  562. {
  563. result += "ReparsePoint|";
  564. options &= ~FILE_FLAG_OPEN_REPARSE_POINT;
  565. }
  566. if ((options & FILE_FLAG_NO_BUFFERING) > 0)
  567. {
  568. result += "NoBuffering|";
  569. options &= ~FILE_FLAG_NO_BUFFERING;
  570. }
  571. if (result == String.Empty || options != FileOptions.None)
  572. {
  573. result += options.ToString().Replace(", ", "|");
  574. }
  575. result = result.TrimEnd(new char[] { '|' });
  576. return result;
  577. }
  578. /// <summary>
  579. /// Will return a virtual allocation size, assuming 4096 bytes per cluster
  580. /// </summary>
  581. public static ulong GetAllocationSize(ulong size)
  582. {
  583. return (ulong)Math.Ceiling((double)size / ClusterSize) * ClusterSize;
  584. }
  585. }
  586. }