;       SCCSID = @(#)d_sfmod.asm	6.1 91/02/15
;	SCCSID = @(#)d_sfmod.asm	6.2 90/01/22
; ****************************************************************************
; *									     *
; *			  IBM/Microsoft Confidential			     *
; *									     *
; *		    Copyright (c) IBM Corporation  1987, 1990		     *
; *		    Copyright (c) Microsoft Corp.  1987, 1990		     *
; *			      All Rights Reserved			     *
; *									     *
; ****************************************************************************
;***  d_sfmod.asm - API stub routine DosSetFileMode
;
;	Member of API library
;	Steve Salisbury & Bill Mershon
;	Copyright MicroSoft Corporation, 1986
;	18-Feb-1986
;
;	library routine for API simulator
;
;	Called from dos 2.x,3.x compatible dos 5.x applications
;
;	Special Information
;
;	BUG: DosSetFileMode will fail when an attempt is made to change
;	the attributes on the root directory (in fact, such an attempt may
;	result in data corruption on the disk).  This bug is a hold-over
;	from DOS 3.x.  No attempt is made to correct the problem since
;	the (complete) solution would be quite difficult.
;
;	Modification History
;
;	15-Jul-86 (billme): document bug that an attempt to change
;	attributes on the root directory will fail
;
;	06-Jan-87 (billme): Replace initial pushes and final pops
;	with calls to __api_begin and __api_end resp.  This will
;	reduce the size of FAPI and allow support for signals.
;
;
;	04-May-87 (robertc): Install hooks for DOSErrorClass Support.
;	All int 21h errors are passed through api_get_extended to get the
;	extended errorcode and to provide the class, action, and locus for
;	the dynamic error FIFO queue.
;
; @@	8-May-87 (Tarng): Check reserved dword are zeros.
;			  Check filename/pathname is in the 8.3 range.
;

include dos2equ.inc
INCLUDE error.inc			;@@ added support for DOSErrorClass

	EXTRN	api_get_extended:far	;@@ added support for DOSErrorClass
	EXTRN	__api_begin:near
	EXTRN	__api_end:near
	EXTRN	name_check:far		;@@ added support for 8.3 filename

;***	DOSSETFILEMODE - stub to emulate DOSSETFILEMODE function call
;
;	simulates DOS 5.0 call from DOS 2.x,3.x environment
;
;	errorcode = unsigned far pascal
;	DosSetFileMode (FileName,NewAttribute,Reserved)
;
;	ENTRY:
;		FileName - file path name
;		NewAttribute - new attribute of tile
;		Reserved - null double word
;
;	RETURN:
;		AX = 0 if no error, else error code (see DOS 5 spec)
;
;	EXIT:
;
;	USES:
;		AX
;
;	Pseudo Code:
;		save registers
;		use BP as pointer to stack parameters
;		load registers for int 21 call
;		execute int 21 with function 43h
;		restore registers
;		return
;
;	WARNING:
;		may return error code from Dos 2.x, 3.x (see dos manuals)
;
;	EFFECTS:
;		none
;

	title	DOSSETFILEMODE - stub to emulate DOSSETFILEMODE function call
;
;	EXTRN	DOSSETFILEMODE:FAR
;
;	PUSH	@ ASCIZ FileName
;	PUSH	WORD NewAttribute
;	PUSH	DWORD 0
;	CALL	DOSSETFILEMODE
;


_TEXT	segment byte public 'CODE'

	assume	CS:_TEXT,DS:NOTHING

	public	DOSSETFILEMODE

FileName	equ	[BP+12]
NewAttribute	equ	[BP+10]
Reserved0	equ	[BP+6]

DOSSETFILEMODE	proc	far

	call	__api_begin	; init bp and save bp,ds,bx,cx,dx,si,di,es
				; required to save: bp,ds,cx,dx

; check validity of reserved words
	mov	ax,ERROR_INVALID_PARAMETER	;@@
	mov	bx, Reserved0			;@@ reserved words not zeros
	or	bx,bx				;@@
	jnz	NormalExit			;@@ then return error
	or	bx,Reserved0+2			;@@
	jnz	NormalExit			;@@ then return error

	lds	dx,[FileName]		; DS:DX <- pointer to pathname
; verify the filename in 8.3 range
	push	si			;@@ save si
	mov	ah,3			;@@ meta char is invalid
	mov	si,dx			;@@ ds:si = pointer to filename
	call	name_check		;@@ check name in 8.3 range
	pop	si			;@@ restor si
	jc	NormalExit		;@@ filename is illegal

	mov	cx,[NewAttribute]	; CX <- attribute to be set
	mov	al,1
	mov	ah,D2_ChangeMode
	int	21H
	jc	ErrorExit
	xor	ax,ax
	jmp	short NormalExit	;@@ Added support for DOSErrorClass
ErrorExit:				;@@ added support for DOSErrorClass
	call	api_get_extended	;@@ added support for DOSErrorClass
NormalExit:				;@@ added support for DOSErrorClass

	call	__api_end	; check sigs & restore es,di,si,dx,cx,bx,ds,bp

	ret	10	; clear stack of entry parameters (bytes)
DOSSETFILEMODE	endp

_TEXT	ends

	end
