Simplified file system and method convenient for memory access
By setting the file index area and file data area in the memory of the embedded device, a streamlined file system is realized that facilitates memory access is solved, and the existing file system is complicated to use and large space is taken up, which improves the performance and availability of the embedded system.
Patent Information
- Application Number
- CN202510146337.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-10
- Publication Date
- 2025-06-20
AI Technical Summary
The file system in existing embedded systems is cumbersome to use and takes up a lot of space, which is not suitable for simple functions. When directly accessing memory such as EEPROM and FLASH, it is inconvenient to store data writing and reading.
It provides a streamlined file system for easy memory access, including setting a file index area and a file data area in the memory of an embedded device. The file index area is used to store file parameter information. The file data area is divided into a sector marking area, a file content storage area and a next sector address storage area, and performs corresponding file operations according to file operation instructions.
It realizes fast and efficient memory access, reduces memory footprint, is compatible with more embedded devices, and improves the overall performance and availability of embedded systems.
Smart Images

Figure CN120179615A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded systems, and in particular to a lightweight file system facilitating memory access. Background Art
[0002] In an embedded system, there are many ways to access memory, such as direct access or file access. Directly accessing memories such as EEPROM and FLASH is inconvenient for writing and reading stored data.
[0003] Although current other file systems have many functions, they are cumbersome to use and occupy a large amount of space, and are not suitable for situations with simple functions. Summary of the Invention
[0004] The purpose of the present invention is to provide a lightweight file system and method facilitating memory access to solve the technical problems in the prior art.
[0005] The many technical effects that can be produced by the optional technical solutions among the many technical solutions provided by the present invention are described in detail below.
[0006] To achieve the above purpose, the present invention provides the following technical solutions:
[0007] In a first aspect, the present application provides a lightweight file system facilitating memory access, including a file index area and a file data area set in the memory of an embedded device; the file index area and the file data area are any non-overlapping areas in the memory;
[0008] The file index area is used to create a file index block corresponding to the file when creating a file, and the file index block is used to store file parameter information, and the file parameter information includes file name, file type, address of file content, file length, and check bit;
[0009] The file data area is used based on the file index block, and the file data area is divided into a first area marked with sector usage, a second area for storing the file content, and a third area for storing the address of the next sector;
[0010] When receiving an incoming file operation instruction, the file index area and the file data area execute corresponding file operations according to the file operation instruction.
[0011] In some embodiments, the file data area is further used such that if the size of the file content does not exceed the range of the second area, the address of the next sector is empty.
[0012] In some embodiments, the file data area is further configured to set the address of the next sector in the third area if the size of the file content exceeds the range of the second area.
[0013] In some embodiments, if the file operation is a file creation operation, the file index area is further configured to, when receiving the name of the file to be created, find an unused file index block and place the name of the file to be created into the unused file index block.
[0014] In some embodiments, if the file operation is a file writing operation, the file index area is further configured to, when receiving the name of the file to be written, find the index block corresponding to the name of the file to be written in the file index area, find the address of the file data area corresponding to the name of the file to be written at the address of the corresponding index block, and write the file content corresponding to the name of the file to be written into the file data area corresponding to the name of the file to be written.
[0015] In some embodiments, if the file operation is a file reading operation, the file index area is further configured to, when receiving the name of the file to be read, find the index block corresponding to the name of the file to be read in the file index area, find the address of the file data area corresponding to the name of the file to be read at the address of the corresponding index block, and read the file content corresponding to the name of the file to be read from the file data area corresponding to the name of the file to be read.
[0016] In some embodiments, if the file operation is a file deletion operation, the file index area is further configured to, when receiving the name of the file to be deleted, find the index block corresponding to the name of the file to be deleted in the file index area, find the address of the file data area corresponding to the name of the file to be deleted at the address of the corresponding index block, so that the file data area corresponding to the name of the file to be deleted marks the first area of the corresponding file data area as discarded, erases the file content in the second area, and traverses the sectors used by the file to be deleted through the address of the next sector in the third area and marks them all as discarded.
[0017] In some embodiments, the lean file system further includes a cache area, and the cache area is configured to, when detecting the file deletion operation, traverse the file data areas marked as discarded, take out the values corresponding to the discarded index blocks and place them in the cache area, and then erase the discarded index blocks to obtain empty index blocks.
[0018] Second aspect, the present application further provides a method for facilitating memory access, which is applied to the thin file system for facilitating memory access described in the first aspect. The thin file system includes a file index area and a file data area set in the memory of the embedded device; the file index area and the file data area are any non-overlapping areas in the memory, and the method is characterized in that the method includes:
[0019] When creating a file, create a file index block corresponding to the file in the file index area; the file index block is used to store file parameter information, and the file parameter information includes the address of the file content.
[0020] Based on the file index block, divide the file data area into a first area marked with sector usage, a second area for storing the file content, and a third area for storing the address of the next sector.
[0021] Based on the file index area and the file data area, create a file operation command.
[0022] Package the file index area, the file data area, and the file operation command to obtain the thin file system, and transplant the thin file system into the embedded device.
[0023] In some embodiments, the method further includes:
[0024] Through macro definition, summarize system parameters into a header file, and provide a function interface for file operation instructions for the embedded device to call the system parameters, where the system parameters include the size of the file index area and the range of the file data area.
[0025] Implementing one of the above technical solutions of the present invention has the following advantages or beneficial effects:
[0026] The thin file system and method for facilitating memory access of the present application provide embedded developers with fast and efficient access to the memory of the embedded device. Moreover, on the premise of adding memory access functions, the thin file system only requires a small amount of memory occupancy space and can be compatible with more embedded devices. It can not only provide the command functions of most file systems but also solve the problem of large memory occupancy space brought by the file system, greatly improving the efficiency of using memory in the embedded device, thereby improving the overall performance and usability of the entire embedded system. Description of the Drawings
[0027] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings. In the drawings:
[0028] Figure 1 It is a schematic diagram of a reduced file system facilitating memory access according to an embodiment of the present application;
[0029] Figure 2 It is a schematic diagram of a file index area according to an embodiment of the present application;
[0030] Figure 3 It is a schematic diagram of a file data area according to an embodiment of the present application;
[0031] Figure 4 It is a schematic flowchart of a method facilitating memory access according to an embodiment of the present application. Specific Embodiments
[0032] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, various exemplary embodiments to be described hereinafter will refer to the corresponding drawings, which form a part of the exemplary embodiments and describe various exemplary embodiments that may be adopted to implement the present invention. Unless otherwise indicated, the same numerals in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. It should be understood that they are merely examples of processes, methods, devices, etc. consistent with some aspects of the present invention as detailed in the appended claims. Other embodiments may also be used, or structural and functional modifications may be made to the embodiments listed herein without departing from the scope and essence of the present invention.
[0033] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", etc. indicate the orientation or positional relationship based on the orientation shown in the drawings. These are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the elements referred to must have a specific orientation, be constructed and operated in a specific orientation. The terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. The meaning of the term "plurality" is two or more. The terms "connected" and "connected to" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, an integral connection, a mechanical connection, an electrical connection, a communication connection, a direct connection, an indirect connection through an intermediate medium. It can be the communication inside two elements or the interaction relationship between two elements. The term "and / or" includes any and all combinations of one or more of the related listed items. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0034] In order to illustrate the technical solutions described in the present invention, the following will be described through specific embodiments, and only the parts related to the embodiments of the present invention are shown.
[0035] Embodiment 1:
[0036] As Figure 1 shown, the present application provides a lightweight file system that facilitates memory access. As Figure 1 shown, it includes a file index area and a file data area set in the memory FLASH of the embedded device.
[0037] The file index area and the file data area are any non-overlapping areas in the memory. There is no requirement for the sector numbers of the file index area and the file data area to be continuous. Their address ranges can be specified in any non-overlapping areas of the FLASH, as long as the sectors within their respective sector sets are continuous. Since the file system separates the underlying IO operations, the file index sector set and the file data sector set can be stored separately on two different FLASHs.
[0038] Specifically, the program of the lightweight file system that facilitates memory access defaults to taking two sectors from the memory of the embedded device as the file index area, and the size of each sector can be 8KB. The size of the two sectors can be compatible with the memory sizes of almost all embedded devices and is adjustable. Its value can be set according to the size of its own configuration, which is convenient for quickly porting to the programs of embedded devices.
[0039] The file index area is used to create a file index block corresponding to the file when creating a file. The file index block is used to store file parameter information, and the file parameter information includes file name, file type, the address of the file content, file length, and check bits.
[0040] Each time a file is newly created by the program of the memory - access - friendly reduced - file system, a file index block is created in the file index area. The file index block stores all the information of the file to be created, which are file parameter information, including file name, file type, address of file content, file length, checksum, etc., totaling 32 bytes. Moreover, the 32 - byte file index block is aligned to make full use of the memory of the embedded device. The file index area can refer to Figure 2 。
[0041] For example, when creating a file named "config.txt", the reduced - file system of this application will create a 32 - byte index block in the file index area: file name: config.txt (occupying 20 bytes), file type: txt (occupying 2 bytes), file content address: 0x1000 (occupying 4 bytes), file length: 1024 (occupying 4 bytes), checksum: 0xAA (occupying 2 bytes).
[0042] By setting up the file index block, it supports fast file search and management. Without having to traverse the entire storage space, files can be efficiently managed. And the 32 - byte alignment design ensures full utilization of the index area space.
[0043] In some embodiments, the size of the index area can be adjusted according to requirements to adapt to different device needs.
[0044] By creating a file index area in the memory, all the file parameter information such as the created file names and file lengths are saved in the file index area, and the corresponding file data area can be located through the file index area, improving the efficiency and allocation rationality of file access.
[0045] After creating the file index area, the program of the memory - access - friendly reduced - file system sets up the file data area. The program defaults to setting 62 sectors for use as the file data area, which can be compatible with most embedded devices and is adjustable. One sector is 4KB.
[0046] The file data area is used based on the file index block. The file data area is divided into a first area marked with sector usage, a second area for storing the file content, and a third area for storing the address of the next sector. Through the address of the next sector, cross - sector storage of files can be achieved. Therefore, files can be supported to be stored in discontinuous sectors.
[0047] The usage distribution of the file data area is as Figure 3 shown. The size of the file data area can be 4KB, the size of the first area marked with sector usage can be 4Byte, the size of the second area for storing the file content can be 4088Byte, and the size of the third area for storing the address of the next sector can be 4Byte.
[0048] The sector usage flag indicates the usage status of the current sector, such as unused, in use, or discarded. Based on its usage status, it is determined whether to use the current sector. If the current sector is unused and its content is empty, the usage flag is "unused"; for a sector that is still in use, the usage flag is "in use". After a file is deleted after use, the sector usage flag is "discarded", indicating that the sector is to be erased and waiting for the garbage collection station to perform the erasure process.
[0049] In some embodiments, the file data area is further configured such that if the size of the file content does not exceed the range of the second area, the address of the next sector is empty.
[0050] In some embodiments, the file data area is further configured such that if the size of the file content exceeds the range of the second area, the address of the next sector is set in the third area.
[0051] For example, to store a 5KB file "large_file.dat": 1. The first sector: Usage flag: 0x01 (in use), File content: 4088 bytes of data, Next sector address: 0x2000; 2. The second sector: Usage flag: 0x01 (in use), File content: The remaining 1000 bytes of data, Next sector address: 0x0000 (end of file).
[0052] The setting of the file data area supports the storage of large files and the use of non - contiguous sectors. It can mark the sector usage status, store file content, connect to other sectors, and store files larger than the size of a single sector. Moreover, through the next sector address, non - contiguous sectors can be used to achieve the continuity of data storage between sectors, improving the utilization rate of storage space. Through the sector usage flag, available space and discarded space can be quickly identified, enabling flexible file management; the structure of this file data area can also simplify file read, write, and delete operations.
[0053] When receiving an incoming file operation instruction, the file index area and the file data area execute corresponding file operations according to the file operation instruction.
[0054] File operations include basic functions such as file creation, file writing, reading file content, and file deletion.
[0055] In some embodiments, if the file operation is a file creation operation, the file index area is further configured to, when receiving the name of the file to be created, find an unused file index block and place the name of the file to be created into the unused file index block.
[0056] Specifically, based on the file index area and the file data area, a file creation operation can be implemented. When the file index area receives the file name to be created, it first searches for an unused file index block and places the file name to be created into the unused file index block. Then, the unused file index block is changed to a used file index block, which stores file parameter information related to the file name, including the file name, file type, address of the file content, file length, and check bit.
[0057] In some embodiments, if the file operation is a file write operation, the file index area is further configured to, when receiving the file name to be written, search for the index block corresponding to the file name to be written in the file index area, and search for the address of the first file data area corresponding to the file name to be written at the address of the index block corresponding to the file name to be written, and write the file content corresponding to the file name to be written in the first file data area.
[0058] After creating the file name in the file index area, it is necessary to write the file content in the file data area. Then, due to the file parameter information stored in the file index block, search for the address of the file data area corresponding to the file name to be written in the file index area, and then write the corresponding file content in the second area of the file data area. At the same time, mark the first area of the file data area as in use.
[0059] In this file data area, if the size of the file content does not exceed the range of the second area, set the address of the next sector of the third area to be empty.
[0060] Conversely, if the size of the file content exceeds the range of the second area, set the address of the next sector of the third area, and store the remaining file content in the sector corresponding to the address of the next sector.
[0061] In some embodiments, if the file operation is a file read operation, the file index area is further configured to, when receiving the file name to be read, search for the index block corresponding to the file name to be read in the file index area, and search for the address of the file data area corresponding to the file name to be read at the address of the corresponding index block, and read the file content corresponding to the file name to be read in the file data area corresponding to the file name to be read.
[0062] When a file needs to be read, the embedded device passes the file name to be read through the lean file system. The file index area receives the file name to be read and searches for the corresponding index block according to the file name to be read, so as to find the address of the file data area corresponding to the file name to be read at the file content address of the index block, realize the rapid positioning of the file content, and quickly find the corresponding file content in the second area of the file data area, so as to read out the file content.
[0063] In some embodiments, if the file operation is a file deletion operation, the file index area is further configured to, when receiving the name of the file to be deleted, search for the index block corresponding to the name of the file to be deleted in the file index area, and search for the address of the file data area corresponding to the name of the file to be deleted at the address of the corresponding index block, so that the file data area corresponding to the name of the file to be deleted marks the first area of the third file data area as discarded, erases the file content of the second area, and marks all sectors used by the file to be deleted as discarded by traversing the next sector address of the third area.
[0064] When a file needs to be deleted, the embedded device passes the name of the file to be deleted through the lean file system, then searches for the index block corresponding to the name of the file to be deleted in the file index area, marks the index block as discarded, and searches for the file content to be deleted in the corresponding index block. After finding the file data area, mark the current sector as discarded, erase the stored file content, and mark all sectors used by the file to be deleted as discarded by traversing the next sector address of the third area.
[0065] If only the current sector stores file content, only the file content of the current sector is deleted.
[0066] In some embodiments, the lean file system further includes a cache area, which is configured to, when detecting the file deletion operation, traverse the file data areas marked as discarded, take out the values corresponding to the discarded index blocks and put them into the cache area, and then erase the discarded index blocks to obtain empty index blocks.
[0067] In this embodiment, garbage collection detection is integrated in the file deletion operation. When the embedded device detects the file deletion operation through the lean file system, it first traverses the file data areas marked as discarded and erases the file content of the file data areas. Then, it takes out the values corresponding to the discarded index blocks and puts them into the cache area, and erases the discarded index blocks, thereby releasing the index blocks and achieving balanced memory usage.
[0068] For example, when deleting the file "old_file.txt": First, mark the corresponding file index block as discarded; then, traverse and mark all data sectors used by the file as discarded. Next, check the storage space usage. If the available space is insufficient, erase all data sectors marked as discarded.
[0069] Through the garbage collection mechanism, the utilization rate of storage space can be improved, and the abandoned space can be recycled in a timely manner to ensure the maximization of available storage space; garbage collection is only invoked for erasure when there is insufficient memory space, reducing the number of memory erasures and balancing the erasure operations, which can extend the lifespan of the storage device; moreover, garbage collection can be performed when necessary, reducing the impact on normal operations; by organizing the file index area, the consistency and integrity of the file system data can be ensured.
[0070] The above file operations of file creation, file writing, reading file content, and file deletion can all be achieved with a small amount of code space, so it can meet the requirements of most embedded devices.
[0071] The lightweight file system of the present application provides embedded developers with fast and efficient access to the memory of embedded devices. On the premise of adding memory access functions, this lightweight file system only requires a small amount of memory occupancy to be compatible with more embedded devices. It can not only provide the command functions of most file systems but also solve the problem of large memory occupancy caused by the file system, greatly improving the efficiency of using memory in embedded devices, thereby enhancing the overall performance and usability of the entire embedded system.
[0072] Furthermore, the lightweight file system of the present application realizes simple access to memory through the use of the mark-sweep method and operations such as file creation, writing, and deletion. It reduces the complexity of directly operating on memory, shortens the getting-started time, and provides convenient file operation commands, thereby improving the efficiency of memory access and achieving a certain degree of read-write balance.
[0073] As Figure 4 shown, the present application also provides a method for facilitating memory access, including steps S100 - S400.
[0074] S100. When creating a file, create a file index block corresponding to the file in the file index area; the file index block is used to store file parameter information, and the file parameter information includes the address of the file content.
[0075] S200. Based on the file index block, divide the file data area into a first area marked with sector usage, a second area for storing the file content, and a third area for storing the address of the next sector.
[0076] S300. Based on the file index area and the file data area, create file operation commands.
[0077] S400. Package the file index area, the file data area, and the file operation commands to obtain the lightweight file system, and transplant the lightweight file system into the embedded device.
[0078] Specifically, the method for facilitating memory access is based on the above-mentioned memory-access-facilitating reduced file system, which has already introduced in detail how to implement system functions and will not be elaborated here.
[0079] The method for facilitating memory access in this application provides embedded developers with fast and efficient access to the memory of embedded devices. Moreover, on the premise of adding memory access functions, it only requires a small amount of memory occupancy to be compatible with more embedded devices. It can not only provide the command functions of most file systems but also solve the problem of large memory occupancy brought by the file system, greatly improving the efficiency of using memory in embedded devices, thereby enhancing the overall performance and usability of the entire embedded system.
[0080] In some embodiments, the method may further include:
[0081] Through macro definition, system parameters are summarized into a header file, and a function interface for file operation instructions is provided for the embedded device to call the system parameters, where the system parameters include the size of the file index area and the range of the file data area.
[0082] After the functions of the reduced file system are implemented, the code of the reduced file system can be transplanted into the program of the embedded device. The code of the reduced file system is compiled by the C language. The set transplantation module can, through macro definition, summarize system parameters such as the size of the file index area and the range of the file data area into the header file for adjustment, and provide a function interface for file operation instructions. Users only need to call file commands to connect the program of the embedded device to this reduced file system, which is easy to transplant and can be compatible with multiple system platforms.
[0083] The embodiment is only a special case and does not indicate that this application has only such an implementation method.
[0084] The above are only the preferred embodiments of the present invention. Those skilled in the art know that without departing from the spirit and scope of the present invention, these features and embodiments can be variously changed or equivalently replaced. Additionally, under the teaching of the present invention, these features and embodiments can be modified to adapt to specific situations and materials without departing from the spirit and scope of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of this application belong to the protection scope of the present invention.
Claims
1. A streamlined file system that facilitates memory access, characterized in that: It includes a file index area and a file data area set in the memory of the embedded device; the file index area and the file data area are any non-overlapping areas in the memory; The file index area is used to create a file index block corresponding to the file when creating a file, and the file index block is used to store file parameter information, and the file parameter information includes the file name, file type, address of the file content, file length and check bit; The file data area is used to divide the file data area into a first area for sector usage mark, a second area for storing the file content, and a third area for storing the next sector address based on the file index block; When receiving an incoming file operation instruction, the file index area and the file data area perform corresponding file operations according to the file operation instruction.
2. The simplified file system for facilitating memory access according to claim 1, characterized in that: The file data area is also used for setting the next sector address to be empty if the size of the file content does not exceed the range of the second area.
3. The simplified file system for facilitating memory access according to claim 1, characterized in that: The file data area is further used to set the address of the next sector in the third area if the size of the file content exceeds the range of the second area.
4. The simplified file system for facilitating memory access according to claim 1, characterized in that: If the file operation is a file creation operation, the file index area is further used to search for unused file index blocks when receiving a file name to be created, and to put the file name to be created into the unused file index blocks.
5. The simplified file system for facilitating memory access according to claim 1, characterized in that: If the file operation is a file write operation, the file index area is also used to search for the index block corresponding to the file name to be written in the file index area when the file name to be written is received, and to search for the address of the file data area corresponding to the file name to be written at the address of the corresponding index block, and to write the file content corresponding to the file name to be written in the file data area corresponding to the file name to be written.
6. The simplified file system for facilitating memory access according to claim 1, characterized in that: If the file operation is a file read operation, the file index area is also used to search for the index block corresponding to the file name to be read in the file index area when the file name to be read is received, and to search for the address of the file data area corresponding to the file name to be read at the address of the corresponding index block, and to read the file content corresponding to the file name to be read in the file data area corresponding to the file name to be read.
7. The simplified file system for facilitating memory access according to claim 1, characterized in that: If the file operation is a file deletion operation, the file index area is also used to search the file index area for the index block corresponding to the file name to be deleted when the file name to be deleted is received, and to search the address of the file data area corresponding to the file name to be deleted at the address of the corresponding index block, so that the file data area corresponding to the file name to be deleted marks the first area of the corresponding file data area as discarded, erases the file content in the second area, and traverses the sectors used by the file to be deleted through the next sector address of the third area to mark them as discarded.
8. The simplified file system for facilitating memory access according to claim 7, characterized in that: The streamlined file system also includes a cache area, which is used to traverse the file data area marked as abandoned when the file deletion operation is detected, and after taking out the value corresponding to the abandoned index block and putting it in the cache area, erase the abandoned index block to obtain an empty index block.
9. A method for facilitating memory access, applied to the simplified file system for facilitating memory access as claimed in any one of claims 1 to 9, wherein the simplified file system comprises a file index area and a file data area set in the memory of an embedded device; The file index area and the file data area are any non-overlapping areas in the memory, characterized in that: The method comprises: When creating a file, a file index block corresponding to the file is created in the file index area; the file index block is used to store file parameter information, and the file parameter information includes the address of the file content; Based on the file index block, the file data area is divided into a first area for sector usage mark, a second area for storing the file content, and a third area for storing the next sector address; Creating a file operation command based on the file index area and the file data area; The file index area, the file data area and the file operation command are encapsulated to obtain the simplified file system, and the simplified file system is transplanted into an embedded device.
10. The method for facilitating memory access according to claim 9, characterized in that: The method further comprises: Through macro definition, the system parameters are summarized into the header file, and a function interface of the file operation instruction is provided so that the embedded device can call the system parameters, wherein the system parameters include the size of the file index area and the range of the file data area.