CN114003576B - Method and device for calculating file traversal progress, computer equipment and storage medium - Google Patents

Method and device for calculating file traversal progress, computer equipment and storage medium Download PDF

Info

Publication number
CN114003576B
CN114003576B CN202111240521.0A CN202111240521A CN114003576B CN 114003576 B CN114003576 B CN 114003576B CN 202111240521 A CN202111240521 A CN 202111240521A CN 114003576 B CN114003576 B CN 114003576B
Authority
CN
China
Prior art keywords
file
space occupation
occupation amount
calculating
traversed
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111240521.0A
Other languages
Chinese (zh)
Other versions
CN114003576A (en
Inventor
唐超
甄鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202111240521.0A priority Critical patent/CN114003576B/en
Publication of CN114003576A publication Critical patent/CN114003576A/en
Application granted granted Critical
Publication of CN114003576B publication Critical patent/CN114003576B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1847File system types specifically adapted to static storage, e.g. adapted to flash memory or SSD
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/11File system administration, e.g. details of archiving or snapshots
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a method, a device, computer equipment and a storage medium for calculating file traversal progress, wherein the method comprises the following steps: the file handle of the disk file directory and the file handle instance of the file to be traversed are obtained, the disk capacity value is calculated according to the file handle, the first total space occupation amount of the file to be traversed and the second total space occupation amount of the file to be traversed, on which the file traversing service is executed, in the file to be traversed are calculated according to the disk capacity value and the second total space occupation amount when the first total space occupation amount is not calculated, the file traversing progress is calculated according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated, and the effective and accurate progress can be reported in most of time in the whole file traversing process, so that the user experience is improved.

Description

Method and device for calculating file traversal progress, computer equipment and storage medium
Technical Field
The present disclosure relates to the field of internet technologies, and in particular, to a method and apparatus for calculating a file traversal progress, a computer device, and a storage medium.
Background
Hard disk file traversal is a generic term for a class of security software behaviors that may be: full-disk file hash value calculation for implementing global application launch control, or full-disk file hash value calculation for implementing detection of full-disk important file integrity. All the actions need to process all files under the whole hard disk or part of the catalogue in a certain operating system, the processing process can be long in duration, and in order to improve the user experience, the progress of the file traversing task needs to be reported at all times in the processing process.
When the progress calculation of the file traversing task is performed, the total capacity use condition of the whole hard disk is generally obtained, then, each time a file is processed, the size of the file is accumulated into a variable, and the progress is obtained by dividing the variable value by the total capacity of the disk. The calculation method does not delay excessive time due to the calculation progress, but the total size of the file to be traversed is far smaller than the total capacity of the disk, and if the accumulated value of the file is close to the total capacity of the disk, the progress of the file traversing task is difficult to calculate accurately.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a method, apparatus, computer device, and storage medium for calculating a file traversal progress, which can accurately calculate the progress of a file traversal task.
In one aspect, a method for calculating a file traversal progress is provided, the method comprising:
acquiring a file handle of a disk file directory and a file handle instance of a file to be traversed;
calculating a disk capacity value according to the file handle;
according to the file handle instance, calculating a first total space occupation amount of a file to be traversed and a second total space occupation amount of a file to be traversed, in which file traversing business is executed, of the file to be traversed;
when the first total space occupation amount is not calculated, calculating file traversal progress according to the disk capacity value and the second total space occupation amount;
and calculating the file traversing progress according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated.
In one possible implementation, calculating the disk capacity value from the file handle includes:
according to the file handle, calling a getmontent function to obtain a mounting directory structure body of a disk file directory, wherein the mounting directory structure body comprises a volume field, a block field and an idle field;
calculating the total capacity value of the magnetic disk according to the volume field and the block field;
calculating a disk idle capacity value according to the volume field and the idle field;
and calculating the disk capacity value according to the disk total capacity value and the disk idle capacity value.
In one possible implementation, calculating a first total space occupation of a file to be traversed according to a file handle instance includes:
obtaining a file handle instance of a current file to be traversed in the files to be traversed according to the paths to be traversed by adopting an iterator, and sequentially calculating the space occupation amount of each file;
and accumulating the space occupation amount of the current file to be traversed and the space occupation amount of the file before the current file to be traversed in the path to be traversed to obtain a first total space occupation amount of the file to be traversed.
In one possible implementation, calculating, according to the file handle instance, a second total space occupation amount of a file in which a file traversing service is executed in the file to be traversed includes:
obtaining a file handle instance of a current file in the file to be traversed according to the path to be traversed by adopting an iterator;
executing file traversing service on the current file according to the file handle instance of the current file to obtain a file of the executed file traversing service;
and calculating the current file space occupation amount of the file traversing service to be executed, and accumulating the current file space occupation amount to the historical space occupation amount to obtain a second total space occupation amount, wherein the historical space occupation amount is the accumulated value of the space occupation amounts of all files before traversing the current file in the path to be traversed.
In one possible implementation, calculating the disk capacity value from the file handle includes:
and calculating the disk capacity value through the main thread according to the file handle.
In one possible implementation, calculating a first total space occupation of a file to be traversed according to a file handle instance includes:
according to the file handle example, the first total space occupation amount of the file to be traversed is calculated through the traversing calculation thread.
In one possible implementation, when the first total space occupation amount is not calculated, calculating a file traversal progress according to the disk capacity value and the second total space occupation amount, including:
when the first total space occupation amount is not calculated, calculating the file traversing progress through a progress calculation thread according to the disk capacity value and the second total space occupation amount;
when the first total space occupation amount is calculated, calculating a file traversal progress according to the first total space occupation amount and the second total space occupation amount, including:
when the first total space occupation amount is calculated, calculating the file traversing progress through the progress calculating thread according to the first total space occupation amount and the second total space occupation amount.
In a second aspect, there is provided a computing device for file traversal progress, the device comprising:
the acquisition module is used for acquiring file handles of the disk file catalogues and file handle instances of files to be traversed;
the computing module is used for computing a disk capacity value according to the file handle;
the calculation module is further used for calculating a first total space occupation amount of the file to be traversed and a second total space occupation amount of the file to be traversed, on which the file traversing service is executed, in the file to be traversed according to the file handle instance;
the calculation module is also used for calculating file traversal progress according to the disk capacity value and the second total space occupation amount when the first total space occupation amount is not calculated;
and the calculation module is also used for calculating the file traversing progress according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated.
In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the method for calculating the file traversal progress in the first aspect or any implementation manner of the first aspect when executing the computer program.
In a fourth aspect, a computer readable storage medium is provided, on which a computer program is stored, which when executed by a processor implements the method of calculating a file traversal progress of the first aspect or any implementation of the first aspect.
According to the method, the device, the computer equipment and the storage medium for calculating the file traversing progress, file handles of disk file catalogues and file handle instances of files to be traversed are obtained, disk capacity values are calculated according to the file handles, first total space occupation amounts of the files to be traversed and second total space occupation amounts of files to be traversed subjected to file traversing business in the files to be traversed are calculated according to the file handle instances, when the first total space occupation amounts are not calculated, file traversing progress is calculated according to the disk capacity values and the second total space occupation amounts, when the first total space occupation amounts are calculated, file traversing progress is calculated according to the first total space occupation amounts and the second total space occupation amounts, effective and accurate progress can be reported in most of time in the whole file traversing process, and user experience is improved.
Drawings
FIG. 1 is a flow chart of a method for calculating a file traversal progress according to one embodiment of the present application;
FIG. 2 is a block diagram of a file traversal progress calculation device, according to one embodiment;
FIG. 3 is an internal block diagram of a computer device in one embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
When the function of calculating the progress is realized, the capacity usage condition of the whole hard disk is generally obtained, after each file is processed, the occupied space of the file is added into a variable, when the reporting progress is required, the variable value is divided by the disk capacity value, the total occupied space of the traversed file is required to be far smaller than the disk capacity value, which is determined by the characteristics of the file system, and if the total occupied space of the traversed file is close to the disk capacity value, a complex calculation algorithm is required. Meanwhile, when only partial directory traversal operation is performed, the progress calculation method is disabled.
In some embodiments, as shown in fig. 1, there is provided a method for calculating a file traversal progress, the method comprising the steps of:
s110, acquiring file handles of disk file directories and file handle instances of files to be traversed;
when reading file data, an application program firstly calls an operating system function to transmit a file name, and selects a path to the file to open the file, and the function retrieves a sequence number, namely a file handle, and the file handle is the unique identification basis of the file.
And acquiring a file handle of the disk file directory by calling a setmentfunction, wherein the acquired file handle is of a type of/etc/mtab file handle for acquiring the mounting information of the current system.
And obtaining a file handle instance of the file to be traversed through the iterator, so as to calculate the size of the file to be traversed. The file to be traversed may be all files of the disk file or part files of the disk file. For the above differences
S120, calculating a disk capacity value according to the file handle.
And obtaining a disk file directory through the file handle, and calculating a disk capacity value according to the disk file directory.
In some embodiments, computing the disk capacity value from the file handle includes:
according to the file handle, calling a getmontent function to obtain a mounting directory structure body of a disk file directory, wherein the mounting directory structure body comprises a volume field, a block field and an idle field;
calculating the total capacity value of the magnetic disk according to the volume field and the block field;
calculating a disk idle capacity value according to the volume field and the idle field;
and calculating the disk capacity value according to the disk total capacity value and the disk idle capacity value.
And after the disk file is identified according to the file handle, obtaining the disk file directory. And acquiring a mounted directory structure body of the disk file directory by calling the getmentfunction, and further extracting a volume field, a block field and an idle field in the mounted directory structure body. The volume field is used for acquiring the size of each data block, namely the occupied amount of the data block space, the block field is used for acquiring the total number of the data blocks of the file system, and the idle field is used for acquiring the number of unused data blocks. In practical applications, the volume field may be denoted by f_bsize, the block field may be denoted by f_blocks, and the free field may be denoted by f_free.
And obtaining the total capacity value of the magnetic disk by running the calculation instructions corresponding to the volume field and the block field. And obtaining the disk idle capacity value by running the calculation instructions corresponding to the volume field and the idle field. Subtracting the disk idle capacity value from the disk total capacity value to obtain a disk capacity value.
S130, according to the file handle instance, calculating a first total space occupation amount of the file to be traversed and a second total space occupation amount of the file to be traversed, on which the file traversing service is executed, in the file to be traversed.
The file handle instance is generally obtained according to a file handle, and comprises file attributes, wherein the file attributes are used for calculating the space occupation amount of a file, and the space occupation amount refers to the size of disk space occupied by the file.
In some embodiments, calculating a first total space footprint of a file to be traversed from a file handle instance includes:
obtaining a file handle instance of a current file to be traversed in the files to be traversed according to the paths to be traversed by adopting an iterator, and calculating the space occupation amount of the current file to be traversed;
and accumulating the space occupation amount of the current file to be traversed and the space occupation amount of the file before the current file to be traversed in the path to be traversed to obtain a first total space occupation amount of the file to be traversed.
Accumulating the space occupation amount of the current file to be traversed and the space occupation amount of the file before the current file to be traversed in the path to be traversed to obtain a first total space occupation amount of the file to be traversed
Taking an example that the files to be traversed comprise an A file, a B file, a C file, a D file and an E file, taking the path to be traversed as an A-B-C-D-E, adopting an iterator to obtain a file handle example of the A file, calculating the space occupation quantity a of the A file, then obtaining a file handle example of the B file, and calculating the space occupation quantity B of the B file, wherein the B file is the current file to be traversed, the A file is the file before the B file in the path to be traversed, and adding the space occupation quantity B of the B file and the space occupation quantity a of the A file to obtain the accumulated space occupation quantity a+b of the A file and the B file. And continuously acquiring a file handle instance of the C file, calculating the space occupation quantity C of the C file, wherein the C file is the current file to be traversed, the A file and the B file are files before the C file in the path to be traversed, adding the space occupation quantity C of the C file and the accumulated space occupation quantity a+b of the A file and the B file to obtain the accumulated space occupation quantity a+b+c of the A file, the B file and the C file, and pushing the sum to finish traversing when no non-traversed file exists in the file to be traversed, so as to obtain the final accumulated space occupation quantity.
In some embodiments, calculating a second total space occupation amount of the files of the executed file traversing business in the files to be traversed according to the file handle instance comprises:
obtaining a file handle instance of a current file in the file to be traversed according to the path to be traversed by adopting an iterator;
executing file traversing service on the current file according to the file handle instance of the current file to obtain a file of the executed file traversing service;
and calculating the current file space occupation amount of the file traversing service to be executed, and accumulating the current file space occupation amount to the historical space occupation amount to obtain a second total space occupation amount, wherein the historical space occupation amount is the accumulated value of the space occupation amounts of all files before traversing the current file in the path to be traversed.
The second space occupation amount is the total space occupation amount of the traversed file in the process of executing the file traversing service.
The history space occupation amount is a file before the current file which has been traversed in the process of executing the file traversing service.
After the space occupation amount of the current file is calculated and accumulated to the history space occupation amount, the iterator continues to obtain a file handle instance of a file which is the next file of the current file in the path to be traversed, the file traversing service is executed, the space occupation amount of the file is calculated, and the space occupation amount is accumulated to the history space occupation amount to obtain a second total space occupation amount.
S140, when the first total space occupation amount is not calculated, calculating the file traversing progress according to the disk capacity value and the second total space occupation amount.
When the first total space occupation amount is not calculated, the ratio of the second total space occupation amount to the disk capacity value is used as the file traversing progress, and the disk capacity value is always larger than the total space occupation amount of the file to be traversed, so that the file traversing progress value is smaller, the file traversing progress value is in a progress large error stage at the moment, and the progress reported by the system is ensured not to be lost when the accurate progress value is not calculated.
S150, calculating the file traversing progress according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated.
When the first total space occupation amount is calculated, the ratio of the second total space occupation amount to the first space occupation amount is used as the file traversing progress, and the file traversing progress is at the accurate progress stage. Because only accumulation of the space occupation amount of the file to be traversed is executed when the first total space occupation amount is calculated, the calculation process of the first total space occupation amount does not take too long, generally occupies less than 10% of the time of the file traversing business process, and then very accurate progress reporting is carried out on more than 90% of the time of the whole file traversing business process. In the stage of large progress error, as the file traversing progress value is smaller, when the progress is switched into the stage of accurate progress, a less obvious jump occurs to the externally reported progress value, and the jump is used by a user naturally, so that the user experience is improved.
In the embodiment of the application, by acquiring the file handle of the disk file directory and the file handle instance of the file to be traversed, calculating the disk capacity value according to the file handle, calculating the first total space occupation amount of the file to be traversed and the second total space occupation amount of the file to be traversed, which is subjected to the file traversing business, in the file to be traversed, when the first total space occupation amount is not calculated, the file traversing progress is calculated according to the disk capacity value and the second total space occupation amount, and when the first total space occupation amount is calculated, the file traversing progress is calculated according to the first total space occupation amount and the second total space occupation amount, so that the effective and accurate progress can be reported in most of time in the whole file traversing process, and the user experience is improved.
In some embodiments, computing the disk capacity value from the file handle includes:
and calculating the disk capacity value through the main thread according to the file handle.
In some embodiments, calculating a first total space footprint of a file to be traversed from a file handle instance includes:
according to the file handle example, the first total space occupation amount of the file to be traversed is calculated through the traversing calculation thread.
In some embodiments, when the first total space occupation amount is not calculated, calculating a file traversal progress according to the disk capacity value and the second total space occupation amount, including:
when the first total space occupation amount is not calculated, calculating the file traversing progress through a progress calculation thread according to the disk capacity value and the second total space occupation amount;
when the first total space occupation amount is calculated, calculating a file traversal progress according to the first total space occupation amount and the second total space occupation amount, including:
when the first total space occupation amount is calculated, calculating the file traversing progress through the progress calculating thread according to the first total space occupation amount and the second total space occupation amount.
And calculating the disk capacity value by using the main line Cheng Shunshi, starting a traversal calculation thread to calculate the first total space occupation amount of the file to be traversed, calculating the file traversal progress by the progress calculation thread according to the disk capacity value and the second total space occupation amount when the first total space occupation amount is not calculated, and calculating the file traversal progress by the progress calculation thread according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated. And the three-thread parallel mode is adopted to realize the progress reporting of the progress large error stage and the progress accurate stage, and the performance consumption is not too much.
It should be understood that, although the steps in the flowchart of fig. 1 are shown in sequence as indicated by the arrows, the steps are not necessarily performed in sequence as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in fig. 1 may include multiple sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, nor do the order in which the sub-steps or stages are performed necessarily performed in sequence, but may be performed alternately or alternately with at least a portion of other steps or sub-steps of other steps.
In one embodiment, as shown in fig. 2, there is provided a file traversal progress calculation device 200, comprising: an acquisition module 210, a calculation module 220, wherein:
an obtaining module 210, configured to obtain a file handle of a disk file directory and a file handle instance of a file to be traversed;
a calculation module 220, configured to calculate a disk capacity value according to the file handle;
the calculating module 220 is further configured to calculate, according to the file handle instance, a first total space occupation amount of a file to be traversed and a second total space occupation amount of a file to be traversed, where the file traversing service is executed in the file to be traversed;
the calculation module 220 is further configured to calculate a file traversal progress according to the disk capacity value and the second total space occupation amount when the first total space occupation amount is not calculated;
the calculation module 220 is further configured to calculate a file traversal progress according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated.
In the embodiment of the application, the effective and accurate progress can be reported in most of time in the whole file traversal process, and the user experience is improved.
In some embodiments, the computing module 220 is specifically configured to:
according to the file handle, calling a getmontent function to obtain a mounting directory structure body of a disk file directory, wherein the mounting directory structure body comprises a volume field, a block field and an idle field;
calculating the total capacity value of the magnetic disk according to the volume field and the block field;
calculating a disk idle capacity value according to the volume field and the idle field;
and calculating the disk capacity value according to the disk total capacity value and the disk idle capacity value.
In some embodiments, the computing module 220 is specifically configured to:
according to the file handle example, calculating the first total space occupation amount of the file to be traversed comprises the following steps:
obtaining a file handle instance of a current file to be traversed in the files to be traversed according to the paths to be traversed by adopting an iterator, and sequentially calculating the space occupation amount of each file;
and accumulating the space occupation amount of the current file to be traversed and the space occupation amount of the file before the current file to be traversed in the path to be traversed to obtain a first total space occupation amount of the file to be traversed.
In some embodiments, the computing module 220 is specifically configured to:
according to the file handle example, calculating a second total space occupation amount of the files of the file to be traversed, which are subjected to the file traversing service, wherein the second total space occupation amount comprises:
obtaining a file handle instance of a current file in the file to be traversed according to the path to be traversed by adopting an iterator;
executing file traversing service on the current file according to the file handle instance of the current file to obtain a file of the executed file traversing service;
and calculating the current file space occupation amount of the file traversing service to be executed, and accumulating the current file space occupation amount to the historical space occupation amount to obtain a second total space occupation amount, wherein the historical space occupation amount is the accumulated value of the space occupation amounts of all files before traversing the current file in the path to be traversed.
In some embodiments, the computing module 220 is specifically configured to:
calculating a disk capacity value from the file handle, comprising:
and calculating the disk capacity value through the main thread according to the file handle.
In one possible implementation, calculating a first total space occupation of a file to be traversed according to a file handle instance includes:
according to the file handle example, the first total space occupation amount of the file to be traversed is calculated through the traversing calculation thread.
In some embodiments, the computing module 220 is specifically configured to:
when the first total space occupation amount is not calculated, calculating the file traversing progress through a progress calculation thread according to the disk capacity value and the second total space occupation amount;
when the first total space occupation amount is calculated, calculating the file traversing progress through the progress calculating thread according to the first total space occupation amount and the second total space occupation amount.
For specific limitation of the calculation means of the file traversal progress, reference may be made to the limitation of the calculation method of the file traversal progress hereinabove, and no further description is given here. The various modules in the above-described file traversal progress computing device may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, which may be a server, the internal structure of which may be as shown in fig. 3. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device is used for storing the disk capacity value and the space occupation value of the file to be traversed. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program, when executed by a processor, implements a method of calculating a file traversal progress.
It will be appreciated by those skilled in the art that the structure shown in fig. 3 is merely a block diagram of some of the structures associated with the present application and is not limiting of the computer device to which the present application may be applied, and that a particular computer device may include more or fewer components than shown, or may combine certain components, or have a different arrangement of components.
In some embodiments, a computer device is provided comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program:
acquiring a file handle of a disk file directory and a file handle instance of a file to be traversed;
calculating a disk capacity value according to the file handle;
according to the file handle instance, calculating a first total space occupation amount of a file to be traversed and a second total space occupation amount of a file to be traversed, in which file traversing business is executed, of the file to be traversed;
when the first total space occupation amount is not calculated, calculating file traversal progress according to the disk capacity value and the second total space occupation amount;
and calculating the file traversing progress according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated.
In some embodiments, the processor when executing the computer program further performs the steps of: calculating a disk capacity value from the file handle, comprising: according to the file handle, calling a getmontent function to obtain a mounting directory structure body of a disk file directory, wherein the mounting directory structure body comprises a volume field, a block field and an idle field; calculating the total capacity value of the magnetic disk according to the volume field and the block field; calculating a disk idle capacity value according to the volume field and the idle field; and calculating the disk capacity value according to the disk total capacity value and the disk idle capacity value.
In some embodiments, the processor when executing the computer program further performs the steps of: according to the file handle example, calculating the first total space occupation amount of the file to be traversed comprises the following steps: obtaining a file handle instance of a current file to be traversed in the files to be traversed according to the paths to be traversed by adopting an iterator, and sequentially calculating the space occupation amount of each file; and accumulating the space occupation amount of the current file to be traversed and the space occupation amount of the file before the current file to be traversed in the path to be traversed to obtain a first total space occupation amount of the file to be traversed.
In some embodiments, the processor when executing the computer program further performs the steps of: according to the file handle example, calculating a second total space occupation amount of the files of the file to be traversed, which are subjected to the file traversing service, wherein the second total space occupation amount comprises: obtaining a file handle instance of a current file in the file to be traversed according to the path to be traversed by adopting an iterator; executing file traversing service on the current file according to the file handle instance of the current file to obtain a file of the executed file traversing service; and calculating the current file space occupation amount of the file traversing service to be executed, and accumulating the current file space occupation amount to the historical space occupation amount to obtain a second total space occupation amount, wherein the historical space occupation amount is the accumulated value of the space occupation amounts of all files before traversing the current file in the path to be traversed.
In some embodiments, the processor when executing the computer program further performs the steps of: calculating a disk capacity value from the file handle, comprising: and calculating the disk capacity value through the main thread according to the file handle.
In some embodiments, the processor when executing the computer program further performs the steps of: according to the file handle example, calculating the first total space occupation amount of the file to be traversed comprises the following steps: according to the file handle example, the first total space occupation amount of the file to be traversed is calculated through the traversing calculation thread.
In some embodiments, the processor when executing the computer program further performs the steps of: when the first total space occupation amount is not calculated, calculating a file traversal progress according to the disk capacity value and the second total space occupation amount, including:
when the first total space occupation amount is not calculated, calculating the file traversing progress through a progress calculation thread according to the disk capacity value and the second total space occupation amount;
when the first total space occupation amount is calculated, calculating a file traversal progress according to the first total space occupation amount and the second total space occupation amount, including:
when the first total space occupation amount is calculated, calculating the file traversing progress through the progress calculating thread according to the first total space occupation amount and the second total space occupation amount.
In some embodiments, a computer readable storage medium is provided having a computer program stored thereon, which when executed by a processor, performs the steps of:
acquiring a file handle of a disk file directory and a file handle instance of a file to be traversed;
calculating a disk capacity value according to the file handle;
according to the file handle instance, calculating a first total space occupation amount of a file to be traversed and a second total space occupation amount of a file to be traversed, in which file traversing business is executed, of the file to be traversed;
when the first total space occupation amount is not calculated, calculating file traversal progress according to the disk capacity value and the second total space occupation amount;
and calculating the file traversing progress according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated.
In some embodiments, the computer program when executed by the processor further performs the steps of: calculating a disk capacity value from the file handle, comprising: according to the file handle, calling a getmontent function to obtain a mounting directory structure body of a disk file directory, wherein the mounting directory structure body comprises a volume field, a block field and an idle field; calculating the total capacity value of the magnetic disk according to the volume field and the block field; calculating a disk idle capacity value according to the volume field and the idle field; and calculating the disk capacity value according to the disk total capacity value and the disk idle capacity value.
In some embodiments, the computer program when executed by the processor further performs the steps of: according to the file handle example, calculating the first total space occupation amount of the file to be traversed comprises the following steps: obtaining a file handle instance of a current file to be traversed in the files to be traversed according to the paths to be traversed by adopting an iterator, and sequentially calculating the space occupation amount of each file; and accumulating the space occupation amount of the current file to be traversed and the space occupation amount of the file before the current file to be traversed in the path to be traversed to obtain a first total space occupation amount of the file to be traversed.
In some embodiments, the computer program when executed by the processor further performs the steps of: according to the file handle example, calculating a second total space occupation amount of the files of the file to be traversed, which are subjected to the file traversing service, wherein the second total space occupation amount comprises: obtaining a file handle instance of a current file in the file to be traversed according to the path to be traversed by adopting an iterator; executing file traversing service on the current file according to the file handle instance of the current file to obtain a file of the executed file traversing service; and calculating the current file space occupation amount of the file traversing service to be executed, and accumulating the current file space occupation amount to the historical space occupation amount to obtain a second total space occupation amount, wherein the historical space occupation amount is the accumulated value of the space occupation amounts of all files before traversing the current file in the path to be traversed.
In some embodiments, the computer program when executed by the processor further performs the steps of: calculating a disk capacity value from the file handle, comprising: and calculating the disk capacity value through the main thread according to the file handle.
In some embodiments, the computer program when executed by the processor further performs the steps of: according to the file handle example, calculating the first total space occupation amount of the file to be traversed comprises the following steps: according to the file handle example, the first total space occupation amount of the file to be traversed is calculated through the traversing calculation thread.
In some embodiments, the computer program when executed by the processor further performs the steps of: when the first total space occupation amount is not calculated, calculating a file traversal progress according to the disk capacity value and the second total space occupation amount, including:
when the first total space occupation amount is not calculated, calculating the file traversing progress through a progress calculation thread according to the disk capacity value and the second total space occupation amount;
when the first total space occupation amount is calculated, calculating a file traversal progress according to the first total space occupation amount and the second total space occupation amount, including:
when the first total space occupation amount is calculated, calculating the file traversing progress through the progress calculating thread according to the first total space occupation amount and the second total space occupation amount.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the various embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples merely represent a few embodiments of the present application, which are described in more detail and are not to be construed as limiting the scope of the invention. It should be noted that it would be apparent to those skilled in the art that various modifications and improvements could be made without departing from the spirit of the present application, which would be within the scope of the present application. Accordingly, the scope of protection of the present application is to be determined by the claims appended hereto.

Claims (9)

1. A method for calculating a file traversal progress, the method comprising:
acquiring a file handle of a disk file directory and a file handle instance of a file to be traversed;
calculating a disk capacity value according to the file handle;
according to the file handle instance, calculating a first total space occupation amount of the file to be traversed and a second total space occupation amount of the file to be traversed, on which the file traversing service is executed;
calculating a file traversal progress according to the disk capacity value and the second total space occupation amount when the first total space occupation amount is not calculated;
calculating file traversal progress according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated;
the calculating a disk capacity value according to the file handle comprises the following steps:
according to the file handle, calling a getmontent function to obtain a mounting directory structure body of the disk file directory, wherein the mounting directory structure body comprises a volume field, a block field and an idle field;
calculating the total capacity value of the magnetic disk according to the volume field and the block field;
calculating a disk idle capacity value according to the volume field and the idle field;
and calculating the disk capacity value according to the disk total capacity value and the disk idle capacity value.
2. The method of claim 1, wherein calculating the first total space footprint of the file to be traversed based on the file handle instance comprises:
obtaining a file handle instance of a current file to be traversed in the files to be traversed according to the paths to be traversed by adopting an iterator;
and accumulating the space occupation amount of the current file to be traversed and the space occupation amount of the file before the current file to be traversed in the path to be traversed to obtain a first total space occupation amount of the file to be traversed.
3. The method of claim 1, wherein calculating a second total space occupation amount of the files of the file to be traversed, which are subjected to the file traversing business, according to the file handle instance, comprises:
obtaining a file handle instance of a current file in the file to be traversed according to the path to be traversed by adopting an iterator;
executing file traversing service on the current file according to the file handle instance of the current file to obtain a file of the executed file traversing service;
and calculating the current file space occupation amount of the file of the executed file traversing service, and accumulating the current file space occupation amount to the historical space occupation amount to obtain a second total space occupation amount, wherein the historical space occupation amount is the space occupation amount accumulated value of all files before traversing the current file in a path to be traversed.
4. The method of claim 1, wherein said calculating a disk capacity value from said file handle comprises:
and calculating a disk capacity value through the main thread according to the file handle.
5. The method of claim 2, wherein calculating the first total space occupation amount of the file to be traversed according to the file handle instance comprises:
and according to the file handle instance, calculating the first total space occupation amount of the file to be traversed through the traversal calculation thread.
6. The method of claim 1, wherein when the first total space usage is not calculated, calculating a file traversal progress from the disk capacity value and the second total space usage comprises:
when the first total space occupation amount is not calculated, calculating the file traversing progress through a progress calculation thread according to the disk capacity value and the second total space occupation amount;
when the first total space occupation amount is calculated, calculating a file traversal progress according to the first total space occupation amount and the second total space occupation amount, including:
and when the first total space occupation amount is calculated, calculating the file traversing progress through a progress calculation thread according to the first total space occupation amount and the second total space occupation amount.
7. A computing device for file traversal progress, the device comprising:
the acquisition module is used for acquiring file handles of the disk file catalogues and file handle instances of files to be traversed;
the calculation module is used for calculating a disk capacity value according to the file handle; the calculating a disk capacity value according to the file handle comprises the following steps: according to the file handle, calling a getmontent function to obtain a mounting directory structure body of the disk file directory, wherein the mounting directory structure body comprises a volume field, a block field and an idle field; calculating the total capacity value of the magnetic disk according to the volume field and the block field; calculating a disk idle capacity value according to the volume field and the idle field; calculating the disk capacity value according to the disk total capacity value and the disk idle capacity value;
the calculation module is further used for calculating the first total space occupation amount of the file to be traversed and the second total space occupation amount of the file to be traversed, on which the file traversing service is executed, in the file to be traversed according to the file handle instance;
the calculation module is further used for calculating file traversal progress according to the disk capacity value and the second total space occupation amount when the first total space occupation amount is not calculated;
and the calculation module is also used for calculating the file traversal progress according to the first total space occupation amount and the second total space occupation amount when the first total space occupation amount is calculated.
8. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any one of claims 1 to 6 when the computer program is executed by the processor.
9. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
CN202111240521.0A 2021-10-25 2021-10-25 Method and device for calculating file traversal progress, computer equipment and storage medium Active CN114003576B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111240521.0A CN114003576B (en) 2021-10-25 2021-10-25 Method and device for calculating file traversal progress, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111240521.0A CN114003576B (en) 2021-10-25 2021-10-25 Method and device for calculating file traversal progress, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN114003576A CN114003576A (en) 2022-02-01
CN114003576B true CN114003576B (en) 2024-01-12

Family

ID=79923777

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111240521.0A Active CN114003576B (en) 2021-10-25 2021-10-25 Method and device for calculating file traversal progress, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114003576B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113010479A (en) * 2021-03-18 2021-06-22 山东英信计算机技术有限公司 File management method, device and medium

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113010479A (en) * 2021-03-18 2021-06-22 山东英信计算机技术有限公司 File management method, device and medium

Also Published As

Publication number Publication date
CN114003576A (en) 2022-02-01

Similar Documents

Publication Publication Date Title
CN110351357B (en) Server current limiting method, device, computer equipment and storage medium
CN106407207B (en) Real-time newly-added data updating method and device
CN106776795B (en) Data writing method and device based on Hbase database
WO2018006721A1 (en) Method and apparatus for storing log file
CN110084476B (en) Case adjustment method, device, computer equipment and storage medium
CN114003576B (en) Method and device for calculating file traversal progress, computer equipment and storage medium
CN116719646A (en) Hot spot data processing method, device, electronic device and storage medium
CN111008233B (en) Method, device and equipment for accessing KV database
CN108664322A (en) Data processing method and system
CN109284260B (en) Big data file reading method and device, computer equipment and storage medium
CN116225314A (en) Data writing method, device, computer equipment and storage medium
CN115269558A (en) Data storage method, apparatus, device, storage medium and program product
CN109753384B (en) Cloud host snapshot backup method and device, computer equipment and storage medium
CN110969430B (en) Suspicious user identification method, suspicious user identification device, computer equipment and storage medium
US10102052B2 (en) Dumping resources
CN112100143A (en) File compression storage method, device, equipment and storage medium
CN112306824B (en) Disk performance evaluation method, system, device and computer readable storage medium
CN111191082A (en) Data management method and device, computer equipment and storage medium
CN112860755B (en) Service identifier generation method, device, computer equipment and medium
CN117435135B (en) Method, device and system for recovering storage space related to repeated data deletion
CN114185620B (en) Method and device for realizing acceleration of SSD firmware loading, computer equipment and storage medium
CN111158701B (en) Library module issuing method, device, equipment and storage medium
CN114390107B (en) Request processing method, apparatus, computer device, storage medium, and program product
CN117938514A (en) Token processing method, device, server, storage medium and program product
CN114968560A (en) Data backup method and device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant