(FILECREATED "18-Feb-85 18:38:18" {PHYLUM}<STANSBURY>LOCALFILE>HARMONY>DLIONFSPATCH.;9 9933   

      changes to:  (FNS \VANILLAEVENTFN \MYREMOVEDEVICE.NAMES DFSCREATEDIRECTORY \DFSCreateDevice 
			\DFSTruncateFile \FIX.TRUNCATEFILE \VANILLADISKINIT \VANILLAHOSTNAMEP)
		   (VARS DLIONFSPATCHCOMS)

      previous date: "18-Feb-85 16:34:24" {PHYLUM}<STANSBURY>LOCALFILE>HARMONY>DLIONFSPATCH.;1)


(* Copyright (c) 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT DLIONFSPATCHCOMS)

(RPAQQ DLIONFSPATCHCOMS ((DECLARE: EVAL@COMPILE DONTCOPY (FILES (LOADCOMP)
								DLIONFS))
			 (DECLARE: (LOCALVARS . T))
			 (* * Dlionfs bug fixes -- \UPDATEOF)
			 (FNS \DFSCloseFile \DFSReadOnePage)
			 (* * Dlionfs bug fixes -- TRUNCATEFILE)
			 (FNS \DFSTruncateFile \DFSCreateDevice \FIX.TRUNCATEFILE)
			 (P (\FIX.TRUNCATEFILE))
			 (* * Vanilladisk bug fixes.)
			 (FNS \MYREMOVEDEVICE.NAMES)
			 (FNS DFSCREATEDIRECTORY)
			 (FNS \VANILLADISKINIT \VANILLAHOSTNAMEP \VANILLAEVENTFN)
			 (INITVARS (\PSEUDODSK))
			 (GLOBALVARS \PSEUDODSK)
			 (P (\VANILLADISKINIT)
			    (MOVD (QUOTE NILL)
				  (QUOTE \DFSDeviceConflict)
				  T))))
(DECLARE: EVAL@COMPILE DONTCOPY 
(FILESLOAD (LOADCOMP)
	   DLIONFS)
)
(DECLARE: 
(DECLARE: DOEVAL@COMPILE DONTCOPY

(LOCALVARS)
)
)
(* * Dlionfs bug fixes -- \UPDATEOF)

(DEFINEQ

(\DFSCloseFile
  [LAMBDA (STREAM)                                           (* hts: "18-Feb-85 15:55")
                                                             (* Update EOF in leader page)
    (WITH.MONITOR \DFStopMonitor (\CLEARMAP STREAM)
		  (\UPDATEOF STREAM)
		  (if (NEQ (fetch ACCESS of STREAM)
			   (QUOTE INPUT))
		      then (UNINTERRUPTABLY
                               (\DFSTrimHelper (fetch (DLIONSTREAM VOLUME) of STREAM)
					       (fetch (DLIONSTREAM FILEDESC) of STREAM)
					       (IPLUS (fetch EPAGE of STREAM)
						      (if (ZEROP (fetch EOFFSET of STREAM))
							  then 1
							else 2)))
			       (\DFSUpdateLeaderPage STREAM)))
		  STREAM])

(\DFSReadOnePage
  [LAMBDA (stream page buffer)                               (* hts: "18-Feb-85 15:57")
    (PROG ((vol (fetch (DLIONSTREAM VOLUME) of stream)))
          (\UPDATEOF stream)
          (if [OR (ILEQ page (fetch EPAGE of stream))
		  (AND (IGREATERP (fetch EOFFSET of stream)
				  0)
		       (EQP page (ADD1 (fetch EPAGE of stream]
	      then (\LvGetPage vol (\DFSFindPageAddr vol (fetch (DLIONSTREAM FILEDESC) of stream)
						     page)
			       buffer])
)
(* * Dlionfs bug fixes -- TRUNCATEFILE)

(DEFINEQ

(\DFSTruncateFile
  [LAMBDA (STREAM PAGE# OFFSET)                              (* hts: "18-Feb-85 16:11")

          (* * Used to shorten or lengthen STREAM. If lengthening, pad the file with nulls. Used by SETEOFPTR and 
	  FORCEOUTPUT.)



          (* * Normalize arguments)


    (\UPDATEOF STREAM)
    (OR (FIXP PAGE#)
	(SETQ PAGE# (fetch (DLIONSTREAM EPAGE) of STREAM)))
    (OR (FIXP OFFSET)
	(SETQ OFFSET (fetch (DLIONSTREAM EOFFSET) of STREAM)))

          (* * If lengthening stream, pad it with nulls.)


    (UNINTERRUPTABLY
        (PROG ((FILEPTR (\GETFILEPTR STREAM)))
	      (to (DIFFERENCE (PLUS (TIMES PAGE# BYTESPERPAGE)
				    OFFSET)
			      (PLUS (TIMES (fetch (DLIONSTREAM EPAGE) of STREAM)
					   BYTESPERPAGE)
				    (fetch (DLIONSTREAM EOFFSET) of STREAM)))
		 do (\BOUT STREAM 0))
	      (\SETFILEPTR STREAM FILEPTR)))

          (* * Record the new file length)


    (replace (DLIONSTREAM EPAGE) of STREAM with PAGE#)
    (replace (DLIONSTREAM EOFFSET) of STREAM with OFFSET)
    (\DFSUpdateLeaderPage STREAM)
    NIL])

(\DFSCreateDevice
  [LAMBDA NIL                                                (* hts: "18-Feb-85 17:57")
    (UNINTERRUPTABLY
        (PROG [(DEV (\MAKE.PMAP.DEVICE (create FDEV
					       NODIRECTORIES ← T
					       DEVICENAME ←(QUOTE DSK)
					       CLOSEFILE ←(FUNCTION \DFSCloseFile)
					       DELETEFILE ←(FUNCTION \DFSDeleteFile)
					       TRUNCATEFILE ←(FUNCTION \DFSTruncateFile)
					       GETFILEINFO ←(FUNCTION \DFSGetFileInfo)
					       GETFILENAME ←(FUNCTION \DFSGetFileName)
					       OPENFILE ←(FUNCTION \DFSOpenFile)
					       READPAGES ←(FUNCTION \DFSReadPages)
					       SETFILEINFO ←(FUNCTION \DFSSetFileInfo)
					       WRITEPAGES ←(FUNCTION \DFSWritePages)
					       REOPENFILE ←(FUNCTION \DFSOpenFile)
					       GENERATEFILES ←(FUNCTION \DFSGenerateFiles)
					       EVENTFN ←(FUNCTION \DFSEventFn)
					       DIRECTORYNAMEP ←(FUNCTION \DFSDirectoryNameP)
					       HOSTNAMEP ←(FUNCTION \DFSHostNameP]
	      (\DEFINEDEVICE (QUOTE DSK)
			     DEV)
	      (SETQ \DFSdevice DEV)
	      (printout NIL "Opened local file system device {DSK}." T)
	      (RETURN DEV)))])

(\FIX.TRUNCATEFILE
  [LAMBDA NIL                                                (* hts: "18-Feb-85 16:21")

          (* * comment)


    (if (type? FDEV \DFSdevice)
	then (replace (FDEV TRUNCATEFILE) of \DFSdevice with (FUNCTION \DFSTruncateFile])
)
(\FIX.TRUNCATEFILE)
(* * Vanilladisk bug fixes.)

(DEFINEQ

(\MYREMOVEDEVICE.NAMES
  [LAMBDA (DEV NAMES)                                        (* bvm: "30-Jan-85 21:53")
    (DECLARE (GLOBALVARS \DEVICENAMETODEVICE \FILEDEVICENAMES))

          (* * removes any names associated with device DEV without actually removing the device itself.
	  If NAMES is non-NIL, removes only the names inside it)


    (for TAIL on \DEVICENAMETODEVICE bind CHANGED when (AND (EQ (CDAR TAIL)
								DEV)
							    (OR (NULL NAMES)
								(EQMEMB (CAAR TAIL)
									NAMES)))
       do (SETQ \FILEDEVICENAMES (DREMOVE (CAAR TAIL)
					  \FILEDEVICENAMES))
	  (RPLACA TAIL NIL)
	  (SETQ CHANGED T)
       finally (COND
		 (CHANGED (SETQ \DEVICENAMETODEVICE (DREMOVE NIL \DEVICENAMETODEVICE])
)
(DEFINEQ

(DFSCREATEDIRECTORY
  [LAMBDA (volName)                                          (* hts: "18-Feb-85 18:32")
    (WITH.MONITOR \DFStopMonitor (\DFSEnsureDlion)
		  (\DFSEnsureInitialized)
		  (if (NOT (\DFSPhysicalVolumeOK T))
		      then (ERROR))
		  (PROG ((vol (\DFSGetLVPage volName)))
		        (if (NULL vol)
			    then (ERROR (CONCAT "Volume " volName " not on local disk")))
		        (if (LVEqual vol (\DFSCurrentVol))
			    then (ERROR "Can't make a lisp file directory on your vmem volume"))
		        (UNINTERRUPTABLY
                            (PROG [(oldDevice (\GETDEVICEFROMNAME (QUOTE DSK]
			          (if (type? COREDEVICE oldDevice)
				      then (\MYREMOVEDEVICE.NAMES oldDevice (QUOTE DSK)))
			          (if (NOT (type? DLIONDISK oldDevice))
				      then (\DFSCreateDevice)))
			    (\DFSVFMInitMap vol)
			    (\DFSMakeVolumeDirectory vol))
		        (RETURN volName])
)
(DEFINEQ

(\VANILLADISKINIT
  [LAMBDA NIL                                                (* hts: "18-Feb-85 16:33")

          (* * Get rid of old vanilla disk device)


    (for DEV in \FILEDEVICES when (EQUAL (fetch (FDEV DEVICENAME) of DEV)
					 "VANILLADISK")
       do (\REMOVEDEVICE DEV))

          (* * Define a device whose sole purpose is to select the appropriate DSK device depending on which machine you're 
	  on)


    (\DEFINEDEVICE NIL (create FDEV
			       DEVICENAME ← "VANILLADISK"
			       EVENTFN ←(FUNCTION NILL)
			       HOSTNAMEP ←(FUNCTION \VANILLAHOSTNAMEP])

(\VANILLAHOSTNAMEP
  [LAMBDA (NAME)                                             (* hts: "18-Feb-85 16:33")

          (* * Fires up the appropriate file system for the machine you're running on)


    (SELECTQ (MACHINETYPE)
	     ((DANDELION DOVE)

          (* * If there is a valid Lisp directory on the disk, use that; otherwise use the pseudo-disk coredevice)


	       (COND
		 ((NEQ NAME (QUOTE DSK))                     (* Not interested in any other names)
		   NIL)
		 [(AND (GETD (QUOTE \DFSDEVICEP))
		       (\DFSDEVICEP (QUOTE DSK]
		 (T 

          (* * Define the PSEUDO-DSK device, if it hasn't been defined yet, and make DSK synonymous with it.
	  On LOGOUT, the name DSK is disassociated with this device, but the device remains)


		    [COND
		      ((NOT \PSEUDODSK)
			(COREDEVICE (QUOTE PSEUDO-DSK))
			(SETQ \PSEUDODSK (\GETDEVICEFROMNAME (QUOTE PSEUDO-DSK)))
			(replace (FDEV EVENTFN) of \PSEUDODSK with (FUNCTION \VANILLAEVENTFN]
		    (\DEFINEDEVICE (QUOTE DSK)
				   \PSEUDODSK)
		    \PSEUDODSK)))
	     ((DOLPHIN DORADO)
	       (\M44HOSTNAMEP NAME))
	     NIL])

(\VANILLAEVENTFN
  [LAMBDA (FDEV EVENT)                                       (* hts: "18-Feb-85 18:37")

          (* * Disassociates the name DSK from the pseudo disk, in case there's a real disk on the machine now)


    (SELECTQ EVENT
	     ((AFTERLOGOUT AFTERSYSOUT AFTERMAKESYS AFTERSAVEVM)
	       (\MYREMOVEDEVICE.NAMES FDEV (QUOTE DSK)))
	     NIL])
)

(RPAQ? \PSEUDODSK )
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \PSEUDODSK)
)
(\VANILLADISKINIT)
(MOVD (QUOTE NILL)
      (QUOTE \DFSDeviceConflict)
      T)
(PUTPROPS DLIONFSPATCH COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1331 2697 (\DFSCloseFile 1341 . 2122) (\DFSReadOnePage 2124 . 2695)) (2744 5471 (
\DFSTruncateFile 2754 . 3962) (\DFSCreateDevice 3964 . 5179) (\FIX.TRUNCATEFILE 5181 . 5469)) (5527 
6365 (\MYREMOVEDEVICE.NAMES 5537 . 6363)) (6366 7420 (DFSCREATEDIRECTORY 6376 . 7418)) (7421 9684 (
\VANILLADISKINIT 7431 . 8078) (\VANILLAHOSTNAMEP 8080 . 9298) (\VANILLAEVENTFN 9300 . 9682)))))
STOP