On Mon, May 10, 2021 at 8:08 AM Justin He <Justin.He@xxxxxxx> wrote: > > > > > char *dentry_path(const struct dentry *dentry, char *buf, int buflen) > > { > >- char *p = NULL; > >+ struct prepend_buffer b = { buf + buflen, buflen }; > > char *retval; > >+ char *p = NULL; > > > > if (d_unlinked(dentry)) { > >- p = buf + buflen; > >- if (prepend(&p, &buflen, "//deleted", 10) != 0) > >+ if (prepend(&b, "//deleted", 10) != 0) > > goto Elong; > >- buflen++; > >+ > >+ // save away beginning of "//deleted" string > >+ // and let "__dentry_path()" overwrite one byte > >+ // with the terminating NUL that we'll restore > >+ // below. > >+ p = b.ptr; > >+ b.ptr++; > >+ b.len++; > > } > >- retval = __dentry_path(dentry, buf, buflen); > >+ retval = __dentry_path(dentry, b.ptr, b.len); > > I didn't quite understand the logic here. Seems it is not equal to > the previous. Should it be s/b.ptr/buf here? Otherwise, in __dentry_path, > it will use the range [b.ptr, b.ptr+b.len] instead of [buf, buf+b.len]. > Am I missing anything here? No, you're right. That __dentry_path() call should get "buf, b.len" as arguments. I knew it was squirrelly, but didn't think it through. I actually wanted to change "__dentry_path()" to take a "struct prepend_buffer", and not add the NUL at the end (so that the caller would have to do it first), because that would have made the logic much more straightforward (and made the semantics the same as the other internal helpers). And that would have fixed that bug of mine too. But then I didn't do it, and just mentioned it as a later cleanup. Good catch. Linus