Previous | Table of Contents | Next |
The key files are transparent files. They have no internal structure and you read and write them as a long sequence of bytes. A record file or cyclic file is organized as a series of records. All the records in a record file with fixed-length records and in a cyclic file are of the same length. Obviously, the records in a record file with variable-length records can be of different lengths. There can be up to 255 records in a record or cyclic file and each record can be up to 255 bytes long.
You are no doubt familiar with record-oriented files on regular computer file systems. Records are also known as TAB cards or rows in tables or, in the most modern parlance, objects. In a typical application, each record contains all the information about a particular item such as a person in an organization, a product in an inventory, or a book in a library.
One of the functions that you frequently perform on a record file is to search for a particular record. The utility of record files, at least large record files, on a smart card would be greatly reduced if one were to have to read all the records from a record file in a smart card from the terminal to find a particular record. It would take a considerable amount of time to do this. Fortunately, the Multiflex card has a Seek instruction that will carry out this search on the card by using the cards processor.
Consider a record file that contains the following 10 records:
Sally Green Ted Yellow Bobby Blue George Gray Barbara Bloom Annette Anise Steve Steamboat Gary Grime Suzie Creamcheese Lisa Lavender
and assume we have selected this file so that it is the current file.
The Multiflex Seek instruction lets us search the records in this file with a particular pattern, starting at a given offset in each record and either starting from the beginning of the file or from the current position in the file. If the pattern is found in a record, then the card returns success and the found record becomes the current record. Otherwise, if a record containing the pattern at the specified offset is not found, an error condition is returned.
As an example, to find Gary Grimes record, we would send the following command to the card:
CLA | INS | Offset | Mode | Data Length | Pattern |
---|---|---|---|---|---|
F016 | A216 | 0016 | 0016 | 0A16 | 4716 6116 7216 7916 2016 |
4716 7216 6916 6D16 6516 |
If we wanted to find all the Garys, we would issue the command
CLA | INS | Offset | Mode | Data Length | Pattern |
---|---|---|---|---|---|
F016 | A216 | 0016 | 0016 | 0416 | 4716 6116 7216 7916 |
which would find the first Gary and then repeat the command
CLA | INS | Offset | Mode | Data Length | Pattern |
---|---|---|---|---|---|
F016 | A216 | 0016 | 0216 | 0A16 | 4716 6116 7216 7916 |
until we got the Not Found error. This would find all the other Garys. At any time, we could use the cards Read Record command to retrieve the Gary record that was found.
The difference between a record file with fixed-length records and a cyclic file is that the cyclic file wraps around and the record file doesnt. For example, when you try to read the next record after the last record in a record file, you get an error, whereas with a cyclic file you get the first record in the file. Similarly, if you try to read the record previous to the first record in a record file, you get an error, whereas with a cyclic file you get the last record in the file.
This wrap-around quality of cyclic files makes them handy for transaction logs. Imagine, for example, that the current record in a cyclic file contains the amount of money currently in an electronic purse, and the cardholder uses the smart card to buy something. To keep track of the transactions on the purse, just subtract the purchase price from the amount in the current record and write the result into the previous record. This will automatically make the previous record the current record in the cyclic file and thus ready it for the next transaction. If there are N records in the cyclic file, then the last N transactions are remembered in the electronic purses transaction file. If something goes wrong with the writing of a transaction, the purse can easily be backed up to the transaction before the garbled one and the owner of the value in the purse is only out one transaction.
Two commands in the Multiflex card automatically perform this electronic purse functionality using a cyclic file: Decrease and Increase. As must be clear, Decrease decreases the amount in the purse and Increase increases the amount in the purse.
Suppose we have selected a cyclic file that we are using as an electronic purse and have been authenticated sufficiently to use the Increase command on this file. If we send the following Increase command to the card
CLA | INS | P1 | P2 | Data Length | Pattern |
---|---|---|---|---|---|
F016 | 3216 | 0016 | 0016 | 0316 | 00001016 |
Previous | Table of Contents | Next |