Linux-based file processing method and device, computer device, readable storage medium and program product
By introducing a recycle bin mechanism into the Linux system, the problem of files being unrecoverable after deletion is solved, and temporary file storage and recovery functions are implemented, which conforms to user habits and makes efficient use of storage space.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA TELECOM CLOUD TECH CO LTD
- Filing Date
- 2024-11-26
- Publication Date
- 2026-06-16
Smart Images

Figure CN119576871B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a file processing method, apparatus, computer device, computer-readable storage medium, and computer program product based on Linux. Background Technology
[0002] In current Linux operating systems, when users want to delete a file, they usually use the `rm` command (delete command). Using the `rm` command to delete a file means the file is directly removed; there is no intermediate mechanism like a recycle bin.
[0003] Users may not want the files to disappear after triggering the rm command; they may simply want to temporarily move the files to a certain location and then clean them up all at once when they run out of space or are sure they don't need them anymore. Summary of the Invention
[0004] Therefore, it is necessary to provide a Linux-based file processing method, apparatus, computer device, computer-readable storage medium, and computer program product that can perform temporary storage and other processing on the file pointed to by the rm command, in order to address the above-mentioned technical problems.
[0005] Firstly, this application provides a file processing method based on Linux, the method including:
[0006] 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, the inode 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 deletion status.
[0007] Create a pending file associated with the file to be deleted in the recycle bin directory; wherein, the pending file is used to record the storage partition information and path information of the corresponding file to be deleted;
[0008] Upon receiving a 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 is removed from the recycle bin directory.
[0009] In one embodiment, the method further includes:
[0010] Upon receiving a move instruction for the file to be processed, the file to be deleted is removed from the storage partition of the file to be deleted corresponding to the file to be processed, the file to be deleted is removed from the recycle bin directory, and the file to be deleted is moved to the target location indicated by the move instruction.
[0011] In one embodiment, if the file to be deleted is removed from the deletion state, the method further includes:
[0012] Remove the inode of the file to be deleted from the data structure of the recycle bin directory.
[0013] In one embodiment, prior to receiving the first deletion instruction, the method further includes:
[0014] When the Linux system root directory is mounted for the first time, a recycling structure is defined under the virtual file system, and a data structure for storing and indexing files to be deleted is created;
[0015] Create a recycle bin directory in the system root directory; the recycle bin directory is used to display the files to be processed corresponding to the files to be deleted.
[0016] In one embodiment, after creating a pending file associated with the file to be deleted in the recycle bin directory, the method further includes:
[0017] The file to be processed is written to the Linux storage, and the file to be processed is displayed in the recycle bin directory when the Linux is booted.
[0018] In one embodiment, after creating a pending file associated with the file to be deleted 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. If the timer reaches its set time and no second deletion instruction is received for the file to be processed, 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 from the recycle bin directory.
[0020] Secondly, this application also provides a Linux-based file processing device, the device comprising:
[0021] The status adjustment module is used to add the inode corresponding to the file to be deleted to the data structure of the recycle bin directory and set the file to be deleted to a state of deletion 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.
[0022] The file creation module is used to create a pending file associated with the file to be deleted in the recycle bin directory; wherein, the pending file is used to record the storage partition information and path information of the corresponding file to be deleted;
[0023] The file deletion module is used to 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 from the recycle bin directory when a second deletion instruction is received for the file to be processed.
[0024] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0025] 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, the inode 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 deletion status.
[0026] Create a pending file associated with the file to be deleted in the recycle bin directory; wherein, the pending file is used to record the storage partition information and path information of the corresponding file to be deleted;
[0027] Upon receiving a 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 is removed from the recycle bin directory.
[0028] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0029] 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, the inode 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 deletion status.
[0030] Create a pending file associated with the file to be deleted in the recycle bin directory; wherein, the pending file is used to record the storage partition information and path information of the corresponding file to be deleted;
[0031] Upon receiving a 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 is removed from the recycle bin directory.
[0032] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0033] 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, the inode 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 deletion status.
[0034] Create a pending file associated with the file to be deleted in the recycle bin directory; wherein, the pending file is used to record the storage partition information and path information of the corresponding file to be deleted;
[0035] Upon receiving a 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 is removed from the recycle bin directory.
[0036] The file processing method, apparatus, computer device, computer-readable storage medium, and computer program product based on Linux provided in this application, wherein the Linux-based file processing method, 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, adds the inode corresponding to the file to be deleted to the data structure of the recycle bin directory and sets the file to be deleted to a deletion state; creates a file to be processed associated with the file to be deleted in the recycle bin directory; wherein the file to be processed is used to record the storage partition information and path information of the corresponding file to be deleted; upon receiving a second deletion instruction for the file to be processed, deletes the file to be deleted from the storage partition of the file to be deleted corresponding to the file to be processed, and removes the file to be processed from the recycle bin directory; it can be seen that this application sets up a recycle bin mechanism (recycle bin directory) for file deletion in Linux, so that any file in Linux can be moved to the recycle bin directory for temporary storage after receiving a first deletion instruction, and then the user can choose to permanently delete the file at any time according to needs, so as to prevent the situation where the file cannot be recovered due to accidental deletion. Attached Figure Description
[0037] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0038] Figure 1 This is a flowchart illustrating a Linux-based file processing method in one embodiment;
[0039] Figure 2 This is a flowchart illustrating the process of creating a recycle bin directory in one embodiment;
[0040] Figure 3 This is a schematic diagram of the file deletion process in one embodiment;
[0041] Figure 4 This is a schematic diagram of the file recovery process in one embodiment;
[0042] Figure 5 This is a block diagram of a Linux-based file processing device in one embodiment;
[0043] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0044] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0045] In related technologies, under the Linux operating system, when a user wants to delete a file, they usually use the `rm` command (delete command). Using the `rm` command to delete a file means the file is directly removed; there is no intermediate mechanism like a recycle bin.
[0046] For users, they may not want the files to disappear after running `rm`. Instead, they might prefer a mode similar to the Recycle Bin in Windows, where files are temporarily moved to a certain location and then cleaned up all at once when space is insufficient or the files are no longer needed.
[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 recover files.
[0048] In related technologies, the Linux system provides several techniques similar to a recycle bin, offering temporary storage or retrieval of deleted files. These include:
[0049] Firstly, some operating systems that provide a graphical interface (such as Ubuntu) offer a recycle bin function. However, this has some drawbacks. Specifically, the graphical interface requires mouse operation, and using the `rm` command still directly deletes files. Furthermore, Ubuntu's recycle bin design actually moves deleted files to the `trash` directory under the user's home directory, which is not applicable to files outside the user's home directory, making it very limited.
[0050] Secondly, the backup function can restore files to a specific point in time. However, it has some drawbacks. While backups ensure storage reliability, they often require additional configuration, making the process cumbersome and resource-intensive, and necessitating additional storage space. Furthermore, file backups can only restore files from a specific point in time, failing to achieve the intended effect of a recycle bin.
[0051] Third, some tools provide a similar recycle bin mechanism (such as trash-cli, a command-line recycle bin tool). However, there are some drawbacks. Specifically, tools like trash-cli require additional installation, which may lead to system compatibility issues. Furthermore, these tools only provide new commands and cannot override the existing rm command, which does not conform to the habits of Linux users, and the way to view deleted files is not intuitive enough.
[0052] Fourth, some vendors provide recycle bin functionality for specific file systems (such as OCFS2 or ext4). However, there are some drawbacks. Specifically, recycle bin systems developed for specific file systems require partitions to be formatted to that specific file system, necessitating data migration beforehand, which is quite limiting. Furthermore, with a large number of partitions, each partition has its own recycle bin directory, making it inconvenient to use. OCFS2 stands for Oracle Cluster File System Version 2, a shared disk file system; ext4 stands for Fourth extended filesystem, an extended file system.
[0053] Based on the aforementioned problems with related technologies, this application proposes a method to modify the kernel's VFS. Specifically, it modifies the VFS layer, which is common to file systems, to provide a recycle bin mechanism for the `rm` command. This way, regardless of the type of file system mounted, the `rm` command can be used to move deleted files to the recycle bin, and all recycled files are concentrated in the same directory. This recycle bin design is more unified, intuitive, and convenient.
[0054] Among them, VFS (Virtual Filesystem) is a virtual file system. It is a wrapper layer for the Linux kernel's file system, shielding various different types of file systems to provide a unified operation entry point for the operating system.
[0055] Specifically, the Linux-based file processing method provided in this application can be applied to terminals, which can be, but are not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, projection devices, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc. Head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The Linux-based file processing method for terminals provided in this application requires that the terminal being used be running the Linux operating system.
[0056] In one exemplary embodiment, such as Figure 1 As shown, a file processing method based on Linux is provided. Taking the application of this method to a terminal with a Linux operating system as an example, the method includes the following steps 202 to 206. Wherein:
[0057] Step 202: Upon 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, add the inode corresponding to the file to be deleted to the data structure of the recycle bin directory, and set the file to be deleted to the deletion status.
[0058] The first deletion instruction is the first rm command applied by the user to the file to be deleted; in this application, it is a command used to move at least some 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, upon receiving a first delete command from a user on a file in the Linux operating system, the system further determines whether the file exists in the Linux operating system's recycle bin directory. If it is determined that the file is not in the recycle bin directory under the system root directory, it means that this is the first time the rm command has been received for this file. That is, the user intends to move the file to the recycle bin directory, rather than completely deleting it from the terminal. The terminal then adds the inode corresponding to the file to be deleted to the recycle bin directory's data structure (the rb+tree global variable) and sets the file to be deleted to a recycling state.
[0061] Files that are being deleted 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 an efficient tree-like data structure for storing and searching target objects, and it is commonly used in file systems to store file nodes or data blocks.
[0063] An inode is a structure stored in persistent storage that describes a file object. This structure contains basic information about the file. In the file system, a file object is queried or managed through its inode.
[0064] Step 204: Create a pending file associated with the file to be deleted in the recycle bin directory; the pending file is used to record the storage partition information and path information of the corresponding file to be deleted.
[0065] The file to be processed describes information about files to be deleted that are being moved to the recycle bin directory. The file to be processed can receive rm and mv commands (move commands), but cannot be modified or viewed.
[0066] For example, 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, 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 has been moved to the recycle bin, 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 using the rm command, the user can no longer view or access the file from its original directory, but can find the file (the file to be processed) in the recycle bin directory under the root directory.
[0068] Step 206: Upon receiving a second deletion instruction for the file to be processed, 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 from the recycle bin directory.
[0069] The second deletion command is the second rm command applied by the user to the file to be deleted; the target of the second deletion command is the file to be deleted in the recycle bin directory.
[0070] For example, after the file to be deleted receives the first deletion command from the user, the file is not completely deleted from the terminal, but remains in a deletion state. It cannot be viewed or accessed in the original directory of the file to be deleted. At the same time, a pending file associated with the file to be deleted is created in the recycle bin directory. This allows the user to apply a second deletion command to the pending file in the recycle bin directory if they need to completely delete the file. Then, based on the second deletion command, the file to be deleted is deleted from the original storage partition of the file to be deleted, and the related pending file in the recycle bin directory is 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 command, 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 file to be processed 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. This makes the deleted file not occupy extra space in the root directory partition, but still occupy the space of the original partition.
[0072] In the aforementioned Linux-based file processing method, upon receiving a first deletion command and determining that the file to be deleted pointed to by the first deletion command is not in the recycle bin directory under the system root directory, the inode 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 deletion state; a file to be processed associated with the file to be deleted is created in the recycle bin directory; wherein, the file to be processed is used to record the storage partition information and path information of the corresponding file to be deleted; upon receiving a second deletion command 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 is removed from the recycle bin directory; it can be seen that this application sets up a recycle bin mechanism (recycle bin directory) for file deletion in Linux, so that any file in Linux can be moved to the recycle bin directory for temporary storage after receiving a first deletion command, and then the user can choose to permanently delete the file at any time according to needs, so as to prevent the situation where the file cannot be recovered due to accidental deletion.
[0073] In one exemplary embodiment, the Linux-based file processing method provided in this application further includes:
[0074] Upon receiving a move instruction for a file to be processed, remove the file from the storage partition corresponding to the file to be deleted, remove the file from the deletion process, remove the file from the recycle bin directory, and move the file to be deleted to the target location indicated by the move instruction.
[0075] The move command, also known as the mv command in the Linux operating system, is used to move the file targeted by the mv command to a different location, at least the location it is displayed in.
[0076] The target location is the location where the file pointed to by the move command needs to be updated and displayed.
[0077] For example, if a user regrets deleting a file after the first `rm` command, the file can be restored from the recycle bin. Specifically, a restore command is applied to the pending files in the recycle bin. Upon receiving this command, the file status of the file to be deleted is changed; that is, the "deleting" status (recycling) is removed from the storage partition of the file to be deleted, restoring it to its state before the first `rm` command, where it is viewable and accessible to the user. Simultaneously, the relevant pending files are removed from the recycle bin and moved to the target location indicated by the move command, allowing the file to be displayed and accessed by the user at the target location.
[0078] As can be seen, this application provides a way to recover deleted files under the Linux operating system. When a user deletes a file using the rm command, it will not be removed directly, but will be moved to the recycle bin directory first. Then, the user can continue to recover the deleted file, which helps to avoid accidental permanent deletion of files.
[0079] In one exemplary embodiment, when the file to be deleted is removed from the deletion process, the method further includes removing the inode of the file to be deleted from the data structure of the recycle bin directory.
[0080] For example, when a file to be deleted is removed from the deletion process, the inode of the file to be deleted will be further removed from the data structure of the recycle bin directory. This ensures that no information about the file to be deleted is associated with the recycle bin directory, thus avoiding any problems with viewing or accessing the recovered file.
[0081] In one 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 recycling structure is defined under the virtual file system, and a data structure is created to store and index files to be deleted.
[0083] Create a Recycle Bin directory in the system root directory; the Recycle Bin directory is used to display the files to be deleted.
[0084] The Virtual File System (VFS) is a wrapper layer for the Linux kernel's file system, shielding it from various file systems to provide a unified operating entry point for the operating system.
[0085] For example, when the Linux system root directory is mounted for the first time in the terminal, a recycle 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. 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 in the Linux system root directory. This directory is used as the recycle bin, where all files removed by the rm command but not completely deleted can be seen. The files to be deleted displayed in the recycle bin directory are the related pending files generated after receiving the rm command.
[0086] In one exemplary embodiment, after creating a pending file associated with the file to be deleted in the recycle bin directory, the method further includes: writing the pending file to Linux storage and displaying the pending file in the recycle bin directory while Linux is running.
[0087] In Linux, the storage device is used to store some file data information from the relevant terminals.
[0088] For example, after creating a pending file associated with the file to be deleted in the recycle bin directory, the pending file can be written to the Linux storage for storage, so that the relevant pending file can be seen in the recycle bin directory every time Linux is in the boot state, and files that have not been completely deleted can be seen in the recycle bin directory in the terminal or after each Linux reboot.
[0089] In an exemplary embodiment, after creating a file to be processed associated with the file to be deleted in the recycle bin directory, the method further includes: starting a timer for the file to be deleted and the corresponding file to be processed; when the timer reaches its set time and no second deletion instruction for the file to be processed is received, deleting the file to be deleted from the storage partition of the file to be deleted corresponding to the file to be processed, and removing the file to be processed from the recycle bin directory.
[0090] For example, to avoid an excessive amount of files in the recycle bin directory and to prevent users from forgetting to completely delete related files in the recycle bin directory, this application also provides an alternative implementation method: 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 its corresponding pending file. If the timer has not reached its set time, the user can completely delete or restore the file in the recycle bin directory as needed. If the timer reaches its set time and no second deletion instruction for the pending file is received, it means that the user forgot to completely delete the file in the recycle bin directory and no longer needs the related file. In this case, the file to be deleted can be automatically deleted from the original storage partition corresponding to the file to be deleted, and the related pending file in the recycle bin directory can be removed, so that the file is completely deleted from the terminal.
[0091] In summary, this application proposes a method to modify the kernel's VFS and some system calls, providing a buffer and quick recovery operation for users' file deletion operations. This application designs a recycle bin system (recycle bin directory) specifically for handling deleted files. When a user deletes a file using the `rm` command (the first deletion command), it is not directly removed but first moved to the recycle bin directory. Users can choose to permanently delete or restore the file at any time to prevent accidental file deletion.
[0092] This application provides a Linux-based file processing method, specifically including: designing a new file type: recycled. This file type is specifically used to record information about files moved to the recycle bin. This file type can be deleted using the `rm` or `mv` command, but cannot be modified or viewed. When a user enters the `rm` command to delete a file, the user can no longer view or access the file from its original directory, but can find the file in the ".recycle" directory (recycle bin directory) under the root directory. Deleted files do not occupy extra space on the root directory partition, but still occupy the space of the original partition. Executing `rm` again (the second deletion command) in the recycle directory (recycle bin directory) will permanently delete the file. The `mv` command can be used to restore files from the ".recycle" directory (recycle bin directory) to a specified location.
[0093] This application modifies the file system to prevent accidental file deletion by users when using the `rm` command. Afterward, files can be recovered using the `mv` command, or the `rm` command can confirm complete deletion. Specifically, this application modifies the `SYSCALL` interface corresponding to `rm` so that after the `rm` command, files are not directly deleted but are first moved to the `.recycle` directory in the root directory. Afterward, users 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's a method provided by the Linux kernel for the operating system to access the kernel. For example, when you type `rm` to delete a file in the command line, this command ultimately calls a specific method in the kernel via a system call.
[0095] Specifically, for the Linux-based file processing method provided in this application, an alternative implementation method is also provided, including:
[0096] Firstly, during the system's file system initialization phase and root directory mounting phase, new features such as... Figure 2 The processing; specifically:
[0097] Define a new structure under VFS: This structure describes 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 space on the root directory partition.
[0098] Create a new global variable named rb+ tree in VFS: this variable is used to store and index all files that have been moved to the recycle bin.
[0099] A new file type, `recycled`, is defined. 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 defined: recycling. Files with the status set to recycling cannot be viewed or accessed temporarily.
[0101] Create a new directory named ".recycle" in the root directory. This directory will be used as a recycle bin. You can see all the files that have been removed by the rm command but have not been completely deleted in this directory.
[0102] Secondly, when using the rm command to delete files, the relevant process is as follows: Figure 3 As shown, specifically:
[0103] When the `rm` command is executed, if it is not executed in a directory other than ".recycle", the original file's status is set to "recycling" (deleting in progress), making it inaccessible and unmodifiable. However, the file is not actually deleted at this point, and the user can choose to restore the file or permanently 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 about the original file, including the partition it was located in and its original path.
[0105] The above types of files need to be written to persistent storage so that the files that have been moved to the recycle bin can be seen in the ".recycle" directory every time the system restarts.
[0106] If `rm` is executed in the ".recycle" directory, it will locate the original partition where the file object is located and delete the file using the corresponding file system's deletion method.
[0107] After deleting the file, remove the corresponding recycled file from the ".recycle" directory and remove the inode from "rb+tree".
[0108] Thirdly, when moving files using the `mv` command in the ".recycle" directory, the process is as follows: Figure 4 As shown, specifically:
[0109] When executing the mv command in the ".recycle" directory, the original file is first located based on the recycled file, and its recycling status is removed.
[0110] Remove recycled files.
[0111] Perform the `mv` operation on the original file and move it to the specified location.
[0112] As can be seen, the Linux-based file processing method provided in this application includes:
[0113] This application directly modifies the `rm` command: Current recycle bin-like designs do not modify the `rm` command itself. This results in either the need for additional commands (such as installing extra components and using special commands) to put files into the recycle bin, or complex configurations (such as backup and restore or recovery from partition dumps) to restore files. This application modifies the kernel to give the `rm` command a recycle bin-like buffering mechanism, eliminating the need for additional installation and configuration, and requiring Linux users to change their established operating habits.
[0114] A recycle bin system designed at the VFS layer: Currently, there are many mainstream file systems, each with its own characteristics. Therefore, the functions and features of different file systems are often not universal. For example, file recovery operations (xfsdump) suitable for xfs (a file system) cannot be performed on ext4. Previously, users needed to develop or find corresponding recycle bin functions for each file system, or format their partitions uniformly to use a specific recycle bin function. For systems with existing data, such upgrades are very costly. This application designs a new structure and file types to integrate the recycle bin mechanism at the VFS layer. This shields the differences between different file systems, allowing a single recycle bin to be used across the entire operating system. In this way, users only need to upgrade the kernel to directly use this function on different partitions.
[0115] The simplified operation method integrated into the kernel: Similar functions in related technologies often require the installation of additional application components or even additional hardware. This is an overhead for the system and inconvenient for users who need to handle files in new ways. This solution avoids the need for additional operations or components, integrating the modification into the kernel. Deletion and restoration operations can be performed using the existing rm and mv commands, conforming to the established operating habits of Linux users.
[0116] A unified recycle bin directory and file format: Common recycle bin functions create a recycle bin directory for each partition or user, primarily to prevent deleted files from occupying space on other partitions. However, this is inconvenient for unified operation and viewing. The recycle bin directory designed in this application creates a new file type, placing all deleted files in a unified recycle bin directory under the root directory for easy viewing, cleaning, and restoration. At the same time, files in the recycle bin occupy almost no extra space.
[0117] Efficient file recycling and restoration: Before completely confirming the deletion of a file, it is not moved to a new directory in a way similar to moving files. Instead, the file is simply marked so that it will no longer be displayed in the original directory. This results in higher rm execution efficiency and file restoration efficiency. When completely deleting, the original file deletion process is used, and its performance is not lower than the original deletion process.
[0118] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0119] Based on the same inventive concept, this application also provides a Linux-based file processing apparatus for implementing the Linux-based file processing method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more Linux-based file processing apparatus embodiments provided below can be found in the limitations of the Linux-based file processing method described above, and will not be repeated here.
[0120] In one exemplary embodiment, such as Figure 5 As shown, a Linux-based file processing device 800 is provided, including: a status adjustment module 81, a file creation module 82, and a file deletion module 83, wherein:
[0121] The status adjustment module 81 is used to add the inode corresponding to the file to be deleted to the data structure of the recycle bin directory and set the file to be deleted to a state of deletion when it receives the first deletion instruction and determines 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.
[0122] The file creation module 82 is used to create a pending file associated with the file to be deleted in the recycle bin directory; the pending file is used to record the storage partition information and path information of the corresponding file to be deleted.
[0123] The file deletion module 83 is used to 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 from the recycle bin directory when a second deletion instruction for the file to be processed is received.
[0124] In an exemplary embodiment, the Linux-based file processing device 800 provided in this application further includes a file recovery module. The file recovery module is used to remove the file to be deleted from the storage partition of the file to be deleted corresponding to the file to be processed, remove the file to be processed from the recycle bin directory, and move the file to be deleted to the target location indicated by the move instruction when a move instruction for the file to be processed is received.
[0125] In one exemplary embodiment, the file recovery module, in addition to removing the file from the deletion process, is also used to remove the inode of the file from the data structure of the recycle bin directory.
[0126] In an exemplary embodiment, the Linux-based file processing device 800 provided in this application further includes a recycle bin creation module. The recycle bin creation module is used to define a recycle structure under the virtual file system and create a data structure for storing and indexing files to be deleted when the Linux system root directory is mounted for the first time before receiving the first deletion instruction; and to create a recycle bin directory under the system root directory; 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 this application further includes a data storage module. The data storage module is used to create a file to be processed associated with the file to be deleted in the recycle bin directory, write the file to be processed to the Linux storage, and display the file to be processed in the recycle bin directory when Linux is in the boot state.
[0128] In an exemplary embodiment, the Linux-based file processing device 800 provided in this application further includes a timed deletion module. The timed deletion module is used to create a file to be processed associated with the file to be deleted in the recycle bin directory, start a timer for the file to be deleted and the corresponding file to be processed, and delete the file to be deleted from the storage partition of the file to be deleted corresponding to the file to be processed when the timer reaches the timeout period and no second deletion instruction for the file to be processed is received, and remove the file to be processed from the recycle bin directory.
[0129] The modules in the aforementioned Linux-based file processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of the computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0130] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 6 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and databases. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media to run. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When executed by the processor, the computer program implements a Linux-based file processing method.
[0131] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0132] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0133] Upon 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, the inode 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 deletion status.
[0134] Create a pending file in the recycle bin directory associated with the file to be deleted; the pending file is used to record the storage partition information and path information of the corresponding file to be deleted;
[0135] Upon receiving a second deletion instruction for a file to be processed, the file to be deleted is removed from the storage partition of the file to be deleted corresponding to the file to be processed, and the file to be processed is removed from the recycle bin directory.
[0136] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:
[0137] Upon 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, the inode 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 deletion status.
[0138] Create a pending file in the recycle bin directory associated with the file to be deleted; the pending file is used to record the storage partition information and path information of the corresponding file to be deleted;
[0139] Upon receiving a second deletion instruction for a file to be processed, the file to be deleted is removed from the storage partition of the file to be deleted corresponding to the file to be processed, and the file to be processed is removed from the recycle bin directory.
[0140] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps:
[0141] Upon 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, the inode 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 deletion status.
[0142] Create a pending file in the recycle bin directory associated with the file to be deleted; the pending file is used to record the storage partition information and path information of the corresponding file to be deleted;
[0143] Upon receiving a second deletion instruction for a file to be processed, the file to be deleted is removed from the storage partition of the file to be deleted corresponding to the file to be processed, and the file to be processed is removed from the recycle bin directory.
[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, data stored, data displayed, 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 the relevant data must comply with relevant regulations.
[0145] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this 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. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0146] The technical features of the above embodiments can be combined in any way. For the sake of brevity, 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 embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A file processing method based on Linux, characterized in that, The method includes: When the Linux system root directory is mounted for the first time, a recycle structure is defined under the virtual file system, and a data structure for storing and indexing files to be deleted is created; the recycle structure is used to describe 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; 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, 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 deletion state; wherein, the index node is a structure stored in persistent storage device to describe the file to be deleted, and the structure of the file to be deleted contains basic information about the file to be deleted; the data structure is used to store and index all files moved to the recycle bin directory, and the data structure includes a tree data structure; Create a pending file associated with the file to be deleted in the recycle bin directory; wherein, the pending file is used to record the storage partition information and path information of the corresponding file to be deleted; wherein, the storage location of the file to be deleted does not change; Upon receiving a 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 is removed from the recycle bin directory.
2. The method according to claim 1, characterized in that, The method further includes: Upon receiving a move instruction for the file to be processed, the file to be deleted is removed from the storage partition of the file to be deleted corresponding to the file to be processed, the file to be deleted is removed from the recycle bin directory, and the file to be deleted is moved to the target location indicated by the move instruction.
3. The method according to claim 2, characterized in that, If the file to be deleted is removed from the deletion state, the method further includes: Remove the inode of the file to be deleted from the data structure of the recycle bin directory.
4. The method according to claim 1, characterized in that, Prior to receiving the first deletion instruction, the method further includes: Create a recycle bin directory in the system root directory; the recycle bin directory is used to display the files to be processed corresponding to the files to be deleted.
5. The method according to claim 1, characterized in that, After creating a pending file associated with the file to be deleted in the recycle bin directory, the process also includes: The file to be processed is written to the Linux storage, and the file to be processed is displayed in the recycle bin directory when the Linux is booted.
6. The method according to claim 1, characterized in that, After creating a pending file associated with the file to be deleted in the recycle bin directory, the process also includes: Start a timer for the file to be deleted and the corresponding file to be processed. If the timer reaches its set time and no second deletion instruction is received for the file to be processed, 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 from the recycle bin directory.
7. A file processing device based on Linux, characterized in that, The device includes: The recycle bin creation module is used to define a recycle structure under the virtual file system when the Linux system root directory is mounted for the first time, and to create a data structure for storing and indexing files to be deleted; the recycle structure is used to describe 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; A status adjustment module is used 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 the index node corresponding to the file to be deleted to the data structure of the recycle bin directory, and set the file to be deleted to a deletion state; wherein, the index node is a structure stored in persistent storage device for describing the file to be deleted, and the structure of the file to be deleted contains basic information about the file to be deleted; the data structure is used to store and index all files moved to the recycle bin directory, and the data structure includes a tree data structure; The file creation module is used to create a pending file associated with the file to be deleted in the recycle bin directory; wherein, the pending file is used to record the storage partition information and path information of the corresponding file to be deleted; wherein, the storage location of the file to be deleted does not change; The file deletion module is used to 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 from the recycle bin directory when a second deletion instruction is received for the file to be processed.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.