Guidelines for the support of long filenames
--------------------------------------------

Andreas Kromke
22.10.95

English translation: Peter West, April 99


1. Here I am
------------

With

	Pdomain( PDOM_MINT /* 1 */ );

one informs DOS that one likes long filenames.
Basically the DOS does not behave differently (->MiNT-docs), but 
MagiC can establish for the file selector whether long filenames 
are possible.


2. To do and not to do
----------------------

The calls Fsfirst/-next() are taboo.
A directory is read in with

{
	XATTR xattr;
	LONG dirhandle;
	LONG err,xr;

	dirhandle = Dopendir(path, DOPEN_NORMAL /* 0 */ );
	if	(dirhandle >= 0)
		{
		do	{
			err = Dxreaddir(fnamebuflen, dirhandle, fnamebuf,
					&xattr, &xr);
			if	(xr)
				.. Error with Fxattr ..
			if	(err)
				.. Error with Dreaddir ..
			}
		while(!err);
		Dclosedir(dirhandle);
		}	
}


fnamebuf here contains the first 4 bytes of the Inode number, which 
one normally does not need (faulty design of Dxreaddir) and which is 
contained in the XATTR structure again anyway.
During this one can not search for filemasks such as "*.prg*; instead 
one has to perform one's own tests for regular expressions.
If one catches a Symlink, one may have to dereference it manually if 
the occasion arises, namely with:

		if	((xattr.mode & S_IFMT) == S_IFLNK)
			{
			XATTR xa2;

			err = Fxattr(0, path_mit_aliasname, &xa2);
			if	(!err)
				xa = xa2;
			err = E_OK;
			}


3. How much?
------------

With

		err = Dpathconf(path, DP_NAMEMAX);
		if	(err > 0L)
			{
			maxnamelen = (int) err;
			dos_mode = (Dpathconf(path, DP_TRUNC) == DP_DOSTRUNC);
			}
		else	{
			dos_mode = TRUE;
			maxnamelen = 12;
			}

one obtains information about the maximum filename length in a 
directory. One can then create the buffers to suit.


4. Gimme Info
-------------

With

		Fxattr(0, path, &xattr);

one obtains information about a file or a path, during which aliases 
will be dereferenced.

With

		Fxattr(1, path, &xattr);

in the case of an alias one obtains information about the alias itself. 
Exactly as with Dxreaddir().

One can obtain the same info via a file handle, namely with

		Fcntl(fd, &xattr, FSTAT);

So no about establishing the file lengths with Fseek() and similar 
rubbish!


5. Other runners
----------------

Basically no placeholders ('?' or '*') are allowed for system calls,
i.e. even not for Fdelete(), Pexec() etc.
Fxattr() is definitely to be preferred to Fattrib().
Dgetcwd() is to be preferred to Dgetpath().
Dreadlabel() and Dwritelabel() should be used rather than some tricks 
with Fcreate(quark, F_VOLUME).


6. Dxreaddir binding for PureC
------------------------------

/*********************************************************************
*
* Dxreaddir()
*
* With Fxattr, Symlinks will not be followed.
* <xr> after the call contains the error code of Fxattr.
*
*********************************************************************/

long Dxreaddir(int len, long dirhandle,
			char *buf, XATTR *xattr, long *xr)
{
	return(gemdos(0x142, len, dirhandle, buf, xattr, xr));
}
