Summary of the invention
In view of this, the purpose of design of the present invention is, it is provided that a kind of storage method of file system and be
System, to save the space of file system, reduces the consumption to internal memory, and improves the performance of file system.
The embodiment of the present invention is achieved in that
A kind of storage method of file system, including:
In the multiple submanifolds being stored in by the file got bunch, described submanifold is in each bunch of disk
It is evenly dividing out in advance;
When in described bunch, the number of files of storage is one, then the described bunch correspondence of record in file allocation table
Next submanifold number;
When the number of files of storage is more than one in described bunch, then in this bunch, sets up one record described
Bunch the file of next submanifold number corresponding to each submanifold distribute from table, and in described file allocation table
Record this bunch and there is the distribution of described file from table.
Preferably, in the storage method of above-mentioned file system, when described bunch does not exist corresponding next
During individual submanifold, then in described file allocation table, the described bunch corresponding next submanifold number of record is empty.
Preferably, in the storage method of above-mentioned file system, when the submanifold of described bunch does not exist correspondence
Next submanifold time, then described file distribution from table, record next height that described submanifold is corresponding
Bunch number it is empty.
Preferably, in the storage method of above-mentioned file system, when in described bunch, the number of files of storage is
One, and when deleting the file in the submanifold of described bunch, then described at described file distribution record from table
Bunch submanifold be unallocated state.
Preferably, in the storage method of above-mentioned file system, when in described bunch, the number of files of storage is big
In one, and when deleting the file in the submanifold of described bunch, then from table, record institute in the distribution of described file
The submanifold stated bunch is unallocated state.
Preferably, in the storage method of above-mentioned file system, when in described bunch, the number of files of storage is big
In one, and when deleting the All Files in described bunch, then delete described file and distribute from table, and in institute
Stating described bunch of record in file allocation table is unallocated state.
Preferably, in the storage method of above-mentioned file system, when storing a literary composition in described disk
Part, and described disk bunch in exist file distribute when table, then described file is preferentially stored to described
File distribution from table place bunch.
Preferably, in the storage method of above-mentioned file system, described submanifold occupies the sky of a sector
Between.
A kind of storage system of FAT file system, including:
Submanifold distribution module, for marking off multiple submanifold the most uniformly in each bunch of disk;
Memory module, in the multiple submanifolds being stored in by the file got bunch;
File allocation table logging modle, for when in described bunch, the number of files of storage is one, then at literary composition
The described bunch corresponding next submanifold number of record in part allocation table;When in described bunch, the number of files of storage is more than
When one, then in described file allocation table, record this bunch there is the distribution of described file from table;
File distribution sets up module from table, is used for when in described bunch, the number of files of storage is more than one, then
A file distribution that record next submanifold number corresponding to each submanifold of described bunch is set up in this bunch
From table.
Compared with prior art, the technical scheme that the present embodiment provides has the following advantages and feature:
In the scheme that the present invention provides, in the submanifold that file can be stored in bunch, and if by two
When above file is stored in one bunch, only need to set up a file in this bunch and distribute from table, and remember
Record, in file allocation table, thus can be distributed from table by file allocation table accessing to file, thus
Have access to the submanifold of each bunch, so the space of each bunch in disk can be made full use of by the present invention
Get up;And, by bunch in set up file distribution from table by the way of, huge file will not be produced and divide
Join table, from the search time without increasing bunch chain.Therefore, the scheme that the present invention provides is the most sufficient
Make use of the space of disk, and effectively reduce the time of bunch chaining search.
Detailed description of the invention
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is carried out
Clearly and completely describe, it is clear that described embodiment is only a part of embodiment of the present invention, and
It is not all, of embodiment.Based on the embodiment in the present invention, those of ordinary skill in the art are not doing
Go out the every other embodiment obtained under creative work premise, broadly fall into the scope of protection of the invention.
Embodiments provide a kind of storage method of file system, including: the file that will get
In the multiple submanifolds being stored in bunch, described submanifold is to be evenly dividing out in advance in each bunch of disk
's;When in described bunch, the number of files of storage is one, then the described bunch correspondence of record in file allocation table
Next submanifold number;When the number of files of storage is more than one in described bunch, then in this bunch, set up one
The individual file that record next submanifold number corresponding to each submanifold of described bunch distributes from table, and described
File allocation table records this bunch and there is the distribution of described file from table.
Owing to there is various ways in the implementing of storage method of above-mentioned file system, below by specifically
Embodiment is described in detail:
Shown in Figure 1, the flow chart of a kind of storage method for file system shown in Fig. 1, should
Method includes:
In step S11, the multiple submanifolds being stored in by the file got bunch, described submanifold is at disk
Each bunch is evenly dividing out in advance;
In step s 11, before using the space of disk, need disk is formatted.Entering
During formatting lines, it is thus necessary to determine that the sector number of good every submanifold, the submanifold number of every bunch, will bunch in mark off
The space come is referred to as submanifold.In order to reach best effect, the most every 1 sector of submanifold, the son of every bunch
Number of clusters=sector byte number/element byte number.After formatting, there is not file and distribute from table.
Step S12, when in described bunch storage number of files be one time, then in file allocation table record institute
State a bunch corresponding next submanifold number;
In step s 12, if bunch in the file only one of which that stored, no matter whether this file
Occupy the space of whole bunch completely, then be required for recording in file allocation table this bunch corresponding under
One submanifold number;If the next submanifold number that the file in this bunch is the most corresponding, then at file
Allocation table records this bunch corresponding for sky.
Step S13, when in described bunch storage number of files more than one time, then in this bunch, set up a note
The file recording next submanifold number corresponding to each submanifold of described bunch distributes from table, and at described file
Allocation table records this bunch and there is the distribution of described file from table.
In step s 13, if bunch in the file that stored more than one time, it is assumed that bunch in store
Two files, then just have no idea to record two that both of these documents is respectively directed in file allocation table
Submanifold number, because simply one bunch and the corresponding relation of a submanifold that record in file allocation table, and nothing
Method records the corresponding relation of two submanifolds in this bunch and two other submanifold.So in file allocation table
In one bunch can only point to a submanifold, it is impossible to pointing to two submanifolds, this is by the structure of file allocation table
Determined.So two submanifolds being it desired to be able to record that in lower bunch can distinguish corresponding two other
Submanifold, then need to set up a file in this bunch and distribute from table, remember from table with the distribution of this file
Record the next submanifold number that each submanifold in this bunch is corresponding.Distribute after table when setting up file in this bunch,
Need to record in file allocation table and this bunch has file distribution from table.
In the embodiment shown in fig. 1, in the submanifold that file can be stored in bunch, and if by two
When above file is stored in one bunch, only need to set up a file in this bunch and distribute from table, and remember
Record, in file allocation table, thus can be distributed from table by file allocation table accessing to file, thus
Have access to the submanifold of each bunch, so the space of each bunch in disk can be made full use of by the present invention
Get up;And, by bunch in set up file distribution from table by the way of, huge file will not be produced and divide
Join table, from the search time without increasing bunch chain.Therefore, the scheme that the present invention provides is the most sufficient
Make use of the space of disk, and effectively reduce the time of bunch chaining search.
In the embodiment shown in fig. 1, when the described bunch of next submanifold that there is not correspondence, then exist
In described file allocation table, the described bunch corresponding next submanifold number of record is empty.When the submanifold of described bunch not
When there is corresponding next submanifold, then from table, record described submanifold in the distribution of described file corresponding
Next submanifold number is empty.When in described bunch, the number of files of storage is one, and delete the submanifold of described bunch
In file time, then be unallocated state at described file distribution submanifold of described bunch of record from table.When
In described bunch, the number of files of storage is more than one, and when deleting the file in the submanifold of described bunch, then in institute
The submanifold stating described bunch of file distribution record from table is unallocated state.When the file of storage in described bunch
Number is more than one, and when deleting the All Files in described bunch, then deletes described file and distribute from table, and
In described file allocation table, described bunch of record is unallocated state.When storing a literary composition in described disk
Part, and described disk bunch in exist file distribute when table, then described file is preferentially stored to described
File distribution from table place bunch.
It is described in detail below by concrete example, refers to shown in Fig. 2 to Fig. 4, shown in Fig. 2
Design sketch is deposited for disk entirety, the schematic diagram for file allocation table shown in Fig. 3, shown in Fig. 4 be
File distribution is from the schematic diagram of table.
In the embodiment shown in Fig. 2 to Fig. 4, there is two kinds of file allocation table, wherein, newly
The file allocation table increasing type is dynamic creation.The original table of FATFS file system can make file divide
Joining table, the newly-increased file that cries distributes from table.
In the embodiment shown in Fig. 2 to Fig. 4, for the ease of analytic explanation, from here on, I
Suppose that a sector is 16 bytes, a submanifold is with regard to a sector.And one bunch has 4 sectors, i.e.
4 submanifolds.And whole disk suppose there is 6 bunches, each element 32 in file allocation table.6 bunches
2 sectors are about needed to deposit, it is assumed that to be just placed on latter two sector of the 0th bunch.Fig. 2 illustrates entirety and deposits
Effect, wherein root occupy the 1st bunch with the 3rd bunch, file 1 occupies in the 2nd bunch and the 4th bunch the 0th
Submanifold.File 2 occupies the 4th bunch of the 1st submanifold, the 2nd submanifold, and the 5th bunch.
Shown in Fig. 3 for file allocation table, mainly a single-track link table, Mei Geyuan in file allocation table
Corresponding one bunch of the position of element, its highest order is called file and distributes from table mark, represents whether this bunch has literary composition
Part distributes from table;Next submanifold is pointed in remaining position, is a bunch index.In the file allocation table shown in Fig. 3
In, the highest order (b31) of each element is that file distributes from table mark, and low level (b0-b30) is a bunch index.?
In Fig. 3, upper row is 0,000 1000, and these eight positions represent whether current bunch exist file distribution
From table, wherein, 0 represents that there is not file distributes from table, and 1 represents that there is file distributes from table.So
5, i.e. the 4th bunch exists file and distributes from table, so the numeral of the see from left to right the 5th is 1,
File distribution is there is from table in conjunction with strictly the 3rd submanifold in the 4th bunch from the point of view of Fig. 2.It addition, at Fig. 3
The element of shown each box indicating one 32, in square frame, numeral above represents whether this bunch is deposited
Distributing from table at file, wherein 0 represents that there is not file distributes from table.Numbers below points to the next one
Submanifold, wherein 0 expression this bunch is unallocated, and-1 expression has distributed or last bunch of file, and-2 represent the trueest
Real bunch correspondence or evil idea bunch.
Distributing from table for file shown in Fig. 4, file distribution is also a single-track link table from table, Mei Geyuan
The position of element represents a submanifold, and its value points to next submanifold.Submanifold belongs to certain bunch, and file distributes
It is stored in submanifold last in its bunch from table.One file distribution occupies a submanifold from table, represents institute
Belong to bunch interior chain relationship.Wherein, the element of each box indicating in Fig. 4 one 32, in square frame
Numeral represents the index of next submanifold, and wherein 0 represents that this submanifold is unallocated, and-1 expression has distributed or literary composition
Last bunch of part.It is-1 in first square frame of Fig. 4, represents that file 1 is last bunch;Second square frame is
18, represent that bunch index of the file 2 in the 17th submanifold is the 18th submanifold, i.e. second square frame is the 17th
Submanifold, bunch index of the 17th submanifold is the 18th submanifold;3rd square frame is 20, in representing the 18th submanifold
File 2 bunch index be the 20th submanifold, i.e. the 3rd square frame is the 18th submanifold, the 18th submanifold
Bunch index is the 20th submanifold;4th square frame is distributing from table for file of depositing of the-1, the 19th submanifold,
And be just last bunch, so it is-1.
By above-described embodiment it can be seen that the file allocation table that the present invention provides is distributed from table with file
Organically combine, co-ordination, it is achieved the traversal of bunch chain.First the directory information (DIRENTRY) of file
Illustrate this file first submanifold bunch number, according to this submanifold numbering can calculate belonged to bunch.
Bunch corresponding with the element of file allocation table, whether the sublist that can check in file allocation table bunch exists.
If the file distribution of this bunch does not exists from table, the most whole bunch is used by file, and lower cluster is file
Bunch index in allocation table;Otherwise, then next bunch of file distribution search from table.
In the embodiment shown in Fig. 2 to Fig. 4, it is also possible to remaining space is calculated.First, exist
File allocation table scans all bunches, represents that this bunch is idle if 0;When exist file distribution from
During table, then file distribution scans all submanifolds from table, represents that this submanifold is idle if 0.This
Sample just can calculate its remaining space.
In the embodiment shown in Fig. 2 to Fig. 4, when a newly-built file or file replicate, need for it
Distribute a certain size space.Recommended hour method of completing the square is as follows: first, and requisite space is cut into N number of bunch.
In file allocation table, this N number of bunch is distributed for it.This process is roughly the same with former FATFS.Secondly,
Bunch cut remaining submanifold, All Files distribution should be searched from table by file allocation table, distribute at file
Submanifold is distributed for it from table.If remaining submanifold cannot be distributed from the distribution of existing file from table, need
To create file a blank bunch to distribute from table, then distribute.
In the embodiment shown in Fig. 2 to Fig. 4, when deleting file, need first to travel through file chain, release
To its distribute bunch and submanifold, during submanifold discharges, if in table, all submanifolds are all in file distribution
Empty, then file distribution is deleted from table, and the file distribution in file allocation table sets to 0 from table mark.
It addition, the above-mentioned data structure having explained double FAT table, logic and operation principle.Based on above-mentioned
Can transform out the file system of double FAT table.But logical AND flow process will be more multiple when being embodied as
Miscellaneous, need to consider more situation, deeper optimize, more powerful function is provided.Such as:
In file allocation table, if file distribution is masked as 1 from table, then bunch index can represent in this bunch with escape
The quantity of blank submanifold, so can accelerate to analyze speed.Increase file: this should analyze this file pair
Whether last bunch answered be free white chessman bunch, first distribute these submanifolds if had.The most again by newly-built literary composition
The regular allocation space of part.Reduce file: what after reduction, the tail bunch of file was corresponding bunch has the more free time
Submanifold, if this bunch does not has file to distribute from table, it should create file and distribute from table, and distribute at file
These idle submanifolds are reflected from table.Virtual USB disk: Study document allocation table with and All Files distribution from
Double FAT table are become a big FAT table by table, are converted into current popular operating system (such as Windows
Deng) file system that can identify.
Shown in Figure 5, the storage system for a kind of FAT file system shown in Fig. 5, this storage
System 1 includes: submanifold distribution module 11, for marking off the most uniformly in each bunch of disk 2
Multiple submanifolds;Memory module 12, in the multiple submanifolds being stored in by the file got bunch;File
Assignment table record module 13, for when in described bunch, the number of files of storage is one, then distributes at file
The described bunch corresponding next submanifold number of record in table;When in described bunch, the number of files of storage is more than one,
In described file allocation table, then record this bunch there is the distribution of described file from table;File distribution is set up from table
Module 14, for when the number of files of storage is more than one in described bunch, then setting up a note in this bunch
The file recording next submanifold number corresponding to each submanifold of described bunch distributes from table.
It should be noted that the embodiment shown in Fig. 1 to Fig. 5 is the present invention being preferable to carry out of being introduced
Example, those skilled in the art on this basis, can be designed that more embodiment completely, do not exist
Repeat herein.
Multiple amendment to these embodiments will be apparent for those skilled in the art
, generic principles defined herein can without departing from the spirit or scope of the present invention,
Realize in other embodiments.Therefore, the present invention is not intended to be limited to the embodiments shown herein,
And it is to fit to the widest scope consistent with principles disclosed herein and features of novelty.