From: 墳墓 <brianhsu.hsu@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: How can I get link target from a full path name.
Date: Wed, 24 Aug 2005 15:42:51 +0800 [thread overview]
Message-ID: <615cd8d1050824004230feb6bc@mail.gmail.com> (raw)
Hello,
I would like to know how can I figure out where is a symbolic link
file pointing to.
for example:
/a.txt is a symbolic link to /root/a.txt , how can I get /root/a.txt
when I passing /a.txt
to my function?
I tought path_loookup and d_path is useful, and I wrote a function,
but the path_lookup
function always return -2 , which seems means that there is no such
file, but I am sure
the file exists.
Here is my code, any sugguestion? and thanks for your help.
int catfs_get_path_target ( const char * filename , char ** target_path ,
char ** target_mnt_point )
{
int error = 0;
char buffer[255];
char buffer2[255];
char * fullpath = NULL;
char * mnt_point = NULL;
struct nameidata nd;
struct file * filp = NULL;
if ( filename == NULL ) {
error = -1;
goto out;
}
error = path_lookup ( filename , 0 , &nd );
if ( error ) {
printk ( "Error:%d\n" , error );
error = -1;
goto out;
}
memset ( buffer , 0 , 255 );
memset ( buffer2 , 0 , 255 );
fullpath = d_path(filp->f_dentry,filp->f_vfsmnt,buffer,255) + 1;
mnt_point =
d_path(filp->f_vfsmnt->mnt_mountpoint,filp->f_vfsmnt->mnt_parent,buffer2,255);
if ( mnt_point[strlen(mnt_point)-1] != '/' ) {
strcat ( mnt_point , "/" );
}
*target_path = kmalloc ( sizeof(char) * strlen(fullpath) + 1 , GFP_KERNEL );
if ( *target_path == NULL ) {
*target_path = NULL;
error = -1;
goto out;
}
*target_mnt_point = kmalloc ( sizeof(char) * strlen(mnt_point) + 1
, GFP_KERNEL );
if ( *target_mnt_point == NULL ) {
*target_path = NULL;
error = -1;
goto out;
}
strcpy ( *target_path , fullpath );
strcpy ( *target_mnt_point , mnt_point );
path_release ( &nd );
out:
return error;
}
reply other threads:[~2005-08-24 7:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=615cd8d1050824004230feb6bc@mail.gmail.com \
--to=brianhsu.hsu@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox