Write() Syscall | 32 Bit OS Dev (in C)
Expanding the write() syscall to work for open()-ed files and File Descriptors (FDs).
Brain was a bit slow on this one, hope that improves.
Errata:
- memcpy32() is wrong, it does not fill out the correct len % 4 number of bytes, or the right bytes at all in dest, from src. It was later changed to be:
for i = 0; i less than len / 4; i++
((uint32_t *)dst)[i] = ((uint32_t *)src)[i];
i *= 4; // NEW
for j = 0; j less than len % 4; i++, j++ // NEW
((uint8_t *)dst)[i] = ((uint8_t *)src)[i];
return dst;
Notes:
- One thing I should've added was a function to add a disk block to a file's data: allocate and add a bit in the data bitmap, and add that bit's disk block to the file's extents, extending the last extent currently used in the file. There is already code to do that in fs_impl.h/create_file() I think, but it would also be used in the write() syscall and possibly other places, so it should be extracted out into a function to make easier changes later.
Next video:
- adding a (buggy) read() syscall, to check that write() actually writes data to files
OS Dev playlist:
https://www.youtube.com/playlist?list=PLT7NbkyNWaqajsw8Xh7SP9KJwjfpP8TNX
Git Repos:
Sourcehut: https://git.sr.ht/~queso_fuego/quesos
Github mirror: https://github.com/queso-fuego/amateuros
Repo state at the start of this video:
git clone -n https://github.com/queso-fuego/amateuros
cd amateuros
git checkout ea5f42df00c755d004780db0e47619a5b0d7e534
Join the Community Discord: https://discord.gg/yKm4T89QFn
Contact:
https://queso_fuego.srht.site/contact.html
- Let me know if there's anything specific you'd like to see!
Outline:
0:00 basic write() logic
2:07 start implementing write()
23:39 add helper function to update inode on disk
44:32 add no. of pages allocated to file table entries
57:01 add test for write()
Questions about setup/software/etc.?
Check the FAQ: https://queso_fuego.srht.site/about.html
Music credits:
City Life by Artificial.Music | https://soundcloud.com/artificial-music/
Music promoted by https://www.chosic.com/free-music/all/
Creative Commons CC BY 3.0
https://creativecommons.org/licenses/by/3.0/
#writesyscall #kerneldev #cprogramming