UNIT 2 • MODULE 3 • LESSON 06
Every school assignment, photo and C program you have ever saved is, as far as the disk is concerned, a long run of bits scattered across storage blocks. You never see those blocks. You see a file called report.docx inside a folder called IA, and you trust that nobody else in the class can open it. The operating system’s file manager creates that tidy, safe view.
This lesson covers how the OS organises files and folders, why and how it compresses files, and the tools it uses to keep files secure: user IDs, passwords, lockwords, access control lists, encryption and activity logs.
What you will learn
- What a file is and what the OS records about it.
- How directories (folders) form a hierarchy, and how paths name a file.
- The jobs of file management.
- What compression is, the difference between lossless and lossy, and how run-length encoding works.
- Six ways the OS keeps files secure, and what each protects against.
Part 1: Files
A file is a named collection of related data stored on secondary storage. To the OS it is a sequence of bytes plus a set of attributes (metadata):
| Attribute | Example |
| Name and extension | scheduler.c (the extension hints at the type) |
| Size | 2,416 bytes |
| Location | Which storage blocks hold the data |
| Dates | Created, last modified, last opened |
| Owner | The user ID that created it |
| Permissions | Who may read, write or run it |
| Flags | Read-only, hidden, system, archive |
The file manager lets users and programs create, open, read, write, rename, copy, move and delete files, without knowing where the bytes physically are. In Text Files in C: Saving, Loading and Appending Data you used fopen, fprintf and fscanf; each of those asks the OS file manager to do the work.
Part 2: Directories and folders
A directory (called a folder in graphical interfaces) is a special file that lists other files and directories, with their attributes or a pointer to them. Directories can contain directories, which gives a tree-shaped hierarchical structure that starts at the root.
C:\ (root) +- Users | +- kemba | | +- Documents | | | +- IA | | | | +- report.docx | | | | +- scheduler.c | | | +- notes.txt | | +- Pictures | +- ravi | +- Documents | +- notes.txt +- Program Files
Four facts about folders come up often:
- A folder can contain zero or more files and sub-folders. An empty folder is perfectly valid.
- Within one folder, every name must be unique. Two files called
notes.txtcan exist only in different folders, as for kemba and ravi above. - Files in a folder do not have to be related. Grouping related files is a good habit, not a rule the OS enforces.
- A file is identified by its path: the chain of folders from the root, for example
C:\Users\kemba\Documents\IA\report.docxon Windows or/home/kemba/Documents/IA/report.docxon Linux.
An absolute path starts from the root. A relative path starts from the current folder: from Documents, the same file is IA\report.docx. The OS keeps track of each process’s current folder.
How the OS finds a file’s data
Storage is divided into fixed-size blocks. When a file is saved, the OS allocates blocks, which need not be next to each other, and records which ones belong to the file in a table (for example a file allocation table or an index of blocks). When you delete a file, the OS usually just marks its blocks as free and removes the directory entry, which is why deleted files can sometimes be recovered. Over time a file’s blocks can become scattered (fragmented) on a hard disk, which slows reading; defragmenting rearranges them.
Part 3: File compression
Compression re-encodes a file so that it takes fewer bytes. The two reasons to compress are:
- To save storage space, so more files fit on a disk, a phone or a backup.
- To reduce transmission time and data use when sending files over a network or the Internet.
Compression is not a security method. A ZIP file can be opened by anyone with the right program unless it is also encrypted.
| Lossless | Lossy | |
| What happens | The original is rebuilt exactly when decompressed | Some detail is thrown away for good |
| Typical size saving | Moderate | Large |
| Used for | Programs, text, spreadsheets, databases (ZIP, PNG) | Photos, music, video (JPEG, MP3, MP4) |
| Why | One wrong byte breaks a program or changes a value | People do not notice small losses in sound or images |
Run-length encoding: a simple lossless method
Run-length encoding (RLE) replaces a run of the same symbol with a count and the symbol. A row of an image that is twelve blue pixels, four white, then eight blue (BBBBBBBBBBBBWWWWBBBBBBBB, 24 characters) becomes 12B4W8B (7 characters). Decompression expands each count back into a run, giving exactly the original.
i <- 0
WHILE i < length(s)
ch <- s[i]
n <- 1
WHILE next char is also ch
n <- n + 1
ENDWHILE
OUTPUT n, ch
i <- i + n
ENDWHILE
RLE works brilliantly on long runs and badly on varied data. Try it:
Try it 1Run-length encoder
Choose an example or type your own letters (up to 60). The tool compresses, then decompresses to check nothing was lost.
Original
Run-length encoded
Notice that MISSISSIPPI gets longer. Real compression tools such as ZIP use cleverer methods that find repeated patterns, not just repeated letters, and they check whether compression actually helps.
Part 4: File security
On a shared or networked computer, the OS must make sure that people can use only the files they are entitled to, and that misuse can be traced. The syllabus names six tools. They work best in layers.
| Tool | What it is | Protects against |
| User ID | A unique name for each account; every file and process is linked to a user ID | Anonymous use; makes permissions and logs possible |
| Password | A secret that proves the user is who the user ID claims | Someone else logging in as you |
| Lockword | A password attached to one particular file (or folder), needed to open it even after logging in | Other logged-in users opening that specific file |
| Access control list (ACL) | A list attached to a file of which users or groups may read, write, run or delete it | Users doing more than they should, for example students editing a marks file |
| File encryption | Scrambling the contents with a key so they are unreadable without it | Theft of the disk or file, or someone bypassing the OS |
| Activity log | A record of who logged in, which files were opened or changed, and when | Undetected misuse; helps trace and investigate problems |
Access control lists in practice
A school server might store a marks spreadsheet with this ACL:
| User or group | Read | Write | Delete |
| Head of department | Yes | Yes | Yes |
| Teachers | Yes | Yes | No |
| Students | No | No | No |
Linux uses a short form of this idea: each file has read, write and execute permissions for the owner, the owner’s group and everyone else, shown as rwxr-x---.
Good passwords and lockwords
A password is only as good as its secrecy and strength. Long passphrases, a different password for each system, and two-factor sign-in all help. The OS stores passwords in a scrambled (hashed) form, so even an administrator cannot read them, and locks an account after several wrong attempts.
Try it 2Match the protection to the problem
Choose the security tool that best fits each situation. Ten items.
Part 5: Common mistakes
- Compression as security. Compression reduces size. Encryption protects content.
- Lockword vs password. A password protects an account (logging in). A lockword protects a particular file.
- Encryption is enough on its own. If the key or password is weak, encryption gives little protection. Layers matter.
- "Folders must contain related files". It is good practice, not a rule.
Try it 3Files and compression drill
Pick a mode. "RLE" asks you to compress or expand a short run. "Facts" checks file management and security facts.
Summary
| Idea | Remember |
| File | Named collection of data with attributes (name, size, dates, owner, permissions). |
| Folder | A directory listing files and folders; hierarchical from the root; names unique within a folder. |
| Path | The route from the root (absolute) or from the current folder (relative). |
| Compression | Smaller files: save space, send faster. Lossless (exact) or lossy (detail lost). |
| RLE | Count plus symbol for each run: good for long runs only. |
| Security | User IDs, passwords, lockwords, ACLs, encryption, activity logs. |
Review questions
1. State four tasks performed by the file management part of an operating system.
Show answer
Creating and deleting files and folders; organising folders in a hierarchy; keeping track of where each file’s data is stored; controlling access to files; opening, reading and writing files for programs; renaming, copying and moving files.
2. Explain the difference between an absolute path and a relative path.
Show answer
An absolute path names a file starting from the root of the file system. A relative path starts from the current folder.
3. Give two reasons for compressing a file.
Show answer
To take up less storage space; to reduce the time (and data) needed to send it over a network.
4. Distinguish between lossless and lossy compression, with an example of each.
Show answer
Lossless: the exact original can be rebuilt (ZIP, PNG), used for text and programs. Lossy: some data is permanently removed for a smaller size (JPEG, MP3), used for images and sound.
5. Compress AAAABBBCCD using run-length encoding.
Show answer
4A3B2C1D.
6. Distinguish between a password and a lockword.
Show answer
A password authenticates a user when logging in to an account. A lockword is a password attached to a particular file that must be given to open that file.
7. Explain how an access control list protects files.
Show answer
It lists, for a file, which users or groups may read, write, execute or delete it. The OS checks the list on every access and refuses anything not permitted.
8. Why is an activity log useful even though it does not stop an attack?
Show answer
It records who accessed or changed files and when, so misuse can be detected, traced to a user ID and investigated; it also deters misuse.
Homework
- Draw the folder tree for your own school work and write the absolute path of one file in it.
- Encode the pixel row WWWWWWBBWWWWWWWW with RLE. What fraction of the original size is it?
- Write a C program that reads a string and prints its run-length encoding.
- Design an access control list for three files on a school server (timetable, marks, student work) for three groups.
Mastery quiz: Files, Folders, Compression and Security
This 10-question quiz is separate from the short Quick quiz at the end of the lesson. Score 8/10 or higher to earn this lesson’s badge. Your best score is saved in this browser on this device.
Mastery quiz: Files, Folders, Compression and File Security
Your course badges: loading saved progress…
View badges
No course badges earned yet. Score 8/10 in a lesson quiz to earn its badge.
Saved in this browser on this device. Clearing browser data may remove your badges.
Answer all 10 questions. Earn this lesson’s badge at 8/10 or higher. Read the explanations, revisit the Try it activities and retry as often as you need. These are self-study badges, not formal grades.
Exam tips
Specimen Unit 2 Paper 01 (2021), Items 33, 35 and 38. These are short fact checks on this lesson: the rules for files and folders (Part 2), which measure is not a way of securing files sent over a network, and the main reason for compressing a file (Part 3). Method: test each statement or option against the rules in this lesson one at a time, and be wary of options that mix up what compression does with what encryption does.
Security questions. When asked for security measures, name the tool and say how it protects the file. "Encryption: the file is scrambled so it cannot be read without the key" scores better than a list of words.
More worked answers are on the CS Solutions page.
Previous: Unit 2 • Module 3 • Lesson 05 – Memory Management: Virtual Memory, Paging and Thrashing. Next: Unit 2 • Module 3 • Lesson 07 – User Interfaces and Device Management.
Syllabus link: CAPE Computer Science (CXC A19/U2/21), Operating Systems and Computer Networks (Unit 2, Module 3). Specific Objective 3: describe the functions of operating systems (file management: directories/folders, files, file compression; security of files: user IDs, passwords, lockwords, access control lists, file encryption, activity logs).
Video search terms
Search YouTube for: "file management operating system folders paths", "run length encoding explained", "access control list file permissions".
Try it 4Quick quiz
Tap an answer. All eight questions are self-checks on this lesson.
Updates
2026/12/01
- First version of the lesson.
© 2026 islandclass.org
