🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #2462

Re: Serious bug in GNUish mv

#2462
From: Noah Friedman
Date: Mon, 01 Oct 1990 23:14
83 lines
4330 bytes
In article <1990Sep26.102324.9233@canterbury.ac.nz> phys169@canterbury.ac.nz writes:
>In article <11303@spool.cs.wisc.edu>, so@brownie.cs.wisc.edu (Bryan So) writes:
>> 
>> Further, there seems to be no shareware/pd versions of mv that
>> conforms to UNIX semantic, in particular, will recursively move 
>> a directory.  The GNU port can rename a directory but will not 
>> move.  Is it that difficult?
>> 
>I have a move command that will move whole directories (and any
>subdirectories), but otherwise isn't all that *ix-comaptible. If you
>want a copy let me know. The reason it is difficult is that the DOS call
>that renames files across directories doesn't work with directories, and 
>the sneaky way of renaming directories (after knocking off the directory
>bit temporarily) doesn't rename across directories. It is possible to
>move directories around on the same disk by stretching compatibility a
>little, but my program moves directories the slow-but-safe way, that also
>lets it work with JOIN'ed disks, etc. It still moves individual files
>quickly, if it can.
>

My XT is down at the moment, so I haven't bothered to write and test
my own mv program, but here is how I would plan the program:

(Note: When making reference to the DOS rename service, I refer to
the newer one, requiring a pathname, not FCB)

1) If the file is a plain file, just use the rename service, which
will rename across directories.

2) If the file is a directory, see where the destination is. If the
destination is the same directory as the source, again, just use the
DOS rename service.

3) If the directory is to be moved and/or renamed to another
directory, and the destination is on the same filesystem (disk),
perform the following steps:

   a) using absolute disk reads and writes, find the directory name
   in its parent table. 

   b) Remove the directory attribute bit (you cannot do this with the chmod
   services, so you have to read in the disk sector, modify it, then write
   it back out). 

   c) Rename the directory just as if it were a normal file. Note that you
   can move this directory anywhere you want now (because it is a plain file)
   on the disk. 

   d) Modify the second entry of the moved directory so that the "parent"
   link now has the correct cluster number in it (you'll have to find this
   using abs diskreads again). If you neglect to do this, then strange
   things will happen when you "cd .." from that directory. I imagine that
   what would happen is that you'd be put back in the directory that the
   moved directory originated from, not its current parent. In any case,
   there would be confusion.

   e) Change the file back into a directory, again using abs diskreads and
   writes.

Note that this automagically moves all the subdirectories under the
directory to be moved - they don't have to be touched!

4) If the directory is to be moved to another filesystem (disk), there
isn't much else you can do besides a recursive copy and delete. These are
fairly trivial, so I won't explain how to do them.

See what a nuisance this is? I don't understand why Microsoft didn't write
the rename service to do this. I spend more time working *around* MS-DOS
than I do working *with* it. Sigh.

I intend to do this myself, and if anyone else is interested in the sources
(which I should have completed in 3 weeks or so - I can't start on the thing
right away), I'll post an FTP site where it will be available.

In the meantime, if someone else does it first, this is the recipe I would
follow for writing the program.

---
Noah Friedman
friedman@ai.mit.edu

Disclaimer: These opinions, statements, comments, etc. are not
representative of any organization including MIT or the FSF.
Technical Details
Message-ID: <11121@life.ai.mit.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!ai-lab!friedman@apple-gunkies.ai.mit.edu
References: <11303@spool.cs.wisc.edu> <1990Sep26.102324.9233@canterbury.ac.nz>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!ai-lab!friedman@apple-gunkies.ai.mit.edu
From: friedman@apple-gunkies.ai.mit.edu (Noah Friedman)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Serious bug in GNUish mv
Summary: Recipe for writing your own mv
Message-ID: <11121@life.ai.mit.edu>
Date: 1 Oct 90 23:14:45 GMT
References: <11303@spool.cs.wisc.edu> <1990Sep26.102324.9233@canterbury.ac.nz>
Sender: news@ai.mit.edu
Organization: The Free Software Foundation
Lines: 83