Presentation is loading. Please wait.

Presentation is loading. Please wait.

Input - Output.

Similar presentations


Presentation on theme: "Input - Output."— Presentation transcript:

1 Input - Output

2 Files API Files are too managed with the help of handles. When handle is set it is possible to use it in input/output operations That goes for all I/O operations

3 CreateFile Returns file handle? What about: streams disks
communications pipes etc?

4

5 lpFileName – file name dwDesiredAccess – generic access rights dwShareMode – sharing mode lpSecurityAttributes – inheritant rights dwCreationDisposition – creation mode dwFlagsAndAttributes – flags and attributes hTemplateFile – template handle

6 dwDesiredAccess Shows what can be done with file: GENERIC_READ
GENERIC_WRITE GENERIC_EXECUTE GENERIC_ALL

7 dwShareMode Sharing mode of the file or device:
0 – file cannot be shared until handle is closed FILE_SHARE_READ FILE_SHARE_WRITE FILE_SHARE_DELETE

8 lpSecurityAttributes – saugumo požymis
Protects against unwanted access NULL – handle cannot be inherited by child processes Pointer to SECURITY_ATTRIBUTES pointer to SECURITY_DESCRIPTOR recommended not to modify structure directly

9 dwCreationDisposition
Action to take: CREATE_ALWAYS CREATE_NEW OPEN_ALWAYS OPEN_EXISTING TRUNCATE_EXISTING requires GENERIC_WRITE

10 dwFlagsAndAttributes
File or device flags and attributes. Some flags and attributes apply to files only 0 – device is not a file Other most common flags and attributes: FILE_ATTRIBUTE_NORMAL FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_READONLY FILE_ATTRIBUTE_ARCHIVE

11 hTemplateFile GENERIC_READ
Supplies file attributes for file being created NULL – if not used Ignored when opening existing file

12 CreateFile2

13 ReadFile

14 ReadFileEx

15 Overlapped I/O Asynchronous I/O Complexity OVERLAPPED structure
FileIOCompletionRoutine callback function

16

17

18 WriteFile

19 WriteFileEx

20 File attributes (GetFileAttributes)
Commonly used attributes: FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_NORMAL FILE_ATTRIBUTE_READONLY FILE_ATTRIBUTE_SYSTEM

21 CopyFile lpExistingFileName – name of an existing file
lpNewFileName – name of new file bFailIfExists – if TRUE existing file will not be overwritten

22 CopyFile2

23 CopyFileEx (1)

24 CopyFileEx (2) lpProgressRoutine – callback function (CopyProgressRoutine) lpData – argument to be passed to callback function (can be NULL) pbCancel – operation canceled if it is set to TRUE dwCopyFlags – specify, how file is to be copied

25 CopyProgressRoutine (1)

26 CopyProgressRoutine (2)
TotalFileSize – file size in bytes TotalBytesTransferred – number of bytes already transferred StreamSize – size of current stream in bytes SteramBytesTransferred – number of bytes already transferred from current stream dwStreamNumber – handle to current stream dwCallbackReason – reason this function was called hSourceFile – handle to the source file hDestinationFile – handle to the destination file lpData – data from CopyFileEx function

27 dwCallbackReason There are two reasons:
CALLBACK_CHUNK_FINISHED – part of data was copied CALLBACK_STREAM_SWITCH – another stream created and is about to be copied

28 CopyProgressRoutine (3)
This function returns: PROGRESS_CONTINUE – continue copying PROGRESS_CANCEL – cancel copying and delete destination file PROGRESS_STOP – stop copying (can be restarted later) PROGRES_QUIET – continue copying without invoking callback function

29 MoveFile[Ex]

30 DeleteFile & RemoveDirectory

31 Other features Enumeration Locking Encoding Archiving Memory-mapping
etc.

32 CloseHandle Handles must be closed
When program is closing, OS automatically closes all associated handles expensive operation handle leak For sockets – closesocket For registry keys - RegCloseKey

33 Handle leaks When closing handle fails: Memory isn’t freed
Kernel keeps all information about handle Sluggish system Crash


Download ppt "Input - Output."

Similar presentations


Ads by Google