              <<< VAXAXP::NOTES$:[NOTES$LIBRARY]VMSNOTES.NOTE;1 >>>
               -< VAX and Alpha VMS - Digital Internal Use Only >-
================================================================================
Note 1775.6                How to Check FD in advance                     6 of 6
EEMELI::MOSER "Orienteers do it in the bush..."     209 lines   7-NOV-1996 10:59
--------------------------------------------------------------------------------

	The following is my 'mount' utility which I also use for CDroms
	where I don't remember labels etc.

	Attempting to run this against an empty floppy station will return
	MEDOFL, medium offline...

	so you can take this program and modify it to your needs. It is still
	in macro, because I wrote that in 1990, before I could spell C... :-)

	/cmos

---------------------


	.title	Mount_Dev	- Mount a Device Systemwide

; ...	Title:		Mount_Dev.mar
;
; ...	Version:	V1.0-002
;
; ...	Facility:	Management Utility
;
; ...	Abstract:	This utility will mount a Device systemwide for a
;			specified device. There is no need to know the 
;			label, since it will be picked up from the homeblock.
;
; ...	Environment:	A/N
;
; ...	Author:		Christian Moser / Digital Equipment Corporation (DEC)
;
; ...	Date:		 7-NOV-1990
;
; ...	Modified by:	
;
;	V1.0-002	Christian Moser		 4-NOV-1993
;		Added checks in case the volume has changed under our feets.
;		In that case, just dismount and re-mount the volume with
;		the correct label.
;
; ...	Remarks:	Idea stolen from Andrew Cullen, DEC,
;			Auckland New Zealand
;			A future version could check the validity of the
;			homeblock and start a homeblock search if LBN 1 is
;			a corrupted homeblock.
;
;--------------------------------------------------------------------------
;
;

	.sbttl	Declarations
	.ident	'V1.0-002'

	.library	/sys$library:lib/

	$dvidef					; $GETDVI definitions
	$iodef					; IO definitions
	$hm2def					; ODS2 Homeblock definitions
	$mntdef					; $MOUNT definitions
	$ucbdef
	$dmtdef


	.macro	onerror action,?l
	blbs	r0,l
	action
	l:
	.endm	onerror



	.sbttl	Data Definitions
	.psect	data	rd,wrt,noexe,long

dev_prompt:	.ascid	/Enter Device Name: /	; input devname prompt string
dev_desc:	.long	dev_len			; input devname string descr
		.address dev_text
dev_text:	.blkb	80			; device name buffer
dev_len = .-dev_text				; device name buffer length

chan:		.long	0			; channel number
iosb:		.blkq	1			; IO status block

buffer:		.blkb	512			; homeblock buffer

mnt_flags:	.long	<mnt$m_noassist!mnt$m_system!mnt$m_message!mnt$m_norebuild>
mntlst:		.blkw	1			; device name info
		.word	mnt$_devnam
		.address dev_text
		.long	0
		.word	12			; label info
		.word	mnt$_volnam
		.address buffer+hm2$t_volname
		.long	0
		.word	4			; mount flags
		.word	mnt$_flags
		.address mnt_flags
		.long	0
		.word	12			; logical name info
		.word	mnt$_lognam
		.address buffer+hm2$t_volname
		.long	0
		.long	0

sts:	.blkl	1				; device status
dvi:		.word	4			; itemlist for device information
		.word	dvi$_sts
		.address sts
		.long	0
		.long	0

timer		=	3			; no. seconds to wait
timeout:	.long	-10*1000*1000*timer,-1	; timer for read I/O
						; (10*1000*1000 = 1 sec => timer sec)



	.page
	.sbttl	Mount_Dev Code
	.psect	code	rd,nowrt,exe,long


	.entry	start,^m<>

	pushal	dev_desc			; push addr to hold devname len
	pushaq	dev_prompt			; push prompt descr
	pushaq	dev_desc			; push devname descr
	calls	#3,g^lib$get_foreign		; get input
	onerror	ret				; check for errors

	$assign_s -				; assign a channel to it
		devnam=dev_desc, -		; device name descr
		chan=chan			; channel
	onerror	ret				; check for errors

10$:	$qiow_s -				; issue a packack 
		chan=chan, -			; channel
		func=#io$_packack, -		; packack function
		iosb=iosb			; I/O status block
	onerror	ret				; check for errors
	movzwl	iosb,r0				; get I/O status
	onerror	ret				; check for errors

	$setimr_s -				; start timer on input
		efn=#2,-
		daytim=timeout
	onerror	ret				; check on errors
	$qio_s -				; read the homeblock
		efn=#1,-
		chan=chan, -			; channel
		func=#io$_readlblk, -		; read logical block
		iosb=iosb, -			; I/O status block
		p1=buffer, -			; buffer address
		p2=#512, -			; read one page
		p3=#1				; get LBN 1
	onerror	ret				; check on errors
	$wflor_s -				; wait for I/O completion or
		#1,#^b110			; timer expiration
	$cantim_s				; cancel timer
	$cancel_s -				; cancel outstanding I/O
		chan=chan
	$waitfr_s -				; wait for I/O completion
		#1
	movzwl	iosb,r0				; get I/O return status
	cmpl	r0,#ss$_cancel			; assume timeout if read was cancelled
	beql	100$			
	cmpl	r0,#ss$_abort			; assume timeout if read was aborted
	beql	100$
	onerror	ret				; check for other errors
	brw	300$				; okay, continue

100$:	$setimr_s -				; start timer
		efn=#2,-
		daytim=timeout
	onerror	ret				; check on errors
	$waitfr_s -				; wait for timer expiration
		efn=#2
	$getdviw_s -				; get device information
		chan=chan,-
		itmlst=dvi,-
		iosb=iosb
	onerror	ret				; check for errors
	movzwl	iosb,r0				; get I/O status
	onerror	ret				; check for errors
	bbs	#ucb$v_wrongvol,sts,200$	; wrong volume mounted ?
	movl	sts,r0				; return status field back
	ret					; completed

200$:	$dismou_s -				; dismount the volume
		devnam=dev_desc,-
		flags=#<dmt$m_abort!dmt$m_nounload!dmt$m_ovr_checks>
	onerror	ret				; check on errors
	$setimr_s -				; start timer
		efn=#2,-
		daytim=timeout
	onerror	ret				; check on errors
	$waitfr_s -				; wait for timer expiration
		efn=#2
	brw	10$				; re-try

300$:	movw	dev_desc,mntlst			; set length of devname
	$mount_s -				; mount the device
		itmlst=mntlst			; addr of mount itemlist
	ret					; return with status


	.end	start
    

