File hiding method and system based on ext4 file system

By creating hard links and deleting directory entries in the ext4 file system, combined with inode node association and secure storage, the problems of file concealment and data persistence are solved, achieving efficient file hiding without key dependence, which is suitable for embedded devices and low-power scenarios.

CN120874119APending Publication Date: 2025-10-31KYLIN CORP
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202511026959.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-24
Publication Date
2025-10-31

AI Technical Summary

Technical Problem

Existing technologies for file hiding suffer from poor concealment, high computational overhead, and insufficient data persistence, making them particularly difficult to meet the needs of lightweight and low-power scenarios.

Method used

By creating hard links and deleting directory entries in the ext4 file system, and using inode node association to ensure the preservation of data blocks, combined with backup of metadata in a secure storage area, key-free file covert storage is achieved.

Benefits of technology

It achieves complete file concealment in the directory structure, avoiding data loss, and has high concealment and low resource overhead, making it suitable for data protection in embedded devices and low-power scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120874119A_ABST
    Figure CN120874119A_ABST
Patent Text Reader

Abstract

The invention discloses a file hiding method and system based on an ext4 file system, and the method comprises the steps: obtaining a target file and metadata information of a directory where the target file is located according to a target file path needing to be hidden, and distributing a new mapping item in an internal mapping table of the ext4 file system for recording; creating a new hard link in a directory where the target file is located, and associating the new hard link with an inode node for storing metadata information of the target file; reopening the ext4 file system, and deleting the directory entry of the target file, so that the target file cannot be found in the ext4 file system; and re-mounting the ext4 file system, refreshing the Linux kernel cache, and recording the new hard link, the original name of the target file, the inode node number of the target file and the file type into a new mapping item. According to the invention, data security can be ensured, and efficient hidden storage of files is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of file hiding technology, specifically to a file hiding method and system based on the ext4 file system. Background Technology

[0002] like Figure 1 The image shows three mainstream methods for hiding / recovering files using existing technologies. Among them, the attribute-hiding method, which disguises files by name (such as .hidden files starting with a dot or using extensions like xattr), has poor concealment and is easily detected by regular operations. The method of encrypted storage (such as LUKS and eCryptfs) requires complex key management and introduces computational overhead, making it difficult to meet the requirements of lightweight hiding. The method of deletion (such as deleting directly to the recycle bin) removes the directory entry, but the freed storage space may be overwritten by new data (such as when the user manually empties the recycle bin or when the disk is automatically cleaned up due to insufficient space), making it impossible to securely save the hidden content.

[0003] Therefore, in view of the shortcomings of the existing technologies, there is an urgent need for a file hiding method that does not require keys and is based on the underlying mechanism of the file system, so as to achieve efficient concealment while ensuring data persistence. Summary of the Invention

[0004] The technical problem to be solved by the present invention is to provide a file hiding method and system based on the ext4 file system, which achieves efficient and hidden file storage while ensuring data security by directly manipulating the underlying structure of the ext4 file system.

[0005] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows: A file hiding method based on the ext4 file system, including the following steps: S1: Obtain the metadata information of the target file and the directory where the target file is located according to the target file path to be hidden, and allocate a new mapping entry in the internal mapping table of the ext4 file system for recording; S2, create a new hard link in the directory where the target file is located, and associate the new hard link with the inode node that stores the metadata information of the target file; S3, reopen the ext4 file system, delete the directory entry of the target file to remove the hard link between the target file and the inode node, so that the target file cannot be found in the ext4 file system; S4, remount the ext4 file system, refresh the Linux kernel cache, and record the new hard link, the original name of the target file, the inode number of the target file, and the file type into the new mapping entry.

[0006] Furthermore, based on the target file path to be hidden, the metadata information of the target file and the directory where the target file is located is obtained, specifically including: The Virtual File System (VFS) locates the directory containing the target file based on the target file path, calls the implementation functions of the ext4 file system to read the data blocks corresponding to the directory containing the target file, traverses the directory entries in the data blocks to find the directory entry that matches the target file name, and obtains the metadata information of the target file based on the inode node number corresponding to the directory entry.

[0007] Furthermore, the new hard link is a hidden file, and the new hard link is configured to point to the inode node that stores the target file's metadata information to establish a connection between the two.

[0008] Furthermore, in step S3, while deleting the directory entry of the target file, the total number of hard links used to record all points to the inode node corresponding to the target file is not changed, so as to preserve the data of the target file.

[0009] Furthermore, step S4 is followed by: S5, mark the inode node corresponding to the target file and the actual storage area of ​​the target file data as "occupied", and back up the metadata information of the target file and the new hard link to an independent secure storage area to ensure the data integrity of the target file.

[0010] Furthermore, the method also includes file recovery, which includes the following steps: The corresponding hard link is read from the secure storage area of ​​the ext4 file system according to the target file identifier to obtain the metadata information of the target file and the directory where the target file is located; Based on the inode number in the target file's metadata, the internal mapping table is searched for a mapping entry with the same inode number. If it exists, the original name of the target file is obtained from the mapping entry, and it is determined whether the original name matches the filename of the target file to be recovered. If they match, and the target directory and original name of the target file have write permissions, the file is reconstructed through the following operations: Create a new directory entry with the original name in the target directory. Configure the directory entry to point to the inode node that stores the metadata information of the target file, so as to re-associate the file name with the inode node. Perform data integrity verification on the inode node, and update the permissions of the target file after the verification passes; Remount the file system and refresh the Linux kernel cache; Close the file system handle, delete the hard link used for recovery, and delete the corresponding mapping entry in the internal mapping table.

[0011] Furthermore, the data integrity verification includes verifying one or more of the following: verifying the core metadata structure of the file data, checking the validity of the data block pointers, verifying the matching between the file size and the actual number of blocks occupied, and scanning whether all data blocks still maintain their original physical locations. The core metadata structure includes one or more of the following: superblock, block group descriptor, inode table, and bitmap.

[0012] Furthermore, updating the target file permissions includes restoring one or more of the following: restoring the target file's owner and group information, restoring the target file's permission bits, and restoring the target file's timestamp attribute.

[0013] A file hiding system based on the ext4 file system includes a microprocessor and a memory interconnected, the microprocessor being programmed or configured to perform steps of a file hiding method based on the ext4 file system.

[0014] A computer-readable storage medium storing a computer program / instructions programmed or configured to perform steps of a file hiding method based on an ext4 file system via a processor.

[0015] Compared with the prior art, the advantages of the present invention are as follows: This invention creates a hard link associated with the inode node of the target file and then deletes the directory entry of the target file. This ensures that the corresponding inode node and its data blocks are preserved even when the directory entry is deleted, preventing data loss. This invention achieves key-free file hiding by directly manipulating the ext4 file system, completely removing the visible entry of the target file in the directory structure. This makes it impossible for conventional file operation tools (such as ls and rm) to recognize or access the hidden content, providing strong concealment. This invention achieves file hiding based on the native mechanism of the ext4 file system, without the need for encryption and decryption calculations, resulting in low resource overhead. It is suitable for embedded devices or low-power scenarios for preventing accidental deletion, temporary privacy isolation, and lightweight data protection. Attached Figure Description

[0016] Figure 1 A diagram illustrating three mainstream solutions for file hiding / recovery using existing technologies.

[0017] Figure 2 This is a flowchart of a file hiding method based on the ext4 file system according to an embodiment of the present invention.

[0018] Figure 3This is a flowchart illustrating the specific process of file hiding and recovery based on the ext4 file system in a particular application embodiment.

[0019] Figure 4 This is an example of a configuration script for file hiding based on the ext4 file system in a specific application embodiment.

[0020] Figure 5 This is a configuration script example for file recovery based on the ext4 file system in a specific application embodiment. Detailed Implementation

[0021] To better understand the above technical solutions, the following will provide a detailed explanation of the technical solutions in conjunction with the accompanying drawings and specific implementation methods.

[0022] like Figure 2 As shown, the file hiding method based on the ext4 file system in this embodiment includes the following steps: S1: Obtain the metadata information of the target file and the directory where the target file is located according to the target file path to be hidden, and allocate a new mapping entry in the internal mapping table of the ext4 file system for recording; S2, create a new hard link in the directory where the target file is located, and associate the new hard link with the inode node that stores the metadata information of the target file; S3, reopen the ext4 file system, delete the directory entry of the target file to remove the hard link between the target file and the inode node, so that the target file cannot be found in the ext4 file system; S4 remounts the ext4 file system, refreshes the Linux kernel cache, and records the new hard link, the original name of the target file, the inode number of the target file, and the file type in the new mapping entry.

[0023] It is understandable that by creating a hard link associated with the inode node of the target file and then deleting the directory entry of the target file, it can be ensured that the corresponding inode node and its data blocks are still preserved even if the directory entry is deleted, thus preventing data loss. This embodiment achieves key-free file hiding storage by directly manipulating the ext4 file system, completely removing the visible entry of the target file in the directory structure, making it impossible for conventional file operation tools to recognize or access the hidden content, thus having strong concealment. Moreover, it does not require encryption and decryption calculations, has low resource overhead, and is suitable for embedded devices or low-power scenarios for preventing accidental deletion, temporary privacy isolation, and lightweight data protection.

[0024] In this embodiment, the metadata information of the target file and the directory where the target file is located is obtained according to the target file path to be hidden, specifically including: The Virtual File System (VFS) locates the directory containing the target file based on the target file path, calls the implementation functions of the ext4 file system to read the data blocks corresponding to the directory containing the target file, traverses the directory entries in the data blocks to find the directory entry that matches the target file name, and obtains the metadata information of the target file based on the inode node number corresponding to the directory entry.

[0025] In this embodiment, the new hard link is a hidden file, and the new hard link is configured to point to the inode node that stores the metadata information of the target file to realize the association between the two.

[0026] In this embodiment, in step S3, while deleting the directory entry of the target file, the total value of all hard links pointing to the inode node corresponding to the target file is not changed, so as to preserve the data of the target file.

[0027] In this embodiment, step S4 is followed by: S5 marks the inode node corresponding to the target file and the actual storage area of ​​the target file data as "occupied", and backs up the target file's metadata information and new hard links to an independent secure storage area to ensure the data integrity of the target file.

[0028] In specific application embodiments, with Figure 3 The flowchart shown and Figure 4 The example script shown illustrates the entire process of file hiding.

[0029] The file hiding process begins after the user initiates a hiding request and submits the target file path. The system first locates the directory containing the target file through the Virtual File System (VFS) interface and parses its directory entry (dirent) structure. This process requires delving into the file system driver layer, traversing the directory's block allocation list to precisely pinpoint the target entry. Taking hiding ` / home / user / file.txt` as an example, in the ext4 file system, when a user accesses ` / home / user / file.txt`, the VFS searches for the directory's inode information level by level based on the path. After entering the ` / home / user` directory, the VFS calls ext4's implementation functions (such as `ext4_readdir`) to read the corresponding data blocks. Each data block stores several directory entries (`struct ext4_dir_entry_2`), each corresponding to a filename. The VFS traverses these directory entries sequentially, searching for an entry named `file.txt`. Once found, the inode number of the target file (let's say 112233) is obtained. The inode node stores metadata information related to the target file and the actual data storage address; the actual data block of the target file can be located through the inode node.

[0030] Before hiding file.txt, metadata information about the target file and its directory is obtained via system calls (such as stat), including the inode number and file type. This provides the foundational data for subsequent hard link operations and directory entry management. Next, a new mapping entry is allocated in the internal mapping table to record information about the hidden file (target filename, inode number storing the target file's metadata, and file type). Then, a new hidden file (i.e., a new hard link, for example, .hide_112233) is created in the target directory. This hard link is configured to point to the inode of the original target file to establish a connection between the two. This operation ensures that even if the original filename is deleted, the hard link can still link to the inode and its data blocks, preventing data loss.

[0031] After reopening the file system, a critical operation is performed: the hard link between the filename and the inode is removed, but the inode node and its corresponding data block set are fully preserved. Specifically, the underlying interface is called to delete the original directory entry (i.e., the mapping between the target file file.txt and inode 112233), but the inode's link count is not reduced. The link count records the total number of hard links pointing to that inode node. Understandably, when a deletion operation is performed directly, VFS will directly remove the directory entry for / home / user / file.txt and reduce its inode number's link count. If no process is opening the file at this time, the inode and its data blocks will be released. By not reducing the inode's link count, it is ensured that the file content is not released, guaranteeing data security.

[0032] Finally, by remounting the file system and refreshing the Linux kernel cache, the file system state is ensured to be consistent with the actual operation, and the new hard links and original file names, inodes, and other information are recorded in the internal mapping table.

[0033] To ensure the proper functioning of the system's storage space management mechanism, the status flags of the inode bitmap and data block bitmap must be updated synchronously. The actual storage areas of the inode nodes and target file data must be marked as "occupied" to prevent space overwriting during subsequent file writes. To ensure recoverability, the system backs up the original target file's dirent entry (containing key metadata such as filename, inode number, and file type) and the new hard link to a separate secure storage area. This area typically uses a log structure and includes a CRC checksum to ensure data integrity.

[0034] In this embodiment, the method further includes file recovery, which includes the following steps: The corresponding hard link is read from the secure storage area of ​​the ext4 file system according to the target file identifier to obtain the metadata information of the target file and the directory where the target file is located; Based on the inode number in the target file's metadata, the internal mapping table is searched for a mapping entry with the same inode number. If it exists, the original name of the target file is obtained from the mapping entry, and it is determined whether the original name matches the filename of the target file to be recovered. If they match, and the target directory and original name of the target file have write permissions, the file is reconstructed through the following operations: Create a new directory entry with the original name in the target directory. Configure the directory entry to point to the inode node that stores the metadata information of the target file, so as to re-associate the file name with the inode node. Perform data integrity verification on the inode node, and update the permissions of the target file after the verification passes; Remount the file system and refresh the Linux kernel cache; Close the file system handle, delete the hard link used for recovery, and delete the corresponding mapping entry in the internal mapping table.

[0035] In this embodiment, data integrity verification includes one or more of the following: verifying the file data core metadata structure, checking the validity of data block pointers, verifying the match between the file size and the actual number of blocks occupied, and scanning all data blocks to see if they still maintain their original physical locations. The core metadata structure includes one or more of the following: superblock, block group descriptor, inode table, and bitmap. Data integrity verification ensures that the file data core metadata structure remains consistent before and after hiding, and data block integrity verification ensures that the data blocks of the hidden file have not been corrupted by the hiding operation.

[0036] In this embodiment, updating the target file permissions includes restoring one or more of the following: the target file's owner (UID) and group (GID) information, restoring the target file's permission bits (including read, write, execute, and other access permissions), and restoring the target file's timestamp attributes (including creation time, access time, and modification time).

[0037] In specific application embodiments, with Figure 3 The flowchart shown and Figure 5 The example file recovery script shown illustrates the entire file recovery process.

[0038] The file recovery mechanism reconstructs file system metadata through reverse engineering. When a user selects a recovery operation, the system first reads the target file and its directory metadata information, including inode number and file type, by using a system call to read the safe area (e.g., .hide_112233) based on the target file identifier (e.g., filename or inode number).

[0039] Then, the hidden file mapping entry corresponding to the inode number of the target file is retrieved from the internal mapping table to obtain information such as the original filename, inode number, and file type of the hidden file. At this point, it is verified whether the original filename obtained from the mapping entry of inode number 112233 is consistent with the filename to be recovered. If they are inconsistent, the recovery process is exited and the message "Unable to recover" is displayed.

[0040] Next, confirm whether the target directory and filename have write permissions. If so, perform the reconstruction operation of the target file dirent entry: call the underlying file system interface to create a new directory entry in the target directory with the original filename file.txt. This directory entry points to the inode 112233 node of the hidden file, realizing the re-association of the filename and the inode node.

[0041] During the metadata reconstruction phase, the system performs deep verification of inode nodes, including checking the validity of data block pointers, verifying the match between file size and the actual number of blocks occupied, and scanning all data blocks to ensure they still maintain their original physical locations. After successful verification, the target file permissions are updated: for advanced metadata such as extended attributes and access control lists (ACLs), the system restores them item by item based on backup logs and recovers key attributes such as file owner, permission bits, and timestamps (including atime, mtime, and ctime) through kernel-level API calls.

[0042] Then, the file system is remounted, and the Linux kernel cache is flushed to ensure the file system state matches the actual operation. Finally, the file system handle is closed, the temporary hard link file used for recovery (such as .hide_112233) is deleted, and the corresponding mapping entry is removed from the internal mapping table, completing the recovery operation. Finally, by triggering the file system log write-back mechanism, all metadata changes are ensured to be persisted to the storage medium. In essence, reconstructing the dirent structure using backup information enables on-demand recovery of hidden files.

[0043] Compared with the prior art, this embodiment has the following specific advantages: By directly manipulating directory entries (dirent) in the ext4 file system, key-free file hiding is achieved, completely removing the visible entry point of the target file in the directory structure. This makes it impossible for conventional file operation tools to identify or access the hidden content, and its concealment far exceeds that of traditional attribute hiding schemes. At the same time, by using inode bitmaps and data block bitmaps to forcibly mark resource occupancy status, it ensures that the physical storage space of the hidden file will not be overwritten by new data, overcoming the data residue risk of the recycle bin deletion mechanism and ensuring the long-term integrity of the data. In addition, by backing up the metadata of deleted directory entries to an independent secure area, one-click accurate recovery without complex key management is achieved, avoiding the problem of permanent data loss caused by key loss in traditional encryption technologies. Moreover, the entire process does not require encryption and decryption calculations, with extremely low resource overhead, making it suitable for embedded devices or low-power scenarios. It shows unique advantages in the fields of preventing accidental deletion, temporary privacy isolation, and lightweight data protection.

[0044] The present invention further provides a file hiding system based on the ext4 file system, including a microprocessor and a memory interconnected, wherein the microprocessor is programmed or configured to perform the steps of the file hiding method based on the ext4 file system.

[0045] The present invention further provides a computer-readable storage medium storing a computer program / instructions, the computer program / instructions being programmed or configured to execute, via a processor, steps of a file hiding method based on the ext4 file system.

[0046] The system and medium of the present invention, corresponding to the methods described above, also have the advantages described above.

[0047] The present invention can implement all or part of the processes in the methods of the above embodiments, or it can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, it can implement the steps of the above method embodiments. The computer program includes computer program code, which can be in the form of source code, object code, executable file, or some intermediate form. Computer-readable media include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. The memory is used to store computer programs and / or modules. The processor implements various functions by running or executing the computer programs and / or modules stored in the memory, and by calling data stored in the memory. The memory may include high-speed random access memory, as well as non-volatile memory, such as hard disks, RAM, plug-in hard disks, smart media cards (SMC), secure digital (SD) cards, flash cards, at least one disk storage device, flash memory device, or other volatile solid-state storage devices.

[0048] The above description is merely a preferred embodiment of the present invention. The scope of protection of the present invention is not limited to the above embodiments. All technical solutions falling within the scope of the present invention's concept are within the scope of protection of the present invention. It should be noted that for those skilled in the art, any improvements and modifications made without departing from the principles of the present invention should also be considered within the scope of protection of the present invention.

Claims

1. A file hiding method based on the ext4 file system, characterized in that, Including the following steps: S1: Obtain the metadata information of the target file and the directory where the target file is located according to the target file path to be hidden, and allocate a new mapping entry in the internal mapping table of the ext4 file system for recording; S2, create a new hard link in the directory where the target file is located, and associate the new hard link with the inode node that stores the metadata information of the target file; S3, reopen the ext4 file system, delete the directory entry of the target file to remove the hard link between the target file and the inode node, so that the target file cannot be found in the ext4 file system; S4, remount the ext4 file system, refresh the Linux kernel cache, and record the new hard link, the original name of the target file, the inode number of the target file, and the file type into the new mapping entry.

2. The file hiding method based on the ext4 file system according to claim 1, characterized in that, Obtain the metadata information of the target file and its directory, based on the target file path to be hidden. Specifically, this includes: The Virtual File System (VFS) locates the directory containing the target file based on the target file path, calls the implementation functions of the ext4 file system to read the data blocks corresponding to the directory containing the target file, traverses the directory entries in the data blocks to find the directory entry that matches the target file name, and obtains the metadata information of the target file based on the inode node number corresponding to the directory entry.

3. The file hiding method based on the ext4 file system according to claim 1, characterized in that, The new hard link is a hidden file, and the new hard link is configured to point to the inode node that stores the target file's metadata information to establish a connection between the two.

4. The file hiding method based on the ext4 file system according to claim 1, characterized in that, In step S3, while deleting the directory entry of the target file, the total number of hard links used to record all points to the inode node corresponding to the target file is not changed, so as to preserve the data of the target file.

5. The file hiding method based on the ext4 file system according to claim 1, characterized in that, Step S4 is followed by: S5, mark the inode node corresponding to the target file and the actual storage area of ​​the target file data as "occupied", and back up the metadata information of the target file and the new hard link to an independent secure storage area to ensure the data integrity of the target file.

6. The file hiding method based on the ext4 file system according to claim 1, characterized in that, The method also includes file recovery, which includes the following steps: The corresponding hard link is read from the secure storage area of ​​the ext4 file system according to the target file identifier to obtain the metadata information of the target file and the directory where the target file is located; Based on the inode number in the target file's metadata, the internal mapping table is searched for a mapping entry with the same inode number. If it exists, the original name of the target file is obtained from the mapping entry, and it is determined whether the original name matches the filename of the target file to be recovered. If they match, and the target directory and original name of the target file have write permissions, the file is reconstructed through the following operations: Create a new directory entry with the original name in the target directory. Configure the directory entry to point to the inode node that stores the metadata information of the target file, so as to re-associate the file name with the inode node. Perform data integrity verification on the inode node, and update the permissions of the target file after the verification passes; Remount the file system and refresh the Linux kernel cache; Close the file system handle, delete the hard link used for recovery, and delete the corresponding mapping entry in the internal mapping table.

7. The file hiding method based on the ext4 file system according to claim 6, characterized in that, The data integrity verification includes: The core metadata structure of the file data is verified by checking one or more of the following: the core metadata structure includes the superblock, block group descriptor, inode table, and bitmap.

8. The file hiding method based on the ext4 file system according to claim 6, characterized in that, Updating target file permissions includes: The system restores one or more of the following: the owner and group information of the target file; the permission bits of the target file, including read, write, and execute access permissions; and the timestamp attribute of the target file.

9. A file hiding system based on the ext4 file system, comprising a microprocessor and a memory interconnected, characterized in that, The microprocessor is programmed or configured to perform the steps of the file hiding method based on the ext4 file system as described in any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program / instructions, characterized in that, The computer program / instructions are programmed or configured to execute the steps of the file hiding method based on the ext4 file system as described in any one of claims 1 to 8 via a processor.

Citation Information

Cited By

  • Semantic traceability inert recovery method for orphan files of distributed file system

    CN122308753A

  • A distributed file system orphan file semantic provenance lazy recovery method

    CN122308753B