CN114238161A - Intelligent disk fragment sorting method and device and electronic equipment - Google Patents
Intelligent disk fragment sorting method and device and electronic equipment Download PDFInfo
- Publication number
- CN114238161A CN114238161A CN202111632499.4A CN202111632499A CN114238161A CN 114238161 A CN114238161 A CN 114238161A CN 202111632499 A CN202111632499 A CN 202111632499A CN 114238161 A CN114238161 A CN 114238161A
- Authority
- CN
- China
- Prior art keywords
- fragment
- file
- block
- fragmented
- free 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.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/0223—User address space allocation, e.g. contiguous or non contiguous base addressing
- G06F12/023—Free address space management
- G06F12/0253—Garbage collection, i.e. reclamation of unreferenced memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F3/00—Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
- G06F3/06—Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
- G06F3/0601—Interfaces specially adapted for storage systems
- G06F3/0628—Interfaces specially adapted for storage systems making use of a particular technique
- G06F3/0638—Organizing or formatting or addressing of data
- G06F3/0644—Management of space entities, e.g. partitions, extents, pools
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (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 embodiment of the invention discloses an intelligent disk fragment sorting method, an intelligent disk fragment sorting device and electronic equipment, relates to the field of computer software, and can solve the problems that an existing disk fragment sorting scheme is not intelligent enough and the efficiency of sorting disk fragments is low. The intelligent disk defragmentation method comprises the following steps: acquiring all fragmented file information of a target disk; the fragment file information at least comprises a fragment file identifier, the number of fragment blocks of the fragment file identifier, the size of each fragment block and the address of a storage space of each fragment block; each chunk of the fragmented file is moved into a continuous free space with addresses preceding its storage space address. The invention can effectively improve the utilization rate of the disk, reduce the seek time of the hard disk and improve the use efficiency of the computer.
Description
Technical Field
The invention relates to the field of computer software, in particular to an intelligent disk defragmentation method and device and electronic equipment.
Background
At present, when the physical memory required by an application program is insufficient, an operating system generally generates a temporary swap file in a disk, and the disk space occupied by the file is virtualized into the memory. The virtual memory management program can frequently read and write the disk, and generates a large amount of fragments, which is a main reason for generating the disk fragments. In addition, when the content of a cluster (composed of sectors) in the middle of a disk is deleted, a smaller file is newly written, so that spaces appear on two sides of the file, at this time, a file is written, any one of the two spaces cannot accommodate the file, at this time, the file needs to be divided into two parts, and fragments are generated again. Most often, large files such as movies are downloaded, during which the disc user typically takes care of other things, and the downloaded movie file is forced to be divided into several fragments to be stored on the disc. Downloading is therefore an important source of fragmentation. And files are frequently deleted and added, and a large amount of disk fragments are generated if the file space is not large enough.
The seek time of the disk is prolonged by the disk fragments, and the system efficiency is influenced; meanwhile, too many disk fragments can occupy the available space of the disk, so that the space of the disk is wasted, the service life of the disk can be influenced by the disk fragments, the disk itself is damaged by frequently reading and writing the disk, and the service life of the disk can be greatly reduced by frequently reading and writing the disk for a long time. Therefore, an intelligent disk fragment sorting scheme is urgently needed to sort the disk fragments.
Disclosure of Invention
In view of this, embodiments of the present invention provide an intelligent disk fragment sorting method, an intelligent disk fragment sorting device, and an electronic device, which can solve the problems that the existing disk fragment sorting scheme is not intelligent enough and the efficiency of sorting the disk fragments is not high.
In a first aspect, an embodiment of the present invention provides an intelligent disk defragmentation method, including: acquiring all fragmented file information of a target disk; the fragment file information at least comprises a fragment file identifier, the number of fragment blocks of the fragment file identifier, the size of each fragment block and the address of a storage space of each fragment block;
each chunk of the fragmented file is moved into a continuous free space with addresses preceding its storage space address.
With reference to the first aspect, in a first implementation manner of the first aspect, the acquiring information of all fragmented files of the target disk includes:
and acquiring all fragmented file information of the target disk through a WMI external interface provided by Windows.
With reference to the first aspect or the first implementation manner of the first aspect, in a second implementation manner of the first aspect, the moving the fragment blocks of the fragment file into a continuous free space with addresses before addresses of a storage space of the fragment file includes:
and for each fragment file, sequentially moving all fragment blocks of the fragment file to a continuous free space with addresses before the addresses of the storage space of the corresponding fragment blocks according to the sequence of the fragment blocks from small to large.
With reference to the second implementation manner of the first aspect, in a third implementation manner of the first aspect, the moving each fragment block of the fragment file into a continuous free space with an address before a storage space address thereof includes:
for each fragmented file, sequencing all fragmented blocks of the fragmented file according to the sequence of the fragmented blocks from small to large to obtain a sequencing result of the fragmented blocks to be sorted corresponding to the fragmented file;
acquiring a fragment file of any fragment block to be sorted as a current fragment file;
acquiring a 1 st fragment block in a fragment block sequencing result to be sorted corresponding to the current fragment file as a current target fragment block;
acquiring the nth continuous free space nearest to the head of the target disk; wherein the initial value of n is 1;
judging whether the address of the nth continuous free space is before the address of the storage space of the current target fragment block;
if the address of the nth continuous free space is before the address of the storage space of the current target fragment block, judging whether the size of the nth continuous free space is not smaller than the size of the current target fragment block;
if the size of the nth continuous free space is not smaller than the size of the current target fragment block, moving the current target fragment block to the nth continuous free space;
updating the address of the storage space of the current target fragment block, merging the original storage space of the current target fragment block with the adjacent continuous free space of the current target fragment block, deleting the current target fragment block in the sequencing result of the fragment blocks to be sorted corresponding to the current fragment file, and restoring n to the initial value;
judging whether the fragmented blocks to be sorted corresponding to the current fragmented file have fragmented blocks to be sorted or not;
if the fragment blocks to be sorted still exist in the fragment block sorting result to be sorted corresponding to the current fragment file, returning to execute the step of obtaining the 1 st fragment block in the fragment block sorting result to be sorted corresponding to the current fragment file;
and if the fragment block to be sorted corresponding to the current fragment file does not have the fragment block to be sorted in the sorting result, returning to execute the step of acquiring any fragment file of the fragment block to be sorted as the current fragment file.
With reference to the third implementation manner of the first aspect, in a fourth implementation manner of the first aspect, after the determining whether the address of the nth continuous free space is before the address of the storage space of the current target fragment block, the method further includes:
and if the address of the nth continuous free space is behind the address of the storage space of the current target fragment block, executing the step of deleting the current target fragment block in the fragment block sequencing result to be sorted corresponding to the current fragment file.
With reference to the third implementation manner of the first aspect, in a fifth implementation manner of the first aspect, after the determining whether the size of the nth continuous free space is not smaller than the size of the current target fragment block, the method further includes:
and if the size of the nth continuous free space is smaller than the size of the current target fragment block, enabling n to be n +1, and then returning to execute the step of acquiring the nth continuous free space closest to the head of the target disk.
With reference to the third implementation manner of the first aspect, in a sixth implementation manner of the first aspect, the moving the current target fragment block to the nth continuous free space includes:
and calling a DeviceloControl function of Windows, and moving the current target fragment block to the nth continuous free space through an FSCTL _ MOVE _ FILE control code.
In a second aspect, an embodiment of the present invention provides an intelligent defragmenter device, including:
the first acquisition module is used for acquiring all fragmented file information of the target disk; the fragment file information at least comprises a fragment file identifier, the number of fragment blocks of the fragment file identifier, the size of each fragment block and the address of a storage space of each fragment block;
and the sorting module is used for moving each fragment block of the fragment file into a continuous free space with the address in front of the address of the storage space.
With reference to the second aspect, in a first implementation manner of the second aspect, the first obtaining module obtains all fragmented file information of the target disk through a WMI external interface provided by Windows.
With reference to the second aspect or the first implementation manner of the second aspect, in a second implementation manner of the second aspect, the sorting module is specifically configured to, for each fragmented file, sequentially move all fragmented blocks of the fragmented file into a continuous free space with addresses before storage space addresses of corresponding fragmented blocks according to a sequence of the fragmented blocks from small to large.
With reference to the second embodiment of the second aspect, in a third embodiment of the second aspect, the finishing module includes:
the sorting unit is used for sorting all the fragmented blocks of each fragmented file according to the sequence of the fragmented blocks from small to large to obtain a fragmented block sorting result to be sorted corresponding to the fragmented file;
the first acquisition unit is used for acquiring a fragment file of any fragment block to be sorted as a current fragment file;
the second obtaining unit is used for obtaining the 1 st fragment block in the fragment block sequencing result to be sorted corresponding to the current fragment file as the current target fragment block;
a third obtaining unit, configured to obtain an nth continuous free space closest to the head of the target disk; wherein the initial value of n is 1;
a first judging unit, configured to judge whether an address of the nth continuous free space is before a storage space address of the current target fragment block;
a second judging unit, configured to judge whether the size of the nth continuous free space is not smaller than the size of the current target fragment block when the judgment result of the first judging unit is yes;
a moving unit, configured to move the current target fragment block to the nth continuous free space when the determination result of the second determining unit is yes;
the updating and sorting unit is used for updating the address of the storage space of the current target fragment block after the current target fragment block is successfully moved to the nth continuous free space by the moving unit, merging the original storage space of the current target fragment block with the adjacent continuous free space, deleting the current target fragment block in the fragment block sequencing result to be sorted corresponding to the current fragment file, and restoring n to the initial value;
a third judging unit, configured to judge whether there are fragmented blocks to be sorted in a fragmented block sorting result to be sorted corresponding to the current fragmented file after the target fragmented block in the fragmented block sorting result to be sorted corresponding to the current fragmented file is deleted by the updating and sorting unit; if so, triggering the second obtaining unit to obtain the 1 st fragment block in the fragment block sequencing result to be sorted corresponding to the current fragment file, otherwise, triggering the first obtaining unit to obtain the fragment file of any fragment block to be sorted as the current fragment file.
With reference to the third implementation manner of the second aspect, in a fourth implementation manner of the second aspect, the update sorting unit is further configured to delete the current target fragment block in a fragment block sorting result to be sorted corresponding to a current fragment file when the determination result of the first determination unit is negative.
With reference to the third implementation manner of the second aspect, in a fifth implementation manner of the second aspect, the finishing module further includes:
and the counting unit is used for enabling n to be n +1 when the judgment result of the second judging unit is negative, and then triggering the third acquiring unit to acquire the nth continuous free space closest to the head of the target disk.
With reference to the third implementation manner of the second aspect, in a sixth implementation manner of the second aspect, the update sorting unit is specifically configured to call a devicolocontrol function of Windows, and MOVE the current target fragment block to the nth continuous free space through an FSCTL _ MOVE _ FILE control code.
In a third aspect, an embodiment of the present invention provides an electronic device, where the electronic device includes: the device comprises a shell, a processor, a memory, a circuit board and a power circuit, wherein the circuit board is arranged in a space enclosed by the shell, and the processor and the memory are arranged on the circuit board; a power supply circuit for supplying power to each circuit or device of the electronic apparatus; the memory is used for storing executable program codes; the processor executes a program corresponding to the executable program code by reading the executable program code stored in the memory, for executing the method described in any of the method embodiments.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, in which a computer program is stored, and the computer program is executed by a processor or implements the method steps of any of the foregoing method embodiments.
According to the intelligent disk defragmentation method, the device and the electronic equipment provided by the embodiment of the invention, the detailed information of all fragmented files of the target disk is obtained, and then the fragmented contents of the fragmented files are moved to the continuous free space in front of the disk, so that the problems that the conventional disk defragmentation scheme is not intelligent enough and the defragmentation efficiency is not high are solved, the utilization rate of the disk can be effectively improved, the seek time of the hard disk is reduced, and the use efficiency of a computer is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a flowchart of a first embodiment of an intelligent defragmentation method according to the present invention;
FIG. 2 is a flowchart of a second embodiment of the intelligent defragmentation method according to the present invention;
FIG. 3 is a schematic structural diagram of an embodiment of an intelligent defragmenter device according to the present invention;
FIG. 4 is a schematic structural diagram of a second embodiment of an intelligent defragmenter device according to the present invention;
FIG. 5 is a schematic diagram of a third structure of an embodiment of an intelligent defragmenter device according to the present invention;
fig. 6 is a schematic structural diagram of an embodiment of an electronic device according to the present invention.
Detailed Description
The following describes an intelligent disk defragmentation method, an intelligent disk defragmentation device, and an electronic apparatus according to embodiments of the present invention in detail with reference to the accompanying drawings.
It should be understood that the described embodiments are only some embodiments of the invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a flowchart of a first embodiment of an intelligent defragmentation method of the present invention, as shown in fig. 1, the method of this embodiment may include steps 101-102:
The fragment file information at least comprises a fragment file identifier, the number of fragment blocks of the fragment file identifier, the size of each fragment block and the address of a storage space of each fragment block.
In this embodiment, the fragment file identifier may be an absolute path + a file name of the file, for example: and C, the file name of Program Files, Microsoft Office and the like can uniquely identify a file and can visually reflect information such as the position, the file attribute and the like of the file. In addition, the number of fragment blocks of the file, the size of each fragment block, and the storage space address of each fragment block can objectively reflect information of the file, for example: the more the number of the fragment blocks of the file is, the smaller the size of each block is, the farther the address interval of the storage space of each fragment block is, which objectively reflects that the storage of the fragment file is unreasonable, the object of arranging the file is to reduce the number of the fragment blocks as much as possible, increase the size of each block, and make the addresses of the storage space of each fragment block continuous, which can effectively improve the efficiency of arranging fragments.
As an alternative embodiment, the step S101 includes: and acquiring all fragmented file information of the target disk through a WMI external interface provided by Windows.
In this embodiment, WMI (Windows Management Instrumentation) is a core Windows Management technology, and WMI has a set of APIs, libraries, and services, and can be used to read local hard disk information, read user information of a remote computer, read domain user information, and the like. Users may manage local and remote computers using WMI. First, applications of both the Win32_ DiskPartion and Win32_ LogicalDisk classes can be used. Win32_ Diskpartition is used for querying disk partition information, and Win32_ LogicalDisk is used for querying logical disk information. Then, according to the partition information, information of all files in the partition is obtained, and finally, according to the storage attribute information of the files, for example: the fragment number information of the file storage can know which files are fragment files. The whole implementation process has the advantages of simple and convenient operation and easy implementation.
In this embodiment, because the storage process of the file in the disk is to store the file content at the position before the address, and then store the file content sequentially backwards, a large number of files are stored at the position before the address in a centralized manner, and each fragment block of the fragment file is moved to the continuous free space with the address before the address of the storage space, so that the storage address of the fragment file can be stored at the position before the address as much as possible, and the storage mode enables the file of the whole disk to be stored at the position before the address in a centralized manner, so that when reading each file, the magnetic head of the disk does not need to go back and forth to the position before the disk address and the position after the disk address, thereby effectively improving the reading efficiency, and effectively prolonging the life of the disk.
As an alternative embodiment, the step S102 includes: and for each fragment file, sequentially moving all fragment blocks of the fragment file to a continuous free space with addresses before the addresses of the storage space of the corresponding fragment blocks according to the sequence of the fragment blocks from small to large.
In this embodiment, all fragment blocks of a fragment file are sequentially moved to a continuous free space with addresses before the addresses of the storage space corresponding to the fragment blocks according to the sequence from small to large of the size of the fragment blocks, so that the number of fragments of the file is reduced to the greatest extent, and the addresses stored by the file are more concentrated. For example, if there is a continuous free space 1 with a size of 6KB, there is a fragmented file with fragment 1 of 2KB, fragment 2 of 3KB and fragment 3 of 5KB, and the fragments are sequentially moved to the free space from small to large according to the sequence of fragment blocks, then the fragments 1 and 2 of the file will be written into the free space 1, and fragment 3 cannot be written, so that the number of fragments of the file is reduced by 1, and if fragment 3 is written into the free space first, the number of fragments of the file is still 3, so that the purpose of reducing the number of fragments is not achieved.
According to the intelligent disk defragmentation method provided by the embodiment of the invention, the detailed information of all fragmented files of the target disk is obtained, and then the fragmented contents of the fragmented files are moved to the continuous free space in front of the disk, so that the problems that the conventional disk defragmentation scheme is not intelligent enough and the defragmentation efficiency of the disk is not high are solved, the utilization rate of the disk can be effectively improved, the seek time of the hard disk is reduced, and the use efficiency of a computer is improved.
Fig. 2 is a flowchart of a second embodiment of the intelligent defragmentation method of the present invention, and as shown in fig. 2, the method of this embodiment may include steps 201 and 211:
In this embodiment, this step is similar to step 101 of the above method embodiment, and is not described here again.
And 204, acquiring the 1 st fragment block in the fragment block sequencing result to be sorted corresponding to the current fragment file as the current target fragment block.
And step 205, acquiring the nth continuous free space closest to the head of the target disk.
Wherein the initial value of n is 1.
In this embodiment, the state information of each cluster may be obtained through FSCTL _ GET _ VOLUME _ BITMAP of DeviceIoControl, and if an FSCTL _ GET _ VOLUME _ BITMAP control code may be sent to a disk device, the occupation status of each cluster in the returned buffer area is represented by one bit of 0 or 1, where 0 represents free (free), and 1 represents allocated. The cluster is a unit of a system when reading and writing files on the hard disk, and is a data block. The sector is the minimum unit value of hard disk partition, namely the occupied place of the cluster (data block), and the size of the cluster is larger than that of the sector. The number of sectors per cluster of a hard disk is related to the total capacity size of the hard disk. Sectors are the basic unit on a storage medium that can be addressed by hardware, and the x86 system almost always defines a sector size of 512 bytes; clusters are addressable data blocks used by many file system formats, the size of a cluster is always an integer multiple of the sector size, and different file systems may have different default cluster sizes for different sized volumes (partitions), such as FAT32 with a default cluster size of 4KB for partitions below 8GB, 16 sectors (8KB) for partitions between 8GB and 16GB, and 8 sectors (4KB) for NTFS with a default cluster size for partitions greater than 2 GB. Here, the number of consecutive free clusters (i.e., clusters with free state) can be obtained by FSCTL _ GET _ VOLUME _ BITMAP, and then the number is multiplied by the size of the clusters to obtain consecutive free space.
In the embodiment, because the files are stored in the disk according to the addresses in sequence and the files are moved to the disk space with the front addresses, the positions where the files are stored can be concentrated as much as possible, so that when the files are read, the magnetic head of the disk does not jump in a large range, and the service life of the disk is effectively prolonged.
As an alternative embodiment, this step 206 further includes: if the address of the nth continuous free space is behind the address of the storage space of the current target fragment block, step 210 is executed.
In this embodiment, if the address of the nth continuous space is found to be behind the address of the storage space of the target fragment block, it indicates that the addresses of all the continuous free spaces behind the nth continuous space are behind the address of the storage space of the target fragment block, so that the target fragment block does not need to be moved, and the defragmentation efficiency is effectively improved.
In this embodiment, if the size of the continuous free space is found to be not smaller than the size of the current target fragment block, the target fragment block may be moved to the continuous free space, for example, the continuous free space is 8KB, and the target fragment block is 7KB, then the 7KB content of the target fragment may be moved to the continuous free space, otherwise, if the continuous free space is 6KB, the target fragment should not be moved, otherwise, the 7KB of the target fragment is divided into fragment blocks of 6KB and 1KB, and instead, the number of fragments is increased.
As an alternative embodiment, step 207 includes: if the size of the nth continuous free space is smaller than the size of the current target fragment block, let n be n +1, and then return to step 205.
In this embodiment, once the current contiguous space is found to be smaller than the size of the fragment, the next contiguous space is immediately traversed, thereby effectively improving the efficiency of defragmentation of the disk.
And 208, moving the current target fragment block to the nth continuous free space.
As an alternative embodiment, in this step 208, the DeviceloControl function of Windows is called, and the current target fragment block is moved to the nth continuous free space through the FSCTL _ MOVE _ FILE control code.
And 209, updating the address of the storage space of the current target fragment block, and merging the original storage space of the current target fragment block and the continuous free space adjacent to the original storage space.
And 210, deleting the current target fragment block in the fragment block sequencing result to be sorted corresponding to the current fragment file, and restoring n to an initial value.
The intelligent disk defragmentation method provided by the embodiment of the invention can move each fragment content of the fragmented files to the continuous free space in front of the disk, so that the fragmented files are merged and stored at the position close to the front of the disk, the fragment number of the fragmented files is reduced, and the files are stored at the starting position of the disk more intensively, thereby solving the problems that the existing disk defragmentation scheme is not intelligent enough and the disk defragmentation efficiency is not high, effectively improving the disk utilization rate, reducing the seek time of the hard disk and improving the computer utilization efficiency.
Fig. 3 is a schematic structural diagram of an embodiment of an intelligent defragmenter device according to the present invention, and as shown in fig. 3, the device of this embodiment may include:
the first acquisition module 1 is used for acquiring all fragmented file information of a target disk; the fragment file information at least comprises a fragment file identifier, the number of fragment blocks of the fragment file identifier, the size of each fragment block and the address of a storage space of each fragment block. Preferably, the first obtaining module 1 obtains all fragmented file information of the target disk through a WMI external interface provided by Windows.
And the sorting module 2 is used for moving each fragment block of the fragment file into a continuous free space with the address before the address of the storage space. Preferably, the sorting module 2 is specifically configured to, for each fragmented file, sequentially move all fragmented blocks of the fragmented file into a continuous free space with addresses before the addresses of the storage space of the corresponding fragmented blocks according to the sequence of the fragmented blocks from small to large.
The apparatus of this embodiment may be used to implement the technical solution of the method embodiment shown in fig. 1, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 4 is a schematic structural diagram of a second embodiment of an intelligent defragmentation device according to the present invention, as shown in fig. 4, the defragmentation module 2 of the present embodiment may further include:
the sorting unit 21 is configured to, for each fragmented file, sort all fragmented blocks of the fragmented file according to a sequence of the fragmented blocks from small to large, and obtain a sorting result of the fragmented blocks to be sorted corresponding to the fragmented file.
A first obtaining unit 22, configured to obtain a fragment file of any fragment block yet to be sorted as a current fragment file.
The second obtaining unit 23 is configured to obtain a 1 st fragment block in a fragment block sorting result to be sorted corresponding to the current fragment file, as the current target fragment block.
A third obtaining unit 24, configured to obtain an nth continuous free space closest to the head of the target disk; wherein the initial value of n is 1.
A first judging unit 25, configured to judge whether an address of the nth continuous free space is before a storage space address of the current target chunk.
A second judging unit 26, configured to judge whether the size of the nth continuous free space is not smaller than the size of the current target fragment block when the judgment result of the first judging unit 25 is yes.
A moving unit 27, configured to, when the determination result of the second determining unit 26 is yes, move the current target fragment block to the nth continuous free space.
An updating and sorting unit 28, configured to update the address of the storage space of the current target fragment block after the moving unit 27 successfully moves the current target fragment block to the nth continuous free space, merge the original storage space of the current target fragment block with the continuous free space adjacent to the original storage space, delete the current target fragment block in the fragment block sorting result to be sorted corresponding to the current fragment file, and restore n to the initial value. Preferably, the updating and sorting unit 28 is further configured to delete the current target fragment block in the sorting result of the fragment blocks to be sorted corresponding to the current fragment file when the determination result of the first determining unit 25 is negative. Preferably, the update sorting unit 28 is specifically configured to call a DeviceloControl function of Windows, and MOVE the current target fragment block to the nth continuous free space through the FSCTL _ MOVE _ FILE control code.
A third determining unit 29, configured to determine whether there are fragmented blocks to be sorted in the fragmented block sorting result to be sorted corresponding to the current fragmented file after the current target fragmented block in the fragmented block sorting result to be sorted corresponding to the current fragmented file is deleted by the updating and sorting unit 28; if so, triggering the second obtaining unit 23 to obtain the 1 st fragment block in the fragment block ordering result to be sorted corresponding to the current fragment file, otherwise, triggering the first obtaining unit 22 to obtain any fragment file of the fragment blocks to be sorted as the current fragment file.
The apparatus of this embodiment may be used to implement the technical solutions of the method embodiments shown in fig. 1 or fig. 2, and the implementation principles and technical effects are similar, which are not described herein again.
Fig. 5 is a schematic structural diagram of a third embodiment of an intelligent defragmentation device according to the present invention, and as shown in fig. 5, the device of this embodiment further includes, on the basis of the device structure shown in fig. 4, an organizing module 2:
and a counting unit 210, configured to, when the determination result of the second determining unit 26 is negative, make n equal to n +1, and then trigger the third obtaining unit 24 to obtain the nth continuous free space closest to the target disk head.
The apparatus of this embodiment may be used to implement the technical solutions of the method embodiments shown in fig. 1 or fig. 2, and the implementation principles and technical effects are similar, which are not described herein again.
Fig. 6 is a schematic structural diagram of an embodiment of an electronic device of the present invention, and as shown in fig. 6, the electronic device may include: the device comprises a shell 41, a processor 42, a memory 43, a circuit board 44 and a power circuit 45, wherein the circuit board 44 is arranged inside a space enclosed by the shell 41, and the processor 42 and the memory 43 are arranged on the circuit board 44; a power supply circuit 45 for supplying power to each circuit or device of the electronic apparatus; the memory 43 is used for storing executable program code; the processor 42 executes a program corresponding to the executable program code by reading the executable program code stored in the memory 43, for executing the intelligent defragmentation method of any of the foregoing embodiments.
The electronic device exists in a variety of forms, including but not limited to:
(1) a mobile communication device: such devices are characterized by mobile communications capabilities and are primarily targeted at providing voice, data communications. Such terminals include: smart phones (e.g., iphones), multimedia phones, functional phones, and low-end phones, among others.
(2) Ultra mobile personal computer device: the equipment belongs to the category of personal computers, has calculation and processing functions and generally has the characteristic of mobile internet access. Such terminals include: PDA, MID, and UMPC devices, etc., such as ipads.
(3) A portable entertainment device: such devices can display and play multimedia content. This type of device comprises: audio, video players (e.g., ipods), handheld game consoles, electronic books, and smart toys and portable car navigation devices.
(4) A server: the device for providing the computing service comprises a processor, a hard disk, a memory, a system bus and the like, and the server is similar to a general computer architecture, but has higher requirements on processing capacity, stability, reliability, safety, expandability, manageability and the like because of the need of providing high-reliability service.
(5) And other electronic equipment with data interaction function.
The embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and the computer program is executed by a processor or implements the steps of the intelligent disk defragmentation method according to any of the foregoing embodiments.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
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 a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The above description is only for the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims (10)
1. An intelligent disk defragmentation method, comprising:
acquiring all fragmented file information of a target disk; the fragment file information at least comprises a fragment file identifier, the number of fragment blocks of the fragment file identifier, the size of each fragment block and the address of a storage space of each fragment block;
each chunk of the fragmented file is moved into a continuous free space with addresses preceding its storage space address.
2. The intelligent disk defragmentation method according to claim 1, wherein the obtaining of all fragmented file information of the target disk comprises:
and acquiring all fragmented file information of the target disk through a WMI external interface provided by Windows.
3. The intelligent disk defragmentation method according to claim 1 or 2, wherein said moving each fragmented block of the fragmented file into a continuous free space with addresses preceding its storage space address comprises:
and for each fragment file, sequentially moving all fragment blocks of the fragment file to a continuous free space with addresses before the addresses of the storage space of the corresponding fragment blocks according to the sequence of the fragment blocks from small to large.
4. The intelligent defragmentation method according to claim 3, wherein said moving each fragmented block of the fragmented file into a continuous free space having addresses preceding its storage space address comprises:
for each fragmented file, sequencing all fragmented blocks of the fragmented file according to the sequence of the fragmented blocks from small to large to obtain a sequencing result of the fragmented blocks to be sorted corresponding to the fragmented file;
acquiring a fragment file of any fragment block to be sorted as a current fragment file;
acquiring a 1 st fragment block in a fragment block sequencing result to be sorted corresponding to the current fragment file as a current target fragment block;
acquiring the nth continuous free space nearest to the head of the target disk; wherein the initial value of n is 1;
judging whether the address of the nth continuous free space is before the address of the storage space of the current target fragment block;
if the address of the nth continuous free space is before the address of the storage space of the current target fragment block, judging whether the size of the nth continuous free space is not smaller than the size of the current target fragment block;
if the size of the nth continuous free space is not smaller than the size of the current target fragment block, moving the current target fragment block to the nth continuous free space;
updating the address of the storage space of the current target fragment block, merging the original storage space of the current target fragment block with the adjacent continuous free space of the current target fragment block, deleting the current target fragment block in the sequencing result of the fragment blocks to be sorted corresponding to the current fragment file, and restoring n to the initial value;
judging whether the fragmented blocks to be sorted corresponding to the current fragmented file have fragmented blocks to be sorted or not;
if the fragment blocks to be sorted still exist in the fragment block sorting result to be sorted corresponding to the current fragment file, returning to execute the step of obtaining the 1 st fragment block in the fragment block sorting result to be sorted corresponding to the current fragment file;
and if the fragment block to be sorted corresponding to the current fragment file does not have the fragment block to be sorted in the sorting result, returning to execute the step of acquiring any fragment file of the fragment block to be sorted as the current fragment file.
5. The intelligent defragmentation method according to claim 4, further comprising, after said determining whether the address of the nth consecutive free space is before the address of the storage space of the current target fragment block:
and if the address of the nth continuous free space is behind the address of the storage space of the current target fragment block, executing the step of deleting the current target fragment block in the fragment block sequencing result to be sorted corresponding to the current fragment file.
6. The intelligent disk defragmentation method according to claim 4, further comprising, after said determining whether the size of the nth contiguous free space is not smaller than the size of the current target fragment block:
and if the size of the nth continuous free space is smaller than the size of the current target fragment block, enabling n to be n +1, and then returning to execute the step of acquiring the nth continuous free space closest to the head of the target disk.
7. The intelligent defragmentation method according to claim 4, wherein said moving the current target defragmentation block to the nth contiguous free space comprises:
and calling a DeviceloControl function of Windows, and moving the current target fragment block to the nth continuous free space through an FSCTL _ MOVE _ FILE control code.
8. An intelligent defragmenter device, comprising:
the first acquisition module is used for acquiring all fragmented file information of the target disk; the fragment file information at least comprises a fragment file identifier, the number of fragment blocks of the fragment file identifier, the size of each fragment block and the address of a storage space of each fragment block;
and the sorting module is used for moving each fragment block of the fragment file into a continuous free space with the address in front of the address of the storage space.
9. The intelligent defragmenter device according to claim 8, wherein the first obtaining module obtains all defragmented file information of the target disc through a WMI external interface provided by Windows.
10. The intelligent disk defragmentation device according to claim 8 or 9, wherein the defragmentation module is specifically configured to, for each fragmented file, sequentially move all fragmented blocks of the fragmented file from small to large into a continuous free space having addresses before the addresses of the storage space of the corresponding fragmented block.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111632499.4A CN114238161A (en) | 2021-12-28 | 2021-12-28 | Intelligent disk fragment sorting method and device and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111632499.4A CN114238161A (en) | 2021-12-28 | 2021-12-28 | Intelligent disk fragment sorting method and device and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114238161A true CN114238161A (en) | 2022-03-25 |
Family
ID=80743958
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111632499.4A Pending CN114238161A (en) | 2021-12-28 | 2021-12-28 | Intelligent disk fragment sorting method and device and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114238161A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116225339A (en) * | 2023-03-14 | 2023-06-06 | 大庆市壹零零壹数据服务有限公司 | Computer information storage analysis system and method based on Internet of things |
WO2024212879A1 (en) * | 2023-04-14 | 2024-10-17 | 深圳Tcl新技术有限公司 | File processing method and apparatus, and device and storage medium |
-
2021
- 2021-12-28 CN CN202111632499.4A patent/CN114238161A/en active Pending
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116225339A (en) * | 2023-03-14 | 2023-06-06 | 大庆市壹零零壹数据服务有限公司 | Computer information storage analysis system and method based on Internet of things |
CN116225339B (en) * | 2023-03-14 | 2023-12-12 | 北京兴汉网际股份有限公司 | Computer information storage analysis system and method based on Internet of things |
WO2024212879A1 (en) * | 2023-04-14 | 2024-10-17 | 深圳Tcl新技术有限公司 | File processing method and apparatus, and device and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2017185579A1 (en) | Method and apparatus for data storage | |
CN110018998B (en) | File management method and system, electronic equipment and storage medium | |
WO2021073635A1 (en) | Data storage method and device | |
US20080059752A1 (en) | Virtualization system and region allocation control method | |
CN114238161A (en) | Intelligent disk fragment sorting method and device and electronic equipment | |
CN110908609B (en) | Method, system and equipment for processing disk and readable storage medium | |
CN108647151A (en) | It is a kind of to dodge system metadata rule method, apparatus, equipment and storage medium entirely | |
JP2002202902A (en) | Partition formation method and deletion method, recording medium having program recorded thereon, and information processing device | |
CN107480074B (en) | Caching method and device and electronic equipment | |
CN108875046A (en) | A kind of storage system access method, device and electronic equipment | |
CN106201652B (en) | Data processing method and virtual machine | |
CN109918380A (en) | Data processing method, device, storage medium and electronic equipment | |
CN107122130A (en) | A kind of data delete method and device again | |
CN112463753A (en) | Block chain data storage method, system, equipment and readable storage medium | |
CN112463020A (en) | Data access method, device and equipment based on Flash | |
CN109558456A (en) | A kind of file migration method, apparatus, equipment and readable storage medium storing program for executing | |
CN110889062A (en) | Page loading method and device, terminal and computer readable storage medium | |
CN113568582A (en) | Data management method and device and storage equipment | |
CN108132759B (en) | Method and device for managing data in file system | |
CN107423425B (en) | Method for quickly storing and inquiring data in K/V format | |
WO2020192710A1 (en) | Method for processing garbage based on lsm database, solid state hard disk, and storage apparatus | |
CN117369731B (en) | Data reduction processing method, device, equipment and medium | |
CN106156038B (en) | Date storage method and device | |
CN117492661A (en) | Data writing method, medium, device and computing equipment | |
CN116340198B (en) | Data writing method and device of solid state disk and solid state disk |
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 |