Sandbox storage space expansion method and device, electronic equipment and storage medium
By unmounting and mounting non-Linux partitions as target partitions in embedded systems and IoT devices, the problem of insufficient sandbox storage space is solved, ensuring the stable operation of the devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU EZVIZ SOFTWARE CO LTD
- Filing Date
- 2025-12-23
- Publication Date
- 2026-04-21
AI Technical Summary
In embedded systems and IoT devices, the sharing of Linux partitions between sandboxes and Linux system programs can lead to insufficient storage space, affecting the stable operation of the devices.
By unmounting a specified directory under the sandbox root directory, mounting a non-Linux partition as the target partition, and switching the root directory, the sandbox storage space is expanded to the non-Linux partition.
Effectively free up Linux partition storage space, ensure stable device operation, and avoid write failures and system instability.
Smart Images

Figure CN121900693A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, electronic device and storage medium for expanding sandbox storage space. Background Technology
[0002] In embedded systems, IoT devices, or resource-constrained Linux environments, sandbox systems are typically deployed on Linux partitions (i.e., storage partitions that use the Linux file system format). These Linux partitions support full Linux features (such as symbolic links and access control) and can meet the runtime requirements of the sandbox.
[0003] However, in real-world applications, electronic devices running sandboxes often employ a hybrid storage architecture, dividing the hard drive into a smaller Linux partition and a larger non-Linux partition (i.e., a partition with a non-Linux file system format, which may contain multiple storage partitions). The Linux partition is used by Linux system programs and the sandbox root file system (the core component of the sandbox (the carrier at the file system level)); the non-Linux partition is used for cross-platform compatibility, such as sharing data between Linux and Windows systems.
[0004] In this application scenario, the sandbox and the Linux system program share the Linux partition. As the data of the application in the sandbox grows (such as data growth caused by large file downloads, log storage, etc.), the storage space of the Linux partition may become insufficient, which may eventually affect the stable operation of the Linux partition of the electronic device, such as causing write failures, process crashes, or system instability. Summary of the Invention
[0005] The purpose of this application is to provide a sandbox storage space expansion method, apparatus, electronic device, and storage medium to ensure the stable operation of the Linux partition of the electronic device. The specific technical solution is as follows:
[0006] In a first aspect, embodiments of this application provide a method for expanding sandbox storage space, the method comprising:
[0007] In response to the fact that the percentage of remaining space of the Linux partition in the electronic device is lower than a first predetermined threshold, a target partition of the electronic device is determined; wherein, the target partition is a storage partition other than the Linux partition;
[0008] The specified directory, which serves as the mount point, under the root directory of the sandbox, is unloaded; wherein, the unloading process is used to unload the currently mounted content of the specified directory;
[0009] In response to the completion of the uninstallation process, the target partition is mounted to the specified directory to obtain the current specified directory;
[0010] Based on the root directory containing the current specified directory, the root directory of the sandbox is switched so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the target partition.
[0011] Optionally, determining the target partition of the electronic device includes:
[0012] For each storage partition existing in the electronic device, at least one candidate storage partition other than the Linux partition is determined based on the file system type supported by each storage partition.
[0013] From the at least one candidate storage partition, select a storage partition whose available storage space meets predetermined conditions; wherein, the predetermined conditions include: the proportion of available storage space is greater than a second predetermined threshold, or the available storage space is the largest, or it belongs to a pre-set storage partition;
[0014] Based on the permission information configured for the selected storage partition, it is determined whether the sandbox has read and write permissions for the selected storage partition.
[0015] In response to having read and write permissions, the selected storage partition is designated as the target partition;
[0016] In response to not having read / write permissions, for the at least one candidate storage partition, excluding the previously selected storage partition, a storage partition whose available storage space meets predetermined conditions is selected, and the step of identifying whether the sandbox has read / write permissions for the selected storage partition based on the permission information configured for the selected storage partition is returned.
[0017] Optionally, the root directory switching process for the sandbox based on the root directory containing the current specified directory includes:
[0018] Copy the root directory containing the current specified directory to the temporary storage space allocated for the sandbox;
[0019] The root directory of the sandbox is switched to the root directory within the temporary storage space via a predefined system call interface provided by the Linux kernel, and the root directory containing the specified directory before the uninstallation process is unloaded.
[0020] Optionally, before determining the target partition of the electronic device in response to the fact that the percentage of remaining space of the Linux partition in the electronic device is lower than a first predetermined threshold, the method further includes:
[0021] In response to the fulfillment of the first detection condition, the remaining space percentage of the Linux partition in the electronic device is determined, and it is identified whether the space percentage is lower than the first predetermined threshold.
[0022] The first detection condition includes: detecting a predetermined write event to the Linux partition, or reaching a preset periodic detection time; the method of detecting a predetermined write event to the Linux partition includes: in response to receiving a notification pushed by a predetermined kernel event regarding the detection of a predetermined write event to the Linux partition, determining that a predetermined write event has occurred to the Linux partition.
[0023] Optionally, the unloading process of the specified directory under the root directory of the sandbox, which serves as the mount point, includes:
[0024] The first command is invoked to unload the specified directory, which is the mount point, under the root directory of the sandbox; wherein, the first command is a command used to perform delayed unloading of the file system;
[0025] And / or,
[0026] Upon completion of the unloading process, the target partition is mounted to the specified directory to obtain the current specified directory, including:
[0027] In response to the completion of the uninstallation process, the second command is invoked using the access identifier information of the specified directory and the target partition as input parameters to mount the target partition to the specified directory, thereby obtaining the current specified directory; wherein, the second command is a command to mount the content of the directory used as the mount point.
[0028] Optionally, after performing the sandbox root directory switching process based on the root directory containing the current specified directory, the method further includes:
[0029] In response to the fulfillment of the second detection condition, it is detected whether the target partition meets the predetermined switching condition;
[0030] In response to the target partition meeting predetermined switching conditions, a backup partition for the electronic device is determined; wherein, the backup partition is: a storage partition other than the Linux partition, which the sandbox has read and write permissions for and has available storage space;
[0031] Perform an uninstallation process on the currently specified directory;
[0032] In response to the completion of the uninstallation process, the spare partition is mounted to the specified directory to obtain the current specified directory;
[0033] Based on the root directory containing the current specified directory, the root directory of the sandbox is switched so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the spare partition.
[0034] The second detection condition includes: detecting a predetermined write event to the target partition, or reaching a preset periodic detection time; the method of detecting a predetermined write event to the target partition includes: in response to receiving a notification pushed by a predetermined kernel event regarding the detection of a predetermined write event to the target partition, determining that a predetermined write event has occurred to the target partition.
[0035] Optionally, after performing the sandbox root directory switching process based on the root directory containing the current specified directory, the method further includes:
[0036] In response to the fact that the remaining space percentage of the Linux partition is higher than a third predetermined threshold, a storage partition with available storage space in the Linux partition is identified as the partition to be mounted.
[0037] Perform an uninstallation process on the currently specified directory;
[0038] In response to the completion of the uninstallation process, the partition to be mounted is mounted to the specified directory, thus obtaining the current specified directory;
[0039] Based on the root directory containing the current specified directory, the root directory of the sandbox is switched so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the partition to be mounted.
[0040] Optionally, the method further includes:
[0041] After performing a root directory switch for any sandbox, an access policy configuration is executed on the storage partition currently mounted to the specified directory; wherein, the access policy configuration is to set a condition that disallows the program from running.
[0042] Secondly, embodiments of this application provide a sandbox storage space expansion device, the device comprising:
[0043] A determination module is configured to determine a target partition of the electronic device in response to a situation where the percentage of remaining space of a Linux partition in the electronic device is lower than a first predetermined threshold; wherein the target partition is a storage partition other than the Linux partition.
[0044] The uninstallation module is used to uninstall a specified directory under the root directory of the sandbox, which serves as the mount point; wherein, the uninstallation process is used to uninstall the content currently mounted in the specified directory;
[0045] The mounting module is used to mount the target partition to the specified directory in response to the completion of the unloading process, thereby obtaining the current specified directory.
[0046] The first switching module is used to perform a sandbox root directory switching process based on the root directory containing the current specified directory, so that the root directory containing the current specified directory becomes the root directory of the sandbox, and after the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the target partition.
[0047] Thirdly, embodiments of this application provide an electronic device, including:
[0048] Memory, used to store computer programs;
[0049] The processor, when executing a program stored in memory, implements any of the described sandbox storage space expansion methods.
[0050] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the aforementioned sandbox storage space expansion methods.
[0051] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to execute any of the sandbox storage space expansion methods described above.
[0052] Beneficial effects of the embodiments in this application:
[0053] The sandbox storage space expansion method provided in this application can determine a target partition other than the Linux partition when the remaining space ratio of the Linux partition in the electronic device is lower than a first predetermined threshold. Since the remaining space of the Linux partition is insufficient, this application unloads the specified directory under the root directory of the sandbox, which serves as the mount point; that is, it unloads the contents of the Linux partition currently mounted in the specified directory. After the unloading process is completed, the target partition is mounted to the specified directory, resulting in the current specified directory. Furthermore, based on the root directory containing the current specified directory, a root directory switch process is performed on the sandbox, so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory switch process, target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the target partition. Therefore, this application can expand the storage space used by the sandbox to a target partition other than the Linux partition. Compared with the method of occupying the storage space of the Linux partition in related technologies, this method can free up the storage space of the Linux partition, thereby ensuring the stable operation of the Linux partition of the electronic device.
[0054] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0055] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0056] Figure 1 A flowchart illustrating a sandbox storage space expansion method provided in an embodiment of this application;
[0057] Figure 2 This is another flowchart illustrating a sandbox storage space expansion method provided in an embodiment of this application;
[0058] Figure 3 Another flowchart illustrating a sandbox storage space expansion method provided in this application embodiment;
[0059] Figure 4 Another flowchart illustrating a sandbox storage space expansion method provided in this application embodiment;
[0060] Figure 5 A schematic diagram of a sandbox storage space expansion device provided in an embodiment of this application;
[0061] Figure 6 This is a block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0062] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0063] In embedded systems, IoT devices, or resource-constrained Linux environments, sandboxes are typically deployed on Linux partitions (such as partitions containing ext4 (Fourth Extended File System), xfs (XFS File System), etc.). The Linux partitions support full Linux features and can meet the needs of the sandbox runtime.
[0064] However, in real-world applications, electronic devices running sandboxes often employ a hybrid storage architecture, dividing the hard drive into a smaller Linux partition and a larger non-Linux partition. For example, the larger non-Linux partition can be a partition that supports formats such as FAT32 (File Allocation Table 32), NTFS (New Technology File System), or exFAT (Extended File Allocation Table).
[0065] In this application scenario, Linux partition storage space is limited. The sandbox shares the Linux partition with the Linux system programs. As the data of applications within the sandbox grows, the storage space on the Linux partition may become insufficient, potentially affecting the stable operation of the electronic device's Linux partition. This could lead to write failures, process crashes, or system instability. For example, a sandbox might contain directories such as bin (Binary), dev (Device), lib (Library), proc (Process), run (Running data), sys (System), usr (Unix System Resources), and mnt (Mount).
[0066] Furthermore, while non-Linux partitions (such as FAT32 partitions) offer large capacities, they lack support for Linux features (e.g., they do not support symbolic links or fine-grained file permission control), making them unsuitable as direct carriers for the sandbox root file system. Related technologies typically rely on static partition resizing (manually adjusting the size of Linux and non-Linux partitions to increase the storage space of the Linux partition) or manual data migration (manually migrating data from the Linux partition to the non-Linux partition, such as large files or logs). However, these methods lack dynamism and interrupt the sandbox's operation, failing to meet the demands of high-availability scenarios.
[0067] Based on this, embodiments of this application provide a sandbox storage space expansion method, apparatus, electronic device, and storage medium to ensure the stable operation of the Linux partition of the electronic device.
[0068] The following section first introduces a sandbox storage space expansion method provided in the embodiments of this application.
[0069] The sandbox storage space expansion method provided in this application can be applied to electronic devices running sandboxes. These electronic devices can be terminal devices such as mobile phones and computers, or servers. This application does not limit the specific form of the electronic device. The sandbox storage space expansion method provided in this application can be applied to scenarios where a sandbox is running, specifically scenarios where the sandbox is running on a Linux partition and the Linux partition's storage space is insufficient.
[0070] In addition, the execution subject of the sandbox storage space expansion method provided in this application embodiment can be a sandbox management module. The sandbox management module can be set on the same electronic device as the sandbox. For example, the sandbox management module can be a sandbox management program running in the electronic device.
[0071] This application provides a method for expanding sandbox storage space, which may include the following steps:
[0072] In response to the fact that the percentage of remaining space of the Linux partition in the electronic device is lower than a first predetermined threshold, a target partition of the electronic device is determined; wherein, the target partition is a storage partition other than the Linux partition;
[0073] The specified directory, which serves as the mount point, under the root directory of the sandbox, is unloaded; wherein, the unloading process is used to unload the currently mounted content of the specified directory;
[0074] In response to the completion of the uninstallation process, the target partition is mounted to the specified directory to obtain the current specified directory;
[0075] Based on the root directory containing the current specified directory, the root directory of the sandbox is switched so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the target partition.
[0076] The sandbox storage space expansion method provided in this application can determine a target partition other than the Linux partition when the remaining space ratio of the Linux partition in the electronic device is lower than a first predetermined threshold. Since the remaining space of the Linux partition is insufficient, this application unloads the specified directory under the root directory of the sandbox, which serves as the mount point; that is, it unloads the contents of the Linux partition currently mounted in the specified directory. After the unloading process is completed, the target partition is mounted to the specified directory, resulting in the current specified directory. Furthermore, based on the root directory containing the current specified directory, a root directory switch process is performed on the sandbox, so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory switch process, target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the target partition. Therefore, this application can expand the storage space used by the sandbox to a target partition other than the Linux partition. Compared with the method of occupying the storage space of the Linux partition in related technologies, this method can free up the storage space of the Linux partition, thereby ensuring the stable operation of the Linux partition of the electronic device.
[0077] The following description, in conjunction with the accompanying drawings, provides an exemplary method for expanding sandbox storage space according to an embodiment of this application.
[0078] like Figure 1 As shown in the embodiments of this application, a sandbox storage space expansion method may include the following steps:
[0079] S101: In response to the fact that the percentage of remaining space of the Linux partition in the electronic device is lower than a first predetermined threshold, the target partition of the electronic device is determined.
[0080] The target partition is a storage partition other than the Linux partition;
[0081] In this application, when the Linux partition lacks sufficient space, the storage space used by the sandbox is expanded to a partition outside the Linux partition, such as a space area in a non-Linux partition. Based on this expansion approach, if the percentage of remaining space in the Linux partition of the electronic device is lower than a first predetermined threshold, the sandbox management module can determine a target partition outside the Linux partition in the electronic device to ensure the stable operation of the Linux partition. Specifically, if the percentage of remaining space in the Linux partition of the electronic device is lower than the first predetermined threshold, it indicates that the Linux partition's storage space is insufficient. The sandbox management module first determines the target partition to be expanded for subsequent expansion. The percentage of remaining space is defined as the ratio of the remaining space capacity in the Linux partition to the total capacity of the Linux partition. The specific value of the first predetermined threshold can be set according to actual conditions, and this application does not limit it. For example, the first predetermined threshold can be 15%, and correspondingly, the percentage of remaining space being lower than the first predetermined threshold means that the ratio of the remaining space capacity in the Linux partition to the total capacity of the Linux partition is lower than 15%.
[0082] It should be noted that electronic devices can be connected to external storage devices or internal hard drives. Both external storage devices and hard drives constitute the storage space of the electronic device. The overall storage space of the electronic device (including the storage space of external storage devices and internal hard drives) can include Linux partitions and partitions other than Linux partitions (such as non-Linux partitions). A Linux partition can contain multiple storage partitions, and a non-Linux partition can contain multiple storage partitions. The target partition can be understood as a storage partition within a non-Linux partition. Furthermore, the target partition can belong to an external storage device or an internal hard drive; this application does not limit this. Additionally, both external storage devices and hard drives can contain storage partitions within Linux partitions and / or storage partitions within non-Linux partitions. The number of external storage devices and hard drives can be one or more; this application does not limit this.
[0083] For example, in one implementation, before determining the target partition of the electronic device in response to a percentage of the remaining space of the Linux partition in the electronic device being lower than a first predetermined threshold, the method further includes:
[0084] In response to the fulfillment of the first detection condition, the remaining space percentage of the Linux partition in the electronic device is determined, and it is identified whether the space percentage is lower than the first predetermined threshold.
[0085] The first detection condition includes: detecting a predetermined write event to the Linux partition, or reaching a preset periodic detection time; the method of detecting a predetermined write event to the Linux partition includes: in response to receiving a notification pushed by a predetermined kernel event regarding the detection of a predetermined write event to the Linux partition, determining that a predetermined write event has occurred to the Linux partition.
[0086] The sandbox management module can also determine the current remaining space ratio of the Linux partition in the electronic device when the first detection condition is met, and identify whether the space ratio is lower than a first predetermined threshold. That is, when the first detection condition is met, it determines whether the storage space of the Linux partition in the electronic device is insufficient. The first detection condition may include: detecting a predetermined write event to the Linux partition, or reaching a predetermined periodic detection time. In this way, the step of determining the current remaining space ratio of the Linux partition in the electronic device and identifying whether the space ratio is lower than the first predetermined threshold can be triggered in a timely manner. That is, when the first detection condition is met, the sandbox management module can determine in a timely manner whether the storage space of the Linux partition in the electronic device is insufficient, so as to expand the storage space used by the sandbox in a timely manner through the solution of this application and ensure the stable operation of the Linux partition.
[0087] The sandbox management module can detect Linux partitions through pre-defined kernel events (detecting file / directory creation, modification, deletion, permission changes, etc.). When a pre-defined kernel event is detected, it pushes a notification to the sandbox management module. Upon receiving this notification, the sandbox management module determines that a pre-defined write event has occurred on the Linux partition. For example, the pre-defined kernel event can be an inotify kernel event, and the pre-defined write event can be an event that writes a file to the Linux partition. Inotify is a file system event monitoring mechanism provided by the Linux kernel, used to monitor various changes to files / directories (such as creation, deletion, modification, and movement), replacing the older dnotify mechanism. It is a core technology for user-space programs (such as file managers) to implement file monitoring. Furthermore, the size of the file written by the scheduled write event can also be detected through the scheduled kernel event. Considering that the scheduled kernel event can also detect the size of the file written by the scheduled write event, the size of the written file can be included in the specific content of the first detection condition. For example, the first detection condition may include: detecting that a scheduled write event has occurred on the Linux partition, and the size of the file written by the scheduled write event is greater than a scheduled file size threshold (e.g., 1GB). For example, whenever a file is written to the Linux partition, the scheduled kernel event can detect the occurrence of the scheduled write event and push a notification (which may carry the size of the written file) to the business layer (e.g., the sandbox management module). The business layer can accumulate the total file size of multiple scheduled write events, and determine that the first detection condition is met when the total file size is greater than the scheduled file size threshold.
[0088] The preset periodic detection times can be pre-set or flexibly adjusted according to the actual situation. For example, the time difference between two adjacent periodic detection times can be 1-5 seconds, etc. This application does not limit this.
[0089] Optionally, in one implementation, if the first detection condition is met, the sandbox management module can determine the current remaining space percentage of the Linux partition in the electronic device using a predefined scan command. For example, the predefined scan command can be the `df` (disk free) command, a user-space command used to display the disk space usage of the file system. After determining the current remaining space percentage of the Linux partition, it can be identified whether this percentage is lower than a first predefined threshold. If it is lower, for example, if the space percentage is 10% and the first predefined threshold is 15%, it indicates that the Linux partition has insufficient storage space, and a target partition needs to be identified.
[0090] For example, in one implementation, determining the target partition of the electronic device includes:
[0091] For each storage partition in an electronic device, at least one candidate storage partition other than the Linux partition is determined based on the file system type supported by each storage partition.
[0092] From at least one candidate storage partition, select a storage partition whose available storage space meets predetermined conditions; wherein the predetermined conditions include: the proportion of available storage space is greater than a second predetermined threshold, or the available storage space is the largest, or it belongs to a pre-defined storage partition.
[0093] Based on the permission information configured for the selected storage partition, identify whether the sandbox has read and write permissions for the selected storage partition.
[0094] In response to having read and write permissions, the selected storage partition is designated as the target partition;
[0095] In response to not having read / write permissions, for at least one candidate storage partition, excluding the previously selected storage partition, a storage partition whose available storage space meets predetermined conditions is selected, and the steps of identifying whether the sandbox has read / write permissions for the selected storage partition based on the permission information configured for the selected storage partition are returned.
[0096] When determining the target partition, considering that the file system type supported by the storage partition can indicate whether the storage partition is a partition other than Linux (i.e., the file system type supported by the storage partition can indicate whether the storage partition belongs to Linux or not), firstly, the sandbox management module can determine at least one candidate storage partition other than Linux partitions for each storage partition existing in the electronic device, based on the file system type supported by each storage partition; then, it can select a storage partition whose available storage space meets predetermined conditions from at least one candidate storage partition, so as to adapt to the sandbox's storage space requirements in the future; in addition, the target partition needs to have Read and write permissions (at least write permissions are required for subsequent storage of target files) are necessary so that target files generated during sandbox operation can be stored in the target partition after storage space is expanded. Therefore, based on the permission information configured for the selected storage partition, it can be determined whether the sandbox has read and write permissions for the selected storage partition. If it has read and write permissions, the selected storage partition can be directly designated as the target partition. If it does not have read and write permissions, it is necessary to reselect a storage partition with available storage space that meets the predetermined conditions from at least one candidate partition, excluding the storage partitions that have already been selected, and re-identify whether the sandbox has read and write permissions for that storage partition.
[0097] The sandbox management module can query the file system types supported by each existing storage partition using query commands or a pre-defined data table of file system types. Then, based on the supported file system types of each storage partition, it determines whether each partition supports Linux. In other words, for each storage partition, it determines whether it is a Linux partition or a non-Linux partition based on the file system types it supports, thus identifying at least one candidate storage partition other than Linux partitions. The sandbox management module can scan for existing storage partitions in the electronic device through block device interfaces, such as / dev / sd or / dev / mmcblk.
[0098] In addition, the sandbox management module can also determine whether each candidate storage partition is available (i.e., whether the candidate storage partition is damaged). Specifically, it can determine whether the candidate storage partition is available by reading the metadata of the candidate storage partition; and select a storage partition that meets the predetermined conditions from the available at least one candidate storage partition.
[0099] It should be noted that the predefined conditions can be understood as conditions that can meet the storage space requirements of the specified directory in the sandbox. Predefined conditions may include: the percentage of available storage space is greater than a second predefined threshold (e.g., 50%), or the available storage space is at its maximum, or it belongs to a pre-defined storage partition. Among these, the percentage of available storage space being greater than the second predefined threshold or the available storage space being at its maximum indicates that the storage partition has sufficient storage space and can meet the storage space requirements of the specified directory in the sandbox. In addition, users can pre-define some storage partitions, all of which can meet the storage space requirements of the specified directory in the sandbox. For example, the pre-defined storage partitions can be external storage devices connected by the user, and the total storage space of the external storage devices is greater than 256GB.
[0100] As can be seen, in this application, for each storage partition existing in the electronic device, at least one candidate storage partition other than the Linux partition is first determined, and a storage partition whose available storage space meets the predetermined conditions is selected. If the sandbox has read and write permissions for the storage partition, then the storage partition is determined as the target partition. If not, then a storage partition is reselected from the other storage partitions in the at least one candidate storage partition, and read and write permission analysis is performed again. In this way, the selected target partition is a storage partition other than the Linux partition, and the available storage space of the target partition meets the predetermined conditions, and the sandbox has read and write permissions for the target partition, so that after the storage space is expanded, the target files generated during the operation of the sandbox that need to be stored in the specified directory are stored in the target partition whose storage space meets the predetermined conditions.
[0101] S102: Unload the specified directory in the root directory of the sandbox that serves as the mount point;
[0102] The uninstallation process is used to uninstall the contents currently mounted in the specified directory;
[0103] After determining the target partition, in order to expand the storage space used by the specified directory, which serves as the mount point under the sandbox's root directory, the specified target can first be unmounted, i.e., the content currently mounted in the specified directory can be a storage partition within a Linux partition.
[0104] It should be noted that the specified directory is the root directory of the sandbox, which is set as a mount point and can mount a storage partition. Files that need to be stored in the specified directory can be stored in the storage partition mounted by the specified directory. Furthermore, the specified directory can be understood as a directory unrelated to the operation of the sandbox. The specified directory can utilize the storage partition of the Linux partition or a non-Linux partition for large file downloads, log storage, etc. Other directories besides the specified directory are directories related to the operation of the sandbox. Programs in other directories need to run on the storage partition of the Linux partition so that the sandbox can function properly. The specified directory can be preset during sandbox initialization, for example, by setting the mnt directory (or data directory) as the specified directory; or, operations such as deleting or adding specified directories can be performed, for example, creating a new directory and setting it as a mount point, then that directory can be used as a new specified directory. The number of specified directories can be one or more, and this application does not limit this.
[0105] For example, in one implementation, unloading a specified directory under the root directory of the sandbox, which serves as the mount point, includes:
[0106] The first command is invoked to unload the specified directory, which is the mount point, under the root directory of the sandbox; the first command is used to perform delayed unloading of the file system.
[0107] The sandbox management module can unload a specified directory by calling the first command. For example, by taking the specified directory as input information, the first command can be called to unload the content currently mounted in the specified directory. After the unloading process, the specified directory will be empty.
[0108] For example, the first command could be `umount --lazy` (delayed unmount command). Before calling the first command, you can stop any currently running programs related to the specified directory (e.g., stop downloading large files or storing log data). Then, the first command is called to unmount the specified directory. After unmounting, the specified directory is remounted, thus mounting the target partition to that directory. Furthermore, after a subsequent root directory switch within the sandbox, the program can be re-executed (e.g., re-downloading large files or re-storing log data) to prevent data loss or program failure.
[0109] In this application, the sandbox management module can first stop the program currently executing in the specified directory, then unload the specified directory by calling the first command, and mount the target partition to the specified directory; and after the subsequent root directory switching process, the program can be re-executed; this can prevent the program executing in the specified directory from not executing or data from being lost; and the process of remounting and root directory switching usually does not interrupt the overall operation of the sandbox, which can meet the needs of high availability scenarios.
[0110] S103: In response to the completion of the unloading process, mount the target partition to the specified directory and obtain the current specified directory;
[0111] After the uninstallation process is complete, in order to extend the storage space used by the specified directory to a non-Linux partition and ensure the stable operation of the Linux partition, the target partition can be mounted to the specified directory, resulting in the current specified directory. The content mounted in the current specified directory is the target partition.
[0112] For example, in one implementation, in response to the completion of the unmounting process, the target partition is mounted to a specified directory to obtain the current specified directory, including:
[0113] In response to the completion of the unloading process, the second command is invoked with the access identifier information of the specified directory and the target partition as input parameters to mount the target partition to the specified directory, thus obtaining the current specified directory; the second command is the command to mount the content of the directory used as the mount point.
[0114] After the unloading process is complete, in order to mount the target partition to the specified directory, the specified directory and the access identifier information of the target partition can be used as input parameters to call the second command, thereby mounting the target partition to the specified directory and obtaining the current specified directory.
[0115] The second command is for mounting content to the directory at the mount point. In other words, it can be understood as a bind mount command, capable of mounting a partition to the directory used as the mount point. For example, the second command can be `mount-bind-R` (i.e., a recursive bind mount command; `mount` means mount; `bind` means bind or bind mount; `R` is equivalent to Recursive Bind, indicating recursive binding). This command takes the name of the specified directory (e.g., the `mnt` directory) and the access identifier information of the target partition as input parameters, and mounts the target partition to the specified directory. The current specified directory is now mounted with the target partition. This ensures that after a root directory switch, target files generated during sandbox operation that need to be stored in the current specified directory can be stored in the target partition, thus ensuring the stable operation of the Linux partition.
[0116] S104: Based on the root directory containing the current specified directory, perform a root directory switching process for the sandbox, so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the target partition.
[0117] After mounting the target partition to the specified directory, the root directory of the sandbox needs to be switched. This means replacing the root directory of the sandbox with the root directory of the target partition mounted in the specified directory. After the root directory of the sandbox is switched, access to the specified directory of the sandbox is mapped to the target partition. Target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the target partition.
[0118] For example, in one implementation, the root directory switching process for the sandbox is performed based on the root directory containing the current specified directory, including:
[0119] Copy the root directory containing the current specified directory to the temporary storage space allocated for the sandbox;
[0120] The root directory of the sandbox is switched to the root directory in the temporary storage space through the predefined system call interface provided by the Linux kernel, and the root directory containing the specified directory before the uninstallation process is unloaded.
[0121] When performing root directory switching for the sandbox, the root directory containing the current specified directory (i.e., the root directory of the specified directory that mounts the target partition) is copied to the temporary storage space allocated for the sandbox. Then, through the predefined system call interface provided by the Linux kernel, the root directory of the sandbox is switched to the root directory in the temporary storage space. Finally, the root directory containing the specified directory before the unloading process (i.e., the root directory of the storage partition where the specified directory mounts the Linux partition) is unloaded, thus achieving the root directory switch.
[0122] It should be noted that the temporary storage space can be allocated by the Linux system program for the sandbox. For example, the access identifier information of this temporary storage space could be ` / opt / sandbox / new_root`. Based on this access identifier information, the root directory containing the currently specified directory can be copied to this temporary storage space. The scheduled system call interface is used to switch the root file system (root directory), enabling the current process's root directory to be switched to a new root directory. For example, the scheduled system call interface could be the `pivot_root` system call interface (i.e., the root file system switching call interface). The `pivot_root` system call interface is neither an independent algorithm nor an application-layer tool, but rather a low-level interface exposed by the kernel to user-space programs, allowing user-space programs (such as container engines and embedded system initialization scripts) to modify the process's root file system, achieving root file system isolation or switching.
[0123] In this application, the root directory containing the current specified directory can be copied to a temporary storage space. Then, through a predefined system call interface provided by the Linux kernel, the root directory of the sandbox can be switched to the root directory within the temporary storage space. This maps access to the specified directory to the target partition on a non-Linux partition, ensuring the stable operation of the Linux partition. Furthermore, to avoid dependencies on the original root directory and further isolate it from the original root directory, the root directory containing the specified directory before the uninstallation process can be unloaded.
[0124] In the technical solution of this application, all operations such as obtaining, storing, using, processing, transmitting, providing and disclosing space ratios, specified directories, target partitions, root directories, etc., are carried out with the user's authorization.
[0125] The sandbox storage space expansion method provided in this application can determine a target partition other than the Linux partition when the remaining space ratio of the Linux partition in the electronic device is lower than a first predetermined threshold. Since the remaining space of the Linux partition is insufficient, this application unloads the specified directory under the root directory of the sandbox, which serves as the mount point; that is, it unloads the contents of the Linux partition currently mounted in the specified directory. After the unloading process is completed, the target partition is mounted to the specified directory, resulting in the current specified directory. Furthermore, based on the root directory containing the current specified directory, a root directory switch process is performed on the sandbox, so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory switch process, target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the target partition. Therefore, this application can expand the storage space used by the sandbox to a target partition other than the Linux partition. Compared with the method of occupying the storage space of the Linux partition in related technologies, this method can free up the storage space of the Linux partition, thereby ensuring the stable operation of the Linux partition of the electronic device.
[0126] Alternatively, in another embodiment of this application, such as Figure 2 As shown, after performing sandbox root directory switching based on the root directory containing the current specified directory, the method further includes:
[0127] S201: In response to the fulfillment of the second detection condition, detect whether the target partition meets the predetermined switching condition;
[0128] S202: In response to the target partition meeting the predetermined switching conditions, determine the backup partition for the electronic device;
[0129] The spare partition is a storage partition other than the Linux partition, which is a sandbox with read and write permissions and available storage space.
[0130] S203: Unload the currently specified directory;
[0131] S204: In response to the completion of the unloading process, mount the spare partition to the specified directory to obtain the current specified directory;
[0132] S205: Based on the root directory containing the current specified directory, perform a root directory switching process for the sandbox, so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the spare partition.
[0133] The second detection condition includes: detecting a predetermined write event to the target partition, or reaching a preset periodic detection time; the method of detecting a predetermined write event to the target partition includes: in response to receiving a notification pushed by a predetermined kernel event regarding the detection of a predetermined write event to the target partition, determining that a predetermined write event has occurred to the target partition.
[0134] In some cases, after mounting the target partition to a specified directory and performing a root directory switch for the sandbox, that is, after expanding the storage space used by the specified directory of the sandbox to the target partition in the non-Linux partition, the storage space of the target partition may become insufficient as the sandbox runs. The sandbox management module can also promptly expand the storage space used by the specified directory of the sandbox to a spare partition in the non-Linux partition to ensure the stable operation of the Linux partition of the electronic device.
[0135] If the second detection condition is met, the target partition can be checked first to see if it meets the predetermined switching conditions. The predetermined switching conditions can be understood as conditions that prevent the sandbox from operating stably, such as insufficient storage space of the target partition or a decline in I / O load performance. If the target partition meets the predetermined switching conditions, it indicates that the target partition currently mounted on the specified directory needs to be switched to another partition. At this time, the spare partition of the electronic device can be determined first. The spare partition is a storage partition other than the Linux partition that the sandbox has read and write permissions for and has available storage space. The method for determining the spare partition can be similar to the method for determining the target partition (the difference is that the target partition is determined when the storage space of the Linux partition is insufficient, while the spare partition is determined when the storage space of the target partition is insufficient), which will not be elaborated here.
[0136] Afterwards, similar processing to steps S102-S104 can be performed (i.e., steps S203-S205 can be similar to steps S102-S104), unmounting the target partition mounted on the specified directory and mounting the spare partition to the specified directory, and switching the root directory of the sandbox to the root directory containing the specified directory with the spare partition mounted, so that the target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the spare partition; that is, access to the specified directory is mapped to the spare partition.
[0137] The second detection condition can be similar to the first detection condition. The difference is that the detection of the predetermined write event in the first detection condition is for the entire Linux partition, while the detection of the predetermined write event in the second detection condition is for the target partition. Furthermore, the detection methods are also similar, both of which can be determined by the notification pushed by the predetermined kernel event.
[0138] It should be noted that the available storage space of the backup partition can be greater than the available storage space of the target partition. This means that the specified target can be expanded to a backup partition with a larger available storage space, thus ensuring the stable operation of the Linux partition on the electronic device.
[0139] As can be seen, in this application, the sandbox management module can also detect whether the storage space of the target partition is insufficient if the second detection condition is met. If it is insufficient, the storage space used by the specified directory can be extended to the spare partition in the non-Linux partition to further ensure the stable operation of the Linux partition of the electronic device.
[0140] Alternatively, in another embodiment of this application, such as Figure 3 As shown, after performing sandbox root directory switching based on the root directory containing the current specified directory, the method further includes:
[0141] S301: In response to the fact that the remaining space of the Linux partition is higher than the third predetermined threshold, a storage partition with available storage space in the Linux partition is identified as the partition to be mounted.
[0142] S302: Unload the currently specified directory;
[0143] S303: In response to the completion of the unloading process, mount the partition to be mounted to the specified directory and obtain the current specified directory;
[0144] S304: Based on the root directory containing the current specified directory, perform a root directory switching process for the sandbox, so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the partition to be mounted.
[0145] In other scenarios, when electronic devices have finished using the Linux partition and the available storage space of the Linux partition can be restored to sufficient capacity, the sandbox management module can also remap the storage space used by the specified directory back to the Linux partition. This allows resources of non-Linux partitions (specifically, the target partition or a spare partition) to be released while ensuring the stable operation of the Linux partition.
[0146] If the remaining space of the Linux partition is higher than the third predetermined threshold, meaning the Linux partition has sufficient remaining space, a storage partition with available storage space (the sandbox can also have read and write permissions for this storage partition) can be identified as the partition to be mounted. After identifying the partition to be mounted, a process similar to steps S102-S104 can be performed (i.e., steps S302-S304 can be similar to steps S102-S104): the target partition (or spare partition) mounted in the specified directory is unmounted, and the partition to be mounted is mounted to the specified directory. Additionally, the root directory of the sandbox is switched to the root directory containing the specified directory with the partition to be mounted. Thus, target files generated during sandbox operation that need to be stored in the current specified directory are stored in the partition to be mounted; that is, access to the specified directory is mapped to the partition to be mounted.
[0147] In addition, prior to step S301, if the third detection condition is met, the current remaining space percentage of the Linux partition in the electronic device can be determined, and it can be identified whether this space percentage is higher than a third predetermined threshold (e.g., 50%). The third detection condition may include: detecting a predetermined space release event for the Linux partition, or reaching a preset periodic detection time. The method of detecting a predetermined space release event for the Linux partition may include: in response to receiving a notification pushed by a predetermined kernel event regarding the detection of a predetermined space release event for the Linux partition, determining that a predetermined space release event has occurred for the Linux partition. The predetermined kernel event can detect whether a file deletion event has occurred on the Linux partition; if so, it can be considered that a predetermined space release event has occurred, and a notification is pushed to the sandbox management module.
[0148] As can be seen, in this application, when the storage space of the Linux partition is insufficient, the storage space used by the specified directory of the sandbox can be extended to the target partition of the non-Linux partition to ensure the stable operation of the Linux partition; when the storage space of the target partition is insufficient, the storage space used by the specified directory of the sandbox can be extended to the spare partition of the non-Linux partition to ensure the stable operation of the sandbox; and when the storage space used by the specified directory has been extended to the target partition or spare partition of the non-Linux partition, if the storage space of the Linux partition is sufficient, this application can also remap the storage space used by the specified directory back to a partition to be mounted in the Linux partition, releasing the storage space of the non-Linux partition, thus releasing the storage space of the non-Linux partition when it is determined that the Linux partition is operating stably.
[0149] For any of the above embodiments, after the root directory switching process, the method further includes:
[0150] After performing a root directory switch for any sandbox, an access policy configuration is executed on the storage partition currently mounted to the specified directory; wherein, the access policy configuration is to set a condition that disallows the program from running.
[0151] After performing a root directory switch for any sandbox, i.e., switching the sandbox's root file system to the new root file system, in order to avoid potential dangers (such as the presence of viruses or other programs) in the storage partition (to be mounted, target partition, or spare partition) mapped to the specified directory, the sandbox management module can also perform access policy configuration processing on the storage partition currently mounted to the specified directory, i.e., configure the storage partition currently mounted to the specified directory to disallow the program from running.
[0152] For example, the sandbox management module can set the storage partition to be disabled by calling the interface of the operating system supported by the storage partition. The specific implementation method can be similar to the existing technology, and will not be described in detail here.
[0153] The sandbox storage space expansion method provided in this application will be described below with reference to a specific embodiment.
[0154] Based on the aforementioned technical issues, there is an urgent need for a dynamic, transparent, and robust storage expansion mechanism that enables sandboxes to seamlessly utilize the storage resources of non-Linux partitions while maintaining the stable operation of Linux partitions. This application addresses this technical gap by proposing a sandbox storage space expansion method based on dynamic binding mounts and pivot_root.
[0155] This application provides a sandbox storage space expansion method, where each stage includes refined sub-steps and decision logic to ensure system robustness; the process is designed as a closed-loop structure, supporting continuous operation and dynamic adjustment. Figure 4 As shown, it may include the following steps:
[0156] S401: Initialize the sandbox; this involves deploying the sandbox root filesystem. A complete root filesystem for the sandbox is deployed on the Linux partition. The root directory can include bin, dev, lib, proc, run, sys, usr, mnt, etc. The root filesystem is mounted in read-only mode to ensure basic stability, but the mnt directory (the specified directory) is reserved as a writable point (i.e., as a mount point) for expanding storage space. During sandbox initialization, an isolated environment is created using Linux kernel namespace technology (such as mount namespaces) to prevent mount operations within the sandbox from affecting the host system.
[0157] S402: Start the daemon process; specifically, start the intelligent space detection daemon process. This can be a multi-threaded daemon process that uses an event-driven architecture, combining polling and interrupt mechanisms to detect the available storage space of a partition (initially detecting the remaining space of the entire Linux partition; after mounting and switching to the target or spare partition, it can detect the available storage space of the target or spare partition in non-Linux partitions). Implementation details:
[0158] Threshold configuration: Set dynamically adjustable space thresholds (for example, trigger expansion when the remaining space of a storage partition is less than 15%, i.e., the first predetermined threshold can be 15%). Threshold parameters are dynamically loaded through configuration files or APIs and support adaptive adjustment.
[0159] Monitoring method: Use inotify kernel events to monitor file system changes, combined with periodic df command scans (interval configurable from 1 to 5 seconds). This corresponds to the first and second detection conditions mentioned above.
[0160] S403: Determine if there is sufficient space; that is, determine whether the available storage space of the currently detected Linux partition (and the target partition) is sufficient, i.e. whether the remaining space percentage is lower than the first predetermined threshold. If yes, proceed to step S404; otherwise, repeat step S403.
[0161] S404: Determine the appropriate partition; that is, determine the storage partition to which the expansion needs to be made, corresponding to the above determination of the target partition (or, in other cases, it can also be to determine the spare partition or the partition to be mounted).
[0162] S405: Detect suitable partitions; that is, after determining suitable partitions, the storage partition can also be scanned and filtered: specifically, it can scan all currently available storage partitions of the electronic device through the block device interface (such as / dev / sd or / dev / mmcblk) to identify non-Linux format partitions. The scanning process uses a multi-level filtering algorithm:
[0163] First-level filtering: Quick filtering based on file system type (such as FAT32, NTFS, exFAT) (corresponding to the above-mentioned determination of at least one candidate storage partition other than Linux partitions based on the file system type supported by each storage partition), using the blkid library (Block ID Library) to read partition metadata and exclude corrupted or unusable partitions.
[0164] The second level of filtering involves evaluating the capacity of candidate storage partitions and selecting the one with the largest remaining space (prioritizing partitions with a high percentage of contiguous space to optimize performance). Simultaneously, the mount status of this storage partition is checked to ensure it is not exclusively occupied by other processes.
[0165] Level 3 verification: Perform file system consistency checks (such as using fsck.vfat (File System Consistency Check for VFAT) to perform non-destructive verification on FAT32 partitions) and test read and write permissions.
[0166] S406: Perform unmounting; that is, for the specified directory (mnt directory) used as the mount point, unmount the existing mnt directory: use the umount –lazy command to unmount the existing mnt directory in the sandbox to prevent failure due to file busy errors. If the unmount fails, the retry mechanism will attempt a maximum of 3 times.
[0167] S407: Recursive binding processing; that is, using the mount-bind-R command to bind the target partition (which in other cases can also be a spare partition or a partition to be mounted) of a non-Linux partition to the mnt directory of the sandbox. The recursive option ensures that the subdirectory structure and file attributes (such as inodes and timestamps) are fully mapped.
[0168] S408: Root directory switching process; this involves switching the root file system to a root file system where the target partition (or, in other cases, a spare partition or a partition to be mounted) is mounted under the `mnt` directory. First, the new root file system is prepared: the sandbox root directory (i.e., the root directory where the target partition is mounted under `mnt`) is copied to a temporary path (e.g., ` / opt / sandbox / new_root`), ensuring all device files (e.g., ` / dev / null`) and library files are in place. Then, the root directory is switched: the `pivot_root` system call interface is used to switch the sandbox root directory to the root directory in the temporary path, and the original root directory is unmounted, achieving complete isolation. After the root directory switching process, access to the specified directory (e.g., ` / mnt / data`) within the sandbox is transparently redirected to the storage partition (target partition) in the non-Linux partition.
[0169] S409: Access policy configuration processing; that is, for the target partition to be extended (in other cases, it can also be a spare partition or a partition to be mounted), the target partition is set to not allow programs to run, in order to avoid security risks.
[0170] S410: Start the dynamic adjustment module; that is, enable the dynamic adjustment module to dynamically adjust the partition mapped to the specified directory, and return to step S403 (execute step S404 when the target partition space is insufficient, and execute step S404 when the Linux partition space is sufficient) to achieve fault tolerance optimization:
[0171] Dynamic load balancing: Detects the I / O load of non-Linux partitions and automatically switches to a spare partition if performance degrades (such as load balancing among multiple FAT32 partitions).
[0172] Resource reclamation: When the Linux partition space is restored to a sufficient level, it can be automatically unbound and the non-Linux partition resources can be released, that is, the specified directory can be remounted to the storage partition in the Linux partition.
[0173] This application achieves dynamic expansion of sandbox storage space through multi-level technology integration, specifically including:
[0174] Dynamic binding mounts and remapping: By using binding mount technology, a specified directory (such as mnt) in the sandbox root file system can be dynamically associated with a non-Linux partition, realizing transparent expansion of storage resources, avoiding direct modification of the sandbox root file system structure, and ensuring compatibility.
[0175] pivot_root root directory switching and isolation enhancement: Combined with the pivot_root system call interface, the sandbox root directory is switched to the extended file system, automatically remapping access to specified directories (such as / mnt) within the sandbox to non-Linux partitions. Simultaneously, namespaces (creating an isolated environment during sandbox initialization) and access control modules (for executing access policy configuration, such as SELinux (Security-Enhanced Linux)) are integrated to prevent security risks arising from storage operations.
[0176] Intelligent space detection and fault tolerance management: A daemon process is introduced to detect the remaining space in real time and automatically perform processes such as partition scanning, mount verification, and error rollback; the entire process supports hot-swapping and dynamic adjustment without manual intervention, improving reliability and scalability.
[0177] As can be seen, this application enables the sandbox to seamlessly utilize the storage resources of non-Linux partitions, dynamically expand the available storage space inside the sandbox, and maintain the stable operation of the Linux partition.
[0178] Based on the above method embodiments, this application also provides a sandbox storage space expansion device, such as... Figure 5 As shown, the device includes:
[0179] The determining module 510 is configured to determine the target partition of the electronic device in response to the fact that the space ratio of the Linux partition in the electronic device with respect to the remaining space is lower than a first predetermined threshold; wherein the target partition is a storage partition other than the Linux partition.
[0180] The uninstallation module 520 is used to uninstall a specified directory under the root directory of the sandbox, which serves as the mount point; wherein, the uninstallation process is used to uninstall the currently mounted content of the specified directory;
[0181] Mounting module 530 is used to mount the target partition to the specified directory in response to the completion of the unloading process, so as to obtain the current specified directory;
[0182] The first switching module 540 is used to perform a sandbox root directory switching process based on the root directory containing the current specified directory, so that the root directory containing the current specified directory becomes the root directory of the sandbox, and after the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the target partition.
[0183] Optionally, the determining module is specifically used for:
[0184] For each storage partition existing in the electronic device, at least one candidate storage partition other than the Linux partition is determined based on the file system type supported by each storage partition.
[0185] From the at least one candidate storage partition, select a storage partition whose available storage space meets predetermined conditions; wherein, the predetermined conditions include: the proportion of available storage space is greater than a second predetermined threshold, or the available storage space is the largest, or it belongs to a pre-set storage partition;
[0186] Based on the permission information configured for the selected storage partition, it is determined whether the sandbox has read and write permissions for the selected storage partition.
[0187] In response to having read and write permissions, the selected storage partition is designated as the target partition;
[0188] In response to not having read / write permissions, for the at least one candidate storage partition, excluding the previously selected storage partition, a storage partition whose available storage space meets predetermined conditions is selected, and the step of identifying whether the sandbox has read / write permissions for the selected storage partition based on the permission information configured for the selected storage partition is returned.
[0189] Optionally, the first switching module is specifically used for:
[0190] Copy the root directory containing the current specified directory to the temporary storage space allocated for the sandbox;
[0191] The root directory of the sandbox is switched to the root directory within the temporary storage space via a predefined system call interface provided by the Linux kernel, and the root directory containing the specified directory before the uninstallation process is unloaded.
[0192] Optionally, the device further includes an identification module for:
[0193] In response to the fulfillment of the first detection condition, the remaining space percentage of the Linux partition in the electronic device is determined, and it is identified whether the space percentage is lower than the first predetermined threshold.
[0194] The first detection condition includes: detecting a predetermined write event to the Linux partition, or reaching a preset periodic detection time; the method of detecting a predetermined write event to the Linux partition includes: in response to receiving a notification pushed by a predetermined kernel event regarding the detection of a predetermined write event to the Linux partition, determining that a predetermined write event has occurred to the Linux partition.
[0195] Optionally, the unloading module is specifically used for:
[0196] The first command is invoked to unload the specified directory, which is the mount point, under the root directory of the sandbox; wherein, the first command is a command used to perform delayed unloading of the file system;
[0197] And / or,
[0198] The mounting module is specifically used for:
[0199] In response to the completion of the uninstallation process, the second command is invoked using the access identifier information of the specified directory and the target partition as input parameters to mount the target partition to the specified directory, thereby obtaining the current specified directory; wherein, the second command is a command to mount the content of the directory used as the mount point.
[0200] Optionally, the device further includes a second switching module for:
[0201] In response to the fulfillment of the second detection condition, it is detected whether the target partition meets the predetermined switching condition;
[0202] In response to the target partition meeting predetermined switching conditions, a backup partition for the electronic device is determined; wherein, the backup partition is: a storage partition other than the Linux partition, which the sandbox has read and write permissions for and has available storage space;
[0203] Perform an uninstallation process on the currently specified directory;
[0204] In response to the completion of the uninstallation process, the spare partition is mounted to the specified directory to obtain the current specified directory;
[0205] Based on the root directory containing the current specified directory, the root directory of the sandbox is switched so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the spare partition.
[0206] The second detection condition includes: detecting a predetermined write event to the target partition, or reaching a preset periodic detection time; the method of detecting a predetermined write event to the target partition includes: in response to receiving a notification pushed by a predetermined kernel event regarding the detection of a predetermined write event to the target partition, determining that a predetermined write event has occurred to the target partition.
[0207] Optionally, the device further includes a third switching module for:
[0208] In response to the fact that the remaining space percentage of the Linux partition is higher than a third predetermined threshold, a storage partition with available storage space in the Linux partition is identified as the partition to be mounted.
[0209] Perform an uninstallation process on the currently specified directory;
[0210] In response to the completion of the uninstallation process, the partition to be mounted is mounted to the specified directory, thus obtaining the current specified directory;
[0211] Based on the root directory containing the current specified directory, the root directory of the sandbox is switched so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the partition to be mounted.
[0212] Optionally, the device further includes a configuration module for:
[0213] After performing a root directory switch for any sandbox, an access policy configuration is executed on the storage partition currently mounted to the specified directory; wherein, the access policy configuration is to set a condition that disallows the program from running.
[0214] This application also provides an electronic device, such as... Figure 6 As shown, it includes:
[0215] Memory 601 is used to store computer programs;
[0216] The processor 602, when executing a program stored in the memory 601, implements any of the described sandbox storage space expansion methods.
[0217] Furthermore, the aforementioned electronic device may also include a communication bus and / or a communication interface, with the processor 602, communication interface, and memory 601 communicating with each other via the communication bus.
[0218] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0219] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0220] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0221] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0222] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described sandbox storage space expansion methods.
[0223] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the sandbox storage space expansion methods described above.
[0224] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.
[0225] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0226] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for embodiments such as apparatus, since they are basically similar to the method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0227] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A method for expanding sandbox storage space, characterized in that, The method includes: In response to the fact that the percentage of remaining space of the Linux partition in the electronic device is lower than a first predetermined threshold, a target partition of the electronic device is determined; wherein, the target partition is a storage partition other than the Linux partition; The specified directory, which serves as the mount point, under the root directory of the sandbox, is unloaded; wherein, the unloading process is used to unload the currently mounted content of the specified directory; In response to the completion of the uninstallation process, the target partition is mounted to the specified directory to obtain the current specified directory; Based on the root directory containing the current specified directory, the root directory of the sandbox is switched so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the target partition.
2. The method according to claim 1, characterized in that, Determining the target partition of the electronic device includes: For each storage partition existing in the electronic device, at least one candidate storage partition other than the Linux partition is determined based on the file system type supported by each storage partition. From the at least one candidate storage partition, select a storage partition whose available storage space meets predetermined conditions; wherein, the predetermined conditions include: the proportion of available storage space is greater than a second predetermined threshold, or the available storage space is the largest, or it belongs to a pre-defined storage partition; Based on the permission information configured for the selected storage partition, it is determined whether the sandbox has read and write permissions for the selected storage partition. In response to having read and write permissions, the selected storage partition is designated as the target partition; In response to not having read / write permissions, for the at least one candidate storage partition, excluding the previously selected storage partition, a storage partition whose available storage space meets predetermined conditions is selected, and the step of identifying whether the sandbox has read / write permissions for the selected storage partition based on the permission information configured for the selected storage partition is returned.
3. The method according to claim 1, characterized in that, The root directory switching process for the sandbox, based on the root directory containing the current specified directory, includes: Copy the root directory containing the current specified directory to the temporary storage space allocated for the sandbox; The root directory of the sandbox is switched to the root directory within the temporary storage space via a predefined system call interface provided by the Linux kernel, and the root directory containing the specified directory before the uninstallation process is unloaded.
4. The method according to any one of claims 1-3, characterized in that, Before determining the target partition of the electronic device in response to the fact that the percentage of remaining space of the Linux partition in the electronic device is lower than a first predetermined threshold, the method further includes: In response to the fulfillment of the first detection condition, the remaining space percentage of the Linux partition in the electronic device is determined, and it is identified whether the space percentage is lower than the first predetermined threshold. The first detection condition includes: detecting a predetermined write event to the Linux partition, or reaching a preset periodic detection time; the method of detecting a predetermined write event to the Linux partition includes: in response to receiving a notification pushed by a predetermined kernel event regarding the detection of a predetermined write event to the Linux partition, determining that a predetermined write event has occurred to the Linux partition.
5. The method according to any one of claims 1-3, characterized in that, The unloading process for the specified directory under the root directory of the sandbox, which serves as the mount point, includes: The first command is invoked to unload the specified directory, which is the mount point, under the root directory of the sandbox; wherein, the first command is a command used to perform delayed unloading of the file system; And / or, Upon completion of the unloading process, the target partition is mounted to the specified directory to obtain the current specified directory, including: In response to the completion of the uninstallation process, the second command is invoked using the access identifier information of the specified directory and the target partition as input parameters to mount the target partition to the specified directory, thereby obtaining the current specified directory; wherein, the second command is a command to mount the content of the directory used as the mount point.
6. The method according to claim 1, characterized in that, After performing the sandbox root directory switching process based on the root directory containing the current specified directory, the method further includes: In response to the fulfillment of the second detection condition, it is detected whether the target partition meets the predetermined switching condition; In response to the target partition meeting predetermined switching conditions, a backup partition for the electronic device is determined; wherein, the backup partition is: a storage partition other than the Linux partition, which the sandbox has read and write permissions for and has available storage space; Perform an uninstallation process on the currently specified directory; In response to the completion of the uninstallation process, the spare partition is mounted to the specified directory to obtain the current specified directory; Based on the root directory containing the current specified directory, the root directory of the sandbox is switched so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the spare partition. The second detection condition includes: detecting a predetermined write event to the target partition, or reaching a preset periodic detection time; the method of detecting a predetermined write event to the target partition includes: in response to receiving a notification pushed by a predetermined kernel event regarding the detection of a predetermined write event to the target partition, determining that a predetermined write event has occurred to the target partition.
7. The method according to claim 1, characterized in that, After performing the sandbox root directory switching process based on the root directory containing the current specified directory, the method further includes: In response to the fact that the remaining space percentage of the Linux partition is higher than a third predetermined threshold, a storage partition with available storage space in the Linux partition is identified as the partition to be mounted. Perform an uninstallation process on the currently specified directory; In response to the completion of the uninstallation process, the partition to be mounted is mounted to the specified directory, thus obtaining the current specified directory; Based on the root directory containing the current specified directory, the root directory of the sandbox is switched so that the root directory containing the current specified directory becomes the root directory of the sandbox. After the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the operation of the sandbox that need to be stored in the current specified directory are stored in the partition to be mounted.
8. The method according to claim 6 or 7, characterized in that, The method further includes: After performing a root directory switch for any sandbox, an access policy configuration is performed on the storage partition currently mounted to the specified directory; wherein, the access policy configuration is to set a condition that disallows the program from running.
9. A sandbox storage space expansion device, characterized in that, The device includes: A determination module is configured to determine a target partition of the electronic device in response to a situation where the percentage of remaining space of a Linux partition in the electronic device is lower than a first predetermined threshold; wherein the target partition is a storage partition other than the Linux partition. The uninstallation module is used to uninstall a specified directory under the root directory of the sandbox, which serves as the mount point; wherein, the uninstallation process is used to uninstall the currently mounted content of the specified directory; The mounting module is used to mount the target partition to the specified directory in response to the completion of the unloading process, thereby obtaining the current specified directory. The first switching module is used to perform a sandbox root directory switching process based on the root directory containing the current specified directory, so that the root directory containing the current specified directory becomes the root directory of the sandbox, and after the root directory containing the current specified directory becomes the root directory of the sandbox, the target files generated during the sandbox operation that need to be stored in the current specified directory are stored in the target partition.
10. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-8.