I'm playing a bit with xv6, a modern implementation of Unix version 6.
For my first hack, I wanted to implement the simple getcwd
syscall, but I'm a bit lost as to which level of abstraction I should use.
struct file
interface?struct inode
interface?I started implementing it with struct inode
manipulations. My naive idea was to retrieve the proc->cwd
, then readi()
its second entry (..
), scan it to retrieve my previous inum
, and so on recursively until I hit the root.
Doesn't seem very performant, but that will fit for a first hack.
My problem though is that I need fs.c:iget()
to retrieve a struct inode
from the inum
s I get in the dirent
s. I've noticed that iget()
is static in fs.c
and not declared in defs.h
which annoys me a bit, but I can't find the reason why.
So, this is my question. Why is it that iget()
was deliberately hidden from the rest of the kernel?
Seems to me they were just pragmatic.
iget is used only by the directory manipulation routines. The directory manipulation routines are in fs.c.
As for the getcwd implementation. It would be much better if you follow the chdir syscall code. The path is there. You just need to store it, probably in a new field in the proc structure. Of course, if the path given is relative, you should append it to the current stored path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With