Bidirectional guessing method of FAT32 cluster number, terminal equipment and storage medium
By sorting the undeletable file and directory entries in the FAT32 file system by creation time, and combining creation time traversal with file size calculation, the lookup table is dynamically updated to determine the cluster number. This solves the problem of inaccurate cluster number retrieval in traditional methods and achieves efficient data recovery in scenarios involving the deletion of a large number of files.
Patent Information
- Application Number
- CN202511542209.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-27
- Publication Date
- 2026-01-20
AI Technical Summary
In the traditional FAT32 file system, the cluster number retrieval method for deleted files has low accuracy in scenarios where a large number of files are deleted. This is because the reference data source is disordered and the search logic lacks systematicity.
A lookup table is constructed by sorting the file and directory entries with cluster numbers that have not been deleted by creation time. The target file entries with cluster numbers that have been deleted are sorted by creation time to form a target set. The target set is then traversed in ascending and descending order of creation time. The guessed cluster number is determined by combining the file size. The lookup table is dynamically updated to supplement reference data.
It significantly improves the accuracy and adaptability of cluster number retrieval, solves the problem of inaccurate cluster number retrieval in scenarios where a large number of files are deleted, and ensures efficient data recovery in complex environments.
Smart Images

Figure CN121365046A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of data processing, and particularly relates to a bidirectional guessing method for FAT32 cluster numbers, a terminal device and a storage medium. BACKGROUND
[0002] In a conventional FAT32 file system, for the cluster number recovery of a deleted file, a manner of separately, unidirectionally and disorderly searching for a non-deleted file with a similar creation time to reference the cluster number of the non-deleted file is usually adopted. In a scenario where a large number of files are deleted, the accuracy of the recovered cluster number is low due to the limited available file items that can be referenced and the lack of systematicness of the searching logic. There is a need for a new technical means to solve the above technical problems. SUMMARY
[0003] In view of this, the embodiments of the present application provide a bidirectional guessing method for FAT32 cluster numbers, a terminal device and a storage medium, which can solve the problem of low accuracy of the recovered cluster number in the related art.
[0004] The first aspect of the present application provides a bidirectional guessing method for FAT32 cluster numbers, comprising: obtaining a search table according to file items and directory items with non-deleted cluster numbers sorted by creation time, and obtaining a target file item set according to file items with deleted cluster numbers sorted by creation time; performing ascending order traversal and descending order traversal of the target file item set by creation time, wherein in each traversal process, for each target file item in the target file item set, a reference cluster number similar to the creation time of the target file item is determined according to the search table, a guessed cluster number of the target file item is determined according to the reference cluster number and the file size of the target file item, and the target file item is inserted into the search table in the order of creation time according to the guessed cluster number; determining target cluster numbers of the target file items in the target file item set according to the guessed cluster numbers in the search table.
[0005] Optionally, in the first implementation manner of the first aspect of the present application, the step of obtaining a search table according to file items and directory items with non-deleted cluster numbers sorted by creation time comprises: obtaining file items and directory items with non-deleted cluster numbers from a storage area of the FAT32 file system, wherein the file items and the directory items each contain complete creation time information and non-erased cluster number information; sorting the file items and the directory items according to the order of the creation time information to obtain the search table.
[0006] Optionally, in the second implementation manner of the first aspect of the present application, the step of determining a reference cluster number similar to the creation time of the target file item according to the search table comprises: According to the creation time of the target file item, the first file items and the first directory items are filtered in the lookup table; A target item with a creation time difference from the target file item being the smallest is selected from the first file items and the first directory items; If ascending creation time traversal is performed, a target item with a creation time smaller than that of the target file item and a creation time difference from the target file item being the smallest is selected from the first file items and the first directory items; if descending creation time traversal is performed, a target item with a creation time greater than or equal to that of the target file item and a creation time difference from the target file item being the smallest is selected from the first file items and the first directory items; The cluster number of the target item is determined as the reference cluster number, wherein the difference is obtained by timestamp difference calculation.
[0007] Optionally, in a third implementation manner of the first aspect of the present application, the step of filtering the first file items and the first directory items in the lookup table according to the creation time of the target file item comprises: If ascending creation time traversal is performed, the first file items and the first directory items with a creation time smaller than or equal to that of the target file item are filtered in the lookup table.
[0008] Optionally, in a fourth implementation manner of the first aspect of the present application, the step of filtering the first file items and the first directory items in the lookup table according to the creation time of the target file item comprises: If descending creation time traversal is performed, the first file items and the first directory items with a creation time greater than that of the target file item are filtered in the lookup table.
[0009] Optionally, in a fifth implementation manner of the first aspect of the present application, the step of determining the guessed cluster number of the target file item according to the reference cluster number and the file size of the target file item comprises: The number of clusters required to be occupied by the target file item is calculated according to the file size of the target file item and a preset cluster size of the FAT32 file system; If the current is ascending creation time traversal, the reference cluster number is added to the number of clusters to obtain a candidate cluster number; if the current is descending creation time traversal for the target file item set, the reference cluster number is subtracted from the number of clusters to obtain the candidate cluster number; If the value of the candidate cluster number is within a valid cluster number range of the FAT32 file system, the candidate cluster number is determined as the guessed cluster number, wherein the valid cluster number range is greater than 0 and less than or equal to the maximum cluster number value.
[0010] Optionally, in a sixth implementation manner of the first aspect of the present application, the step of inserting the target file item into the lookup table according to the guessed cluster number comprises: adding a guessed cluster number as a temporary cluster number attribute to the target file item; locating a neighboring item adjacent to the creation time of the target file item in the lookup table; inserting the target file item carrying the temporary cluster number attribute between the neighboring items.
[0011] Optionally, in a seventh implementation form of the first aspect of the present application, the step of determining the target cluster number of each target file item in the target file item set according to each guessed cluster number in the lookup table comprises: extracting two guessed cluster numbers obtained by the target file item in ascending order traversal and descending order traversal respectively; if the two guessed cluster numbers are the same, then the two guessed cluster numbers are determined as the target cluster number of the target file item; if the two guessed cluster numbers are different, then it is judged whether the two guessed cluster numbers are obtained by accurate search or fuzzy search, wherein the guessed cluster number obtained by accurate search is preferentially determined as the target cluster number of the target file item, and the fuzzy search comprises finding the most adjacent neighboring item in the lookup table by using the creation time of the target file, directly using the high 16-bit cluster number of the cluster number of the neighboring item and the low 16-bit cluster number of the target file to form a 32-bit cluster number as a fuzzy search result; if neither of the two guessed cluster numbers is obtained by accurate search, then the two guessed cluster numbers are verified for validity, and the guessed cluster number verified for validity is determined as the target cluster number of the target file item.
[0012] In a second aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the bidirectional guessing method of the FAT32 cluster number when executing the computer program.
[0013] In a third aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program implements the steps of the bidirectional guessing method of the FAT32 cluster number when executed by a processor.
[0014] In a fourth aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, causes the terminal device to perform the bidirectional guessing method of the FAT32 cluster number.
[0015] Compared with the prior art, the embodiment of the present application has the beneficial effects that: by first constructing a lookup table by sorting the file items and directory items whose cluster numbers are not deleted according to the creation time, forming a target set by sorting the target file items whose cluster numbers are deleted according to the creation time, and then performing ascending and descending creation time traversal on the target set, during the traversal process, determining the similar reference cluster number from the lookup table for each target file item in the target file item set and determining the guessed cluster number in combination with the file size, and inserting the processed target file items into the lookup table according to the creation time to dynamically supplement the reference data, the problem of inaccurate cluster number recovery in the case of a large number of deleted files is effectively solved, and the accuracy of cluster number guessing and the adaptability to the case of a large number of deleted files are significantly improved. BRIEF DESCRIPTION OF DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0017] Figure 1 An embodiment of the bidirectional guessing method of the FAT32 cluster number in the embodiment of the present application is shown in the figure. Figure 2 An embodiment of step S101 of the bidirectional guessing method of the FAT32 cluster number in the embodiment of the present application is shown in the figure. Figure 3 An embodiment of step S102 of the bidirectional guessing method of the FAT32 cluster number in the embodiment of the present application is shown in the figure. Figure 4 An embodiment of step S103 of the bidirectional guessing method of the FAT32 cluster number in the embodiment of the present application is shown in the figure. Figure 5 An embodiment of the terminal device in the embodiment of the present application is shown in the figure. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solutions and advantages of the present application more clear, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0019] It should be noted that the terms "comprising," "including," and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this invention, are intended to cover non-exclusive inclusion. For example, a process, method, terminal, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices. In the claims, specification, and accompanying drawings of this invention, relational terms such as "first" and "second" are used merely to distinguish one entity / operation / object from another entity / operation / object, and do not necessarily require or imply any such immediate relationship or order between these entities / operations / objects.
[0020] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0021] In the traditional FAT32 file system, the recovery of cluster numbers for deleted files typically involves searching for each deleted file entry individually, unidirectionally, and unordered for undeletable files with similar creation times to reference their cluster numbers. However, in scenarios involving a large number of deleted files, this method suffers from low accuracy due to the limited number of valid file entries to reference and the lack of systematic search logic. A new technical approach is needed to address these issues.
[0022] In view of this, embodiments of the present invention provide a bidirectional guessing method, terminal device, and storage medium for FAT32 cluster numbers. The method involves first constructing a lookup table by sorting file items and directory items whose cluster numbers have not been deleted by creation time, and then sorting target file items whose cluster numbers have been deleted by creation time to form a target set. The target set is then traversed in ascending and descending order of creation time. During the traversal, for each target file item in the target file item set, a similar reference cluster number is determined from the lookup table, and the guessed cluster number is determined by combining the file size. Simultaneously, the processed target file items are inserted into the lookup table by creation time to dynamically supplement reference data. This effectively solves the problem of inaccurate cluster number retrieval in scenarios where a large number of files are deleted, significantly improving the accuracy of cluster number guessing and its adaptability to scenarios involving large-scale file deletion.
[0023] To illustrate the technical solution of the present invention, specific embodiments are described below.
[0024] Figure 1A flowchart of a method for bidirectional guessing of a FAT32 cluster number is shown, which can be applied to a terminal device. The terminal device can be a mobile phone, a tablet computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, etc.
[0025] Specifically, the method for bidirectional guessing of a FAT32 cluster number can include the following steps S101-S103.
[0026] In step S101, a lookup table is obtained by sorting file items and directory items whose cluster numbers are not deleted according to creation time, and a target file item set is obtained by sorting file items whose cluster numbers are deleted according to creation time.
[0027] In an embodiment of the present application, the terminal device filters and acquires two types of core data from a storage area of a FAT32 file system.
[0028] Specifically, one type of core data is file items and directory items whose cluster numbers are not deleted, which are sorted according to the order of creation time to generate a lookup table for subsequent cluster number reference.
[0029] Specifically, the other type of core data is file items whose cluster numbers are deleted, which are sorted in order according to the creation time to form a target file item set to be processed. In this process, the storage metadata can be directly read through a file system interface to ensure accurate extraction of the creation time information of the two types of data, and a conventional timestamp ascending sorting algorithm can be used for sorting to ensure the consistency of the data sequence.
[0030] In step S102, the target file item set is traversed in ascending order of creation time and descending order of creation time, respectively. In each traversal process, for each target file item in the target file item set, a reference cluster number close to the creation time of the target file item is determined according to the lookup table, a guessed cluster number of the target file item is determined according to the reference cluster number and the file size of the target file item, and the target file item is inserted into the lookup table in the order of creation time according to the guessed cluster number.
[0031] In an embodiment of the present application, the terminal device processes each target file item in the target file item set in ascending order of creation time.
[0032] For the target file item being processed, the lookup table constructed in the first step is queried to filter out file items or directory items close to the creation time of the target file item from the lookup table, and the cluster number of the file items or directory items is determined as a reference cluster number. Subsequently, in combination with the file size of the current target file item, the cluster resource related parameters required to be occupied by the file are calculated, and the guess cluster number of the current target file item is derived based on the reference cluster number.
[0033] Finally, the guess cluster number is added as a temporary attribute for the current target file item, and an insertion operation is performed in the corresponding position of the lookup table according to the creation time, so that the lookup table dynamically supplements new reference data, and provides more abundant cluster number reference basis for the processing of subsequent target file items.
[0034] In step S103, according to each guess cluster number in the lookup table, the target cluster number of each target file item in the target file item set is determined.
[0035] In the embodiment of the application, after the ascending order traversal is completed, the terminal device switches the traversal direction, and processes each target file item in the target file item set in descending order of creation time.
[0036] Consistent with the ascending order traversal logic, for the current target file item, the reference item with similar creation time is still searched from the lookup table (at this time, the lookup table has contained the temporary target file item inserted in the ascending order traversal) to determine the reference cluster number, but the change of the traversal direction can adjust the selection priority of the reference item.
[0037] Subsequently, the terminal device also derives the guess cluster number in combination with the file size of the current target file item, and inserts the target file item carrying the guess cluster number into the lookup table according to the creation time, and further updates the reference data of the lookup table.
[0038] Optionally, when the reference cluster number is selected in descending order traversal, the file item or directory item with creation time greater than or equal to the creation time of the current target file item in the lookup table is preferentially selected, so as to match the time reference logic of “from new to old” in descending order traversal, and improve the relevance of the reference cluster number.
[0039] Compared with the prior art, the embodiment of the application has the beneficial effects that: by first constructing a lookup table by sorting the file items and directory items with non-deleted cluster numbers according to the creation time, forming a target set by sorting the target file items with deleted cluster numbers according to the creation time, and then performing ascending order and descending order traversal on the target set, for each target file item in the target file item set, the similar reference cluster number is determined from the lookup table, the guess cluster number is determined in combination with the file size, and the processed target file item is inserted into the lookup table according to the creation time to dynamically supplement the reference data, the problem of inaccurate cluster number recovery in the scenario of a large number of deleted files is effectively solved, and the accuracy of cluster number guessing and the adaptability to the scenario of a large number of deleted files are significantly improved.
[0040] In the traditional FAT32 cluster number recovery method, the file items and directory items whose cluster numbers are not deleted are not systematically collected, and the reference data is not orderly arranged according to the creation time, so that when the reference cluster number of the deleted file created at the same time is searched, there is a lack of uniform and orderly data source, and the reference items are easily missed and the matching logic is disordered, thereby affecting the accuracy of the reference cluster number. Based on this, an optional embodiment is provided. Figure 2 , Figure 2 is a specific embodiment of step S101 of the bidirectional guessing method of the FAT32 cluster number in the embodiment of the application, and step S101 further includes the following specific implementation: Step S1011, obtaining the file items and directory items whose cluster numbers are not deleted from the storage area of the FAT32 file system, wherein the file items and the directory items both contain complete creation time information and cluster number information that is not erased.
[0041] In the embodiment of the application, the terminal device screens and obtains the file items and the directory items whose cluster numbers are not deleted through the metadata access interface of the FAT32 file system.
[0042] Optionally, in this process, the effectiveness of each extracted data is verified. For example, it is confirmed that the cluster number of the file item and the directory item is not erased, it is verified that the file item and the directory item contain complete creation time information, and the file item and the directory item that satisfy the cluster number validity and the creation time completeness at the same time are reserved.
[0043] Optionally, invalid data is further filtered by comparing whether the cluster number is in the valid cluster number interval preset by the FAT32 system.
[0044] Step S1012, sorting the file items and the directory items according to the chronological order of the creation time information to obtain a lookup table.
[0045] In the embodiment of the application, the creation time of the extracted valid file items and directory items is converted into a uniform format timestamp, so as to eliminate the sorting deviation caused by different time formats; then, the file items and the directory items are sorted according to the chronological order of the creation time with the timestamp as the core; after the sorting is completed, the ordered data set is defined as a lookup table, and is stored in a temporary buffer area.
[0046] Optionally, if there are multiple file items or directory items with the same creation time, the ASCII code order of the file name and the file size and other auxiliary information can be additionally combined for secondary sorting.
[0047] In the embodiment of the present application, by extracting the file items and directory items containing complete creation time and valid cluster number, and constructing a lookup table according to the creation time, the problem of unordered and incomplete reference data source in the prior art is solved, and the reference cluster number matching deviation caused by the confusion or loss of reference data is effectively avoided.
[0048] In the conventional FAT32 cluster number recovery method, when searching for a reference file with a creation time close to that of the deleted file, only a one-way unordered search is used to roughly locate the file with a close time, and the creation time difference between the file in the search range and the target file is not quantitatively calculated and compared, so that a non-optimal reference object with a larger creation time difference from the target file is easily selected, resulting in insufficient accuracy of the determined reference cluster number, and further affecting the subsequent cluster number recovery result. Based on this, an optional embodiment of the present application is proposed. Referring to Figure 3 , Figure 3 is a specific embodiment of step S102 of the bidirectional guessing method of the FAT32 cluster number in the embodiment of the present application, and step S102 further includes the following specific implementation: In step S1021, the first file item and the first directory item are filtered in the lookup table according to the creation time of the target file item.
[0049] In the embodiment of the present application, the complete creation time information of the current target file item to be processed is extracted, and then the retrieval interface of the lookup table is called to filter the file items and directory items associated with the creation time of the target file item in the lookup table by taking the creation time as the core filtering condition, and these filtered objects are defined as the first file item and the first directory item.
[0050] In the filtering process, it is determined that the data in the lookup table is not tampered with, and the filtering logic is adapted to the subsequent traversal direction (for example, when ascending order traversal is performed, the objects with a creation time earlier than that of the target file item can be preferentially filtered, and when descending order traversal is performed, the objects with a creation time later than that of the target file item can be preferentially filtered).
[0051] Optionally, if ascending order traversal of the creation time is performed, the first file item and the first directory item with a creation time less than or equal to that of the target file item are filtered in the lookup table.
[0052] Optionally, if descending order traversal of the creation time is performed, the first file item and the first directory item with a creation time greater than that of the target file item are filtered in the lookup table.
[0053] Step S1022, if ascending creation time traversal is performed, a target item with a creation time smaller than the creation time of the target file item and a smallest time stamp difference is selected from the first file item and the first directory item; if descending creation time traversal is performed, a target item with a creation time greater than or equal to the creation time of the target file item and a smallest time stamp difference is selected from the first file item and the first directory item.
[0054] In the embodiment of the application, the final target item is determined from the above candidate target items according to the current traversal direction of the target file item set; if ascending creation time traversal is currently performed, the terminal device further screens a target item with a creation time smaller than the creation time of the target file item and a smallest time stamp difference from the candidate target items, and takes the target item as the final target item; if descending creation time traversal is currently performed, the terminal device further screens a target item with a creation time greater than or equal to the creation time of the target file item and a smallest time stamp difference from the candidate target items, and takes the target item as the final target item.
[0055] Optionally, if there are multiple candidate target items with the same time stamp difference and satisfying the condition corresponding to the traversal direction, the cluster number continuity of the candidate target items is additionally compared, and a candidate target item with better cluster number continuity is taken as the final target item.
[0056] Step S1023, the cluster number of the target item is determined as the reference cluster number, wherein the difference is obtained by time stamp difference calculation.
[0057] In the embodiment of the application, after the optimal target item is determined, the complete cluster number information of the target item that is not erased is read, and then the cluster number is directly determined as the reference cluster number of the current target file item to be processed. Meanwhile, the target item information and the time stamp difference corresponding to the reference cluster number are recorded.
[0058] Optionally, the determined reference cluster number is secondarily verified, for example, whether the cluster number is occupied by other confirmed valid file items is checked, to avoid errors in subsequent guessed cluster numbers due to cluster number conflicts.
[0059] In the embodiment of the application, the associated data in the lookup table is first screened according to the creation time of the target file item, and then the reference cluster number is determined based on the time stamp difference calculation and the target item with the smallest difference. The problem that the reference object is not quantitatively screened in the prior art is solved, the accuracy of the reference cluster number is significantly improved, and reliable basic data support is provided for subsequent derivation of the guessed cluster number based on the reference cluster number.
[0060] In the conventional FAT32 deleted file cluster number recovery method, when the deleted file cluster number is derived based on the reference cluster number, the actual size of the deleted file is not combined with the system preset cluster size to calculate the required cluster number, and the derived result is not verified whether it is in the effective cluster number range of the FAT32 system, so that the guessed cluster number cannot completely accommodate the file data or exceeds the cluster number range supported by the system, thereby causing the cluster number guessing to fail or the recovered file data to be incomplete. Based on this, an optional embodiment is provided. Step S102 further includes the following specific implementation: Step S1024, according to the file size of the target file item and the preset cluster size of the FAT32 file system, the cluster number required by the target file item is calculated.
[0061] In the embodiment of the application, the complete file size information of the current target file item to be processed is extracted from the directory item metadata of the FAT32 file system; at the same time, the "preset cluster size" recorded in the BIOS parameter block (BPB) of the FAT32 system boot sector is read. Then, the cluster number is calculated by division operation, specifically, the file size of the target file item is divided by the preset cluster size, if there is no remainder, the quotient is the required cluster number; if there is a remainder (i.e. the file size cannot be divided by the cluster size), the quotient is rounded up (because the remaining byte data still needs to occupy a complete cluster to meet the FAT32 file storage rule), and finally the accurate cluster number of the target file item is obtained.
[0062] Optionally, the result is verified after calculation, for example, confirming that the cluster number is a positive integer, or comparing the size relationship between the cluster number and the maximum cluster number that can be allocated at a time by the system, to avoid errors in subsequent operations caused by abnormal data.
[0063] Step S1025, if the current is ascending order traversal of the creation time, the reference cluster number and the cluster number are added to obtain the candidate cluster number; if the current is descending order traversal of the creation time of the target file item set, the reference cluster number and the cluster number are subtracted to obtain the candidate cluster number.
[0064] In the embodiment of the application, the traversal direction of the target file item set is determined, and the reference cluster number and the cluster number are operated according to the traversal direction to obtain the candidate cluster number.
[0065] Specifically, if the current is ascending order traversal of the creation time, the reference cluster number determined before and the cluster number calculated are added, that is, the candidate cluster number is equal to the reference cluster number plus the cluster number; if the current is descending order traversal of the creation time, the reference cluster number and the cluster number are subtracted, that is, the candidate cluster number is equal to the reference cluster number minus the cluster number.
[0066] Step S1026, if the value of the candidate cluster number is within the valid cluster number range of the FAT32 file system, the candidate cluster number is determined as the guessed cluster number, wherein the valid cluster number range is greater than 0 and less than or equal to the maximum cluster number value.
[0067] In the embodiment of the present application, the "valid cluster number range" of the FAT32 file system is first obtained: according to the system specification, the range can be "greater than 0 and less than or equal to the maximum cluster number of the system", wherein the "maximum cluster number" can be derived from the "total cluster number" field of the boot sector BPB structure. Then, the candidate cluster number is compared with the valid cluster number range.
[0068] Specifically, if the value of the candidate cluster number falls within the range, it is determined that the candidate cluster number is valid, and it is directly determined as the "guessed cluster number" of the current target file item; if the candidate cluster number exceeds the valid range, it is determined that the candidate cluster number is invalid, and the process returns to the previous step for re-execution.
[0069] Optionally, a cluster number occupation state check is performed by querying the marker state of the candidate cluster number in the FAT (File Allocation Table), if the cluster number is marked as "unoccupied", its validity is further confirmed; if it is marked as "occupied", it is determined that the candidate cluster number has a conflict, and the cumulative operation or the reference cluster number needs to be re-executed.
[0070] In the embodiment of the present application, the accurate cluster number is first calculated by combining the size of the target file item and the system preset cluster size, then the candidate cluster number is generated based on the reference cluster number, and finally it is verified whether the candidate cluster number is within the valid range, solving the problem that the existing method does not consider the file storage requirement and the validity of the cluster number.
[0071] In the traditional FAT32 cluster number recovery method, when processing file items whose cluster numbers are deleted, only the cluster numbers of the file items and directory items whose cluster numbers are not deleted collected initially are used as reference data to construct a lookup table, and the lookup table remains static during the entire processing process, resulting in that the amount of valid data that can be referred to gradually decreases when processing other deleted file items subsequently, and especially in the scenario where a large number of files are deleted, the lack of reference data will further reduce the accuracy of cluster number guessing. Based on this, an optional embodiment of the present application is proposed. Step S102 further includes the following specific implementation: Step S1027, adding the guessed cluster number as a temporary cluster number attribute for the target file item.
[0072] In the embodiment of the present application, the currently determined guessed cluster number of the target file item is read, then a "temporary cluster number attribute" field is added for the target file item, and the guessed cluster number is written into the field. At the same time, a "temporary" identifier (such as a "_temp" mark after the attribute name) is added in the attribute field, so as to clearly distinguish that the cluster number is temporary data generated by guessing, and avoid confusion with the original cluster number of the file item that is not deleted.
[0073] Optionally, the generation source of the temporary cluster number can be recorded synchronously to clearly distinguish the generation scenario of the cluster number during subsequent backtracking queries and to investigate potential data conflicts.
[0074] Step S1028: Locate the adjacent item in the lookup table that is adjacent to the creation time of the target file item.
[0075] In an embodiment of the present invention, the ordered retrieval function of the lookup table is invoked, and the creation time of the current target file item is used as the retrieval basis to filter out file items or directory items adjacent to the creation time in the lookup table, which are defined as "adjacent items".
[0076] Specifically, first find the preceding item in the lookup table whose creation time is "less than and closest to" the creation time of the target file item, and then find the following item whose creation time is "greater than and closest to" the creation time of the target file item. These two items together constitute the adjacent items of the target file item. If the creation time of the target file item is earlier than the creation time of all items in the lookup table, then only the following adjacent item (i.e., the first item in the lookup table) exists. If the creation time of the target file item is later than the creation time of all items in the lookup table, then only the preceding adjacent item (i.e., the last item in the lookup table) exists.
[0077] Step S1029: Insert the target file item carrying the temporary cluster number attribute between adjacent items.
[0078] In an embodiment of the present invention, after determining adjacent items, the target file item carrying the "temporary cluster number attribute" is inserted between the preceding and following adjacent items according to the lookup table's "sorted by creation time" rule (if only a single adjacent item exists, it is inserted at the beginning or end of the lookup table). Simultaneously, the lookup table's index information is updated (e.g., array indices or linked list pointers are regenerated) to ensure that subsequent retrieval and filtering operations on the lookup table can be executed normally.
[0079] Optionally, a historical version of the lookup table can be backed up after insertion. If an error is subsequently found in the temporary cluster number, the lookup table data can be rolled back using the backup version to avoid the erroneous data causing a chain reaction to subsequent cluster number guesses.
[0080] In this embodiment of the invention, by adding a temporary cluster number attribute to the target file item whose cluster number has been calculated and guessed, and inserting it into the lookup table in sorted order by creation time, the problem of static and unchanging lookup table and insufficient reference data in the existing method is solved. This allows the lookup table to be dynamically supplemented with new reference data as it is traversed, and the reference cluster number can be determined based on richer reference data when processing other target file items in the future, which significantly improves the accuracy of cluster number guessing in scenarios where a large number of files are deleted.
[0081] The traditional FAT32 cluster number recovery method only generates a guessed cluster number through single one-way traversal, does not perform secondary verification on the accuracy of the cluster number, and does not compare and screen the results of bidirectional traversal, so when the guessed cluster number is deviated (such as exceeding the effective range or not matching the file size), the error cannot be timely identified and corrected, resulting in that the wrong cluster number is used for file recovery, and further causing problems such as damaged recovered files and data loss. Based on this, an optional embodiment is provided. Referring to Figure 4 , Figure 4 is a specific embodiment of step S103 of the bidirectional guessing method of the FAT32 cluster number in the embodiment of the application, and step S103 further includes the following specific implementation: Step S1031, extracting two guessed cluster numbers obtained by the target file item in ascending order traversal and descending order traversal respectively.
[0082] In the embodiment of the application, according to the unique identifier of the target file item, the corresponding records of the target file item in the two traversals (ascending order traversal of creation time and descending order traversal of creation time) are searched in the dynamically updated lookup table.
[0083] The previous step has inserted the target file item with a temporary cluster number into the lookup table, and the temporary cluster number attribute will mark the traversal type (such as "ascending order traversal temporary cluster number" and "descending order traversal temporary cluster number"), so the guessed cluster numbers generated in two different traversal scenarios can be quickly located and extracted, which are recorded as "ascending order guessed cluster number" and "descending order guessed cluster number" respectively.
[0084] Optionally, the traversal log associated with the target file item is confirmed to confirm that the generation process of the two cluster numbers is in compliance, so as to avoid extracting invalid cluster numbers that do not complete the complete process.
[0085] Step S1032, if the two guessed cluster numbers are the same, the two guessed cluster numbers are determined as the target cluster number of the target file item.
[0086] In the embodiment of the application, the "ascending order guessed cluster number" and the "descending order guessed cluster number" extracted are compared in value. If the values of the two cluster numbers are exactly the same, the value is directly determined as the "target cluster number" of the current target file item, and a "temporary identifier removal" operation is performed on the cluster number, and the cluster number state of the target file item in the lookup table is updated to clearly indicate that it is a confirmed valid cluster number.
[0087] Optionally, the corresponding storage capacity is calculated through the target cluster number, and it is confirmed that the capacity can completely accommodate the file size of the target file item, further ensuring the accuracy of the cluster number.
[0088] If the two guess cluster numbers are different, it is judged whether the two guess cluster numbers are obtained by accurate search or fuzzy search in step S1033, wherein the guess cluster number obtained by accurate search is determined as the target cluster number of the target file item, and the fuzzy search includes finding the adjacent item with the closest time in the search table by using the creation time of the target file, directly using the high 16-bit cluster number of the cluster number of the adjacent item and the low 16-bit cluster number of the target file to form a 32-bit cluster number as the fuzzy search result.
[0089] In the embodiment of the application, if the first guess cluster number and the second guess cluster number are different in value, the guess type marks corresponding to the two guess cluster numbers are called. It is judged whether there is an accurate guess cluster number in the two cluster numbers: if one is an accurate guess cluster number and the other is a fuzzy guess cluster number, the accurate guess cluster number is determined as the target cluster number of the target file item; if both are accurate guess cluster numbers, the calculation method of the fuzzy search includes finding the adjacent item with the closest time in the search table by using the creation time of the target file, directly using the high 16-bit cluster number of the cluster number of the adjacent item and the low 16-bit cluster number of the target file to form a 32-bit cluster number as the fuzzy search result.
[0090] Optionally, the reference cluster numbers corresponding to the two accurate guess cluster numbers are further compared with the time difference of the target file item, and the guess cluster number corresponding to the reference cluster number with the smaller time difference is determined as the target cluster number.
[0091] In step S1034, if neither of the two guess cluster numbers is obtained by accurate search, the validity of the two guess cluster numbers is verified, and the guess cluster number passing the validity verification is determined as the target cluster number of the target file item.
[0092] In the embodiment of the application, if neither of the first guess cluster number and the second guess cluster number is obtained by accurate search, the cluster number validity verification process is started.
[0093] Specifically, it is checked whether the two cluster numbers are in the valid cluster number range of the FAT32 file system, and the invalid cluster numbers beyond the range are excluded; the FAT table of the FAT32 file system is queried to confirm whether the remaining valid cluster numbers are not occupied by other existing file items; and the cluster numbers passing the validity range verification and the occupation state verification are determined as the target cluster number of the target file item.
[0094] Optionally, if both of the fuzzy guess cluster numbers pass the validity verification, the file size of the target file item is referred to to judge whether the cluster numbers corresponding to the cluster numbers can completely store the file, and the cluster number with the higher matching degree is determined as the final target cluster number.
[0095] In the embodiment of the present application, two guessed cluster numbers generated by bidirectional traversal are extracted, the effective cluster number is directly determined by comparison of consistency, and multi-dimensional effectiveness verification is performed on the inconsistent cluster numbers, thereby solving the cluster number error problem caused by the lack of bidirectional comparison and secondary verification in the prior art.
[0096] As shown in Figure 5 Fig. 5 is a schematic diagram of a terminal device provided by the embodiment of the present application. The terminal device 500 can include a processor 501, a memory 502, and a computer program 503 stored in the memory 502 and executable on the processor 501, for example, a bidirectional guessing program of FAT32 cluster number. The processor 501 implements the steps in the above various embodiments of bidirectional guessing of FAT32 cluster number when executing the computer program 503.
[0097] The computer program can be divided into one or more modules / units, one or more modules / units are stored in the memory 502 and executed by the processor 501 to complete the present application. One or more modules / units can be a series of computer program instruction segments capable of completing a specific function, which is used to describe the execution process of the computer program in the terminal device.
[0098] The terminal device can include, but is not limited to, the processor 501 and the memory 502. Those skilled in the art can understand that Figure 5 It is only an example of the terminal device and does not constitute a limitation on the terminal device, and can include more or fewer components than the diagram, or combine certain components, or different components, for example, the terminal device can also include an input / output device, a network access device, a bus, etc.
[0099] The processor 501 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0100] The memory 502 can be an internal storage unit of the terminal device, for example, a hard disk or a memory of the terminal device. The memory 502 can also be an external storage device of the terminal device, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device. Further, the memory 502 can include both the internal storage unit and the external storage device of the terminal device. The memory 502 is used to store computer programs and other programs and data required by the terminal device. The memory 502 can also be used to temporarily store data that has been output or will be output.
[0101] It should be noted that, for the convenience and brevity of description, the structure of the terminal device described above can also refer to the specific description of the structure in the method embodiments, which will not be described here.
[0102] The embodiment of the present application also provides a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program is executed by a processor to realize the steps in the bidirectional guessing method of the FAT32 cluster number.
[0103] The embodiment of the present application provides a computer program product, when the computer program product is run on a mobile terminal, so that the mobile terminal executes the steps in the bidirectional guessing method of the FAT32 cluster number.
[0104] In the above embodiments, the description of each embodiment has its own emphasis, and the parts not described or recorded in a certain embodiment can be referred to the related description of other embodiments.
[0105] Those skilled in the art can appreciate that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. A person skilled in the art can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0106] In the embodiments provided by the present application, it should be understood that the disclosed terminal device and method can be implemented by other ways. For example, the terminal device embodiments described above are only schematic. In addition, the mutual coupling or direct coupling or communication connection between the shown or discussed elements can be indirect coupling or communication connection through some interface, device or unit, and can be electrical, mechanical or other forms.
[0107] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, i.e. may be located in one place, or may be distributed to multiple network units. Part or all of the units may be selected according to actual needs to achieve the purpose of the embodiment.
[0108] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0109] The integrated module / unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on this understanding, all or part of the processes in the above-mentioned embodiment methods can also be completed by a computer program instructing related hardware, and the computer program can be stored in a computer readable storage medium. When the processor executes the computer program, the steps of each method embodiment can be implemented. The computer program includes computer program code, which can be in the form of source code, object code, executable file or some intermediate form, etc. The computer readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0110] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than limit them. Although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalent ones. These modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A bidirectional guessing method of FAT32 cluster number, characterized in that, The method comprises the following steps: According to the file items and directory items whose cluster numbers are not deleted, a lookup table is obtained by sorting according to the creation time, and according to the file items whose cluster numbers are deleted, a target file item set is obtained by sorting according to the creation time; The target file item set is respectively traversed in ascending order of creation time and descending order of creation time, wherein, in each traversal process, for each target file item in the target file item set, a reference cluster number close to the creation time of the target file item is determined according to the lookup table, then a guessed cluster number of the target file item is determined according to the reference cluster number and the file size of the target file item, and the target file item is inserted into the lookup table in order of creation time according to the guessed cluster number; The target cluster number of each target file item in the target file item set is determined according to each guessed cluster number in the lookup table.
2. The method of claim 1, wherein the FAT32 cluster number is guessed in both directions, and the guessed cluster number is compared with the cluster number of the FAT32 file system. The step of obtaining the lookup table by sorting the file items and directory items whose cluster numbers are not deleted according to the creation time comprises the following steps: The file items and directory items whose cluster numbers are not deleted are obtained from the storage area of the FAT32 file system, wherein the file items and directory items both contain complete creation time information and unerased cluster number information; The file items and directory items are sorted according to the sequence of the creation time information to obtain the lookup table.
3. The method of claim 1, wherein the FAT32 cluster number is bi-directionally guessed by, The step of determining the reference cluster number close to the creation time of the target file item according to the lookup table comprises the following steps: The first file items and first directory items are filtered in the lookup table according to the creation time of the target file item; The target item with the smallest difference value of creation time from the target file item is selected from the first file items and first directory items; If the ascending order traversal of the creation time is performed, the target item with the smallest difference value of creation time from the target file item and smaller than the creation time of the target file item is selected from the first file items and first directory items; if the descending order traversal of the creation time is performed, the target item with the smallest difference value of creation time from the target file item and greater than or equal to the creation time of the target file item is selected from the first file items and first directory items; The cluster number of the target item is determined as the reference cluster number, wherein the difference value is obtained by timestamp difference calculation.
4. The method of claim 3, wherein the FAT32 cluster number is guessed in both directions. The step of filtering the first file items and first directory items in the lookup table according to the creation time of the target file item comprises the following steps: If the ascending order traversal of the creation time is performed, the first file items and first directory items with creation time smaller than or equal to the creation time of the target file item are filtered in the lookup table.
5. The method of claim 3, wherein the FAT32 cluster number is guessed in both directions, and The step of filtering the first file items and first directory items in the lookup table according to the creation time of the target file item comprises the following steps: If the descending order traversal of the creation time is performed, the first file items and first directory items with creation time greater than the creation time of the target file item are filtered in the lookup table.
6. The method of claim 1, wherein the FAT32 cluster number is bi-directionally guessed by, The step of determining the guessed cluster number of the target file item according to the reference cluster number and the file size of the target file item comprises the following steps: calculating a number of clusters required to be occupied by the target file item according to a file size of the target file item and a preset cluster size of a FAT32 file system; if the current is ascending order traversal of the creation time, then the reference cluster number is added to the cluster number to obtain a candidate cluster number; if the current is descending order traversal of the creation time of the target file item set, then the reference cluster number is subtracted from the cluster number to obtain a candidate cluster number; if the value of the candidate cluster number is within a valid cluster number range of the FAT32 file system, then the candidate cluster number is determined as the guess cluster number, wherein the valid cluster number range is greater than 0 and less than or equal to a maximum cluster number value.
7. The method of claim 1, wherein the FAT32 cluster number is bi-directionally guessed by, The step of inserting the target file item into the lookup table according to the guess cluster number includes: adding the guess cluster number as a temporary cluster number attribute for the target file item; locating adjacent items adjacent to the creation time of the target file item in the lookup table; inserting the target file item carrying the temporary cluster number attribute between the adjacent items.
8. The method of claim 1, wherein the FAT32 cluster number is bi-directionally guessed by, The step of determining the target cluster number of each target file item in the target file item set according to each guess cluster number in the lookup table includes: extracting two guess cluster numbers of the target file item obtained in the ascending order traversal and the descending order traversal respectively; if the two guess cluster numbers are the same, then the two guess cluster numbers are determined as the target cluster number of the target file item; if the two guess cluster numbers are different, then it is judged whether the two guess cluster numbers are obtained by accurate search or fuzzy search, wherein the guess cluster number obtained by accurate search is preferentially determined as the target cluster number of the target file item, and the fuzzy search includes finding the adjacent items with the closest time in the lookup table using the creation time of the target file, directly using the high 16-bit cluster number of the adjacent item cluster number and the low 16-bit cluster number of the target file to form a 32-bit cluster number as a fuzzy search result; if neither of the two guess cluster numbers is obtained by accurate search, then the two guess cluster numbers are verified for validity, and the guess cluster number passing the validity verification is determined as the target cluster number of the target file item.
9. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor implements the steps of the bidirectional guess method of the FAT32 cluster number according to any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1-9. The computer program implements the steps of the bidirectional guess method of the FAT32 cluster number according to any one of claims 1 to 8 when executed by the processor.