Linux.com

swap_chau

swap_chau

  • Linux.com Member
  • Posts: 1
  • Member Since: 19 Nov 10
  • Last Logged In: 19 Nov 10

Latest Posts

Posted by
Topic
Post Preview
Posted
  • swap_chau
    kernel code not working
    Hi, I wrote small code in read_write.c in linux-2.6.35.4/fs/. I am trying to retrieve entire path of some file where read operation is being performed. I changed 'SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)' to call my function 'getEntirePath(file->f_dentry, path, &length)'. The definition of getEntirePath is as follows: [code]void getEntirePath(struct dentry *self, char *filePath, int *length) { int i=0; //int offset; int MAX_PATH_DEPTH=30; char stack[MAX_PATH_DEPTH][40]; do { strcpy(stack[i], self->d_name.name); printk("swapnil: Dir::%s",stack[i]); if(i!=0 && stack[i][0]!='/') { stack[i][self->d_name.len]='/'; } self=self->d_parent; }while(stack[i++][0]!='/' && i0) strcat(filePath,stack[--i]); *length=strlen(filePath); }[/code] This code takes the dentry *self as input parameter and should trace back the path up to '/'. This code hangs as soon as I enable it through a driver. Also I want to know from which function I should call this code for getting the entire path of file being read/written? I called it from vfs_write/vfs_read, do_sync_write/do_sync_read, but the function is not getting called each time some file is read/wrote. dentry structure reference: http://www.freeweb.hu/linuxkernel2/ch12lev1sec7.html qstr structure reference: http://www.win.tue.nl/~aeb/linux/lk/lk-8.html Thanks for help.
    Link to this post 19 Nov 10

    Hi,
    I wrote small code in read_write.c in linux-2.6.35.4/fs/. I am trying to retrieve entire path of some file where read operation is being performed. I changed 'SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)' to call my function 'getEntirePath(file->f_dentry, path, &length)'.
    The definition of getEntirePath is as follows:

    void getEntirePath(struct dentry *self, char *filePath, int *length)
    {
    int i=0;
    //int offset;
    int MAX_PATH_DEPTH=30;
    char stack[MAX_PATH_DEPTH][40];

    do
    {
    strcpy(stack, self->d_name.name);
    printk("swapnil: Dir::%s",stack);
    if(i!=0 && stack[0]!='/')
    {
    stack[self->d_name.len]='/';
    }
    self=self->d_parent;
    }while(stack[i++][0]!='/' && i<MAX_PATH_DEPTH);

    while(i>0)
    strcat(filePath,stack[--i]);
    *length=strlen(filePath);
    }

    This code takes the dentry *self as input parameter and should trace back the path up to '/'.
    This code hangs as soon as I enable it through a driver. Also I want to know from which function I should call this code for getting the entire path of file being read/written? I called it from vfs_write/vfs_read, do_sync_write/do_sync_read, but the function is not getting called each time some file is read/wrote.
    dentry structure reference: http://www.freeweb.hu/linuxkernel2/ch12lev1sec7.html
    qstr structure reference: http://www.win.tue.nl/~aeb/linux/lk/lk-8.html

    Thanks for help.

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board