[X-Unix] Unlinking a file... illegal characters?
Stroller
MacMonster at myrealbox.com
Sat Feb 26 18:40:02 PST 2005
On Feb 26, 2005, at 11:25 pm, Stroller wrote:
> 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
> eÌ•yÌ√yÌ√yÌ√vkâ∆•â∆•..â∆•â∆• 169384
>
> ...With the benefit of Mr Tilliard's code, I'm gonna have a crack at
> writing something to unlink $1.
Bah! I spent ages (IE: the last 3 hours) at this - far too long making
it pretty & doing error checking & stuff.
See the attached. Still no joy. Grrrr!
$ ls /Volumes/CLEARLIGHT/foo/legoland
e??y??y??y??vk??????..??????
$ ./godir !!:$
./godir /Volumes/CLEARLIGHT/foo/legoland
. 731381
.. 772975
eÌyÌyÌyÌvkââ..ââ 169384
$ ./delinode 169384
Usage: ./delinode <inode number> <containing directory>
$ ./delinode 169384 !-2:$
./delinode 169384 /Volumes/CLEARLIGHT/foo/legoland
Looking for inode 169384 in directory /Volumes/CLEARLIGHT/foo/legoland
eÌyÌyÌyÌvkââ..ââ is the name of the file referred to by
inode 169384Failed to remove it :(
$ ls /Volumes/CLEARLIGHT/foo/legoland
e??y??y??y??vk??????..??????
$ ./delinode 169384 /Volumes/CLEARLIGHT/foo/legoland
Looking for inode 169384 in directory /Volumes/CLEARLIGHT/foo/legoland
eÌyÌyÌyÌvkââ..ââ is the name of the file referred to by
inode 169384Failed to remove it :(
$
Any suggestions, anyone? if this wasn't a Useful Academic Exercise (tm)
I'd just back-up my data & format the damn thing.
Stroller.
-------------- next part --------------
#include <stdio.h>
#include <dirent.h>
static int
usage (char *myname)
{
// TODO: See K&R 7.6 re STDERR
printf ("Usage: %s <inode number> <containing directory>\n", myname);
}
static int
doDirectory (char *name, int inode)
{
struct dirent *dir;
DIR *dirp;
int return_value = 1;
// Check to see if directory exists
if ((dirp = opendir (name)) == (DIR *) 0L)
{
perror (name);
return (-1);
}
// Navigate thro' directory looking for inode prey
while (dir = readdir (dirp))
{
if (dir->d_ino == inode)
{
printf ("%s is the name of the file referred to by inode %d\n",
dir->d_name, inode);
return_value = (remove (dir->d_name));
}
}
closedir (dirp);
return (return_value);
}
int
main (int argc, char **argv)
{
int inode;
if ((argc != 3) || !(inode = atoi (argv[1])))
{
usage (argv[0]);
return (1);
}
printf ("Looking for inode %d in directory %s\n", inode, argv[2]);
if (doDirectory (argv[2], inode))
{
printf ("Failed to remove it :(\n");
return 1;
}
else
printf ("Inode removed sucessfully :D\n");
return (0);
}
More information about the X-Unix
mailing list