home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 14 Text / 14-Text.zip / EADAT2.ZIP / EADATA.TXT
Text File  |  1991-04-21  |  10KB  |  178 lines

  1. The EA DATA. SF file, and what it does
  2. ======================================
  3.  
  4. I originally wrote this because of all the queries about the file named
  5. EA DATA. SF file which is a frequent subject of discussion.  I have
  6. tried to explain what it does, why it exists, and what you should and
  7. should not do with it. Various people on CompuServe have given me extra
  8. information; particular thanks to Dean Gibson (73427,2072) who figured
  9. out the format of the EA DATA. SF file and put me right on a few points.
  10. Some of the following information (and nearly all of Appendix A) is due
  11. to Dean.
  12.  
  13. OS/2 1.2 and beyond support the concept of "extended attributes" (EAs)
  14. on files.  These are used for all kinds of things, and can be very small
  15. or quite large (the limit is 64K per file at present).  EAs might
  16. represent a file type, a file classification, an icon type, some free
  17. text...practically anything.  Use the Properties entry in the File
  18. pulldown on the File Manager to see the EAs on a specified file
  19. (actually, I have found that Properties doesn't seem to tell you
  20. absolutely everything). 
  21.  
  22. EAs are supported directly by the High Performance File System (HPFS). 
  23. They are stored in an efficient manner; a small EA does not effectively
  24. take any additional space most of the time (typically, if it is less
  25. than several hundred bytes). 
  26.  
  27. However, for backwards compatibility the DOS (File Allocation Table, or
  28. FAT) file system needs to support EAs too.  In order to do this, and
  29. keep the file system consistent for DOS if it is booted instead of OS/2
  30. on the same machine, some trickery is needed. 
  31.  
  32. FAT directory entries have ten spare bytes in them, starting at offset
  33. 0CH (immediately after the filename and the attribute byte); these are
  34. normally zero.  They are there because originally the directory entry
  35. layout was modelled on the CP/M file system, and these bytes (among
  36. others) were used to describe the location of the disk extents making up
  37. the file; they aren't used for that purpose under DOS.  Two of these
  38. spare bytes (at offsets 14H and 15H within the directory entry)
  39. are used to head a chain of disk allocation units (or
  40. clusters) which hold the EAs for that file.  This causes interesting
  41. problems (for example) with early versions of the Norton Utilities,
  42. which flag the directory entry as one with an "illegal" format! So,
  43. effectively an OS/2 FAT directory entry can head two chains of clusters;
  44. one for the file itself (as usual) and one for the EAs attached to the
  45. file.  The latter listhead is often null.
  46.  
  47. All this would be fine until you ran CHKDSK under DOS.  It would find
  48. all these clusters holding the EAs, and because they would appear not to
  49. belong to any file, they would be collected up and marked as "lost"
  50. clusters to be added to the free list.  Disaster next time OS/2 looked
  51. at the file (well, eventually anyway) because the chances are that the
  52. clusters making up the EAs would have been allocated to another file by
  53. that time.  To prevent this, the file named EA DATA. SF (the EA
  54. datafile) is used.  This file is never meant to be read directly.  Its
  55. directory entry heads a chain of clusters (as usual), but these clusters
  56. are the SAME ones that hold all the EAs on that disk.  In other words,
  57. there are two references to every EA cluster; one via the file's
  58. directory entry and one via the EA datafile.  This makes the disk appear
  59. consistent under DOS; all of the clusters used on the disk belong to a
  60. valid file.  Microsoft say that the EA datafile is position dependent,
  61. and it shouldn't be manipulated or deleted; to make this hard, it has a
  62. strange name with spaces in it (which defeats a lot of software), and it
  63. is marked readonly, system and hidden.  Observation has shown this not
  64. to be strictly true; it seems that you can back up and restore the file
  65. without any damage (of course, the EA datafile must correspond to the
  66. files on the disk; if you attempted to restore such a file on its own
  67. without also restoring the various files that reference it, you would
  68. have problems).  The snag is that restored files won't generally have
  69. the entire directory entry restored, so the head of the EA cluster chain
  70. (in offsets 14H and 15H) will be lost (set to zero). 
  71.  
  72. Notice the implication for backup under OS/2.  A proper, EA-aware backup
  73. program need not back up the EA datafile; it simply reads the EAs for
  74. each file as it is backed up, and of course it restores them the same
  75. way - with system calls.  So, the fact that OS/2 locks the EA datafile
  76. open is actually a benefit of sorts - it saves the file being backed up
  77. when its contents will never be needed; and it would be semi-useless
  78. unless the directory entries were also restored in their entirety. 
  79.  
  80. Why is this file so big? I can speak only for IBM OS/2 1.2 and 1.3,
  81. which are the ones I have run.  When installing OS/2, the installation
  82. utility scans the OS/2 hard disk (if FAT) for any files it considers
  83. should have EAs on them.  This means all .EXE files for a start.  To
  84. each one it helpfully adds a short EA that marks the file as executable;
  85. this EA is 23 bytes long, but since each EA needs to be in a cluster
  86. unique to the file to which it is attached, it actually occupies a whole
  87. 2K cluster.  Note that EAs are attached at this time even to DOS .EXE
  88. files found on the disk.  In my case this used up 700K of disk space;
  89. your mileage may vary.  Incidentally, the EA datafile is created when
  90. the first EA is attached to any file on the disk; try it out with a
  91. floppy; it also takes one cluster (the first one) for some kind of
  92. internal housekeeping information.  I suspected that this cluster is some
  93. kind of map similar to the FAT, chaining together the clusters relating
  94. to one file within the EA datafile; if so, it would probably expand if
  95. you had a lot of EAs on your disk. Dean Gibson figured out a lot more
  96. about the format of the file; the details are given in Appendix A.
  97.  
  98. You can safely delete the EAs from all your DOS files, and from many
  99. OS/2 ones.  Beware, though! Some files have large EAs that are used for
  100. special purposes.  Ones I know of include some printer drivers, and the
  101. VIEW utility used for the online command reference.  DIR/N will show you
  102. the sizes of the EAs for each file.  To delete the EAs from all of the
  103. files in my DOS directory, I used:
  104.  
  105.     FOR %X IN (*.EXE) DO EAUTIL /S %X
  106.  
  107. This splits off the EA for each file into another file of the same name,
  108. in a subdirectory called EAS (which is created automatically).  Delete
  109. this directory and its contents to free up the space.  The clusters are
  110. automatically removed from the EA datafile at this time.  I have found
  111. this the easiest way to remove EAs. 
  112.  
  113. EAs are also removed from the EA datafile if the file to which they are
  114. attached is deleted; this ONLY applies if deletion takes place under
  115. OS/2 (the DOS box will do).  If deleted under vanilla DOS, the EA
  116. datafile retains the "lost" EA clusters; they can be reclaimed by
  117. running CHKDSK under OS/2 (using the installation disk if DLLs or a
  118. swapfile are open on the disk in question). 
  119.  
  120. All this of course plays havoc with defragmenters.  They have to work
  121. round all of the scattered, immobile clusters making up the EA datafile. 
  122. Yes, it's a kludge; but quite a good one, given the constraint that it
  123. has to look OK under normal DOS as well as provide the functionality
  124. under OS/2. 
  125.  
  126. Please let me know if you have any comments on the above; if I receive
  127. more information, I'll produce a further updated version. 
  128.  
  129.  
  130. Appendix A - Notes on the format of the EA datafile
  131. ---------------------------------------------------
  132.  
  133. Most of this information came from Dean Gibson - many thanks, Dean! I have
  134. made the occasional addition.
  135.  
  136. The actual EA DATA. SF file format is as follows (this has been verified
  137. with both 128 & 512 byte sector disks):
  138.  
  139. The first word is for identification and contains the ASCII characters
  140. 'ED'; the next 15 words seem unused.  The next 240 words (call this
  141. "table A") contain offsets into "table B".  Table B starts at file byte
  142. offset 512 and continues for as many contiguous 128 word segments as
  143. necessary. 
  144.  
  145. Given a non-zero 16 bit EA pointer "X" in a FAT system directory entry
  146. (in offsets 14H and 15H):
  147.  
  148.  1. Shift X right 7 bits, and use the result as a WORD INDEX to obtain a
  149.     word entry from table A.  Note that since a FAT system can only have
  150.     64K entries, that means a maximum of 32K files that have EA entries
  151.     (since each file and each EA takes one cluster each), so the max EA
  152.     pointer value is <32K, and thus the high-order bit of X is unused.
  153.  
  154.  2. Use X as a relative WORD INDEX into table B, to obtain the word entry
  155.     at that location.  A value of FFFFH means that the entry is unused.
  156.  
  157.  3. Add the values from steps 2 & 3 to obtain the relative CLUSTER of the EA
  158.     for the target file within EA_DATA._SF.
  159.  
  160. In order to keep the EA DATA. SF file logically contiguous when table B is
  161. expanded into a new cluster or when an EA is deleted, the FAT cluster chain
  162. for EA DATA. SF is altered, and values in table A and/or segments of table B
  163. are changed to reflect this.
  164.  
  165. The first word of the EA sector is for identification and contains the ASCII
  166. characters 'EA'; the next word is the relative sector number of this sector
  167. (consistency check); then the next two words are zero; the next twelve bytes
  168. contain the target file name (no path); the next word has an as yet
  169. undeciphered meaning; then the next two words are zero; followed by the EA
  170. data for the target file.  The first word of the EA data is the length of the
  171. EA data in bytes, including the count word.
  172.  
  173.  
  174. Bob Eager
  175. Compuserve:    100016,2770
  176. USENET:        rde@ukc.ac.uk
  177.  
  178.