File reading method, system and intelligent terminal based on embedded file structure
By combining metadata blocks and hash structures in the embedded file system, file information can be quickly obtained, solving the problem of slow reading speed in existing technologies and achieving efficient file reading.
Patent Information
- Application Number
- CN202310970570.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-02
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2043-08-02
AI Technical Summary
In existing technologies, embedded file systems need to traverse the entire metadata to find the best match when reading files, resulting in slow reading speeds.
By obtaining the first file information from the metadata block and quickly obtaining the second file information using the hash structure, the file location can be directly located, avoiding traversing the entire hash structure and metadata block.
It enables fast reading of embedded files, reducing reading time and improving file reading speed.
Smart Images

Figure CN116932469B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of file reading, and in particular to a file reading method, system, smart terminal, and computer-readable storage medium based on an embedded file structure. Background Technology
[0002] In the embedded systems field, there are many mature file systems for Flash (Macromedia Flash, 2D animation software). Currently, common file systems can be categorized as follows: COW (Copy-on-write) file systems, represented by btrfs (Butter FS) and ZFS (Zettabyte File System); journaling-based file systems, represented by JFFS (Journaling Flash File System); and journaling + COW file systems, represented by LittleFS (Little File System).
[0003] Each of the three types of file systems has its own advantages and disadvantages: the COW file system has good performance but consumes a lot of resources, making it unsuitable for embedded systems; the journaling file system supports power loss protection and wear leveling, but its performance is poor; while the journaling+COW file system combines the ideas of the first two types, supporting both power loss protection and wear leveling, and consuming fewer resources, but its performance is relatively average. When opening a file using the journaling+COW file system, the file ID stored in the metadata is traversed and matched based on the file path to be read. Even if a match is found, it is only temporarily stored in the best match result. The best match result is only returned after traversing the entire metadata, which results in slow reading speed and affects file reading speed.
[0004] Therefore, existing technologies still need to be improved and developed. Summary of the Invention
[0005] The main purpose of this application is to provide a file reading method, system, smart terminal, and computer-readable storage medium based on an embedded file structure. It aims to solve the problem that in the prior art, when reading embedded files, the matching result is only temporarily stored in the best matching result, and the current best matching result is only returned after traversing all the metadata, which leads to slow reading and affects the file reading speed.
[0006] The first aspect of this application provides a file reading method based on an embedded file structure, comprising the following steps: obtaining a metadata block, obtaining first file information of an embedded file to be read based on the metadata block; obtaining a hash structure, obtaining second file information from the information in the hash structure based on the first file information, wherein the hash structure is a data storage structure of the embedded file, and the second file information is a piece of information in the hash structure; extracting the position information corresponding to the second file information according to a preset storage relationship, and reading the information of the embedded file to be read based on the position information.
[0007] Based on the above technical means, the embodiments of this application can obtain the first file information of the embedded file to be read through the metadata block, and then obtain the second file information from the numerous information in the hash structure based on the first file information. Based on the second file information, the location of the embedded file to be read can be found, and then the information of the embedded file to be read can be read. Thus, when reading the embedded file, it is not necessary to traverse the entire hash structure and metadata block. After obtaining the first file information, the second file information is obtained. Correspondingly, once the corresponding second file information is obtained through the hash structure, the extraction of information in the hash structure ends, so that the embedded file to be read can be read quickly.
[0008] Optionally, in one embodiment of this application, the step of obtaining the metadata block and obtaining the first file information of the embedded file to be read based on the metadata block further includes: storing the open paths and file tag information of all embedded files in the metadata block, wherein the first file information of each embedded file is obtained from the corresponding file tag information; and storing the first file information of each embedded file, the second file information corresponding to the first file information of each embedded file, and the position information corresponding to the second file information in the hash structure.
[0009] Based on the above technical means, this application embodiment can store the embedded files according to the method to be read before reading them, storing the opening paths and file tag information of all embedded files in the metadata block. This allows the file tag information stored in the metadata block to be obtained based on the opening path of the embedded file when reading the embedded file, and then the first file information to be obtained from the file tag information. Furthermore, this application embodiment stores the first file information, second file information, and location information of each embedded file in a hash mechanism, so that the information of the embedded file to be read can be easily and quickly obtained based on the correspondence when reading the embedded file.
[0010] Optionally, in one embodiment of this application, the file reading method based on the embedded file structure further includes: obtaining the remaining memory space size of the metadata block; when the remaining memory space size is less than a preset size, extracting non-redundant data from the metadata block into a new metadata block according to a preset redundancy information removal method.
[0011] Based on the above technical means, the embodiments of this application can clear redundant information when the metadata block stores a large amount of redundant information after a long running time. The existence of this redundant information causes the space of the metadata block to be occupied, which will affect the subsequent storage and reading of embedded files. Therefore, under the clearing method of the application embodiment, redundant data can be quickly removed and non-redundant data can be stored in a new metadata block, thereby increasing the storage space in the new metadata block and not affecting the storage and reading of embedded files.
[0012] Optionally, in one embodiment of this application, the step of submitting non-redundant data in the metadata block to a new metadata block according to a preset redundancy removal method specifically includes: traversing each file tag information in the metadata block and determining whether the file tag information is redundant data; if the file tag information is redundant data, then marking the file tag information as data to be removed; if the file tag information is not redundant data, then not marking the file tag information; and extracting all unmarked file tag information and their corresponding open paths into the new metadata block.
[0013] Based on the above technical means, in the process of deleting redundant data, this application embodiment only needs to determine whether each file tag information in each file information data of the metadata block is redundant data. If it is, it is not marked; otherwise, it is marked. Finally, all the marked file tag information is extracted into the new metadata block. Thus, through unified processing, non-redundant data is placed in the new metadata block at once, and non-redundant data is processed quickly and efficiently.
[0014] Optionally, in one embodiment of this application, determining whether the file tag information is redundant data specifically includes: obtaining the hash structure, determining whether the final state identifier of the hash structure information is a predetermined redundancy identifier; if the final state identifier of the hash structure information is not the predetermined redundancy identifier, then the file tag information corresponding to the hash structure information is not redundant data; if the final state identifier of the hash structure information is the predetermined redundancy identifier, then the file tag information corresponding to the hash structure information is redundant data.
[0015] Based on the above technical means, in the embodiments of this application, when determining whether the tag information is redundant data, the final identifier of the information in the hash structure corresponding to the file tag information in the metadata block can be directly judged as a preset redundancy identifier. If it is a preset redundancy identifier, it means that the file corresponding to the file tag information has been deleted, and therefore the preset redundancy identifier has been submitted. If it is not a preset redundancy identifier, it means that the corresponding file still exists, and therefore the corresponding file tag information cannot be deleted. By quickly judging the file tag information, it is possible to quickly determine which part is redundant information, thereby freeing up space for the metadata block, which facilitates the storage and reading of embedded files.
[0016] Optionally, in one embodiment of this application, obtaining the hash structure and obtaining the second file information from the information of the hash structure based on the first file information specifically includes: obtaining the hash structure, sequentially obtaining each piece of information in the information of the hash structure, and sequentially determining whether the information obtained from the information of the hash structure is the same as the first file information; if the information obtained from the information of the hash structure is the same as the first file information, then the information obtained from the information of the hash structure is the second file information.
[0017] According to the above technical means, in the embodiments of this application, when obtaining the corresponding second file information from the hash structure based on the first file information, the corresponding information can be obtained sequentially from the second file information, and it can be determined whether the obtained information is the same as the first file information. If the obtained information is the same as the first file information, it means that the information obtained at this time is the information of the embedded file to be opened stored in the hash structure, and the second file information is obtained accordingly. This technical means enables the second file information to be obtained one by one, thereby ensuring that the obtained second file information will not be wrong and guaranteeing the security when opening the embedded file.
[0018] Optionally, in one embodiment of this application, the step of obtaining the hash structure involves sequentially obtaining each piece of information in the hash structure and sequentially determining whether the information obtained from the hash structure is the same as the first file information. The step further includes: if the information obtained from the hash structure is not the same as the first file information, then obtaining the next piece of information in the hash structure; traversing all information in the hash structure until the second file information is obtained.
[0019] Based on the above technical means, the embodiments of this application can sequentially traverse the hash structure when obtaining the second file information based on the first file information, so that no data is missed, thereby ensuring the comprehensiveness of the acquisition process by sequentially traversing the process of obtaining the second file information based on the first file information.
[0020] A second aspect of this application provides a file reading system based on an embedded file structure. The file reading system includes: a first file information acquisition module, configured to acquire a metadata block and acquire first file information of an embedded file to be read based on the metadata block; a second file information acquisition module, configured to acquire a hash structure and acquire second file information from the information in the hash structure based on the first file information, wherein the hash structure is a data storage structure for the embedded file, and the second file information is a piece of information in the hash structure; and a file reading module, configured to extract location information corresponding to the second file information according to a pre-set storage relationship and read the information of the embedded file to be read based on the location information.
[0021] Optionally, in one embodiment of this application, the file reading system based on the embedded file structure further includes: a first data storage module, used to store the open paths and file tag information of all embedded files into the metadata block, wherein the first file information of each embedded file is obtained from the corresponding file tag information; and a second data storage module, used to store the first file information of each embedded file, the second file information corresponding to the first file information of each embedded file, and the location information corresponding to the second file information into the hash structure.
[0022] Optionally, in one embodiment of this application, the file reading system based on the embedded file structure further includes: a redundancy removal module, used to obtain the memory space size of the metadata block, and when the memory space size is less than a preset size, to extract non-redundant data in the metadata block into a new metadata block according to a preset redundancy information removal method.
[0023] Optionally, in one embodiment of this application, the redundancy removal module includes: a first judgment unit, configured to traverse each file tag information in the metadata block and determine whether the file tag information is redundant data; a first marking unit, configured to mark the file tag information as data to be removed if the file tag information is redundant data; a second marking unit, configured to not mark the file tag information if the file tag information is not redundant data; and a metadata block update unit, configured to extract all unmarked file tag information and their corresponding open paths into the new metadata block.
[0024] Optionally, in one embodiment of this application, the first judgment unit of this application embodiment further includes: a status identifier judgment unit, used to obtain the hash structure and determine whether the final status identifier of the information of the hash structure is a predetermined redundancy identifier; a first redundancy judgment unit, used to determine that if the final status identifier of the information of the hash structure is not the predetermined redundancy identifier, the file tag information corresponding to the information of the hash structure is not redundant data; and a second redundancy judgment unit, used to determine that if the final status identifier of the information of the hash structure is the predetermined redundancy identifier, the file tag information corresponding to the information of the hash structure is redundant data.
[0025] Optionally, in one embodiment of this application, the second file information acquisition module of this application embodiment includes: a second judgment unit, configured to acquire the hash structure, sequentially acquire each piece of information in the information of the hash structure, and sequentially judge whether the information acquired from the information of the hash structure is the same as the first file information; and a second file information acquisition unit, configured to, if the information acquired from the information of the hash structure is the same as the first file information, then the information acquired from the information of the hash structure is the second file information.
[0026] Optionally, in one embodiment of this application, the file reading system based on the embedded file structure of this application further includes: a traversal unit, used to obtain the next piece of information in the hash structure if the information obtained from the information of the hash structure is different from the first file information; and a traversal acquisition unit, used to traverse all the information in the hash structure until the second file information is obtained.
[0027] A third aspect of this application provides a smart terminal, the vehicle including: a memory, a processor, and a file reading program based on an embedded file structure stored in the memory and executable on the processor, wherein when the file reading program based on the embedded file structure is executed by the processor, it implements the steps of the file reading method based on the embedded file structure as described in the above embodiments.
[0028] A fourth aspect of this application provides a computer-readable storage medium storing a file reading program based on an embedded file structure. When executed by a processor, the file reading program based on the embedded file structure implements the steps of the file reading method based on the embedded file structure described in the above embodiments.
[0029] The beneficial effects of this application are:
[0030] (1) In this embodiment of the application, when reading an embedded file, the first file information can be obtained through the metadata block, and then the second file information can be obtained sequentially in the hash structure through the first file information, so as to read the embedded file. When the second file information is obtained, the traversal of the hash structure is immediately ended. Therefore, when reading the embedded file, it is not necessary to traverse the entire metadata block, but only to obtain the first file information. It is also not necessary to traverse the entire hash structure, but only to obtain the corresponding second file information to read the embedded file, so as to make the entire embedded file reading process faster.
[0031] (2) In this embodiment of the application, when storing embedded files, the embedded files can be stored in accordance with the reading method of the embedded files in this embodiment of the application, so that when reading, the embedded files that need to be read can be quickly read according to the stored content.
[0032] (3) In this embodiment of the application, when the space of the metadata block is insufficient, the final state of the information in the hash structure can be used to determine whether the corresponding file has been deleted. Based on the file deletion status, the redundant content in the corresponding metadata block can be deleted, and the time complexity used in this process is lower.
[0033] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0034] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0035] Figure 1 This is a flowchart of a preferred embodiment of the file reading method based on an embedded file structure in this application;
[0036] Figure 2 This is a flowchart illustrating the steps of a file system traversing a path to find a corresponding file in the prior art provided in this application.
[0037] Figure 3 This is a flowchart illustrating the steps of a preferred embodiment of the file reading method based on an embedded file structure in this application.
[0038] Figure 4 This is a flowchart illustrating the steps for removing redundant data from a file system in the prior art provided in this application;
[0039] Figure 5This is a flowchart illustrating the steps of a preferred embodiment of removing redundant data in this application;
[0040] Figure 6 This is a schematic diagram of a preferred embodiment of the file reading system based on an embedded file structure according to this application;
[0041] Figure 7 This is a schematic diagram of a preferred embodiment of the smart terminal of this application.
[0042] Among them, 10-file reading system based on embedded file structure; 100-first file information acquisition module, 200-second file information acquisition module and 300-file reading module; 701-memory, 702-processor and 703-communication interface. Detailed Implementation
[0043] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application.
[0044] The following describes a file reading method, system, and smart terminal based on an embedded file structure according to embodiments of this application, with reference to the accompanying drawings. Addressing the problem mentioned in the background art where, when reading embedded files, the matching result is only temporarily stored in the best matching result, and the current best matching result is only returned after traversing the entire metadata, resulting in slow reading and affecting file reading speed, this application provides a file reading method based on an embedded file structure. In this method, a metadata block is obtained; first file information of the embedded file to be read is obtained based on the metadata block; a hash structure is obtained; second file information is obtained from the information in the hash structure based on the first file information, wherein the hash structure is the data storage structure of the embedded file, and the second file information is a piece of information in the hash structure; according to a pre-set storage relationship, the position information corresponding to the second file information is extracted; and the information of the embedded file to be read is read based on the position information. This approach allows for the retrieval of the first file information of the embedded file to be read from the metadata block. Then, based on this first file information, the second file information is obtained from the numerous pieces of information in the hash structure. The location of the embedded file to be read can be located using this second file information, allowing for the reading of its information. This eliminates the need to traverse the entire hash structure and metadata block when reading the embedded file. The second file information is retrieved immediately after the first file information is obtained. Correspondingly, once the corresponding second file information is obtained through the hash structure, the extraction of information from the hash structure ends, enabling rapid reading of the embedded file. This solves the problem in related technologies where, when reading embedded files, the matching result is only temporarily stored in the best matching result, requiring the traversal of the entire metadata block before returning the current best matching result, thus causing slow reading and impacting file reading speed.
[0045] Specifically, Figure 1 This is a flowchart illustrating a file reading method based on an embedded file structure provided in an embodiment of this application.
[0046] like Figure 1 As shown, this file reading method based on an embedded file structure includes the following steps:
[0047] In step S101, a metadata block is obtained, and the first file information of the embedded file to be read is obtained based on the metadata block.
[0048] It is understandable that the embedded file information is stored before it can be read. The storage method corresponds to the reading method.
[0049] Therefore, the step of obtaining the metadata block, and obtaining the first file information of the embedded file to be read based on the metadata block, further includes:
[0050] The open paths and file tag information of all embedded files are stored in the metadata block, wherein the first file information of each embedded file is obtained from the corresponding file tag information;
[0051] The first file information of each embedded file, the second file information corresponding to the first file information of each embedded file, and the position information corresponding to the second file information are stored in the hash structure.
[0052] It is understandable that when storing each embedded file, the corresponding embedded file's open path and file tag information are stored in the metadata block. In one implementation, the file tag information is a tag, consisting of a 32-bit hexadecimal data. The 0th bit is the valid bit, bits 1-12 store the tag type, bits 13-22 store the file name (id), and bits 22-32 store the length. The tag type can be determined by reading bits 1-12, and the file name can be determined by reading bits 13-22. The hash structure is also stored in the metadata block. The corresponding first file information is the stored file name, i.e., the id. Accordingly, in this embodiment, a hash structure is applied. This embodiment stores the first file information of an embedded file, the second file information corresponding to the first file information of each embedded file, and the position information corresponding to each second file information in a hash table within the hash structure. In one implementation, the second file information is a linked list storing operations on the same file. This list is called a tag list, which stores tags. The position information is the address corresponding to the operation in the tag list. The position information is represented by a tag. For example, if the final operation is to delete a file, the corresponding position information is stored as a delete tag, and the corresponding information is stored in this tag. In one embodiment of this application, when using a hash structure to store file information, the tag list of operations on the same file is stored first; then a hash table is stored, with the file ID as the key and the tag list as the value. The value corresponding to the key is the address of the operation in the tag list. The first file information is the file ID, and the second file information is the tag list, with the position information being the address corresponding to the tag list.
[0053] Before reading the embedded file to be read, the data is stored according to the method to be read. The open paths and file tag information of all embedded files are stored in the metadata block. Thus, when reading the embedded file, the file tag information stored in the metadata block can be obtained according to the open path of the embedded file, and then the first file information can be obtained from the file tag information. In this embodiment, the first file information, second file information and position information of each embedded file are stored in a hash mechanism, so that when reading the embedded file, the information of the embedded file to be read can be obtained conveniently and quickly according to the correspondence.
[0054] After the embedded files are stored, when reading an embedded file, the open path is obtained based on the open operation of the file. This open path contains corresponding file tag information, and the first file information (file ID) can be obtained from the file tag information. In one implementation, a metadata block is obtained, a tag is retrieved from the metadata block, and the first file information, i.e., the file ID, is obtained from the tag.
[0055] It is understandable that when reading an embedded file to be opened, the information of the embedded file to be read will be obtained according to the click operation, and the first file information can be obtained according to the click operation.
[0056] In step S102, a hash structure is obtained, and second file information is obtained from the information in the hash structure based on the first file information. The hash structure is a data storage structure for an embedded file, and the second file information is a piece of information in the hash structure.
[0057] A hash structure is a key-value mapping structure that implements the mapping relationship between element keys and element values. In this application, a hash structure is used to store embedded files; that is, the hash structure is the data storage structure for embedded files. In this embodiment, after obtaining the first file information, the corresponding second file information is obtained from the hash structure based on the first file information. Thus, the second file information uniquely corresponding to each piece of first file information can be obtained according to the one-to-one correspondence.
[0058] It is understandable that obtaining the corresponding second file information based on the first file information is equivalent to obtaining the corresponding tag list based on the file ID. In the specific acquisition process, obtaining the hash structure and retrieving the second file information from the hash structure based on the first file information specifically includes:
[0059] Obtain the hash structure, sequentially obtain each piece of information in the hash structure, and sequentially determine whether the information obtained from the hash structure is the same as the information in the first file;
[0060] If the information obtained from the hash structure is the same as the first file information, then the information obtained from the hash structure is the second file information.
[0061] Understandably, when retrieving the second file information corresponding to the first file information based on the hash structure, the hash structure is obtained first, and the second file information is retrieved using the obtained hash structure. The hash table in the hash structure stores the first file information for each embedded file, the second file information corresponding to the first file information of each embedded file, and the position information corresponding to each second file information. Therefore, when retrieving the second file information from the hash structure based on the first file information, the hash structure is obtained first. Each entry in the hash structure contains the first file information of an embedded file, the corresponding second file information, and the corresponding position information. Each entry in the hash structure is retrieved sequentially, and it is determined whether the first file information contained in the hash structure is the same as the first file information retrieved from the metadata block. If the first file information in the current entry retrieved from the hash structure is the same as the first file information retrieved from the metadata block, it means that when storing the embedded file to be opened, the storage position is located at the information currently retrieved from the hash structure, and the corresponding second file information is retrieved from the hash structure at this time.
[0062] In this embodiment, when obtaining the corresponding second file information from the hash structure based on the first file information, the corresponding information is sequentially obtained from the second file information, and it is determined whether the obtained information is the same as the first file information. If the obtained information is the same as the first file information, it means that the information obtained at this time is the information of the embedded file to be opened stored in the hash structure, and the second file information is obtained accordingly. This technical means ensures that the second file information can be obtained one-to-one, so that the obtained second file information will not be wrong, thus ensuring the security when opening the embedded file.
[0063] Furthermore, the step of obtaining the hash structure, sequentially obtaining each piece of information in the hash structure, and sequentially determining whether the information obtained from the hash structure is the same as the first file information, further includes:
[0064] If the information obtained from the hash structure is different from the first file information, then the next piece of information in the hash structure is obtained;
[0065] Iterate through all the information in the hash structure until the second file information is obtained.
[0066] It is understandable that when obtaining the hash structure, sequentially retrieving each piece of information from the hash structure, and sequentially determining whether the information obtained from the hash structure is the same as the first file information obtained from the metadata block, if the first file information in the current information obtained from the hash structure is different from the first file information of the embedded file to be read, it means that the information currently obtained from the hash structure is not the information of the embedded file to be opened stored in the hash structure, and then the next piece of information in the hash structure is retrieved. All information in the hash structure is traversed sequentially, and the retrieval of information in the hash structure ends when the second file information is obtained. Based on the traversal of the hash structure, this embodiment of the application can sequentially traverse the hash structure when retrieving the second file information based on the first file information, thus ensuring that no data is missed, and thus ensuring the comprehensiveness of the retrieval process.
[0067] If the hash structure does not contain information identical to the first file information obtained from the metadata block after traversal, the message "file does not exist" will be output.
[0068] In step S103, the location information corresponding to the second file information is extracted according to the preset storage relationship, and the information of the embedded file to be read is read according to the location information.
[0069] It is understandable that the hash structure stores the location information corresponding to the second file information; that is, based on the obtained second file information, a unique corresponding location information can be obtained from the hash structure. This location information contains the address of the operation information for the embedded file to be read, therefore, the embedded file information can be read through the location information.
[0070] Furthermore, in this embodiment, the storage space of the metadata block is not unlimited. Therefore, when the storage space of the metadata block is smaller than a certain size, it will affect the reading process of the embedded file.
[0071] The file reading method based on the embedded file structure also includes:
[0072] Obtain the remaining memory space size of the metadata block. When the remaining memory space size is less than a preset size, extract the non-redundant data in the metadata block into a new metadata block according to a preset redundancy removal method.
[0073] It is understood that in this embodiment, the remaining memory space of the metadata block is obtained. When the remaining memory space is less than a preset size, it indicates that the metadata block will affect the reading of the embedded file due to insufficient memory. Therefore, it is necessary to extract the non-redundant data in the metadata block into a new metadata block according to a preset redundancy removal method. The preset size is set by the user according to actual conditions and is not limited in this embodiment. By processing the data in the metadata block, when the metadata block stores a large amount of redundant information after a long running time, this redundant information can be cleared. The presence of this redundant information causes the metadata block space to be occupied, affecting the subsequent storage and reading of the embedded file. Therefore, under the clearing method of this embodiment, redundant data can be quickly removed, and non-redundant data can be stored in a new metadata block, thereby increasing the storage space in the new metadata block and not affecting the storage and reading of the embedded file.
[0074] Furthermore, the step of submitting non-redundant data in the metadata block to a new metadata block according to a preset redundancy removal method specifically includes: traversing each file tag information in the metadata block and determining whether the file tag information is redundant data; if the file tag information is redundant data, then marking the file tag information as data to be removed; if the file tag information is not redundant data, then not marking the file tag information; and extracting all unmarked file tag information and their corresponding open paths into the new metadata block.
[0075] It is understandable that when submitting non-redundant data from the metadata block to a new metadata block according to a preset redundancy removal method, it is determined whether each file tag information in the metadata block is redundant. If so, it is marked as data to be removed; otherwise, it is left unmarked. After finally determining each file tag information in the metadata block, the marked file tag information and its corresponding open path are extracted into the new metadata block. In one embodiment of this application, after extracting the non-redundant data into the metadata block, the original metadata block is deleted or its memory is cleared. Through the preset redundancy removal method, during the process of deleting redundant data, it is only necessary to determine whether each file tag information in each file information data of the metadata block is redundant. If so, it is left unmarked; otherwise, it is marked. Finally, all the marked file tag information is extracted into the new metadata block, thereby processing the non-redundant data quickly and efficiently by placing it into the new metadata block in a unified manner.
[0076] Furthermore, determining whether the file tag information is redundant data specifically includes:
[0077] Obtain the hash structure and determine whether the final status identifier of the information in the hash structure is a predetermined redundancy identifier;
[0078] If the final state identifier of the information in the hash structure is not the predetermined redundancy identifier, then the file tag information corresponding to the information in the hash structure is not redundant data;
[0079] If the final state identifier of the information in the hash structure is the predetermined redundancy identifier, then the file tag information corresponding to the information in the hash structure is redundant data.
[0080] The final state identifier is the tag name of the location information in the hash structure information. When the tag name of the location information in the hash structure information is a deleted tag, it is a predetermined redundancy identifier.
[0081] It is understandable that when determining whether file tag information is redundant data, the first file information corresponding to the file tag information is stored in a hash structure, which stores the file's operation address. Based on the operation address, the final operation content of the file can be obtained. If the final operation content is to delete the file, a corresponding deletion tag (delete tag), i.e., a pre-defined redundancy identifier, will be submitted. This deletion tag will be recorded in the last tag corresponding to the value in the hash structure, i.e., the deletion tag. Therefore, the file tag information corresponding to this file is redundant data. Since a unique file tag information can be obtained based on the information in the corresponding hash structure, it is possible to determine whether the corresponding file tag information is redundant data. In one embodiment of this application, before traversing each file tag information in the metadata block to determine whether the file tag information is redundant data, the hash structure is traversed first to determine whether all final state identifiers in the hash structure are pre-defined redundancy identifiers. Then, the result is obtained, and based on the result, the file tag information in the metadata block is determined one by one to determine whether it is redundant data.
[0082] Furthermore, when submitting the file tag information and the corresponding open path to the new metadata block, the hash structure is updated accordingly and submitted to the new metadata block.
[0083] The following section further describes the steps involved in traversing a path to find the corresponding file in existing file systems, such as... Figure 2 As shown:
[0084] Step S1: Start fetching. Parse the next tag from the disk and calculate the CRC. The CRC is a type of tag that will be the last tag after the operation is committed. In other words, only the tag before the CRC is a truly valid tag.
[0085] Step S2: Check the boundary to determine if the boundary exceeds the box size or if the tag is invalid. If yes, proceed to step S3.2; otherwise, proceed to step S3.
[0086] Step S3: Determine if the tag is a CRC. If it is, proceed to step S3.1; otherwise, proceed to step S4.
[0087] Step S3.1: Check if there is data in the accumulated CRC that is equal to the CRC corresponding to the tag. If so, proceed to step S3.1; otherwise, proceed to step S3.2.
[0088] Step S3.2: End the acquisition process and return the error value;
[0089] Step S3.3: Update the best matching result and reset the CRC;
[0090] Step S4: Update according to tag type. If the tag is a name, proceed to step S4.1. If the tag is a delete tag, proceed to step S4.2. If the tag is a tail tag, proceed to step S4.3.
[0091] Step S4.1: Increment the file count by 1 and proceed to step S5;
[0092] Step S4.2: Invalidate and proceed to step S5;
[0093] Step S4.3: Update the corresponding data and proceed to step S5;
[0094] Step S5: Determine if the tag type is a name. If yes, proceed to step S6; otherwise, proceed to step S8.
[0095] Step S6: Call the callback function to read data from the disk and determine whether it matches the tag. If it matches, proceed to step S7; otherwise, proceed to step S8.
[0096] Step S7: Update the best matching result (tempbesttag) and proceed to step S8;
[0097] Step S8: Determine whether all tags have been read. If yes, proceed to step S9; otherwise, proceed to step S1.
[0098] Step S9: End the acquisition process, set tempbesttag to besttag, and return the best tag.
[0099] Understandably, in existing technologies, when the file system searches for a file based on a path, it iterates through and matches the file ID stored in the metadata against the input file path. Even if a match is found, it is only temporarily stored in the best match result. The best match result is only returned after traversing the entire metadata. Therefore, as the number of tags in the metadata increases, the traversal time will gradually increase.
[0100] The steps of the file reading method based on the embedded file structure in this application embodiment will be further described, such as... Figure 3 As shown:
[0101] Step S11, open the file;
[0102] Step S12: Retrieve the file ID from the metadata block based on the file's open path;
[0103] Step S13: Traverse the hash structure;
[0104] Step S14: Determine whether the hash structure has been traversed. If the key corresponding to the file id is not found in the hash structure after traversing, proceed to step S17. If the traversal is not complete, proceed to step S15.
[0105] Step S15: Determine whether the current key being traversed is equal to the file ID. If they are equal, proceed to step S16; otherwise, proceed to step S14.
[0106] Step S16: Read the latest information of the current file from the location mapped by the file ID;
[0107] Step S17: The file does not exist.
[0108] It is understood that the embodiments of this application can obtain the first file information of the embedded file to be read through the metadata block, and then obtain the second file information from the numerous information in the hash structure based on the first file information. Based on the second file information, the location of the embedded file to be read can be found, and then the information of the embedded file to be read can be read. Thus, when reading the embedded file, it is not necessary to traverse the entire hash structure and metadata block. After obtaining the first file information, the second file information is obtained. Correspondingly, once the corresponding second file information is obtained through the hash structure, the extraction of information in the hash structure ends, so that the embedded file to be read can be read quickly.
[0109] The steps for removing redundant data from a file system in the prior art provided in this application embodiment will be further described, such as... Figure 4 As shown:
[0110] Step S21: When there is no space in the metadata block, remove redundant tags;
[0111] Step S22: Traverse the metadata and obtain the next tag;
[0112] Step S23: Determine whether the traversal is complete. If yes, proceed to step S24; otherwise, proceed to step S25.
[0113] Step S24, end the traversal;
[0114] Step S25: Iterate through the metadata again, comparing each tag with the first tag;
[0115] Step S26: Determine if the tag is duplicated. If so, proceed to step S27; otherwise, proceed to step S28.
[0116] Step S27: Remove redundant tags;
[0117] Step S28: Determine if the traversal is complete. If yes, proceed to step S22; otherwise, proceed to step S25.
[0118] Understandably, the process of removing redundant tags involves two traversals, requiring each tag in the metadata to be compared sequentially with all the remaining tags to determine if it is redundant. Therefore, the corresponding time complexity is O(N). 2 N is the number of tags. Specifically, for the first tag, it needs to be compared with the remaining (N-1) tags to determine if it is redundant. For the second tag, it needs to be compared with the remaining (N-2) tags. Therefore, the corresponding time complexity is O(N). 2 ).
[0119] The steps of the preferred embodiment for removing redundant data in this application will be further described, such as... Figure 5 As shown:
[0120] Step S31: When there is no space in the metadata block, redundant file tag information needs to be removed.
[0121] Step S32: Traverse the hash structure;
[0122] Step S33: Determine whether the hash structure has been traversed. If yes, proceed to step S34; otherwise, proceed to step S35.
[0123] Step S34: The file tag information corresponding to the tags that were not marked as removed in the hash structure will be resubmitted to the new metadata block;
[0124] Step S35: Find the key that is the same as id, and find the corresponding value through the key;
[0125] Step S36: Determine whether the tag stored in the value is deleted. If yes, proceed to step S37; otherwise, proceed to step S32.
[0126] Step S37: The corresponding file tag information is redundant, so it is marked for removal.
[0127] It is understandable that, after using the hash structure, the operation tags for the same file are recorded in the position of the value corresponding to the same key. This process only needs to traverse the last tag stored in each value in the hash structure to see if it is a deletion tag. Therefore, the time complexity is O(N).
[0128] In summary, the embodiments of this application can obtain a metadata block, obtain first file information of the embedded file to be read based on the metadata block; obtain a hash structure, obtain second file information from the information in the hash structure based on the first file information, wherein the hash structure is the data storage structure of the embedded file, and the second file information is a piece of information in the hash structure; extract the position information corresponding to the second file information according to a preset storage relationship, and read the information of the embedded file to be read based on the position information. When reading an embedded file, the first file information can be obtained through the metadata block, and then the second file information can be sequentially obtained from the hash structure using the first file information, thus reading the embedded file. Specifically, the traversal of the hash structure ends immediately upon obtaining the second file information. Therefore, when reading the embedded file, it is not necessary to traverse the entire metadata block; only the first file information needs to be obtained. Nor is it necessary to traverse the entire hash structure; only the corresponding second file information is needed to read the embedded file, making the entire embedded file reading process faster. When storing the embedded file, it is stored according to the embedded file reading method of this application embodiment, so that the required embedded file can be quickly read based on the stored content. When the space of the metadata block is insufficient, the final state of the information in the hash structure can be used to determine whether the corresponding file has been deleted. Redundant content in the corresponding metadata block is deleted according to the file deletion status, and the time complexity of this process is lower.
[0129] Next, referring to the accompanying drawings, a file reading system based on an embedded file structure proposed according to an embodiment of this application is described.
[0130] Figure 6 This is a block diagram of a file reading system based on an embedded file structure according to an embodiment of this application.
[0131] like Figure 6As shown, the file reading system 10 based on the embedded file structure includes: a first file information acquisition module 100, a second file information acquisition module 200, and a file reading module 300.
[0132] The first file information acquisition module 100 is used to acquire metadata blocks and acquire the first file information of the embedded file to be read based on the metadata blocks.
[0133] The second file information acquisition module 200 is used to acquire a hash structure and acquire second file information from the information in the hash structure based on the first file information, wherein the hash structure is a data storage structure for an embedded file and the second file information is a piece of information in the hash structure.
[0134] The file reading module 300 is used to extract the location information corresponding to the second file information according to the preset storage relationship, and read the information of the embedded file to be read according to the location information.
[0135] Optionally, in one embodiment of this application, the file reading system based on the embedded file structure further includes: a first data storage module and a second data storage module.
[0136] The first data storage module is used to store the open paths and file tag information of all embedded files into the metadata block, wherein the first file information of each embedded file is obtained from the corresponding file tag information.
[0137] The second data storage module is used to store the first file information of each embedded file, the second file information corresponding to the first file information of each embedded file, and the position information corresponding to each second file information into the hash structure.
[0138] Optionally, in one embodiment of this application, the file reading system based on the embedded file structure further includes a redundancy removal module.
[0139] The redundancy removal module is used to obtain the memory space size of the metadata block. When the memory space size is less than a preset size, it extracts the non-redundant data in the metadata block into a new metadata block according to a preset redundancy removal method.
[0140] Optionally, in one embodiment of this application, the redundancy removal module includes: a first judgment unit, a first marking unit, a second marking unit, and a metadata block update unit.
[0141] The first judgment unit is used to traverse each file tag information in the metadata block and determine whether the file tag information is redundant data.
[0142] The first marking unit is used to mark the file tag information as data to be removed if the file tag information is redundant data.
[0143] The second marking unit is used to not mark the file tag information if the file tag information is not redundant data.
[0144] The metadata block update unit is used to extract all untagged file tag information and their corresponding open paths into the new metadata block.
[0145] Optionally, in one embodiment of this application, the first judgment unit of this application embodiment further includes: a second judgment unit, a first redundant judgment unit, and a second redundant judgment unit.
[0146] The second judgment unit is used to obtain the hash structure and determine whether the final status identifier of the information in the hash structure is a predetermined redundancy identifier.
[0147] The first redundancy determination unit is configured to determine that if the final state identifier of the information in the hash structure is not the predetermined redundancy identifier, then the file tag information corresponding to the information in the hash structure is not redundant data.
[0148] The second redundancy determination unit is used to determine if the final state identifier of the information in the hash structure is the predetermined redundancy identifier, and the file tag information corresponding to the information in the hash structure is redundant data.
[0149] Optionally, in one embodiment of this application, the second file information acquisition module 200 of this application embodiment includes: a third judgment unit and a second file information acquisition unit.
[0150] The third judgment unit is used to obtain the hash structure, sequentially obtain each piece of information in the information of the hash structure, and sequentially judge whether the information obtained from the information of the hash structure is the same as the first file information.
[0151] The second file information acquisition unit is configured to, if the information obtained from the information in the hash structure is the same as the first file information, then the information obtained from the information in the hash structure is the second file information.
[0152] Optionally, in one embodiment of this application, the file reading system based on the embedded file structure of this application further includes: a traversal unit and a traversal acquisition unit.
[0153] The traversal unit is used to obtain the next piece of information in the hash structure if the information obtained from the information in the hash structure is different from the information in the first file.
[0154] The traversal acquisition unit is used to traverse all information in the information of the hash structure until the second file information is obtained.
[0155] It should be noted that the foregoing explanation of the file reading method embodiment based on embedded file structure also applies to the file reading system based on embedded file structure in this embodiment, and will not be repeated here.
[0156] According to the file reading system based on the embedded file structure proposed in the embodiments of this application, the first file information of the embedded file to be read can be obtained through the metadata block. Then, the second file information can be obtained from the numerous information in the hash structure based on the first file information. Based on the second file information, the location of the embedded file to be read can be found, and then the information of the embedded file to be read can be read. Thus, when reading the embedded file, it is not necessary to traverse the entire hash structure and metadata block. After obtaining the first file information, the second file information is obtained. Correspondingly, once the corresponding second file information is obtained through the hash structure, the extraction of information in the hash structure ends, so that the embedded file to be read can be read quickly.
[0157] This solves the problem in related technologies where, when reading embedded files, the matching results are only temporarily stored in the best matching result, and the current best matching result is only returned after traversing all the metadata, thus causing slow reading and affecting file reading speed.
[0158] Figure 7 A schematic diagram of the structure of a smart terminal provided in an embodiment of this application. The smart terminal may include:
[0159] The memory 701, the processor 702, and the computer program stored on the memory 701 and executable on the processor 702.
[0160] When the processor 702 executes the program, it implements the file reading method based on the embedded file structure provided in the above embodiments.
[0161] Furthermore, smart terminals also include:
[0162] Communication interface 703 is used for communication between memory 701 and processor 702.
[0163] The memory 701 is used to store computer programs that can run on the processor 702.
[0164] The memory 701 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0165] If the memory 701, processor 702, and communication interface 703 are implemented independently, then the communication interface 703, memory 701, and processor 702 can be interconnected via a bus to complete communication between them. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EIS) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 7 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0166] Optionally, in a specific implementation, if the memory 701, processor 702, and communication interface 703 are integrated on a single chip, then the memory 701, processor 702, and communication interface 703 can communicate with each other through an internal interface.
[0167] The processor 702 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.
[0168] This embodiment also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the file reading method based on the embedded file structure described above.
[0169] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0170] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "N" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0171] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or N executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.
[0172] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable storage medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable storage medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable storage medium could be paper or other suitable media on which the program can be printed, since the program can be obtained electronically by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0173] It should be understood that the various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, the N steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0174] Those skilled in the art will understand that all or part of the steps of the methods described in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it includes one or a combination of the steps of the method embodiments.
[0175] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0176] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.
[0177] It should be understood that the application of this application is not limited to the examples above. Those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.
Claims
1. A file reading method based on an embedded file structure, characterized in that, The file reading method based on the embedded file structure includes: Obtain the metadata block, and obtain the first file information of the embedded file to be read based on the metadata block; Obtain a hash structure, and retrieve second file information from the information in the hash structure based on the first file information, wherein the hash structure is a data storage structure for an embedded file, and the second file information is a piece of information in the hash structure; extract the position information corresponding to the second file information according to a pre-set storage relationship, and read the information of the embedded file to be read based on the position information; The step of obtaining the metadata block, which involves obtaining the first file information of the embedded file to be read based on the metadata block, also includes: The open paths and file tag information of all embedded files are stored in the metadata block, wherein the first file information of each embedded file is obtained from the corresponding file tag information; The first file information of each embedded file, the second file information corresponding to the first file information of each embedded file, and the position information corresponding to each second file information are stored in the hash structure; The step of obtaining the hash structure, specifically obtaining the second file information from the information in the hash structure based on the first file information, includes: Obtain the hash structure, sequentially obtain each piece of information in the hash structure, and sequentially determine whether the information obtained from the hash structure is the same as the information in the first file; If the information obtained from the hash structure is the same as the first file information, then the information obtained from the hash structure is the second file information.
2. The file reading method based on an embedded file structure according to claim 1, characterized in that, The file reading method based on the embedded file structure also includes: Obtain the remaining memory space size of the metadata block. When the remaining memory space size is less than a preset size, extract the non-redundant data in the metadata block into a new metadata block according to a preset redundancy removal method.
3. The file reading method based on an embedded file structure according to claim 2, characterized in that, The step of submitting non-redundant data from the metadata block to a new metadata block according to a preset redundancy removal method specifically includes: Iterate through each file tag information in the metadata block and determine whether the file tag information is redundant data; If the file tag information is redundant data, then mark the file tag information as data to be removed; If the file tag information is not redundant data, then the file tag information is not marked; Extract all untagged file tag information and their corresponding open paths into the new metadata block.
4. The file reading method based on an embedded file structure according to claim 3, characterized in that, The step of determining whether the file tag information is redundant data specifically includes: Obtain the hash structure and determine whether the final status identifier of the information in the hash structure is a predetermined redundancy identifier; If the final state identifier of the information in the hash structure is not the predetermined redundancy identifier, then the file tag information corresponding to the information in the hash structure is not redundant data; If the final state identifier of the information in the hash structure is the predetermined redundancy identifier, then the file tag information corresponding to the information in the hash structure is redundant data.
5. The file reading method based on an embedded file structure according to claim 1, characterized in that, The step of obtaining the hash structure involves sequentially obtaining each piece of information from the hash structure, and sequentially determining whether the information obtained from the hash structure is the same as the information in the first file. The process then further includes: If the information obtained from the hash structure is different from the first file information, then the next piece of information in the hash structure is obtained; Iterate through all the information in the hash structure until the second file information is obtained.
6. A file reading system based on an embedded file structure, characterized in that, The file reading system based on the embedded file structure is applied to the file reading method based on the embedded file structure according to any one of claims 1-5, wherein the file reading system based on the embedded file structure comprises: The first file information acquisition module is used to acquire metadata blocks and acquire the first file information of the embedded file to be read based on the metadata blocks. The second file information acquisition module is used to acquire a hash structure and acquire second file information from the information in the hash structure based on the first file information, wherein the hash structure is a data storage structure for an embedded file and the second file information is a piece of information in the hash structure. The file reading module is used to extract the location information corresponding to the second file information according to the preset storage relationship, and read the information of the embedded file to be read according to the location information.
7. A smart terminal, characterized in that, The smart terminal includes a memory, a processor, and a file reading program based on an embedded file structure stored in the memory and executable on the processor. When the file reading program based on the embedded file structure is executed by the processor, it implements the steps of the file reading method based on an embedded file structure as described in any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a file reading program based on an embedded file structure, which, when executed by a processor, implements the steps of the file reading method based on an embedded file structure as described in any one of claims 1-5.
Citation Information
Patent Citations
Embedded file system for high-definition media
CN101980203A
File accessing method and system for embedded terminal
CN104346357A