public static void AllocateFileSpace(StorageEnvironmentOptions options, int fd, long size, string file) { bool usingLseek; var result = Syscall.AllocateFileSpace(fd, size, file, out usingLseek); if (result == (int)Errno.ENOSPC) { int matchLen = 0; DriveInfo match = null; foreach (var drive in DriveInfo.GetDrives()) { if (file.StartsWith(drive.RootDirectory.Name)) { if (drive.RootDirectory.Name.Length > matchLen) { match = drive; } } } throw new DiskFullException(file, size, match?.AvailableFreeSpace); } if (result != 0) { Syscall.ThrowLastError(result, $"posix_fallocate(\"{file}\", {size})"); } }
public static void AllocateFileSpace(StorageEnvironmentOptions options, int fd, long size, string file) { bool usingLseek; var result = Syscall.AllocateFileSpace(fd, size, file, out usingLseek); if (result == (int)Errno.ENOSPC) { var diskSpaceResult = DiskSpaceChecker.GetDiskSpaceInfo(file); throw new DiskFullException(file, size, diskSpaceResult?.TotalFreeSpace.GetValue(SizeUnit.Bytes)); } if (result != 0) { Syscall.ThrowLastError(result, $"posix_fallocate(\"{file}\", {size})"); } }
public static unsafe void AllocateFileSpace(StorageEnvironmentOptions options, int fd, long size, string file) { bool usingLseek; var result = Syscall.AllocateFileSpace(fd, size, file, out usingLseek); if (result == (int)Errno.ENOSPC) { var diskSpaceResult = DiskSpaceChecker.GetDiskSpaceInfo(file); // Use Pal's detailed error string (until PosixHelper will be entirely removed) var nativeMsg = PalHelper.GetNativeErrorString(result, "Failed to AllocateFileSpace (PosixHelper)", out _); throw new DiskFullException(file, size, diskSpaceResult?.TotalFreeSpace.GetValue(SizeUnit.Bytes), nativeMsg); } if (result != 0) { Syscall.ThrowLastError(result, $"posix_fallocate(\"{file}\", {size})"); } }
public static void AllocateFileSpace(StorageEnvironmentOptions options, int fd, long size, string file) { bool usingLseek; var result = Syscall.AllocateFileSpace(fd, size, file, out usingLseek); if (result == (int)Errno.ENOSPC) { foreach (var drive in DriveInfo.GetDrives()) { if (file.StartsWith(drive.RootDirectory.Name)) { throw new DiskFullException(drive, file, (long)size); } } // shouldn't happen, and we can throw normally here throw new DiskFullException(null, file, (long)size); } if (result != 0) { Syscall.ThrowLastError(result, $"posix_fallocate(\"{file}\", {size})"); } }