Пример #1
0
        private static void Notify(bool created, string sourceVolumeName, string targetVolumeName)
        {
            using (MemoryAlloc data = new MemoryAlloc(
                       MountMgrVolumeMountPoint.SizeOf +
                       sourceVolumeName.Length * 2 +
                       targetVolumeName.Length * 2
                       ))
            {
                MountMgrVolumeMountPoint mountPoint = new MountMgrVolumeMountPoint
                {
                    SourceVolumeNameLength = (ushort)(sourceVolumeName.Length * 2),
                    SourceVolumeNameOffset = (ushort)MountMgrVolumeMountPoint.SizeOf,
                    TargetVolumeNameLength = (ushort)(targetVolumeName.Length * 2)
                };

                mountPoint.TargetVolumeNameOffset = (ushort)(mountPoint.SourceVolumeNameOffset + mountPoint.SourceVolumeNameLength);

                data.WriteStruct(mountPoint);
                data.WriteUnicodeString(mountPoint.SourceVolumeNameOffset, sourceVolumeName);
                data.WriteUnicodeString(mountPoint.TargetVolumeNameOffset, targetVolumeName);

                using (FileHandle fhandle = OpenMountManager(FileAccess.GenericRead | FileAccess.GenericWrite))
                {
                    fhandle.IoControl(
                        created ? IoCtlVolumeMountPointCreated : IoCtlVolumeMountPointDeleted,
                        data.Memory,
                        data.Size,
                        IntPtr.Zero,
                        0
                        );
                }
            }
        }
Пример #2
0
        public static unsafe StorageHotplugInfo GetHotplugInfo(FileHandle fileHandle)
        {
            StorageHotplugInfo hotplugInfo;

            fileHandle.IoControl(IoCtlGetHotplugInfo, null, 0, &hotplugInfo, StorageHotplugInfo.SizeOf);

            return(hotplugInfo);
        }
Пример #3
0
        public static unsafe StorageHotplugInfo GetHotplugInfo(FileHandle fileHandle)
        {
            StorageHotplugInfo hotplugInfo;

            fileHandle.IoControl(IoCtlGetHotplugInfo, null, 0, &hotplugInfo, StorageHotplugInfo.SizeOf);

            return hotplugInfo;
        }
Пример #4
0
        public static StorageHotplugInfo GetHotplugInfo(FileHandle fileHandle)
        {
            unsafe
            {
                StorageHotplugInfo hotplugInfo;

                fileHandle.IoControl(IoCtlGetHotplugInfo, null, 0, &hotplugInfo, Marshal.SizeOf(typeof(StorageHotplugInfo)));

                return(hotplugInfo);
            }
        }
Пример #5
0
        public static StorageHotplugInfo GetHotplugInfo(FileHandle fileHandle)
        {
            unsafe
            {
                StorageHotplugInfo hotplugInfo;

                fileHandle.IoControl(IoCtlGetHotplugInfo, null, 0, &hotplugInfo, Marshal.SizeOf(typeof(StorageHotplugInfo)));

                return hotplugInfo;
            }
        }
Пример #6
0
        public static string GetDeviceName(FileHandle fhandle)
        {
            using (MemoryAlloc data = new MemoryAlloc(600))
            {
                fhandle.IoControl(IoCtlQueryDeviceName, IntPtr.Zero, 0, data, data.Size);

                MountDevName name = data.ReadStruct <MountDevName>();

                return(data.ReadUnicodeString(MountDevName.NameOffset, name.NameLength / 2));
            }
        }
Пример #7
0
        public static unsafe DiskCacheState GetCacheSetting(FileHandle fileHandle, out bool isPowerProtected)
        {
            DiskCacheSetting diskCacheSetting;

            fileHandle.IoControl(
                IoCtlGetCacheSetting,
                null,
                0,
                &diskCacheSetting,
                DiskCacheSetting.SizeOf
                );

            isPowerProtected = diskCacheSetting.IsPowerProtected;

            return diskCacheSetting.State;
        }
Пример #8
0
        public static unsafe void SetCacheSetting(FileHandle fileHandle, DiskCacheState state, bool isPowerProtected)
        {
            DiskCacheSetting diskCacheSetting;

            diskCacheSetting.Version          = DiskCacheSetting.SizeOf;
            diskCacheSetting.State            = state;
            diskCacheSetting.IsPowerProtected = isPowerProtected;

            fileHandle.IoControl(
                IoCtlSetCacheSetting,
                &diskCacheSetting,
                DiskCacheSetting.SizeOf,
                null,
                0
                );
        }
Пример #9
0
        public static unsafe DiskCacheState GetCacheSetting(FileHandle fileHandle, out bool isPowerProtected)
        {
            DiskCacheSetting diskCacheSetting;

            fileHandle.IoControl(
                IoCtlGetCacheSetting,
                null,
                0,
                &diskCacheSetting,
                DiskCacheSetting.SizeOf
                );

            isPowerProtected = diskCacheSetting.IsPowerProtected;

            return(diskCacheSetting.State);
        }
Пример #10
0
        public static DiskCacheState GetCacheSetting(FileHandle fileHandle, out bool isPowerProtected)
        {
            unsafe
            {
                DiskCacheSetting diskCacheSetting;

                fileHandle.IoControl(
                    IoCtlGetCacheSetting,
                    null,
                    0,
                    &diskCacheSetting,
                    Marshal.SizeOf(typeof(DiskCacheSetting))
                    );

                isPowerProtected = diskCacheSetting.IsPowerProtected;

                return diskCacheSetting.State;
            }
        }
Пример #11
0
        public static void SetCacheSetting(FileHandle fileHandle, DiskCacheState state, bool isPowerProtected)
        {
            unsafe
            {
                DiskCacheSetting diskCacheSetting;

                diskCacheSetting.Version          = Marshal.SizeOf(typeof(DiskCacheSetting));
                diskCacheSetting.State            = state;
                diskCacheSetting.IsPowerProtected = isPowerProtected;

                fileHandle.IoControl(
                    IoCtlSetCacheSetting,
                    &diskCacheSetting,
                    Marshal.SizeOf(typeof(DiskCacheSetting)),
                    null,
                    0
                    );
            }
        }
Пример #12
0
        public static DiskCacheState GetCacheSetting(FileHandle fileHandle, out bool isPowerProtected)
        {
            unsafe
            {
                DiskCacheSetting diskCacheSetting;

                fileHandle.IoControl(
                    IoCtlGetCacheSetting,
                    null,
                    0,
                    &diskCacheSetting,
                    Marshal.SizeOf(typeof(DiskCacheSetting))
                    );

                isPowerProtected = diskCacheSetting.IsPowerProtected;

                return(diskCacheSetting.State);
            }
        }
Пример #13
0
        private static string GetReparsePointTarget(FileHandle fhandle)
        {
            using (MemoryAlloc data = new MemoryAlloc(FileSystem.MaximumReparseDataBufferSize))
            {
                fhandle.IoControl(FileSystem.FsCtlGetReparsePoint, IntPtr.Zero, 0, data, data.Size);

                FileSystem.ReparseDataBuffer buffer = data.ReadStruct <FileSystem.ReparseDataBuffer>();

                // Make sure it is in fact a mount point.
                if (buffer.ReparseTag != (uint)IoReparseTag.MountPoint)
                {
                    Win32.Throw(NtStatus.InvalidParameter);
                }

                return(data.ReadUnicodeString(
                           FileSystem.ReparseDataBuffer.MountPointPathBuffer + buffer.SubstituteNameOffset,
                           buffer.SubstituteNameLength / 2
                           ));
            }
        }
Пример #14
0
        public static unsafe void SetCacheSetting(FileHandle fileHandle, DiskCacheState state, bool isPowerProtected)
        {
            DiskCacheSetting diskCacheSetting;

            diskCacheSetting.Version = DiskCacheSetting.SizeOf;
            diskCacheSetting.State = state;
            diskCacheSetting.IsPowerProtected = isPowerProtected;

            fileHandle.IoControl(
                IoCtlSetCacheSetting,
                &diskCacheSetting,
                DiskCacheSetting.SizeOf,
                null,
                0
                );
        }
Пример #15
0
 public static void EjectMedia(FileHandle fileHandle)
 {
     fileHandle.IoControl(IoCtlEjectMedia, IntPtr.Zero, 0, IntPtr.Zero, 0);
 }
Пример #16
0
        private static string GetReparsePointTarget(FileHandle fhandle)
        {
            using (MemoryAlloc data = new MemoryAlloc(FileSystem.MaximumReparseDataBufferSize))
            {
                fhandle.IoControl(FileSystem.FsCtlGetReparsePoint, IntPtr.Zero, 0, data, data.Size);

                FileSystem.ReparseDataBuffer buffer = data.ReadStruct<FileSystem.ReparseDataBuffer>();

                // Make sure it is in fact a mount point.
                if (buffer.ReparseTag != (uint)IoReparseTag.MountPoint)
                    Win32.Throw(NtStatus.InvalidParameter);

                return data.ReadUnicodeString(
                    FileSystem.ReparseDataBuffer.MountPointPathBuffer + buffer.SubstituteNameOffset,
                    buffer.SubstituteNameLength / 2
                    );
            }
        }
Пример #17
0
 public static void EjectMedia(FileHandle fileHandle)
 {
     fileHandle.IoControl(IoCtlEjectMedia, IntPtr.Zero, 0, IntPtr.Zero, 0);
 }
Пример #18
0
        public KphFeatures KphGetFeatures()
        {
            KphGetFeaturesInput input;
            int features;

            input.Features = &features;
            _fileHandle.IoControl(IoCtlGetFeatures, &input, sizeof(KphGetFeaturesInput), null, 0);

            return((KphFeatures)features);
        }
Пример #19
0
        public static void SetCacheSetting(FileHandle fileHandle, DiskCacheState state, bool isPowerProtected)
        {
            unsafe
            {
                DiskCacheSetting diskCacheSetting;

                diskCacheSetting.Version = Marshal.SizeOf(typeof(DiskCacheSetting));
                diskCacheSetting.State = state;
                diskCacheSetting.IsPowerProtected = isPowerProtected;

                fileHandle.IoControl(
                    IoCtlSetCacheSetting,
                    &diskCacheSetting,
                    Marshal.SizeOf(typeof(DiskCacheSetting)),
                    null,
                    0
                    );
            }
        }
Пример #20
0
        public static string GetDeviceName(FileHandle fhandle)
        {
            using (MemoryAlloc data = new MemoryAlloc(600))
            {
                fhandle.IoControl(IoCtlQueryDeviceName, IntPtr.Zero, 0, data, data.Size);

                MountDevName name = data.ReadStruct<MountDevName>();

                return data.ReadUnicodeString(MountDevName.NameOffset, name.NameLength / 2);
            }
        }
Пример #21
0
        public void ClientCloseHandle(IntPtr handle)
        {
            byte *inData = stackalloc byte[4];

            *(int *)inData = handle.ToInt32();

            _fileHandle.IoControl(CtlCode(Control.ClientCloseHandle), inData, 4, null, 0);
        }