This project's goal is to work directly with memory-mapped files using mmap. The task was to implement a command-line tool that performs file operations entirely through memory mapping, and without an read/write system calls directly on the target file.
All of the source code for the command line tool is written in src/main.cc. Its contents include:
create()function: creates a new file at a given path with the size of a given number of bytesinsert()function: inserts some bytes at a given offset in a file. if there is an error, it restores the original fileappend()function: appends some bytes to the end of a filemain()function: executes the desired function based on the command line call
- Create:
bin/mmap_util create <path> <fill_char> <size> - Insert:
bin/mmap_util insert <path> <offset> <bytes_incoming> < stdin - Append:
bin/mmap_util append <path> <bytes_incoming> < stdin
Example execution:
bin/mmap_util create dat/data.bin A 1024
echo -n "hello" | bin/mmap_util insert dat/data.bin 100 4
bin/mmap_util append dat/data.bin 1027 < dat/data_app.bin