Sunday, April 7, 2013

How to get ".." right?

Long ago Rob Pike published a paper about how to get ".." right, and the idea was applied to Plan 9.

But I think I have a better way: remove ".." from the system. That does not mean that we can't use "..",  only that the kernel would remove any ".." from names before using those names as paths.

I have an experimental 9 kernel with a changed namec that

  1. cleans the path name given to it  (nothing new by now).
  2. If it starts with "..", 
    1. takes the (string) path from up->dot
    2. appends the name given to namec
    3. cleans the resulting path.


Point 1 gets rid of middle ".."'s in the path name, as done always in Plan 9.
Point 2 will make a leading ".." become an intermediate ".." and then get rid of it.

Not much is gained by doing it this way, but for code simplicity. I was able to remove several portions of code that did worry about "..". Moreover, if the experiment works as expected, I will be able to remove even more, because all the machinery in Chan's to walk back from mount points will no longer be needed: there will be no "walk back" in the system.

If you argue that this would require resolving longer paths when you use leading ".."'s, you are right; but hopefully, after a few more changes, the system might be a lot faster. Stay tuned.

By the way, in the course of the experiment I found that cleanname does not play well with kernel device paths...

No comments:

Post a Comment