[comp.os.msdos.programmer] Symbolic link in MS-DOS

alexande@borland.com (Mark Alexander) (05/29/91)

In article <1991May29.153829.8742@bullet.ecf.toronto.edu> xiaoy@bullet.ecf (XIAO  Yan) writes:
>When I used chkdsk and I was told two files were cross linked to the
>same cluster [...] so I assume that it is feasible to have symbolic link...

Unfortunately, no.  It's possible to have a corrupted file system
where two directory entries have the same starting cluster number, as
in your case.  This is more like a UNIX hard link than a symbolic
link.  But DOS doesn't keep a link count in an inode anywhere, so if
you delete one or both of the directory entries, Bad Things will
happen to your data in short order.

>... it should also be possible to have cross directory rename
>command (rather than 'copy-delete' scheme which sometimes is hard to do).

The DOS rename function (INT 21H, AH=56H) is actually capable of
moving a file from one directory to another on the same disk.  The REN
command doesn't use it, though, in the attempt to be compatible with
DOS 1.0 (gack).  You could use the rename() function in your C compiler
library to write a trivial 'mv' program that does what you want.

ins845b@monu4.cc.monash.edu.au (mr k.l. lentin) (05/30/91)

In article <1991May29.153829.8742@bullet.ecf.toronto.edu> xiaoy@bullet.ecf (XIAO  Yan) writes:
>A otherwise accident freshes my dream of symblic link of fils in MS-DOS.
>(much like under unix 'ln -s').
>
>When I used chkdsk and I was told two files were cross linked to the
>same claster.  These two files are on the same disk but in different
>directories and orginally they are different files.  After I saw this 
>message I found that, indeed, these two files contained the same 
>contents.
>
>I recalled that this happened after I used PCTOOLS to undelete one of the
>files.
>
>So I assume that it is feasible to have symbolic link on MS-DOS.  Along
>the same line, it should also be possible to have cross directory rename
>command (rather than 'copy-delete' scheme which sometimes is hard to do).
>I am no expert in FAT stuff.
>
>Any comment?
>
>Xiao

It ispossible to have such a link  as you have found out EXCEPT there are so
many things that can go wrong. When you delete one of the files, DOS will mark
the clusters as free and then later reallocate them and overwrite your other
file. So the link can exist but thats about it. Also don't run norton or
chkdsk or anything else remotely similar!

Cross directory renames are done in XTREE-GOLD (and rpevious versions) using
the move command and they onlyadjust directory entries. It does not
delete/rename. I am surprised norton hasn't given us a nr (nnorton rename)
program. Hes given us everything else.!

|/
|\evin

phys169@csc.canterbury.ac.nz (05/30/91)

In article <1991May29.165933.12688@borland.com>, alexande@borland.com (Mark Alexander) writes:
> In article <1991May29.153829.8742@bullet.ecf.toronto.edu> xiaoy@bullet.ecf (XIAO  Yan) writes:
>>When I used chkdsk and I was told two files were cross linked to the
>>same cluster [...] so I assume that it is feasible to have symbolic link...
> 
> Unfortunately, no.  It's possible to have a corrupted file system
> where two directory entries have the same starting cluster number, as
> in your case.  This is more like a UNIX hard link than a symbolic
> link.  But DOS doesn't keep a link count in an inode anywhere, so if
> you delete one or both of the directory entries, Bad Things will
> happen to your data in short order.
> 
True, it is a hard link, and you have problems when you delete the file or
directory, and you keep getting annoying warnings from CHKDSK. But you could
set some extra bits in the attribute word to stop it being deleted by anything
other than your own program (which would do it neatly). But the best thing is
to wait for a version of DOS with support for links a la Unix or AOS/VS.

It might be possible to get a soft link by playing with SUBST and JOIN; I
haven't succeeded yet, but it is worth tinkerring with.

> The DOS rename function (INT 21H, AH=56H) is actually capable of
> moving a file from one directory to another on the same disk. 
But it doesn't do subdirectories, except for renaming within the same directory.
You could temporarily take off the directory bit, of course.

Mark Aitchison.

frisk@rhi.hi.is (Fridrik Skulason) (05/31/91)

In article <1991May29.153829.8742@bullet.ecf.toronto.edu> xiaoy@bullet.ecf (XIAO  Yan) writes:
>... so I assume that it is feasible to have symbolic link...

Well, yes and no - I did write such a program once, and it works (sort of).
It creates a link by creating a small program containing a special header
and the name of the "linked" file or directory.

A small TSR program will then intercept the DOS "Open" function.  

The program is not finished (it does not intercept FCB calls) - maybe I'll
get the time soon, but considering the number of new viruses awaiting
analysis I doubt it... :-(

-frisk

Fridrik Skulason                 Technical Editor of the Virus Bulletin (UK)  
(author of F-PROT)               E-Mail: frisk@rhi.hi.is    Fax: 354-1-28801

rm3@ornl.gov (MCBROOM R C) (06/01/91)

In article <1991May30.045153.3337@oghma.ocunix.on.ca> rjc@oghma.ocunix.on.ca (Robert J Carter) writes:
>In article <1991May29.153829.8742@bullet.ecf.toronto.edu> xiaoy@bullet.ecf (XIAO  Yan) writes:
...
>
>>Along
>>the same line, it should also be possible to have cross directory rename
>>command (rather than 'copy-delete' scheme which sometimes is hard to do).
>>I am no expert in FAT stuff.
>>
>>Any comment?
>>
>>Xiao
>
>Yes, you could do a cross-directory rename, with the caveat that you
>could step in much doggie-do if your machine goes down during the
>process, although the window would be very small. (I wrote a programme
>to do this a couple of years ago - god knows where it is now).
>Basically, this is the procedure:
>
>	-	Open the source directory
>	-	Open the destination directory
>	- 	Read the directory entry for the file to be moved
>	-	Write the *IDENTICAL* information into an empty
>		directory entry in the destination directory
>	-	Mark the source directory entry as deleted. Please note
>		that I said MARK - DO NOT use the O/S Delete File system
>		calls.
>	-	Close the source and destination directories.
>
>Note: NO mucking about with the FAT is involved! This is a (all things
>being relative) simple, 1 to 2 page C programme, using nothing more
>than open(), close(), read(), and write() calls.
>
Lots of the move utilities around do just this.  A couple that come to mind are
DIRMAGIC that was send out as a subscription enticement by PC-MAG and the move
function in Windows.  There are lots of others.

Robert McBroom internet: rm3@ornl.gov