On Sat, Jun 02, 2012 at 09:45:55PM +1200, Ralph Versteegen wrote:
> On 2 June 2012 19:25, David Gowers (kampu) <[email protected]> wrote:
> > On Sat, Jun 2, 2012 at 6:43 AM, James Paige <[email protected]> 
> > wrote:
> >>> Actually, I can't believe I missed this before, but it looks like ALL
> >>> files < 4096 bytes are affected. The filenames that have smaller sizes
> >>> that were not affected were actually the names of directories.
> >>>
> >>> I am not sure why OPEN works at all on directories, but it does. The LOF
> >>> when opening a directory appears to be nonsense.
> >>>
> >>
> >> When using the Linux version of FreeBasic, you can always successfully
> >> OPEN directories, and LOF is always 4096.
> >
> > This is rather academic, but.. is that true even for directories that
> > aren't 4096 bytes in size (which is the default size for ext*) ?
> >
> > ( after running the following code in a Python shell,:
> >
> > ---
> >
> > import os
> >
> > def spamfiles (directory, nfiles = 256):
> >    try:
> >        os.mkdir(directory)
> >    except:
> >        pass
> >    for i in range (nfiles):
> >        f = open(os.path.join(directory, str(i)), 'wb')
> >        f.write (b'\x00')
> >        f.close()
> >
> > ---
> >
> > you can type in, for example, "spamfiles ('/tmp/foo8')" which creates
> > a directory with 256 files inside. ('ls' tells me that this directory
> > is 5160 bytes. larger nfiles produce larger directory size, for
> > example 512 makes the directory 10280 bytes, 1024 -> 20520)
> >
> >
> > SHORT VERSION: I suspect FreeBasic is just returning the actual
> > directory size, which may vary according to the number of items
> > inside. I guess the only alternative behaviour they could have chosen
> > here is to return an invalid value like -1 for directories. But then
> > you'd have problems if you really wanted to check the actual directory
> > size (for example if you want to defer investigating large directories
> > during a tree walking operation)
> >
> > I'm not sure what use it is to OPEN a directory, though ;)
> >
> > [using Python, opening a directory for reading is possible with the
> > low-level descriptor-based access tools in 'os' module; AFAICS this
> > seems to be only useful for chdir/chmod/chown, and stat. Nothing
> > remarkable except being faster than doing these operations by name.]
> 
> David is right: FB isn't doing anything unusual here. You can open a
> directory using open(2), get a DIR* using fdopendir(2), and then use
> functions like readdir(3). Note that opening a directory for writing
> is not possible.

But if you open the directory as a file and read it, isn't the data you 
read completely filesystem dependent? Won't you get different 
information if the directory is on an ext3 or vfat or ntfs or xfs or 
hfs+ filesystem?

Maybe I am just thinking too high-level. it seems insane to me that a 
language that intends to be cross-platform would have dramatically 
different behavior on different filesystems and platforms.

I guess FreeBasic has even more assembly language background than it has 
QuickBasic background, so I shouldn't really be surprused :)

---
James
_______________________________________________
Ohrrpgce mailing list
[email protected]
http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org

Reply via email to