[Mono-dev] Mono.Unix.Native

Greg Young gregoryyoung1 at gmail.com
Mon Jan 12 01:55:50 UTC 2015

I have been trying to use Syscalls a bit but am getting an exception I
can't figure out why.

Opening code throws no exceptions:
            var flags = OpenFlags.O_RDWR | OpenFlags.O_DIRECT |
            //var f = NativeConvert.FromOpenFlags(flags); not needed?
            var han = Syscall.open(path, flags, FilePermissions.S_IRWXU);
            if(han < 0)
                throw new Win32Exception();

            var handle = new SafeFileHandle((IntPtr) han, true);
            if(handle.IsInvalid) throw new Exception("Invalid handle");
            return handle;

Then I call write:

            fixed (byte* b = buffer)
                long ret = 0;
                 do {
                    ret = Syscall.write
(handle.DangerousGetHandle().ToInt32(), b ,count);
                } while (Mono.Unix.UnixMarshal.ShouldRetrySyscall ((int) ret));
                if(ret == -1)
((int) ret);

I get an invalid parameter exception. Read seems to work following a
similar pattern so not quite sure whats wrong.

My writes are of size 4096. Perhaps the issue is needing to call
memalign? I would expect reads to fail as well then though



13) Test Error :
   System.ArgumentException : Invalid argument
  ----> Mono.Unix.UnixIOException : Invalid argument [EINVAL].
  at Mono.Unix.UnixMarshal.ThrowExceptionForLastError () [0x00000] in
<filename unknown>:0
  at Mono.Unix.UnixMarshal.ThrowExceptionForLastErrorIf (Int32 retval)
[0x00000] in <filename unknown>:0
  at EventStore.Core.TransactionLog.Unbuffered.NativeFile.Write
(Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.Byte[]
buffer, UInt32 count, System.Int32& written) [0x00000] in <filename
  at EventStore.Core.TransactionLog.Unbuffered.UnbufferedIOFileStream.InternalWrite
(System.Byte[] buffer, UInt32 count) [0x00000] in <filename unknown>:0
  at EventStore.Core.TransactionLog.Unbuffered.UnbufferedIOFileStream.Flush
() [0x00000] in <filename unknown>:0
  at EventStore.Core.TransactionLog.Unbuffered.UnbufferedIOFileStream.Dispose
(Boolean disposing) [0x00000] in <filename unknown>:0
  at System.IO.Stream.Close () [0x00000] in <filename unknown>:0
  at System.IO.Stream.Dispose () [0x00000] in <filename unknown>:0
  at EventStore.Core.Tests.TransactionLog.Unbuffered.UnbufferedTests.when_writing_then_seeking_exact_to_alignment_and_writing_again
() [0x00000] in <filename unknown>:0
  at (wrapper managed-to-native)
  at System.Reflection.MonoMethod.Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000] in <filename unknown>:0

Studying for the Turing test

More information about the Mono-devel-list mailing list