public static FileMap FromStreamInternal(FileStream stream, FileMapProtect prot, int offset, int length) { if (length == 0) { length = (int)stream.Length; } #if DEBUG Console.WriteLine("Opening file map: {0}", stream.Name); #endif switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: return(new wFileMap(stream.SafeFileHandle.DangerousGetHandle(), prot, offset, (uint)length) { _baseStream = stream, _path = stream.Name }); case PlatformID.Unix: return(new lFileMap(stream.SafeFileHandle.DangerousGetHandle(), prot, (uint)offset, (uint)length) { _baseStream = stream, _path = stream.Name }); } return(null); }
internal wFileMap(VoidPtr hFile, FileMapProtect protect, long offset, uint length) { long maxSize = offset + length; uint maxHigh = (uint)(maxSize >> 32); uint maxLow = (uint)maxSize; Win32._FileMapProtect mProtect; Win32._FileMapAccess mAccess; if (protect == FileMapProtect.ReadWrite) { mProtect = Win32._FileMapProtect.ReadWrite; mAccess = Win32._FileMapAccess.Write; } else { mProtect = Win32._FileMapProtect.ReadOnly; mAccess = Win32._FileMapAccess.Read; } using (Win32.SafeHandle h = Win32.CreateFileMapping(hFile, null, mProtect, maxHigh, maxLow, null)) { h.ErrorCheck(); _addr = Win32.MapViewOfFile(h.Handle, mAccess, (uint)(offset >> 32), (uint)offset, length); if (!_addr) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } _length = (int)length; } }
public static FileMap FromFile(string path, FileMapProtect prot, int offset, int length) { FileStream stream = new FileStream(path, FileMode.Open, (prot == FileMapProtect.ReadWrite) ? FileAccess.ReadWrite : FileAccess.Read, FileShare.Read, 8, FileOptions.RandomAccess); try { return(FromStreamInternal(stream, prot, offset, length)); } catch (Exception x) { stream.Dispose(); throw x; } }
public static FileMap FromStream(FileStream stream, FileMapProtect prot, int offset, int length) { //FileStream newStream = new FileStream(stream.Name, FileMode.Open, prot == FileMapProtect.Read ? FileAccess.Read : FileAccess.ReadWrite, FileShare.Read, 8, FileOptions.RandomAccess); //try { return FromStreamInternal(newStream, prot, offset, length); } //catch (Exception x) { newStream.Dispose(); throw x; } if (length == 0) { length = (int)stream.Length; } #if DEBUG Console.WriteLine("Opening file map: {0}", stream.Name); #endif switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: return(new wFileMap(stream.SafeFileHandle.DangerousGetHandle(), prot, offset, (uint)length) { _path = stream.Name }); case PlatformID.Unix: return(new lFileMap(stream.SafeFileHandle.DangerousGetHandle(), prot, (uint)offset, (uint)length) { _path = stream.Name }); } return(null); }
public cFileMap(FileStream stream, FileMapProtect protect, int offset, int length) { MemoryMappedFileAccess cProtect = (protect == FileMapProtect.ReadWrite) ? MemoryMappedFileAccess.ReadWrite : MemoryMappedFileAccess.Read; _length = length; _mappedFile = MemoryMappedFile.CreateFromFile(stream, stream.Name, _length, cProtect, null, HandleInheritability.None, true); _mappedFileAccessor = _mappedFile.CreateViewAccessor(offset, _length, cProtect); _addr = _mappedFileAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(); }
public cFileMap(FileStream stream, FileMapProtect protect, long offset, int length) { MemoryMappedFileAccess cProtect = (protect == FileMapProtect.ReadWrite) ? MemoryMappedFileAccess.ReadWrite : MemoryMappedFileAccess.Read; _length = length; _mappedFile = MemoryMappedFile.CreateFromFile(stream, stream.Name, _length, cProtect, null, HandleInheritability.None, true); _mappedFileAccessor = _mappedFile.CreateViewAccessor(offset, _length, cProtect); _addr = _mappedFileAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(); }
public static FileMap FromFile(string path, FileMapProtect prot, int offset, int length, FileOptions options) { FileStream stream; FileMap map; try { stream = new FileStream(path, FileMode.Open, (prot == FileMapProtect.ReadWrite) ? FileAccess.ReadWrite : FileAccess.Read, FileShare.Read, 8, options); } catch //File is currently in use, but we can copy it to a temp location and read that { string tempPath = Path.GetTempFileName(); File.Copy(path, tempPath, true); stream = new FileStream(tempPath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 8, options | FileOptions.DeleteOnClose); } try { map = FromStreamInternal(stream, prot, offset, length); } catch (Exception x) { stream.Dispose(); throw x; } map._path = path; //In case we're using a temp file return map; }
public static FileMap FromFile(string path, FileMapProtect prot, int offset, int length, FileOptions options) { FileStream stream; FileMap map; try { stream = new FileStream(path, FileMode.Open, (prot == FileMapProtect.ReadWrite) ? FileAccess.ReadWrite : FileAccess.Read, FileShare.Read, 8, options); } catch //File is currently in use, but we can copy it to a temp location and read that { string tempPath = Path.GetTempFileName(); File.Copy(path, tempPath, true); stream = new FileStream(tempPath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 8, options | FileOptions.DeleteOnClose); } try { map = FromStreamInternal(stream, prot, offset, length); } catch (Exception x) { stream.Dispose(); throw; } map._path = path; //In case we're using a temp file return(map); }
public static FileMap FromStream(FileStream stream, FileMapProtect prot, int offset, int length) { //FileStream newStream = new FileStream(stream.Name, FileMode.Open, prot == FileMapProtect.Read ? FileAccess.Read : FileAccess.ReadWrite, FileShare.Read, 8, FileOptions.RandomAccess); //try { return FromStreamInternal(newStream, prot, offset, length); } //catch (Exception x) { newStream.Dispose(); throw x; } if (length == 0) length = (int)stream.Length; switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: return new wFileMap(stream.SafeFileHandle.DangerousGetHandle(), prot, offset, (uint)length) { _path = stream.Name }; default: return new cFileMap(stream, prot, offset, length) { _path = stream.Name }; } //#if DEBUG // Console.WriteLine("Opening file map: {0}", stream.Name); //#endif }
public lFileMap(VoidPtr hFile, FileMapProtect protect, uint offset, uint length) { Linux.MMapProtect mProtect = (protect == FileMapProtect.ReadWrite) ? Linux.MMapProtect.Read | Linux.MMapProtect.Write : Linux.MMapProtect.Read; _addr = Linux.mmap(null, length, mProtect, Linux.MMapFlags.Shared, hFile, offset); _length = (int)length; }
public static FileMap FromStream(FileStream stream, FileMapProtect prot) { return(FromStream(stream, prot, 0, 0)); }
public static FileMap FromFile(string path, FileMapProtect prot) { return(FromFile(path, prot, 0, 0)); }
public static FileMap FromFile(string path, FileMapProtect prot, int offset, int length) { return FromFile(path, prot, 0, 0, FileOptions.RandomAccess); }
public static FileMap FromFile(string path, FileMapProtect prot) { return FromFile(path, prot, 0, 0); }
public static FileMap FromFile(string path, FileMapProtect prot, uint offset, int length) { return(FromFile(path, prot, offset, length, FileOptions.RandomAccess)); }
public override void Replace(string fileName, FileMapProtect prot, FileOptions options) { base.Replace(fileName, prot, options); }
public static FileMap FromStream(FileStream stream, FileMapProtect prot) { return FromStream(stream, prot, 0, 0); }
public unsafe virtual void Replace(string fileName, FileMapProtect prot, FileOptions options) { //Name = Path.GetFileNameWithoutExtension(fileName); ReplaceRaw(FileMap.FromFile(fileName, prot, 0, 0, options)); }
public static FileMap FromStreamInternal(FileStream stream, FileMapProtect prot, int offset, int length) { if (length == 0) length = (int)stream.Length; switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: return new wFileMap(stream.SafeFileHandle.DangerousGetHandle(), prot, offset, (uint)length) { _baseStream = stream, _path = stream.Name }; default: return new cFileMap(stream, prot, offset, length) { _baseStream = stream, _path = stream.Name }; } //#if DEBUG // Console.WriteLine("Opening file map: {0}", stream.Name); //#endif }
internal wFileMap(VoidPtr hFile, FileMapProtect protect, long offset, uint length) { long maxSize = offset + length; uint maxHigh = (uint)(maxSize >> 32); uint maxLow = (uint)maxSize; Win32._FileMapProtect mProtect; Win32._FileMapAccess mAccess; if (protect == FileMapProtect.ReadWrite) { mProtect = Win32._FileMapProtect.ReadWrite; mAccess = Win32._FileMapAccess.Write; } else { mProtect = Win32._FileMapProtect.ReadOnly; mAccess = Win32._FileMapAccess.Read; } using (Win32.SafeHandle h = Win32.CreateFileMapping(hFile, null, mProtect, maxHigh, maxLow, null)) { h.ErrorCheck(); _addr = Win32.MapViewOfFile(h.Handle, mAccess, (uint)(offset >> 32), (uint)offset, length); if (!_addr) Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); _length = (int)length; } }