07 - File I-O
Class: CSCE-313
Notes:
Background
Applications running in the system are addresses space abstractions called processes.
Processes need to talk to the outside world, and they do so via privileged interfaces (system calls)
In this module we will focus on the UNIX I/O interface.
- Transfer happens in bytes
- I/O devices are treated as files for uniformity
- Basic operations are read and write
- Checks are needed to ensure secure access
- Done through open and close
- Session state also created.
Notes:
- Once you know how to deal with a file, everything else is very similar in UNIX
- In UNIX a file is just a sequence of bytes, if there is any structure to those bytes, that is built by an application.
- Example:
- A SQLite database
bookmarks.db - Print the byte string from this database file
- It is just a sequence of bytes, you will be able to see the offset and the bytes
- There is no structure that UNIX OS imposes on this file
- If we wanted to build any structure on this, we would need to use an application which understands this array of bytes
- For example run:
sqlite3 bookmarks.db- Then
.show tablesto show info of this file - It reads the bytes on from the file and lets you interpret them
- Then
- A SQLite database
- Takeaway: In UNIX, files are just a sequence of bytes with no structure, the application needs to read these bytes and apply a structure to them.
- When you open a file for reading or writing, you also create a session for that file
- In particular there is a pointer that the OS will create for you, as you read through the file, the pointer will advance, now you don't need to specify at what number of bytes you left off.