File Management.

Slides:



Advertisements
Similar presentations
MUMS API CUEL IMAN MLIM 2010/11/18. CUEL Module Function Description – This function allows the caller to request that the module name be added to the.
Advertisements

Secure Operating Systems Lesson 3: OS Structures.
Win32 Programming Lesson 5: Error Codes. Before We Begin  Much of the time in this class we’ll be calling Win32 Functions  However, sometimes they’re.
1 JMH Associates © 2004, All rights reserved Chapter 11 Interprocess Communication.
1 JMH Associates © 2004, All rights reserved Chapter 6 Process Management.
Recitation summary What you should know for the exam
Web siteWeb site ExamplesExamples 1 Mode of Operation Protected mode  4 GB  32-bit address  Windows, Linux Real-address mode  1 MB space  20-bit address.
1 JMH Associates © 2004, All rights reserved Chapter 15 Windows System Security.
2: OS Structures 1 Jerry Breecher OPERATING SYSTEMS STRUCTURES.
7-1 JMH Associates © 2003, All rights reserved Designing and Developing Reliable, Scaleable Multithreaded Windows Applications Chapter 10 Supplement Advanced.
WinAPI i System Plików 1. Volume Management 2. Disk Management 3. Directory Management 4. File Management Autor: Tomasz Jurkiewicz.
1 JMH Associates © 2004, All rights reserved Chapters 2-3 Input/Output With File and Directory Processing.
© 2004 Microsoft Corporation. All rights reserved. 1 User / Kernel Communication Model.
1 JMH Associates © 2004, All rights reserved Chapter 15 Asynchronous Input/Output.
1 JMH Associates © 2004, All rights reserved Chapter 1 Getting Started with Win32/64.
Week 12: File System Issues Pascal Meunier, Ph.D., M.Sc., CISSP April 4, 2007 Developed thanks to the support of Symantec Corporation, NSF SFS Capacity.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
Using WinUSB for your USB Devices
Chapter 8 File Management
Input/Output With File and Directory Processing. – 2 – OBJECTIVES Describe the Windows file systems (compared to UNIX/Linux) Perform sequential file processing.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS8: File System 8.5. Windows File and Directory.
Introduction (Processes and Files)
 Mathew George Sr. Software Engineer Microsoft Corporation ES23.
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
2.3 InterProcess Communication (IPC)
Win32 Programming Lesson 7: Kernel Objects. Abstract  Many of the concepts we’ll look at today won’t make complete sense until you use them  However,
Win32 Programming Lesson 18: More Memory Mapped Files and the HEAP (Finally, cool stuff!)
Operating Systems COMP 4850/CISG 5550 File Systems Files Dr. James Money.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS A: Windows Networking A.3. Microsoft-specific.
 For an application programmer, the operating system interface is most important  The functions provided by the OS  Abstract resources that are available.
Memory Management II CS Spring Overview Logical Addressing and Virtual Memory –Logical to Linear Address Mapping –Linear to Physical Address.

Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS2: Operating System Principles 2.4. The Windows.
Win32 Programming Lesson 17: Memory Mapped Files (Finally, cool stuff again, all this work is getting tedious!)
File Systems cs550 Operating Systems David Monismith.
The File System & Directory System Module Presented By: Erhan Atilla Avinal Maitreya Natu Shivkundan Singh Tej Tam H. Vu.
System Programming Course introduction Getting Started …
Other Thread Synchronization Functions 井民全製作. Introduction.
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2.
OS features can be described by considering the most important resources that a modern OS manages: Memory: The OS manages a large, flat, virtual memory.
Memory Mapped I/O Gregory Mortensen CSIS 4330, Advanced Windows Programming – UVSC.
Lecture Lecture 25 Review of Last Lecture DLL’s DLL’s Processes Processes Threads Threads Memory Management Memory Management.
Window Threads Chapter 7 Windows Thread Management.
Lecture 3: System Calls & API Standards
Input/Output With File and Directory Processing
Mario Tayah and Jim Fawcett CSE 775 – Distributed Objects Spring 2007
File Management Mario Tayah and Jim Fawcett
Windows Programming Lecture 09.
Lecture 4: Operating System Structures
Z502 File System Contains: Disk Structure Description System Calls
CSE451 I/O Systems and the Full I/O Path Autumn 2002
Windows Concurrency Concepts and APIs
This pointer, Dynamic memory allocation, Constructors and Destructor
Using the Operating System
Windows APIs File Processing Copyright © 2016 Curt Hill.
Files in Windows API David Halbig Lopez.
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
files Dr. Bhargavi Goswami Department of Computer Science
Multi-modules programming
Input - Output.
Console A presentation by Inti Vincenzo Pizzoni.
Windows APIs Some odds and ends Copyright © 1997 – 2016 Curt Hill.
OPERATING SYSTEMS STRUCTURES
Mario Tayah and Jim Fawcett CSE775 – Distributed Objects Spring 2007
The CreateFile Function
The File Manager Implementation issues
Operating systems (OS) This can be done by trap routine.
Memory allocation.
Presentation transcript:

File Management

What is File? File I/O device: File stream Directory Physical disk Volume Console buffer Tape drive Communications resource Mailslot Pipe

HANDLE WINAPI CreateFile( _In_     LPCTSTR     lpFileName, _In_     DWORD       dwDesiredAccess, _In_     DWORD       dwShareMode, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _In_     DWORD       dwCreationDisposition, _In_     DWORD       dwFlagsAndAttributes, _In_opt_ HANDLE   hTemplateFile);

lpFileName The name of the file or device to be created or opened. Name can have either forward slashes (/) or backslashes (\) used.

dwDesiredAccess Requested access to the file or device: GENERIC_READ GENERIC_WRITE GENERIC_EXECUTE GENERIC_ALL Etc. If zero, querying some metadata available

dwShareMode Prevent sharing FILE_SHARE_DELETE Subsequent delete access Prevent sharing FILE_SHARE_DELETE Subsequent delete access FILE_SHARE_READ Subsequent read access FILE_SHARE_WRITE Subsequent write access

lpSecurityAttributes A pointer to a SECURITY_ATTRIBUTES Can be NULL (default security descriptor will be used) Child process can’t inherit file handle

dwCreationDisposition What action should be taken: CREATE_ALWAYS Allways creates file CREATE_NEW Creates file if not existing OPEN_ALWAYS Allways opens file OPEN_EXISTING Opens file if existing TRUNCATE_EXISTING Opens and clears file

dwFlagsAndAttributes FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_ENCRYPTED FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_NORMAL 20 more…

hTemplateFile Handle to a template file - supplies file attributes and extended attributes

Is there something simple? HANDLE WINAPI CreateFile2( _In_     LPCWSTR lpFileName, _In_     DWORD dwDesiredAccess, _In_     DWORD dwShareMode, _In_     DWORD dwCreationDisposition, _In_opt_ LPCREATEFILE2_EXTENDED_PARAMETERS pCreateExParams);

Copy, transfer and renaming CopyFile CopyFile2 CopyFileEx

CopyFile lpExistingFileName – pointer to string lpNewFileName – pointer to string bFailIfExists – if TRUE, existing file will be not overwritten

CopyFileEx (1)

CopyFileEx (2) lpProgressRoutine – CALLBACK function, called after portion of file is copied lpData – argument to be passed to the CALLBACK function (can be NULL) pbCancel – if it becames TRUE during copy operation, operation is canceled dwCopyFlags – specify how the file is to be copied

dwCopyFlags COPY_FILE_ALLOW_DECRYPTED_DESTINATION COPY_FILE_FAIL_IF_EXISTS COPY_FILE_OPEN_SOURCE_FOR_WRITE COPY_FILE_RESTARTABLE

CopyProgressRoutine (1)

CopyProgressRoutine (2) TotalFileSize – file size in bytes TotalBytesTransferred – total transfered bytes StreamSize – current stream size in bytes StreamBytesTransferred – transfered bytes in stream dwStreamNumber – handle to current stream dwCallbackReason – reason why function was called hSourceFile – handle to source file hDestinationFile – handle to destination file lpData – argument from CopyFileEx function

dwCallbackReason CALLBACK_CHUNK_FINISHED CALLBACK_STREAM_SWITCH

CopyProgressRoutine (3) PROGRESS_CONTINUE PROGRESS_CANCEL PROGRESS_STOP PROGRESS_QUIET

MoveFile[Ex]

dwFlags MOVEFILE_COPY_ALLOWED MOVEFILE_CREATE_HARDLINK reserved MOVEFILE_DELAY_UNTIL_REBOOT MOVEFILE_FAIL_IF_NOT_TRACKABLE MOVEFILE_REPLACE_EXISTING MOVEFILE_WRITE_THROUGH

DeleteFile & RemoveDirectory

ReadFile BOOL WINAPI ReadFile( _In_ HANDLE hFile, _Out_ LPVOID lpBuffer, _In_ DWORD nNumberOfBytesToRead, _Out_opt_ LPDWORD lpNumberOfBytesRead, _Inout_opt_ LPOVERLAPPED lpOverlapped);

ReadFileEx BOOL WINAPI ReadFileEx( _In_ HANDLE hFile, _Out_opt_ LPVOID lpBuffer, _In_ DWORD nNumberOfBytesToRead, _Inout_ LPOVERLAPPED lpOverlapped, _In_ LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);

OVERLAPPED Structure to contain information for asynchronous (or overlapped) I/O typedef struct _OVERLAPPED { ULONG_PTR Internal; ULONG_PTR InternalHigh; union { struct { DWORD Offset; DWORD OffsetHigh; }; PVOID  Pointer; HANDLE    hEvent; } OVERLAPPED, *LPOVERLAPPED;

WriteFile BOOL WINAPI WriteFile( _In_ HANDLE hFile, _In_ LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped);

WriteFileEx BOOL WINAPI WriteFileEx( _In_ HANDLE hFile, _In_opt_ LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Inout_ LPOVERLAPPED lpOverlapped, _In_ LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine );

OpenFile Creates, opens, reopens, or deletes a file Obsolete (use CreateFile) HFILE WINAPI OpenFile( _In_ LPCSTR lpFileName, _Out_ LPOFSTRUCT lpReOpenBuff, _In_ UINT uStyle);

Don’t forget to use CloseHandle to release resources. If not – some problems may occur.

Other “things” There are a lot of functions to manage files. Feel free to use MSDN library.