Data storage method and electronic equipment
By determining the file index area and file data area of the file object at both ends of the target storage area, the problem of insufficient data storage methods in the existing technology is solved, and the flexible creation and management of file objects is realized, and the access efficiency of files is improved. .
Patent Information
- Application Number
- CN202411515768.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-02-14
AI Technical Summary
The existing data storage methods are not rich enough, making it difficult to achieve flexible creation and management of file objects.
A data storage method is provided, by determining the file index area and file data area of the file object at both ends of the target storage area, and storing the file attributes and file contents at both ends.
It realizes flexible creation and management of file objects, improves file access efficiency, and effectively utilizes storage space.
Smart Images

Figure CN119441146A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of file storage technology, and in particular to a data storage method and an electronic device. Background Art
[0002] Data storage refers to storing information in a certain form. Existing data storage methods in fixed storage space include sequential storage, linked list storage and hash storage. It can be seen that the existing data storage methods are not rich enough. Summary of the invention
[0003] The present application provides a data storage method and electronic device, which can enrich the existing data storage methods. The technical solution is as follows:
[0004] In one aspect, a method for storing a file object is provided, the method comprising:
[0005] In response to a creation instruction for a first file object, determining a file index area and a file data area of the first file object from a target storage area, wherein the file index area and the file data area are located at two ends of the target storage area;
[0006] Storing the file attribute of the first file object in the file index area of the first file object;
[0007] The file content of the first file object is stored in the file data area of the first file object.
[0008] Optionally, the first file object is a file object newly created in the target folder;
[0009] The target storage area is a file data area of the target folder, and the file data area of the target folder is used to store the file content of the target folder;
[0010] The file attributes of the target folder are stored in the file index area of the target folder, and the file index area of the target folder and the file data area of the target folder are located at two ends of the storage space.
[0011] Optionally, the end address of the file index area of the first file object is smaller than the start address of the file data area of the first file object; determining the file index area and the file data area of the first file object from the target storage area includes:
[0012] Determine an end address of a file index area of a first file object based on an end address of the index area in the target storage area, and determine a start address of a file index area of the first file object based on the end address of the file index area of the first file object, the index area being used to store file attributes of each file object included in the target folder;
[0013] Based on the starting address of the data area in the target storage area and the size of the first file object, the starting address of the file data area of the first file object is determined, and the data area is used to store the file content of each file object included in the target folder.
[0014] Optionally, the target storage area further includes: a directory information storage unit for storing basic directory information of the target folder;
[0015] The basic directory information includes: the end address of the index area, the start address of the data area, and the total number of file objects included in the target folder.
[0016] Optionally, after creating the first file object, the method further includes:
[0017] Update the basic information of the directory;
[0018] Among them, the end address of the updated index area is the end address of the file index area of the first file object, the starting address of the updated data area is the starting address of the file data area of the first file object, and the total number after update is greater than the total number before update.
[0019] Optionally, the end address of the directory information storage unit is greater than the start address of the index area in the target storage area.
[0020] Optionally, before creating the first file object, the target folder further includes: a second file object; determining a file index area and a file data area of the first file object from the target storage area includes:
[0021] If it is detected that the remaining memory of the target storage area is greater than the memory occupied by the first file object, determining the file index area and the file data area of the first file object from the target storage area;
[0022] The remaining memory is the memory in the target storage area except the memory occupied by the file index area and the file data area of the second file object.
[0023] Optionally, after storing the file content of the first file object in the file data area of the first file object, the method further includes:
[0024] In response to a read instruction for the first file object, based on an identifier of the first file object, retrieve a file index area of the first file object from an index area of the target storage area;
[0025] Based on the starting address of the file data area of the first file object recorded in the file index area of the first file object, the first file object is read from the file data area of the first file object.
[0026] In another aspect, an electronic device is provided, the electronic device comprising: a processor; the processor is configured to:
[0027] In response to a creation instruction for a first file object, determining a file index area and a file data area of the first file object from a target storage area, wherein the file index area and the file data area are located at two ends of the target storage area;
[0028] Storing the file attribute of the first file object in the file index area of the first file object;
[0029] The file content of the first file object is stored in the file data area of the first file object.
[0030] On the other hand, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the data storage method as described in the above aspects is implemented.
[0031] On the other hand, a computer program product is provided, which includes a computer program or computer instructions, and when the computer program or the computer instructions are executed by a processor, the data storage method as described in the above aspects is implemented.
[0032] The beneficial effects brought about by the technical solution claimed in this application include at least:
[0033] The present application provides a data storage method, which responds to a creation instruction for a first file object, can determine the file index area and file data area of the first file object from the target storage area, and then store the file attributes of the first file object in the file index area, and store the file content of the first file object in the file data area. The file index area and the file data area are located at both ends of the target storage area. It can be seen that when the method provided by the embodiment of the present application creates a new first file object, the file attributes and file content of the first file object can be stored at both ends of the target storage area. Therefore, on the one hand, the storage method of the file object is enriched; on the other hand, it can be convenient to continue to store new file objects in the remaining space in the middle of the target storage area, which is convenient for the flexible creation of file objects, so as to realize flexible management of file objects; on the other hand, by storing the file attributes and file content at both ends of the target storage area, the physical separation of the file attributes and the file content can be realized, so that the access efficiency of the file can be improved in the scenario of searching the file content with the file attributes as the index.
[0034] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 is a flowchart of a method for storing a file object provided by an embodiment of the present application;
[0036] Figure 2 is a flowchart of another method for storing file objects provided in an embodiment of the present application;
[0037] Figure 3 is a schematic diagram of a file data area of a folder provided in an embodiment of the present application;
[0038] Figure 4 is a schematic diagram of a multi-level file object created in a storage space provided in an embodiment of the present application;
[0039] Figure 5 It is a schematic diagram of storage space allocation provided in an embodiment of the present application;
[0040] Figure 6 is another schematic diagram of storage space allocation provided in an embodiment of the present application;
[0041] Figure 7 This is another schematic diagram of storage space allocation provided in an embodiment of the present application;
[0042] Figure 8 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.
[0044] The present application embodiment provides a file operation method, which is applied to an electronic device, such as a file management system of an electronic device. The capacity of the storage area for storing data in the electronic device is fixed. Optionally, the electronic device can be a mobile phone, a tablet computer, a desktop computer or a server. The server can be a single server, or a server cluster composed of several servers, or a cloud computing service center. Figure 1 , the method comprising:
[0045] Step 101: In response to a creation instruction for a first file object, determine a file index area of the first file object and a file data area of the first file object from a target storage area.
[0046] The file index area of the first file object and the file data area of the first file object are located at both ends of the target storage area. For example, the end address of the file index area of the first file object may be smaller than the start address of the file data area of the first file object, that is, the file index area of the first file object is located at the low address end (also referred to as the head end) of the target storage area, and the file data area of the first file object is located at the high address end (also referred to as the tail end) of the target storage area. Alternatively, the end address of the file data area of the first file object may be smaller than the start address of the file index area of the first file object, that is, the file data area of the first file object is located at the head end of the target storage area, and the file data area of the first file object is located at the tail end of the target storage area.
[0047] In an embodiment of the present application, if the first file object is the first file object newly created by the electronic device in its fixed storage space, then the target storage area is the storage space. If the first file object is not the first file object newly created by the electronic device in the storage space, such as the first file object is a file object newly created in a target folder stored in the storage space, then the target storage area can be the file data area of the target folder. The file data area of the target folder is a storage area allocated by the electronic device from the storage space for the target folder to store the file content of the target folder. Optionally, the first file object can be a file (also called a basic file) or a folder (also called a directory file).
[0048] Optionally, the electronic device may display a create button for the file object, and the create instruction may be triggered by a touch operation or a click operation on the create button. Alternatively, the create instruction may be triggered by a voice operation to create the first file.
[0049] Step 102: Store the file attribute of the first file object in the file index area of the first file object.
[0050] After the electronic device determines to obtain the file index area of the first file object, it can record the file attribute of the first file object in the file index area of the first file object to store the file attribute in the file index area of the first file object. It can be understood that the file attributes of files and folders are slightly different.
[0051] Step 103: Store the file content of the first file object into the file data area of the first file object.
[0052] After the electronic device determines to obtain the file data area of the first file object, it can record the file content of the first file object in the file data area of the first file object to store the file content in the file data area of the first file object.
[0053] It is understandable that the file content of a file is the body of the file. The file content of a folder may include: file attributes and file content of each file object in the folder.
[0054] In summary, the embodiment of the present application provides a data storage method, which responds to the creation instruction for the first file object, can determine the file index area and file data area of the first file object from the target storage area, and then store the file attributes of the first file object in the file index area, and store the file content of the first file object in the file data area. The file index area and the file data area are located at both ends of the target storage area. It can be seen that when the method provided by the embodiment of the present application creates a new first file object, the file attributes and file content of the first file object can be stored at both ends of the target storage area. Therefore, on the one hand, the storage method of the file object is enriched; on the other hand, it can be convenient to continue to store new file objects in the remaining space in the middle of the target storage area, which is convenient for the flexible creation of file objects, so as to realize flexible management of file objects; on the other hand, by storing the file attributes and file content at both ends of the target storage area, the physical separation of the file attributes and the file content can be realized, so that the access efficiency of the file can be improved in the scenario of searching the file content with the file attributes as the index.
[0055] This embodiment of the application takes creating a first file object in a target folder as an example to exemplarily illustrate the data storage method provided by the embodiment of the application, and the method is applied to an electronic device. Figure 2 , the method may include:
[0056] Step 201: In response to a creation instruction for a first file object, determine a file index area of the first file object and a file data area of the first file object from a target storage area.
[0057] The file index area of the first file object and the file data area of the first file object are located at both ends of the target storage area. For example, the end address of the file index area of the first file object may be smaller than the start address of the file data area of the first file object, that is, the file data area of the first file object is located at the head end of the target storage area, and the file index area of the first file object is located at the tail end of the target storage area. Alternatively, the end address of the file data area of the first file object may be smaller than the start address of the file index area of the first file object, that is, the file data area of the first file object is located at the head end of the target storage area, and the file data area of the first file object is located at the tail end of the target storage area.
[0058] The target storage area can be a continuous storage area allocated by the electronic device from a continuous storage space for the target folder to store the file content of the target folder, that is, the target storage area is the file data area of the target folder. The file content of the target folder includes: the file attributes and file content of each file object included in the target folder.
[0059] The storage space also includes: a file index area of a target folder, which is used to store the file attributes of the target folder. The file index area of the target folder and the file data area of the target folder are located at both ends of the storage space. For example, the target storage area (i.e., the file data area of the target folder) can be located at the high address end of the storage space, and the file index area of the target folder can be located at the low address end of the storage space. Alternatively, the target storage area can be located at the low address end of the storage space, and the file index area of the target folder can be located at the high address end of the storage space. Among them, the high address end and the low address end are relative.
[0060] It should be understood that the relative positions of the file data areas (or file index areas) of each file object in the storage area are the same, for example, the file data areas are all located at the end of the storage area, and the file index areas are all located at the beginning of the storage area.
[0061] Optionally, the electronic device may display a creation control for a file object. The file creation instruction for the first file object may be triggered by a click operation or a touch operation on the creation control. The first file object may be a file or a folder.
[0062] In the embodiment of the present application, the end address of the file index area of the first file object is greater than the start address of the file data area of the first file object as an example, that is, the file index area of the first file object is located at the head end of the target storage area, and the file data area of the first file object is located at the tail end of the target storage area as an example, and the process of the electronic device determining the file index area and the file data area of the first file object from the target storage area is exemplarily described:
[0063] Figure 3 A schematic diagram showing a file data area of a folder. Figure 3 The target storage area includes: an index area and a data area. The index area in the target storage area is used to store the file attributes of each file object included in the target folder. The data area in the target storage area is used to store the file content of each file object included in the target folder.
[0064] The electronic device may determine the end address of the file index area of the first file object based on the end address of the index area in the target storage area, and determine the start address of the file index area of the first file object based on the end address of the file index area of the first file object. Furthermore, the electronic device may determine the start address of the file data area of the first file object based on the start address of the data area in the target storage area and the size of the first file object. The end address of the index area and the start address of the data area may both be pre-recorded by the electronic device.
[0065] In an embodiment of the present application, the end address of the file index area of the first file object can be obtained by adding the end address of the index area in the target storage area to the capacity of the file index area of the first file object. The starting address of the file index area of the first file object can be obtained by subtracting the capacity of the file index area of the first file object from the end address of the file index area of the first file object. The starting address of the file data area of the first file object can be obtained by subtracting the size of the first file object from the starting address of the data area in the target storage area. The capacity of the file index area of the first file object can be a fixed value pre-stored in the electronic device, and the capacity is slightly larger than the capacity required to store the file attributes of the file object. For example, the capacity of the file index area of the first file object can be 32 bytes.
[0066] According to the above description, the electronic device provided in the embodiment of the present application allocates a file data area matching the size of the file content of the first file object to the first file object in the target storage area completely based on the size of the first file object. In this way, compared with the sequential storage method, there will be no scattered idle space, and the effective allocation of the storage area can be achieved, avoiding the waste of the target storage area, so that the target storage area can be fully utilized.
[0067] Furthermore, since the capacity of the file index area is slightly larger than the capacity required for storing the file attributes of the file object, and the capacity is a fixed value, compared to the linked list storage method, especially when storing a large number of small files and fragmented files, it can effectively avoid the waste of space. In addition, since the method provided in the embodiment of the present application performs continuous storage in the storage space, after power failure, compared to the linked list storage, only the data area needs to be protected, and the linked list information and data information do not need to be protected. Therefore, the storage method provided in the embodiment of the present application is simpler to operate when the system is abnormal.
[0068] It is understandable that the index area of the target storage area may include: file index areas corresponding to the file objects included in the target folder, each file index area is used to store the file attributes of a corresponding file object. The end address of the index area in the target storage area may be: the end address of the file index area with the largest end address among the file index areas corresponding to the file objects included in the target folder. The file index areas corresponding to any two file objects in the target folder have the same size, for example, both are 32 bytes.
[0069] The data area of the target storage area may include: a file data area corresponding to the file objects included in the target folder. The size of each file data area is determined based on the size of the file object. For the file included in the target folder, that is, the file object of the file, the file data area corresponding to the file can store the file content of the file. For the folder included in the target folder, that is, the file object of the folder, the file data area corresponding to the folder can store the file attributes of each file object included in the folder, and the file content of each file object included in the folder. In other words, the file data area corresponding to the folder may include: an index area for storing the file attributes of each file included in the folder, and a data area for storing the file content of the folder. The starting address of the data area in the target storage area may be: the starting address of the file data area with the smallest starting address among the multiple file data areas corresponding to the file objects included in the target folder.
[0070] In the examples of this application, please continue to refer to Figure 3 The target storage area may further include: a directory information storage unit for storing basic directory information of the target folder. The basic directory information may include: an end address of an index area in the target storage area, a start address of a data area in the target storage area, and the total number of file objects included in the target folder. In addition, the target basic information may further include: status information indicating a directory lock state, specific file object information, and other information. The directory lock state is locked or unlocked. The specific file object information may be used for quick retrieval of specific files.
[0071] It can be seen that the electronic device can pre-record the end address of the index area and the start address of the data area in the target storage area in the target information storage unit. Optionally, the size of the target information storage unit can be a fixed value, for example, 16 bytes.
[0072] Since the target storage area can record the basic directory information of the target folder, when creating a new first file object, the electronic device can quickly allocate a file index area and a file data area for the first file object in the target storage area based on the basic directory information.
[0073] Optionally, the end address of the directory information storage unit may be greater than the start address of the file index area in the target storage area. Figure 3 As shown, compared with the file index area, the directory information storage unit is closer to the head end of the target storage area.
[0074] It is understandable that the end address of the index area and the start address of the data area in the target storage area recorded by the electronic device may change as the number of file objects included in the target folder changes. In other words, the space occupied by the index area and the data area may change as file objects are created or deleted. The remaining space between the index area and the data area in the target storage area is always kept in the middle of the target storage area, so that the electronic device can continue to create new file objects and store the newly created file objects in the remaining space.
[0075] Specifically, in the embodiment of the present application, after the creation of the first file object is completed, the electronic device can update the basic directory information recorded in the directory information storage unit. In this way, when the next file object is newly created in the target folder, the electronic device can accurately and quickly determine the file index area for storing the file attributes of the next file object and the file data area for storing the file content of the next file object from the target storage area.
[0076] The end address of the updated index area is the end address of the file index area of the first file object, the start address of the updated data area is the start address of the file data area of the first file object, and the total number of the updated file objects is greater than the total number of the file objects before the update. For example, the total number of the updated file objects is 1 more than the total number of the file objects before the update.
[0077] It is understandable that, assuming that the size of the directory information storage unit is 16 bytes and the target folder is empty, before creating the first file object, the end address of the index area in the target storage area can be the value obtained by adding 16 to the start address of the directory information storage unit and then subtracting 1. The start address of the data area in the target storage area can be the end address of the target storage area.
[0078] In the embodiment of the present application, it is assumed that before the first file object is created, the target folder also includes: a second file object, and accordingly, the target storage area stores the file attributes and file content of the second file object. Specifically, the target storage area also includes: a file index area and a file data area of the second file object, and the file index area and the file data area of the second file object are located at two ends of the target storage area.
[0079] At this time, the process of the electronic device determining the file index area of the first file object and the file data area of the first file object from the target storage area may include: detecting whether the remaining memory of the target storage area is greater than the memory required to be occupied by the first file object, that is, detecting whether the target storage area is sufficient to store the first file object. If the electronic device detects that the remaining memory is greater than or equal to the memory required to be occupied by the first file object, it can be determined that the target storage area is sufficient to store the first file object, and then the file index area of the first file object and the file data area of the first file object can be determined from the target storage area. If the electronic device detects that the remaining memory is less than the content required to be occupied by the first file object, it can be determined that the target storage area cannot store the first file object, and then a prompt message can be issued. The prompt message is used to indicate that there is insufficient space in the target storage area.
[0080] The remaining memory is the memory in the target storage area except the memory occupied by the file index area and the file data area of the second file object. The number of the second file objects can be one or more.
[0081] Optionally, the prompt information may include: at least one of character information and sound information. The character information may be an error status code.
[0082] In the embodiment of the present application, after the electronic device is powered on, the size of the remaining memory of the target storage area can be determined by the end address of the index area and the start address of the data area in the basic directory information of the target folder. For example, the size of the remaining memory can be the difference between the start address and the end address and 1.
[0083] It can be determined without a doubt that after a new file object is created in the target folder, the end address of the index area and the start address of the data area recorded in the target information storage unit are updated in time, and the electronic device can also accurately and quickly obtain the remaining memory of the target storage area, thereby allocating storage area for the newly created file object in real time.
[0084] Step 202: Store the file attribute of the first file object in the file index area of the first file object.
[0085] In the embodiment of the present application, if the first file object is a file, the content of the file attribute of the first file object may be as shown in Table 1. As can be seen from Table 1, the file attributes of the file may include: file identifier, file type and line protection attribute, file size, starting address and reserved bit, etc. The starting address is the starting address of the file data area of the file object.
[0086] Table 1
[0087]
[0088] Optionally, the capacity of the file index area of the first file object can be a fixed value, for example, 32 bytes. In this case, the file identifier in the file attributes can occupy 2 bytes. The file type and line protection attributes can occupy 1 byte, and the first bit (bit, i.e., bit0) to the fifth bit bit5 in the 1 byte are used to record characters indicating the file type, and bit6 and bit7 are used to record characters indicating line protection attributes. The character can be 00, 01 or 11. 00 indicates that the file is plain text, and 01 indicates that a message authentication code (MAC) check is required for the file. 11 means that the file is ciphertext and a MAC check is required.
[0089] The file size can occupy 2 bytes, the file read permission, file write permission, file read and write operation mode and protection key identification can each occupy 1 byte. The starting address of the file can occupy 4 bytes, and the reserved bit occupies 20 bytes.
[0090] As shown in Table 1, in the 1 byte occupied by the file read and write operation mode and the protection key identifier, the character recorded in bit7 is used to indicate the read mode, and the character can be 0 or 1. 0 indicates that line protection read is not supported, and 1 indicates that line protection read is used. Bits 4 to 6 are reserved bits, bits 2 and 3 are recorded to indicate the read operation key identifier, and bits 0 and 1 are recorded to indicate the write operation key identifier. The read operation key identifier is the identifier of the key required when reading a file, and the write operation key identifier is the identifier of the key required when writing a file.
[0091] If the first file object is a folder, the content of the file attribute of the first file object may be as shown in Table 2. Figure 2 It can be seen that the file attributes of the first file object may include: file identifier, file type, file size, file creation permission, file erasure permission, directory name related information, etc.
[0092] Table 2
[0093] project Size (bytes) File Identifier 2 File Type 1 File size 2 File creation permissions 1 File Erase Permission 1 Key establishment and erasure identification 1 Starting address 4 Directory name related information 20
[0094] Continuing with the example that the capacity of the file index area of the first file object is 32 bytes, the file identifier and file size can occupy 2 bytes respectively. The file type, file creation permission, file erasure permission, key creation and erasure flag can occupy 1 byte respectively. The starting address can occupy 4 bytes, and the directory name related information can occupy 20 bytes, etc. The directory name related information can include: file control information (FCI). The FCI can include: the name of the folder, other information such as the file identifier that expands the FCI, and a data byte string that can be used to respond to the file selection command, etc.
[0095] Step 203: Store the file content of the first file object into the file data area of the first file object.
[0096] After determining to obtain the file data area of the first file object, the electronic device may store the file content of the first file object in the file data area of the first file object.
[0097] It is understandable that the file content of a file is the body of the file. The file content of a folder may include: file attributes and file content of each file object in the folder.
[0098] Step 204: In response to the read instruction for the first file object, based on the identifier of the first file object, retrieve the file index area of the first file object from the index area of the target storage area.
[0099] After obtaining the read instruction of the first file object, the electronic device can search the index area in the target storage area based on the identifier of the first file object to retrieve the file index area of the first file object. The identifier of the first file object can be an identifier or a name of the first file object.
[0100] Optionally, the electronic device may display a read button for the first file object. The read instruction may be triggered by a click operation or a touch operation on the read button.
[0101] Step 205: Read the first file object from the file data area of the first file object according to the starting address of the file data area of the first file object recorded in the file index area of the first file object.
[0102] After the electronic device retrieves the file index area of the first file object, it can read the starting address of the file data area of the first file object and the file size of the first file object from the file index area of the first file object. Then, the electronic device can determine the ending address of the file data area of the first file object based on the starting address of the file data area of the first file object and the file size, thereby obtaining the storage location of the file content of the first file object, that is, the file data area of the first file object. Afterwards, the electronic device can read the first file object from the file data area of the first file object.
[0103] It is understandable that, since the file data areas allocated to each file object are all continuous storage areas, when a file object needs to be accessed, the file data area of the file object can be quickly located by only using the starting address and file size recorded in the file index area of the file object to read the file object. It can be seen that the data storage method provided in the embodiment of the present application greatly improves the access efficiency of files.
[0104] In the embodiment of the present application, assuming that the first file object is a folder, the electronic device can also create a new file object in the first file object. The process of the electronic device creating a new file object in the first file object can refer to the relevant implementation process of creating the first file object in the target folder, and the embodiment of the present application will not be repeated here.
[0105] Assume that the electronic device creates a multi-level file object in the storage space such as Figure 4 As shown, from Figure 4 It can be seen that the multi-level file object includes: a first-level folder DF01, first-level files EF01 and EF02; a second-level folder DF11, second-level basic files EF11 and EF12 established under the first-level folder DF01; a third-level folder DF21, second-level files EF21 and EF22 established under the second-level folder DF11.
[0106] Assume that the starting address of the storage space is 0000, the size is 65536 bytes, the size of the file index area used to store the file attributes of each file object is 32 bytes, and the size of the directory information storage unit of each folder is 16 bytes. Then, for Figure 4 For a multi-level file object as shown, the storage space can be allocated as follows Figure 5 As shown. Figure 5It can be seen that the storage space can be divided into: a storage unit for storing basic information of the root directory, an index area and a data area in the storage space. The index area and the data area are located at both ends of the storage space. The index area includes: a file index area of the first-level folder DF01 (referred to as the DF01 file index area), and a file index area of each first-level file in the first-level files EF01 and EF02, namely the EF01 file index area and the EF02 file index area. The DF01 file index area, the EF01 file index area and the EF02 file index area are arranged in the form of a list, and are all 32 bytes.
[0107] The data area in the storage space includes: the file data area of the first-level folder DF01 (referred to as DF01 file data area), the EF01 file data area and the EF02 file data area. The size and address of each partition (such as storage unit, file data area or file index area) are detailed in Figure 5 . Figure 5 0x indicates hexadecimal.
[0108] Please continue to see Figure 5 The DF01 file data area may include: a storage unit for storing basic information of the DF01 directory, an index area and a data area in the file data area. The index area includes: a DF11 file index area, an EF11 file index area and an EF12 file index area. The data area includes: a DF11 file data area, an EF11 file data area and an EF12 file data area.
[0109] The composition of the file data area of the secondary folder DF11 is similar to that of the file data area of the primary folder DF01 , and the embodiment of the present application will not further describe the composition of the file data area of the secondary folder DF11 .
[0110] based on Figure 5 If it is necessary to create another file EF03 with a size of 4K (i.e., 0x1000) in the storage space, the electronic device can directly allocate a file index area for the file EF03 from the remaining space indicated by the address 0x0070-0xA7FF to store the file attributes of the file EF03, and allocate a file data area for the file EF03 to store the file content of the file EF03.
[0111] The end address of the file index area of file EF03 is the sum of the end address of the file index area of file EF02 (i.e., the end address of the index area in the storage space) 0x006F and 0x0020 (i.e., 16 bytes), 0x008F. The start address of the file data area of file EF03 is the difference 0x9800 obtained by subtracting 0x1000 (i.e., 4K) from the start address of the file data area of file EF02 (i.e., the start address of the data area in the storage space) 0xA800. At this time, the allocation of storage space can be as follows: Figure 6 shown.
[0112] based on Figure 5 If it is necessary to create a DF02 folder with a size of 8K (i.e. 0x2000) in the storage space, the electronic device can allocate the file index area and the file data area for the folder DF02 from the remaining space indicated by the address 0x0070-0xA7FF. The process of the electronic device determining the end address of the file index area of the folder DF02 and the starting address of the file data area can refer to the related implementation process of determining the file index area and the file data area of the file EF03 in the previous text, and the embodiments of the present application will not be repeated here. At this time, the allocation of storage space can be as follows: Figure 7 shown.
[0113] It is understandable that if a file object is created in the folder DF02, it can be stored according to the directory file storage structure, and a file index area and a file data area are allocated to the created file object in the file data area of the folder DF02.
[0114] according to Figures 5 to 7 As shown, the data storage method provided by the embodiment of the present application performs continuous storage in the storage space, and the file index area and file data area of each file object are distributed at both ends of the file data area of the folder to which the file object belongs. And for each folder, the electronic device can sequentially store the file objects included in the folder from both ends of the file data area of the folder to the middle. As a result, the allocation of file attributes and file contents of the file objects is clearer, thereby improving the reading and writing efficiency of the file objects.
[0115] Furthermore, the method provided in the embodiment of the present application supports multi-level creation of file objects, any two levels of file objects are independent of each other, and supports fast and flexible reading and writing operations of file objects, fully utilizing the storage space, and the method is easy to operate.
[0116] In the field of data storage, especially for data storage with fixed storage space such as smart cards, security modules and terminals, and application scenarios that require file system management, how to efficiently utilize storage space and achieve flexible file management has become an important technical challenge.
[0117] Existing data storage methods for fixed storage space include sequential storage, linked list storage, and hash storage. Sequential storage is to store data in a continuous storage area in sequence. Linked list storage is a discrete storage method, in which data blocks are linked by linked lists. Specifically, in addition to storing data, each linked list node also needs to store a pointer to the next linked list node. Hash storage (also known as hash storage) can evenly distribute data elements in the storage space through hash functions to increase the speed of data access.
[0118] However, sequential storage does not support flexible operations such as adding, reading or deleting files, and wastes a lot of space. In addition, if you want to retrieve intermediate data, you must traverse the linked list node by node until you find the target location, which leads to low access efficiency when accessing large data files or scenarios where frequent random access is required. It can be seen that sequential storage is not suitable for data storage in multi-file or multi-level file systems.
[0119] Although linked list storage is flexible, the access operation is relatively complicated. As the length of the linked list increases, the space occupied by the pointer will also increase accordingly, which may lead to a waste of storage space. This waste is particularly obvious when storing a large number of small files or fragmented files. Hash storage does not support range queries. Therefore, when querying files, users need to query by file name, creation date or other attribute content, which is inefficient.
[0120] The embodiment of the present application provides a data storage method, which, in response to a creation instruction for a first file object, can determine a file index area and a file data area of the first file object from a target storage area, and then store the file attributes of the first file object in the file index area, and store the file content of the first file object in the file data area. Since the file index area and the file data area are located at both ends of the target storage area, it is convenient to continue to create new file objects in the remaining space in the middle of the target storage area, thereby facilitating the flexible creation of file objects.
[0121] Furthermore, by storing the file attributes and the file contents at both ends of the target storage area respectively, the physical separation of the file attributes and the file contents can be achieved, so that when accessing a file through the file attributes, the file data area of the file can be quickly determined, thereby achieving fast access and query of the file object.
[0122] It is understandable that the sequence of the steps of the data storage method provided in the embodiment of the present application can be appropriately adjusted, and the steps can also be increased or decreased accordingly according to the situation. For example, step 204 and step 205 can also be deleted according to the situation. Any technician familiar with the technical field can easily think of the method of change within the technical scope disclosed in this application, which should be included in the protection scope of this application, so it will not be repeated.
[0123] In summary, the embodiment of the present application provides a data storage method, which responds to the creation instruction for the first file object, can determine the file index area and file data area of the first file object from the target storage area, and then store the file attributes of the first file object in the file index area, and store the file content of the first file object in the file data area. The file index area and the file data area are located at both ends of the target storage area. It can be seen that when the method provided by the embodiment of the present application creates a new first file object, the file attributes and file content of the first file object can be stored at both ends of the target storage area. Therefore, on the one hand, the storage method of the file object is enriched; on the other hand, it can be convenient to continue to store new file objects in the remaining space in the middle of the target storage area, which is convenient for the flexible creation of file objects, so as to realize flexible management of file objects; on the other hand, by storing the file attributes and file content at both ends of the target storage area, the physical separation of the file attributes and the file content can be realized, so that the access efficiency of the file can be improved in the scenario of searching the file content with the file attributes as the index.
[0124] The embodiment of the present application provides an electronic device, which can be used to execute the data storage method provided by the above method embodiment. Figure 8 The electronic device 300 includes a processor 301. The processor 301 is used to:
[0125] In response to a creation instruction for a first file object, determining a file index area and a file data area of the first file object from a target storage area, wherein the file index area and the file data area are located at two ends of the target storage area;
[0126] Storing the file attribute of the first file object in the file index area of the first file object;
[0127] The file content of the first file object is stored in the file data area of the first file object.
[0128] Optionally, the first file object is a file object newly created in the target folder;
[0129] The target storage area is a file data area of a target folder, and the file data area of the target folder is used to store the file content of the target folder;
[0130] The file attributes of the target folder are stored in the file index area of the target folder. The file index area of the target folder and the file data area of the target folder are located at two ends of the storage space.
[0131] Optionally, the end address of the file index area of the first file object is less than the start address of the file data area of the first file object. The process of the processor 301 determining the file index area and the file data area of the first file object from the target storage area may include:
[0132] Based on the end address of the index area in the target storage area, determine the end address of the file index area of the first file object, and based on the end address of the file index area of the first file object, determine the start address of the file index area of the first file object, the index area being used to store file attributes of each file object included in the target folder;
[0133] Based on the starting address of the data area in the target storage area and the size of the first file object, the starting address of the file data area of the first file object is determined, and the data area is used to store the file content of each file object included in the target folder.
[0134] Optionally, the target storage area further includes: a directory information storage unit for storing basic directory information of the target folder;
[0135] The basic directory information includes: the end address of the index area, the start address of the data area, and the total number of file objects included in the target folder.
[0136] Optionally, after creating the first file object, the processor 301 may also be used to:
[0137] Update basic directory information;
[0138] Among them, the end address of the updated index area is the end address of the file index area of the first file object, the start address of the updated data area is the start address of the file data area of the first file object, and the total number after update is greater than the total number before update.
[0139] Optionally, the end address of the directory information storage unit is greater than the start address of the index area in the target storage area.
[0140] Optionally, before creating the first file object, the target folder further includes: a second file object. The processor 301 may be configured to:
[0141] If it is detected that the remaining memory of the target storage area is greater than the memory occupied by the first file object, determining the file index area and the file data area of the first file object from the target storage area;
[0142] The remaining memory is the memory in the target storage area except the memory occupied by the file index area and the file data area of the second file object.
[0143] Optionally, the processor 301 may also be used for:
[0144] After storing the file content of the first file object in the file data area of the first file object, in response to a read instruction for the first file object, based on an identifier of the first file object, retrieve a file index area of the first file object from an index area of the target storage area;
[0145] The first file object is read from the file data area of the first file object based on the start address of the file data area of the first file object recorded in the file index area of the first file object.
[0146] In summary, an embodiment of the present application provides an electronic device, which, in response to a creation instruction for a first file object, can determine a file index area and a file data area of the first file object from a target storage area, and then store the file attributes of the first file object in the file index area, and store the file content of the first file object in the file data area. The file index area and the file data area are located at both ends of the target storage area. It can be seen that when the electronic device provided by the embodiment of the present application creates a new first file object, the file attributes and the file content of the first file object can be stored at both ends of the target storage area. Thus, on the one hand, the storage method of the file object is enriched; on the other hand, it can be convenient to continue to store new file objects in the remaining space in the middle of the target storage area, which is convenient for the flexible creation of file objects, so as to realize flexible management of file objects; on the other hand, by storing the file attributes and the file content at both ends of the target storage area, the physical separation of the file attributes and the file content can be realized, so that the access efficiency of the file can be improved in the scenario of searching the file content with the file attributes as the index.
[0147] like Figure 8 As shown, the electronic device 300 also includes: a memory 303. The processor 301 and the memory 303 are connected, such as through a bus 302. Optionally, the electronic device 300 may also include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the electronic device 300 does not constitute a limitation on the embodiments of the present application.
[0148] Processor 301 may be a CPU (Central Processing Unit), a general purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0149] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0150] The memory 303 is used to store a computer program corresponding to the data storage method of the above embodiment of the present application, and the computer program is controlled and executed by the processor 301. The processor 301 is used to execute the computer program stored in the memory 303 to implement the content shown in the above method embodiment.
[0151] Among them, the electronic device 300 includes but is not limited to: mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The electronic device 300 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0152] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the data storage method provided in the above method embodiment is implemented. For example, Figure 1 or Figure 2 The method shown.
[0153] The present application also provides a computer program product, which includes a computer program or a computer instruction. When the computer program or the computer instruction is executed by a processor, the data storage method provided in the above method embodiment is implemented. For example, Figure 1 or Figure 2 The method shown.
[0154] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.
[0155] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0156] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0157] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0158] In this application, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.
[0159] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A method for storing a file object, characterized in that: The method comprises: In response to a creation instruction for a first file object, determining a file index area and a file data area of the first file object from a target storage area, wherein the file index area and the file data area are located at two ends of the target storage area; Storing the file attribute of the first file object in the file index area of the first file object; The file content of the first file object is stored in the file data area of the first file object.
2. The method according to claim 1, characterized in that The first file object is a file object newly created in the target folder; The target storage area is a file data area of the target folder, and the file data area of the target folder is used to store the file content of the target folder; The file attributes of the target folder are stored in the file index area of the target folder, and the file index area of the target folder and the file data area of the target folder are located at two ends of the storage space.
3. The method according to claim 2, characterized in that The end address of the file index area of the first file object is smaller than the start address of the file data area of the first file object; Determining the file index area and the file data area of the first file object from the target storage area includes: Determine an end address of a file index area of a first file object based on an end address of the index area in the target storage area, and determine a start address of a file index area of the first file object based on the end address of the file index area of the first file object, the index area being used to store file attributes of each file object included in the target folder; Based on the starting address of the data area in the target storage area and the size of the first file object, the starting address of the file data area of the first file object is determined, and the data area is used to store the file content of each file object included in the target folder.
4. The method according to claim 3, characterized in that: The target storage area further comprises: a directory information storage unit for storing basic directory information of the target folder; The basic directory information includes: the end address of the index area, the start address of the data area, and the total number of file objects included in the target folder.
5. The method according to claim 4, characterized in that After creating the first file object, the method further includes: Update the basic information of the directory; Among them, the end address of the updated index area is the end address of the file index area of the first file object, the starting address of the updated data area is the starting address of the file data area of the first file object, and the total number after update is greater than the total number before update.
6. The method according to claim 4, characterized in that The end address of the directory information storage unit is greater than the start address of the index area in the target storage area.
7. The method according to any one of claims 1 to 6, characterized in that: Before creating the first file object, the target folder further includes: a second file object; determining a file index area and a file data area of the first file object from the target storage area, including: If it is detected that the remaining memory of the target storage area is greater than the memory occupied by the first file object, determining the file index area and the file data area of the first file object from the target storage area; The remaining memory is the memory in the target storage area except the memory occupied by the file index area and the file data area of the second file object.
8. The method according to any one of claims 1 to 6, characterized in that: After storing the file content of the first file object in the file data area of the first file object, the method further includes: In response to a read instruction for the first file object, based on an identifier of the first file object, retrieve a file index area of the first file object from an index area of the target storage area; Based on the starting address of the file data area of the first file object recorded in the file index area of the first file object, the first file object is read from the file data area of the first file object.
9. An electronic device, characterized in that: The electronic device comprises: a processor; the processor is used for: In response to a creation instruction for a first file object, determining a file index area and a file data area of the first file object from a target storage area, wherein the file index area and the file data area are located at two ends of the target storage area; Storing the file attribute of the first file object in the file index area of the first file object; The file content of the first file object is stored in the file data area of the first file object.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Cited By
File storage method and file storage system
CN121578938A