# module Chef::ReservedNames::Win32::API::File

### Constants

FILE_ANY_ACCESS

  Access

FILE_ATTRIBUTE_ARCHIVE
FILE_ATTRIBUTE_COMPRESSED
FILE_ATTRIBUTE_DEVICE
FILE_ATTRIBUTE_DIRECTORY
FILE_ATTRIBUTE_ENCRYPTED
FILE_ATTRIBUTE_HIDDEN
FILE_ATTRIBUTE_NORMAL
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
FILE_ATTRIBUTE_OFFLINE
FILE_ATTRIBUTE_READONLY

  Win32 API Constants

FILE_ATTRIBUTE_REPARSE_POINT
FILE_ATTRIBUTE_SPARSE_FILE
FILE_ATTRIBUTE_SYSTEM
FILE_ATTRIBUTE_TEMPORARY
FILE_ATTRIBUTE_VIRTUAL
FILE_DEVICE_8042_PORT
FILE_DEVICE_ACPI
FILE_DEVICE_BATTERY
FILE_DEVICE_BEEP

  DeviceIoControl control codes

FILE_DEVICE_BIOMETRIC
FILE_DEVICE_BLUETOOTH
FILE_DEVICE_BUS_EXTENDER
FILE_DEVICE_CD_ROM
FILE_DEVICE_CD_ROM_FILE_SYSTEM
FILE_DEVICE_CHANGER
FILE_DEVICE_CONTROLLER
FILE_DEVICE_CRYPT_PROVIDER
FILE_DEVICE_DATALINK
FILE_DEVICE_DFS
FILE_DEVICE_DFS_FILE_SYSTEM
FILE_DEVICE_DFS_VOLUME
FILE_DEVICE_DISK
FILE_DEVICE_DISK_FILE_SYSTEM
FILE_DEVICE_DVD
FILE_DEVICE_FILE_SYSTEM
FILE_DEVICE_FIPS
FILE_DEVICE_FULLSCREEN_VIDEO
FILE_DEVICE_INFINIBAND
FILE_DEVICE_INPORT_PORT
FILE_DEVICE_KEYBOARD
FILE_DEVICE_KS
FILE_DEVICE_KSEC
FILE_DEVICE_MAILSLOT
FILE_DEVICE_MASS_STORAGE
FILE_DEVICE_MIDI_IN
FILE_DEVICE_MIDI_OUT
FILE_DEVICE_MODEM
FILE_DEVICE_MOUSE
FILE_DEVICE_MT_COMPOSITE
FILE_DEVICE_MT_TRANSPORT
FILE_DEVICE_MULTI_UNC_PROVIDER
FILE_DEVICE_NAMED_PIPE
FILE_DEVICE_NETWORK
FILE_DEVICE_NETWORK_BROWSER
FILE_DEVICE_NETWORK_FILE_SYSTEM
FILE_DEVICE_NETWORK_REDIRECTOR
FILE_DEVICE_NULL
FILE_DEVICE_PARALLEL_PORT
FILE_DEVICE_PHYSICAL_NETCARD
FILE_DEVICE_PMI
FILE_DEVICE_PRINTER
FILE_DEVICE_SCANNER
FILE_DEVICE_SCREEN
FILE_DEVICE_SERENUM
FILE_DEVICE_SERIAL_MOUSE_PORT
FILE_DEVICE_SERIAL_PORT
FILE_DEVICE_SMARTCARD
FILE_DEVICE_SMB
FILE_DEVICE_SOUND
FILE_DEVICE_STREAMS
FILE_DEVICE_TAPE
FILE_DEVICE_TAPE_FILE_SYSTEM
FILE_DEVICE_TERMSRV
FILE_DEVICE_TRANSPORT
FILE_DEVICE_UNKNOWN
FILE_DEVICE_VDM
FILE_DEVICE_VIDEO
FILE_DEVICE_VIRTUAL_DISK
FILE_DEVICE_VMBUS
FILE_DEVICE_WAVE_IN
FILE_DEVICE_WAVE_OUT
FILE_DEVICE_WPD
FILE_FLAG_BACKUP_SEMANTICS
FILE_FLAG_DELETE_ON_CLOSE
FILE_FLAG_FIRST_PIPE_INSTANCE
FILE_FLAG_NO_BUFFERING
FILE_FLAG_OPEN_NO_RECALL
FILE_FLAG_OPEN_REPARSE_POINT
FILE_FLAG_OVERLAPPED
FILE_FLAG_POSIX_SEMANTICS
FILE_FLAG_RANDOM_ACCESS
FILE_FLAG_SEQUENTIAL_SCAN
FILE_FLAG_WRITE_THROUGH
FILE_NAME_NORMALIZED
FILE_NAME_OPENED
FILE_READ_ACCESS
FILE_SHARE_READ

  TODO add the rest of these CONSTS

FILE_SPECIAL_ACCESS
FILE_WRITE_ACCESS
FSCTL_GET_REPARSE_POINT
INVALID_FILE_ATTRIBUTES
INVALID_HANDLE_VALUE
IO_REPARSE_TAG_CSV
IO_REPARSE_TAG_DFS
IO_REPARSE_TAG_DFSR
IO_REPARSE_TAG_HSM
IO_REPARSE_TAG_HSM2
IO_REPARSE_TAG_MOUNT_POINT

  Reparse point tags

IO_REPARSE_TAG_SIS
IO_REPARSE_TAG_SYMLINK
IO_REPARSE_TAG_WIM
MAXIMUM_REPARSE_DATA_BUFFER_SIZE
MAX_PATH
METHOD_BUFFERED

  Methods

METHOD_DIRECT_FROM_HARDWARE
METHOD_DIRECT_TO_HARDWARE
METHOD_IN_DIRECT
METHOD_NEITHER
METHOD_OUT_DIRECT
OPEN_EXISTING
SYMBOLIC_LINK_FLAG_DIRECTORY

### Public Class Methods

CTL_CODE( device_type, function, method, access ) click to toggle source

    # File lib/chef/win32/api/file.rb, line 161
    def self.CTL_CODE( device_type, function, method, access )
      (device_type << 16) | (access << 14) | (function << 2) | method
    end

### Public Instance Methods

encode_path(path) click to toggle source

takes the given path pre-pends “\?" and UTF-16LE encodes it. Used to prepare paths to be passed to the *W vesion of WinAPI File functions

    # File lib/chef/win32/api/file.rb, line 461
    def encode_path(path)
      (path_prepender << path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR)).to_wstring
    end

file_handle(path, &block) click to toggle source

retrieves a file handle and passes it to +&block+ along with the find_data. also ensures the handle is closed on exit of the block

    # File lib/chef/win32/api/file.rb, line 496
    def file_handle(path, &block)
      begin
        path = encode_path(path)
        handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ,
                              nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, nil)

        if handle == INVALID_HANDLE_VALUE
          Chef::ReservedNames::Win32::Error.raise!
        end
        block.call(handle)
      ensure
        CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE
      end
    end

file_search_handle(path, &block) click to toggle source

retrieves a file search handle and passes it to +&block+ along with the find_data. also ensures the handle is closed on exit of the block

    # File lib/chef/win32/api/file.rb, line 472
    def file_search_handle(path, &block)
      begin
        # Workaround for CHEF-4419:
        # Make sure paths starting with "/" has a drive letter
        # assigned from the current working diretory.
        # Note: With CHEF-4427 this issue will be fixed with a
        # broader fix to map all the paths starting with "/" to
        # SYSTEM_DRIVE on windows.
        path = ::File.expand_path(path) if path.start_with? "/"
        path = encode_path(path)
        find_data = WIN32_FIND_DATA.new
        handle = FindFirstFileW(path, find_data)
        if handle == INVALID_HANDLE_VALUE
          Chef::ReservedNames::Win32::Error.raise!
        end
        block.call(handle, find_data)
      ensure
        FindClose(handle) if handle && handle != INVALID_HANDLE_VALUE
      end
    end

path_prepender() click to toggle source

    # File lib/chef/win32/api/file.rb, line 465
    def path_prepender
      "\\\\?\\"
    end

retrieve_file_info(file_name) click to toggle source

    # File lib/chef/win32/api/file.rb, line 526
    def retrieve_file_info(file_name)
      file_information = nil
      file_handle(file_name) do |handle|
        file_information = BY_HANDLE_FILE_INFORMATION.new
        success = GetFileInformationByHandle(handle, file_information)
        if success == 0
          Chef::ReservedNames::Win32::Error.raise!
        end
      end
      file_information
    end

symlink_file_handle(path, &block) click to toggle source

    # File lib/chef/win32/api/file.rb, line 511
    def symlink_file_handle(path, &block)
      begin
        path = encode_path(path)
        handle = CreateFileW(path, FILE_READ_EA, FILE_SHARE_READ,
                              nil, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, nil)

        if handle == INVALID_HANDLE_VALUE
          Chef::ReservedNames::Win32::Error.raise!
        end
        block.call(handle)
      ensure
        CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE
      end
    end