예제 #1
0
        // http://cboard.cprogramming.com/c-programming/126630-using-sys-mount-h-mounting-usb-thumb-drive.html
        // http://stackoverflow.com/questions/10458549/mount-usb-drive-in-linux-with-c
        // mount("/dev/loop1", "/mnt/testdisk", "vfat");
        public static bool mount(string strDevice, string strMountPoint, string strFsType, MountFlags mflags, IntPtr options)
        {
            // http://linux.die.net/man/2/mount
            // MS_RDONLY
            // MS_RELATIME (default for Linux >= 2.6.30)
            // MS_STRICTATIME (default for Linux < 2.6.30)

            if (UnsafeNativeMethods.mount(strDevice, strMountPoint, strFsType, mflags, options) != 0)
            {
                Mono.Unix.Native.Errno errno = Mono.Unix.Native.Syscall.GetLastError();

                if (errno == Mono.Unix.Native.Errno.EBUSY)
                {
                    Console.WriteLine("Mountpoint busy");
                }
                else
                {
                    Console.WriteLine("Mount error: " + Mono.Unix.Native.Syscall.strerror(errno));
                }

                return(false);
            }
            else
            {
                Console.WriteLine("Successfully mounted device !");
            }

            return(true);;
        }     // End Function mount
        private void ThrowException()
        {
            if (m_Dll == null)
            {
                return;
            }

#if NETSTANDARD15
            throw new Exception(string.Format("Error {0}", m_Dll.errno));
#else
            Mono.Unix.Native.Errno errno = Mono.Unix.Native.NativeConvert.ToErrno(m_Dll.errno);
            string description           = m_Dll.serial_error(m_Handle);

            switch (errno)
            {
            case Mono.Unix.Native.Errno.EINVAL:
                throw new ArgumentException(description);

            case Mono.Unix.Native.Errno.EACCES:
                throw new UnauthorizedAccessException(description);

            default:
                throw new InvalidOperationException(description);
            }
#endif
        }
예제 #3
0
 // For compatibility with libnserial 1.0 only.
 private void ThrowExceptionMono()
 {
     Mono.Unix.Native.Errno errno = Mono.Unix.Native.NativeConvert.ToErrno(m_Dll.errno);
     string description = m_Dll.serial_error(m_Handle);
     switch (errno) {
     case Mono.Unix.Native.Errno.EINVAL:
         throw new ArgumentException(description);
     case Mono.Unix.Native.Errno.EACCES:
         throw new UnauthorizedAccessException(description);
     default:
         throw new InvalidOperationException(description);
     }
 }
예제 #4
0
        } // End Function del_loop

        /*public static bool mount(string strDevice, string strMountPoint, string strFsType){
         *  return mount(strDevice, strMountPoint, strFsType, MountFlags.MS_NOATIME);
         * }*/

        /*public bool Mount(string strDevice, string strMountPoint, string strFsType, MountFlags mflags){
         *  return mount(strDevice, strMountPoint, strFsType, mflags, IntPtr.Zero);
         * }*/


        // http://cboard.cprogramming.com/c-programming/126630-using-sys-mount-h-mounting-usb-thumb-drive.html
        // http://stackoverflow.com/questions/10458549/mount-usb-drive-in-linux-with-c
        // mount("/dev/loop1", "/mnt/testdisk", "vfat");
        public bool Mount(string strDevice, string strMountPoint, string strFsType, MountFlags mflags, string options)
        {
            // http://linux.die.net/man/2/mount
            // MS_RDONLY
            // MS_RELATIME (default for Linux >= 2.6.30)
            // MS_STRICTATIME (default for Linux < 2.6.30)

            if (UnsafeNativeMethods.mount(strDevice, strMountPoint, strFsType, mflags, options) != 0)
            {
                Mono.Unix.Native.Errno errno = Mono.Unix.Native.Syscall.GetLastError();
                throw new Exception(errno.ToString());
            }
            else
            {
                return(true);
            };
        } // End Function mount