This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] ls & "magic" cygdrive dir (was: RE: cygdrive stuff)


Hello all,

After the overwhelming display of interest for my last mail on this subject (which had gone completely unnoticed as far as I can tell), I have patched up the patch I sent earlier to take care of a lacking feature.
Much of my original mail is still valid, so I'm re-posting:

-- BEGIN RE-POST --
> On Wed, Sep 19, 2001 at 04:11:52PM -0300, salvador wrote:
>> 1) "ls -la /" doesn't show any cygdrive directory. Note it could 
>> be solved in the same way UNIX solves the /proc stuff, just mounting
>> over an existent directory a fake one.
>> 2) "ls -la /cygdrive" doesn't work.
> Correct.
> If you'd like to correct this, patches will be, as always, 
> gratefully accepted.
I saw this, it itched me, so I'm attaching a patch :)

The patch I'm attaching is against the source 'ls.c' as found in 
fileutils-4.1-1. It introduces three methods, of which one is called: 
ls-cygwin-loop(). It is called whenever needed.

I've *only* tested this on a Win98 platform, but I don't think NT 
changes anything in this case (I don't have any NT platforms here, so I 
can't test them).

Here's how it works:

$ ls -la /
(..)
?---------    0 0        Sigma           0 Jan  1  1970 cygdrive
(..)

Note it only shows you that cygdrive exists. As there is no "magic dir" 
filetype, and it's not a real directory, I'm not showing it as one. My 
patch only does anything when there *is* no real directory - if it comes 
through a stat() call, it is not handled.

$ ls -la /cygdrive/
?---------    0 0        Sigma           0 Jan  1  1970 c
?---------    0 0        Sigma           0 Jan  1  1970 d
?---------    0 0        Sigma           0 Jan  1  1970 p
?---------    0 0        Sigma           0 Jan  1  1970 u

Note that 'ls -la /cygdrive' *only* shows:
?---------    0 0        Sigma           0 Jan  1  1970 cygdrive

The patch works regardless of the cygdrive setting, but does 
(regrettably) not show the mounted drives if the cygdrive setting is 
'/' and -an 'ls -la /' is done. I guess I should fix this, but the 
problem is that the mounted drives come through a stat() call as a 
directory, so I don't know whether or not they're really there - 
ideas would help.

Everything where displaying etc. is concerned is handled by the old code 
- my code only adds stuff to the list and does so conservatively (so it 
does not, for example, show the /usr/bin mount when an ls -la /usr is 
done, unless the directory is really there, in which case ls would show 
it anyway. (This is to avoid duplicates in the file list).

I lifted some code from mount - code used to see what mounts exist, and 
what the cygdrive prefix is.. I've surrounded those by copyright notices 
attributing it to mount & Cygnus. The rest is my own (but I'm quite 
willing to sign it over, if it's significant enough for any signatures: 
I'm no lawyer, so I'm being conservative - this, ofcourse, only if it 
proves useful enough to apply to ls..).

All code is surrounded by the magic __CYGWIN__ ifdefs - so no other 
platforms should be affected at all. (However, I don't know how MinGW32 
handles this, or how this goes along with the -mno-cygwin flag)
--- END RE-POST ---
In addition to this, my former patch didn't handle relative directories 
(at all). I.e. running "ls ../../../.." from the "/usr/src/fileutils-
4.1-1/src" directory didn't show the /cygdrive magic dir, while "ls /" 
did. This has been fixed by expanding the path as handled by the patch 
to the full POSIX path.

Once again: this patch has *only* been tested on my development machine, 
because I do not have any other configurations available here. Please, 
if you have other configurations, feel free to test it - it's only 
prudent.

I hope this will be helpful (and won't go unnoticed this time) :)

Greetz!

Ronald

ls.c.diff.gz

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]