CN110286859B - Data storage method and device based on FAT file system - Google Patents

Data storage method and device based on FAT file system Download PDF

Info

Publication number
CN110286859B
CN110286859B CN201910574107.XA CN201910574107A CN110286859B CN 110286859 B CN110286859 B CN 110286859B CN 201910574107 A CN201910574107 A CN 201910574107A CN 110286859 B CN110286859 B CN 110286859B
Authority
CN
China
Prior art keywords
data
cluster
file
file system
area
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
CN201910574107.XA
Other languages
Chinese (zh)
Other versions
CN110286859A (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.)
Ocean University of China
Original Assignee
Ocean University of China
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 Ocean University of China filed Critical Ocean University of China
Priority to CN201910574107.XA priority Critical patent/CN110286859B/en
Publication of CN110286859A publication Critical patent/CN110286859A/en
Application granted granted Critical
Publication of CN110286859B publication Critical patent/CN110286859B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/0643Management of files

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a data storage method and a device based on a FAT file system, which continuously store data files to a data area by taking a data block as a unit, record the storage state of clusters with the same number in the data area in each table entry of a file allocation table, form a cluster chain by each cluster occupied by the data files, and use the partition storage mode to avoid the occurrence of the situation that the cluster chain of the files starts in the sector of the FAT table, save all reading operations of the FAT table when the data files are stored, simplify the updating of the FAT table into two steps of continuous cluster chain generation and continuous sector writing, and greatly simplify the operation flow.

Description

Data storage method and device based on FAT file system
Technical Field
The invention belongs to the technical field of computers, and particularly relates to a data storage method and device based on a FAT file system.
Background
The FAT file system is a file system supported by operating systems such as Windows, and in order to ensure that data in the SD card can be directly read by the field monitoring host, the file system needs to be mounted in the SD card, so that the data in the SD card is stored in the SD card in a file form.
In the use process of the traditional file system, when a file is created, a root directory needs to be updated to provide a file reading and writing basis for subsequent access, and when each sector and cluster are read and written, repeated reading and updating are carried out on corresponding sectors and FSINFO sectors in a FAT1 table and a FAT2 table so as to determine the address of the current reading and writing and update the next available sector. That is, when the system stores valid data, the system not only needs to store the data, but also needs to store a lot of information related to the file where the data is located, such as a series of file system parameters, such as a file name, a file storage cluster chain, a file start position, and the like. This complex implementation is not advantageous for its logical implementation.
In view of the above, it is desirable to provide a data storage method and apparatus based on the FAT file system.
Disclosure of Invention
The present invention provides a data storage method and apparatus based on FAT file system to solve the above problems.
In order to achieve the purpose, the invention adopts the technical scheme that:
a data storage method based on FAT file system, the said FAT file system includes reservation area, file allocation table and data area, the method includes the following steps sequentially:
step S1: reading the state information area in the data area, wherein the state information area is used for storing a custom identifier;
step S2: judging whether a user-defined identifier exists or not; if the user-defined identifier does not exist, executing step S3 and then executing step S4; if the user-defined identifier exists, executing step S4;
step S3: customizing the FAT file system: defining a first sector of a fourth cluster of the data area as the state information area, wherein the state information area stores the self-defined identification and the number of clusters occupied by the data blocks, and the data blocks consist of a fixed number of clusters;
step S4: after reading the root directory, creating a file directory entry and updating the root directory;
step S5: and storing the data file to the data area by taking the data block as a unit, and creating a cluster chain updating file distribution table.
Preferably, in step S5, the specific process of creating the cluster chain update file allocation table is as follows:
each newly-built data file is continuously stored from the first address of the currently available data block, and after the currently available data block is full, the data file is continuously stored into the next data block until the data file is finished; if the currently available data block is not full when the data file is ended, discarding the remaining clusters of the currently available data block, and directly storing the next data file from the head address of the next currently available data block;
and sequentially numbering the entries in the file allocation table, recording the storage state of the cluster with the same number in the data area in each entry, and filling the cluster number of the next cluster occupied by the data file into the entries so as to form a cluster chain for each cluster occupied by the data file.
Preferably, in step S3, the data block occupies 128 clusters, the clusters occupy 16 sectors, and each sector is 512 Bytes.
Preferably, the root directory is read in a root directory area, wherein the root directory area is located in a third cluster of the data area.
Preferably, in step S3, the address of the next currently available data block and the cluster number of the next available cluster are stored in the status information area.
Preferably, the method further comprises step S6: and updating the state information area.
Preferably, the entries in the file allocation table occupy 4 bytes.
A FAT file system based data storage device comprising: one or more processors;
a storage unit for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the above-mentioned FAT file system-based data storage method.
The invention has the advantages and positive effects that:
1) the data storage method based on the FAT file system continuously stores the data files into the data area by taking the data blocks as units, the storage state of the clusters with the same number in the data area is recorded in each table entry of the file allocation table, each cluster occupied by the data files forms a cluster chain, the condition that the cluster chain of the files starts in the sector of the FAT table is avoided by using the partition storage mode, all reading operations of the FAT table when the data files are stored are omitted, the updating of the FAT table can be simplified into two steps of continuous cluster chain generation and continuous sector writing, and the operation flow is greatly simplified.
2) In the data storage method based on the FAT file system, the list items of the FAT file system with the sequential labels correspond to the clusters of the data area with the sequential labels, and the data files are stored by taking the data blocks as units, so that the cluster chains in the FAT list are continuous in a self-defined FAT file system form and are always integral multiples of 128 in length, the complete cluster chains can be conveniently obtained, and the complete cluster chains can be calculated according to the number of sectors stored in the data files.
Drawings
FIG. 1 is a schematic structural diagram of a FAT file system according to the present invention;
FIG. 2 is a schematic diagram of a data area of the FAT file system according to the present invention;
FIG. 3 is a flowchart of a data storage method based on the FAT file system according to the present invention.
Detailed Description
The invention is described in detail below by way of exemplary embodiments. It should be understood, however, that elements, structures and features of one embodiment may be beneficially incorporated in other embodiments without further recitation.
The invention aims to simplify the operation process of the FAT file system to carry out the re-self-definition on the original FAT file: custom file allocation table (FAT table) partition: taking every 4 bytes as a unit in the FAT table, which is called as an entry, numbering the entries from 0, recording the storage state of clusters with the same number in a data area in each entry, and filling the entry with the cluster number of the next cluster occupied by a data file (the entry corresponding to the last cluster of the data file does not need to be filled with the cluster number of the next cluster occupied by the data file), so as to form a cluster chain for each cluster occupied by the data file;
and (4) self-defining data area partition: referring to fig. 2, it should be noted that the data stored in the SD card is default to 16 sectors of a cluster, each 512Bytes, i.e. 8KB of each cluster. The custom data partition divides the data into 4 parts:
1) a default area: the first two clusters (labeled as cluster 0 and cluster 1) are the default areas of the FAT32 file system.
2) Root directory area: the third cluster (marked as 2 clusters) is the actual starting position of the data area, defined as the root directory area, and is used for storing directory information of files and information such as the data file storage starting cluster.
3) A state information area: and a fourth cluster (marked as 3 clusters), wherein the first sector of the cluster is defined as a state information area by itself, the size of the state information area is 512Bytes, and the state information area is used for summarizing part of data file information randomly stored in the DBR sector, the FSINFO sector, the FAT table and the root directory in the file system and adding the use parameters of the self-defined file system partition. The remaining 15 sectors and 124 clusters (clusters 4-127) after the cluster are reserved and are not used for the moment.
4) The fourth part is a remaining partition of the original data area, all clusters from the 128 th cluster are regarded as a new data area, and the minimum storage unit of the new data area is redefined.
Dividing the rest partitions in the custom data area into continuous data blocks with the same size of 1MB (the data blocks occupy 128 clusters, one cluster occupies 16 sectors, and each sector is 512Bytes, so the size of the data block is 1MB), and ensuring that the data files use the continuous data blocks in the data file storage process to ensure that the generated cluster chain is continuous, so that the complete cluster chain can be calculated as long as the number of the sectors stored in the data files is increased; because the list items of the FAT file system with the serial labels correspond to the clusters of the data area with the serial labels, and the data files are stored by taking the data blocks as units, the cluster chain in the FAT table is continuous in a self-defined FAT file system form, and the length of the cluster chain is always integral multiple of 128, so that the complete cluster chain can be conveniently obtained.
Note that the first three portions of the custom data area partition and the reserved area are contained in the first data Block (Block _0) numbered 0.
The content of the status information area is defined as shown in the following table:
Figure BDA0002111605310000041
Figure BDA0002111605310000051
the data in the state information area is obtained from the initialization self-definition or the monitoring and management of the operating process of the file system, and the state information area comprises the definition of partial self-definition partition variables and all sector address information required by the writing of the data, the FAT table and the root directory of the FAT file system. And the file partition mode is realized by re-customizing, and for an SD card which is never used in the system, the inside of the SD card does not have the State Information area, so the first 11 bytes of the State Information area are used for storing a State Information area customized identifier (mark and version number), and are fixed as 'SISECTOR 1.0', namely, a State Information Sector, version 1.0. When the SD card performs file system operation, the information content of the sector where the state information area is located needs to be read first, whether a state information area mark exists is checked, and whether initialization operation of the state information area is performed or not is determined, so that the user-defined file system partition scheme designed in the SD card has universality in the same type of SD cards.
A data storage method based on FAT file system, the said FAT file system includes reservation area, file allocation table and data area, the method includes the following steps sequentially:
step S1: reading the state information area in the data area, wherein the state information area is used for storing a custom identifier;
step S2: judging whether a user-defined identifier exists or not; if the user-defined identifier does not exist, executing step S3 and then executing step S4; if the user-defined identifier exists, executing step S4;
step S3: customizing the FAT file system: defining a first sector of a fourth cluster of the data area as the state information area, wherein the state information area stores the self-defined identifier and the number of clusters occupied by the data blocks, the data blocks are composed of a fixed number of clusters, the data blocks occupy 128 clusters, the clusters occupy 16 sectors, and each sector is 512 Bytes;
step S4: after reading the root directory, creating a file directory entry and updating the root directory, wherein the root directory is read in a root directory area, and the root directory area is located in a third cluster of the data area;
step S5: and storing the data file to the data area by taking the data block as a unit, and creating a cluster chain updating file distribution table.
Further, in step S3, the address of the next currently available data block and the cluster number of the next available cluster are stored in the status information area.
Further, the method also includes step S6: and updating the state information area.
Further, in step S5, the specific process of creating the cluster chain update file allocation table is as follows:
each newly-built data file is continuously stored from the first address of the currently available data block, and after the currently available data block is full, the data file is continuously stored into the next data block until the data file is finished; if the currently available data block is not full when the data file is ended, discarding the remaining clusters of the currently available data block, and directly storing the next data file from the head address of the next currently available data block;
and sequentially numbering the entries in the file allocation table, wherein the entries in the file allocation table occupy 4 bytes, the storage state of the clusters with the same number in the data area is recorded in each entry, and the cluster number of the next cluster occupied by the data file is filled in each entry, so that each cluster occupied by the data file forms a cluster chain.
A FAT file system based data storage device comprising: one or more processors;
a storage unit for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the above-mentioned FAT file system-based data storage method.
The above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (8)

1. A data storage method based on FAT file system, the FAT file system includes reserved area, file allocation table and data area, its characteristic is: the method sequentially comprises the following steps:
step S1: reading a state information area in the data area, wherein the state information area is used for storing a custom identifier;
step S2: judging whether a user-defined identifier exists or not; if the user-defined identifier does not exist, executing step S3 and then executing step S4; if the user-defined identifier exists, executing step S4;
step S3: customizing the FAT file system: defining a first sector of a fourth cluster of the data area as the state information area, wherein the state information area stores the self-defined identification and the number of clusters occupied by the data blocks, and the data blocks consist of a fixed number of clusters;
step S4: after reading the root directory, creating a file directory entry and updating the root directory;
step S5: and storing the data file to the data area by taking the data block as a unit, and creating a cluster chain updating file distribution table.
2. The FAT file system-based data storage method according to claim 1, wherein: in step S5, the specific process of creating the cluster chain update file allocation table is as follows:
each newly-built data file is continuously stored from the first address of the currently available data block, and after the currently available data block is full, the data file is continuously stored into the next data block until the data file is finished; if the currently available data block is not full when the data file is ended, discarding the remaining clusters of the currently available data block, and directly storing the next data file from the head address of the next currently available data block;
and sequentially numbering the entries in the file allocation table, recording the storage state of the cluster with the same number in the data area in each entry, and filling the cluster number of the next cluster occupied by the data file into the entries so as to form a cluster chain for each cluster occupied by the data file.
3. The FAT file system-based data storage method according to claim 1, wherein: in step S3, the data block occupies 128 clusters, the clusters occupy 16 sectors, and each sector is 512 Bytes.
4. The FAT file system-based data storage method according to claim 1, wherein: and reading the root directory in a root directory area, wherein the root directory area is positioned in a third cluster of the data area.
5. The FAT file system-based data storage method according to claim 1, wherein: in step S3, the status information area further stores the address of the next currently available data block and the cluster number of the next available cluster.
6. The FAT file system-based data storage method according to claim 5, wherein: further comprising step S6: and updating the state information area.
7. The FAT file system-based data storage method according to claim 2, wherein: the entries in the file allocation table occupy 4 bytes.
8. A data storage device based on a FAT file system, comprising: one or more processors;
a storage unit for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the FAT file system-based data storage method of any of claims 1-7.
CN201910574107.XA 2019-06-28 2019-06-28 Data storage method and device based on FAT file system Active CN110286859B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910574107.XA CN110286859B (en) 2019-06-28 2019-06-28 Data storage method and device based on FAT file system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910574107.XA CN110286859B (en) 2019-06-28 2019-06-28 Data storage method and device based on FAT file system

Publications (2)

Publication Number Publication Date
CN110286859A CN110286859A (en) 2019-09-27
CN110286859B true CN110286859B (en) 2020-04-14

Family

ID=68019509

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910574107.XA Active CN110286859B (en) 2019-06-28 2019-06-28 Data storage method and device based on FAT file system

Country Status (1)

Country Link
CN (1) CN110286859B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111177070A (en) * 2019-12-03 2020-05-19 贵州朗盛科技股份有限公司 File allocation method and storage device
CN112463753B (en) * 2020-11-06 2023-01-10 苏州浪潮智能科技有限公司 Block chain data storage method, system, equipment and readable storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2005119459A1 (en) * 2004-06-04 2005-12-15 Renosoft Technology Inc. Apparatus and method for protecting system data on computer hard-disk
CN1776685A (en) * 2005-12-16 2006-05-24 北京中星微电子有限公司 Method and device for supporting multi-languages in FAT file system
CN101382877A (en) * 2008-10-15 2009-03-11 青岛海信移动通信技术股份有限公司 FAT file data reading/writing method, system and mobile communication terminal
CN101763426A (en) * 2010-01-08 2010-06-30 浙江大学 Method and device for realizing reliability of file allocation table file system
CN101853275A (en) * 2010-05-05 2010-10-06 北京中星微电子有限公司 Data management method of FAT file system and system

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100507919C (en) * 2007-05-11 2009-07-01 北京中星微电子有限公司 FAT file system and its processing method
CN101303667B (en) * 2008-06-25 2010-06-09 炬力集成电路设计有限公司 Method and device for establishing magnetic disk null cluster table and seeking magnetic disk null cluster
US8375192B2 (en) * 2008-12-16 2013-02-12 Sandisk Il Ltd. Discardable files
CN101515276B (en) * 2008-12-29 2012-07-04 北京握奇数据系统有限公司 Method for write operation of file data, and recovery method and recovery system for file data
CN102541969B (en) * 2011-03-29 2015-04-29 深圳市江波龙电子有限公司 File protection method and system based on file allocation table (FAT) file system, and memory

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2005119459A1 (en) * 2004-06-04 2005-12-15 Renosoft Technology Inc. Apparatus and method for protecting system data on computer hard-disk
CN1776685A (en) * 2005-12-16 2006-05-24 北京中星微电子有限公司 Method and device for supporting multi-languages in FAT file system
CN101382877A (en) * 2008-10-15 2009-03-11 青岛海信移动通信技术股份有限公司 FAT file data reading/writing method, system and mobile communication terminal
CN101763426A (en) * 2010-01-08 2010-06-30 浙江大学 Method and device for realizing reliability of file allocation table file system
CN101853275A (en) * 2010-05-05 2010-10-06 北京中星微电子有限公司 Data management method of FAT file system and system

Also Published As

Publication number Publication date
CN110286859A (en) 2019-09-27

Similar Documents

Publication Publication Date Title
CN102508784B (en) Data storage method of flash memory card in video monitoring equipment, and system thereof
JP3629510B2 (en) Expansion card file system
CN104346357B (en) The file access method and system of a kind of built-in terminal
JP4206688B2 (en) Data processing apparatus and data processing method
US8924664B2 (en) Logical object deletion
US8312554B2 (en) Method of hiding file at data protecting mode for non-volatile memory module, memory controller and portable memory storage apparatus
US20090300082A1 (en) Method for memory space management
WO2016165597A1 (en) Processing method and device for data storage
JP2003308240A (en) Data storage device
CN111522507B (en) Low-delay file system address space management method, system and medium
CN106502587A (en) Data in magnetic disk management method and magnetic disk control unit
CN105446664B (en) A kind of pair of memory carries out file memory method and storage device
CN103514249A (en) Method and system for automatic data reduction and storage device
CN110286859B (en) Data storage method and device based on FAT file system
CN101582084A (en) Method and device for data storage
CN106326384A (en) File storage method suitable for high-speed mass storage based on FPGA (Field Programmable Gate Array)
CN101303667B (en) Method and device for establishing magnetic disk null cluster table and seeking magnetic disk null cluster
CN107544912B (en) Log recording method, loading method and device
CN117473117B (en) Video cyclic storage method, system and computer
US20190026033A1 (en) Method and system for hardware accelerated cache flush
CN111949212B (en) File system and file management method based on self-defined open channel SSD
CN112148640A (en) Cache memory replacement method, cache memory and computer system
EP1017028A2 (en) Extended card file system
CN107544866B (en) Log updating method and device
CN107544913B (en) FTL table rapid reconstruction method and device

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