Esempio n. 1
0
    def create_vhd(self, new_vhd_path, new_vhd_type, src_path=None,
                   max_internal_size=0, parent_path=None):
        new_device_id = self._get_vhd_device_id(new_vhd_path)

        vst = vdisk_struct.VIRTUAL_STORAGE_TYPE(
            DeviceId=new_device_id,
            VendorId=w_const.VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT)

        params = vdisk_struct.CREATE_VIRTUAL_DISK_PARAMETERS()
        params.Version = w_const.CREATE_VIRTUAL_DISK_VERSION_2
        params.Version2.MaximumSize = max_internal_size
        params.Version2.ParentPath = parent_path
        params.Version2.SourcePath = src_path
        params.Version2.PhysicalSectorSizeInBytes = (
            VIRTUAL_DISK_DEFAULT_PHYS_SECTOR_SIZE)
        params.Version2.BlockSizeInBytes = (
            w_const.CREATE_VHD_PARAMS_DEFAULT_BLOCK_SIZE)
        params.Version2.SectorSizeInBytes = (
            VIRTUAL_DISK_DEFAULT_SECTOR_SIZE)

        handle = wintypes.HANDLE()
        create_virtual_disk_flag = CREATE_VIRTUAL_DISK_FLAGS.get(
            new_vhd_type, 0)

        self._run_and_check_output(virtdisk.CreateVirtualDisk,
                                   ctypes.byref(vst),
                                   ctypes.c_wchar_p(new_vhd_path),
                                   0,
                                   None,
                                   create_virtual_disk_flag,
                                   0,
                                   ctypes.byref(params),
                                   None,
                                   ctypes.byref(handle),
                                   cleanup_handle=handle)
Esempio n. 2
0
    def create_pipe(self,
                    security_attributes=None,
                    size=0,
                    inherit_handle=False):
        """Create an anonymous pipe.

        The main advantage of this method over os.pipe is that it allows
        creating inheritable pipe handles (which is flawed on most Python
        versions).
        """
        r = wintypes.HANDLE()
        w = wintypes.HANDLE()

        if inherit_handle and not security_attributes:
            security_attributes = wintypes.SECURITY_ATTRIBUTES()
            security_attributes.bInheritHandle = inherit_handle
            security_attributes.nLength = ctypes.sizeof(security_attributes)

        self._run_and_check_output(
            kernel32.CreatePipe, ctypes.byref(r), ctypes.byref(w),
            ctypes.byref(security_attributes) if security_attributes else None,
            size)

        return r.value, w.value
Esempio n. 3
0
    def _open(self,
              vhd_path,
              open_flag=0,
              open_access_mask=w_const.VIRTUAL_DISK_ACCESS_ALL,
              open_params=None):
        device_id = self._get_vhd_device_id(vhd_path)

        vst = vdisk_struct.VIRTUAL_STORAGE_TYPE(
            DeviceId=device_id,
            VendorId=w_const.VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT)
        handle = wintypes.HANDLE()

        self._run_and_check_output(virtdisk.OpenVirtualDisk, ctypes.byref(vst),
                                   ctypes.c_wchar_p(vhd_path),
                                   open_access_mask, open_flag, open_params,
                                   ctypes.byref(handle))
        return handle
Esempio n. 4
0
# The following flags specify access rights that may be
# requested when opening proccesses.
#
# Allows setting process limits.
PROCESS_SET_QUOTA = 0x0100
# Allows terminating a process.
PROCESS_TERMINATE = 0x0001
# Allows waiting for a process.
SYNCHRONIZE = 0x00100000

# winioctl.h
FILE_DEVICE_DISK = 7

# handleapi.h
INVALID_HANDLE_VALUE = wintypes.HANDLE(-1).value

# minwindef.h
MAX_PATH = 260

# AccCtrl.h
TRUSTEE_IS_NAME = 1
# Indicates a file or directory object.
SE_FILE_OBJECT = 1
# ---------

# ClusApi.h
# ---------
CLUSPROP_SYNTAX_NAME = 262147
CLUSPROP_SYNTAX_ENDMARK = 0
CLUSPROP_SYNTAX_LIST_VALUE_DWORD = 65538