File Manipulation Assignment for Operating Systems CS570 - Spring 2004, Assignments of Operating Systems

A programming assignment for the operating systems course cs570 in spring 2004. The goal is to learn about file manipulation using win32 api. The assignment consists of three parts: creating and reading a binary file (part a), random access to a binary file (part b), and file mapping and random access (part c). Students are required to write three programs (p31.cpp, p32.cpp, and p33.cpp or p34.cpp) using functions like srand(), rand(), createfile(), writefile(), closehandle(), setfilepointer(), readfile(), getfilesize(), getfiletime(), filetimetolocalfiletime(), filetimetosystemtime(), createfilemapping(), mapviewoffile(), unmapviewoffile(), flushviewoffile(), and closehandle().

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-38z
koofers-user-38z 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The goal of this assignment is to learn about file manipulation using Win32 API.
A good description of the related system services is given in "Win32 System Services" by Marshall Brain 2nd
edition: pages 24-58, and 76-83; 3rd edition: pages 21-46 and 59-64).
Please create a new directory for this assignment.
The assignment has three parts:
PART A - Create and read a binary file
Write two programs p31.cpp and p32.cpp. First program generates N=25 random numbers (4-byte integers)
and stores them into file with the fixed name d3. The seed of the random number generator should be set to your
masc number. For example, if your login name is masc1234, then use srand(1234);
The second program, p32, reads and prints the entire contents of the file d3 (don't make assumption about the
number of integers in file, read until EOF.) At the end print a small report which informs us about the size of the
file and the time of its creation (the time should be displayed in format: dd/mm/yyyy hh:mm).
HINT: For p31.cpp use: srand(), rand(), CreateFile(), WriteFile(), CloseHandle();
For p32.cpp use: CreateFile(), ReadFile(), GetFileSize(), GetFileTime(),
FileTimeToLocalFileTime(), FileTimeToSystemTime(), CloseHandle().
PART B - Random access to a binary file
Write the program p33.cpp that does the following:
1. Gets an index m, 0 < m <= N and an integer value v from the command line: p33 m v.
2. Opens the file d3 (which has been previously created by p31) and sets the file pointer to the m-th
integer in the file.
3. Reads the m-th integer from the file and displays it on the screen (do not forget output labeling!).
4. Replaces the m-th integer in d3 with the value from the command line.
Using the program p32 from part A, before and after invoking p33, can help you to check the validity of both
programs
HINT: Use: CreateFile(), atoi(), SetFilePointer(), ReadFile(), WriteFile(),
CloseHandle().
CS570 Operating Systems Spring 2004
Programming Assignment #3 Assigned: February 18 Due: March 3
pf2

Partial preview of the text

Download File Manipulation Assignment for Operating Systems CS570 - Spring 2004 and more Assignments Operating Systems in PDF only on Docsity!

The goal of this assignment is to learn about file manipulation using Win32 API.

A good description of the related system services is given in "Win32 System Services" by Marshall Brain 2 nd edition: pages 24-58, and 76-83; 3 rd^ edition: pages 21-46 and 59-64).

Please create a new directory for this assignment.

The assignment has three parts:

PART A - Create and read a binary file

Write two programs p31.cpp and p32.cpp. First program generates N=25 random numbers (4-byte integers) and stores them into file with the fixed name d3. The seed of the random number generator should be set to your masc number. For example, if your login name is masc1234, then use srand(1234);

The second program, p32, reads and prints the entire contents of the file d3 (don't make assumption about the number of integers in file, read until EOF.) At the end print a small report which informs us about the size of the file and the time of its creation (the time should be displayed in format: dd/mm/yyyy hh:mm).

HINT: For p31.cpp use: srand(), rand(), CreateFile(), WriteFile(), CloseHandle(); For p32.cpp use: CreateFile(), ReadFile(), GetFileSize(), GetFileTime(), FileTimeToLocalFileTime(), FileTimeToSystemTime(), CloseHandle().

PART B - Random access to a binary file

Write the program p33.cpp that does the following:

  1. Gets an index m, 0 < m <= N and an integer value v from the command line: p33 m v.
  2. Opens the file d3 (which has been previously created by p31) and sets the file pointer to the m-th integer in the file.
  3. Reads the m-th integer from the file and displays it on the screen (do not forget output labeling!).
  4. Replaces the m-th integer in d3 with the value from the command line.

Using the program p32 from part A, before and after invoking p33, can help you to check the validity of both programs

HINT: Use: CreateFile(), atoi(), SetFilePointer(), ReadFile(), WriteFile(), CloseHandle().

CS570 Operating Systems Spring 2004

Programming Assignment #3 Assigned: February 18 Due: March 3

Part C - File mapping and random access

Write program p34.cpp, which does the modification of the m-th, value similarly as in program p33.cpp, only it does this by file mapping. Once the file d3 is mapped into memory, its content is treated as an array of integers (could be array of any other type). The modification is done in memory and the modified memory is flushed back to disk. Again, the validity of p34 can be verified by using p32.

HINT: Use: CreateFile(), CreateFileMapping(), MapViewOfFile(), UnmapViewOfFile(), FlushViewOfFile(), CloseHandle().

Please do development for the three parts independently, exactly in this order: p31.cpp, then p32.cpp, and then p33.cpp. After you are sure that everything works properly, and your sources are nicely formatted and commented, generate the final documentation for the grader:

turnin3 > results

Then FTP file results3 to rohan, so you can mail it to the grader:

mail grade570 < results

File turnin3.bat you can find in http://medusa.sdsu.edu/cs570/Projects/Assignments.htm Don't forget to update your banner (assignment # and date). Results can be sent only once.

END a3.