-------------------- AmigaOS 3.1.4.(1) project -----------------------

Changes for release 45.2 (16.12.2016)

- Changed the puddle size of the memory pools such that an entire
multiple of the block size of the RAM allocated internal block storage
fits into them. A single puddle can now keep 64 RAM blocks.

NOTE: memory pools are probably not ideal for RAM-Handler usage anyhow,
and a smarter mechanism should be used instead in future releases.

- Updated ACTION_DISK_INFO to correctly return the total available
RAM and hence the correct fill state of RAM:. This avoids problems with
some programs that try to learn whether they have enough free storage on
the target medium for a particular operation. Note that this calculation
includes the safety margin added on the amount of ram the ram-handler does
not allocate for its purposes. Currently, this safety margin is 32K.

Changes for release 45.4 (2.8.2017)

- A link to a delete-protected file could still be deleted, even though its
  protection bits indicate that it cannot.
- Hard links can now have their own file note.
- ACTION_EXALL did not follow links to fill in protection information, file
  date and the file size, and hence reported wrong information for hard
  links.

Changes for release 45.5 (6.5.2018)

- ACTION_DISK_INFO no longer scans for the largest block, just for the size
  of memory available. This may still give somewhat misleading information,
  but at least better information than it did before.
- ACTION_DISK_INFO includes now the overhead of the data structure itself.

----------------------------- AmigaOS 3.2 project --------------------

Changes for release 47.1 (24.4.2019):

- The RAM-Disk supports now "external links", that is, links going to other
  file systems. Whenever such a link is "resolved", the RAM-Disk either
  creates a directory within RAM: if such a directory exists on the link
  target, or pulls the target file into the RAM-Disk transparently. This
  allows RAM: to automatically mirror ENVARC: by the following simple line:
  "MakeLink RAM:ENV to ENVARC: Force"
  "Assign ENV: RAM:ENV"
  and all works transparently: RAM: will not copy all files in ENVARC:, but
  only the subset that is required by the system, as soon as it is required
  by the system.

Changes for release 47.2 (25.4.2019):

- The size of a temporary FileInfoBlock was allocated 4 bytes too small.

- In case creating the external link failed, a lock to the target object
  might have remained.

- The packet delegation function could still return ERROR_IS_SOFT_LINK which
  might trigger a non-supported softlink resolution from RAM: to its
  external link.

- Some minor optimizations.

Changes for release 47.3 (21.5.2019):

- In case resolving an external object failed, the lock to the external
  object was erroneously released.

- The file handler delegation function is now a bit more careful and also
  checks for a ZERO lock to external, upon which it fails instead of doing
  some nonsense.

- Lock now (silently) accepts anything but an EXCLUSIVE_LOCK as ,
  as some programs seem to fail to deliver the right mode.

- Reading a file released a lock twice.

- The special rule of truncating only the first block of a file has been
  extended to the last block as well, allowing to reduce the memory size
  the RAM disk requires for many files that are small, but not quite as small
  as a single block.

- In case an empty file was opened from a lock, a hit might have been created
  upon the next ACTION_READ or ACTION_WRITE.

- Regular sized blocks are now no longer taken from the memory pool. This is
  just more overhead without benefits.

- ACTION_SET_FILESIZE now fails if the file is write-protected.

Changes for release 47.4 (6.6.2019):

- Some file systems delete the lock upon a FH_FROM_LOCK, hence the handler
  has to work with the original lock instead.

Changes for release 47.5 (30.11.2019):

- If the node currently examined is deleted and then ExNext() is called,
  RAM: could have accessed a stale pointer. Fixed.

Changes for release 47.6 (2.1.2020):

- The RAM-handler created a hit (or multiple) in an attempt to
  ExNext() or ExAll() the 0-lock.

Changes for release 47.7 (8.1.2020):

- A SetFileSize() that extended the size of a file left the file
  pointer at the end of the file instead of leaving it untouched.

------------------------ AmigaOS 3.2.1 update ------------------------

Changes for release 47.8 (2.10.2021):

- The external links introduced in 47.1 and used for ENV: to ENVARC: linking
  had a nasty bug. Files could not be deleted from ENV: without them coming
  back immediately. This was somewhat worked around for environment variables
  in dos.library, but that had another side effect as it broke some scripts.
  Now when deleting files that came from an external link are deleted in RAM:
  and don't come back. This removes the need for the dos.library workaround.


ram-handler 47.9 (18.10.2022)

- Lost a couple of files which were not being used at all...

- Changed all 'char' types to 'UBYTE' where they were used as
  strings. Why? Some of these strings may contain a leading
  length field > 127, for example, which then has interesting
  consequences when copying the string.

- Replaced 'short' types with 'int'.

- Made a bold attempt to bring some consistency to code indentation
  and comment formatting.

- locate_external() now uses the fancy D_S() macro which allows you
  to declare a pointer to a LONG-aligned data structure on the stack
  instead of using a global 260-byte buffer. Explained why this
  actually works as intended.

- Because you know it makes sense: renamed parameters called "flag"
  to something which suggests the purpose of the parameter.

- Replacing the volume name now uses AllocVec()/FreeVec() instead
  of the local replacements which may draw from a memory pool.

- There should be no major functional changes in this code, it just
  looks different and, hopefully, still has the same bugs as before.


ram 47.10 (20.10.2022)

- Added diagnostic and debug output which can be enabled through the
  "assert.h" header file. This is a compile-time feature.

- Attempted to make the code readable and not quite so beholden to
  the K&R 'C' legacy of the late 1980'ies when everything was
  permitted and encouraged which produced small source code files,
  often to the detriment of readability and maintainability.
  What does this mean? Variable names now reflect the purpose of
  the respective variables. Integers are compared with integer
  values and pointers are compared with NULL, etc. rendering
  the underlying types more visible. You can now tell better whether
  the variable being checked is an integer, pointer or a boolean
  type. Don't expect any miracles, though :-(

- Although the internal data structures for files and file locks
  are exactly the same, the code now attempts to identify whether
  a file or file lock is required for the specific file system
  implementation. Errors will be produced if the expected type of
  data structure is not found.

- Dropped the GETTRUELOCK() macro, which was basically useless.

- The SetComment() function would always allocate memory for a
  comment even if this was not necessary because it tested the wrong
  pointer, this being a function pointer, actually. Fixed.

- The ExAll() function now aborts processing altogether if the
  designated output buffer is too short to even hold a single
  record.

- The big, impressive function which implements ExAll(), Examine()
  and ExNext() now keys off the packet type to decide what needs
  doing, instead of the first three non-negative integers.

- Repaired the ReadLink() function to properly signal to dos.library
  if the name buffer is too short. Previously, it would fail to return
  the soft link name after the first attempt to use a short buffer
  failed.

- Replaced all uses of memcpy() with memmove() to save space.

- The LockRecord() function now makes sure that it understands the
  locking mode and will reject all unknown mode values.

- Name comparisons are now performed using the ISO 8859-1 rules
  used by the "international mode" of the FFS.

- The Seek() function now verifies that the intended position is
  well within the 2 GByte limit and does not trigger an integer
  overflow. Negative offsets are rejected. Same goes for
  SetFileSize() which will not create files larger than 2 GBytes.
  In fact, if the effective size is greater than 2 GBytes, SetFileSize()
  will not even try to create a 2 GByte file.

- The ChangeMode() code now makes sure that for a file lock the new
  mode is either EXCLUSIVE_LOCK if EXCLUSIVE_LOCK is called for and
  SHARED_LOCK if anything other than EXCLUSIVE_LOCK is used.

  For an actual file, ChangeMode() will use what amounts to EXCLUSIVE_LOCK
  if MODE_NEWFILE is called for and what amounts to SHARED_LOCK if
  anything other than MODE_NEWFILE is used.

  Previously, you could end up with a file lock mode that was neither
  EXCLUSIVE_LOCK nor SHARED_LOCK, etc.

- The Read() function will no longer allow for a negative number of
  bytes to be read.

- The Write() function will no longer allow for a negative number of
  bytes to be written and will abort if the effective size of the
  file would exceed 2 GBytes or trigger an integer overflow.

- Deleted the dbwin.h, dbsupp.c and ram.lnk files because they are no
  longer needed.


ram 47.11 (21.10.2022)

- Added further sanity checks/assertions to notify.c in the hope that
  they will lead to a more robust implementation, or at least an
  insight into what works and what does not...

- The start/length passed to the LockRecord() function uses unsigned
  32-bit integers, yet the whole record locking code dealt with them
  as signed 32-bit integers. What could possibly not go wrong?

  Fixed by using casts as necessary and replacing the signed 32-bit
  integer math support functions in "support.a" with their respective
  unsigned 32-bit integer math variants.

- The record locking range checks performed no overflow tests and
  therefore were unreliable except for 16-bit integer values. Fixed
  by adding overflow detection and changing the none too complex
  calculations to yield the largest 32-bit integer which is part
  of the range. This allows for convenient range checking without
  involving 64-bit integers.

- Documented that lockrecord() may return DOSFALSE, DOSTRUE and
  a previously rather mysterious value known as 1. The value of
  1 now has a name of RECORD_LOCK_NOREPLY which says something
  about its purpose. If lockrecord() returns RECORD_LOCK_NOREPLY
  it means that the DosPacket involved cannot be replied to the
  sender because the associated record locking operation needs
  to succeed/fail first.

- When stopping a pending timer request, a CheckIO() test is
  now performed before calling AbortIO(). This is more polite.


ram 47.12 (22.10.2022)

- Changed node.back to node.parentdir because that actually is the
  respective node's parent node.

- Added more debug mode assertions and sanity checks. Converted some
  of the last remaining debug kprintf() calls into debug output
  function calls.

- Reworked the Rename() code so that the detection of renaming a
  directory entry is somewhat simpler if the old and new names
  are identical or equivalent (with regard to lower/upper case).
  Eventually, just the name may need to be replaced.

- The Rename() code no longer triggers two directory notifications
  if the name of a directory entry was changed.

- Verified that renaming a file from "áéú" to "ÁÉÚ" indeed works
  without causing the corresponding directory entry to vanish.

- Changed the code optimization options to "optimize optsize optinlinelocal"
  which actually saves space. Not much can be done about making this funny
  file system run faster, short of changing how its data structures and
  algorithms work.


ram 47.13 (23.10.2022)

- Lucky number 13!

- The delegate() function now produces more diagnostic output. Some
  of it may actually be helpful ;-)

- Creating a soft/hard link now produces more diagnostic output in case
  it might be useful.

- Hard links can reference files or directories, which rendered the
  local lock type validation call useless I had added. This turned into
  a bug. Thanks go to Thomas Klein for providing the log files which
  identified the issue.

- You can no longer create hard links to the root directory, which was
  a side effect rather than a real feature. The FFS cannot do this either.


ram 47.14 (23.10.2022)

- Added more diagnostic output to the hard and soft link creation code,
  including the portions which deal with the delegation mechanism.

- Found a very rare blue-white striped memory leak in the delegate()
  function which could result from a memory allocation failure (oh,
  the irony).

- Renamed the 'struct node' "prot" member to "protection" which does not
  have to be quite so short.


ram 47.15 (3.11.2022)

- Figured out which functions return TRUE/FALSE and which ones need
  to return DOSTRUE and DOSFALSE (also known as "quadruple precision
  boolean") values. Made the return values consistent. If possible,
  the rspective local variables which carry that boolean value around
  until returned are now called "success" rather than "res" or
  "result".

- Removed casts of the BADDR() return value to specific pointer types
  because BADDR() casts the BCPL pointer to 'APTR' anyway, or has
  started to do that with the AmigaDOS 2.0 header files which have
  been released somewhat recently.

- Introduced fancy macro alias names for TRUE and FALSE, as passed to
  functions such as locatenode(). So, for example, locatenode(foo,bar,FALSE)
  now reads as locatenode(foo,bar,FINDENTRY_DONT_FOLLOW_LINKS). This rendered
  quite a number of "useful" code comments such as those which said
  "don't follow links", etc. redundant and also helped for those few
  instances in which the explanatory comments as to what FALSE/TRUE stands
  for this time around were wholly absent.

  One peculiar case of this is the result of the checkname() function,
  which previously returned TRUE or FALSE but didn't really say what
  that meant. Now the result of checkname() is compared against
  CHECKNAME_LOOKS_BAD (== FALSE) to indicate what went on here. Previously,
  "if (!checkname(foo))" suggested that the name could not be checked
  rather than that the string pointed to by "foo" did not pass muster
  in terms of being a valid directory entry name in the first place.

- Rewrote how the ExAll() implementation deals with all those mysterious
  magic numbers by plugging in either the respective associated constant
  values (as per #include <dos/exall.h>, for example) which gives a name
  to its purpose or by writing out which data structure members are involved.
  This looks complicated but is really the documentation you needed to make
  sense of this stuff.

- Fixed a real, actual, honest bug in the ExAll() implementation which had a
  certain chance to corrupt the contents of the ExAll() buffer (or what
  followed it) because the alignment byte sometimes added at the end of each
  record was not counted towards the total size of the record when the "does
  this record really fit into the buffer?" test was made. Better 32 years
  too late than never.

- The Examine() and ExamineFH() implementation now initializes the
  FileInfoBlock buffer to be 0 before it continues to fill in whatever needs
  to go in there. Previously, any gunk left in that buffer would carry over
  into it which mostly affected the user and group ID information which was
  totally bunk for ram-handler. Now you know why :-(

- You may not know it, but some software passes the same address to
  ReadLink() as the path string and the resolution buffer. This mostly
  works by accident unless it does not work for some truly mysterious
  reasons (?!?). The implementation now makes a copy of the path string
  before the buffer is modified if it finds path string and buffer to
  have the same address.

- Fixed two instances in which the ReadLink() code could fail to report that
  the resolution buffer was too short, actually.

- The SameLock() implementation now returns DOSTRUE rather than just TRUE if
  two locks are referring to the same object.

- Both Read() and Write() take a signed length/size parameter. The
  implementation now reflects that, with consequences down the line.

- Reworked the naming of local variables in the Read() and Write()
  implementations, respectively, because they apparently still adhered to the
  original BCPL naming when space (screen space, too) was at a premium. The
  new naming hopefully makes things clearer, which the source code comments
  (if any) not always succeeded at.

- The checkname() function is now used by the renamedisk() function, now
  making it impossible to relabel "Ram Disk" as ":/:\t\033", like you might
  be accustomed used to.


ram 47.16 (4.11.2022)

- Added support for the particularly elusive ACTION_SET_OWNER packet
  type, which was introduced rather recently, but never to ram-handler.
  To get into the right spirit, I made good use of the fact that you
  can access the owner user ID and owner group ID information as a
  single 32-bit word. Looks too clever for its own good, though. But
  when in Rome, do as the Romans do.

- Changing the comment attached to a directory now allocates memory for
  the new comment first, and if that should fail, will back out without
  removing the current comment. Previously, it set the current comment
  to "" first and then attempted to allocate memory for the new comment.

- Deleting a directory entry for which hard links exist will make the
  owner/group information move to the next link which will become
  the "original".

- ExAll() now supports ED_OWNER and Examine(), ExamineFH() and ExNext()
  will fill in the owner information.


ram 47.17 (5.11.2022)

- The optimization in shrinkfile() was not entirely robust. Its purpose
  is to shrink the last block of a file if it does not fill the entire
  1 KByte data block. Whether this made sense was determined by whether
  the difference between the maximum block size and the actual "payload"
  of the data block was larger than 4 bytes, because that apparently made
  a difference for the exec memory allocation, saving perhaps 4 bytes
  or even more. Turns out that the threshold value is 8 bytes.

  Fixed that one.

  Good enough? Not by a long shot. Turns out that if the final block
  of any file was smaller than the maximum possible block size, it
  would *always* get reallocated when the file was closed, even if
  the file was opened for read access only. Reallocating the final
  block both involved allocating new memory for the block and copying
  the contents of the old block into the new one, of course.
  New code has been added which checks if this is needed and, more
  importantly, if it has already been done and won't have to be done
  all over again.

- Adjusted the memory puddle size to take the memory allocation
  granularity into account, which should produce more accurate
  memory allocation threshold boundaries.

- Documented what the numbers underlying the contents of the
  'str_offset' table in exall.c actually mean.

- The 'struct notify', 'struct record_lock' and 'struct rlock_wait' data
  structures actually begin with a 'struct MinNode'. The definitions
  now reflect this.


ram 47.18 (5.11.2022)

- Replaced calls to CopyMem() with calls to memmove() where this would
  result in small code size savings.

- Reworked the renamedisk() function so that it becomes even more clearer
  which specific purpose each respective memory allocation serves.

- Changed the seek() code which performs file size extension for SetFileSize().
  Instead of passing a pointer to a preallocated 1024-byte buffer containing
  zeroes, it now signals to the write() function which performs the file size
  extension that no data should be copied, but that the data block contents
  should be set to 0 instead. This increased the total size of the code by
  some 40 bytes.

- Refactored the swapblock() function as well as the code which made
  use of it, thereby eliminating duplicate code which could now be
  shared. This resulted in saving some 64 bytes of code.


ram 47.19 (6.11.2022)

- Removed the length limit check in the MakeLink() code which assumed that
  a soft link target string could not be longer than 255 characters due to
  BSTR limitations. The ReadLink() code both in dos.library and ram-handler,
  however, uses 'C' strings and has no limitations other than imposed by the
  size of the path resolution buffer provided. Possibly, the length limit
  check may have been a historic artefact while the soft link resolution API
  was still under development.

- Removed dead code from the ReadLink() implementation which is not needed
  and also happens to save a bit of space.

- Combined code size savings amount to about 50 bytes.

- Added a helper function to makelink.c which can assist in keeping the
  total length of the soft link resolution string in check. This is badly
  needed and should be part of dos.library, really. Sadly, that function
  would contribute another 150 bytes of code, so it remains disabled for
  the time being.


ram 47.20 (7.11.2022)

- How to save 48 bytes of code? Easy...

  1) Replaced the lone memmove() call in comment() with a call to BtoC()
  2) Small refactoring of createnode()
  3) Refactored openmakefile() so that creating a new file no longer
     uses two different but almost identical code paths
  4) Refactored mygetvec.c to eliminate duplicate code and stub functions,
     then reworked how ram-handler uses the memory allocation function
     which is used only for allocating data blocks
  5) Refactored FindMsg() not to check if the list of available messages
     is empty. It's easier to call RemHead() and then allocate memory
     for a new message if the result was NULL.

- How to lose 48 bytes of code saved? Easy...

  1) Discovered that deleting an external link created by the delegation
     mechanism was merely shuffling it over to a designated separate
     list within its parent directory
  2) Found that such deleted external link nodes could never be freed,
     even if you deleted the parent directory which would contain them
  3) Added the necessary cleanup code which, as a side effect, now
     correctly updates the number of "blocks in use" by ram-handler
     (previously, deleting an external link node would pretend that
     its memory had been freed)

- How to lose even more code saved? Implement the code necessary to
  allow for deleted external links to be correctly overwritten. Currently,
  this is not feasible and produces mysterious and hard to explain
  errors.

- create() no longer trashes a file's comment if it discovers that the
  file to be overwritten is write-protected. This is possibly the oldest
  known (at least to me) bug in ram-handler recently fixed, which goes
  back to the days when the original BCPL version was still in use.

- create() no longer triggers the change notification mechanism until
  after it has succeeded in obtaining a lock on the file just created.

- Renamed freelist() to free_block_list() because that's what it does.

- Before delete() finally frees an object or stores the object in the
  parent directory's list of deleted external link nodes, it now
  frees the object's comment text to save a bit of space. The comment
  would never be needed again, only the name is relevant.

- Reworked seek() to use variable names other than "p" and "ptr"
  which you might assume stood for a pointer and a different kind of
  pointer, possibly a more sophisticated one. Turns out that "p"
  was a pointer to a data block (a memory address) and "ptr" was the
  read/write position within the file (a scalar). Now we can finally
  dispense with the code documentation which described the purpose
  of "p" vs. "ptr". Mercifully, there was none to begin with.

- Changed the 'struct node' members 'block', 'offset' and 'cpos' to
  the more obscure and mysterious "current_block", "current_block_offset"
  and "current_file_position" but left what passes for code documentation
  regarding the structure members intact in order to educate and/or
  entertain the casual reader.


ram 47.21 (8.11.2022)

- Reworked the names of the 'struct node' members to make a little
  more sense, rather than requiring code comments to explain what
  they are good for. Shuffled the metadata information to the
  beginning of the 'struct node'. Lost the 'fromExtern' member
  because it duplicated what the former 'externlock' member already
  provided.

- Removed duplicated code which initialized the former 'struct node'
  'deletedSoftList' member. The initialization now happens only
  once when the node is allocated.

- Simplified the code in delete() somewhat which deals with the
  original file/directory entry getting deleted and the first
  hard link associated with it becoming the "new original".

- Simplified the exall() function even further by eliminating
  unnecessary initializations and tests.

- Fixed an ancient subtle bug in exall() which could lead to
  an infinite loop on the client's side. If the output buffer
  was too short to hold even a single complete directory
  record, the old code would return an "empty" ExAllData
  structure with uninitialized data and also indicate that
  there was more data to be read. If the client then
  attempted to resume scanning, it would be served the
  same uninitialized data again, with an indication that
  there was more data to be read. Plenty of opportunity
  for things to go wrong :-(

- Simplified the handling of nodes with external references
  in makelink().

- Bug fix included, these changes save 68 bytes of code :-)


ram 47.22 (8.11.2022)

- When deleting directories which have hard links attached,
  the deletion now frees the list of deleted soft links, too.
  The first link becomes the new original, which may sit
  in a different directory and/or have a different name than
  the original directory being deleted. This renders the deleted
  soft link list useless.


ram 47.23 (8.11.2022)

- Changed how ram-handler determines whether a directory entry is
  a file or directory. Two macros now test if the type of directory
  entry is negative (must be a file) or positive (must be a directory).
  This actually saved 16 bytes of code.

- Discovered that ram-handler allowed Examine() to be followed by
  ExNext() on a file, leading to unpredictable behaviour. Fixed this
  by checking whether a file is involved at the ExNext() stage,
  aborting the operation if this is so with error code
  ERROR_NO_MORE_ENTRIES. This consumed the 16 bytes saved.

- Reactivated the soft link path reduction code. This consumes
  an additional 132 bytes.


ram 47.24 (9.11.2022)

- Changed the name of the 'struct node' "block_list" member to
  "contents_list" because it holds 'struct node' entries for
  directories and 'struct data' for files and soft links.
  "block_list" was too specific after all :-(

- Deleting directory entries from a parent directory associated
  with an external lock must remember the names of the respective
  directory entries. Previously, the node to be removed had to
  feature an external reference, too. For the sake of consistency,
  the list of deleted directory entries on an external file
  system must not contain duplicates, which is what the delete()
  function now takes care of.

- Renaming a directory entry or moving it into a different
  directory now has the effect of purging the deleted soft
  linked directory entry names, just like it happens with
  the delete() function.

- Changed the naming of several local variables in exall.c which
  were either called "node" or "ptr", making it hard to tell
  what purpose they served, specifically. This was particularly
  peculiar because in all such cases both "node" and "ptr"
  were pointers to the 'struct node' data structure.

- Renamed resolve_external() to resolve_external_file() because this
  is closer to its purpose.

- Replaced multiple uses of delegate() calls which only freed a lock
  by calling a single dedicated free_delegate_lock() function instead.

- makelink() no longer converts a FileLock BPTR into a 'struct FileLock'
  pointer twice. Once should be perfectly sufficient.

- makelink() could fail to release the external lock it obtained if
  an error had occured. Fixed.


ram 47.25 (10.11.2022)

- More refactoring, renaming odd variables and functions to something
  that should hopefully require no additional detailed documentation to
  describe their respective purposes. Added more code documentation in
  case it might be useful someday.

- Extracted the function which checks if a deleted directory entry for
  a remote directory is already known. This function is used twice and
  should not need to be duplicated.

- Removed a small mountain of special purpose code which sometimes
  checked if a file already had a data block attached, but sometimes
  didn't for reasons which are hard to explain. Removed a somewhat
  smaller mountain of code (let's call it a hillock) which then
  sometimes added a new data block if perhaps needed. There is now
  just one function left which can add data blocks to files, other
  than the one which copies data from an external source, and it's
  write(). If data is to be written to a file which is writable
  and has no data block attached yet, it will be allocated and added
  as needed.

- Deleting an entry from a remote directory checked the wrong
  directory node. Oops.

- findentry() could fail to return a proper error code if the
  locate_external() and resolve_external_link_to_file() functions
  failed. This is an old bug :-(


ram 47.26 (11.11.2022)

- Merged "ram.h" and "ram_includes.h" into a single header file "ram.h".

- ram-handler can now be built without falling back onto the global
  SysBase symbol. This will save 32 bytes of code and run slightly
  slower. But then this is a file system which is by nature limited
  to what dos.library can do. And dos.library always uses AbsExecBase
  and has no SysBase pointer to reference.

- Updated the code documentation again and added further assertions.

- The delegate() and makelink() functions no longer check for soft link
  directory entries when performing Examine(). The reason being that
  Examine() uses a FileLock and dos.library always resolves a soft link
  to a file or directory (or hard link to one of these). If the soft
  link cannot be resolved, it will return NULL and set the error code to
  ERROR_IS_SOFT_LINK.

- Replaced a handful of double pointer indirections in the record locking
  code which actually saved space. The compiler cannot know that the
  'struct DosPacket' pointer addresses being referenced in this manner will
  not change.

- The rename() function now handles the NULL (or ZERO) lock better, testing
  the result of the checklock() function for the respective source and
  destination directories.

- Replaced the assert.c/assert.h files with the most recent variants, taken
  from the layout.gadget source code.


ram 47.27 (12.11.2022)

- create() now initializes the associated lock's "current_block" pointer
  to make sure that it is never NULL. getlock() already does this for
  existing directory entries, so now we have all the instances covered.

- Changed delegate() to use a single 'struct StandardPacket' instead of
  separate 'struct DosPacket' and 'struct Message' variables. This is a
  bit more readable and also reduces code size.

- locate_external() now insists that the comment text for a directory
  entry must be preserved. This is a file system after all, and its
  job includes looking after the metadata.

- Renamed findnode() to find_by_node() and locatenode() to find_by_lock().
  These two functions perform almost exactly the same task, with the
  difference being what type of data structure (or NULL pointer) is
  provided as the starting point of the search.

- getlock() now uses memset() on the lock memory allocated for good
  measure. That way, the lock contents are always consistent and the
  individual data structure members do not need to be zeroed one
  at a time (you might overlook one).

- Moved the freelock() code portion which combined verifying that a
  lock is valid and removing it from the BCPL lock list into its own
  dedicated function, called unlink_lock(). That code is still ugly,
  but now you can look away when dealing with the freelock() code ;-)

- change_lock() now makes sure that a NULL lock parameter will always
  produce the error code ERROR_INVALID_LOCK.

- The seek() function could stumble into undefined behaviour because
  any file opened or created no longer has a single data block attached
  until the first write operation takes care of that. The logic in
  seek() only handled those cases correctly in which the current
  read/write position was to be changed, but if it remained as it was,
  (e.g. for Seek(fh, 0, OFFSET_BEGINNING)) would produce a seek error.
  This has been fixed. Thanks go to Thomas Klein who found and reported
  the problem!

- Changed seek() to set the IoErr() value to 0 before doing any
  actual seeking. That way, a negative Seek() return value will
  have a meaningful IoErr() value if something went wrong with
  the file handle, for example.

- Changed the file system's main packet switch() to be shorter and
  not to use jump labels directly following a "break" statement.
  Turns out that the switch() table had three distinct "case"
  statements which were equivalent to the default case. The compiler
  generated code for these labels which were basically useless.
  Removing them reduced the code size.

- Changed the utility.library integer function calls in support.a
  to see what impact it has if they use a scratch address register
  instead of A6 when calling them (shades of Folsom Prison Blues).
  This is permitted and intended to help in keeping ROM space usage
  in check. Turns out that here it saves 20 bytes of code.

- Dropped a handful of code comments which are no longer helpful,
  needed or have stopped making sense.

- Validation of locks, indicating whether or not they refer to a
  file or a directory, have been changed, as needed, to use the
  results of the checklock() function. If the API calls for a file
  or a directory, checklock() will say whether the lock is sound
  and whether it refers to the expected type of directory entry.
  This is both more robust in context and saves space.


ram 47.28 (13.11.2022)

- Replaced the integer constants representing the maximum file name
  and comment lengths with sizeof() expressions which the compiler
  can evaluate at build time. Less of a chance to pick the wrong
  number. Also added a constant which represents the size of the
  string buffer for a file name. None of these changes affect the
  code size, for a change.

- Fixed a loophole in the delegate() function with respect to
  message handling. When waiting for the packet just sent to
  return, the code now correctly checks for the packet to come
  back, for file notification messages to arrive and for
  record locking timeouts to elapse. Up until now, the record
  locking timeouts were delayed until the main packet handling
  loop in start.c would resume. That cost some 72 bytes of
  code size.

- Removed the "ram_rev.h" header file because only the "ram_rev.i"
  is needed to build this component.


ram 47.29 (13.11.2022)

- locate_external() now initializes the local FileInfoBlock buffer
  to 0, prior to using it with an ACTION_EXAMINE_OBJECT packet.
  This is necessary because the file system which receives that
  packet might not fill in anything but the fields it understands and
  supports. This is problematic for the fib_OwnerUID and fib_OwnerGID
  fields which could then remain unitialized, containing unpredictable
  values.


ram 47.30 (15.11.2022)

- Moved the lock/file handle validation out of the respective
  functions and into the main packet handling loop, if possible.
  This turns out to be more space-efficient and avoids the special
  case of read() and write() being used by the MakeLink() and
  ReadLink() code being blocked. Ouch.

  This change fixes soft link resolution which I broke just a
  week ago :-(

- Parameter validation now specifically avoids mistaking a soft link
  for a directory thing.


ram 47.31 (16.11.2022)

- Overwriting a directory entry in a directory which is linked to an
  external resource now cleans out the associated deleted directory
  entry, if any, freeing up any memory wasted on it. A real bargain
  at only 24 bytes of extra code needed. Can't be sold separately.


ram 47.32 (16.11.2022)

- Fix for SetFileSize(fh, 0, OFFSET_BEGINNING) which affected global
  environment variables. Thanks go to James Jacobs for finding and
  reporting the problem!


ram 47.33 (16.11.2022)

- SetFileSize() did not work correctly if an empty file was created
  and then resized, allocating the first data block. Fixed.


ram 47.34 (17.11.2022)

- In place of more code documentation which may have been necessary
  to clarify the purpose and intent, reworked the naming of data
  structures, parameters and functions. No functional changes.

- Added more assertions, specifically to ferret out unexpected
  effects of the current block pointer.

- Moved one set of variable initializations in transfer.c which were
  not needed so early in the write() function body, thereby saving
  a whopping 4 bytes.


ram 47.35 (19.11.2022)

- Fixed typos in the existing documentation.

- More rework for data structures, structure members, variables,
  parameters and functions, in place of new code documentation
  making sense of what the previous names supposedly stood for.
  Added some more documentation, though, because it might become
  useful one day.

- Managed to find some redundant code which could be removed
  without loss of functionality. Shaved off a modest 24 bytes
  of code.


ram 47.36 (20.11.2022)

- How easy it is to break ACTION_RENAME_DISK by mistake. Thanks
  go to Mikhail Malyshev for spotting and reporting the problem!


ram 47.37 (20.11.2022)

- Truncating the volume name, if necessary, needs to be taken
  into account, too.


ram 47.38 (21.11.2022)

- Found some more unused code in setinfo() which was never, ever used.

- Added missing NULL pointer checks in both findentry.c and makelink.c,
  which somehow amounted, along with the setinfo() code removal, to
  a total of 8 bytes of code size saved.

- Of course, 'struct lock' used to contain a structure member by,
  wait for it, the name of "lock". Which is actually not a self-reference
  but a reference to the 'struct FileLock' which 'struct lock' is
  an extension of.

- Corrected the usual remaining typos and punctuation errors.


ram 47.39 (23.11.2022)

- If findentry() succeeds in finding a soft link, it now skips the
  code which might just try to resolve an external reference. This
  is apparently unnecessary because the soft link was correctly
  identified and is slated for resolution.

- Turns out that walking down the list of directory entries in
  findentry() does not need to be that complex and can result in
  some small code size savings of 14 bytes.


ram 47.40 (23.11.2022)

- More refactoring to turn terse parameter and variable names into something
  which speaks for itself. Further fixes for documentation which no longer
  really agreed with the implementation. Added more code documentation.

- Found a bug in the swap_block() function which was already present in the
  Kickstart 2.0 ram-handler. When writing to a file whose last block is
  shorter than the default, ram-handler will call grow_block() and expects
  it to be replaced by a standard-size block. This never worked safely
  because grow_block() never returned NULL if swap_block() failed to allocate
  memory for the replacement. ram-handler would eventually try to allocate
  a new block if this attempt to "grow" it would fail. Nevertheless, it makes
  sense to check if the allocation failed and to stop the write operation.

  Bug fixed by making swap_block() return NULL in case of failure, which only
  grow_block() function tested for. Somehow, this fix managed to save some 8
  bytes of code.


ram 47.41 (24.11.2022)

- Added a NULL pointer check to delete() which could have caused
  hickups if Delete(NULL, name) had been called (the NULL lock is equivalent
  to a lock on the root directory). We just skip the part which would have
  attached a deleted directory entry to its parent directory because you
  cannot delete the root directory and the root directory can never
  be a hard link to an external directory.


ram 47.42 (26.11.2022)

- The delegation mechanism always created the on-demand copy under
  the same name as the file found on the external volume. This was
  almost always correct, except when the file on the external
  volume was a hard link to a file of a different name. In such a
  case the copy was created under that different name, which broke
  file notification and ended up adding another copy of the file
  data under that different name in RAM:.

  This bug has been fixed at the terrible expense of 60 bytes and
  might not work consistently for directories with nested // parent
  directory path references. There seems to be no remedy to this,
  though, at least for now.


ram 47.43 (4.12.2022)

- Documented how ram-handler ought to deal with soft links in the delegate()
  function, just to make sure that the technical limitations of the soft
  link resolution are not forgotten.

- The ACTION_FREE_LOCK packet handling within the delegate() function must
  never result in the global error code (stored in the "fileerr" variable)
  getting clobbered. Turns out that this is done most robustly within the
  delegate() function instead of writing new code which would save and then
  restore the value of the "fileerr" variable. This change thus did not
  change the size of the ram-handler.


ram 47.44 (21.12.2022)

- Replaced the function which figures out of the sum of two signed
  32 bit integers would produce a numeric overflow with a much
  simpler implementation. This should save 16 bytes of code :-)


ram 47.45 (27.2.2023)

- Very late, but still in time, it turned out that the rename operation
  did not verify if the entry to be renamed would collide with a directory
  entry within the destination directory. The test which would have avoided
  this outcome sat in the wrong place, a victim of crude refactoring gone
  very wrong indeed.

  As before, Mikhail Malyshev spotted the problem before it could turn
  into a greater embarrassment. Thank you, most kindly!

- Surprisingly, the rename bug fix work also revealed that the lock on
  the destination object was never used. Removing it saved a little
  ROM space.


ram 47.46 (8.5.2023)

- Raised the "low water mark" which defines how much memory must be
  available for data block allocations to proceed from 32 KBytes to
  to 128 KBytes. It has been 32 KBytes since 1985. If the largest
  free memory block happens to be 128 KBytes or smaller, then
  no memory for new data blocks may be allocated.


ram 47.47 (20.5.2023)

- Updated the code which assists in debugging ram-handler so that it
  may yield more information.

- Found & fixed a bug in the debug output of the Examine/ExNext
  support which had the effect of the debug output indentation
  increasing with every call.

- If possible, the file system now displays the name of the Process,
  Task or CLI command which sent the packet it is supposed to
  process.

- The specific name of the packet to be processed is now displayed
  in the debug output.


ram 47.48 (20.5.2023)

- Dropped an unwise optimization for file size change collisions
  which should have stuck around. So much for optimizing ram-handler
  for size and the price you might end up paying for it :-(  The
  total size of ram-handler is now 12284 bytes.

  The change now has the effect that SetFileSize() truncating a
  file to size which renders the file handle "current position"
  invalid is silently permitted, and this respective file handle
  will have its "current position" updated.


ram 47.49 (21.5.2023)

- This is the first version of ram-handler which only uses memory
  pools for managing file data and every other kind of data.
  Previously, file data would be allocated via AllocMem() and
  sometimes smaller portions of that would be allocated from a
  general memory pool.

  This version now draws file data from its own dedicated memory
  pool and this goes, too, for data block tail allocations which
  may be much shorter than a full block. This memory pool uses
  a puddle size which allows for up to 4 full data blocks to
  share it.

  Every memory allocation made for file data checks first if
  the total amount of memory available right now is lower than
  a certain threshold value, and if so, will stop the attempt
  to allocate more memory. Previously, this threshold test was
  reserved for full-sized data blocks. Querying the total
  amount of available memory is much faster than determining the
  size of the largest memory fragment, which was the previous
  metric used for deciding whether new memory should be
  allocated.

  The minimum total amount of memory which has to be available
  for a file data allocation is 64 KBytes now.

  Everything which is not a file data block comes from a general
  memory pool which uses a puddle size of 4096 bytes.


ram 47.50 (22.5.2023)

- Changed how ram-handler reports its memory usage, e.g. for use
  with the dos.library/Info() function.

  Previously, the number of data blocks used by files were counted
  along with the number of directories and directory entries (each
  of these was assumed to be worth as much as a single data block)
  and this information was then used by the ACTION_INFO and
  ACTION_DISK_INFO packet processing. The mélange of data blocks and
  directories/directory entries was then transformed into a
  fictional number of blocks, which sometimes correlated with the
  actual memory usage of RAM: at the time. The total number of
  blocks was then arrived at by dividing the amount of available
  public memory by the same fictional block size.

  All of this is gone now... The new approach attempts to make the
  memory usage reported by Info() more consistent by actually
  checking how much memory is currently allocated by ram-handler,
  which is a truly novel concept.

  Because ram-handler now exclusively uses memory pools both for
  the data block storage and everything else, counting the number
  of bytes allocated by ram-handler becomes much simpler, but
  requires insight into how exec memory pools work.

  That number of bytes used is now easy to transform into something
  which Info() can make use of and the fictional block size is
  no longer quite so ficticious.


ram 47.51 (27.6.2023)

- Moved a name collision test in the rename() function, so that
  changing the name of a directory entry to something equivalent
  (e.g. "name" is equivalent to "NAME", and certainly to "name" as
  well) is no longer rejected because an object of that name
  already exists (D'oh!). Thanks go to Rainer Müller for reporting
  the problem!

- Added a bit more documentation for the finddir() function, which
  is somewhat misnamed and its parameters are, too.


ram 47.52 (28.6.2023)

- Changed the behaviour of ACTION_CHANGE_MODE to reflect how the
  dos.library approaches the problem. For files, any Open()
  mode of MODE_NEWFILE/MODE_OLDFILE/MODE_READWRITE is converted
  into EXCLUSIVE_LOCK or SHARED_LOCK. If the lock type is not
  understood, it will be rejected.


ram 47.53 (10.10.2023)

- Reworked the overly complex memory pool accounting code which
  delivers the total amount of memory allocated for RAM:. The
  previous version was unable to properly determine the size
  of a large allocation, producing comically wrong usage
  information for the RAM: device. Thanks go to Brian Carpignano
  for finding and reporting the problem!


ram 47.54 (9.12.2023)

- Restored the ReadLink() buffer overflow handling behaviour,
  which involves returning -2 as an error indication, with the
  minimum buffer size required returned in IoErr().


ram 47.55 (10.12.2023)

- Removing the memset(fib, 0, sizeof(*fib)) resolved the issues
  with the Workbench 1.2 "Dir" command crashing.

  As research into the BCPL CLI commands showed, almost every single
  command which made use of the Examine()/ExamineNext() functions would
  reserve space on the stack only for the fib_DiskKey..fib_Comment fields
  plus one 32 bit word. In total, this is 32 bytes shorter than
  sizeof(struct FileInfoBlock), has been since the Kickstart 1.0 days.
  The "Assign", "CD", "List", "Path" and "Which" CLI commands use a
  FileInfoBlock structure which covers only the fib_DiskKey..fib_Comment
  fields.

  The memset(fib, 0, sizeof(*fib)) performed by ram-handler would end up
  corrupting the BCPL stack, leading to the crash. This problem exists
  on perhaps a smaller scale since dos.library V39 added extra code
  for the BCPL call which winds up invoking Examine/ExNext to reset the
  fib_OwnerUID/fib_OwnerGID members to 0 first. This, too, can corrupt
  the BCPL stack for the "Assign", "CD", "List", "Path" and "Which"
  CLI commands.


ram 47.56 (8.1.2024)

- Fixed a bug in the finddir() function, caused by the global path_pos
  variable not being initialized to 0. This bug would affect link
  resolution, and not in a good way. Thanks go to Thomas Richter for
  pointing out its presence!

- The volume name provided by ACTION_RENAME_DISK is now truncated to
  30 characters, which is the operating system limit for device,
  assign and volume names.

- Changed the names of all the functions which are called directly
  from the DosPacket handling loop and nominally should serve only a
  single purpose (do what the packet says). This makes it easier to
  identify functions which are not used just in the DosPacket handling
  loop, but also indirectly, such as by action_read() for retrieving the
  name of a soft link target.

- As per Thomas Richter's request, reviewed the file system code
  which tinkered with the global variable value that would invariably
  become the secondary DosPacket result value, even if this made no
  sense or caused side effects later on the client side. Some code
  is apparently happy to check if a function succeeded by comparing
  the IoErr() result against 0 and this is what we get now. I wonder
  how many of the other dozen Amiga file systems and handlers are as
  diligent as ram-handler is now in this regard.

  Added new code which made sure that the secondary result value would
  be 0 if the respective DosPacket action succeeded. This was either
  the responsibility of the respective packet handling function, or
  could be moved to a common set of tests within the DosPacket loop
  itself. For example, many packet actions indicate failure by returning
  a result value of 0 (zero) or of NULL. The common test code now just
  checks whether result value is non-zero and then sets the secondary
  result value to 0 if this is the case.

- Rearranged the packet type checks in the DosPacket loop for the benefit
  of reducing duplicate code. This worked so well, with all the
  changes made, including the common success tests in the loop, that this
  version of ram-handler is just 4 bytes larger than its precursor.


ram 47.57 (24.3.2024)

- The ACTION_SET_FILESIZE packet handling could lead to a file staying
  the same size, rather than becoming shorter. Thanks go to
  Mikhail Malyshev for spotting the problem! And just for once, the
  bug fix even resulted in saving 12 bytes of code.

- The ACTION_WRITE packet handling code no longer assumes that the
  file was changed when it exits without indicating an error
  condition. For example Write(file, "", 0) would have counted
  as changing the file. The new code now sets the "this file was
  changed, trust me" flag if data was copied from the client buffer
  to the file or data was set to zero via ACTION_SET_FILESIZE.
