On Sun, 24 Mar 2019 18:48:08 +0530, Bharath Vedartham said:
I was interested in implementing copy-on-write for my filesystem(for fun :P). When I do a "cp" operation, I do not want to create a seperate inode for the new file. I only want to create a inode when I make a change to the file.
Actually, /bin/cp isn't where copy-on-write gets you benefits. Where it really shines is when you have a versioning filesystem that keeps track of the last N versions of a file with minimum overhead. So if you have a 100 megabyte file, open it, write 5 blocks of data, and close it, you now can read back either the original or new versions of the file, and you're only using 100M plus 5 blocks plus a tiny bit of metadata.
There is no vfs api for cp. I would need to make creat syscall aware of the fact that it is being executed by "cp". My immediate idea was to check if a file with the same data exists in the filesystem but that would be way too much overhead.
Have you looked at other filesystems that already support copy-on-write? Hint: How do file systems that support point-in-time snapshots work?