Posted with author's authorization.

---------- Forwarded message ----------
Date: Mon, 6 Dec 1999 10:15:16 -0500
From: Serge E. Hallyn <[EMAIL PROTECTED]>
To: Marc SCHAEFER <[EMAIL PROTECTED]>
Subject: Re: d_path or way to get full pathname

Just a note: It looks like you're not following mount points.  I'm assuming
this must be what you want since I'm sure you would have noticed :)

Since you originally asked for code, (and since its always fun to see other
people's code) my version (which I began before you posted, but didn't bother
to fix until now) is attached.  You can tell I didn't want to spend the time
shifting the buffer, so instead I limited myself to a 100-element pathname....
(quick-and-dirty)

good day,
-serge

void dte_getfullname(struct dentry *d, char *dest, int destlen) {
   struct dentry *tmp_dentry;
   struct qstr *p[100];
   int len, np, i;

   dest[0]='\0'; dest[1]='\0';
   *(dest+1)='\0';
   if (!d) return;

   tmp_dentry=d; np=0;
   *dest='/'; len=1;
   while (tmp_dentry) {
      if (tmp_dentry->d_name.len) {
         if (!(tmp_dentry->d_name.len==1&&tmp_dentry->d_name.name[0]=='/')) {
            len+=tmp_dentry->d_name.len+1;
            p[np++]=&tmp_dentry->d_name;
            if (len>=destlen || np>99)
               return;
         }
      }
      if (tmp_dentry==tmp_dentry->d_parent) 
         if (tmp_dentry==tmp_dentry->d_covers) tmp_dentry=NULL;
         else tmp_dentry = tmp_dentry->d_covers;
      else tmp_dentry = tmp_dentry->d_parent;
   }
   while (np--) {
      *dest++='/';
      for (i=0;i<p[np]->len;i++) *dest++=p[np]->name[i];
      *dest='\0';
   }
}

Reply via email to