Messages in this thread | | | From | (Linus Torvalds) | Subject | Re: d_path to be removed? | Date | 27 Jul 1997 04:52:32 GMT |
| |
In article <5rai7g$735$1@work.smurf.noris.de>, Matthias Urlichs <smurf@work.smurf.noris.de> wrote: > lendecke@math.uni-goettingen.de writes: >> >> I was just frightened by the following comment in 2.1.47: >> >> + * This is broken in more ways than one. Unchecked recursion, >> + * unchecked buffer size. Get rid of it. >> int d_path(struct dentry * entry, struct dentry * chroot, char * buf) >> >> My reimplementation of smbfs depends HEAVILY on this feature. d_path >> could be implemented better, but I NEED the complete path. >> >Linus has said that he regards the abillity to have a getpwd() system call >(or similar; we want to do that for files too ;-) a Good Thing, so I doubt >the feature is going to vanish.
The feature will _not_ vanish.
However, "d_path()" WILL go away, because it is such a horribly broken function. At the very least it will have to check for buffer size issues, and never overflow a buffer. It also has to be rewritten to not be recursive.
The most likely rewrite will involve - limiting the buffer size to one page, and giving only the end of the path if the path is longer. - starting to fill in the path from high addresses: this means that we don't have to be recursive.
I suspect the code will look something like this:
/* * "buflen" should be PAGE_SIZE or more. */ char * d_path(struct dentry *dentry, char *buffer, int buflen) { char * end = buffer+buflen; char * retval; struct dentry * root = current->fs->root;
*--end = '\0'; buflen--;
/* Get '/' right */ retval = end-1; *retval = '/';
for (;;) { struct dentry * parent; int namelen;
parent = dentry->d_covers->d_parent; if (dentry == root || dentry == parent) break; namelen = dentry->d_name.len; buflen -= namelen + 1; if (buflen < 0) break; end -= namelen; memcpy(end, dentry->d_name.name, namelen); *--end = '/'; retval = end; } return retval; }
The above is what I currently have, but it's untested. Feel free to test. The semantics are: - the caller has to allocate the buffer - d_path returns a pointer to inside the buffer, but probably not the start.
Comments?
Linus
| |