LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2006, 04:47 AM   #1
amr.ramadan
LQ Newbie
 
Registered: Jun 2006
Posts: 5

Rep: Reputation: 0
VFS's lookup


As I understand, the lookup function in VFS works as follows, for resolving the path /x/y (where y is a directory). First, the inode of / is stored in the superblock, and is pointed to by the dentry of superblock. The kernel calls lookup to look for x in the inode of /, and passes it the dentry of x. What I then do is attach the passed dentry of x a new inode. Then, I expect, the kernel would call lookup, pass it the inode of x I created and the dentry of y, I then should create an inode of y and attach it to the dentry of x. However, when I do this implementation, and do an "ls /x/y", lookup is only called for x, but not for y (I used printk to know that). Is there something wrong in my logic?

I am writing a simple pseudo file system driver, that is merely responsible for resolving a Path, and according to its contents, communicates with a user-level API.

Here is the code of inode_operations.lookup! I am just testing my logic with it, but something is wrong. What I am trying to do is to resolve the path to reach the deepest directory (or inode), so I would fill its contents later with file_operations.readdir. In this code, I only create an inode for each request and attach it to the passed dentry.

With this code, and when doing "ls /x/y/", lookup is not called on y. It is only called on x. However, if I do "ls /x/" I do get the results I hard coded in readdir (note: there is no logic in readdir, it fills the results irregardless of the passed file structure contents).

Code:
my_lookup(struct inode *parent_inode, struct dentry *dentry, struct nameidata *nameidata) {

  printk("my_lookup:\t");
  printk(dentry->d_name.name);
  printk("\n");

  // i is a global variable.
  struct inode *file_inode iget(parent_inode->i_sb, FILE_INODE_NUMBER + i);
  i++;

  if(!file_inode) {
    printk("Can't allocate the inode\n");
    return ERR_PTR(-EACCES);
  }

  file_inode->i_size = file_size; // some fixed value
  file_inode->i_mode = S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|DT_DIR;

  file_inode->i_op = &my_iops;
  file_inode->i_sb = parent_inode->i_sb;
  d_add(dentry, file_inode);

 out:
  return NULL;
}
I know my question might be answered in proc's code, but disecting it would require some time I am short of. :-(
 
  


Reply

Tags
driver, filesystems, kernel, vfs



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Traceroute, Ping, Domain Name Server (DNS) Lookup, WHOIS, and DNS Records Lookup netoknet General 1 05-09-2005 03:43 AM
Self Lookup Hampster Linux - Networking 0 01-13-2005 05:32 PM
IP lookup jimthing2001 Linux - General 13 01-13-2004 11:32 PM
Cant lookup dns . Trygve Linux - Networking 2 10-23-2003 03:31 PM
NS Lookup problems spearless Linux - Networking 1 04-19-2001 09:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration