When first introduced to CPU cards, the definition of various files and applications is often unclear, and it is often difficult to accurately define what a file is? What is an application? Is the difference between DF and EF really like directories and documents in a computer? When did the concepts of FID, AID, and SFI come into play? Does an EF have to depend on some DF? Is MF necessary to exist? There will be countless question marks rushing through my mind.
In fact, the essence of a file is just a set of data, and operations on this data (selection, reading, writing/updating) are completed through specific file operation APDU commands. So data is the essence, files are just appearances. The type of file that a certain set of data should be accessed by the outside world is determined by the COS of the card.
According to the standard, DF refers to the abbreviation of Dedicated File, which can be equivalent to a directory file in a computer. EF is the Elementary File, which means that data related to applications is usually stored in EF.
In order to access files, it is necessary to assign a specific identifier to the file. Both DF and EF will have corresponding two byte long ID identifiers, also known as FIDs. And DF will also have a name that is 5-16 bytes long, also known as AID. EF will also have a 5-digit short file identifier (ranging from 1 to 30), which is SFI. According to the definition of the 7816 standard, as well as some industry application standards derived from 7816, the definition is basically like this. Whether it is FID, AID, or SFI, within the range of selectable paths (this sentence may be a bit convoluted, but it will naturally become clear after understanding), the values of different files (including DF and EF) cannot be the same.
In a card (referring to the card rather than an application), there is only one special DF called the main file MF. The FID of this MF defaults to 3F00, which is equivalent to the root directory in the computer, and MF can be selected at any time. If there are no child DFs under a certain DF and only several EFs, then this DF is also called ADF. Conversely, if there are child DFs under a DF besides EF, then the parent DF is also called DDF.
In the process of using the card, there is only one operation for DF, which is "select", but for EF, there are three forms of operation: select, read, and write.
During the file selection process, the selection of DF can be achieved through FID or AID, while the selection of EF can only be achieved through FID. The files that can be selected (whether DF or EF) must be within the visible path range (this sentence is also a bit convoluted).
As for reading and writing EF files, it can be done directly through SFI, or by selecting a certain EF through FID before reading and writing.
It should be emphasized that all of the above are closely related to certain application specifications and the implementation of COS. In other words, if you write a COS that meets a specific application, you can do it according to your own wishes. For example, defining the FID of MF as 8F00, adding AID to EF, allowing cards to select various levels of DF and their subordinate EF at any time, and so on......
