home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 36 Tips / 36-Tips.zip / WPEADT.FAX < prev    next >
Text File  |  1994-11-25  |  10KB  |  195 lines

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