Master the fundamental concepts of file systems through this focused micro-challenge.
Creating a file is open(path, O_CREAT|O_WRONLY, mode) followed by write and close. The kernel allocates an fd table slot, creates the inode on disk or tmpfs, and returns a small integer handle.
Sequence:
open returns fd 3 (after stdin/out/err)write(3, buf, len) copies to page cacheclose(3) drops reference countFor example, writing 5 bytes to /tmp/test.txt creates the dentry if missing when O_CREAT is set with mode 0644.
open(), write(), and close() are the exact three syscalls every C library's fopen()/fwrite()/fclose() eventually wraps, and the O_CREAT|O_TRUNC flag combination here is what tools like logrotate rely on to atomically replace files. Skipping the return-value check on open() is one of the most common real-world causes of silent data loss in production logging pipelines.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will create files with raw syscalls or libc wrappers and verify contents with read. The task asks you to handle EEXIST when O_EXCL is requested on an existing path.
Create files using system calls.
Requirements:
Test:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github