Module: Chef::ReservedNames::Win32::API::File

Extended by:
Chef::ReservedNames::Win32::API
Includes:
Security, System
Included in:
File::Info, ReservedNames::Win32::File, ReservedNames::Win32::File
Defined in:
lib/chef/win32/api/file.rb

Defined Under Namespace

Classes: BY_HANDLE_FILE_INFORMATION, FILETIME, REPARSE_DATA_BUFFER, REPARSE_DATA_BUFFER_GENERIC, REPARSE_DATA_BUFFER_MOUNT_POINT, REPARSE_DATA_BUFFER_SYMBOLIC_LINK, REPARSE_DATA_BUFFER_UNION, SECURITY_ATTRIBUTES, WIN32_FIND_DATA

Constant Summary collapse

FILE_ATTRIBUTE_READONLY =

Win32 API Constants

0x00000001
FILE_ATTRIBUTE_HIDDEN =
0x00000002
FILE_ATTRIBUTE_SYSTEM =
0x00000004
FILE_ATTRIBUTE_DIRECTORY =
0x00000010
FILE_ATTRIBUTE_ARCHIVE =
0x00000020
FILE_ATTRIBUTE_DEVICE =
0x00000040
FILE_ATTRIBUTE_NORMAL =
0x00000080
FILE_ATTRIBUTE_TEMPORARY =
0x00000100
FILE_ATTRIBUTE_SPARSE_FILE =
0x00000200
FILE_ATTRIBUTE_REPARSE_POINT =
0x00000400
FILE_ATTRIBUTE_COMPRESSED =
0x00000800
FILE_ATTRIBUTE_OFFLINE =
0x00001000
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED =
0x00002000
FILE_ATTRIBUTE_ENCRYPTED =
0x00004000
FILE_ATTRIBUTE_VIRTUAL =
0x00010000
INVALID_FILE_ATTRIBUTES =
0xFFFFFFFF
FILE_FLAG_WRITE_THROUGH =
0x80000000
FILE_FLAG_OVERLAPPED =
0x40000000
FILE_FLAG_NO_BUFFERING =
0x20000000
FILE_FLAG_RANDOM_ACCESS =
0x10000000
FILE_FLAG_SEQUENTIAL_SCAN =
0x08000000
FILE_FLAG_DELETE_ON_CLOSE =
0x04000000
FILE_FLAG_BACKUP_SEMANTICS =
0x02000000
FILE_FLAG_POSIX_SEMANTICS =
0x01000000
FILE_FLAG_OPEN_REPARSE_POINT =
0x00200000
FILE_FLAG_OPEN_NO_RECALL =
0x00100000
FILE_FLAG_FIRST_PIPE_INSTANCE =
0x00080000
INVALID_HANDLE_VALUE =
0xFFFFFFFF
MAX_PATH =
260
0x1
FILE_NAME_NORMALIZED =
0x0
FILE_NAME_OPENED =
0x8
FILE_SHARE_READ =

TODO add the rest of these CONSTS

0x00000001
OPEN_EXISTING =
3
FILE_DEVICE_BEEP =

DeviceIoControl control codes


0x00000001
FILE_DEVICE_CD_ROM =
0x00000002
FILE_DEVICE_CD_ROM_FILE_SYSTEM =
0x00000003
FILE_DEVICE_CONTROLLER =
0x00000004
0x00000005
FILE_DEVICE_DFS =
0x00000006
FILE_DEVICE_DISK =
0x00000007
FILE_DEVICE_DISK_FILE_SYSTEM =
0x00000008
FILE_DEVICE_FILE_SYSTEM =
0x00000009
FILE_DEVICE_INPORT_PORT =
0x0000000a
FILE_DEVICE_KEYBOARD =
0x0000000b
FILE_DEVICE_MAILSLOT =
0x0000000c
FILE_DEVICE_MIDI_IN =
0x0000000d
FILE_DEVICE_MIDI_OUT =
0x0000000e
FILE_DEVICE_MOUSE =
0x0000000f
FILE_DEVICE_MULTI_UNC_PROVIDER =
0x00000010
FILE_DEVICE_NAMED_PIPE =
0x00000011
FILE_DEVICE_NETWORK =
0x00000012
FILE_DEVICE_NETWORK_BROWSER =
0x00000013
FILE_DEVICE_NETWORK_FILE_SYSTEM =
0x00000014
FILE_DEVICE_NULL =
0x00000015
FILE_DEVICE_PARALLEL_PORT =
0x00000016
FILE_DEVICE_PHYSICAL_NETCARD =
0x00000017
FILE_DEVICE_PRINTER =
0x00000018
FILE_DEVICE_SCANNER =
0x00000019
FILE_DEVICE_SERIAL_MOUSE_PORT =
0x0000001a
FILE_DEVICE_SERIAL_PORT =
0x0000001b
FILE_DEVICE_SCREEN =
0x0000001c
FILE_DEVICE_SOUND =
0x0000001d
FILE_DEVICE_STREAMS =
0x0000001e
FILE_DEVICE_TAPE =
0x0000001f
FILE_DEVICE_TAPE_FILE_SYSTEM =
0x00000020
FILE_DEVICE_TRANSPORT =
0x00000021
FILE_DEVICE_UNKNOWN =
0x00000022
FILE_DEVICE_VIDEO =
0x00000023
FILE_DEVICE_VIRTUAL_DISK =
0x00000024
FILE_DEVICE_WAVE_IN =
0x00000025
FILE_DEVICE_WAVE_OUT =
0x00000026
FILE_DEVICE_8042_PORT =
0x00000027
FILE_DEVICE_NETWORK_REDIRECTOR =
0x00000028
FILE_DEVICE_BATTERY =
0x00000029
FILE_DEVICE_BUS_EXTENDER =
0x0000002a
FILE_DEVICE_MODEM =
0x0000002b
FILE_DEVICE_VDM =
0x0000002c
FILE_DEVICE_MASS_STORAGE =
0x0000002d
FILE_DEVICE_SMB =
0x0000002e
FILE_DEVICE_KS =
0x0000002f
FILE_DEVICE_CHANGER =
0x00000030
FILE_DEVICE_SMARTCARD =
0x00000031
FILE_DEVICE_ACPI =
0x00000032
FILE_DEVICE_DVD =
0x00000033
FILE_DEVICE_FULLSCREEN_VIDEO =
0x00000034
FILE_DEVICE_DFS_FILE_SYSTEM =
0x00000035
FILE_DEVICE_DFS_VOLUME =
0x00000036
FILE_DEVICE_SERENUM =
0x00000037
FILE_DEVICE_TERMSRV =
0x00000038
FILE_DEVICE_KSEC =
0x00000039
FILE_DEVICE_FIPS =
0x0000003A
FILE_DEVICE_INFINIBAND =
0x0000003B
FILE_DEVICE_VMBUS =
0x0000003E
FILE_DEVICE_CRYPT_PROVIDER =
0x0000003F
FILE_DEVICE_WPD =
0x00000040
FILE_DEVICE_BLUETOOTH =
0x00000041
FILE_DEVICE_MT_COMPOSITE =
0x00000042
FILE_DEVICE_MT_TRANSPORT =
0x00000043
FILE_DEVICE_BIOMETRIC =
0x00000044
FILE_DEVICE_PMI =
0x00000045
METHOD_BUFFERED =

Methods

0
METHOD_IN_DIRECT =
1
METHOD_OUT_DIRECT =
2
METHOD_NEITHER =
3
METHOD_DIRECT_TO_HARDWARE =
METHOD_IN_DIRECT
METHOD_DIRECT_FROM_HARDWARE =
METHOD_OUT_DIRECT
FILE_ANY_ACCESS =

Access

0
FILE_SPECIAL_ACCESS =
FILE_ANY_ACCESS
FILE_READ_ACCESS =
0x0001
FILE_WRITE_ACCESS =
0x0002
FSCTL_GET_REPARSE_POINT =
CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS)
IO_REPARSE_TAG_MOUNT_POINT =

Reparse point tags

0xA0000003
IO_REPARSE_TAG_HSM =
0xC0000004
IO_REPARSE_TAG_HSM2 =
0x80000006
IO_REPARSE_TAG_SIS =
0x80000007
IO_REPARSE_TAG_WIM =
0x80000008
IO_REPARSE_TAG_CSV =
0x80000009
IO_REPARSE_TAG_DFS =
0x8000000A
0xA000000C
IO_REPARSE_TAG_DFSR =
0x80000012
MAXIMUM_REPARSE_DATA_BUFFER_SIZE =
16*1024

Constants included from System

System::PRODUCT_BUSINESS, System::PRODUCT_BUSINESS_N, System::PRODUCT_CLUSTER_SERVER, System::PRODUCT_DATACENTER_SERVER, System::PRODUCT_DATACENTER_SERVER_CORE, System::PRODUCT_DATACENTER_SERVER_CORE_V, System::PRODUCT_DATACENTER_SERVER_V, System::PRODUCT_ENTERPRISE, System::PRODUCT_ENTERPRISE_E, System::PRODUCT_ENTERPRISE_N, System::PRODUCT_ENTERPRISE_SERVER, System::PRODUCT_ENTERPRISE_SERVER_CORE, System::PRODUCT_ENTERPRISE_SERVER_CORE_V, System::PRODUCT_ENTERPRISE_SERVER_IA64, System::PRODUCT_ENTERPRISE_SERVER_V, System::PRODUCT_HOME_BASIC, System::PRODUCT_HOME_BASIC_E, System::PRODUCT_HOME_BASIC_N, System::PRODUCT_HOME_PREMIUM, System::PRODUCT_HOME_PREMIUM_E, System::PRODUCT_HOME_PREMIUM_N, System::PRODUCT_HOME_PREMIUM_SERVER, System::PRODUCT_HOME_SERVER, System::PRODUCT_HYPERV, System::PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT, System::PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING, System::PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY, System::PRODUCT_PROFESSIONAL, System::PRODUCT_PROFESSIONAL_E, System::PRODUCT_PROFESSIONAL_N, System::PRODUCT_SB_SOLUTION_SERVER, System::PRODUCT_SERVER_FOR_SMALLBUSINESS, System::PRODUCT_SERVER_FOR_SMALLBUSINESS_V, System::PRODUCT_SERVER_FOUNDATION, System::PRODUCT_SMALLBUSINESS_SERVER, System::PRODUCT_SOLUTION_EMBEDDEDSERVER, System::PRODUCT_STANDARD_SERVER, System::PRODUCT_STANDARD_SERVER_CORE, System::PRODUCT_STANDARD_SERVER_CORE_V, System::PRODUCT_STANDARD_SERVER_V, System::PRODUCT_STARTER, System::PRODUCT_STARTER_E, System::PRODUCT_STARTER_N, System::PRODUCT_STORAGE_ENTERPRISE_SERVER, System::PRODUCT_STORAGE_EXPRESS_SERVER, System::PRODUCT_STORAGE_STANDARD_SERVER, System::PRODUCT_STORAGE_WORKGROUP_SERVER, System::PRODUCT_ULTIMATE, System::PRODUCT_ULTIMATE_E, System::PRODUCT_ULTIMATE_N, System::PRODUCT_UNDEFINED, System::PRODUCT_WEB_SERVER, System::PRODUCT_WEB_SERVER_CORE, System::SM_SERVERR2, System::VER_NT_DOMAIN_CONTROLLER, System::VER_NT_SERVER, System::VER_NT_WORKSTATION, System::VER_SUITE_BACKOFFICE, System::VER_SUITE_BLADE, System::VER_SUITE_COMPUTE_SERVER, System::VER_SUITE_DATACENTER, System::VER_SUITE_EMBEDDEDNT, System::VER_SUITE_ENTERPRISE, System::VER_SUITE_PERSONAL, System::VER_SUITE_SINGLEUSERTS, System::VER_SUITE_SMALLBUSINESS, System::VER_SUITE_SMALLBUSINESS_RESTRICTED, System::VER_SUITE_STORAGE_SERVER, System::VER_SUITE_TERMINAL, System::VER_SUITE_WH_SERVER

Constants included from Security

Security::ACCESS_ALLOWED_ACE_TYPE, Security::ACCESS_ALLOWED_CALLBACK_ACE_TYPE, Security::ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE, Security::ACCESS_ALLOWED_COMPOUND_ACE_TYPE, Security::ACCESS_ALLOWED_OBJECT_ACE_TYPE, Security::ACCESS_DENIED_ACE_TYPE, Security::ACCESS_DENIED_CALLBACK_ACE_TYPE, Security::ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE, Security::ACCESS_DENIED_OBJECT_ACE_TYPE, Security::ACCESS_MAX_MS_ACE_TYPE, Security::ACCESS_MAX_MS_OBJECT_ACE_TYPE, Security::ACCESS_MAX_MS_V2_ACE_TYPE, Security::ACCESS_MAX_MS_V3_ACE_TYPE, Security::ACCESS_MAX_MS_V4_ACE_TYPE, Security::ACCESS_MAX_MS_V5_ACE_TYPE, Security::ACCESS_MIN_MS_ACE_TYPE, Security::ACCESS_MIN_MS_OBJECT_ACE_TYPE, Security::ACCESS_SYSTEM_SECURITY, Security::ACL_REVISION, Security::ACL_REVISION1, Security::ACL_REVISION2, Security::ACL_REVISION3, Security::ACL_REVISION4, Security::ACL_REVISION_DS, Security::CONTAINER_INHERIT_ACE, Security::DACL_SECURITY_INFORMATION, Security::DELETE, Security::FAILED_ACCESS_ACE_FLAG, Security::FILE_ADD_FILE, Security::FILE_ADD_SUBDIRECTORY, Security::FILE_ALL_ACCESS, Security::FILE_APPEND_DATA, Security::FILE_CREATE_PIPE_INSTANCE, Security::FILE_DELETE_CHILD, Security::FILE_EXECUTE, Security::FILE_GENERIC_EXECUTE, Security::FILE_GENERIC_READ, Security::FILE_GENERIC_WRITE, Security::FILE_LIST_DIRECTORY, Security::FILE_READ_ATTRIBUTES, Security::FILE_READ_DATA, Security::FILE_READ_EA, Security::FILE_TRAVERSE, Security::FILE_WRITE_ATTRIBUTES, Security::FILE_WRITE_DATA, Security::FILE_WRITE_EA, Security::GENERIC_ALL, Security::GENERIC_EXECUTE, Security::GENERIC_READ, Security::GENERIC_WRITE, Security::GROUP_SECURITY_INFORMATION, Security::INHERITED_ACE, Security::INHERIT_ONLY_ACE, Security::LABEL_SECURITY_INFORMATION, Security::MAXDWORD, Security::MAX_ACL_REVISION, Security::MIN_ACL_REVISION, Security::NO_PROPAGATE_INHERIT_ACE, Security::OBJECT_INHERIT_ACE, Security::OWNER_SECURITY_INFORMATION, Security::PROTECTED_DACL_SECURITY_INFORMATION, Security::PROTECTED_SACL_SECURITY_INFORMATION, Security::READ_CONTROL, Security::SACL_SECURITY_INFORMATION, Security::SECURITY_DESCRIPTOR_MIN_LENGTH, Security::SECURITY_DESCRIPTOR_REVISION, Security::SECURITY_DESCRIPTOR_REVISION1, Security::SE_DACL_AUTO_INHERITED, Security::SE_DACL_AUTO_INHERIT_REQ, Security::SE_DACL_DEFAULTED, Security::SE_DACL_PRESENT, Security::SE_DACL_PROTECTED, Security::SE_GROUP_DEFAULTED, Security::SE_OBJECT_TYPE, Security::SE_OWNER_DEFAULTED, Security::SE_PRIVILEGE_ENABLED, Security::SE_PRIVILEGE_ENABLED_BY_DEFAULT, Security::SE_PRIVILEGE_REMOVED, Security::SE_PRIVILEGE_USED_FOR_ACCESS, Security::SE_PRIVILEGE_VALID_ATTRIBUTES, Security::SE_RM_CONTROL_VALID, Security::SE_SACL_AUTO_INHERITED, Security::SE_SACL_AUTO_INHERIT_REQ, Security::SE_SACL_DEFAULTED, Security::SE_SACL_PRESENT, Security::SE_SACL_PROTECTED, Security::SE_SELF_RELATIVE, Security::SID_NAME_USE, Security::SPECIFIC_RIGHTS_ALL, Security::STANDARD_RIGHTS_ALL, Security::STANDARD_RIGHTS_EXECUTE, Security::STANDARD_RIGHTS_READ, Security::STANDARD_RIGHTS_REQUIRED, Security::STANDARD_RIGHTS_WRITE, Security::SUCCESSFUL_ACCESS_ACE_FLAG, Security::SYNCHRONIZE, Security::SYSTEM_ALARM_ACE_TYPE, Security::SYSTEM_ALARM_CALLBACK_ACE_TYPE, Security::SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE, Security::SYSTEM_ALARM_OBJECT_ACE_TYPE, Security::SYSTEM_AUDIT_ACE_TYPE, Security::SYSTEM_AUDIT_CALLBACK_ACE_TYPE, Security::SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE, Security::SYSTEM_AUDIT_OBJECT_ACE_TYPE, Security::SYSTEM_MANDATORY_LABEL_ACE_TYPE, Security::TOKEN_ADJUST_DEFAULT, Security::TOKEN_ADJUST_GROUPS, Security::TOKEN_ADJUST_PRIVILEGES, Security::TOKEN_ADJUST_SESSIONID, Security::TOKEN_ALL_ACCESS, Security::TOKEN_ASSIGN_PRIMARY, Security::TOKEN_DUPLICATE, Security::TOKEN_IMPERSONATE, Security::TOKEN_INFORMATION_CLASS, Security::TOKEN_QUERY, Security::TOKEN_QUERY_SOURCE, Security::TOKEN_READ, Security::UNPROTECTED_DACL_SECURITY_INFORMATION, Security::UNPROTECTED_SACL_SECURITY_INFORMATION, Security::VALID_INHERIT_FLAGS, Security::WRITE_DAC, Security::WRITE_OWNER

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.CTL_CODE(device_type, function, method, access) ⇒ Object



161
162
163
# 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

Instance Method Details

#encode_path(path) ⇒ Object

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



461
462
463
464
# File 'lib/chef/win32/api/file.rb', line 461

def encode_path(path)
  path.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR)
  (path_prepender << path).to_wstring
end

#file_handle(path, &block) ⇒ Object

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



490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/chef/win32/api/file.rb', line 490

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) ⇒ Object

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



473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/chef/win32/api/file.rb', line 473

def file_search_handle(path, &block)
  begin
    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_prependerObject



466
467
468
# File 'lib/chef/win32/api/file.rb', line 466

def path_prepender
  "\\\\?\\"
end

#retrieve_file_info(file_name) ⇒ Object



520
521
522
523
524
525
526
527
528
529
530
# File 'lib/chef/win32/api/file.rb', line 520

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


505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/chef/win32/api/file.rb', line 505

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