CN111177070A - File allocation method and storage device - Google Patents

File allocation method and storage device Download PDF

Info

Publication number
CN111177070A
CN111177070A CN201911220851.6A CN201911220851A CN111177070A CN 111177070 A CN111177070 A CN 111177070A CN 201911220851 A CN201911220851 A CN 201911220851A CN 111177070 A CN111177070 A CN 111177070A
Authority
CN
China
Prior art keywords
cluster
target file
file
storage device
occupied
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.)
Pending
Application number
CN201911220851.6A
Other languages
Chinese (zh)
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.)
Guizhou Langsheng Technology Co ltd
Original Assignee
Guizhou Langsheng Technology Co ltd
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 Guizhou Langsheng Technology Co ltd filed Critical Guizhou Langsheng Technology Co ltd
Priority to CN201911220851.6A priority Critical patent/CN111177070A/en
Publication of CN111177070A publication Critical patent/CN111177070A/en
Pending legal-status Critical Current

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/11File system administration, e.g. details of archiving or snapshots

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention provides a file allocation method and storage equipment, relates to the field of file systems, and can avoid waste of storage space of the storage equipment. The method comprises the following steps: acquiring an initial cluster number; the starting cluster number is used for indicating a first cluster of the storage device for storing the target file; determining the cluster number occupied by the target file in the storage device according to the initial cluster number and the size of the target file; writing a cluster number occupied by the target file into the FAT, and identifying a first cluster as an end cluster of the target file; the first cluster is the last cluster occupied by the target file in the storage device. The invention is used for distributing files for the storage device.

Description

File allocation method and storage device
Technical Field
The present invention relates to the field of file systems, and in particular, to a file allocation method and a storage device.
Background
In a computer, software in an operating system, which is responsible for managing and storing file information, is referred to as a file management system (or file system), and the operating system manages files on a storage device through the file management system, for example, writes files, reads files, and the like. File Allocation Table (FAT) file systems are often used as file systems for storage devices by different operating systems due to their superior compatibility. Due to the development of storage devices, the capacity of the storage devices increases year by year, and the FAT file system gradually takes a 32-bit file allocation table area as a main stream, which is called FAT32 file system for short.
In the prior art, a file system writes a cluster chain relation of a storage file into a FAT, modifies the number of remaining clusters of a partition in a reserved area to 0 after completing file allocation of the file system, and fills unused clusters in a FAT table. Although the cluster chain relation of the storage files is written in the FAT in the prior art, the read-write efficiency of the disk is improved, the number of the remaining clusters in the partition is modified to 0 after the files are distributed by the file system, and the file system cannot store the files in the storage device any more, so that the space waste of the storage device is caused.
Disclosure of Invention
Embodiments of the present invention provide a file allocation method and a storage device, which can avoid wasting a storage space of the storage device.
In order to achieve the above purpose, the embodiment of the invention adopts the following technical scheme:
in a first aspect, a method for allocating a file by a file system is provided, including: acquiring an initial cluster number; the starting cluster number is used for indicating a first cluster of the storage device for storing the target file; determining the cluster number occupied by the target file in the storage device according to the initial cluster number and the size of the target file; writing a cluster number occupied by the target file into the FAT, and identifying a first cluster as an end cluster of the target file; the first cluster is the last cluster occupied by the target file in the storage device.
In a second aspect, there is provided a file system comprising: the acquisition module is used for acquiring the initial cluster number; the starting cluster number is used for indicating a first cluster of the storage device for storing the target file; the computing module is used for determining the cluster number occupied by the target file in the storage device according to the initial cluster number and the size of the target file acquired by the acquisition module; the distribution module is used for writing the cluster number occupied by the target file determined by the calculation module into the FAT and identifying the first cluster as the ending cluster of the target file; the first cluster is the last cluster occupied by the target file in the storage device.
In a third aspect, a storage device is provided, comprising: a memory, a processor, and a bus; the memory is used for storing computer execution instructions, and the processor is connected with the memory through a bus; when the file system is running, the processor executes computer-executable instructions stored by the memory to cause the storage device to perform the file allocation method as provided by the first aspect.
In a fourth aspect, a computer-readable storage medium is provided, comprising: the computer executes instructions which, when executed on a computer, cause the computer to perform the file allocation method as provided in the first aspect.
The embodiment of the invention provides a file allocation method and storage equipment, wherein the method comprises the following steps: acquiring an initial cluster number; the starting cluster number is used for indicating a first cluster of the storage device for storing the target file; determining the cluster number occupied by the target file in the storage device according to the initial cluster number and the size of the target file; writing a cluster number occupied by the target file into the FAT, and identifying a first cluster as an end cluster of the target file; the first cluster is the last cluster occupied by the target file in the storage device. In the file allocation method provided by the embodiment of the present invention, when the cluster number of the target file is written into the FAT, the last cluster occupied by the target file is identified as the end cluster of the target file. Therefore, after the target file is stored according to the embodiment provided by the invention, the storage device can write the cluster number information occupied by the file into the FAT again, and allocate the file to the storage device through the file system, thereby avoiding the space waste of the storage device.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic structural diagram of a FAT32 file system according to an embodiment of the present invention;
fig. 2 is a first flowchart of a file allocation method according to an embodiment of the present invention;
FIG. 3 is a block diagram of a boot sector according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating a data structure of an information sector according to an embodiment of the present invention;
fig. 5 is a second flowchart illustrating a file allocation method according to an embodiment of the present invention;
fig. 6 is a first diagram illustrating a data structure of a FAT according to an embodiment of the present invention;
fig. 7 is a second schematic diagram of a data structure of a FAT according to an embodiment of the present invention;
fig. 8 is a third schematic diagram of a data structure of a FAT provided in the embodiment of the present invention;
fig. 9 is a third schematic flowchart of a file allocation method according to an embodiment of the present invention;
FIG. 10 is a diagram illustrating a data structure of a directory entry according to an embodiment of the present invention;
fig. 11 is a fourth schematic flowchart of a file allocation method according to an embodiment of the present invention;
FIG. 12 is a first schematic structural diagram of a memory device according to an embodiment of the present invention;
fig. 13 is a second schematic structural diagram of a storage device according to an embodiment of the present invention;
fig. 14 is a schematic structural diagram of a storage device according to an embodiment of the present invention;
fig. 15 is a schematic structural diagram of a storage device according to a fourth embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that, in the embodiments of the present invention, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "e.g.," an embodiment of the present invention is not necessarily to be construed as preferred or advantageous over other embodiments or designs. Rather, use of the word "exemplary" or "such as" is intended to present concepts related in a concrete fashion.
It should be noted that, in the embodiments of the present invention, "of", "corresponding" and "corresponding" may be sometimes used in combination, and it should be noted that, when the difference is not emphasized, the intended meaning is consistent.
For the convenience of clearly describing the technical solutions of the embodiments of the present invention, in the embodiments of the present invention, the words "first", "second", and the like are used for distinguishing the same items or similar items with basically the same functions and actions, and those skilled in the art can understand that the words "first", "second", and the like are not limited in number or execution order.
Software in the operating system that is responsible for managing and storing file information is called a file management system, referred to as a file system for short. Among them, the FAT file system is often used as a file system of a storage device because of its excellent compatibility, and as the capacity of the storage device increases year by year, the FAT32 file system gradually develops into the mainstream of the FAT file system. When the storage space of the storage device is managed using the FAT file system, the storage space of the storage device includes a plurality of clusters. Wherein one cluster may include a plurality of sectors.
It should be noted that the storage device according to the embodiment of the present invention may be a phase change rewritable optical disk drive (PD drive), a read-only optical disk (CD-ROM), a magnetic disk storage medium or other magnetic storage devices, an electrically erasable programmable read-only memory (EEPROM), a removable hard disk, a U disk, a TF card, and the like.
As shown in fig. 1, the FAT32 file system includes a boot sector, an information sector, a reserved sector, a FAT area, and a data area. The boot sector is used for storing attribute information of the storage device, such as byte number of each sector, sector number of each cluster, reserved sector number, FAT number, total sector number, sector number occupied by each FAT and initial cluster number of a root directory;
the information sector is used for storing the number of available clusters and the initial cluster number of the storage device;
the reserved sector is a sector reserved in the storage device, and data can be stored in the reserved sector according to actual storage requirements;
the FAT area is used for storing FATs, and the FATs are used for indicating storage addresses of stored files in the storage equipment so as to be convenient for reading the stored files; the FAT area includes FAT1 and FAT2, FAT2 being a backup of FAT 1.
Specifically, the data structure of the FAT32 file system is shown in table 1 below:
TABLE 1
Figure BDA0002300802300000041
Offset addresses 0x0E to 0x0F and 0x24 to 0x27 in table 1 above are offset addresses in the boot sector, and information stored in a storage space of offset addresses such as 0x0E to 0x0F in the boot sector may indicate the number of sectors occupied by the reserved sector; the information stored in the storage space of offset addresses such as 0x 24-0 x27 in the boot sector may indicate the number of sectors occupied by each FAT.
An embodiment of the present invention provides a method for allocating files in a file system, which is applicable to a FAT32 file system, and as shown in fig. 2, the method includes the following steps:
s101, acquiring an initial cluster number.
Wherein the start cluster number is used to indicate the first cluster in the storage device to store the target file.
Specifically, when the storage device is connected to the computer, a device file mapped in the driver by the storage device can be opened through the 16-ary editor, and the boot sector information and the information sector information of the storage device can be obtained from the device file. The information sector information comprises the number of usable clusters and the initial cluster number of the storage device.
For example, the 16-system Editor may be a tool of a Bless Hex Editor, taking a Linux operating system as an example. The above steps may be implemented by obtaining boot sector information and information sector information in a device file through a Bless Hex Editor tool, where the boot sector information and the information sector information obtained through the Bless Hex Editor tool include, for example, a TF Card (Trans flash Card) with a storage device of 16G:
the number of bytes per sector is 512, the number of sectors per cluster is 32,
total number of sectors 30425088, total number of clusters 9050784,
each cluster is 16KB in size, the number of reserved sectors is 6,
the number of bytes of FAT occupied by each cluster is 4.
Fig. 3 is one possible implementation of the boot sector information and fig. 4 is one possible implementation of the information sector information. Referring to FIG. 3, 3 bytes occupied by offset addresses 0x 00-0 x02 are jump instructions; the 2Bytes occupied by the offset addresses 0x 0B-0 x0C are the number of Bytes of each sector, where 0x0200 denotes the size of each sector is 512 Bytes; the offset address 0x0D occupies bytes, which is the number of sectors per cluster, where 0x20 indicates that each cluster includes 32 sectors; 2bytes occupied by offset addresses 0x 0E-0 x0F are reserved sectors, where 0x0006 denotes that the number of reserved sectors is 6; the byte occupied by the offset address 0x10 is the number of FAT, where 0x02 indicates that the file system includes 2 FAT; the offset addresses 0x 20-0 x23 occupy 4bytes as the total number of sectors, where 0x00E83800 represents 30425088 as the total number of sectors.
Referring to fig. 4, 4bytes occupied by offset addresses 0x3E 8-0 x3EB are the number of available clusters of the storage device, where 0x008a0460 indicates that the number of available clusters is 9045088; the 4bytes occupied by the offset addresses 0x3 EC-0 x3EF are the starting cluster number of the storage target file, where 0x00000003 indicates that the starting cluster number of the cluster occupied by the target file is 3.
It should be noted that fig. 3 and fig. 4 only show partial contents of the guide sector and the information sector, and the above contents are only described for partial byte contents of the guide sector and the information sector, which are only exemplary, and those skilled in the art can clearly understand the meaning of information representation included in different bytes in the guide sector and the information sector according to the technical means commonly used in the art.
S102, determining the cluster number occupied by the target file in the storage device according to the initial cluster number and the size of the target file.
Specifically, when the storage device stores the target file, it needs to determine whether the available storage space of the storage device satisfies the storage of the target file.
For example, if the target file is 256M, the number of clusters occupied by the target file is: (256 × 1024)/16 ═ 16384, that is, the target file needs to occupy 16384 clusters. At this time, if the number of available clusters obtained according to the information sector information is less than 16384, the available storage space of the storage device is smaller than the size of the target file and cannot be used for storing the target file; if the number of available clusters obtained from the information sector information is 16384 or more, the storage device may be used to store the target file.
If the available storage space of the storage device meets the storage requirement of the target file, the number of clusters occupied by the target file is 16384, and the initial cluster number obtained according to the information sector information is 3, the cluster number of the last cluster occupied by the target file is 3+16384 ═ 16387, that is, the cluster number of the cluster occupied by the target file is 3-16387.
S103, writing the cluster number occupied by the target file into the FAT, and identifying the first cluster as the ending cluster of the target file.
The first cluster is the last cluster occupied by the target file in the storage device.
Illustratively, if the cluster number of the cluster occupied by the target file is 3-16387, the cluster number of the cluster occupied by the target file is written into the FAT, and the first cluster is the 16387 cluster. The details are shown in table 2 below:
TABLE 2
Figure BDA0002300802300000071
The cluster 0 and the cluster 1 are reserved clusters, do not participate in the storage of file data, and can be used for storing boot sector information and information sector information of a file system; cluster 2 is used to store the root directory, and in fact cluster 2 is also part of the data area. Referring to table 2, the target file is stored starting from cluster No. 3, and the next cluster No. of cluster No. 3 is identified as 0x00000004, indicating that the next cluster occupied by the target file is cluster No. 4; the next cluster number identification of cluster No. 4 is 0x00000005, which indicates that the next cluster occupied by the target file is cluster No. 5; the next cluster number identification of cluster No. 5 is 0x00000006, indicating that the next cluster occupied by the target file is cluster No. 6; by analogy, the cluster number next to each cluster number can be identified to indicate the cluster number of the next cluster occupied by the target file, so as to facilitate the rapid reading and writing of the target file. Of course, since the cluster numbers of the clusters occupied by the target file are 3-16387, the next cluster number of 16387 is identified herein as 0xFFFFFF0F, and 0xFFFFFF0F is an end flag bit to indicate that the storage of the target file is complete. The description in table 2 above is for indicating the role of the cluster of the corresponding cluster number, e.g., cluster number 2 is for storing the root directory data of the target file, and cluster number 3 is for storing the data of the target file.
It should be noted that, in the above example, the clusters occupied by the target file are continuous, and in practice, the clusters occupied by the target file may also be discontinuous, such as occupying cluster numbers 3 to 7 and 9 to 16388, where the next cluster number of cluster number 7 is identified as 0x00000009, and is used to indicate that the target file occupies cluster number 9 after cluster number 7, but does not occupy cluster number 8.
Optionally, as shown in fig. 5, step S103 may specifically include the following steps:
and S1031, determining the initial byte of the cluster chain information in the FAT according to the initial cluster number.
Specifically, the starting cluster number of the storage target file is determined according to the boot sector information of the file system obtained in step S101, and since each 4Bytes in the FAT indicates a cluster number, after the starting cluster number of the target file is determined, the starting byte of the cluster chain information of the target file in the FAT can be determined according to the starting cluster number × 4.
For example, as shown in fig. 6, if the starting cluster number is 3, the starting byte of the cluster chain information of the target file in the FAT is 3 × 4 — 12, where the starting byte is specifically 0x 0C-0 x 0F.
S1032 writes the cluster chain information into the FAT sequentially from the start byte.
Specifically, according to the determined starting byte of the cluster chain information of the target file in the FAT, the cluster chain information of the target file is written into the corresponding offset address.
For example, fig. 7 is a possible implementation of the FAT, the cluster chain information of the cluster occupied by the target file may be written into the corresponding byte as shown in fig. 7, and for example, the table entry 0 is 0x0FFFFFF8, which is the starting fixed identifier of the FAT; the number 1 table entry is 0x0FFFFFFF which is a default value and is not used in the FAT; the number 2 table entry is a corresponding number 2 cluster and is a root directory; the item of table No. 3 corresponds to the cluster No. 3, where the value of the item of table No. 3 is 0x00000004, which indicates that the next cluster occupied by the target file is cluster No. 4; the item of table No. 4 corresponds to the item of cluster No. 4, where the value of the item of table No. 4 is 0x00000005, which indicates that the next cluster occupied by the target file is the cluster No. 5; the entry of table 5 corresponds to cluster 5, where the value of entry 5 is 0x00000006, which indicates that the next cluster occupied by the target file is cluster 6; by analogy, the entry No. 16386 corresponds to the entry No. 16386 cluster, where the value of the entry No. 16386 is 0x00004003, which indicates that the next cluster occupied by the target file is the 16387 cluster.
S1033, modifying a first byte corresponding to the first cluster in the FAT into an end bit identifier.
Wherein the first byte is used to indicate a cluster next to the first cluster.
Illustratively, as shown in fig. 8, the entry No. 16386 corresponds to the cluster No. 16386, where the value of the entry No. 16386 is 0x00004003, which indicates that the next cluster occupied by the target file is the cluster No. 16387; entry number 16387 corresponds to cluster number 16387, where the value of entry number 16387 is modified to 0x0FFFFFFF, indicating that the storage of the target file is finished.
According to the embodiment provided by the invention, the file system can realize the distribution of the target file, identify the cluster occupied by the target file, facilitate the quick reading and writing of the target file and the storage of the next file, and simultaneously avoid the space waste of the storage equipment.
Optionally, as shown in fig. 9, after step S102, the method further includes:
s201, establishing a heap memory, wherein cluster chain information of the target file is stored in the heap memory.
The cluster chain information is used for indicating the cluster occupied by the target file.
For example, as can be seen from the above embodiments, when the target file is 256M, since the number of clusters occupied by the target file is 16384, and each cluster occupies 4Bytes in the FAT, the created heap memory is 16384 × 4 ═ 65536Bytes ═ 64 KB; the cluster chain shown in table 2 above is generated in the created heap memory.
It should be noted that the cluster number occupied by the target file written in the FAT in step S103 may be cluster chain information generated in the heap memory. The cluster chain information occupied by the target file is generated in the heap memory in advance, and when the occupied clusters are distributed to the target file in the FAT, the cluster chain information in the heap memory is directly called, so that the distribution of the clusters occupied by the target file can be quickly completed, and the distribution speed of the target file in a file system is improved.
S202, creating a directory entry field of the target file according to the long filename format.
Specifically, directory entry fields of the target file are created according to the long filename format, and each directory entry field includes information such as the filename, the starting cluster number, and the file creation time of the target file. Each directory entry field occupies 32Bytes or (32 × P) Bytes, characters in the long filename are coded by unicode, and P is a positive integer.
For example, if the file name of the target file is amp3foryatoumadabefgd20090808summer. txt, the directory entry field of the target file created according to the long file name is as shown in fig. 10. Since the file name of the target file has 39 characters in total, a single long filename directory entry field cannot completely represent the file name of the target file, and thus the directory entry field of the target file is divided into 3 long filename directory entry fields.
Wherein, 10 bytes occupied by the offset address 0x 01-0 x0A of the long filename directory entry field are the first 5 characters of the long filename; the offset address 0x0B is a mark of a long filename directory entry field, and is fixed to 0x 0F; the offset address 0x0D is a checksum of the long directory entry field, and if the long filename of the target file requires storage of multiple long filename directory entry fields, the checksums of these long filename directory entry fields are the same, as shown in fig. 10, where the offset address 0x0D, the offset address 0x2D, and the offset address 0x4D are all 0x8B, which indicates that these three directory entry fields are the long filename directory entry fields of the same target file.
01 at offset address 0x40 bytes of the long filename directory entry field represents the first long filename directory entry field of the target file, 02 at offset address 0x20 bytes represents the second long filename directory entry field of the target file, and 43 at offset address 0x00 bytes represents the third long filename directory entry field of the target file. The field information of offset addresses 0x 41-0 x4A bytes represents amp3f, which is the first 5 characters of the target file name; the field information of offset addresses 0x 4E-0 x59 bytes indicates oryto; the field information of offset addresses 0x 5C-0 x5F bytes indicates um, that is, the first long filename directory entry field of the target file stores the filename information of amp3 foryatoum. The corresponding address of the second long filename directory entry field of the same target file stores the filename information of adebyfgd20090, and the corresponding address of the third long filename directory entry field of the target file stores the filename information of 808 sum.
After the file system generates the long filename directory entry field, it also generates a short filename directory entry field corresponding to the long filename directory entry field, i.e., the directory entry field with offset addresses 0x 60-0 x7F shown in FIG. 10, where the field information of the offset addresses 0x 60-0 x67 bytes represents AMP3 FO-1, and the field information of the offset addresses 0x 68-0 x6A bytes represents TXT.
It should be noted that after the long filename directory entry field is created, the file system generates a short filename directory entry field corresponding to the long filename directory entry field, and when the file system queries the target file, the file system queries according to the short filename directory entry field. As with the generation of cluster chain information, the file system may create another heap memory for generating directory entry fields for the target file, i.e., the directory entry fields in the above steps are generated in the heap memory. The heap memory storing cluster chain information is different from the heap memory storing directory entry fields.
In the embodiment of the invention, the cluster chain information and the directory entry field of the target file are generated by using the heap memory, so that the occupation of the memory of the file system when the file is distributed is reduced, and the file system can support more storage processes.
S203, determining the offset of the directory entry field according to the anti-coverage algorithm, and writing the directory entry field into the second cluster according to the offset.
Wherein the second cluster is used for storing the directory entry field of the target file.
Specifically, if the storage device already stores file data, a directory entry of a file has been written in a root directory of the file system, so that an occupied byte in the root directory can be detected according to an anti-overwrite algorithm, and after the occupied byte is determined, directory entry information of a target file is written after the occupied byte, so that when the directory entry of the target file is written into the file system, the directory entry information of the target file overwrites the existing directory entry information, thereby destroying the existing directory entry and causing a read-write error of the stored file.
For example, as shown in FIG. 10, 0x 00-0 x7F of the root directory is occupied, so that the starting storage address of the directory entry of the target file can be detected to be 0x80 according to the anti-overwrite algorithm.
In a possible implementation manner, the method for allocating a file by a file system according to an embodiment of the present invention further includes: and determining whether the file name of the target file directory entry is renamed according to a renaming prevention algorithm, and modifying the file name of the target file if the file name of the target file is renamed.
Illustratively, if the file name of the target file is text and directory entry information with the file name of text is already stored in the root directory, the file name of the directory entry of the target file may be modified to be text 1; if the file name text1 still exists, modifying the file name in the directory entry of the target file to be text 2; by analogy, when the file name of the target file already exists in the root directory, the target file is distinguished from the stored file by adding characters after the file name of the target file.
Optionally, as shown in fig. 11, after step S103, the method further includes:
and S204, updating the initial cluster number to the cluster number of the next cluster of the first cluster.
Specifically, after the target file is allocated by the file system, the initial cluster number and the available cluster number in the file system are modified, the initial cluster number is modified into the cluster number of the next cluster of the first cluster, and the available cluster number is modified into the difference value between the available cluster number and the cluster number occupied by the target file. The updated initial cluster number is used for indicating the first cluster when the storage device stores the next file, and the updated available cluster number is used for indicating the remaining storage space after the storage device stores the target file.
For example, if the cluster number of the cluster occupied by the target file is 3-16387, the starting cluster number may be modified to 16388; if the number of available clusters is 9045088 and the number of clusters occupied by the target file is 16384, the number of available clusters may be modified to 9028704.
It should be noted that the file system in the embodiment of the present invention refers to a FAT32 file system, and the file system includes two configuration tables of FAT1 and FAT2, where FAT2 is a backup of FAT1 and is used to ensure that the file system can normally operate when FAT1 is damaged.
The embodiment of the invention provides a file allocation method, which comprises the following steps: acquiring an initial cluster number; the starting cluster number is used for indicating a first cluster of the storage device for storing the target file; determining the cluster number occupied by the target file in the storage device according to the initial cluster number and the size of the target file; writing a cluster number occupied by the target file into the FAT, and identifying a first cluster as an end cluster of the target file; the first cluster is the last cluster occupied by the target file in the storage device. In the file allocation method provided by the embodiment of the present invention, when the cluster number of the target file is written into the FAT, the last cluster occupied by the target file is identified as the end cluster of the target file. Therefore, after the target file is stored according to the embodiment provided by the invention, the storage device can write the cluster number information occupied by the file into the FAT again, and allocate the file to the storage device through the file system, thereby avoiding the space waste of the storage device.
As shown in fig. 12, an embodiment of the present invention further provides a storage device 30, including:
an obtaining module 301, configured to obtain a starting cluster number; the start cluster number is used to indicate the first cluster in the storage device that stores the target file.
A calculating module 302, configured to determine, according to the starting cluster number and the size of the target file obtained by the obtaining module 301, a cluster number occupied by the target file in the storage device.
The allocating module 303 is configured to write the cluster number occupied by the target file determined by the calculating module 302 into the FAT, and identify the first cluster as an end cluster of the target file; the first cluster is the last cluster occupied by the target file in the storage device.
Further, the allocating module 303 is specifically configured to: modifying a first byte corresponding to a first cluster in the FAT into an end bit identifier; the first byte is used to indicate the next cluster of the first cluster.
Optionally, as shown in fig. 13, the storage device 30 further includes a memory creation module 304 and a directory entry creation module 305.
A memory creating module 304, configured to create a heap memory according to the number of clusters occupied by the target file determined by the calculating module 302, and generate a cluster chain of the target file in the heap memory; the cluster chain is used for indicating the cluster occupied by the target file.
A directory entry creation module 305 for creating a directory entry field of the target file according to the long filename format; determining the offset of the directory entry field according to an anti-coverage algorithm, and writing the directory entry field into a second cluster according to the offset; the second cluster is for storing directory entry fields of the target file.
Further, the allocating module 303 is further specifically configured to: determining the initial byte of cluster chain information in the FAT according to the initial cluster number; the cluster chain information is sequentially written into the FAT from the start byte.
Optionally, as shown in fig. 14, the storage device 30 further includes an update module 306.
An updating module 306, configured to update the starting cluster number to a cluster number of a cluster next to the first cluster.
The storage device provided by the embodiment of the invention comprises: the acquisition module is used for acquiring the initial cluster number; the starting cluster number is used for indicating a first cluster of the storage device for storing the target file; the computing module is used for determining the cluster number occupied by the target file in the storage device according to the initial cluster number and the size of the target file acquired by the acquisition module; the distribution module is used for writing the cluster number occupied by the target file determined by the calculation module into the FAT and identifying the first cluster as the ending cluster of the target file; the first cluster is the last cluster occupied by the target file in the storage device. In the storage device provided in the embodiment of the present invention, when the cluster number of the target file is written into the FAT, the last cluster occupied by the target file is identified as the end cluster of the target file. Therefore, after the target file is stored according to the embodiment provided by the invention, the storage device can write the cluster number information occupied by the file into the FAT again, and allocate the file to the storage device through the file system, thereby avoiding the space waste of the storage device.
As shown in fig. 15, an embodiment of the present invention also provides a storage device including a memory 41, a processor 42, and a bus 43; the memory 41 is used for storing computer execution instructions, and the processor 42 is connected with the memory 41 through a bus 43; when the file system is running, the processor 42 executes computer-executable instructions stored by the memory 41 to cause the file system to perform the method for allocating files by the file system as provided in the above embodiments.
In particular implementations, processor 42(42-1 and 42-2) may include one or more CPUs, such as CPU0 and CPU1 shown in FIG. 15, for example, as one embodiment. And as an example, the file system may include multiple processors 42, such as processor 42-1 and processor 42-2 shown in fig. 15. Each of the processors 42 may be a single-Core Processor (CPU) or a multi-Core Processor (CPU). Processor 42 may refer herein to one or more devices, circuits, and/or processing cores that process data (e.g., computer program instructions).
The memory 41 may be, but is not limited to, a read-only memory 41 (ROM) or other type of static storage device that can store static information and instructions, a Random Access Memory (RAM) or other type of dynamic storage device that can store information and instructions, an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compact disc, laser disc, optical disc, digital versatile disc, blu-ray disc, etc.), a magnetic disc storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer. The memory 41 may be self-contained and coupled to the processor 42 via a bus 43. The memory 41 may also be integrated with the processor 42.
In a specific implementation, the memory 41 is used for storing data in the present application and computer-executable instructions corresponding to software programs for executing the present application. The processor 42 may perform various functions of the file system by running or executing software programs stored in the memory 41, and calling data stored in the memory 41.
The bus 43 may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended ISA (EISA) bus, or the like. The bus 43 may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 15, but this is not intended to represent only one bus or type of bus.
An embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium includes computer-executable instructions, and when the computer-executable instructions run on a computer, the computer is enabled to execute the file allocation method provided in the foregoing embodiment.
The embodiment of the present invention further provides a computer program, where the computer program may be directly loaded into a memory and contains a software code, and the computer program is loaded and executed by a computer to implement the file allocation method provided in the above embodiment.
Those skilled in the art will recognize that, in one or more of the examples described above, the functions described in this invention may be implemented in hardware, software, firmware, or any combination thereof. When implemented in software, the functions may be stored on or transmitted over as one or more instructions or code on a computer-readable medium. Computer-readable media includes both computer storage media and communication media including any medium that facilitates transfer of a computer program from one place to another. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.
Through the above description of the embodiments, it is clear to those skilled in the art that, for convenience and simplicity of description, the foregoing division of the functional modules is merely used as an example, and in practical applications, the above function distribution may be completed by different functional modules according to needs, that is, the internal structure of the device may be divided into different functional modules to complete all or part of the above described functions.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules or units is only one logical function division, and there may be other division ways in actual implementation. For example, various elements or components may be combined or may be integrated into another device, or some features may be omitted, or not implemented. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form. Units described as separate parts may or may not be physically separate, and parts displayed as units may be one physical unit or a plurality of physical units, may be located in one place, or may be distributed to a plurality of different places. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit. The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application may be essentially or partially contributed to by the prior art, or all or part of the technical solutions may be embodied in the form of a software product, where the software product is stored in a storage medium and includes several instructions to enable a device (which may be a single chip, a chip, or the like) or a processor (processor) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a U disk, a removable hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. A method for file allocation, comprising:
acquiring an initial cluster number; the starting cluster number is used for indicating a first cluster of a storage device for storing a target file;
determining the cluster number occupied by the target file in the storage device according to the starting cluster number and the size of the target file;
writing the cluster number occupied by the target file into a file configuration table (FAT), and identifying a first cluster as an ending cluster of the target file; the first cluster is the last cluster occupied by the target file in the storage device.
2. The file allocation method according to claim 1, wherein said identifying the first cluster as an ending cluster of the target file comprises:
modifying a first byte corresponding to the first cluster in the FAT into an end bit identifier; the first byte is used to indicate a cluster next to the first cluster.
3. The file allocation method according to claim 1, further comprising:
establishing a heap memory, wherein the heap memory stores cluster chain information of the target file; the cluster chain information is used for indicating the cluster occupied by the target file.
4. The file allocation method according to claim 3, further comprising:
creating a directory entry field of the target file according to the long filename format;
determining the offset of the directory entry field according to an anti-coverage algorithm, and writing the directory entry field into a second cluster according to the offset; the second cluster is used for storing a directory entry field of the target file.
5. The method of claim 1, wherein the writing the cluster number occupied by the target file into the FAT specifically comprises:
determining the initial byte of cluster chain information in the FAT according to the initial cluster number;
and sequentially writing the cluster chain information into the FAT from the starting byte.
6. The method according to claim 1, wherein after writing the cluster number of the cluster occupied by the target file into the FAT, the method further comprises:
and updating the starting cluster number to the cluster number of the next cluster of the first cluster.
7. A storage device, comprising:
the acquisition module is used for acquiring the initial cluster number; the starting cluster number is used for indicating a first cluster of a storage device for storing a target file;
a calculating module, configured to determine, according to the starting cluster number and the size of the target file obtained by the obtaining module, a cluster number occupied by the target file in the storage device;
the distribution module is used for writing the cluster number occupied by the target file determined by the calculation module into the FAT and identifying a first cluster as an end cluster of the target file; the first cluster is the last cluster occupied by the target file in the storage device.
8. The storage device of claim 7, wherein the allocation module is specifically configured to:
modifying a first byte corresponding to the first cluster in the FAT into an end bit identifier; the first byte is used to indicate a cluster next to the first cluster.
9. A memory device comprising a memory, a processor, and a bus; the memory is used for storing computer execution instructions, and the processor is connected with the memory through the bus; the computer executable instructions stored by the memory are executed by the processor when the file system is running to cause the file system to perform the file allocation method of any of claims 1-6.
10. A computer-readable storage medium comprising computer-executable instructions that, when executed on a computer, cause the computer to perform the file allocation method of any of claims 1-6.
CN201911220851.6A 2019-12-03 2019-12-03 File allocation method and storage device Pending CN111177070A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911220851.6A CN111177070A (en) 2019-12-03 2019-12-03 File allocation method and storage device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911220851.6A CN111177070A (en) 2019-12-03 2019-12-03 File allocation method and storage device

Publications (1)

Publication Number Publication Date
CN111177070A true CN111177070A (en) 2020-05-19

Family

ID=70624496

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911220851.6A Pending CN111177070A (en) 2019-12-03 2019-12-03 File allocation method and storage device

Country Status (1)

Country Link
CN (1) CN111177070A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112286871A (en) * 2020-12-31 2021-01-29 湖南源科创新科技有限公司 Cluster distribution method and system for multi-host FAT file system
CN112306975A (en) * 2020-11-06 2021-02-02 山东云海国创云计算装备产业创新中心有限公司 File storage method, device, equipment and computer readable storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003280951A (en) * 2002-03-20 2003-10-03 Ricoh Co Ltd File management program and recording medium
CN101286177A (en) * 2008-05-30 2008-10-15 中兴通讯股份有限公司 Method and device for allocating space to file in file allocation table
JP2009266026A (en) * 2008-04-25 2009-11-12 Sharp Corp Data processor, storage device and computer program
CN102841894A (en) * 2011-06-22 2012-12-26 比亚迪股份有限公司 Data storage method of file allocation table
CN107992763A (en) * 2017-11-06 2018-05-04 北京东土科技股份有限公司 The power-off protection method and device of a kind of file system
CN110286859A (en) * 2019-06-28 2019-09-27 中国海洋大学 Date storage method and device based on FAT file system

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003280951A (en) * 2002-03-20 2003-10-03 Ricoh Co Ltd File management program and recording medium
JP2009266026A (en) * 2008-04-25 2009-11-12 Sharp Corp Data processor, storage device and computer program
CN101286177A (en) * 2008-05-30 2008-10-15 中兴通讯股份有限公司 Method and device for allocating space to file in file allocation table
CN102841894A (en) * 2011-06-22 2012-12-26 比亚迪股份有限公司 Data storage method of file allocation table
CN107992763A (en) * 2017-11-06 2018-05-04 北京东土科技股份有限公司 The power-off protection method and device of a kind of file system
CN110286859A (en) * 2019-06-28 2019-09-27 中国海洋大学 Date storage method and device based on FAT file system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112306975A (en) * 2020-11-06 2021-02-02 山东云海国创云计算装备产业创新中心有限公司 File storage method, device, equipment and computer readable storage medium
CN112286871A (en) * 2020-12-31 2021-01-29 湖南源科创新科技有限公司 Cluster distribution method and system for multi-host FAT file system

Similar Documents

Publication Publication Date Title
US10983955B2 (en) Data unit cloning in memory-based file systems
KR101157171B1 (en) A storage system for a smart card and a method of managing file creation in the storage system
US7853772B2 (en) Method for managing partitions in a storage device
US9069468B2 (en) Pooled partition layout and representation
CN102103567B (en) multiple versions of the data of virtual memory shared among isomerous processors
CN105830022B (en) The method and apparatus for accessing file
CN100578505C (en) Apparatus for file system management
US20100070544A1 (en) Virtual block-level storage over a file system
US9563446B2 (en) Binary file generation
CN105739961B (en) Starting method and device of embedded system
CN108628541B (en) File storage method, device and storage system
CN111177070A (en) File allocation method and storage device
JP2014206884A (en) Information processor, information processing method, and program
US10372684B2 (en) Metadata peering with improved inodes
US10198352B2 (en) Efficient pointer swizzling for persistent objects
US20170277632A1 (en) Virtual computer system control method and virtual computer system
CN106709014B (en) File system conversion method and device
CN109766057B (en) Firmware data processing method and system
US9792042B2 (en) Systems and methods for set membership matching
US20200117722A1 (en) Efficient file storage and retrieval system, method and apparatus
CN116483740B (en) Memory data migration method and device, storage medium and electronic device
US20230289207A1 (en) Techniques for Concurrently Supporting Virtual NUMA and CPU/Memory Hot-Add in a Virtual Machine
US7539832B2 (en) Option ROM code acquisition
CN112181910B (en) Extended short file name generation method, file access method and device
US11372792B1 (en) Automatic bus resource adjustment in a multiple root bridge computing 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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20200519