home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / INFO / FAQS / OS2FAX2 / OSDIEADT.FAX < prev    next >
Encoding:
Text File  |  1994-07-20  |  11.6 KB  |  221 lines

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