Method for processing file, storage medium and electronic device
By caching the file information list and reserving contiguous storage space during the file system repair process, the problem of excessively long file operation time is solved, achieving fast file reading and deletion.
Patent Information
- Application Number
- CN202210806303.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-08
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2042-07-08
AI Technical Summary
Existing technologies cannot quickly retrieve the file information list during cyclic deletion of files, resulting in excessively long file operation times. This is especially true when there are many files on the storage device, where reading the file information list can take several minutes, which cannot meet product requirements.
During the file system repair process, a list of all file information is cached, and file operations are performed using the cached list of file information. This eliminates the step of reading the file information list from the kernel and reserves contiguous storage space to avoid file directory fragmentation.
It significantly shortens the overall time of file operations, improves the efficiency of file reading and deletion, reduces the steps the file system takes to read the file information list from the kernel, and meets the product's need for fast operation.
Smart Images

Figure CN115309699B_ABST
Abstract
Description
Technical Field
[0001] This invention generally relates to the field of document processing technology, and in particular to methods, storage media and electronic devices for processing documents. Background Technology
[0002] Currently, products that record loops, such as IPCs (IP cameras, network cameras), require a loop-based file deletion function. When performing loop-based file deletion, it's necessary to first know the total number of files in the storage space of the disk / card or other storage device, their creation dates, and file sizes; this will be referred to as a file information list. When the storage space is nearly full, files need to be deleted sequentially from oldest to newest, based on their creation date. Furthermore, during media library playback, it's necessary to quickly sort all files by their thumbnails.
[0003] However, the normal sorting method involves reading and sorting simultaneously, so it's not possible to quickly find the latest file. Based on actual testing, reading the entire list of over 20,000 files from a single card would take several minutes, a reading time that is clearly unacceptable for many products. Summary of the Invention
[0004] This disclosure provides methods, storage media, and electronic devices for processing files, which can solve the problem of not being able to quickly obtain a list of file information and apply the obtained list of file information to perform various operations.
[0005] In a first aspect of this disclosure, a method for processing files is provided. The method includes: obtaining the formatting state of a storage device storing files; if the formatting state is unformatted, formatting the storage device and reserving contiguous storage space for different directories in the storage device during formatting; and if the formatting state is formatted, performing file system repair on the storage device to parse a list of file information associated with the files, and caching the list of file information on the storage device for processing the files.
[0006] In one embodiment of the present invention, the method further includes: performing read and write operations on the file according to the cached file information list.
[0007] In one embodiment of the present invention, the method further includes: previewing and / or cyclically deleting the file according to the cached file information list.
[0008] In one embodiment of the present invention, previewing and / or repeatedly deleting a file based on the cached file information list includes: determining whether the repair code corresponding to the file information list is compiled into the same executable application as the user's required application; if yes, determining it to be a same-process transfer, and transferring the memory address corresponding to the file information list to the user's required application in the application layer; and if no, determining it to be a cross-process transfer, and transferring the file information list to the user's required application through cross-process transfer.
[0009] In one embodiment of the present invention, obtaining the formatting status of a storage device storing files includes: obtaining the formatting status of an inserted disk or memory card.
[0010] In one embodiment of the present invention, formatting the storage device and reserving contiguous storage space for different directories in the storage device during formatting includes: estimating the number of clusters required for each directory based on the capacity of the storage device and the storage file types of different directories; and reserving contiguous storage space for different directories in the storage device based on the number of clusters.
[0011] In one embodiment of the present invention, the storage device includes a first directory and a second directory. The first directory stores video files, and the second directory stores image files. Estimating the number of clusters required for each directory based on the capacity of the storage device and the file types stored in different directories includes: determining the number of video files to be stored based on the format requirements of the video files and the capacity of the storage device, and estimating the number of clusters required for the first directory based on the number of video files to be stored; and determining the number of image files to be stored based on the format requirements of the image files and the capacity of the storage device, and estimating the number of clusters required for the second directory based on the number of image files to be stored.
[0012] In one embodiment of the present invention, performing file system repair on the storage device to parse the file information list associated with the file includes: reading a preset file table and various directory information according to the rules of a preset file system; parsing all file information lists of the storage device from the directory information; comparing all file information lists with the preset file table to determine the damaged file, and repairing the damaged file.
[0013] In a second aspect of this disclosure, a computer-readable storage medium is provided. The storage medium stores a computer program that, when executed by a processor, implements the described method for processing files.
[0014] In a third aspect of this disclosure, an electronic device is provided. The electronic device includes: a processor and a memory; the memory is configured to store a computer program, and the processor is configured to execute the computer program stored in the memory to cause the electronic device to perform the method for processing files.
[0015] In the method, storage medium, and electronic device for processing files according to embodiments of this disclosure, when formatting the storage device, a corresponding contiguous space can be reserved for different file directories based on the product's form factor. This avoids file directory fragmentation and saves some file read time. Furthermore, during file system repair, by caching the entire file information list during the repair process, the step of reading the file information list from the kernel in the existing method is omitted, thereby significantly shortening the overall file operation time. Attached Figure Description
[0016] Figure 1 This is a flowchart illustrating a method for processing files according to an embodiment of the present invention.
[0017] Figure 2 This is a flowchart illustrating formatting in a method for processing files according to an embodiment of the present invention.
[0018] Figure 3 This is a flowchart illustrating the repair process in a method for processing files according to an embodiment of the present invention.
[0019] Figure 4 This is a flowchart illustrating a method for processing files according to an embodiment of the present invention, specifically a file reading process.
[0020] Figure 5 This is a block diagram illustrating an electronic device according to an embodiment of the present invention. Detailed Implementation
[0021] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.
[0022] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Therefore, the illustrations only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0023] In existing technical solutions, taking the FAT32 (File Allocation Table) file system as an example, when a card or disk is first inserted into the device, the device needs to read the information list of all files in the card or disk, which requires three steps: (1) If it has not been formatted, the card or disk needs to be formatted first; (2) File system repair is performed; (3) The file information list in the card is read from the kernel. Usually, the function of deleting files in a loop or the file manager traverses all files from the kernel. If there are many files, the whole process will be very time-consuming.
[0024] To address at least the aforementioned technical issues, this disclosure provides a solution for handling files that caches a list of all file information during the repair process, omitting the step of the normal file system reading the file information list from the kernel in existing methods, thereby significantly reducing the overall time of file operations.
[0025] The following will combine Figures 1 to 5 This embodiment details the principles and implementation methods of the file processing method, storage medium, and electronic device, enabling those skilled in the art to understand the file processing method, storage medium, and electronic device without creative effort.
[0026] Figure 1 A flowchart illustrating a method for processing files according to an embodiment of the present invention is shown. Figure 1 As shown, the method specifically includes the following steps S11 to S12.
[0027] In step S11, the formatting status of the storage device containing the files is obtained.
[0028] In one embodiment, step S11 includes: obtaining the formatting status of the inserted disk or the inserted memory card. Specifically, the formatting status includes unformatted and formatted.
[0029] In step S12, if the formatting state is unformatted, the storage device is formatted, and during formatting, contiguous storage space is reserved for different directories in the storage device.
[0030] Specifically, the reserved storage space in the directory is used to store information about all files or folders in the directory. The information includes file size, file name, creation time, and index of file data (where the file data is stored in other clusters, and the information stored in the reserved storage space only stores the index of its starting cluster), etc.
[0031] In step S13, if the formatting status is "formatted", the storage device is repaired to parse the file information list associated with the file, and the file information list of the storage device is cached for processing the file.
[0032] According to embodiments of this disclosure, by caching a list of all file information during the file system repair process and performing various operations on files based on the cached list of file information, the step of reading the file information list from the kernel is omitted, thereby significantly reducing the overall time of file operations.
[0033] Figure 2 A flowchart illustrating formatting in a method for processing files according to an embodiment of the present invention is shown. Figure 2 As shown, step S12 specifically includes steps S121 to S122.
[0034] In step S121, the number of clusters required for each directory is estimated based on the capacity of the storage device and the storage file types of different directories.
[0035] In one embodiment, the storage device includes a first directory and a second directory, wherein the first directory stores video files and the second directory stores image files. S121 specifically includes the following steps.
[0036] First, the number of video files to be stored is determined based on the format requirements of the video files and the capacity of the storage device, and the number of clusters required for the first directory is estimated based on the number of video files to be stored.
[0037] Specifically, the first directory is directory A. Based on the card's capacity and product requirements, such as whether the videos and photos are 4K or 1080P, and assuming directory A contains videos, after estimation, there will be approximately how many files. For example, if a card is 16GB, it can store approximately 200 videos. From this, we can calculate approximately how many clusters directory A will need. During formatting, we can directly reserve a contiguous and sufficient storage space for directory A.
[0038] Secondly, the number of image files to be stored is determined based on the format requirements of the image files and the capacity of the storage device, and the number of clusters required for the second directory is estimated based on the number of image files to be stored.
[0039] Specifically, the second directory is directory B. Based on the card's capacity and product requirements, such as whether the videos and photos are 4K or 1080P, directory B is assumed to contain photos. After estimation, it is estimated how many files there will be. For example, if a card is 16G and can store about 2000 photos, the number of clusters required for directory B can be calculated. During formatting, a contiguous and sufficient storage space is reserved for directory B.
[0040] In step S122, contiguous storage space is reserved for different directories in the storage device based on the number of clusters.
[0041] Figure 3 This is a flowchart illustrating the repair process in a method for processing files according to an embodiment of the present invention. Figure 3 As shown, step S13 specifically includes steps S131 to S133.
[0042] In step S131, according to the rules of the preset file system, the preset file table and information of each directory are read.
[0043] Specifically, file system repair follows the rules of the corresponding file system type. For example, with FAT32, it uses FAT32 rules to identify whether any files on the disk are corrupted, and if so, repairs them using FAT32 rules. The repaired file information list only needs to retain the file information lists of the directories specified by the application layer, and then it is passed to the application. Taking the FAT32 file system as an example, the FAT table and information of each directory are read according to FAT32 rules. Furthermore, other file systems are handled similarly to the FAT32 file system when executing the file processing method of this invention.
[0044] In step S132, a list of all file information of the storage device is parsed from the directory information.
[0045] Specifically, information about all files is parsed from the directory information, and this parsed file information is cached for use by other applications, such as a file circular deletion function or a file manager. Normally, a file circular deletion function or file manager traverses all files from the kernel, which can be very time-consuming if there are many files. Step S132 of this invention can eliminate this time.
[0046] In practical applications, the cached file information list is stored in ddr memory, and the information includes the file name, path, size and attributes of each file.
[0047] In step S133, the list of all file information is compared with the preset file table to identify the damaged files and repair them.
[0048] Specifically, based on the information of all files parsed from the directory information, the data is compared with the FAT table to determine which files are corrupted. If a file is corrupted, the FAT table or the file information is modified to repair it.
[0049] In one embodiment, after the step of caching a list of all file information on the storage device, the method for processing files further includes: performing read and write operations on the files according to the cached list of file information. In some embodiments, the method involves reading file information required by the user according to the list of file information, and performing read and write operations on the file information in response to the user's read and write requests.
[0050] In one embodiment, after the step of caching a list of all file information of the storage device, the method for processing files further includes: previewing and / or cyclically deleting the files according to the cached list of file information.
[0051] In some embodiments, the file information list is transmitted to the user's desired application to perform previewing and / or cyclic deletion of the files corresponding to the file information list. Specifically, the cached file information list is transmitted to the application layer. If it is the same process, the memory address is directly transmitted to the application layer; if it is a different process, the file information list is transmitted through inter-process communication.
[0052] Specifically, the step of transmitting the file information list to the user's desired application and performing preview and / or cyclic deletion of the files corresponding to the file information list includes the following steps.
[0053] It determines whether the repair code corresponding to the file information list is compiled into the same executable application as the user's required application. Specifically, if the file repair code is made into a library or compiled into the same executable application as the application, it is determined to be in the same process. If the file repair code is compiled into a separate executable application, it is determined to be in a different process.
[0054] If so, it is determined to be a same-process transfer, and the memory address corresponding to the file information list is transferred to the user's required application in the application layer.
[0055] If not, it is determined to be a cross-process transfer, and the file information list is transferred to the user's required application via cross-process transfer. Specifically, during cross-process transfer, the file repair code is made into a library or compiled into the same executable application as the application. The application layer code directly calls the function to start the file repair function, and returns the file list information after the repair is completed. Cross-process communication can be achieved through socket communication or shared memory to transfer all file information.
[0056] Please see Figure 4 The diagram shows a file reading flowchart of a method for processing files according to an embodiment of the present invention. Figure 4 As shown, firstly, after inserting the card or disk, it is determined whether the card or disk has been formatted. If not, the card or disk is formatted. Formatting refers to pre-creating directories in a contiguous area according to the product form. The created directories refer to the created folders. After formatting, as shown in the right figure, a FAT table, directory A, directory B, directory B, and free clusters are obtained. In this embodiment, directory A or folder A is estimated to require two clusters. The first directory A represents the first cluster corresponding to folder A, and the second directory A represents the second cluster corresponding to folder A. The same applies to directory B. Free clusters are used as clusters for directory A when the estimated value of directory A is insufficient. By pre-allocating the number of clusters according to different folder directories during formatting, contiguous space is pre-allocated. The purpose is to ensure that each reserved space is just right or slightly more for each directory based on the estimation. When the estimation is insufficient, free clusters are used to supplement it. If formatting is complete, file system repair is performed. After parsing the information of all files in the entire disk, this information is cached. When the card or disk reaches the Ready state, the user can perform read and write operations. The operation of reading and writing the card / disk refers to directly reading the required information based on the file information list cached during the repair process, and then performing read and write operations.
[0057] The scope of protection of the method for processing files described in this invention is not limited to the execution order of the steps listed in this embodiment. Any solution implemented by adding, subtracting, or replacing steps in the prior art based on the principles of this invention is included within the scope of protection of this invention.
[0058] This embodiment provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for processing files.
[0059] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented using computer program-related hardware. The aforementioned computer program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned computer-readable storage medium includes various computer storage media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0060] Please see Figure 5 The diagram shows a structural connection schematic of the electronic device of the present invention in one embodiment. Figure 5 As shown, this embodiment provides an electronic device 5, specifically including: a processor 51 and a memory 52; the memory 52 is used to store computer programs, and the processor 51 is used to execute the computer programs stored in the memory 52, so that the electronic device 5 performs the various steps of the method for processing files.
[0061] The processor 51 mentioned above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0062] The aforementioned memory 52 may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device.
[0063] In practical applications, the electronic device may be a computer capable of reading file information from a storage device, including all or some components such as a memory, a storage controller, one or more processing units (CPUs), peripheral interfaces, RF circuits, audio circuits, speakers, microphones, input / output (I / O) subsystems, a display screen, other output or control devices, and external ports. The computer includes, but is not limited to, personal computers such as desktop computers, laptops, tablets, smartphones, and personal digital assistants (PDAs). In other embodiments, the electronic device may also be a server, which may be deployed on one or more physical servers based on factors such as function and load, or it may be a cloud server composed of distributed or centralized server clusters; this embodiment does not impose such limitations.
[0064] In summary, the file processing method, storage medium, and electronic device described in this invention can reserve a corresponding contiguous space for different file directories based on the product's form factor during storage device formatting. This avoids file directory fragmentation and saves file reading time. During file system repair, by caching the entire file information list during the repair process, the step of reading the file information list from the kernel in existing methods is omitted, thereby significantly shortening the overall file operation time. This invention effectively overcomes the various shortcomings of existing technologies and has high industrial application value.
[0065] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.
Claims
1. A method for processing files, characterized in that, include: Get the formatting status of the storage device containing files, where the files are those used for previewing and / or cyclic deletion operations; If the formatting status is unformatted, the storage device is formatted, and during formatting, contiguous storage space is reserved for different directories in the storage device. The storage space is used to store information about all files or folders in the directory. The information includes file size, file name, creation time, and index of file data. as well as If the formatting status is "formatted", the storage device undergoes file system repair to parse the file information list associated with the file, and the file information list on the storage device is cached for use in processing the file. The file system repair of the storage device to parse the file information list associated with the file includes: reading a preset file table and various directory information according to the rules of a preset file system; parsing all file information lists of the storage device from the directory information; and comparing all file information lists with the preset file table to identify damaged files and repair the damaged files.
2. The method according to claim 1, characterized in that, Also includes: The file is read and written according to the cached file information list.
3. The method according to claim 1, characterized in that, Also includes: The files are previewed and / or deleted in a loop based on the cached list of file information.
4. The method according to claim 3, characterized in that, Previewing and / or repeatedly deleting files based on the cached list of file information includes: Determine whether the repair code corresponding to the file information list is compiled into the same executable application as the user's required application; If so, it is determined to be a same-process transfer, and the memory address corresponding to the file information list is transferred to the user's required application in the application layer; and If not, it is determined to be a cross-process transfer, and the file information list is transferred to the user's required application through cross-process transfer.
5. The method according to claim 1, characterized in that, Retrieving the formatting status of a storage device containing files includes retrieving the formatting status of an inserted disk or memory card.
6. The method according to claim 1, characterized in that, Formatting the storage device and reserving contiguous storage space for different directories within the storage device during formatting includes: Based on the capacity of the storage device and the file types stored in different directories, estimate the number of clusters required for each directory; and Based on the number of clusters, contiguous storage space is reserved for different directories in the storage device.
7. The method according to claim 6, characterized in that, The storage device includes a first directory and a second directory. The first directory stores video files, and the second directory stores image files. Based on the capacity of the storage device and the different file types stored in the directories, the estimated number of clusters required for each directory includes: The number of video files to be stored is determined based on the format requirements of the video files and the capacity of the storage device, and the number of clusters required for the first directory is estimated based on the number of video files to be stored; and The number of image files to be stored is determined based on the format requirements of the image files and the capacity of the storage device, and the number of clusters required for the second directory is estimated based on the number of image files to be stored.
8. A computer-readable storage medium storing a computer program thereon, characterized in that, When the computer program is executed by a processor, it implements the method according to any one of claims 1 to 7.
9. An electronic device, characterized in that, include: Memory, configured to store computer programs; A processor is configured to execute the computer program to cause the electronic device to perform the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
KR1017802360000B1