File system space optimization method and device, equipment and readable storage medium

By freeing the file system space occupied by unallocated data clusters in the qcow2 image file, the file system space occupation problem caused by frequent writing and deletion is solved, and efficient file system space optimization is achieved.

CN119690333APending Publication Date: 2025-03-25WUHAN OPENKER COMPUTING
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411609409.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-12
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

When using the qcow2 image file format, frequent writing and deletion operations lead to a continuous increase in file size and occupying file system space. The existing optimization methods require generating new image files and deleting the original files, which is time-consuming and requires sufficient file system space.

Method used

By determining the unallocated data cluster in the image file, deleting its corresponding target file system cluster number, updating the cluster status and footprint size from the NTFS file system, directly releasing the file system space occupied by the unallocated data cluster.

Benefits of technology

No need to generate new image files, the file system space is directly optimized, which improves optimization efficiency and is not limited by the size of the available file system space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690333A_ABST
    Figure CN119690333A_ABST
Patent Text Reader

Abstract

The invention discloses a file system space optimization method and device, equipment and a readable storage medium. The method comprises the following steps: determining an unallocated data cluster in a qcow2 mirror image file; deleting a target file system cluster number corresponding to the unallocated data cluster from a file system cluster number set recorded in an operation list of the NTFS; modifying the state of a target file system cluster corresponding to the unallocated data cluster to be unoccupied; and subtracting the size of the file system space occupied by the unallocated data clusters from the size of the file system space occupied by the mirror image file recorded in the main file table of the NTFS. According to the method and the device, a new mirror image file does not need to be generated, and the file system space occupied by the unallocated data clusters is directly released, so that the optimization of the file system space is realized. Compared with the conventional technology, a large amount of data does not need to be read and written, so that the optimization efficiency is improved; and the space size of an available file system is not required, so that the method is more practical.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, equipment and computer-readable storage medium for optimizing file system space. Background Art

[0002] When using qcow2 as the image file format of VOI desktop, if users often do some operations such as writing and deleting data, the size of the qcow2 file may continue to increase. For example, if a user creates 1G of data on a partition of a hard disk, the size of the image file will increase by 1G, and deletes 1G of data on another partition, the qcow2 file will not decrease at this time. This is because there is a mapping relationship between the file start offset of the data stored in the qcow2 file and the sector offset of the corresponding virtual disk. Even if the data is deleted, the mapping relationship is still there. Unless the new data written by the user is written to the same disk sector position, the size of the image file will continue to increase.

[0003] As the size of the image file increases, the available file system space will become smaller and smaller. Currently, the way to optimize the file system space is to extract the valid data in the image file to generate a new image file, and then delete the original image file. However, this method has two disadvantages:

[0004] 1. Generating a new image file requires a lot of data reading and writing, which is time-consuming;

[0005] 2. Because the new image file needs to be stored in the file system space before deleting the original image file, if the available file system space is not enough to store the new image file, this method cannot be implemented. Summary of the invention

[0006] In order to solve the above technical problems, the present application provides a method, device, equipment and computer-readable storage medium for optimizing file system space.

[0007] In a first aspect, an embodiment of the present application provides a method for optimizing file system space, and the method for optimizing file system space includes:

[0008] Determine the unallocated data clusters in the image file, where the image file format is qcow2;

[0009] The target file system cluster number corresponding to the unallocated data cluster is deleted from the file system cluster number set recorded in the running list of the NTFS file system;

[0010] Modify the state of the target file system cluster corresponding to the unallocated data cluster to unoccupied, wherein in the NTFS file system, a bitmap is used to record whether each file system cluster in the data storage area of ​​the NTFS partition is occupied, and the value of each bit indicates the occupation state of a corresponding file system cluster;

[0011] The file system space size occupied by the mirror file recorded in the master file table of the NTFS file system is modified to c, where c is the difference between a and b, a is the original size of the file system space occupied by the mirror file, and b is the size of the file system space occupied by the unallocated data cluster.

[0012] In combination with the first aspect, in one implementation, before deleting the target file system cluster number corresponding to the unallocated data cluster from the set of file system cluster numbers recorded in the running list of the NTFS file system, the method further includes:

[0013] Determine the file cluster number of the unallocated data cluster in the image file according to the offset address of the unallocated data cluster in the image file;

[0014] The target file system cluster number corresponding to the file cluster number is determined according to the first mapping information, wherein the first mapping information includes a correspondence between the file cluster number and the file system cluster number.

[0015] In combination with the first aspect, in one implementation, determining the unallocated data clusters in the image file includes:

[0016] Obtain the corresponding image file path and the corresponding file handle based on the selected cloud desktop;

[0017] Based on the obtained file handle, the disk partition table is read, the partitions of the virtual disk are analyzed, and the file system of each partition is analyzed to obtain valid data and record the corresponding disk offset to the valid data information list in the form of blocks;

[0018] Based on the metadata of the image file, a set of all allocated data clusters is obtained, and disk offset position information in the virtual disk image mapped by each cluster in the set is stored in an allocated data cluster information list;

[0019] The allocated data cluster information list is traversed to determine that the allocated data cluster whose disk offset is not in the valid data information list is an unallocated data cluster.

[0020] In combination with the first aspect, in one implementation, obtaining the corresponding image file path and the corresponding file handle based on the selected cloud desktop includes:

[0021] Determining a selected cloud desktop based on a selection operation performed on the cloud desktop selection interface;

[0022] Get the corresponding qcow2 file path according to the selected cloud desktop;

[0023] Take the obtained qcow2 file path as a parameter and open the file interface by calling qcow2 to obtain the corresponding file handle.

[0024] In a second aspect, an embodiment of the present application provides a device for optimizing file system space, and the device for optimizing file system space includes:

[0025] A determination module, used for determining unallocated data clusters in an image file, wherein the image file is in a qcow2 format;

[0026] The first optimization module is used to delete the target file system cluster number corresponding to the unallocated data cluster from the file system cluster number set recorded in the running list of the NTFS file system;

[0027] A second optimization module is used to modify the state of the target file system cluster corresponding to the unallocated data cluster to unoccupied, wherein in the NTFS file system, a bitmap is used to record whether each file system cluster in the data storage area of ​​the NTFS partition is occupied, and the value of each bit indicates the occupation state of a corresponding file system cluster;

[0028] The third optimization module is used to modify the file system space size occupied by the mirror file recorded in the master file table of the NTFS file system to c, where c is the difference between a and b, a is the original size of the file system space occupied by the mirror file, and b is the size of the file system space occupied by unallocated data clusters.

[0029] In conjunction with the second aspect, in one implementation, the first optimization module is further configured to:

[0030] Determine the file cluster number of the unallocated data cluster in the image file according to the offset address of the unallocated data cluster in the image file;

[0031] The target file system cluster number corresponding to the file cluster number is determined according to the first mapping information, wherein the first mapping information includes a correspondence between the file cluster number and the file system cluster number.

[0032] In conjunction with the second aspect, in one implementation, the determining module is used to:

[0033] Obtain the corresponding image file path and the corresponding file handle based on the selected cloud desktop;

[0034] Based on the obtained file handle, the disk partition table is read, the partitions of the virtual disk are analyzed, and the file system of each partition is analyzed to obtain valid data and record the corresponding disk offset to the valid data information list in the form of blocks;

[0035] Based on the metadata of the image file, a set of all allocated data clusters is obtained, and disk offset position information in the virtual disk image mapped by each cluster in the set is stored in an allocated data cluster information list;

[0036] The allocated data cluster information list is traversed to determine that the allocated data cluster whose disk offset is not in the valid data information list is an unallocated data cluster.

[0037] In conjunction with the second aspect, in one implementation, the determining module is used to:

[0038] Determining a selected cloud desktop based on a selection operation performed on the cloud desktop selection interface;

[0039] Get the corresponding qcow2 file path according to the selected cloud desktop;

[0040] Take the obtained qcow2 file path as a parameter and open the file interface by calling qcow2 to obtain the corresponding file handle.

[0041] In a third aspect, an embodiment of the present application provides a file system space optimization device, wherein the file system space optimization device comprises a processor, a memory, and a file system space optimization program stored in the memory and executable by the processor, wherein when the file system space optimization program is executed by the processor, the steps of the file system space optimization method described in the first aspect are implemented.

[0042] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a file system space optimization program is stored. When the file system space optimization program is executed by a processor, the steps of the file system space optimization method described in the first aspect are implemented.

[0043] The beneficial effects brought by the technical solution provided in the embodiments of the present application include:

[0044] In the embodiment of the present application, the unallocated data clusters in the image file are determined, wherein the format of the image file is qcow2; the target file system cluster number corresponding to the unallocated data cluster is deleted from the set of file system cluster numbers recorded in the running list of the NTFS file system; the state of the target file system cluster corresponding to the unallocated data cluster is modified to unoccupied, wherein in the NTFS file system, a bitmap is used to record whether each file system cluster in the data storage area of ​​the NTFS partition is occupied, and the value of each bit indicates the occupation state of a corresponding file system cluster; the file system space size occupied by the image file recorded in the master file table of the NTFS file system is modified to c, wherein c is the difference between a and b, a is the original size of the file system space occupied by the image file, and b is the file system space size occupied by the unallocated data cluster. Through the embodiment of the present application, there is no need to generate a new image file, but directly release the file system space occupied by the unallocated data cluster, thereby realizing the optimization of the file system space. Compared with conventional technology, there is no need to read and write a large amount of data, thereby improving the optimization efficiency; and there is no requirement for the size of the available file system space, which is more practical. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 A flowchart of an embodiment of a method for optimizing file system space of the present application;

[0046] Figure 2 A schematic diagram of functional modules of an embodiment of a device for optimizing file system space of the present application;

[0047] Figure 3 This is a schematic diagram of the hardware structure of a file system space optimization device involved in the embodiment of the present application. DETAILED DESCRIPTION

[0048] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0049] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0050] In a first aspect, an embodiment of the present application provides a method for optimizing file system space.

[0051] In one embodiment, referring to Figure 1 , Figure 1This is a flow chart of an embodiment of a method for optimizing file system space of the present application. Figure 1 As shown in the figure, the optimization methods of file system space include:

[0052] Step S10, determining unallocated data clusters in the image file, wherein the image file is in a qcow2 format;

[0053] In this embodiment, the format of the image file may be qcow2 (QEMUCopy-On-Write 2), which is a virtual disk image format for virtualization platforms, such as QEMU or KVM. It supports features such as compression, snapshots, and incremental images. Qcow2 uses Copy-On-Write technology to copy disk sectors only when needed, thereby saving storage space and allowing snapshots to be created and efficient incremental backups to be performed.

[0054] During the use of the cloud desktop, if some operations such as writing and deleting data are often performed, the size of the qcow2 file corresponding to the cloud desktop may continue to increase, thereby occupying more file system space. At this time, it is necessary to optimize the file system space. For example, the execution subject of this embodiment determines the selected cloud desktop based on the user's selection operation, uses the qcow2 file corresponding to the selected cloud desktop as the mirror file referred to in step S10, and then determines the unused data clusters in the qcow2 file with a reference count of 0 as unallocated data clusters.

[0055] For cloud desktop usage scenarios, the solution used to determine the unallocated data clusters in the image file is as follows:

[0056] Determine the selected cloud desktop based on the selection operation performed on the cloud desktop selection interface; obtain the corresponding qcow2 file path according to the selected cloud desktop; use the obtained qcow2 file path as a parameter and obtain the corresponding file handle by calling qcow2 to open the file interface. Obtain the corresponding image file path and the corresponding file handle based on the selected cloud desktop; read the disk partition table based on the obtained file handle, analyze the partitions of the virtual disk, and analyze the file system of each partition to obtain valid data and record the corresponding disk offset in the form of blocks to the valid data information list; obtain the set of all allocated data clusters based on the metadata of the image file, and store the disk offset position information in the virtual disk image mapped by each cluster in the set in the allocated data cluster information list; traverse the allocated data cluster information list to determine that the allocated data cluster whose disk offset is not in the valid data information list is an unallocated data cluster.

[0057] The specific implementation of determining the unallocated data clusters in the image file can refer to the prior art, such as the invention patent application with application number 202211167293.3, which will not be described in detail here.

[0058] Step S20, deleting the target file system cluster number corresponding to the unallocated data cluster from the set of file system cluster numbers recorded in the running list of the NTFS file system;

[0059] In this embodiment, the file system takes NTFS (New Technologies File System) as an example. NTFS is the file system of Windows NT operating environment and Windows NT Advanced Server Network Operating System environment.

[0060] In the NTFS partition (i.e., the file system space), there are area 1 for storing metadata and area 2 for storing data, where area 2 is divided into file system clusters, and the file system cluster numbers (i.e., the file system cluster number set) of all the file system clusters storing data are recorded in the running list. In order to release the file system space occupied by the unallocated data cluster, it is necessary to delete the target file system cluster number corresponding to the unallocated data cluster from the file system cluster number set recorded in the running list of the NTFS file system.

[0061] Step S30, modifying the state of the target file system cluster corresponding to the unallocated data cluster to unoccupied, wherein in the NTFS file system, a bitmap is used to record whether each file system cluster in the data storage area of ​​the NTFS partition is occupied, and the value of each bit indicates the occupation state of a corresponding file system cluster;

[0062] In this embodiment, the state of the target file system cluster corresponding to the unallocated data cluster is modified to unoccupied. In the NTFS file system, whether each file system cluster in area 2 of the NTFS partition is occupied is recorded by a bitmap, that is, the value of each bit indicates the occupation state of a corresponding file system cluster, for example, a bit value of 0 indicates unoccupied, and a bit value of 1 indicates occupied. For example, the value of the bit corresponding to the target file system cluster corresponding to the unallocated data cluster is modified to 0.

[0063] Step S40, modify the file system space size occupied by the mirror file recorded in the master file table of the NTFS file system to c, where c is the difference between a and b, a is the original size of the file system space occupied by the mirror file, and b is the file system space size occupied by unallocated data clusters.

[0064] In this embodiment, the metadata information (such as file name, file size, etc.) of all files and directories in the NTFS partition (i.e., file system space) is recorded in the master file table in the NTFS file system. The file system space size occupied by the mirror file in the master file table can be modified to c, thereby updating the file system space size occupied by the mirror file. Among them, the value of b can be determined based on the file system space size occupied by the target file system cluster corresponding to the unallocated data cluster.

[0065] It should be noted that the execution order of step S20, step S30 and step S40 is not limited here, and the three steps can be performed in any order and can also be performed in parallel.

[0066] In this embodiment, the file system space occupied by the unallocated data clusters is released by processing the relevant data corresponding to the unallocated data clusters in the file allocation table of the file system.

[0067] In the embodiment of the present application, the unallocated data clusters in the image file are determined, wherein the format of the image file is qcow2; the target file system cluster number corresponding to the unallocated data cluster is deleted from the set of file system cluster numbers recorded in the running list of the NTFS file system; the state of the target file system cluster corresponding to the unallocated data cluster is modified to unoccupied, wherein in the NTFS file system, a bitmap is used to record whether each file system cluster in the data storage area of ​​the NTFS partition is occupied, and the value of each bit indicates the occupation state of a corresponding file system cluster; the file system space size occupied by the image file recorded in the master file table of the NTFS file system is modified to c, wherein c is the difference between a and b, a is the original size of the file system space occupied by the image file, and b is the file system space size occupied by the unallocated data cluster. Through the embodiment of the present application, there is no need to generate a new image file, but directly release the file system space occupied by the unallocated data cluster, thereby realizing the optimization of the file system space. Compared with conventional technology, there is no need to read and write a large amount of data, thereby improving the optimization efficiency; and there is no requirement for the size of the available file system space, which is more practical.

[0068] Furthermore, in one embodiment, before step S20, the method further includes:

[0069] Determine the file cluster number of the unallocated data cluster in the mirror file according to the offset address of the unallocated data cluster in the mirror file; determine the target file system cluster number corresponding to the file cluster number according to the first mapping information, wherein the first mapping information includes the correspondence between the file cluster number and the file system cluster number.

[0070] In this embodiment, firstly, the file cluster number of the unallocated data cluster in the mirror file is determined according to the offset address of the unallocated data cluster in the mirror file. Since there is a corresponding relationship between the cluster number of the mirror file cluster and the cluster number of the file system cluster, the target file system cluster number corresponding to the file cluster number can be determined based on this, wherein the target file system cluster number is the cluster number of the target file system cluster.

[0071] What needs to be explained is:

[0072] The cluster of the file system and the cluster of the qcow2 image file are not the same concept. The cluster of the file system is a unit of file system management and organization of storage space. The cluster of the file system is composed of a group of continuous sectors, each sector usually contains 512 bytes. The cluster size of a file system may be 4k. The actual size of a file is 2k, but it occupies 4k in the file system. The qcow2 image file is also based on clusters, and the size may be 64k. If 1k of data is added to the qcow2 image file, the actual size of the qcow2 image file will be expanded by 64k.

[0073] Based on the above description, the following examples are given:

[0074] If the size of a qcow2 image file is 1024k and the size of a qcow2 cluster is 64k, it can be divided into 16 image file clusters, and the cluster numbers of the 16 image file clusters are A0 to A15 respectively; if the size of a file system cluster is 4k, the qcow2 file can be divided into 256 file system clusters, and the cluster numbers of the 256 file system clusters are B0 to B255 respectively.

[0075] At this time, cluster number A0 of mirror file cluster 0 corresponds to cluster numbers B0~B15 of file system clusters 0~15, cluster number A1 of mirror file cluster 1 corresponds to cluster numbers B16~B31 of file system clusters 16~31, cluster number A2 of mirror file cluster 2 corresponds to cluster numbers B32~B47 of file system clusters 32~47, and so on, forming a correspondence between file cluster numbers and file system cluster numbers.

[0076] Assuming that the file cluster number of the unallocated data cluster in the image file is A2, the target file system cluster number is determined to be B32~B47 according to the above correspondence, that is, the target file system cluster corresponding to the unallocated data cluster is determined to be file system clusters 32~47, which means that file system clusters 32~47 are actually invalid now, and thus they are released.

[0077] In a second aspect, an embodiment of the present application also provides a device for optimizing file system space.

[0078] In one embodiment, referring to Figure 2 , Figure 2This is a functional module diagram of an embodiment of the device for optimizing file system space of the present application. Figure 2 As shown, the file system space optimization device includes:

[0079] A determination module 10 is used to determine an unallocated data cluster in an image file, wherein the image file is in a qcow2 format;

[0080] The first optimization module 20 is used to delete the target file system cluster number corresponding to the unallocated data cluster from the file system cluster number set recorded in the running list of the NTFS file system;

[0081] The second optimization module 30 is used to modify the state of the target file system cluster corresponding to the unallocated data cluster to unoccupied, wherein in the NTFS file system, a bitmap is used to record whether each file system cluster in the data storage area of ​​the NTFS partition is occupied, and the value of each bit indicates the occupation state of a corresponding file system cluster;

[0082] The third optimization module 40 is used to modify the file system space size occupied by the mirror file recorded in the master file table of the NTFS file system to c, where c is the difference between a and b, a is the original size of the file system space occupied by the mirror file, and b is the size of the file system space occupied by unallocated data clusters.

[0083] Furthermore, in one embodiment, the first optimization module 20 is further configured to:

[0084] Determine the file cluster number of the unallocated data cluster in the image file according to the offset address of the unallocated data cluster in the image file;

[0085] The target file system cluster number corresponding to the file cluster number is determined according to the first mapping information, wherein the first mapping information includes a correspondence between the file cluster number and the file system cluster number.

[0086] Furthermore, in one embodiment, the determination module 10 is used to:

[0087] Obtain the corresponding image file path and the corresponding file handle based on the selected cloud desktop;

[0088] Based on the obtained file handle, the disk partition table is read, the partitions of the virtual disk are analyzed, and the file system of each partition is analyzed to obtain valid data and record the corresponding disk offset to the valid data information list in the form of blocks;

[0089] Based on the metadata of the image file, a set of all allocated data clusters is obtained, and disk offset position information in the virtual disk image mapped by each cluster in the set is stored in an allocated data cluster information list;

[0090] The allocated data cluster information list is traversed to determine that the allocated data cluster whose disk offset is not in the valid data information list is an unallocated data cluster.

[0091] Furthermore, in one embodiment, the determination module 10 is used to:

[0092] Determining a selected cloud desktop based on a selection operation performed on the cloud desktop selection interface;

[0093] Get the corresponding qcow2 file path according to the selected cloud desktop;

[0094] Take the obtained qcow2 file path as a parameter and open the file interface by calling qcow2 to obtain the corresponding file handle.

[0095] Among them, the functional implementation of each module in the above-mentioned file system space optimization device corresponds to the various steps in the above-mentioned file system space optimization method embodiment, and its functions and implementation processes will not be repeated here one by one.

[0096] In a third aspect, an embodiment of the present application provides a device for optimizing file system space. The device for optimizing file system space may be a personal computer (PC), a laptop computer, a server, or other device having data processing capabilities.

[0097] Reference Figure 3 , Figure 3 The hardware structure diagram of the file system space optimization device involved in the embodiment of the present application is shown in FIG. In the embodiment of the present application, the file system space optimization device may include a processor, a memory, a communication interface, and a communication bus.

[0098] The communication bus may be of any type and is used to interconnect the processor, the memory, and the communication interface.

[0099] The communication interface includes input / output (I / O) interfaces, physical interfaces, and logical interfaces, which are used to interconnect the internal devices of the file system space optimization device, and interfaces used to interconnect the file system space optimization device with other devices (such as other computing devices or user devices). The physical interface can be an Ethernet interface, a fiber optic interface, an ATM interface, etc.; the user device can be a display, a keyboard, etc.

[0100] The memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.

[0101] The processor may be a general-purpose processor, and the general-purpose processor may call the optimization program of the file system space stored in the memory, and execute the optimization method of the file system space provided in the embodiment of the present application. For example, the general-purpose processor may be a central processing unit (CPU). The method executed when the optimization program of the file system space is called may refer to the various embodiments of the optimization method of the file system space of the present application, and will not be repeated here.

[0102] Those skilled in the art will understand that Figure 3 The hardware structure shown in the figure does not constitute a limitation on the present application, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0103] In a fourth aspect, an embodiment of the present application also provides a computer-readable storage medium.

[0104] The computer-readable storage medium of the present application stores a file system space optimization program, wherein when the file system space optimization program is executed by a processor, the steps of the file system space optimization method as described above are implemented.

[0105] Among them, the method implemented when the file system space optimization program is executed can refer to the various embodiments of the file system space optimization method of the present application, and will not be repeated here.

[0106] It should be noted that the serial numbers of the above-mentioned embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.

[0107] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. The terms "first", "second" and "third" are used to distinguish different objects, etc., and do not represent a sequence, nor do they limit "first", "second" and "third" to different types.

[0108] In the description of the embodiments of the present application, "exemplary", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a specific way.

[0109] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; the “and / or” in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, “multiple” refers to two or more than two.

[0110] In some processes described in the embodiments of the present application, multiple operations or steps that appear in a specific order are included, but it should be understood that these operations or steps may not be executed in the order in which they appear in the embodiments of the present application or in parallel, and the sequence number of the operation is only used to distinguish the different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed in sequence or in parallel, and these operations or steps may be combined.

[0111] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.

[0112] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method for optimizing file system space, characterized in that: The method for optimizing the file system space includes: Determine the unallocated data clusters in the image file, where the image file format is qcow2; The target file system cluster number corresponding to the unallocated data cluster is deleted from the file system cluster number set recorded in the running list of the NTFS file system; Modify the state of the target file system cluster corresponding to the unallocated data cluster to unoccupied, wherein in the NTFS file system, a bitmap is used to record whether each file system cluster in the data storage area of ​​the NTFS partition is occupied, and the value of each bit indicates the occupation state of a corresponding file system cluster; The file system space size occupied by the mirror file recorded in the master file table of the NTFS file system is modified to c, where c is the difference between a and b, a is the original size of the file system space occupied by the mirror file, and b is the size of the file system space occupied by the unallocated data cluster.

2. The method for optimizing file system space according to claim 1, characterized in that: Before deleting the target file system cluster number corresponding to the unallocated data cluster from the set of file system cluster numbers recorded in the running list of the NTFS file system, the method further includes: Determine the file cluster number of the unallocated data cluster in the image file according to the offset address of the unallocated data cluster in the image file; The target file system cluster number corresponding to the file cluster number is determined according to the first mapping information, wherein the first mapping information includes a correspondence between the file cluster number and the file system cluster number.

3. The method for optimizing file system space according to claim 1, characterized in that: Determining the unallocated data clusters in the image file includes: Obtain the corresponding image file path and the corresponding file handle based on the selected cloud desktop; Based on the obtained file handle, the disk partition table is read, the partitions of the virtual disk are analyzed, and the file system of each partition is analyzed to obtain valid data and record the corresponding disk offset to the valid data information list in the form of blocks; Based on the metadata of the image file, a set of all allocated data clusters is obtained, and disk offset position information in the virtual disk image mapped by each cluster in the set is stored in an allocated data cluster information list; The allocated data cluster information list is traversed to determine that the allocated data cluster whose disk offset is not in the valid data information list is an unallocated data cluster.

4. The method for optimizing file system space as claimed in claim 3, characterized in that: The obtaining of the corresponding image file path and the corresponding file handle based on the selected cloud desktop includes: Determining a selected cloud desktop based on a selection operation performed on the cloud desktop selection interface; Get the corresponding qcow2 file path according to the selected cloud desktop; Take the obtained qcow2 file path as a parameter and open the file interface by calling qcow2 to obtain the corresponding file handle.

5. A device for optimizing file system space, characterized in that: The file system space optimization device comprises: A determination module, used for determining unallocated data clusters in an image file, wherein the image file is in a qcow2 format; The first optimization module is used to delete the target file system cluster number corresponding to the unallocated data cluster from the file system cluster number set recorded in the running list of the NTFS file system; A second optimization module is used to modify the state of the target file system cluster corresponding to the unallocated data cluster to unoccupied, wherein in the NTFS file system, a bitmap is used to record whether each file system cluster in the data storage area of ​​the NTFS partition is occupied, and the value of each bit indicates the occupation state of a corresponding file system cluster; The third optimization module is used to modify the file system space size occupied by the mirror file recorded in the master file table of the NTFS file system to c, where c is the difference between a and b, a is the original size of the file system space occupied by the mirror file, and b is the size of the file system space occupied by unallocated data clusters.

6. The device for optimizing file system space as claimed in claim 5, characterized in that: The first optimization module is further used for: Determine the file cluster number of the unallocated data cluster in the image file according to the offset address of the unallocated data cluster in the image file; The target file system cluster number corresponding to the file cluster number is determined according to the first mapping information, wherein the first mapping information includes a correspondence between the file cluster number and the file system cluster number.

7. The device for optimizing file system space as claimed in claim 5, characterized in that: The determining module is used to: Obtain the corresponding image file path and the corresponding file handle based on the selected cloud desktop; Based on the obtained file handle, the disk partition table is read, the partitions of the virtual disk are analyzed, and the file system of each partition is analyzed to obtain valid data and record the corresponding disk offset to the valid data information list in the form of blocks; Based on the metadata of the image file, a set of all allocated data clusters is obtained, and disk offset position information in the virtual disk image mapped by each cluster in the set is stored in an allocated data cluster information list; The allocated data cluster information list is traversed to determine that the allocated data cluster whose disk offset is not in the valid data information list is an unallocated data cluster.

8. The device for optimizing file system space as claimed in claim 7, characterized in that: The determining module is used to: Determining a selected cloud desktop based on a selection operation performed on the cloud desktop selection interface; Get the corresponding qcow2 file path according to the selected cloud desktop; Take the obtained qcow2 file path as a parameter and open the file interface by calling qcow2 to obtain the corresponding file handle.

9. A device for optimizing file system space, characterized in that: The file system space optimization device includes a processor, a memory, and a file system space optimization program stored in the memory and executable by the processor, wherein when the file system space optimization program is executed by the processor, the steps of the file system space optimization method as described in any one of claims 1 to 4 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a file system space optimization program, wherein when the file system space optimization program is executed by a processor, the steps of the file system space optimization method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Method and system for arranging virtual disk in qcow2 format

    CN115509449A