home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / amiga / programm / 17591 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  5.5 KB

  1. Path: sparky!uunet!cbmvax!jesup
  2. From: jesup@cbmvax.commodore.com (Randell Jesup)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: A few Handler/FileSys Q's (Mod.Long.)
  5. Message-ID: <38054@cbmvax.commodore.com>
  6. Date: 19 Dec 92 01:22:31 GMT
  7. References: <1992Dec17.051905.1@economics.adelaide.edu.au> <1992Dec18.120551.3866@odin.diku.dk>
  8. Reply-To: jesup@cbmvax.commodore.com (Randell Jesup)
  9. Organization: Commodore, West Chester, PA
  10. Lines: 103
  11. Keywords: handler filesystem packets Amiga DOS AmigaDOS lock FileLock
  12.  
  13. bombadil@diku.dk (Kristian Nielsen) writes:
  14. >Now, say the handler has to put up a requester. This is done in the
  15. >usual way using EasyRequest() or whatever. The usual approach would
  16. >be to have some code like
  17. >
  18. >    EasyRequest(winptr, &myrequest);
  19. >    WaitPort(myicdmport);
  20. >
  21. >However, this would lock out *ANY* access to the file system while the
  22. >requester was being displayed. To avoid this, the WaitPort() is replaced
  23. >by a coroutine context switch to the coroutine doing the central handler
  24. >loop. Later, when the requester is satisfied, the coroutine doing the
  25. >EasyRequest() will be resumed.
  26.  
  27.     Well, actually the filesystem almost never puts up requesters itself -
  28. that's normally done by dos (using ErrorReport()).
  29.  
  30. >The usual way to implement coroutines involve having seperate stacks for
  31. >each coroutine, swapping them when nessesary. The ROM file systems may
  32. >do it differently, we'd need one of the commodore gurus to give the
  33. >details.
  34.  
  35. How The Amiga FS Works (preview showing, by invitation only):
  36.  
  37.     Yes, they're coroutines (BCPL ones).  Anything that blocks in exec
  38. (i.e. Wait()) will stop all of them.  Internally, it switches around between
  39. them as needed (no preemption).  CallCo() will swap to a coroutine (much like
  40. jsr), WaitCo() returns a results to the parent (much like rts).  One important
  41. difference with subroutines is that the coroutines maintain their own stacks
  42. and state.  ResumeCo() is basically a branch to a coroutine (as if it had
  43. been CallCo'd by your caller - much like exiting a subroutine with jmp
  44. some_other_subrutine).  There are various other utility functions, like
  45. StartCo, KillCo, CreateCo, etc.
  46.  
  47.     Each open filehandle is a coroutine.  The master coroutine CallCo()'s
  48. it when it gets a packet or when IO comes back.  Note that this is where the
  49. stack-based state information of the coroutine come into play - a filehandle
  50. coroutine does IO by queuing a request, and calling WaitCo().  The disk
  51. read/write coroutine pulls things from the queue and gets woken up when IO
  52. is done.  When an IO is complete and verified, it notes which coroutine is
  53. waiting for the IO to complete (can be a list), and ResumeCo()'s that 
  54. coroutine.  Since the coroutine has a stack, it continues at the point after
  55. the WaitCo with whatever it was doing, now knowing the IO was complete.
  56. Note that the master coroutine doesn't CallCo() an active filehandle coroutine,
  57. it queues the packet for later handling.
  58.  
  59.     If this seems simple, I guarantee you, IT'S NOT.  It's mind-warping
  60. and arcane when you need to care about the coroutines (but easy and
  61. straightforward when you don't).  A lot of state information becomes 
  62. automatic, without having to build a (massive) explicit state machine.  I
  63. burnt out a lot of brain cells figuring out how to handle locking of updates
  64. to hash chains in this setup, since this required major interactions between
  65. coroutines.  The end result was simple, but it was a bitch to figure out.
  66.  
  67. >ixemul.library by Marcus Wild). For this reason, lock->fl_Task MUST
  68. >remain valid at all times.
  69.  
  70.     Correct.
  71.  
  72. >>3) As a filesystem, if a volume has just been inserted into the device you're
  73. >>managing, and you grab the locks from the dol_LockList, can you Forbid(), go
  74. >>through and change the fl_Task field of all the locks to yourself, then Permit()
  75. >>so that any further use of the active FileLocks will be directed to you?
  76. >
  77. >(minor detail: in 2.0 you use LockDoslist() / UnlockDoslist() instead of
  78. >Forbid() / Permit(). )
  79.  
  80.     Correct, I missed that in my last post.  If you must work under 1.3,
  81. please make the LDL/ULDL calls conditional.
  82.  
  83. >I don't think this should be done. I can hardly imagine it's 'legal',
  84. >for one. Just imagine the instant disaster that would result if you
  85. >somehow mixed of a volume belonging to a completely alien file system!
  86. >Anyway, it shouldn't be nessesary to do this.
  87.  
  88.     You need to make SURE it's the same volume (date AND name AND
  89. DLT_VOLUME).  When you find it, you must change dol_Task in the volumenode,
  90. and the fl_Task's of all of the locks on the locklist.
  91.  
  92. >>4) If, again as a filesystem, I get an argument FileLock for a volume I am
  93. >>no longer managing (volume was ejected from my device), can I, upon inspection
  94. >>of the DosList finding a non-NULL dol_Task field, send the packet onto
  95.  
  96. >Again, the best thing to do would be to ask for the volume to be
  97. >inserted in the right drive.
  98.  
  99.     Fail the packet (note: some packets use -1 for error (read/write/
  100. seek/setfilesize), some use 0 (end(close))), with an ERROR_DEVICE_NOT_MOUNTED.
  101. Dos will put up the Please insert xxx: in device yyy: for you.
  102.  
  103. >[Aside: This asking the user to move the disk might seem unfriendly
  104. >(though it seldom occurs in practice; perhaps dos.library does some
  105. >magic with ASSIGNed names?).
  106.  
  107.     Since Assigns are locks, not filehandles, they can move with the
  108. disk from filesystem to filesystem.  Filehandles, being coroutines, can't.
  109.  
  110. -- 
  111. To be or not to be = 0xff
  112. -
  113. Randell Jesup, Jack-of-quite-a-few-trades, Commodore Engineering.
  114. {uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.cbm.commodore.com  BIX: rjesup  
  115. Disclaimer: Nothing I say is anything other than my personal opinion.
  116.