CN107239526B - File system implementation method, defragmentation method and operation position positioning method - Google Patents

File system implementation method, defragmentation method and operation position positioning method Download PDF

Info

Publication number
CN107239526B
CN107239526B CN201710392808.2A CN201710392808A CN107239526B CN 107239526 B CN107239526 B CN 107239526B CN 201710392808 A CN201710392808 A CN 201710392808A CN 107239526 B CN107239526 B CN 107239526B
Authority
CN
China
Prior art keywords
area
fdt
fat
cluster
file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710392808.2A
Other languages
Chinese (zh)
Other versions
CN107239526A (en
Inventor
赵霄
杨清祥
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Henan Thinker Track Traffic Technology Research Institute
Original Assignee
Henan Thinker Track Traffic Technology Research Institute
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Henan Thinker Track Traffic Technology Research Institute filed Critical Henan Thinker Track Traffic Technology Research Institute
Priority to CN201710392808.2A priority Critical patent/CN107239526B/en
Publication of CN107239526A publication Critical patent/CN107239526A/en
Application granted granted Critical
Publication of CN107239526B publication Critical patent/CN107239526B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/11File system administration, e.g. details of archiving or snapshots
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/1724Details of de-fragmentation performed by the file system

Abstract

The invention provides a file system implementation method, which comprises the steps of allocating an FST area, an FDT area, an FAT area and a data cluster area which are stored in a block in a storage area; the FST area represents a file system information area; the FDT area represents a file description information area; the FAT area represents a file allocation information area, and the data cluster area stores file contents; the FST area stores the initial address of the FDT area and the initial address of the FAT area at the same time; setting an FDT table in the FDT area; setting a FAT table in the FAT area; the FDT area and the FAT area are indexed through the initial address of the FST area, the file initial cluster is indexed through the FDT table, the link relation of each cluster of the file is indexed through the FAT table, and the whole file content stored in the data cluster area is indexed through the link relation of each cluster. The FDT area and the FAT area can update the positions of the blocks in which the rotation is performed along with the file, and the initial addresses of the corresponding areas in the FST are additionally updated while the FDT area and the FAT area are transferred, so that the balanced rotation and erasing balance of the FDT area, the FAT area and the data cluster area in the whole storage space are realized.

Description

File system implementation method, defragmentation method and operation position positioning method
Technical Field
The invention relates to the field of embedded file systems, in particular to a method for realizing a file system suitable for an IC card.
Background
With the rapid development of electronic technology and computer technology, the application requirements for storing and managing a large amount of data, whether in a PC system or an embedded system, are becoming more extensive. The IC card is a flash memory card specially designed for large-capacity storage, and has the advantages of low cost, good compatibility and the like. In some industry applications, in order to conveniently exchange data between an IC card and a PC system or an embedded system according to a specific format, a file system needs to be designed to shield technical details of a physical memory and organize managed information into a file form, so that the portability and maintainability of the application are increased, a user can effectively manage a large amount of data, and meanwhile, certain special industries have certain confidentiality and private customization requirements on file contents and formats, so that the establishment of a special file system suitable for the IC card has certain practical significance.
At present, a plurality of mature file systems such as FAT (file allocation table), NTFS (remote File System) and Unix and Linux file systems exist on a general computer, but the file systems are not suitable for being directly used by IC (integrated Circuit) cards, and the main problems are as follows: firstly, when the IC card is applied to a PC system, the IC card is operated by a reader-writer, the application environment is relatively severe, the problems of unstable power supply voltage, sudden power failure, frequent plugging and unplugging and the like exist, and the design consideration of a general file system on the reliability is insufficient; secondly, when the IC card is applied to reading and writing of the embedded equipment, a general file system needs to consume a large amount of resources based on a PC platform with rich resources and a slow disk driver, and the embedded system is often limited in resources; thirdly, the Flash memory chip inherent properties of IC cards determine that the universal file system is not applicable, which usually consists of several blocks, a block consisting of several pages/sectors, and a page containing a certain number of bytes of memory cells. The read operation of the Flash memory is consistent with that of a magnetic disk, but the write operation is different from that of the magnetic disk, and a general file system has no corresponding special design. The basic unit of the storage space occupied by the Flash memory file is a Block, data writing operation must be performed in a blank Block or an erased Block, erasing is required to be performed in a Block unit (OxFF is written into a memory Block to be erased), writing operation is performed in a Page/sector Page mode (one Page must be written at a time), the erasing frequency of the Flash memory is limited, the inherent characteristics of the Flash memory must be considered when a file system is established on the Flash memory, and the service life of the Flash memory is greatly shortened due to excessive erasing of some blocks. In view of the above disadvantages of the FAT file system in IC cards, a file system implementation method suitable for IC cards is needed.
Disclosure of Invention
The invention provides a method for realizing a file system, which aims to solve the problems in the prior art.
The invention adopts the following technical scheme:
the file system implementation method includes that a storage area is allocated with an FST area, an FDT area, an FAT area and a data cluster area which are stored in a block;
the FST area represents a file system information area and is used for storing basic information of a file system; the FDT area represents a file description information area and is used for storing basic information describing a file, wherein the basic information of the file at least comprises a file name, a starting cluster, a size and creation time; the FAT area represents a file allocation information area and is used for storing file allocation information, and the data cluster area stores file contents;
the FST area stores the initial address of the FDT area and the initial address of the FAT area at the same time;
setting an FDT table in the FDT area, wherein the FDT table stores file description information of files; when the file description information is changed due to the operation on the file, the FDT area generates a new FDT table and stores the new FDT table;
setting a FAT table in the FAT area, wherein the FAT table stores cluster allocation conditions and cluster connection relations of files in a data cluster area; when the operation on the file causes the change of the file allocation information, the FAT area generates a new FAT table and stores the new FAT table;
when the operation on the file causes the change of the file description information and/or the file allocation information, the FDT area generates and stores a new FDT table, and the FAT area generates and stores a new FAT table;
the FDT area and the FAT area are indexed through the initial address of the FST area, the file initial cluster is indexed through the FDT table, the link relation of each cluster of the file is indexed through the FAT table, and the whole file content stored in the data cluster area is indexed through the link relation of each cluster.
The FST area is fixedly stored in the block i, the FDT area and the FAT area are stored in different blocks, and the data cluster area is stored in the rest blocks; wherein i is more than or equal to 0 and less than or equal to N-1, N represents the number of blocks in the storage area, and i represents the ith block of the storage area;
the FDT area is divided into an FDT table area and an FDT table index area, the FDT table is stored in the FDT table area, and the FDT table can be indexed through the FDT table index area;
the FAT area is divided into a FAT table area and a FAT table index area, the FAT table is stored in the FAT table area, and the FAT table can be indexed through the FAT table index area;
when the operation on the file causes the file description information and the file allocation information to be changed, the following operations are performed on the FDT area and the FAT area:
FDT region: regenerating a new FDT table, incrementally adding the new FDT table to the next position of the previous FDT table, and incrementally adding a new effective index number in the index area of the FDT table, wherein the effective index number can index the new FDT table; when the FDT table index area is full, distributing a new block to the FDT area, erasing the block where the current FDT area is located, and updating the initial address of the new FDT area to the FST area;
and the FAT area: regenerating a new FAT table, incrementally adding the new FAT table to the next position of the last FAT table, and incrementally adding a new effective index number in the index area of the FAT table, wherein the effective index number can index the new FAT table; when the FAT table index area is full, distributing a new block to the FAT area, erasing the block where the current FAT area is located, and updating the initial address of the new FAT area to the FST area;
updating the initial address of the FDT area and the initial address of the FAT area stored in the FST area along with the transfer of the block where the FDT area is located and the block where the FAT area is located, wherein the updating mode is an incremental additional writing mode; when the block i stored in the FST area is full, the erasing and rewriting of the whole block i are triggered.
The file system basic information stored in the FST area comprises system sector, cluster and block information, and the storage area is a Flash memory of the IC card.
The method comprises the steps that mapping copies are set in a memory for an FDT table and an FAT table, when file description information and file allocation information are changed due to file operation, the FDT table and the FAT table in the memory are regenerated firstly, after the generation is completed, the FDT table and the FAT table in the memory are written into an FDT area and an FAT area in a storage area respectively, and the FDT table and the FAT table in the FDT area and the FAT area are updated into a currently effective FDT table and FAT table;
setting dirty marks on mapping copies of the FDT table and the FAT table respectively, setting the dirty marks to be true when the FDT table and the FAT table in the memory change, and clearing the dirty marks after the FDT table and the FAT table are written back into a storage area;
synchronously writing the FDT table in the memory into the FDT area of the storage area: if the dirty mark of the FDT table is cleared and the contents of the FDT table in the current memory are consistent with the contents of the current effective FDT table in the storage area FDT, synchronous writing is not carried out; when any one of the data storage areas does not meet the requirement, synchronously writing the FDT table in the memory into the FDT table in the FDT area as a current effective FDT table of the storage area, and clearing the dirty mark of the FDT table in the memory;
synchronously writing the FAT table in the memory into the FAT area of the storage area: if the dirty mark of the FAT table is cleared and the contents of the FAT table in the current memory are consistent with the contents of the current effective FAT table in the FAT area of the storage area, synchronous writing is not carried out; and when any one of the FAT tables is not satisfied, synchronously writing the FAT table in the memory into the FAT table in the FAT area to be used as the current effective FAT table of the memory area, and simultaneously clearing the dirty marks of the FAT table in the memory.
When the data is written into the appointed file in the data cluster area, firstly, a writing buffer area is established in a memory, when the writing buffer area is full, firstly, the tail cluster of the current appointed file is retrieved from the FAT table, meanwhile, the residual space of the cluster where the tail cluster is located is calculated, and if the residual space is not smaller than the size of the writing buffer area, the data with the length being the size of the writing buffer area is written; otherwise, writing the data with the residual space size of the tail cluster, and simultaneously continuing applying the new cluster to write the residual data.
The FAT table is composed of a plurality of 2-byte cluster states, and the cluster states comprise 4 states of unallocated, allocated, dirty and end.
The defragmentation method comprises the following steps:
scanning the storage area by taking blocks as units, calculating the proportion of dirty clusters in each block, and when the proportion exceeds a set sorting threshold, performing defragmentation on the file system; the dirty clusters are: deleting the file to enable the cluster occupied by the file to be a dirty cluster;
when the file system is defragmented, firstly checking an FAT table, searching effective clusters in blocks to be defragmented, immediately applying for idle clusters after the effective clusters are found, and copying the effective cluster contents to the newly applied idle clusters; if the effective cluster is a file tail cluster, only copying the effective length in the cluster, otherwise, copying the content of the whole cluster;
generating a new FAT table while copying the cluster content, and writing a new cluster chain into the new FAT table; after the current cluster transfer is finished, dirty placement is carried out on the whole cluster;
repeating the above operations until all the blocks are dirty clusters, erasing the whole block, releasing the corresponding FAT table, and finishing one-time defragmentation.
The operation position positioning method comprises the following steps:
establishing a fast lookup table in an internal memory, regarding a plurality of clusters storing the same file, calling a section of continuous cluster as a cluster segment, intensively mapping all cluster segments into the fast lookup table, calculating a corresponding serial number of the continuous cluster according to the operating position of the file, and obtaining a corresponding cluster number through the fast lookup table;
the quick search is realized by the following steps:
traversing the FAT table; defining the number of continuous clusters of the operation position = reading position/cluster size; and traversing all cluster fragments of the quick lookup table, subtracting the number of the continuous clusters in the current fragment from the number of the continuous clusters each time until the number of the continuous clusters is less than the number of the continuous clusters in the current fragment, and returning the sum of the initial cluster number of the fragment and the number of the residual continuous clusters to be the cluster number corresponding to the operation position.
The invention has the beneficial effects that: four types of areas are distributed in a storage area of a memory, namely a file system information data cluster area (FST) area, a file description information (FDT) area, a file allocation information (FAT) area and a data cluster area. The FDT area and the FAT area can rotate along with file updating and update the block positions, and the FDT area and the FAT area are transferred and simultaneously additionally update the initial addresses of the corresponding areas in the FST, so that the balanced rotation and erasing balance of the FDT area, the FAT area and the data cluster area in the whole storage space are realized.
Drawings
FIG. 1 is a diagram of an IC card file system management partition.
FIG. 2 is a schematic diagram of memory write back of the FDT region during FDT table change.
Fig. 3 is an initialization diagram of the IC card file system.
FIG. 4 is a diagram illustrating fast positioning of a cluster where a file operation location is located.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings 1 to 4 and the embodiments.
The invention provides a method for realizing a file system, in particular to a method for realizing a file system which is suitable for an IC card and a memory similar to the IC card.
Firstly, allocating an FST area, an FDT area, an FAT area and a data cluster area which are stored in a block in a storage area of a memory; wherein the FST area represents a file system information area for storing file system basic information, such as sectors, blocks, clusters, etc.; the FDT area represents a file description information area for storing basic information describing a file, the basic information of the file at least including a file name, a start cluster, a size, a creation time, a state of the file, and the like; the FAT area represents a file allocation information area for storing allocation information of files, and the data cluster area stores contents of the files. The FST area is fixedly stored in the block i, the FDT area and the FAT area are stored in different blocks, and the data cluster area is stored in the other blocks; wherein i is more than or equal to 0 and less than or equal to N-1, N represents the number of blocks in the storage area, and i represents the ith block of the storage area; the FDT area and the FAT area are rotated along with the file update.
The FST area stores the initial address of the FDT area and the initial address of the FAT area at the same time, the addresses are updated along with the transfer of the blocks where the FDT area and the FAT area are located, and the address updating can adopt an incremental additional writing mode, so that a plurality of groups of the initial addresses of the FDT area and the FAT area exist in the FST area, but only one group which is updated newly is currently effective, and the FDT area and the FAT area can be indexed from the FST area at any time.
The FDT area and the FAT area are indexed through the initial address of the FST area, the file initial cluster is indexed through the FDT table, the link relation of each cluster of the file is indexed through the FAT table, and the whole file content stored in the data cluster area can be indexed through the link relation of each cluster.
Setting an FDT table in the FDT area, wherein the FDT table stores file description information of files; when the operation on the file causes the file description information to be changed, the FDT area generates a new FDT table and stores the table.
The method preferentially adopts an incremental additional writing mode to update the FDT table, at the moment, the FDT area is divided into an FDT table area and an FDT table index area, the FDT table is stored in the FDT table area, and the FDT table can be indexed through the FDT table index area; the FDT table area stores a plurality of FDT tables, and only one FDT table is valid at any time, which is usually the most recently updated table. In one embodiment, description information of up to 256 files may be stored in the FDT table, and the description information includes information of a state, a start cluster, a name, a size, a creation time, and the like of the file. The operations of reading, writing, adding, deleting, renaming and the like of the file generally cause the change of the information, so that the FDT table needs to be updated in time.
When the FDT table is updated, a new FDT table needs to be generated again, the new FDT table is added to the next position of the last FDT table in the FDT table area in an increasing mode, and meanwhile a new effective index number is added in the FDT table index area in an increasing mode, and the effective index number can index the new FDT table; when the FDT table index area is full, the block where the FDT area is located is full, a new block is allocated to the FDT area, the block where the current FDT area is located is erased, and the starting address of the new FDT area is updated to the FST area.
Setting a FAT table in the FAT area, wherein the FAT table stores cluster allocation conditions and cluster connection relations of files in a data cluster area; when the operation on the file causes the change of the file allocation information, the FAT area generates a new FAT table and stores the new FAT table.
When the incremental additional writing mode is adopted to update the FAT table, the FAT area is divided into a FAT table area and a FAT table index area, the FAT table is stored in the FAT table area, and the FAT table can be indexed through the FAT table index area. The FAT table area stores a plurality of FAT tables, and only one FAT table is valid at any time, which is usually the most recently updated table. The FAT table is used for representing cluster allocation conditions and cluster link relations of all files in the whole data cluster area and is composed of a plurality of 2-byte cluster states, wherein the cluster states comprise 4 states of unallocated, allocated, dirty and ending, and the ending state indicates that the current cluster is a file ending cluster. The operations of reading and writing, adding and deleting, defragmentation and the like of the file usually cause the state changes of new allocation, dirty setting and the like of the file cluster, so that the FAT table needs to be updated in time.
When updating the FAT table, firstly regenerating a new FAT table, incrementally adding the new FAT table to the next position of the last FAT table in the FAT table area, and incrementally adding a new effective index number in the index area of the FAT table, wherein the effective index number can index the new FAT table; when the FAT table index area is full, which indicates that the block of the FAT area is full, a new block is allocated to the FAT area, the block of the current FAT area is erased, and the initial address of the new FAT area is updated to the FST area.
In the process, the initial address of the FDT area and the initial address of the FAT area stored in the FST area are updated along with the transfer of the block where the FDT area is located and the block where the FAT area is located, and the updating mode also adopts an address increment additional writing mode, namely, a new initial address is added at the next position of the initial address of the last FDT area and the initial address of the last FAT area stored in the FST area, and the initial address can index the currently effective FDT area and FAT area; when the block i stored in the FST area is fully added, the FST area is fixedly stored in a certain block, so that the erasure of the whole block i and the rewriting in the block i are directly triggered without performing the round-robin updating at the fast position. Based on the above, the balanced rotation and erase-write balance of the FDT area, the FAT area and the data cluster area in the whole storage space are realized.
Because each operation on the file needs to update the FAT table and/or the FDT table, the read-write life of some blocks in the storage area is shortened in order to avoid frequent rewriting of the FDT table and the FAT table in the storage area. The invention sets mapping copies with completely same format in the memory of the FDT table and the FAT table in the storage area, when the operation on the file causes the change of the file description information and the file distribution information, the FDT table and the FAT table in the memory are regenerated at first, after the generation is finished, the FDT table and the FAT table in the memory are respectively written into the FDT area and the FAT area in the storage area, and the FDT table and the FAT table in the FDT area and the FAT area are updated into the currently effective FDT table and FAT table.
The mapping copies of the FDT table and the FAT table need to be respectively provided with a dirty mark, when the FDT table and the FAT table in the memory change, the dirty mark is set to be true, and after the FDT table and the FAT table are written back into the storage area, the dirty mark is cleared.
Synchronously writing the FDT table in the memory into the FDT area of the storage area: if the dirty mark of the FDT table is cleared and the contents of the FDT table in the current memory are consistent with the contents of the current effective FDT table in the storage area FDT, synchronous writing is not carried out; and when any one of the FDT tables is not satisfied, synchronously writing the FDT table in the memory into the FDT table in the FDT area to be used as the current effective FDT table of the storage area, and clearing the dirty mark of the FDT table in the memory.
Synchronously writing the FAT table in the memory into the FAT area of the storage area: if the dirty mark of the FAT table is cleared and the contents of the FAT table in the current memory are consistent with the contents of the current effective FAT table in the FAT area of the storage area, synchronous writing is not carried out; and when any one of the FAT tables is not satisfied, synchronously writing the FAT table in the memory into the FAT table in the FAT area to be used as the current effective FAT table of the memory area, and simultaneously clearing the dirty marks of the FAT table in the memory.
When data are written into a specified file in a data cluster area of a file system, in order to avoid excessively frequent writing and limit the data to the minimum writing unit of the current Flash memory, the invention adopts a mode of writing into a buffer area in advance. Firstly, establishing a write buffer area in a memory, searching a tail cluster of a current specified file from an FAT table after the write buffer area is full, simultaneously calculating the residual space of the cluster where the tail cluster is located, and writing data with the length of the write buffer area if the residual space is not smaller than the size of the write buffer area; otherwise, writing the data with the residual space size of the tail cluster, and simultaneously continuing applying the new cluster to write the residual data.
When a specified file is read from a file system, firstly, the content of the first cluster of the file needs to be found in an FDT area, then, a cluster where the read starting position is located is retrieved along a cluster chain in an FAT (file allocation table) according to an incoming read offset, then, data offset from the inside of the cluster to the tail of the cluster is read, and if the read length is not enough, the data of other clusters on the cluster chain is continuously read in a crossing mode until the required length is read.
Because the cluster occupied by the file becomes a dirty cluster due to the deletion operation on the file, the file system needs to provide a defragmentation function to reorganize the file, store the file in consecutive cluster blocks as much as possible, and release the dirty cluster space.
When defragmentation is carried out, firstly, the storage area is scanned by taking a block as a unit, the proportion of dirty clusters in each block is calculated, and when the proportion exceeds a set defragmentation threshold value, defragmentation is carried out. During sorting, firstly checking the FAT table, searching for effective clusters in blocks to be sorted, immediately applying for idle clusters in blocks not to be sorted after finding the effective clusters, and copying the contents of the effective clusters to the newly applied idle clusters; if the effective cluster is a file tail cluster, only copying the effective length in the effective cluster, otherwise, copying the content of the whole cluster; generating a new FAT table while copying the cluster content, and writing a new cluster chain into the new FAT table; after the current cluster transfer is finished, dirty placement is carried out on the whole cluster; repeating the above operations until all the blocks are dirty clusters, erasing the whole block, releasing the corresponding FAT table, and finishing one-time defragmentation. The block to be sorted refers to a block in which the proportion of dirty clusters exceeds a set sorting threshold.
As shown in fig. 4, the chain-type distributed storage of the files causes that a cluster chain needs to be traversed when the operating positions of the files are located, and many times, some clusters of the same file are adjacent, a section of continuous cluster is called a cluster segment, at this time, a fast lookup table is set in the memory, all cluster segments of the same file are mapped into one fast lookup table in a centralized manner, the corresponding serial numbers of the continuous clusters are calculated according to the operating positions of the files, and the corresponding cluster numbers can be obtained through the fast lookup table. Quick searching: traversing the FAT and creating a quick lookup table; the number of consecutive clusters in the operating position = reading position/cluster size; and traversing all the segments of the quick lookup table, subtracting the number of the continuous clusters in the current segment each time by the number of the continuous clusters until the number of the continuous clusters is less than the number of the continuous clusters in the current segment, and returning the sum of the initial cluster number of the segment and the number of the residual continuous clusters to be the cluster number corresponding to the operation position.
As shown in fig. 1 to 3, a method of using a file system for an IC card using Flash with block 0 as a fixed storage block of FST is described.
Before using a file system in a Flash memory of an IC card, the file system needs to be newly created, that is, formatted. The file system formatting comprises two steps of hard formatting and soft formatting, wherein the hard formatting is firstly carried out on an IC chip, all bytes are set to be 0xFF, and then the soft formatting is carried out according to the design format of the file system.
The soft formatting of the file system includes:
as shown in fig. 1 and 3, the whole information of the corresponding file system is filled according to the information of the Flash memory block, cluster and sector, the corresponding information is assigned to the FST area, then, the address of block 1 is assigned to the initial address information of the FDT area of the FST area, the address of block 2 is assigned to the initial address information of the FAT area of the FST area, and the FST area is written into block 0. At this point, the initialization of the FST area is completed.
And indexing the FDT table according to the initial address information of the FDT area in the FST area, setting all table contents to 0xFF and setting the index byte to 0x55550000, and thus finishing the initialization of the FDT.
As described above, the system FST occupies block 0, the FDT occupies block 1, and the FAT occupies block 2. Therefore, the first 3 blocks of the FAT table have special values of 0xFFF1, 0xFFF2, and 0xFFF3, respectively, to indicate that the blocks are occupied specially, and the bytes of the rest of the FAT table have all 0 bits to indicate that the blocks are not allocated clusters. Subsequently, the index byte is set to 0xAAAA0000, and at this point, the initialization of the FAT is completed.
The mount is required before the file system operates. In the mounting process of the file system, the currently effective FDT table and FAT table need to be moved from Flash to a memory so as to adapt to possible frequent modification, meanwhile, dirty marks of respective tables are designed to ensure the consistency of the memory and the content of Flash, the dirty marks are true due to the change of the FDT and FAT tables in the memory, and the dirty marks are removed when the FDT and FAT tables are written back to the Flash.
The file writing operation may cause a change in the file length, a change in the cluster chain, and the like, and the FDT table and the FAT table are often required to be updated. Because the FDT table and the FAT table have mapping copies in the memory, the corresponding updating operation is directly performed in the memory, and after the FDT table and the FAT table of the memory are changed, the corresponding updating operation is written back to Flash through two mechanisms for synchronization.
Synchronously writing an FDT table into Flash: and checking that the dirty mark is cleared, comparing whether the contents of the memory FDT table are consistent with the contents of the current effective FDT table of the read Flash, and if the contents of the memory FDT table and the contents of the current effective FDT table of the read Flash are consistent, synchronously writing in is not needed. Otherwise, adding 1 to the index number of the effective table of the FDT area, sequentially and progressively writing the latest index number in the index area, simultaneously writing the updated table area by the sequential address, copying the contents of the FDT table in the current memory to the latest index pointing position in Flash, and clearing the dirty mark. When the index number is increased, if the current index area is full, the block where the current FDT area is located is full, the FDT area needs to be moved, namely a new block is allocated to the FDT area, meanwhile, the initial address information of the FDT area in the FST area needs to be updated, and the FAT table changes caused by the allocation of the new block, and then the original block is erased.
Synchronously writing an FAT table into Flash: and checking that the dirty mark is cleared, comparing whether the content of the memory FAT table is consistent with the content of the current effective FAT table of the read Flash, and if so, not performing synchronous writing. Otherwise, adding 1 to the index number of the effective table of the FAT management area, sequentially and progressively writing the latest index number in the index area, simultaneously writing the updated table area by the sequential address, copying the content of the current memory FAT table to the latest index pointing position in the Flash, and clearing the dirty mark. When the index number is increased, if the current index area is full, the block where the current FAT management area is located is full, and the block needs to be moved, namely, a new block is allocated to the FAT management area, meanwhile, the initial address information of the FAT management area in the FST needs to be updated, and the FAT table changes caused by the allocation of the new block, and then the original block is erased.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various changes and modifications can be made without departing from the overall concept of the present invention, and these should also be considered as the protection scope of the present invention.

Claims (7)

1. The file system implementation method is characterized in that: allocating an FST area, an FDT area, an FAT area and a data cluster area which are stored in a block in a storage area;
the FST area represents a file system information area and is used for storing basic information of a file system; the FDT area represents a file description information area and is used for storing basic information describing a file, wherein the basic information of the file at least comprises a file name, a starting cluster, a size and creation time; the FAT area represents a file allocation information area and is used for storing file allocation information, and the data cluster area stores file contents;
the FST area stores the initial address of the FDT area and the initial address of the FAT area at the same time;
setting an FDT table in the FDT area, wherein the FDT table stores file description information of files; when the file description information is changed due to the operation on the file, the FDT area generates a new FDT table and stores the new FDT table;
setting a FAT table in the FAT area, wherein the FAT table stores cluster allocation conditions and cluster connection relations of files in a data cluster area; when the operation on the file causes the change of the file allocation information, the FAT area generates a new FAT table and stores the new FAT table;
when the operation on the file causes the change of the file description information and/or the file allocation information, the FDT area generates and stores a new FDT table, and the FAT area generates and stores a new FAT table;
indexing an FDT area and an FAT area through an initial address of the FST area, simultaneously indexing a file initial cluster through an FDT table, indexing the link relation of each cluster of the file through the FAT table, and indexing the whole file content stored in a data cluster area through the link relation of each cluster;
the FST area is fixedly stored in the block i, the FDT area and the FAT area are stored in different blocks, and the data cluster area is stored in the rest blocks; wherein i is more than or equal to 0 and less than or equal to N-1, N represents the number of blocks in the storage area, and i represents the ith block of the storage area;
the FDT area is divided into an FDT table area and an FDT table index area, the FDT table is stored in the FDT table area, and the FDT table can be indexed through the FDT table index area;
the FAT area is divided into a FAT table area and a FAT table index area, the FAT table is stored in the FAT table area, and the FAT table can be indexed through the FAT table index area;
when the operation on the file causes the file description information and the file allocation information to be changed, the following operations are performed on the FDT area and the FAT area:
FDT region: regenerating a new FDT table, incrementally adding the new FDT table to the next position of the previous FDT table, and incrementally adding a new effective index number in the index area of the FDT table, wherein the effective index number can index the new FDT table; when the FDT table index area is full, distributing a new block to the FDT area, erasing the block where the current FDT area is located, and updating the initial address of the new FDT area to the FST area;
and the FAT area: regenerating a new FAT table, incrementally adding the new FAT table to the next position of the last FAT table, and incrementally adding a new effective index number in the index area of the FAT table, wherein the effective index number can index the new FAT table; when the FAT table index area is full, distributing a new block to the FAT area, erasing the block where the current FAT area is located, and updating the initial address of the new FAT area to the FST area;
updating the initial address of the FDT area and the initial address of the FAT area stored in the FST area along with the transfer of the block where the FDT area is located and the block where the FAT area is located, wherein the updating mode is an incremental additional writing mode; when the block i stored in the FST area is full, the erasing and rewriting of the whole block i are triggered.
2. The file system implementation method of claim 1, wherein: the file system basic information stored in the FST area comprises system sector, cluster and block information, and the storage area is a Flash memory of the IC card.
3. The file system implementation method of claim 1, wherein: the method comprises the steps that mapping copies are set in a memory for an FDT table and an FAT table, when file description information and file allocation information are changed due to file operation, the FDT table and the FAT table in the memory are regenerated firstly, after the generation is completed, the FDT table and the FAT table in the memory are written into an FDT area and an FAT area in a storage area respectively, and the FDT table and the FAT table in the FDT area and the FAT area are updated into a currently effective FDT table and FAT table;
setting dirty marks on mapping copies of the FDT table and the FAT table respectively, setting the dirty marks to be true when the FDT table and the FAT table in the memory change, and clearing the dirty marks after the FDT table and the FAT table are written back into a storage area;
synchronously writing the FDT table in the memory into the FDT area of the storage area: if the dirty mark of the FDT table is cleared and the contents of the FDT table in the current memory are consistent with the contents of the current effective FDT table in the storage area FDT, synchronous writing is not carried out; when any one of the data storage areas does not meet the requirement, synchronously writing the FDT table in the memory into the FDT table in the FDT area as a current effective FDT table of the storage area, and clearing the dirty mark of the FDT table in the memory;
synchronously writing the FAT table in the memory into the FAT area of the storage area: if the dirty mark of the FAT table is cleared and the contents of the FAT table in the current memory are consistent with the contents of the current effective FAT table in the FAT area of the storage area, synchronous writing is not carried out; and when any one of the FAT tables is not satisfied, synchronously writing the FAT table in the memory into the FAT table in the FAT area to be used as the current effective FAT table of the memory area, and simultaneously clearing the dirty marks of the FAT table in the memory.
4. The file system implementation method of claim 1, wherein:
when data are written into a designated file in a data cluster area, a write buffer area is established in a memory, when the write buffer area is full, a tail cluster of the current designated file is retrieved from an FAT table, the residual space of the cluster where the tail cluster is located is calculated, and if the residual space is not smaller than the size of the write buffer area, data with the length being the size of the write buffer area are written; otherwise, writing the data with the residual space size of the tail cluster, and simultaneously continuing applying the new cluster to write the residual data.
5. The file system implementation method of claim 1, wherein:
the FAT table is composed of a plurality of 2-byte cluster states, and the cluster states comprise 4 states of unallocated, allocated, dirty and end.
6. The defragmentation method of a file system in a file system implementation method according to claim 1, characterized in that:
scanning the storage area by taking blocks as units, calculating the proportion of dirty clusters in each block, and when the proportion exceeds a set sorting threshold, performing defragmentation on the file system; the dirty clusters are: deleting the file to enable the cluster occupied by the file to be a dirty cluster;
when the file system is defragmented, firstly checking an FAT table, searching effective clusters in blocks to be defragmented, immediately applying for idle clusters after the effective clusters are found, and copying the effective cluster contents to the newly applied idle clusters; if the effective cluster is a file tail cluster, only copying the effective length in the cluster, otherwise, copying the content of the whole cluster;
generating a new FAT table while copying the cluster content, and writing a new cluster chain into the new FAT table; after the current cluster transfer is finished, dirty placement is carried out on the whole cluster;
repeating the above operations until all the blocks are dirty clusters, erasing the whole block, releasing the corresponding FAT table, and finishing one-time defragmentation.
7. The method for locating the operating position of a file system in a file system implementation method according to claim 1, characterized in that:
establishing a fast lookup table in an internal memory, regarding a plurality of clusters storing the same file, calling a section of continuous cluster as a cluster segment, intensively mapping all cluster segments into the fast lookup table, calculating a corresponding serial number of the continuous cluster according to the operating position of the file, and obtaining a corresponding cluster number through the fast lookup table;
the quick search is realized by the following steps:
traversing the FAT table; defining the number of continuous clusters of the operation position = reading position/cluster size; and traversing all cluster fragments of the quick lookup table, subtracting the number of the continuous clusters in the current fragment from the number of the continuous clusters each time until the number of the continuous clusters is less than the number of the continuous clusters in the current fragment, and returning the sum of the initial cluster number of the fragment and the number of the residual continuous clusters to be the cluster number corresponding to the operation position.
CN201710392808.2A 2017-05-27 2017-05-27 File system implementation method, defragmentation method and operation position positioning method Active CN107239526B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710392808.2A CN107239526B (en) 2017-05-27 2017-05-27 File system implementation method, defragmentation method and operation position positioning method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710392808.2A CN107239526B (en) 2017-05-27 2017-05-27 File system implementation method, defragmentation method and operation position positioning method

Publications (2)

Publication Number Publication Date
CN107239526A CN107239526A (en) 2017-10-10
CN107239526B true CN107239526B (en) 2020-11-13

Family

ID=59984705

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710392808.2A Active CN107239526B (en) 2017-05-27 2017-05-27 File system implementation method, defragmentation method and operation position positioning method

Country Status (1)

Country Link
CN (1) CN107239526B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108491402B (en) * 2018-01-17 2021-09-21 艾体威尔电子技术(北京)有限公司 Method for implementing lightweight file system
CN108647278B (en) * 2018-05-03 2021-07-02 中北大学 File management method and system
CN108664577B (en) * 2018-05-03 2021-03-12 中北大学 File management method and system based on FLASH idle area
CN109597793B (en) * 2018-12-04 2023-02-17 中国航空工业集团公司西安航空计算技术研究所 Method for improving IO performance of file system
CN109739683B (en) * 2018-12-31 2022-08-05 河南思维自动化设备股份有限公司 LKJ file writing method based on power failure protection medium and storage medium
CN112764689A (en) * 2021-02-02 2021-05-07 湖南师范大学 Airborne radar-oriented data storage file management method and management system
CN113806803B (en) * 2021-09-17 2023-06-02 厦门服云信息科技有限公司 Data storage method, system, terminal equipment and storage medium
CN113934371B (en) * 2021-10-08 2024-04-12 福建星网视易信息系统有限公司 Memory, data management method thereof and computer storage medium
CN114237513A (en) * 2021-12-17 2022-03-25 四川九洲空管科技有限责任公司 File data memory, writing method, reading method and storage system

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1632765A (en) * 2004-12-31 2005-06-29 大唐微电子技术有限公司 A flash memory file system management method
CN101441634A (en) * 2007-11-19 2009-05-27 凤凰微电子(中国)有限公司 Embedded type file system suitable for smart card application environment
CN101853417A (en) * 2010-05-24 2010-10-06 北京飞天诚信科技有限公司 Working method and system of CF (Compact Flash) interface information safety equipment
CN102110145A (en) * 2011-02-15 2011-06-29 中国科学院计算技术研究所 Micro FAT file system and quick data access method thereof

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7194563B2 (en) * 2001-12-05 2007-03-20 Scientific-Atlanta, Inc. Disk driver cluster management of time shift buffer with file allocation table structure

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1632765A (en) * 2004-12-31 2005-06-29 大唐微电子技术有限公司 A flash memory file system management method
CN101441634A (en) * 2007-11-19 2009-05-27 凤凰微电子(中国)有限公司 Embedded type file system suitable for smart card application environment
CN101853417A (en) * 2010-05-24 2010-10-06 北京飞天诚信科技有限公司 Working method and system of CF (Compact Flash) interface information safety equipment
CN102110145A (en) * 2011-02-15 2011-06-29 中国科学院计算技术研究所 Micro FAT file system and quick data access method thereof

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"基于S3C2410航迹标绘控制系统设计与实现";孙亚娟;《中国优秀硕士学位论文全文数据库 信息科技辑》;20140430;第48-51页 *

Also Published As

Publication number Publication date
CN107239526A (en) 2017-10-10

Similar Documents

Publication Publication Date Title
CN107239526B (en) File system implementation method, defragmentation method and operation position positioning method
US11636032B2 (en) Memory system, data storage device, user device and data management method thereof
US7475185B2 (en) Nonvolatile memory system, nonvolatile memory device, memory controller, access device, and method for controlling nonvolatile memory device
US8607016B2 (en) FAT analysis for optimized sequential cluster management
US8335907B2 (en) Micro-update architecture for address tables
US7395384B2 (en) Method and apparatus for maintaining data on non-volatile memory systems
US7669003B2 (en) Reprogrammable non-volatile memory systems with indexing of directly stored data files
US7949845B2 (en) Indexing of file data in reprogrammable non-volatile memories that directly store data files
US7594062B2 (en) Method for changing data of a data block in a flash memory having a mapping area, a data area and an alternative area
US10275361B2 (en) Managing multiple namespaces in a non-volatile memory (NVM)
CN105760113B (en) High-speed processing apparatus and file management method based on nand flash memory
US20080109589A1 (en) Nonvolatile Storage Device And Data Write Method
US20060218347A1 (en) Memory card
US20150186259A1 (en) Method and apparatus for storing data in non-volatile memory
CN111522507B (en) Low-delay file system address space management method, system and medium
KR20070039957A (en) Method and device to improve usb flash write performance
CN111143285A (en) Small file storage file system and small file processing method
KR101893897B1 (en) Memory system and user device, and data management method thereof
WO2016106757A1 (en) Method for managing storage data, storage manager and storage system
CN114610228A (en) File management system and file management method and device thereof
CN109739683B (en) LKJ file writing method based on power failure protection medium and storage medium
CN107608636B (en) Design method based on FAT file system and data acquisition device applied by same
CN114265562B (en) File storage method and system based on flash memory
JP2008134777A (en) Caching method of file allocation table
CN110716904A (en) Design method of embedded file system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant