[X-Unix] Unlinking a file... illegal characters?

Stroller MacMonster at myrealbox.com
Sat Feb 26 15:25:18 PST 2005


On Feb 26, 2005, at 1:55 pm, Robert Tillyard wrote:
>
> Here is some 'C' code that I have used to find the i-node, just copy 
> it to a file with a .c extension such as inode.c then type make inode 
> and then run ./inode <path> from the terminal.
>
> #include <stdio.h>
> #include <dirent.h>
>
> static int doDirectory (char *);
>
> int main (int argc, char **argv)
> {
> int i;
>
>    if (argc == 1)
>       return (doDirectory ("."));
>
>    for (i = 1; i < argc; i ++)
>       doDirectory (argv [i]);
>
>    return (0);
> }
>
> static int doDirectory (char *name)
> {
> struct dirent *dir;
> DIR           *dirp;
>
>    if ((dirp = opendir (name)) == (DIR *) 0L)
>       {
>       perror (name);
>       return (-1);
>       }
>
>    while (dir = readdir (dirp))
>       {
>       printf ("%-30.30s ", dir->d_name);
>
>       if (dir->d_ino == 0)
>          printf ("<deleted>\n");
>       else
>          printf ("%lu\n", dir->d_ino);
>
>       }
>
>    closedir (dirp);
> }

C was the language I thought to do this in. Thanks for this code - I 
didn't get past the thinking-about-it stage because I've never done any 
file handling in C before (in my defence, I did complete a compiler 
project with C in uni).

   $ ./godir
   .                              1041563
   ..                             224420
   godir                          1041568
   godir.c                        1041561
   $ ./godir /Volumes/CLEARLIGHT/foo/legoland
   .                              731381
   ..                             772975
   èÿÿÿvk␀␀..␀␀   169384

Unfortunately, having found the inode number:

   $ find /Volumes/CLEARLIGHT/foo/legoland -inum 169384
   find: /Volumes/CLEARLIGHT/foo/legoland/èÿÿÿvk␀␀..␀␀: 
File name too long
   $ find /Volumes/CLEARLIGHT/foo/legoland -inum 169384 -delete
   find: /Volumes/CLEARLIGHT/foo/legoland/èÿÿÿvk␀␀..␀␀: 
File name too long

`-print0 | xargs` gives the same result. With the benefit of Mr 
Tilliard's code, I'm gonna have a crack at writing something to unlink 
$1.

Stroller.



More information about the X-Unix mailing list