Two identical filenames in one directory!

Conor P. Cahill cpcahil at virtech.UUCP
Sun Oct 1 22:47:20 AEST 1989


In article <705 at lakart.UUCP>, dg at lakart.UUCP (David Goodenough) writes:
> What happens if you do the following:
> 
> tar cf - . | ( cd someplace_else ; tar xf - )
> 
> I.e. use tar to shift the whole directory structure someplace else.
> However, I'm still not 100% sure how you'd set about removing both
> entries in the original directory, rm might still do ugly things.

The problem with this solution is that you can't remove the bad entry 
through the system call interface.  You must bypass the kernel and 
directly modify the file system.  Tools that allow you to do this 
include clri, fsdb, fsck, etc.

> If I were a _REAL_ hacker, I'd suggest opening the raw disk device
> (/dev/rsm0g or whatever) for UPDATE, seeking along it looking for
> the string "active", and then just patching the disk itself. [1]
> I do this on a fairly regular basis to my machine at home, but then
> the file structure of CP/M is a bit simpler that UNIX :-)

If you are going to use the raw device you have to remember to read/write
with the proper block sizes (usually 512 or 1024), or multiples thereof.
You can expect wierd results if you do not use the proper multiple.
Another big problem with this is that you have to ensure that the 
pattern you are searching for does not appear anywhere else on the disk.  

You might say to me that  "active\0\0\0\0\0\0\0\102" is not a pattern that
would duplicate very much but what if you had the following in a directory:

		\000 \002 .  \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
		\000 \002 .  .  \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
		\000 \010 s  a  c  t  i  v  e  \0 \0 \0 \0 \0 \0 \0
		\102 \003 d  u  m  m  y  \0 \0 \0 \0 \0 \0 \0 \0 \0
		\000 \011 s  2  a  c  t  i  v  e  \0 \0 \0 \0 \0 \0
		\000 \102 d  u  m  m  y  2  \0 \0 \0 \0 \0 \0 \0 \0
		\000 \012 a  c  t  i  v  e  \0 \0 \0 \0 \0 \0 \0 \102

Note that the string "active\0\0\0\0\0\0\0\102" can be found three times in
that directory.

The only way to properly do this is to use an existing tool, or write a new one
that understands the disk file system structure.


> [1] This is not meant to be taken totally seriously, I'd suggest
> waiting to hear what flames people have for such a brutal idea
> before trying it. Also sync the disk, and umount it before
> attempting this.

Since the file name is in the data portion of the disk, why not use the 
block interface.  This way you can leave the fs mounted and don't have to
worry about syncing.

However I prefer to use the fsdb tool which already understands the layout
of the disk file system.
-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.wizards mailing list