All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael L. Welles" <mike@bangstate.com>
To: linux-kernel@vger.kernel.org
Subject: kernel space getcwd()? (using current() to find out cwd)
Date: Mon, 16 Apr 2001 18:42:52 -0400 (EDT)	[thread overview]
Message-ID: <15067.30060.436790.458922@bangstate.com> (raw)


This is probably a stupid question, and probably directed to the wrong
list.  Apologies in advance, but I'm stumped

I've been working on a kernel module to report on "changed files". It
works just fine -- I wrap the orignal system calls with my
replacements which queue the filenames being modified, and when
another proccess reads from the device or proc entry, they get a nice
snapshot of what's going on in the system -- except that all the paths
are relative to the calling process.

So, a little ignorance being a dangerous thing, I thought I'd be clever
and manually reconstruct the full path by walking up
current->fs->pwd->d_parent and padding d_name to the filename until it
hits root.

Unfortunatly, this approach causes kernel panics.  e.g., the attached
code snippet will inevitably bring down the machine if I call it
during in my replacement open, mkdir, rmdir, unlink routines -- and
tehy all work fine without itq. 

What am I not getting? I do see, before I go down, that there's a few
occasions where current() is NULL... 

Apologies in advance for a wordy, probably stupid question, but I'm
stumped.   

If this is not the right approach for what I'm trying to do (e.g. a
kernel space getcwd()), can someone point me to something else I can try?

Thanks in advance, 

Mike Welles


----------------------------------------

(this is the greatly reduced version which does nothing but try and
reference current->fs->pwd)

void fill_full_path(char *name)
{ 
    if (current==NULL) 
    { 
#ifdef DEBUG
	  printk("ERROR! current == NULL\n"); 
#endif
	  return; 
    }

  if (current->fs==NULL) 
    { 
#ifdef DEBUG
	  printk("ERROR! current-> == NULL\n"); 
#endif
	  return; 
    }

  if (current->fs->pwd==NULL) 
    { 
#ifdef DEBUG
	  printk("ERROR! current->fs->pwd == NULL\n"); 
#endif
	  return; 
    }

    return; 
}








This is probably a stupid question: I've been working on a kernel
module to report on "changed files". 

It works just fine -- I wrap the orignal system calls with my
replacements which queue the filenames being modified, and when
another proccess reads from the device or proc entry, they get a nice
snapshot of what's going on in the system -- except that all the paths
are relative to the calling process. 

So, a little ignorance being a dangerous thing, I thought I'd be clever
and manually reconstruct the full path by walking up
current->fs->pwd->d_parent and padding d_name to the filename until it
hits root.

Unfortunatly, this approach causes kernel panics.  e.g., the attached
code snippet will inevitably bring down the machine if I call it
during in my replacement open, mkdir, rmdir, unlink routines -- and
tehy all work fine without itq. 

What am I not getting? I do see, before I go down, that there's a few
occasions where current() is NULL... 

Apologies in advance for a wordy, probably stupid question, but I'm
stumped.   

If this is not the right approach for what I'm trying to do (e.g. a
kernel space getcwd()), can someone point me to where I should look?

Thanks in advance, 

Mike Welles


----------------------------------------

(this is the greatly reduced version which does nothing but try and
reference current->fs->pwd)

void fill_full_path(char *name)
{ 
    if (current==NULL) 
    { 
#ifdef DEBUG
	  printk("ERROR! current == NULL\n"); 
#endif
	  return; 
    }

  if (current->fs==NULL) 
    { 
#ifdef DEBUG
	  printk("ERROR! current-> == NULL\n"); 
#endif
	  return; 
    }

  if (current->fs->pwd==NULL) 
    { 
#ifdef DEBUG
	  printk("ERROR! current->fs->pwd == NULL\n"); 
#endif
	  return; 
    }

    return; 
}






             reply	other threads:[~2001-04-16 22:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-16 22:42 Michael L. Welles [this message]
2001-04-17 12:30 ` kernel space getcwd()? (using current() to find out cwd) Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2001-04-17 22:43 Brian J. Watson
2001-04-17 23:28 ` Brian J. Watson

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=15067.30060.436790.458922@bangstate.com \
    --to=mike@bangstate.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.