home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 36 Tips / 36-Tips.zip / DIEADT.FAX < prev    next >
Text File  |  1994-12-08  |  12KB  |  224 lines

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