Advanced Features of the EA Class Library

For more information visit EA Class Library

Comparing Extended Attribute
File comparison utilities like comp.com (provided with OS/2) or UNIX-ports of diff only compare the contents of files, not the EAs. This is a true shortcoming. If you need to compare the EAs of different files, use the following code snippet: EAList list1("file1"), list2("file2"); if (list1 == list2) cout << "EAs of file1 and file2 are equal" << endl; else cout << "EAs of file1 and file2 differ" << endl;

If you are only interested if the files differ in specific EAs, you should only compare the relevant elements.

Note: The operator= is inherited from the parent class and checks if both collections have the same number of elements and if the elements are equal.

Dumping Extended Attributes to files
Some programs have the need to store files in a special format, maybe on devices not supporting EAs. Typical examples are archive programs. OS/2 provides the eautil utility to strip of EAs from a file and to join the EAs and the file later on again.

A similar functionality can be achieved using operator<< and operator>>: // saving EAs to a file fstream binStream; binStream.open("file.eas",ios::bin|ios::out); EAList list("file"); binStream << list; binStream.close; // restoring EAs from a file binStream.open("file.eas",ios::bin|ios::in); EAList list; list.remove("file",false); // delete existing EAs binStream >> list; binStream.close; list.write("file",true);


 * Note:operator<< writes the internal buffer to the specified stream. This buffer is changed by every call to read and write. Also, it does not reflect any changes in the collection like adding/changing/deleting elements.

Multi-Value Extended Attributes
Multi-valued EAs (MVEAs) are used to store more than a single piece of information in an EA. Examples are lists of data-types or users allowed to access a file.

Multi-valued EAs are implemented as the concatenation of the data areas of simple EAs. If all EAs in an MVEA have the same type (a so called multi-valued, single-typed EA) the type information is only recorded once. In addition, the data area is prefixed by two additional fields: the code page and the number of entries. The code page information allows EAs of different code pages. This field is for application use only, the operating system does not examine the field. A value of 0 for the code page is used for the file default.

The classes EA and EAList support MVEAs. There is a constructor for class EA which accepts a name and an const EAList&. The constructor creates a single-typed or multi-typed MVEA, depending on the EAList. The name-information of individual EAs in the EAList is lost, but since class EAList is a key sorted set, the order is preserved.

An EAList can also be constructed from a MVEA. The names of the individual EAs in the EAList are created by appending an index to the basename argument of the constructor. A different approach is to construct an EAList with EAs with individual names and then using the setValues member function to set the values of all EAs. This function throws an exception if the number of EAs in the EAList and the number of EAs in the MVEA differ.

Class EA has two additional functions which are useful for MVEAs: codePage and numValues. The former returns the code page field of a MVEA, the latter the number of entries in the MVEA.


 * Note:A prerequisite for all functions except codePage and numValues is that all entries in a MVEA have length-preceded types. If you use private EA-types the conversion functions will fail (exept if you change the isLengthPreceded private member function of class EA).