CN114003576A - 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
CN114003576A
CN114003576A CN202111240521.0A CN202111240521A CN114003576A CN 114003576 A CN114003576 A CN 114003576A CN 202111240521 A CN202111240521 A CN 202111240521A CN 114003576 A CN114003576 A CN 114003576A
Authority
CN
China
Prior art keywords
file
space occupation
occupation amount
calculating
total space
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.)
Granted
Application number
CN202111240521.0A
Other languages
Chinese (zh)
Other versions
CN114003576B (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

Images

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 and a device for calculating file traversal progress, computer equipment and a storage medium, wherein the method comprises the following steps: the file processing method comprises the steps of obtaining a file handle of a disk file directory and a file handle example of a file to be traversed, calculating a disk capacity value according to the file handle, calculating a first total space occupation amount of the file to be traversed and a second total space occupation amount of the file of which the file traversal service is executed in the file to be traversed according to the file handle example, 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 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, reporting effective and accurate progress in most time in the whole file traversal process, and improving user experience.

Description

Method and device for calculating file traversal progress, computer equipment and storage medium
Technical Field
The present application relates to the field of internet technologies, and in particular, to a method and an apparatus for calculating a file traversal progress, a computer device, and a storage medium.
Background
Hard file traversal is a general term for a class of security software behaviors, which may be: the method comprises the steps of calculating the hash value of the full disk file for realizing global application program starting control or detecting the integrity of the full disk important file. These behaviors all require processing of all files in the entire hard disk or in a partial directory of an operating system, which may be long-lasting, and in order to improve user experience, it is necessary to report the progress of the file traversal task at any time during the processing.
When the progress calculation of the file traversal task is carried out, 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 too much time due to calculation progress, but the total size of the file to be traversed is far smaller than the total capacity of a disk, and if the accumulated value of the file is close to the total capacity of the disk, the progress of the file traversal task is difficult to be accurately calculated.
Disclosure of Invention
In view of the foregoing, it is necessary to provide a method, an apparatus, a computer device and a 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, and the method includes:
acquiring a file handle of a disk file directory and a file handle example of a file to be traversed;
calculating the disk capacity value according to the file handle;
calculating a first total space occupation amount of the file to be traversed and a second total space occupation amount of the file of which the file traversal service is executed in the file to be traversed according to the file handle example;
when the first total space occupation amount is not calculated, calculating the file traversal progress according to the disk capacity value and the second total space occupation amount;
and when the first total space occupation amount is calculated, calculating the file traversal progress according to the first total space occupation amount and the second total space occupation amount.
In one possible implementation, calculating a disk capacity value from the file handle includes:
calling a gettnent function to obtain a mounting directory structure body of the disk file directory according to the file handle, wherein the mounting directory structure body comprises a volume field, a block field and an idle field;
calculating the total capacity value of the disk according to the volume field and the block field;
calculating the free capacity value of the disk according to the volume field and the free field;
and calculating the capacity value of the disk according to the total capacity value and the free capacity value of the disk.
In one possible implementation, calculating a first total space occupation amount of a file to be traversed according to a file handle instance includes:
acquiring a file handle example of a current file to be traversed in the files to be traversed by adopting an iterator according to the path to be traversed, 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 the first total space occupation amount of the file to be traversed.
In one possible implementation manner, calculating a second total space occupation amount of a file subjected to a file traversal service in the files to be traversed according to the file handle instance includes:
acquiring a file handle example of a current file in the file to be traversed by adopting an iterator according to the path to be traversed;
according to the file handle example of the current file, executing the file traversal service on the current file to obtain the file of the executed file traversal service;
and calculating the current file space occupation amount of the file of the executed file traversal 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 the path to be traversed.
In one possible implementation, calculating a 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 amount of a file to be traversed according to a file handle instance includes:
and calculating the first total space occupation amount of the file to be traversed through the traversal calculation thread according to the file handle example.
In a possible implementation manner, 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 includes:
when the first total space occupation amount is not calculated, calculating the file traversal 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, the file traversal progress is calculated according to the first total space occupation amount and the second total space occupation amount, and the method comprises the following steps:
and when the first total space occupation amount is calculated, calculating the file traversal progress through the progress calculation thread according to the first total space occupation amount and the second total space occupation amount.
In a second aspect, a computing device for file traversal progress is provided, the device including:
the acquisition module is used for acquiring a file handle of a disk file directory and a file handle example of a file to be traversed;
the calculation module is used for calculating the disk capacity value according to the file handle;
the computing module is further used for computing a first total space occupation amount of the file to be traversed and a second total space occupation amount of the file of which the file traversal service is executed in the file to be traversed according to the file handle example;
the calculation module is further used for calculating the 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.
In a third aspect, a computer device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the method for calculating the file traversal progress in the first aspect or any one of the implementations 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, and the computer program, when executed by a processor, implements the method for calculating the file traversal progress in the first aspect or any one of the implementations of the first aspect.
According to the file traversal progress calculation method, the file traversal progress calculation device, the computer equipment and the storage medium, a file handle of a disk file directory and a file handle example of a file to be traversed are obtained, a disk capacity value is calculated according to the file handle, a first total space occupation amount of the file to be traversed and a second total space occupation amount of a file with file traversal service executed in the file to be traversed are calculated according to the file handle example, when the first total space occupation amount is not calculated, the file traversal progress is calculated according to the disk capacity value and the second total space occupation amount, when the first total space occupation amount is calculated, the file traversal progress is calculated according to the first total space occupation amount and the second total space occupation amount, effective and accurate traversal progress can be reported in most time in the whole file process, and user experience is improved.
Drawings
FIG. 1 is a flowchart illustrating a method for calculating a file traversal progress according to an embodiment of the present application;
FIG. 2 is a block diagram of a file traversal progress calculation device in one embodiment;
FIG. 3 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
When the calculation progress function is realized, the capacity use condition of the whole hard disk is usually obtained, after one file is processed, the occupied space amount of the file is accumulated into one variable, when the progress needs to be reported, a variable value is divided by a disk capacity value, the total occupied space amount of the traversal file needs to be far smaller than the disk capacity value, which is determined by the characteristics of a file system, and if the total occupied space amount of the traversal file is close to the disk capacity value, a complex calculation algorithm is needed. Meanwhile, when only the traversal operation of a part of directories is performed, the progress calculation method is invalid.
In some embodiments, as shown in fig. 1, a method for calculating a file traversal progress is provided, the method comprising the following steps:
s110, acquiring a file handle of a disk file directory and a file handle example of a file to be traversed;
when reading file data, an application program firstly calls an operating system function to transmit a file name, selects a path to the file to open the file, and the function retrieves a sequence number, namely a file handle which is a unique identification basis of the file.
And acquiring the file handle of the disk file directory by calling the setmtent function, wherein the acquired file handle is a/etc/mtab file handle in order to acquire the mounting information of the current system.
And acquiring a file handle example 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 a part of files of the disk file. For the above differences
And S120, calculating the disk capacity value according to the file handle.
And acquiring a disk file directory through the file handle, and calculating a disk capacity value according to the disk file directory.
In some embodiments, calculating a disk capacity value from the file handle includes:
calling a gettnent function to obtain a mounting directory structure body of the disk file directory according to the file handle, wherein the mounting directory structure body comprises a volume field, a block field and an idle field;
calculating the total capacity value of the disk according to the volume field and the block field;
calculating the free capacity value of the disk according to the volume field and the free field;
and calculating the capacity value of the disk according to the total capacity value and the free capacity value of the disk.
And identifying the disk file according to the file handle to obtain a disk file directory. And acquiring a mounted directory structure of the disk file directory by calling a getmtent function, and further extracting a volume field, a block field and a free field in the mounted directory structure. The volume field is used for acquiring the size of each data block, namely the space occupation of the data block, the block field is used for acquiring the total number of the data blocks of the file system, and the free field is used for acquiring the number of the unused data blocks. In practical applications, the volume field may be represented by f _ bsize, the block field may be represented by f _ blocks, and the free field may be represented by f _ free.
And obtaining the total capacity value of the disk by operating the calculation instructions corresponding to the volume field and the block field. And obtaining the free capacity value of the disk by operating the calculation instructions corresponding to the volume field and the free field. And subtracting the free capacity value of the disk from the total capacity value of the disk to obtain the capacity value of the disk.
S130, according to the file handle example, calculating a first total space occupation amount of the file to be traversed and a second total space occupation amount of the file traversal service executed in the file to be traversed.
The file handle instance is usually obtained according to the file handle, and contains file attributes, and is used for calculating the space occupation amount of the file, wherein the space occupation amount refers to the size of the disk space occupied by the file.
In some embodiments, calculating a first total space footprint for a file to be traversed based on a file handle instance comprises:
acquiring a file handle example of a current file to be traversed in the file to be traversed according to the path 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 the 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 in the path to be traversed before the current file to be traversed to obtain the first total space occupation amount of the file to be traversed
Taking the files to be traversed including A files, B files, C files, D files and E files, taking the path to be traversed as A-B-C-D-E as an example, adopting an iterator to obtain a file handle example of the A files, calculating the space occupation amount a of the A files, then obtaining a file handle example of the B files, and calculating the space occupation amount B of the B files, wherein at the moment, the B files are the current files to be traversed, the A files are the files before the B files in the path to be traversed, and the space occupation amount B of the B files is added with the space occupation amount a of the A files to obtain the accumulated space occupation amount a + B of the A files and the B files. And continuing to obtain a file handle example of the C file, calculating the space occupation amount 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 a path to be traversed, adding the space occupation amount C of the C file and the accumulated space occupation amounts a + B of the A file and the B file to obtain the accumulated space occupation amounts a + B + C of the A file, the B file and the C file, and so on.
In some embodiments, calculating a second total space occupation amount of the file subjected to the file traversal service in the files to be traversed according to the file handle instance comprises:
acquiring a file handle example of a current file in the file to be traversed by adopting an iterator according to the path to be traversed;
according to the file handle example of the current file, executing the file traversal service on the current file to obtain the file of the executed file traversal service;
and calculating the current file space occupation amount of the file of the executed file traversal 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 the path to be traversed.
The second space occupation amount is the total space occupation amount of the traversed files in the process of executing the file traversal business.
The historical space occupation amount is a file before the current file traversed in the process of executing the file traversal business.
After the space occupation amount of the current file is calculated and accumulated to the historical space occupation amount, the iterator continuously acquires a file handle example of a file next to the current file in the path to be traversed, executes file traversal service, calculates the space occupation amount of the file, and accumulates the space occupation amount of the file to the historical space occupation amount to obtain a second total space occupation amount.
And S140, when the first total space occupation amount is not calculated, calculating the 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 ratio of the second total space occupation amount to the disk capacity value is used as the file traversal 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 traversal progress value is smaller, and at the moment, the file traversal progress value is in a progress large error stage, and the progress reported by the system cannot be lost when the progress accurate value is not calculated.
And S150, when the first total space occupation amount is calculated, calculating the file traversal progress according to the first total space occupation amount and the second total space occupation amount.
And when the first total space occupation amount is calculated, taking the ratio of the second total space occupation amount to the first space occupation amount as the file traversal progress, wherein the file traversal progress is at a progress accurate stage. Because only accumulation of the occupation amount of the file space to be traversed is executed when the first total space occupation amount is calculated, the calculation process of the first total space occupation amount is not too long and generally occupies time within 10% of the file traversal business process, and then very accurate progress report is carried out on more than 90% of the time of the whole file traversal business process. In the stage of large error of the progress, because the traversal progress value of the file is smaller, when the progress is shifted to the stage of accurate progress, the progress value reported to the outside can generate a less obvious jump, and the jump can be used by a user more naturally, so that the user experience is improved.
In the embodiment of the application, effective and accurate progress can be reported in most of time in the whole file traversal process by obtaining the file handle of the disk file directory and the file handle example 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 traversal service executed in the file to be traversed according to the file handle example, calculating the 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 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, so that the user experience is improved.
In some embodiments, calculating a 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 for a file to be traversed based on a file handle instance comprises:
and calculating the first total space occupation amount of the file to be traversed through the traversal calculation thread according to the file handle example.
In some embodiments, when the first total space occupation amount is not calculated, calculating the file traversal progress according to the disk capacity value and the second total space occupation amount comprises:
when the first total space occupation amount is not calculated, calculating the file traversal 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, the file traversal progress is calculated according to the first total space occupation amount and the second total space occupation amount, and the method comprises the following steps:
and when the first total space occupation amount is calculated, calculating the file traversal progress through the progress calculation thread according to the first total space occupation amount and the second total space occupation amount.
The method comprises the steps that a main thread is utilized to calculate instantly to obtain a disk capacity value, meanwhile, a traversal calculation thread is started to calculate the first total space occupation amount of a file to be traversed, when the first total space occupation amount is not calculated, a progress calculation thread calculates the file traversal progress according to the disk capacity value and the second total space occupation amount, and when the first total space occupation amount is calculated, the progress calculation thread calculates the file traversal progress according to the first total space occupation amount and the second total space occupation amount. The progress report of a progress large error stage and a progress accurate stage is realized by adopting a three-thread parallel form, and too much performance consumption is avoided.
It should be understood that, although the steps in the flowchart of fig. 1 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in fig. 1 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
In one embodiment, as shown in FIG. 2, there is provided a file traversal progress computing device 200, comprising: an obtaining module 210 and a calculating 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;
the calculating module 220 is used for calculating the 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 the file to be traversed and a second total space occupation amount of a file in the file to be traversed, where the file traversal service is executed;
the calculating 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 calculating 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 calculation module 220 is specifically configured to:
calling a gettnent function to obtain a mounting directory structure body of the disk file directory according to the file handle, wherein the mounting directory structure body comprises a volume field, a block field and an idle field;
calculating the total capacity value of the disk according to the volume field and the block field;
calculating the free capacity value of the disk according to the volume field and the free field;
and calculating the capacity value of the disk according to the total capacity value and the free capacity value of the disk.
In some embodiments, the calculation module 220 is specifically configured to:
according to the file handle example, calculating a first total space occupation amount of the file to be traversed comprises the following steps:
acquiring a file handle example of a current file to be traversed in the files to be traversed by adopting an iterator according to the path to be traversed, 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 the first total space occupation amount of the file to be traversed.
In some embodiments, the calculation module 220 is specifically configured to:
calculating a second total space occupation amount of the file subjected to the file traversal service in the files to be traversed according to the file handle example, wherein the second total space occupation amount comprises the following steps:
acquiring a file handle example of a current file in the file to be traversed by adopting an iterator according to the path to be traversed;
according to the file handle example of the current file, executing the file traversal service on the current file to obtain the file of the executed file traversal service;
and calculating the current file space occupation amount of the file of the executed file traversal 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 the path to be traversed.
In some embodiments, the calculation module 220 is specifically configured to:
calculating a disk capacity value based on 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 amount of a file to be traversed according to a file handle instance includes:
and calculating the first total space occupation amount of the file to be traversed through the traversal calculation thread according to the file handle example.
In some embodiments, the calculation module 220 is specifically configured to:
when the first total space occupation amount is not calculated, calculating the file traversal progress through a progress calculation thread according to the disk capacity value and the second total space occupation amount;
and when the first total space occupation amount is calculated, calculating the file traversal progress through the progress calculation thread according to the first total space occupation amount and the second total space occupation amount.
The specific definition of the computing device regarding the file traversal progress may refer to the above definition of the computing method of the file traversal progress, and is not described herein again. The modules in the above-mentioned computing device for file traversal progress can be wholly or partially implemented by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the 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 comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. 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 is executed by a processor to implement a method of calculating a file traversal progress.
Those skilled in the art will appreciate that the architecture shown in fig. 3 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In some embodiments, there is provided a computer device 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 example of a file to be traversed;
calculating the disk capacity value according to the file handle;
calculating a first total space occupation amount of the file to be traversed and a second total space occupation amount of the file of which the file traversal service is executed in the file to be traversed according to the file handle example;
when the first total space occupation amount is not calculated, calculating the file traversal progress according to the disk capacity value and the second total space occupation amount;
and when the first total space occupation amount is calculated, calculating the file traversal progress according to the first total space occupation amount and the second total space occupation amount.
In some embodiments, the processor, when executing the computer program, further performs the steps of: calculating a disk capacity value based on the file handle, comprising: calling a gettnent function to obtain a mounting directory structure body of the disk file directory according to the file handle, wherein the mounting directory structure body comprises a volume field, a block field and an idle field; calculating the total capacity value of the disk according to the volume field and the block field; calculating the free capacity value of the disk according to the volume field and the free field; and calculating the capacity value of the disk according to the total capacity value and the free capacity value of the disk.
In some embodiments, the processor, when executing the computer program, further performs the steps of: according to the file handle example, calculating a first total space occupation amount of the file to be traversed comprises the following steps: acquiring a file handle example of a current file to be traversed in the files to be traversed by adopting an iterator according to the path to be traversed, 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 the 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: calculating a second total space occupation amount of the file subjected to the file traversal service in the files to be traversed according to the file handle example, wherein the second total space occupation amount comprises the following steps: acquiring a file handle example of a current file in the file to be traversed by adopting an iterator according to the path to be traversed; according to the file handle example of the current file, executing the file traversal service on the current file to obtain the file of the executed file traversal service; and calculating the current file space occupation amount of the file of the executed file traversal 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 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 based on 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 a first total space occupation amount of the file to be traversed comprises the following steps: and calculating the first total space occupation amount of the file to be traversed through the traversal calculation thread according to the file handle example.
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 the file traversal progress according to the disk capacity value and the second total space occupation amount, wherein the file traversal progress comprises the following steps:
when the first total space occupation amount is not calculated, calculating the file traversal 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, the file traversal progress is calculated according to the first total space occupation amount and the second total space occupation amount, and the method comprises the following steps:
and when the first total space occupation amount is calculated, calculating the file traversal progress through the progress calculation thread according to the first total space occupation amount and the second total space occupation amount.
In some embodiments, there is provided a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of:
acquiring a file handle of a disk file directory and a file handle example of a file to be traversed;
calculating the disk capacity value according to the file handle;
calculating a first total space occupation amount of the file to be traversed and a second total space occupation amount of the file of which the file traversal service is executed in the file to be traversed according to the file handle example;
when the first total space occupation amount is not calculated, calculating the file traversal progress according to the disk capacity value and the second total space occupation amount;
and when the first total space occupation amount is calculated, calculating the file traversal progress according to the first total space occupation amount and the second total space occupation amount.
In some embodiments, the computer program when executed by the processor further performs the steps of: calculating a disk capacity value based on the file handle, comprising: calling a gettnent function to obtain a mounting directory structure body of the disk file directory according to the file handle, wherein the mounting directory structure body comprises a volume field, a block field and an idle field; calculating the total capacity value of the disk according to the volume field and the block field; calculating the free capacity value of the disk according to the volume field and the free field; and calculating the capacity value of the disk according to the total capacity value and the free capacity value of the disk.
In some embodiments, the computer program when executed by the processor further performs the steps of: according to the file handle example, calculating a first total space occupation amount of the file to be traversed comprises the following steps: acquiring a file handle example of a current file to be traversed in the files to be traversed by adopting an iterator according to the path to be traversed, 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 the 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: calculating a second total space occupation amount of the file subjected to the file traversal service in the files to be traversed according to the file handle example, wherein the second total space occupation amount comprises the following steps: acquiring a file handle example of a current file in the file to be traversed by adopting an iterator according to the path to be traversed; according to the file handle example of the current file, executing the file traversal service on the current file to obtain the file of the executed file traversal service; and calculating the current file space occupation amount of the file of the executed file traversal 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 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 based on 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 a first total space occupation amount of the file to be traversed comprises the following steps: and calculating the first total space occupation amount of the file to be traversed through the traversal calculation thread according to the file handle example.
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 the file traversal progress according to the disk capacity value and the second total space occupation amount, wherein the file traversal progress comprises the following steps:
when the first total space occupation amount is not calculated, calculating the file traversal 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, the file traversal progress is calculated according to the first total space occupation amount and the second total space occupation amount, and the method comprises the following steps:
and when the first total space occupation amount is calculated, calculating the file traversal progress through the progress calculation thread according to the first total space occupation amount and the second total space occupation amount.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile 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), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A method for calculating file traversal progress is characterized by comprising the following steps:
acquiring a file handle of a disk file directory and a file handle example of a file to be traversed;
calculating a disk capacity value according to the file handle;
calculating a first total space occupation amount of the file to be traversed and a second total space occupation amount of a file of which the file traversal service is executed in the file to be traversed according to the file handle example;
when the first total space occupation amount is not calculated, calculating the file traversal progress according to the disk capacity value and the second total space occupation amount;
and when the first total space occupation amount is calculated, calculating the file traversal progress according to the first total space occupation amount and the second total space occupation amount.
2. The method of claim 1, wherein calculating a disk capacity value based on the file handle comprises:
calling a gettnent function to obtain a mount directory structure of the disk file directory according to the file handle, wherein the mount directory structure comprises a volume field, a block field and an idle field;
calculating the total capacity value of the disk according to the volume field and the block field;
calculating the free capacity value of the disk according to the volume field and the free field;
and calculating the disk capacity value according to the disk total capacity value and the disk free capacity value.
3. The method of claim 1, wherein the calculating a first total space occupation amount of the file to be traversed according to the file handle instance comprises:
acquiring a file handle example of a current file to be traversed in the files to be traversed by adopting an iterator according to the path 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 the first total space occupation amount of the file to be traversed.
4. The method of claim 1, wherein the calculating a second total space occupation amount of the file subjected to the file traversal service in the file to be traversed according to the file handle instance comprises:
acquiring a file handle example of a current file in the file to be traversed by adopting an iterator according to the path to be traversed;
according to the file handle example of the current file, executing file traversal service on the current file to obtain a file of the executed file traversal service;
and calculating the current file space occupation amount of the file of the executed file traversal service, and accumulating the current file space occupation amount to 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.
5. The method of claim 2, wherein said calculating a disk capacity value based on said file handle comprises:
and calculating the disk capacity value through the main thread according to the file handle.
6. The method of claim 3, wherein the calculating a first total space occupation amount of the file to be traversed according to the file handle instance comprises:
and calculating the first total space occupation amount of the file to be traversed through a traversal calculation thread according to the file handle example.
7. The method of claim 1, wherein 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 comprises:
when the first total space occupation amount is not calculated, calculating the file traversal 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 traversal progress according to the first total space occupation amount and the second total space occupation amount, and the method comprises the following steps:
and when the first total space occupation amount is calculated, calculating the file traversal progress through a progress calculation thread according to the first total space occupation amount and the second total space occupation amount.
8. A computing apparatus for file traversal progress, the apparatus comprising:
the acquisition module is used for acquiring a file handle of a disk file directory and a file handle example of a file to be traversed;
the calculation module is used for calculating the disk capacity value according to the file handle;
the computing module is further used for computing a first total space occupation amount of the file to be traversed and a second total space occupation amount of a file of the file to be traversed, in which the file traversal service is executed, according to the file handle instance;
the calculation module is further used for calculating the 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.
9. 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 steps of the method of any of claims 1 to 7 are implemented when the computer program is executed by the processor.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 7.
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 true CN114003576A (en) 2022-02-01
CN114003576B 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
CN114003576B (en) 2024-01-12

Similar Documents

Publication Publication Date Title
CN110351357B (en) Server current limiting method, device, computer equipment and storage medium
CN109039937B (en) Dynamic current limiting method, dynamic current limiting device, computer equipment and storage medium
CN109766349B (en) Task duplicate prevention method, device, computer equipment and storage medium
CN109597571B (en) Data storage method, data reading method, data storage device, data reading device and computer equipment
CN110377454B (en) Data verification method and device, computer equipment and storage medium
CN109215771B (en) Medical mapping relation library establishment method, device, computer equipment and storage medium
CN112363937B (en) Differential coverage rate testing method, differential coverage rate testing device, computer equipment and storage medium
CN109413153B (en) Data crawling method and device, computer equipment and storage medium
CN110727724A (en) Data extraction method and device, computer equipment and storage medium
CN108512948B (en) Address book updating method and device, computer equipment and storage medium
CN109753384B (en) Cloud host snapshot backup method and device, computer equipment and storage medium
CN110084476B (en) Case adjustment method, device, computer equipment and storage medium
CN108389124B (en) Data processing method, data processing device, computer equipment and storage medium
CN112527479A (en) Task execution method and device, computer equipment and storage medium
CN114003576A (en) Method and device for calculating file traversal progress, computer equipment and storage medium
CN109471852B (en) Medical database establishing method, medical database establishing device, computer equipment and storage medium
CN113312309A (en) Management method and device of snapshot chain and storage medium
CN110555017A (en) block chain data cleaning method and device, computer equipment and storage medium
CN115269558A (en) Data storage method, apparatus, device, storage medium and program product
CN110969430B (en) Suspicious user identification method, suspicious user identification device, computer equipment and storage medium
CN114239076A (en) Block chain-based electronic signature file processing method and device, and computer equipment
CN113626240A (en) Cluster fault recovery method and device, computer equipment and storage medium
US10102052B2 (en) Dumping resources
CN112860702A (en) Test execution work order verification method and device, computer equipment and storage medium
CN112800123A (en) Data processing method, data processing 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