Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is iget() hidden in xv6

Tags:

getcwd

pwd

xv6

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.

  • Should I use the struct file interface?
  • Or maybe the struct inode interface?
  • For what matters, it seems it could even be implemented purely in userland.

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 inums I get in the dirents. 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?

like image 458
NewbiZ Avatar asked Nov 11 '22 09:11

NewbiZ


1 Answers

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.

like image 63
Morass Avatar answered Dec 18 '22 20:12

Morass