Linux-based file processing method and device, computer equipment, readable storage medium and program product
By introducing a recycling bin mechanism in the Linux operating system, the problem of unrecoverable files after the rm command is deleted is solved, the temporary storage and recovery functions of files are realized, and the security and convenience of user operations are improved.
Patent Information
- Application Number
- CN202411702560.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-03-07
- Estimated Expiration
- 2044-11-26
AI Technical Summary
In Linux operating system, when using the rm command to delete files, there is a lack of a recycling bin mechanism, which makes it impossible for the file to be temporarily stored and it is difficult for users to recover accidentally deleted files.
A Linux-based file processing method is provided, by adding the inode node of the file to be deleted to the data structure of the recycling bin directory when receiving the deletion instruction, and creating a pending file associated with the file to be deleted, recording its storage partition information and path information. The user can completely delete the file through the second deletion command, or recover the file through the mobile command.
The recycling bin mechanism for deleting Linux files is implemented, allowing users to temporarily store files to be deleted, avoiding mistaken deletion, and improving the convenience of file recovery.
Smart Images

Figure CN119576871A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a file processing method, device, computer equipment, computer-readable storage medium and computer program product based on Linux. Background Art
[0002] Currently, in Linux operating systems, when users want to delete a file, they often use the rm command (delete command). Using the rm command to delete a file means that the file is directly removed without a mechanism such as a recycle bin as an intermediate layer.
[0003] For users, they may not want the files to disappear after triggering the rm command, but just want to temporarily move the files to a certain place until there is not enough space or they are confirmed not to be needed, and then clean up the files all at once. Summary of the invention
[0004] Based on this, it is necessary to provide a Linux-based file processing method, device, computer equipment, computer-readable storage medium and computer program product that can temporarily store and perform other processing on the files pointed to by the rm command in order to solve the above technical problems.
[0005] In a first aspect, the present application provides a file processing method based on Linux, the method comprising:
[0006] When receiving a first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, adding an index node corresponding to the file to be deleted to a data structure of the recycle bin directory, and setting the file to be deleted to a deleting state;
[0007] Creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file;
[0008] When a second deletion instruction for the to-be-processed file is received, the to-be-processed file is deleted from the storage partition of the to-be-deleted file corresponding to the to-be-processed file, and the to-be-processed file in the recycle bin directory is removed.
[0009] In one embodiment, the method further comprises:
[0010] When a move instruction for the file to be processed is received, the storage partition of the file to be deleted corresponding to the file to be processed and the deleting state of the file to be deleted are removed, the file to be processed in the recycle bin directory is removed, and the file to be deleted is moved to the target location pointed to by the move instruction.
[0011] In one of the embodiments, when the to-be-deleted file removes the deleting state, the method further includes:
[0012] The index node of the to-be-deleted file is removed from the data structure of the recycle bin directory.
[0013] In one embodiment, before receiving the first deletion instruction, the method further includes:
[0014] When the Linux system root directory is mounted for the first time, a recovery structure is defined under the virtual file system, and a data structure for storing and indexing files to be deleted is created;
[0015] A recycle bin directory is created under the system root directory; the recycle bin directory is used to display the to-be-processed files corresponding to the to-be-deleted files.
[0016] In one of the embodiments, after creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory, the method further includes:
[0017] The to-be-processed file is written into the memory of the Linux, and the to-be-processed file is displayed in the recycle bin directory when the Linux is started.
[0018] In one of the embodiments, after creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory, the method further includes:
[0019] Start a timer for the file to be deleted and the corresponding file to be processed. When the timer reaches the timing time and no second deletion instruction for the file to be processed is received, delete the file to be deleted from the storage partition of the file to be deleted corresponding to the file to be processed, and remove the file to be processed in the recycle bin directory.
[0020] In a second aspect, the present application further provides a file processing device based on Linux, the device comprising:
[0021] a state adjustment module, configured to, upon receiving a first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, add an index node corresponding to the file to be deleted to a data structure of the recycle bin directory, and set the file to be deleted to a deleting state;
[0022] A file creation module, used to create a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file;
[0023] The file deletion module is used to delete the to-be-processed file from the storage partition of the to-be-processed file corresponding to the to-be-processed file and remove the to-be-processed file in the recycle bin directory when receiving a second deletion instruction for the to-be-processed file.
[0024] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0025] When receiving a first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, adding an index node corresponding to the file to be deleted to a data structure of the recycle bin directory, and setting the file to be deleted to a deleting state;
[0026] Creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file;
[0027] When a second deletion instruction for the to-be-processed file is received, the to-be-processed file is deleted from the storage partition of the to-be-deleted file corresponding to the to-be-processed file, and the to-be-processed file in the recycle bin directory is removed.
[0028] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0029] When receiving a first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, adding an index node corresponding to the file to be deleted to a data structure of the recycle bin directory, and setting the file to be deleted to a deleting state;
[0030] Creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file;
[0031] When a second deletion instruction for the to-be-processed file is received, the to-be-processed file is deleted from the storage partition of the to-be-deleted file corresponding to the to-be-processed file, and the to-be-processed file in the recycle bin directory is removed.
[0032] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0033] When receiving a first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, adding an index node corresponding to the file to be deleted to a data structure of the recycle bin directory, and setting the file to be deleted to a deleting state;
[0034] Creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file;
[0035] When a second deletion instruction for the to-be-processed file is received, the to-be-processed file is deleted from the storage partition of the to-be-deleted file corresponding to the to-be-processed file, and the to-be-processed file in the recycle bin directory is removed.
[0036] In the Linux-based file processing method, device, computer equipment, computer-readable storage medium and computer program product provided by the present application, the Linux-based file processing method adds the index node corresponding to the to-be-deleted file to the data structure of the recycle bin directory and sets the to-be-deleted file to the deleting state when receiving a first deletion instruction and determining that the to-be-deleted file pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory; creates a to-be-deleted file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-deleted file is used to record the storage partition information and path information of the corresponding to-be-deleted file; when receiving a second deletion instruction for the to-be-deleted file, deletes the to-be-deleted file from the storage partition of the to-be-deleted file corresponding to the to-be-deleted file, and removes the to-be-deleted file in the recycle bin directory; it can be seen that the present application sets a recycle bin mechanism (recycle bin directory) for Linux file deletion, so that any file in Linux can be moved to the recycle bin directory for temporary storage after receiving the first deletion instruction, and then the user can choose to completely delete the file at any time according to needs to prevent the situation where the file cannot be restored due to accidental deletion of the file. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0038] Figure 1 A schematic diagram of a flow chart of a file processing method based on Linux in one embodiment;
[0039] Figure 2 A schematic diagram of a process for creating a recycle bin directory in one embodiment;
[0040] Figure 3 A schematic diagram of a process of deleting a file in one embodiment;
[0041] Figure 4 A schematic diagram of a process of restoring files in one embodiment;
[0042] Figure 5 is a structural block diagram of a Linux-based file processing device in an embodiment;
[0043] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0045] In the related art, in the Linux operating system, when a user wants to delete a file, the rm command (delete command) is often used. The operation of deleting a file using the rm command means that the file is directly removed without a mechanism such as a recycle bin as an intermediate layer.
[0046] For users, they may not want the files to disappear after rm, but they may want to move the files temporarily to a certain place, similar to the Recycle Bin mode under Windows (operating system), until there is not enough space or it is confirmed that they are not needed, and then clean up the files all at once.
[0047] Providing a recycle bin mechanism for deleted files can effectively serve as a buffer for deletion operations and also provide a more convenient way to retrieve files.
[0048] In the related technology, similar to the recycle bin under the Linux system, the technologies for temporarily storing or retrieving files after deletion are mainly as follows:
[0049] First, some operating systems that provide graphical interfaces (such as Ubuntu) provide a recycle bin function. However, there are some defects. Specifically, the graphical interface requires mouse operation, and if the rm command is used, the file is still deleted directly. In addition, the recycle bin design of Ubuntu actually moves the deleted files to the trash directory under the user directory, which is not applicable to files in non-user directories, and has great limitations.
[0050] Secondly, the backup function can restore files to a certain point in time. However, there are some defects. Specifically, although the backup method ensures the reliability of storage, it often requires additional configuration, the process is cumbersome and heavy, and requires additional storage space for support. At the same time, file backup can only restore files at a specific point in time, which cannot achieve the expected effect of the recycle bin function.
[0051] Third, some tools provide similar means to the recycle bin (such as trash-cli, a command-line recycle bin tool). However, there are some defects. Specifically, tools like trash-cli need to be installed separately, which may have compatibility issues with the system; and the tool only provides new commands and cannot overwrite the original rm command, which is not in line with the habits of Linux users, and the way to view deleted files is not intuitive enough.
[0052] Fourth, some manufacturers provide a recycle bin function for specific file systems (such as ocfs2 or ext4). However, there are some defects. Specifically, the recycle bin system developed for a specific file system requires the partition to be formatted as a specific file system and data migration must be done first, which is very restrictive. In addition, when there are many partitions, each partition will have a recycle bin directory. It is very inconvenient to use. Among them, ocfs2 is the abbreviation of Oracle Cluster File System Version 2, which is a shared disk file system; ext4 is the abbreviation of Fourth Extended Filesystem, which is an extended file system.
[0053] Based on the above problems in related technologies, this application proposes a method for modifying the kernel's VFS, specifically, modifying the VFS layer common to the file system, and providing a recycle bin mechanism for the rm command, so that no matter what type of file system is mounted, the rm command can be used to move deleted files to the recycle bin, and the recycled files are concentrated in the same directory. The recycle bin designed in this way is more unified, intuitive, and convenient.
[0054] Among them, VFS (Virtual Filesystem) is a virtual file system. The encapsulation layer of the file system of the Linux kernel shields various types of file systems to provide a unified operation entry for the operating system.
[0055] Specifically, the Linux-based file processing method provided in the embodiment of the present application can be applied to a terminal, which can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The Linux-based file processing method applied to the terminal provided in the present application needs to be a Linux operating system for the terminal to which it is adapted.
[0056] In an exemplary embodiment, Figure 1 As shown, a file processing method based on Linux is provided, and the method is applied to a terminal with a Linux operating system as an example for description, including the following steps 202 to 206. Among them:
[0057] Step 202, when the first deletion instruction is received and it is determined that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, the index node corresponding to the file to be deleted is added to the data structure of the recycle bin directory, and the file to be deleted is set to the deleting state.
[0058] The first deletion instruction is the first rm command applied by the user to the file to be deleted; in the present application, it is a command for moving at least part of the relevant information of the file to be deleted to the recycle bin directory.
[0059] The Recycle Bin directory is used to store all files in the terminal that have been removed by the rm command but have not been completely deleted.
[0060] For example, when receiving the first delete command applied by the user to a certain file in the Linux operating system, it is further determined whether the file exists in the recycle bin directory of the Linux operating system. When it is determined that the file is not in the recycle bin directory under the system root directory, it means that the file has received the rm command for the first time, that is, the user wants to move the file to the recycle bin directory instead of completely deleting the file from the terminal. Then the terminal will add the index node (inode) corresponding to the file to be deleted to the data structure (rb+tree global variable) of the recycle bin directory, and set the file to be deleted to the deleting state (recycling).
[0061] Among them, files in the deletion state cannot be viewed or accessed temporarily.
[0062] The data structure (rb+ tree global variable) is used to store and index all files moved to the recycle bin directory. "rb+ tree" is a tree data structure that efficiently stores and searches for target objects. This structure is often used in file systems to store file nodes or data blocks.
[0063] Among them, inode is a structure stored in a persistent storage device to describe a file object. The structure contains some basic information about the file. In the file system, a file object is queried or managed through inode.
[0064] Step 204: Create a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file.
[0065] The pending files are used to describe the information of the files to be deleted that are moved to the recycle bin directory. The pending files can receive rm commands and mv commands (move commands), but cannot be modified or viewed.
[0066] Exemplarily, when a first deletion instruction is received and it is determined that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, a pending file associated with the file to be deleted will be created in the recycle bin directory to record information about the file to be deleted that is moved to the recycle bin in the recycle bin directory, such as at least the storage partition information and path information of the file to be deleted.
[0067] Furthermore, after a user deletes a file based on the rm command, the user can no longer view or access the file from the original directory of the to-be-deleted file, but can find the file (the file to be processed) in the recycle bin directory under the root directory.
[0068] Step 206: When receiving the second deletion instruction for the file to be processed, the file to be deleted is deleted from the storage partition of the file to be deleted corresponding to the file to be processed, and the file to be processed in the recycle bin directory is removed.
[0069] The second deletion instruction is the second rm command applied by the user to the file to be deleted; the application object of the second deletion instruction is the to-be-processed file corresponding to the file to be deleted in the recycle bin directory.
[0070] Exemplarily, after the file to be deleted receives the first deletion instruction applied by the user, the file to be deleted is not completely deleted from the terminal, but is in a deleting state, and cannot be viewed or accessed in the original directory of the file to be deleted; at the same time, a to-be-processed file associated with the file to be deleted is created in the recycle bin directory, so that when the user has a need to completely delete the file, a second deletion instruction is applied to the to-be-processed file corresponding to the file to be deleted in the recycle bin directory; and based on the second deletion instruction, the file to be deleted is deleted from the storage partition originally corresponding to the file to be deleted, and the related to-be-processed files in the recycle bin directory are removed, so that the file is completely deleted from the terminal.
[0071] It should be added that, after the file to be deleted receives the first deletion instruction, although it cannot be viewed or accessed in the original directory of the file to be deleted, the storage location of the file to be deleted does not change, that is, even if a pending file corresponding to the file to be deleted is created in the recycle bin directory, the storage location of the file to be deleted in the terminal does not change, which means that the deleted file will not occupy additional space in the partition of the root directory, but will still occupy the space of the original partition.
[0072] In the above-mentioned file processing method based on Linux, when a first deletion instruction is received and it is determined that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, the index node corresponding to the file to be deleted is added to the data structure of the recycle bin directory, and the file to be deleted is set to a deleting state; a to-be-processed file associated with the file to be deleted is created in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding file to be deleted; when a second deletion instruction is received for the file to be processed, the file to be deleted is deleted from the storage partition of the file to be deleted corresponding to the file to be processed, and the to-be-processed file in the recycle bin directory is removed; it can be seen that the present application sets up a recycle bin mechanism (recycle bin directory) for Linux file deletion, so that any file in Linux can be moved to the recycle bin directory for temporary storage after receiving the first deletion instruction, and then the user can choose to completely delete the file at any time according to needs to prevent the situation where the file cannot be recovered due to accidental deletion of the file.
[0073] In an exemplary embodiment, the Linux-based file processing method provided by the present application further includes:
[0074] When a move instruction for a file to be processed is received, the storage partition of the file to be deleted corresponding to the file to be processed and the deleting state of the file to be deleted are removed, and the file to be processed in the recycle bin directory is removed, and the file to be deleted is moved to the target location pointed to by the move instruction.
[0075] The move instruction is also the mv command related to the Linux operating system, which is used to move the location of the file targeted by the mv command, at least to the display location.
[0076] The target location is the location where the file pointed to by the move instruction needs to be updated and displayed.
[0077] Exemplarily, after a user applies the rm command to a certain file for the first time, if the user regrets deleting the file, the file can be restored from the recycle bin directory. That is, a recovery instruction is applied to the pending files in the recycle bin directory, specifically, a move instruction is applied to the pending files in the recycle bin directory. When the pending files receive the move instruction applied to them, the file status of the pending files corresponding to the pending files is first changed, that is, the deleting status (recycling) of the pending files in the storage partition of the pending files corresponding to the pending files is removed, so that the relevant pending files can be restored to the status before receiving the first rm command, that is, the status that allows the user to view or access. Then, the relevant pending files in the recycle bin directory will be removed synchronously, and the relevant pending files will be moved to the target location pointed to by the move instruction, so that the relevant files can be displayed at the target location, and the user is allowed to view or access the files at the target location.
[0078] It can be seen that the present application provides a method for allowing recovery after deletion for files under the Linux operating system, so that when a user uses the rm command to delete a file, it will not be removed directly, but will be moved to the Recycle Bin directory first. The user can then continue to restore the deleted file as needed, which is helpful to avoid complete deletion of files due to accidental operation.
[0079] In an exemplary embodiment, when the file to be deleted is removed from the deleting state, the method further includes: removing the index node of the file to be deleted from the data structure of the recycle bin directory.
[0080] Exemplarily, when the file to be deleted is removed from the deleting state, the index node of the file to be deleted will be further removed from the data structure of the recycle bin directory to ensure that no information of the file to be deleted is associated with the recycle bin directory, thereby avoiding viewing or access obstacles to the restored file.
[0081] In an exemplary embodiment, before receiving the first deletion instruction, the method further includes:
[0082] When the Linux system root directory is mounted for the first time, a recovery structure is defined under the virtual file system, and a data structure for storing and indexing files to be deleted is created;
[0083] Create a recycle bin directory under the system root directory; the recycle bin directory is used to display the pending files corresponding to the files to be deleted.
[0084] Among them, the full English name of the virtual file system is Virtual Filesystem (VFS), which is the encapsulation layer of the file system of the Linux kernel, shielding various types of file systems to provide a unified operation entry for the operating system.
[0085] For example, when the Linux system root directory of the terminal is mounted for the first time, a recycling structure is defined under VFS. The structure describes the object in the recycle bin and needs to point to the inode corresponding to the file, the partition to which the file belongs, and the corresponding original path. A new data structure (rb+ tree global variable) is created under VFS to store and index all files moved to the recycle bin. Then, a recycle bin directory is created under the Linux system root directory. This directory is used as a recycle bin. All files that have been removed by the rm command but have not been completely deleted can be seen in this directory. The files to be deleted displayed in the recycle bin directory are related files to be processed generated after receiving the rm command.
[0086] In an exemplary embodiment, after creating a to-be-processed file associated with a to-be-deleted file in a recycle bin directory, the process further includes: writing the to-be-processed file into a memory of Linux, and displaying the to-be-processed file in the recycle bin directory when Linux is started.
[0087] Among them, the Linux memory is used to store some file data information in the relevant terminal.
[0088] Exemplarily, after creating a to-be-processed file associated with a to-be-deleted file in the recycle bin directory, the to-be-processed file can be simultaneously written into the Linux memory for storage, so that the relevant to-be-processed file can be viewed in the recycle bin directory each time Linux is in the startup state, so that the file that has not been completely deleted can be viewed in the recycle bin directory each time the terminal or Linux is restarted.
[0089] In an exemplary embodiment, after creating a to-be-processed file associated with a to-be-deleted file in a recycle bin directory, it also includes: starting a timer for the to-be-deleted file and the corresponding to-be-processed file, and when the timer reaches the timing time and no second deletion instruction for the to-be-processed file is received, deleting the to-be-deleted file from the storage partition of the to-be-deleted file corresponding to the to-be-processed file, and removing the to-be-processed file in the recycle bin directory.
[0090] Exemplarily, in order to avoid excessive file information in the Recycle Bin directory and to avoid users forgetting to completely delete related files in the Recycle Bin directory, the present application also provides an optional implementation method, which is, after creating a pending file associated with the file to be deleted in the Recycle Bin directory, immediately start a timer for the file to be deleted and the corresponding pending file. If the timer has not reached the timing time, the user can completely delete or restore the file in the Recycle Bin directory based on demand. If the timer reaches the timing time and no second deletion instruction is received for the file to be processed, it means that the user has forgotten to completely delete the file in the Recycle Bin directory and no longer needs the related files. At this time, the file to be deleted can be directly and automatically deleted from the storage partition originally corresponding to the file to be deleted, and the related pending files in the Recycle Bin directory can be removed to achieve complete deletion of the file from the terminal.
[0091] In summary, it can be seen that this application proposes a method for modifying the kernel's VFS and some system calls, which can provide buffering and quick recovery operations for users' file deletion operations. This application designs a recycle bin system (recycle bin directory) that is specifically used to process deleted files. When a user uses the rm command (the first delete instruction) to delete a file, it will not be removed directly, but will be moved to the recycle bin directory first. Users can choose to completely delete or restore files at any time to prevent accidental deletion of files.
[0092] The Linux-based file processing method provided in the present application specifically includes: designing a new file type: recycled. This type of file is specifically used to record the information of files moved to the recycle bin. This type of file can be rm or mv, but cannot be modified or viewed. When the user enters the rm command to delete a file, the user can no longer view or access the file from the original directory, but can find the file in the ".recycle" directory (recycle bin directory) under the root directory. Deleted files will not occupy additional space in the root directory partition, but will still occupy the space of the original partition. Executing rm (the second deletion instruction) again in the recycle directory (recycle bin directory) will completely delete the file. The file can be restored from the ".recycle" (recycle bin directory) to a specified location using the mv command.
[0093] This application makes modifications to the file system to prevent accidental deletion of files due to user misoperation when the user uses the rm command. After that, the file can be restored through the mv command, or rm can be used to confirm the complete deletion of the relevant files. Specifically, this application modifies the SYSCALL interface corresponding to rm so that after the rm command, the file is not deleted directly but is first moved to the ".recycle" directory under the root directory. After that, the user can choose to actually delete the file from the ".recycle" directory, or restore it to a specified directory.
[0094] SYSCALL is a system call. It is a method provided by the Linux kernel for the operating system to access the kernel. For example, if you enter rm in the command line to delete a file, the command will eventually call a specific method in the kernel through the system.
[0095] Specifically, for the Linux-based file processing method provided in the present application, an optional implementation is also provided, including:
[0096] First, during the system's file system initialization phase and root directory mounting phase, add Figure 2 processing; specifically:
[0097] A new structure is defined under VFS: This structure describes the objects in the recycle bin and needs to point to the inode corresponding to the file, the partition to which the file belongs, and the corresponding original path. The size of this structure should be as small as possible to reduce the consumption of the root directory partition space.
[0098] Create a new rb+ tree global variable under VFS: this variable is used to store and index all files moved to the recycle bin.
[0099] A new file type is defined: recycled. Directories and files of type recycled provide mv and rm operations, but do not provide create, copy, open, or modify operations. This type of file is only used to describe a file that has been moved to the Recycle Bin.
[0100] New file status: recycling. Files in the recycling status cannot be viewed or accessed temporarily.
[0101] Create a new ".recycle" directory in the root directory. This directory is used as a recycle bin. In this directory, you can see all the files that have been removed by the rm command but not completely deleted.
[0102] Second, when using the rm command to delete files, the relevant process is as follows Figure 3 As shown, specifically:
[0103] When executing rm to delete a file, if it is executed in a directory other than ".recycle", the original file status will be set to recycling (deleting status), making it no longer accessible or modifiable. However, the file is not actually deleted at this time, and the user can choose to restore the file or completely delete it at any time.
[0104] Add the inode corresponding to the file to the "rb+ tree" under ".recycle" and create a corresponding recycled file to describe some key information of the original file, including the partition and the original path.
[0105] The above types need to be written to persistent storage so that each time you restart, you can see the files that have been moved to the recycle bin in the ".recycle" directory.
[0106] If rm is executed in the ".recycle" directory, the original partition where the file object is located will be found and the file will be deleted using the deletion method of the corresponding file system.
[0107] After the file is deleted, remove the corresponding recycled file from the ".recycle" directory and remove the inode from the "rb+tree".
[0108] Third, when using the mv command to move files in the ".recycle" directory, the process is as follows Figure 4 As shown, specifically:
[0109] When executing the mv command in the ".recycle" directory, first find the original file based on the recycled file and remove its recycling status.
[0110] Remove recycled files.
[0111] Perform the mv operation on the original file and move it to the specified location.
[0112] It can be seen that the Linux-based file processing method provided by this application includes:
[0113] Directly modify the rm command: The existing designs similar to the recycle bin function do not modify the rm command itself, which results in either requiring additional commands (such as installing additional components and using special commands) to put files into the recycle bin, or requiring complex configurations (such as backup recovery or recovery from partition dump) to restore files. This application implements the function of giving the rm command a recycle bin buffer mechanism by modifying the kernel, eliminating additional installation and configuration, and does not require Linux users to change their usual operation methods.
[0114] Recycle Bin system designed at the VFS layer: There are many mainstream file systems, and each has its own characteristics. Therefore, the functions and features of each file system are often not universal. For example, the file recovery operation (xfsdump) applicable to xfs (a file system) cannot work on ext4. In the past, users needed to develop or find the corresponding recycle bin function for each file system separately, or format their partitions uniformly in order to use a specific recycle bin function. For systems with existing data, such an upgrade cost is very high. This application designs the recycle bin mechanism at the VFS layer by designing new structures and file types, which can shield the differences between different file systems and meet the design of a recycle bin that is applicable to the entire operating system. In this way, users only need to upgrade the kernel to use this function directly on different partitions.
[0115] Simple operation method integrated into the kernel: The recycle bin function or similar functions in related technologies require the installation of additional application components or even additional hardware configurations. On the one hand, this is an overhead for the system, and on the other hand, users need to use a new way to handle files, which is very inconvenient. No additional operations are designed or additional components need to be installed. The modification of the solution is integrated into the kernel, and the deletion and recovery operations can be performed by the original rm and mv commands, which is in line with the usual operating habits of Linux users.
[0116] Unified Recycle Bin Directory and File Format: The commonly used Recycle Bin function will create a Recycle Bin directory under each partition or each user. This is mainly due to the consideration that deleted files cannot occupy space in other partitions, but it is not convenient for unified operation and viewing. The Recycle Bin directory designed by this application creates a new file type and puts all deleted files into the Recycle Bin directory under the root directory, which is convenient for viewing, cleaning and restoring at any time. At the same time, the files in the Recycle Bin will hardly take up extra space.
[0117] Efficient file recovery and restoration method: Before completely confirming the deletion of a file, it is not moved to a new directory in a similar way to moving files, but is simply marked so that it is no longer displayed in the original directory. This can bring higher rm execution efficiency and file restoration efficiency; when completely deleting, the original file deletion process is used, and the performance is no lower than the original deletion process.
[0118] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0119] Based on the same inventive concept, the embodiment of the present application also provides a Linux-based file processing device for implementing the above-mentioned Linux-based file processing method. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above-mentioned method, so the specific limitations in the one or more Linux-based file processing device embodiments provided below can refer to the above-mentioned limitations on the Linux-based file processing method, and will not be repeated here.
[0120] In an exemplary embodiment, Figure 5 As shown, a file processing device 800 based on Linux is provided, comprising: a state adjustment module 81, a file creation module 82 and a file deletion module 83, wherein:
[0121] The state adjustment module 81 is used to add the index node corresponding to the to-be-deleted file to the data structure of the recycle bin directory and set the to-be-deleted file to the deleting state when receiving the first deletion instruction and determining that the to-be-deleted file pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory;
[0122] The file creation module 82 is used to create a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file;
[0123] The file deleting module 83 is used to delete the to-be-processed file from the storage partition of the to-be-processed file corresponding to the to-be-processed file, and remove the to-be-processed file in the recycle bin directory when receiving the second deletion instruction for the to-be-processed file.
[0124] In an exemplary embodiment, the Linux-based file processing device 800 provided in the present application also includes a file recovery module, which is used to remove the storage partition of the to-be-deleted file corresponding to the to-be-deleted file and the deleting status of the to-be-deleted file in the storage partition corresponding to the to-be-deleted file, remove the to-be-processed file in the recycle bin directory, and move the to-be-deleted file to the target location pointed to by the move instruction when receiving a move instruction for the to-be-deleted file.
[0125] In an exemplary embodiment, the file recovery module is used to remove the in-deletion state of the to-be-deleted file, and is also used to remove the index node of the to-be-deleted file from the data structure of the recycle bin directory.
[0126] In an exemplary embodiment, the Linux-based file processing device 800 provided in the present application also includes a recycle bin creation module, which is used to define a recycling structure under the virtual file system and create a data structure for storing and indexing files to be deleted before receiving the first deletion instruction when the Linux system root directory is mounted for the first time; create a recycle bin directory under the system root directory; and the recycle bin directory is used to display the files to be processed corresponding to the files to be deleted.
[0127] In an exemplary embodiment, the Linux-based file processing device 800 provided in the present application also includes a data storage module, which is used to create a to-be-processed file associated with a to-be-deleted file in a recycle bin directory, write the to-be-processed file into the Linux memory, and display the to-be-processed file in the recycle bin directory when Linux is started.
[0128] In an exemplary embodiment, the Linux-based file processing device 800 provided in the present application also includes a timed deletion module, which is used to start a timer for the file to be deleted and the corresponding file to be processed after creating a file to be processed associated with the file to be deleted in the recycle bin directory. When the timer reaches the timing time and no second deletion instruction for the file to be processed is received, the file to be deleted is deleted from the storage partition of the file to be deleted corresponding to the file to be processed, and the file to be processed in the recycle bin directory is removed.
[0129] Each module in the above-mentioned Linux-based file processing device can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each of the above modules.
[0130] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 6 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a file processing method based on Linux is implemented.
[0131] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0132] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0133] When receiving the first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, adding the index node corresponding to the file to be deleted to the data structure of the recycle bin directory, and setting the file to be deleted to a deleting state;
[0134] Creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file;
[0135] When the second deletion instruction for the to-be-processed file is received, the to-be-deleted file is deleted from the storage partition of the to-be-deleted file corresponding to the to-be-processed file, and the to-be-processed file in the recycle bin directory is removed.
[0136] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0137] When receiving the first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, adding the index node corresponding to the file to be deleted to the data structure of the recycle bin directory, and setting the file to be deleted to a deleting state;
[0138] Creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file;
[0139] When the second deletion instruction for the to-be-processed file is received, the to-be-deleted file is deleted from the storage partition of the to-be-deleted file corresponding to the to-be-processed file, and the to-be-processed file in the recycle bin directory is removed.
[0140] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0141] When receiving the first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, adding the index node corresponding to the file to be deleted to the data structure of the recycle bin directory, and setting the file to be deleted to a deleting state;
[0142] Creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file;
[0143] When the second deletion instruction for the to-be-processed file is received, the to-be-deleted file is deleted from the storage partition of the to-be-deleted file corresponding to the to-be-processed file, and the to-be-processed file in the recycle bin directory is removed.
[0144] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0145] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0146] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0147] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A file processing method based on Linux, characterized in that: The method comprises: When receiving a first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, adding an index node corresponding to the file to be deleted to a data structure of the recycle bin directory, and setting the file to be deleted to a deleting state; Creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file; When a second deletion instruction for the to-be-processed file is received, the to-be-processed file is deleted from the storage partition of the to-be-deleted file corresponding to the to-be-processed file, and the to-be-processed file in the recycle bin directory is removed.
2. The method according to claim 1, characterized in that The method further comprises: When a move instruction for the file to be processed is received, the storage partition of the file to be deleted corresponding to the file to be processed and the deleting state of the file to be deleted are removed, the file to be processed in the recycle bin directory is removed, and the file to be deleted is moved to the target location pointed to by the move instruction.
3. The method according to claim 2, characterized in that In the case where the to-be-deleted file is removed from the deleting state, the method further includes: The index node of the to-be-deleted file is removed from the data structure of the recycle bin directory.
4. The method according to claim 1, characterized in that Before receiving the first deletion instruction, the method further includes: When the Linux system root directory is mounted for the first time, a recovery structure is defined under the virtual file system, and a data structure for storing and indexing files to be deleted is created; A recycle bin directory is created under the system root directory; the recycle bin directory is used to display the to-be-processed files corresponding to the to-be-deleted files.
5. The method according to claim 1, characterized in that After creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory, the method further includes: The to-be-processed file is written into the memory of the Linux, and the to-be-processed file is displayed in the recycle bin directory when the Linux is started.
6. The method according to claim 1, characterized in that After creating a to-be-processed file associated with the to-be-deleted file in the recycle bin directory, the method further includes: Start a timer for the file to be deleted and the corresponding file to be processed. When the timer reaches the timing time and no second deletion instruction for the file to be processed is received, delete the file to be deleted from the storage partition of the file to be deleted corresponding to the file to be processed, and remove the file to be processed in the recycle bin directory.
7. A file processing device based on Linux, characterized in that: The device comprises: a state adjustment module, configured to, upon receiving a first deletion instruction and determining that the file to be deleted pointed to by the first deletion instruction is not in the recycle bin directory under the system root directory, add an index node corresponding to the file to be deleted to a data structure of the recycle bin directory, and set the file to be deleted to a deleting state; A file creation module, used to create a to-be-processed file associated with the to-be-deleted file in the recycle bin directory; wherein the to-be-processed file is used to record the storage partition information and path information of the corresponding to-be-deleted file; The file deletion module is used to delete the to-be-processed file from the storage partition of the to-be-processed file corresponding to the to-be-processed file and remove the to-be-processed file in the recycle bin directory when receiving a second deletion instruction for the to-be-processed file.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
File recovery method and device of linux system
CN104199750A
Data object deleting method and device based on distributed file system
CN106354884A
File processing method and device
CN107402846A
Method of creating recycle bin based on KUX operating system
CN107562898A
File system processing method, recycle bin management method, device and equipment
CN114490516A
Cited By
Linux-based file processing method and apparatus, and computer device
WO2026114077A1