/*static char *SCCSID = "@(#)qfsa.c	6.1 90/11/17";*/
/*static char *SCCSID = "@(#)qfsa.c  6.8 90/08/06";*/

/************************************************************************
 *
 * QFSA.C - Pre and post processor for aligned data DosQueryFSAttach
 *
 ************************************************************************/

#define INCL_DOS
#define INCL_DOSFILEMGR
#define INCL_32
#define INCL_DOSERRORS
#define INCL_NOPMAPI
#include <os2.h>
#include "align32.h"


/**** Dos32QueryFSAttach
 *
 *  pre- and post- processor for aligned data API.
 *
 *  ENTRY:	*(pfsqb) is random
 *		*(pcbBuffLength) is the size of *(pfsqb)
 *
 *  EXIT:	*(pfsqb) is return buffer
 *		*(pcbBuffLength) is amount of data in *(pfsqb)
 *
 *
 *  ARGUMENTS:	pszDeviceName	- drive letter or pseudo-character device name
 *		ulOrdinal	- Index into set of drives.  1 based
 *		ulFSAInfoLevel	- info level requested
 *		pfsqb		- addr of buffer for return data
 *		pcbBuffLength	- addr of size of buffer
 *
 *  RETURNS:	0, or dos error code
 *
 *  CALLS:	DosQueryFSAttach
 *
 *  WARNINGS:	None.
 *
 *  PSEUO-CODE:
 *	BEFORE
 *	    nothing
 *
 *	AFTER
 *	    save values of cbFSDName and cbFSAData
 *	    move szFSDName up 2 bytes
 *	    move szFSAData up 4 bytes
 *	    put cbFSDName and cbFSAData where they belong.
 */

APIRET	APIENTRY DOS32QUERYFSATTACH(   PSZ     pszDeviceName,
			    ULONG   ulOrdinal,
			    ULONG   ulFSAInfoLevel,
			    PFSQBUFFER2 pfsqb,
			    PULONG  pcbBuffLength) {

    PBYTE   p;
    USHORT  cbFSDName;
    USHORT  cbFSAData;
    USHORT  i;
    APIRET  rc;

    rc = Dos32PQueryFSAttach( pszDeviceName, ulOrdinal, ulFSAInfoLevel,
					  (PFSQBUFFER) pfsqb, pcbBuffLength);

    if (!rc) {
	cbFSDName = *(PUSHORT)(p = ((PBYTE)pfsqb + ((PFSQBUFFER)pfsqb)->cbName + 4 + 1 ));
	cbFSAData = *(PUSHORT)(p += cbFSDName + 2 + 1 );
	p--;

	/* now p points to the last byte in szFSDName */

	/* Move szFSDName up 2 bytes */

	i = cbFSDName + 1;		    /* for the trailing \0 */
	while (i--)
	    *(p + 2) = *p--;

	/* now p points to cbFSDName, so decrement it past that and it
	 * will point to the last byte of szName */

	p -= 2;

	/* Move szName up 4 bytes */

	i = pfsqb->cbName + 1;		    /* for the trailing \0 */
	while (i--)
	    *(p + 4) = *p--;

	/* Fill in the gaps */

	pfsqb->cbFSDName = cbFSDName;
	pfsqb->cbFSAData = cbFSAData;
    }
    return rc;
}
