Accessing filesystem

Accessing filesystem

Post by Jos Hulzin » Thu, 26 Mar 1998 04:00:00



Hi!

I'm working on a tool to cleanup linux parititions (removing backup files,
unneeded zip-files, files not accessed for a certain period etc. To do this,
I have to scan all directories. I have found a way to scan the root
directory (with calls in <dir.h> en <linux/dirent.h>) but they only return
the name of the entry, not the type. To examine type and time, i need to
access the inode. I got a inode-number, but no pointer to the inode. I
searched the .h files, but all calls to request inodes require a superblock
or __KERNEL__ defined. Can someone tell me:
1) How to access inodes in a normal program

or

2) How to find the superblock of the root device

3) Has anyone some interesting tips or ideas about scanning the filesystem ?

Maybe I didn't see the very simple solution, but after days of searching I
think this is a more efficient way...

Greetz,

Jos
--



 
 
 

Accessing filesystem

Post by Paul Flinder » Thu, 26 Mar 1998 04:00:00



> Hi!

> I'm working on a tool to cleanup linux parititions (removing backup files,
> unneeded zip-files, files not accessed for a certain period etc. To do this,
> I have to scan all directories. I have found a way to scan the root
> directory (with calls in <dir.h> en <linux/dirent.h>) but they only return
> the name of the entry, not the type. To examine type and time, i need to
> access the inode. I got a inode-number, but no pointer to the inode. I
> searched the .h files, but all calls to request inodes require a superblock
> or __KERNEL__ defined. Can someone tell me:
> 1) How to access inodes in a normal program

> or

> 2) How to find the superblock of the root device

> 3) Has anyone some interesting tips or ideas about scanning the filesystem ?

> Maybe I didn't see the very simple solution, but after days of searching I
> think this is a more efficient way...

To do this in C you need to call stat (documented in section two of
the manual so you need "man 2 stat" from the command line) - this
takes a file name, there's no system call which takes an inode number.

However it may be worth your while to look at what the "find" command
does. Expressing "delete all the emacs backup files not accessed in
the last week" as a command is

  find / -name '*~' -atime +7 | xargs rm

It may be argued that this is a little cryptic but it's almost
certainly fewer lines of code than you will need in C.

--
Paul

 
 
 

Accessing filesystem

Post by mar » Thu, 26 Mar 1998 04:00:00



Quote:>Hi!

>I'm working on a tool to cleanup linux parititions (removing backup files,
>unneeded zip-files, files not accessed for a certain period etc. To do this,
>I have to scan all directories. I have found a way to scan the root
>directory (with calls in <dir.h> en <linux/dirent.h>) but they only return
>the name of the entry, not the type. To examine type and time, i need to
>access the inode. I got a inode-number, but no pointer to the inode. I
>searched the .h files, but all calls to request inodes require a superblock
>or __KERNEL__ defined. Can someone tell me:

strace ls -F

reveals that stat() and friends might be useful

regards

marc

--

Return address mangled to dodge spam. Consult
http://jade.cs.uct.ac.za/m/address.html
for proper address

 
 
 

Accessing filesystem

Post by di.. » Fri, 27 Mar 1998 04:00:00



> Hi!

> I'm working on a tool to cleanup linux parititions (removing backup files,
> unneeded zip-files, files not accessed for a certain period etc. To do this,
> I have to scan all directories.

The cfengine tool does this and much more. If nothing else, you can use
the source
of the 'tidy' function to learn how to do it. But chances are cfengine
will do exactly
what you want. I currently use it to clean up windows temp files,
notes.rip files etc.
via ncpfs. It has the useful property of only scanning the directory
once regardless of
the number of patterns to match against.

I don't have a url handy, but it is not hard to find. It is available as
an rpm from
Red Had contrib directory, from debian as a deb file, or as a tar.gz
from the gnu home
site.

regards, Frank Ranner

 
 
 

Accessing filesystem

Post by Victor Wagn » Sat, 28 Mar 1998 04:00:00


: Hi!

: I'm working on a tool to cleanup linux parititions (removing backup files,
: unneeded zip-files, files not accessed for a certain period etc. To do this,
: I have to scan all directories. I have found a way to scan the root
: directory (with calls in <dir.h> en <linux/dirent.h>) but they only return
: the name of the entry, not the type. To examine type and time, i need to
: access the inode. I got a inode-number, but no pointer to the inode. I
: searched the .h files, but all calls to request inodes require a superblock
: or __KERNEL__ defined. Can someone tell me:

why do not use tools which already exist?
just popen("/usr/bin/find / -ls","r")

For me, task you described is not job for C program at all. Much
similier (and easier to maintain) to write it as shell script, or
perl script, if you want to parse human readable config files.
Or Tcl/Tk if you want GUI.

: 1) How to access inodes in a normal program

If I have been forced to write this in C without using find, I
probably wouldn't bother with analysing inodes anyway. May be
I would use opendir() if glob() prove to be to inefficient, but
stat() for accessing neccessary information.
: or

--
--------------------------------------------------------
I have tin news and pine mail...