Summary of the invention
The present invention provides a kind of establishment and read method and device of virtual FAT file system based on standard FAT file system, thereby can realize visiting by virtual FAT file system the disk space of huge capacity.
For this reason, the embodiment of the invention adopts following technical scheme:
A kind of creation method of virtual FAT file system, for authentic document is created its corresponding virtual file under the target directory of target partition, this method comprises the step of creating virtual directory and creating virtual file, wherein, the step of described establishment virtual file comprises: the item that under the target directory of target partition, creaties directory, revise the title that the directory entry property file is called virtual file; In the FAT of target partition table, distribute continuous bunch according to the size of authentic document, constitute bunch chain of virtual file.
Before creating virtual directory, also comprise: after virtual FAT file system place device format is turned to the FAT32 system, only save contents in the data field of FAT32 system.
Describedly virtual FAT file system place device format is turned to the FAT32 system also comprise: the FAT table number of revised file system boot sector is 1.
Before virtual FAT file system place device format is turned to the FAT32 system, also comprise: revise the registration parameter of the driver of virtual FAT file system place equipment to the equipment of accesses virtual FAT file system.
Preferably, this method also comprises: the virtual cluster chain number and the authentic document table of comparisons of creating the corresponding relation comprise bunch chain number, bunch chain size and authentic document comspec.
Wherein, the step of described establishment virtual directory is carried out at preassigned disk space.
A kind of read method of virtual FAT file system, by reading the virtual file visit authentic document in the virtual FAT file system, this method comprises: receive the read operation request of virtual file, comprise sector number and size in this request; According to described sector number and search the parameter that described virtual FAT system obtains, calculate bunch chain number of virtual file; Search the virtual file bunch chain and the authentic document table of comparisons that generates in advance according to the size in described bunch of chain number and the described read operation request, obtain the comspec and the positional information of authentic document; According to the size in authentic document comspec and positional information and the described read operation request, determine the access path information of authentic document; According to described access path message reference authentic document.
Wherein, described according to described sector number and search the parameter that described virtual FAT system obtains, the detailed process that calculates bunch chain number of virtual file is: search the DBR of virtual FAT system, obtain reserve sector number, FAT table sector number and the every number of clusters in sector; Utilize described sector number, described reserve sector number, FAT table sector number and the every number of clusters in sector to calculate bunch chain number of virtual file.
Calculate bunch chain number of virtual file by following formula: bunch chain number=(sector number-reserve sector number-FAT shows the sector number)/every number of clusters in sector+2.
Wherein, describedly search the virtual file bunch chain and the authentic document table of comparisons that generates in advance according to described bunch of chain number and described size, the detailed process that obtains authentic document comspec and positional information is: search the virtual file bunch chain and the authentic document table of comparisons according to described bunch of chain number and size, determine that described bunch of chain number and size in starting cluster chain number and the determined space of bunch chain size, match the comspec of authentic document; Number calculate the sector number of starting cluster chain correspondence according to described reserve sector number, FAT table sector number, the every number of clusters in sector and starting cluster chain, calculate the positional information of authentic document according to the sector number of the sector number in the described read operation request, starting cluster chain correspondence.
A kind of creation apparatus of virtual FAT file system, for authentic document is created its corresponding virtual file under the target directory of target partition, this device comprises virtual directory creating unit and virtual file creating unit, wherein, described virtual file creating unit comprises: directory entry is created subelement, be used for the item that under the target directory of target partition, creaties directory, and revise the title of directory entry property file virtual file by name; Bunch chain creation subelement is used for distributing continuous bunch according to the size of authentic document at the FAT of target partition table, constitutes bunch chain of virtual file.
A kind of reading device of virtual FAT file system, read authentic document by the virtual file in the virtual FAT file system, this device comprises: read operation request receiving element, be used to receive the read operation request of virtual file, and comprise sector number and size in this request; Bunch chain determining unit is used for according to described sector number and searches the parameter that described virtual FAT system obtains, and calculates bunch chain number of virtual file; Authentic document path determining unit, be used for searching the virtual file bunch chain and the authentic document table of comparisons that generates in advance according to described bunch of chain number and described size, obtain the comspec and the positional information of authentic document, and, determine the access path information of authentic document according to the size in authentic document comspec and positional information and the described read operation request; The authentic document addressed location is used for according to described access path message reference authentic document.
By some network technologies, for example network storage agreement (ISCSI) can realize that certain or some disk partition of a machine A are mapped as certain subregion of machine B, and the file system of machine A is the complete file system normally, the metadata of include file system, catalogue and file data.The virtual FAT file system (FictFAT32) that the present invention realizes is the metadata and the catalogue of include file system only, and file data storing is in other subregion.FictFAT32 needs very little disk space, just can shine upon the file on the 32G physical disk usually in the space of 16M capacity.Be mapped completely to it in the memory headroom of certain embedded device by procotol, and the memory headroom of embedded device can be visited as the USB memory device by other main frame so long.By scheme provided by the invention, realized on some equipment (for example on the embedded device), visit huge capacity disk space by less memory headroom.
Embodiment
At present to the use of FAT file system, all be the parsing from document cluster chain number to file sectors number, in application, certain the subregion P that requires map machines is to subregion Q, and subregion P and subregion Q adopt the FAT file system.Suppose that subregion Q only comprises FAT32 file system metadata and catalogue, do not comprise concrete file data, but write down the information (file comspec, side-play amount and size) of certain file on other subregions, this moment, subregion P just needed to support sector number to be converted to the operation of document misregistration amount.Because document misregistration and document cluster chain number also are one to one, promptly require on the FAT file system, to realize file sectors number parsing to document cluster chain number.The present invention proposes a file sectors number virtual FAT file system to the reverse visit of file data, and on this file system, only comprise catalogue (being used for constituent act), but the data of include file not, thus, by visiting this virtual FAT file system, can realize reading to data in the large capacity disc space.
The FAT32 file system of standard consists of the following components: DBR, FAT1, FAT2, FDT (catalogue listing) and data field, and the virtual FAT file system based on the FAT32 file system (FictFAT32) of the present invention structure does not comprise that the storage of file True Data, the True Data of file are to leave on other the Physical Extents.
For the ease of understanding the present invention, at first define following term:
Virtual partition (FictPart32): self-defining memory partitioning, only preserve DBR, catalogue listing, FAT1 and part disk space, wherein, so-called part disk space is meant and only is used for the shared disk space of storing directory;
Virtual FAT file system (FictFAT32): the file system that on FictPart32, realizes, the file system correspondence has increased the virtual file bunch chain and the authentic document table of comparisons newly therewith, thereby supports the file read operation;
Virtual file: the file in that virtual FAT file system FictFAT32 preserves, only distribute directory entry and disk allocation bunch chain for it in FictFAT32;
Virtual directory: the catalogue that virtual FAT file system FictFAT32 preserves, in FictFAT32, distribute directory entry, bunch chain and disk space for it.
Referring to Fig. 2, the method flow diagram for the present invention creates virtual FAT file system may further comprise the steps:
S201: the driver of revising FictFAT32 to be created place equipment to the equipment of visit FictFAT32 (for example: Digital Television) registration parameter, the equipment of feasible visit FictFAT32 (for example: Digital Television) see the dummy block will equipment of fixed size, for example 32G one by one;
Above-mentioned S201 step fundamental purpose is that the equipment of " deception " visit FictFAT32 (for example: Digital Television), make this access means think that FictFAT32 place equipment is the memory storage of similar USB.In fact, FictFAT32 place equipment is the computer system with CPU, for example ordinary PC or embedded device etc.
Need to prove that the S201 step is omissible.
S202: this FictFAT32 to be created place equipment of definition initialization according to the FirtFat32 file system becomes the FAT32 form, and, only comprise catalogue in the data field of FAT32 system, and do not comprise file;
Preferably, in formatting procedure, the FAT table number of revised file system boot sector is 1 (address offset 0 * 10), because the FAT2 table is generally used for the recovery of file system data, because FictFAT32 is a read-only file system, so in FictFAT32, dispense the FAT2 table to save disk space.
The process that establishment source file A (authentic document A) corresponding virtual file B is described below is (because source file is arranged in different devices with virtual file, therefore, these two file names can repeat), wherein, suppose that source file A is present under the M catalogue of subregion P, virtual file B is present under the N catalogue of FictFAT32 subregion Q.
S203: create virtual directory;
The FAT32 directory management is identical with ordinary file, and a sub-catalogue file also occupies the directory entry of 32 bytes in the FDT table.Because bibliographic structure need distribute disk space at FictFAT32 subregion Q, therefore, after File Directory Table FDT, for it reserves corresponding bunch of chain space (CS) and corresponding disk space (DS).FictFAT32 is when being the catalogue allocation space:
A, only search idle bunch chain number in the pre-bunch chain space (CS) that keeps, distribute to virtual directory and use;
B, each virtual directory all use different bunches, and the size of supposing each bunch is that (be generally 4K, 8K 16K), stores m virtual directory to nk, then needs the disk space of space m nk.The shared disk space (DD) of virtual directory need be on virtual partition FictPart32 actual allocated.
S204: create virtual file;
A, the item that creaties directory under the N catalogue of FictFAT32 subregion Q are revised directory entry attribute (byte offset 0 * 0 and 0 * 8), and file is called B;
B, according to the size of source file A, in the FAT1 of FictFAT32 subregion Q table for its distribution continuous bunch, constitute bunch chain of this file data correspondence.Number only distribution in document cluster chain space (FS) of bunch chain of file B.Number do not distribute concrete disk sector for bunch chain in document cluster chain space (FS), promptly do not have corresponding disk space.
The read operation of c, modification subregion.During certain sector on reading this subregion, according to the newly-increased virtual file bunch chain and the authentic document table of comparisons (follow-up introduction), the read operation of this file is redirected to the data reading operation of certain file on other subregion according to a tlv triple [authentic document comspec, position, size], other subregion can adopt file system such as FAT32 or NTFS.
As seen, catalogue bunch chain allocation scheme is different with document cluster chain allocation scheme, and the former need distribute actual disk space, and the latter does not need.
The so-called virtual file bunch chain and the authentic document table of comparisons, FictFAT32 generates simultaneously in establishment, comprise: the corresponding relation of virtual file bunch chain number, bunch chain size and authentic document comspec, can match [authentic document comspec] by [virtual file bunch chain number, bunch chain size], can realize visit then authentic document.
Referring to Fig. 3, for virtual FAT file system of the present invention and standard FAT file system contrast synoptic diagram, as seen, compare with standard FAT file system, virtual FAT file system has omitted FAT2, and, FAT1 is divided into two parts, part 1 is used for storage directory, part 2 is used for store file data, in addition, the data field of virtual FAT file system is storing directory only, and does not deposit file.
Thus, the equipment by visit FictFAT32 (for example: Digital Television) to FAT file system standard file access method, can determine the authentic document comspec on virtual partition, thereby realize visiting authentic document by virtual FAT file system.
Referring to Fig. 4, for the present invention reads the method flow diagram of virtual FAT file system, and please in conjunction with read virtual FAT file system synoptic diagram 5 referring to the present invention.
Fig. 4 comprises:
S401: receive the read operation request of virtual file, comprise sector number and size in this request;
S402: search FictFAT32, the DBR by FictFAT32 obtains parameter, utilizes the calculation of parameter of sector number and acquisition to obtain bunch chain number (formula 1 that concrete face is as follows introduced) of virtual file;
For standard FAT32 file system, bunch chain number is as follows to the computing formula of sector:
Sector number=reserve sector number+FAT sector number+(bunch chain number-2) every number of clusters in * sector
Thus, reverse sector number to bunch computing formula be:
Bunch chain number=(sector number-reserve sector number-FAT sector number)/every number of clusters in sector+2........ formula 1
That is, can try to achieve bunch chain number of this sector correspondence by certain sector number.
S403: utilize bunch chain number and bunch chain size to be key word, search the virtual file bunch chain and the authentic document table of comparisons, obtain authentic document comspec and positional information;
Referring to table 1, be an example of the virtual file bunch chain and the authentic document table of comparisons.
Table 1
In the virtual file bunch chain and the authentic document table of comparisons, defined certain virtual cluster chain number pairing file.Because when being file allocation bunch chain, bunch chain is normally continuous, so preferably, adopt two tuples [bunch chain number, bunch chain size] to represent one section bunch of chain of a file, can save the space.This virtual file bunch chain and the authentic document table of comparisons are preserved as the configuration file of FictPart32.For virtual file, its data are kept on other subregion, FictFAT32 only comprises bunch chained list of corresponding document, so, can regularly upgrade the virtual file bunch chain and the authentic document table of comparisons according to the authentic document comspec, take a plurality of discontinuous bunch situations to reduce by a file, this mode can reduce the size of the virtual file bunch chain and the authentic document table of comparisons effectively.
S404: by the size in authentic document comspec, positional information and the read operation, can determine the accessing operation of file, that is, know the routing information of authentic document;
S405: utilize the routing information of authentic document, read the information that is positioned at this authentic document on other subregions.
The present invention will be described with an instantiation below.
Referring to Fig. 6, be the application scenarios synoptic diagram of the embodiment of the invention.
Fig. 6 shows the concrete application scenarios of FictFAT32 provided by the invention.
Among Fig. 6, USB device (USB Dongle) promptly is to realize the equipment of FictFAT32, this equipment has been realized interconnected based between the Digital Television of WIFI and the computing machine, in the Digital Television angle, USB Dongle equipment class is similar to common USB, and in fact, this equipment is the embedded device with CPU.By the USB Gadget driver on the USB device, Digital Television is identified as USB flash disk to the internal memory of USB device, and reads certain authentic document according to the FictFAT32 on the USB flash disk and play.Because the memory size of USB device limited (16Mbytes usually), the size of storage file and quantity are all less, therefore need a kind of mode, make Digital Television can visit a large amount of files.Support that this requirement designs in order to satisfy just to the FictFAT32 of the reverse visit of file data for file sectors number.
Below in conjunction with Fig. 6, introduce Digital Television by the process that FictFAT32 reads authentic document on the computing machine, comprising:
A), Digital Television sends virtual file read operation request to USB Dongle, this read operation request drives by USB Gadget and obtains, and comprises sector number Q, the size N of input in this request;
B), USB Dongle searches FictFAT32, and calculates a bunch chain C according to the sector number Q in information that finds and the read operation request;
Suppose that searching FictFAT32 obtains: the reserve sector number is R (the FAT32 boot sector by FictFAT32 obtains), FAT1 table sector number F (only uses the FAT1 table here, FAT1 by FictFAT32 obtains), the every number of clusters S in sector then calculates a bunch chain C according to formula 1 and is:
Bunch chain C=(input sector number-reserve sector number-FAT shows the sector number)/every number of clusters in sector+2
=(Q-R-F)/S+2
C), search the virtual file bunch chain and the authentic document table of comparisons according to (bunch chain C, size N), check (bunch chain C, size N) whether in (starting cluster chain U, bunch chain size W) determined space, thereby obtain authentic document comspec T;
And,
The sector number Y=reserve sector of starting cluster chain correspondence is counted Q+FAT sector number F*1+ (starting cluster chain
Number U-2) the every number of clusters S in * sector;
Document location P=(the sector number Y of the starting cluster chain correspondence of sector number Q-file) * 512;
Wherein, the unit of document location P is Byte.
D), give network communication unit (the network communication unit has write down host side IP address) (authentic document comspec T, document location P, size N), the network communication unit of network communication unit and computing machine carries out communication.At computer terminal,, utilize the normative document access interface of windows can obtain the data of some authentic documents according to (authentic document comspec T, document location P, size N).Thus, realized the USB Dongle device access jumbo computing machine of Digital Television by low capacity.
In addition, in specific implementation, the present invention also can carry out the synchronous operation of virtual file and authentic document.
Deleted or when revising or removing operation, its result will have influence on virtual file when authentic document.Change in order to monitor these, can in the system at authentic document place, set up monitoring thread.This thread is generally sleep (sleep) state.Operating system adds file system call back function or Hook Function for this reason in addition, is used to wake up monitoring thread.The monitoring thread of authentic document place system passes to USB Dongle to these information further by the network communication unit.After information was received in the network communication unit of USB Dongle side, notice FictFat32 monitoring thread was revised the relevant information of virtual file.
The synchronous operation of virtual file and authentic document specifically comprises following several situation:
1, authentic document is deleted, and then this corresponding virtual file is also deleted.Deletion action comprises: delete the directory entry in the Virtual File System, empty bunch chain of this file; Relevant item in the deletion virtual file bunch chain and the authentic document table of comparisons;
2, the size of authentic document changes.When the size of authentic document changes, the attribute of immediate updating respective virtual file directory item, bunch chained list of file (add new bunch or revise bunch end mark).It is as follows to visit the corresponding FAT list item of certain bunch position formula, and list item skew=reserve sector is counted * 512+ (bunch number-2) * 4.Can revise bunch number by this formula.When file size increases, for new bunch distribution, bunch allocation strategy and the function that still use operating system to carry.When file size reduces, calculate bunch chain length that file directory needs, set FAT32 end-of-file mark (0 * 0FFFFFFF) at new end position.If the length of file does not change, and only is content change, then only upgrade in the virtual file directory item attribute and the part of time correlation.
3, the move operation of authentic document is broken down into the deletion action and the newly-built operation of virtual file of authentic document, and promptly the corresponding virtual file is also deleted, the contrast relationship of the authentic document after rebuliding virtual file then and moving.
Corresponding with the method for above-mentioned establishment virtual FAT file system, the invention provides a kind of creation apparatus of virtual FAT file system, for authentic document is created its corresponding virtual file under the target directory of target partition, referring to Fig. 7, this device comprises virtual directory creating unit 701 and virtual file creating unit 702, wherein, the specific implementation of virtual directory creating unit 701 establishment virtual directories and the process of standard FAT32 system creation catalogue are similar, do not make emphasis herein and describe; Virtual file creating unit 702 comprises directory entry establishment subelement 7021 and bunch chain creation subelement 7022, wherein:
Directory entry is created subelement 7021, is used for the item that creaties directory under the target directory of target partition, and it is by name to property file to revise catalogue;
Bunch chain creation subelement 7022 is used for distributing continuous bunch according to the size of authentic document at the FAT of target partition table, constitutes bunch chain of virtual file.
Corresponding with the above-mentioned method that reads virtual FAT file system, the invention provides a kind of reading device of virtual FAT file system, by reading the virtual file visit authentic document in the virtual FAT file system, referring to Fig. 8, this device comprises:
Read operation request receiving element 801 is used to receive the read operation request of virtual file, comprises sector number and size in this request;
Bunch chain determining unit 802 is used for the sector number of the read operation request that receives according to read operation request receiving element 801 and searches the parameter that described virtual FAT system obtains, and calculates bunch chain number of virtual file;
Authentic document path determining unit 803, be used for bunch chain that obtains according to bunch chain determining unit 802 number, and the size in the read operation request of read operation request receiving element 801 receptions, search the virtual file bunch chain and the authentic document table of comparisons that generate in advance, obtain the comspec and the positional information of authentic document, and, determine the access path information of authentic document according to the size in authentic document comspec and positional information and the read operation request;
Authentic document addressed location 804 is used for the access path information of the authentic document determined according to authentic document path determining unit 803, visit authentic document.
For some specific implementations of above-mentioned two devices, can not give unnecessary details at this referring to method embodiment.
By some network technologies, for example network storage agreement (ISCSI) can realize that certain or some disk partition of a machine A are mapped as certain subregion of machine B, and the file system of machine A is the complete file system normally, the metadata of include file system, catalogue and file data.The virtual FAT file system FictFAT32 that the present invention realizes is the metadata and the catalogue of include file system only, and file data storing is in other subregion.FictFAT32 needs very little disk space, just can shine upon the file on the 32G physical disk usually in the space of 16M capacity.Be mapped completely to it in the memory headroom of certain embedded device by procotol, and the memory headroom of embedded device can be visited as the USB memory device by other main frame so long.By scheme provided by the invention, realized on some equipment (for example on the embedded device), visit huge capacity disk space (for example among Fig. 6, Digital Television is by the USB device access computer) by less memory headroom.
One of ordinary skill in the art will appreciate that, the process of the method for realization the foregoing description can be finished by the relevant hardware of programmed instruction, described program can be stored in the read/write memory medium, and this program is carried out the corresponding step in the said method when carrying out.Described storage medium can be as ROM/RAM, magnetic disc, CD etc.
The above only is a preferred implementation of the present invention; should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the principle of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.