A method, apparatus, and electronic device for managing file identifiers.
Patent Information
- Application Number
- CN202210655420.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-10
- Publication Date
- 2026-09-01
- Estimated Expiration
- 2042-06-10
AI Technical Summary
[0004]现有的文件标识符的复制方法中,新的文件标识符和原文件标识符均指向原文件标识符对应的文件结构,如果操作系统中存在指向同一个文件结构的大量的文件标识符的并发复制请求时,不同的进程需要同时访问同一个文件结构,导致系统的一致性开销较大
[0061]本发明实施例提供了一种文件标识符的管理方法,该方法能够对待复制文件标识符进行复制,得到目标文件标识符,所述目标文件标识符中填入的是所述待复制文件标识符的标识符信息,所述目标文件标识符指向所述待复制文件标识符。如果操作系统中存在执行一个文件的大量的文件标识符并发复制请求,采用本发明实施例提供的文件标识符的管理方法,针对不同的进程,只需访问进程中的待复制文件标识符,以获取标识符信息,不会存在不同进程同时访问同一个文件结构的情况,从而降低了系统的一致性开销。
Smart Images

Figure CN115080508B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, and electronic device for managing file identifiers. Background Technology
[0002] In an operating system, files opened by a user are organized into a file structure and stored in memory. User processes operate on these files using file identifiers. The operating system kernel provides users with methods to copy file identifiers; the copied file identifier has the same operands as the original.
[0003] Existing technologies typically perform the following operations when copying file identifiers: look up the corresponding file structure based on the original file identifier; request a new file identifier in the existing process file identifier table, and fill the new file identifier with the file structure corresponding to the original file identifier.
[0004] In existing file identifier copying methods, both the new file identifier and the original file identifier point to the file structure corresponding to the original file identifier. If there are a large number of concurrent copying requests for file identifiers pointing to the same file structure in the operating system, different processes need to access the same file structure at the same time, resulting in a large consistency overhead for the system. Summary of the Invention
[0005] This invention provides a method, apparatus, and electronic device for managing file identifiers, which can reduce the consistency overhead of the operating system.
[0006] To address the aforementioned problems, this invention discloses a method for managing file identifiers, the method comprising:
[0007] When a file identifier copy operation is detected, the file identifier to be copied corresponding to the file identifier copy operation is obtained;
[0008] Obtain the identifier information of the file identifier to be copied;
[0009] Create a new file identifier in the file identifier table;
[0010] The identifier information of the file identifier to be copied is filled into the new file identifier to obtain the target file identifier; the target file identifier points to the file identifier to be copied.
[0011] Optionally, the method further includes:
[0012] Create a first data structure and a second data structure, and associate the first data structure and the second data structure with the target process. The first data structure is used to record the file identifiers that have been copied in the target process, and the second data structure is used to record the file identifiers that have been copied but not yet used in the target process.
[0013] The identifier of the file to be copied is recorded in the first data structure, and the identifier of the target file is recorded in the second data structure.
[0014] Optionally, the method further includes:
[0015] When a file identifier usage operation is detected, the file identifier to be used corresponding to the file identifier usage operation is obtained;
[0016] Detect whether the file identifier to be used exists in the second data structure;
[0017] If the file identifier to be used exists in the second data structure, then the original file identifier corresponding to the file identifier to be used is obtained according to the identifier information in the file identifier to be used;
[0018] The target file is accessed based on the original file identifier to obtain the file structure information of the target file, wherein the original file identifier points to the target file;
[0019] The file structure information is filled into the file identifier to be used, and the file identifier to be used is cleared in the second data structure.
[0020] Optionally, clearing the file identifier to be used in the second data structure includes:
[0021] Set the flag corresponding to the file identifier to be used in the second data structure to 0.
[0022] Optionally, the method further includes:
[0023] When a file identifier close operation is detected, the file identifier to be closed corresponding to the file identifier close operation is obtained;
[0024] Detect whether the file identifier to be closed exists in the first data structure;
[0025] If the file identifier to be closed exists in the first data structure, then check if there is a file identifier pointing to the file identifier to be closed in the second data structure;
[0026] If the second data structure contains at least one file identifier that points to the file identifier to be closed, then obtain the file identifier that points to the file identifier to be closed from the second data structure;
[0027] Perform a backfilling operation on the file identifier in the second data structure that points to the file identifier to be closed;
[0028] Perform a close operation on the file identifier to be closed, and clear the file identifier to be closed from the first data structure.
[0029] Optionally, after detecting whether the file identifier to be closed exists in the first data structure, the method further includes:
[0030] If the file identifier to be closed does not exist in the first data structure, then check if the file identifier to be closed exists in the second data structure.
[0031] If the file identifier to be closed exists in the second data structure, then a closing operation is performed on the file identifier to be closed, and the file identifier to be closed is cleared from the second data structure.
[0032] On the other hand, embodiments of the present invention disclose a file identifier management device, the device comprising:
[0033] The first acquisition module is used to acquire the file identifier to be copied corresponding to the file identifier copy operation when a file identifier copy operation is detected.
[0034] The second acquisition module is used to acquire the identifier information of the identifier of the file to be copied;
[0035] Create a module to create a new file identifier in the file identifier table;
[0036] The copy module is used to fill the identifier information of the file identifier to be copied into the new file identifier to obtain the target file identifier; the target file identifier points to the file identifier to be copied.
[0037] Optionally, the device further includes:
[0038] A data structure creation module is used to create a first data structure and a second data structure, and associate the first data structure and the second data structure with a target process. The first data structure is used to record file identifiers that have been copied in the target process, and the second data structure is used to record file identifiers that have been copied but not yet used in the target process.
[0039] The recording module is used to record the identifier of the file to be copied in the first data structure and the identifier of the target file in the second data structure.
[0040] Optionally, the device further includes:
[0041] The third acquisition module is used to acquire the file identifier to be used corresponding to the file identifier use operation when a file identifier use operation is detected;
[0042] The first detection module is used to detect whether the file identifier to be used exists in the second data structure;
[0043] The fourth acquisition module is used to acquire the original file identifier corresponding to the file identifier to be used based on the identifier information in the file identifier to be used if the file identifier to be used exists in the second data structure.
[0044] The fifth acquisition module is used to access the target file and obtain the file structure information of the target file based on the original file identifier, wherein the original file identifier points to the target file;
[0045] The clearing module is used to fill the file structure information into the file identifier to be used and to clear the file identifier to be used in the second data structure.
[0046] Optionally, the clearing module includes:
[0047] The clearing submodule is used to set the flag position corresponding to the file identifier to be used in the second data structure to 0.
[0048] Optionally, the device further includes:
[0049] The sixth acquisition module is used to acquire the file identifier to be closed corresponding to the file identifier closing operation when a file identifier closing operation is detected;
[0050] The second detection module is used to detect whether the file identifier to be closed exists in the first data structure;
[0051] The third detection module is used to detect whether there is a file identifier pointing to the file identifier to be closed in the second data structure if the file identifier to be closed exists in the first data structure.
[0052] The seventh acquisition module is used to acquire the file identifier pointing to the file identifier to be closed in the second data structure if there is at least one file identifier pointing to the file identifier to be closed in the second data structure.
[0053] The backfill module is used to perform a backfill operation on the file identifier in the second data structure that points to the file identifier to be closed;
[0054] The first closing module is used to perform a closing operation on the file identifier to be closed and to clear the file identifier to be closed in the first data structure.
[0055] Optionally, the device further includes:
[0056] The fourth detection module is used to detect whether the file identifier to be closed exists in the second data structure if the file identifier to be closed does not exist in the first data structure.
[0057] The second closing module is used to perform a closing operation on the file identifier to be closed if the file identifier to be closed exists in the second data structure, and to clear the file identifier to be closed from the second data structure.
[0058] In another aspect, embodiments of the present invention also disclose an electronic device, the electronic device including a memory and one or more programs, wherein one or more programs are stored in the memory and configured to be executed by one or more processors using the aforementioned file identifier management method.
[0059] This invention also discloses a readable storage medium, which, when the instructions in the storage medium are executed by the processor of an electronic device, enables the electronic device to execute the aforementioned file identifier management method.
[0060] The embodiments of the present invention have the following advantages:
[0061] This invention provides a method for managing file identifiers. This method copies a file identifier to be copied, obtaining a target file identifier. The target file identifier contains the identifier information of the file identifier to be copied, and the target file identifier points to the file identifier to be copied. If there are numerous concurrent file identifier copying requests executing a file in the operating system, the file identifier management method provided by this invention allows different processes to access only the file identifier to be copied within their respective processes to obtain the identifier information. This prevents different processes from simultaneously accessing the same file structure, thereby reducing system consistency overhead. Attached Figure Description
[0062] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0063] Figure 1 This is a flowchart illustrating the steps of an embodiment of a file identifier management method according to the present invention;
[0064] Figure 2 This is a structural block diagram of an embodiment of a file identifier management device according to the present invention;
[0065] Figure 3 This is a structural block diagram of an electronic device for managing file identifiers, provided by an example of the present invention. Detailed Implementation
[0066] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0067] Method Implementation Examples
[0068] Reference Figure 1 The diagram illustrates a flowchart of an embodiment of a file identifier management method according to the present invention. The method may specifically include the following steps:
[0069] Step 101: When a file identifier copy operation is detected, obtain the file identifier to be copied corresponding to the file identifier copy operation.
[0070] Step 102: Obtain the identifier information of the file identifier to be copied.
[0071] Step 103: Create a new file identifier in the file identifier table.
[0072] Step 104: Fill the identifier information of the file identifier to be copied into the new file identifier to obtain the target file identifier; the target file identifier points to the file identifier to be copied.
[0073] The file identifier management method provided in this invention can be applied to electronic devices, including but not limited to: servers, smartphones, voice recorders, tablets, e-book readers, MP3 (Moving Picture Experts Group Audio Layer III) players, MP4 (Moving Picture Experts Group Audio Layer IV) players, laptops, in-vehicle computers, desktop computers, set-top boxes, smart TVs, wearable devices, etc.
[0074] It should be noted that the file identifier is used to identify an open file in the operating system, and all system calls related to file I / O operations can be implemented through the file identifier. For example, the file identifier can be a file descriptor (fd) in a Linux or Unix operating system, or a file handle (fh) in a Windows operating system.
[0075] The file identifier table (FIG) records the files opened by a process, with one FIG for each process. Each entry in the FIG contains a pointer to an open file. In this embodiment, the file identifier can be an index of the FIG. Each file identifier corresponds to an entry in the FIG. User programs cannot directly access the file descriptor table in the kernel; they can only use the index. When a user program opens or creates a file, the kernel allocates a file identifier and returns it to the user program. Essentially, obtaining the file identifier is equivalent to obtaining the index of the process's FIG, which allows the user program to access the pointer to the corresponding entry, pointing to an open file. As an example, the FIG can be the file descriptor table in the Linux operating system. In Linux, the index of the file descriptor table is the file descriptor, stored as an integer variable.
[0076] In this embodiment of the invention, the files may include ordinary files, directory files, character device files (such as keyboards, mice, etc.), block device files (such as hard drives, optical drives, etc.), sockets, etc., in an operating system. As an example, the files may include, but are not limited to, application files, such as word processing files, spreadsheet files, presentation files, personal information management program files, database files, publishing program files, drawing files, notepad files, presentation files, project files, etc. As another example, the files may include multimedia files, such as audio files, image files, video files, animation files, game files, web page files, social networking service files, etc. As yet another example, the files may include web pages, social networking site feeds, news feeds (e.g., news aggregation websites, news portals, etc.), search engine results, and other online content types.
[0077] Copying a file identifier refers to using another file identifier to point to the same open file. The operating system can copy the original file identifier by calling the file identifier copy function to obtain a new file identifier. Both the original and new file identifiers point to the same file.
[0078] It should be noted that in existing technologies, the new file identifier generated after copying has the same operand as the original file identifier; in other words, the two file identifiers point to the same open file. When there are a large number of concurrent copy requests for file identifiers pointing to the same file in the operating system, different processes need to access the same file structure simultaneously, which leads to a significant system consistency overhead.
[0079] To address this issue, this invention provides a method for managing file identifiers. Specifically, when a file identifier copy operation is detected, the method first obtains the file identifier to be copied corresponding to the file identifier copy operation, and then obtains the identifier information of the file identifier to be copied. The file identifier copy operation can be a call to a file identifier copy function, such as the `dup` function or the `dup2` function. The identifier information of the file identifier to be copied uniquely identifies the identity of the file identifier to be copied, and may include the process to which the file identifier to be copied belongs and the file identifier ID of the file identifier to be copied, etc.
[0080] Next, a new file identifier is created in the file identifier table. It's important to note that each process corresponds to its own file identifier table. When creating a new file identifier, the process corresponding to the file identifier operation needs to be determined, and the new file identifier is created in the corresponding process's file identifier table.
[0081] Finally, the identifier information of the file identifier to be copied is filled into the new file identifier to obtain the target file identifier after copying. At this point, the target file identifier has not been used, that is, it has not been used to access the file.
[0082] It is understood that, in this embodiment of the invention, the target file identifier is filled with the identifier information of the file identifier to be copied, and the target file identifier points to the file identifier to be copied. Assume the file identifier to be copied is f1, which points to file A, and the resulting target file identifier is f2. If the file identifier copying method in the prior art is followed, both the target file identifier f2 and the file identifier to be copied f1 point to the opened file A; however, in this embodiment of the invention, the target file identifier f2 points to the file identifier to be copied f1.
[0083] If there are a large number of concurrent file identifier copying requests in the operating system to execute a file, the file identifier management method provided in this embodiment of the invention can be used to obtain the identifier information by only accessing the file identifier to be copied in the process for different processes. This will prevent different processes from accessing the same file structure at the same time, thereby reducing the consistency overhead of the system.
[0084] In an optional embodiment of the present invention, the method further includes:
[0085] Step S11: Create a first data structure and a second data structure, and associate the first data structure and the second data structure with the target process. The first data structure is used to record the file identifiers that have been copied in the target process, and the second data structure is used to record the file identifiers that have been copied but not yet used in the target process.
[0086] Step S12: Record the identifier of the file to be copied in the first data structure, and record the identifier of the target file in the second data structure.
[0087] In this embodiment of the invention, two data structures can also be created in the operating system for each process to coordinate with the file identifier copying process described in steps 101 to 104 above, enabling unified management of copied file identifiers and unused file identifiers after copying. Specifically, a first data structure and a second data structure can be created first, and then the first and second data structures can be associated with the target process respectively. This allows the operating system to manage file descriptors in the target process by traversing the first and / or second data structures corresponding to the target process based on the association between the first and second data structures and the process.
[0088] The first data structure is used to record the file identifiers that have been copied, and the second data structure is used to record the file identifiers that have not yet been used after copying.
[0089] When the method provided in this embodiment of the invention is used to perform a copy operation on the file identifier f1 to be copied and obtain the target file identifier f2 after copying, the file identifier f1 to be copied is recorded in the first data structure corresponding to its own process, and the target file identifier f2 is recorded in the second data structure corresponding to its own process.
[0090] It should be noted that, in this embodiment of the invention, the first data structure and the second data structure can be arrays or bitmaps. Taking both the first and second data structures as bitmaps as an example, each element in the bitmap can represent the presence or absence of data. Specifically, if the element corresponding to the data is 0, it means that the data does not exist; if the element corresponding to the data is 1, it means that the data exists. In this embodiment of the invention, two bitmaps can be used to record the file identifiers that have been copied and the file identifiers that have not yet been used after copying. Assume that the first data structure is bitmap w1 and the second data structure is bitmap w2, and all elements in both bitmaps are defaulted to 0.
[0091] After completing the copying operation of the file identifier f1 to be copied, the file identifier f1 to be copied is recorded in bitmap w1. Specifically, an element, denoted as element a1, can be allocated in bitmap w1 to describe the file identifier f1 to be copied, and element a1 is set to 1. Figure 2 The target file identifier f2, which has not yet been used after copying, is recorded in bitmap w2. Similarly, an element a2 is allocated in bitmap w2 to describe the target file identifier f2, and element a2 is set to 1.
[0092] In an optional embodiment of the present invention, the method further includes:
[0093] Step S21: When a file identifier usage operation is detected, obtain the file identifier to be used corresponding to the file identifier usage operation;
[0094] Step S22: Detect whether the file identifier to be used exists in the second data structure;
[0095] Step S23: If the file identifier to be used exists in the second data structure, then obtain the original file identifier corresponding to the file identifier to be used based on the identifier information in the file identifier to be used.
[0096] Step S24: Obtain the file structure information of the target file based on the original file identifier, wherein the original file identifier points to the target file;
[0097] Step S25: Fill in the file structure information into the file identifier to be used, and clear the file identifier to be used in the second data structure.
[0098] It should be noted that in existing technologies, after copying the original file descriptor to obtain a new file descriptor, the new file descriptor needs to be immediately populated. This means filling the new file descriptor with the corresponding file structure information and adding a reference to the file resource. Afterwards, closing the file descriptor releases the file resource again. If the file descriptor is not actually used, adding a reference to the file resource or releasing the file resource is completely redundant for the system and affects its operational efficiency.
[0099] To address this issue, this embodiment of the invention postpones the backfilling operation of the copied target file identifier until the first use of the target file identifier. Specifically, when a file identifier usage operation is detected, the file identifier to be used corresponding to that file identifier usage operation is obtained, and it is checked whether the file identifier to be used exists in the second data structure. The file identifier usage operation can be, for example, a user accessing or creating a file using a file identifier returned by the kernel. In this embodiment, the presence of the file identifier can be indicated by a flag bit in the second data structure. For example, a flag bit of 1 indicates that the file identifier exists in the second data structure; a flag bit of 0 indicates that the file identifier does not exist in the second data structure. For instance, if the flag bit of the file identifier to be used in the second data structure is 1, it indicates that the file identifier to be used exists in the second data structure.
[0100] In this invention, the second data structure is used to record file identifiers that have not yet been used after copying. If the file identifier to be used exists in the second data structure, it indicates that the file identifier to be used is the target descriptor f2 that has not yet been used after copying in this invention. In this case, the identifier information of the corresponding file identifier f1 to be copied is filled into the file identifier to be used. In this situation, a backfilling operation needs to be performed on the file identifier f1 to be used. Specifically, based on the identifier information in the file identifier to be used, the original file identifier corresponding to the file identifier to be used is obtained, and the target file and the file structure information of the target file are obtained based on the original file identifier. Finally, the obtained file structure information is filled into the file identifier to be used, and the file identifier to be used is cleared from the second data structure.
[0101] Optionally, clearing the unused file identifier in the second data structure includes: setting the flag position corresponding to the unused file identifier in the second data structure to 0. Taking bitmap w2 as an example, the element in bitmap w2 used to describe the unused file identifier can be set to 0, thereby clearing the unused file identifier.
[0102] In this embodiment of the invention, the backfilling operation of the target file identifier after copying is delayed until the moment the target file identifier is used for the first time. Compared with the prior art, which backfills the target file identifier when copying the file identifier, this embodiment of the invention does not need to obtain file structure information when copying the file identifier. It only needs to operate on the data inside the process, which simplifies the operation process of copying the file identifier, improves the processing efficiency of the system, and helps to improve the concurrency of the copying operation.
[0103] It is understood that in this embodiment of the invention, the file identifier is backfilled upon its first use after being copied. After the backfilling operation, the copied file identifier already contains the file structure information of the file it points to. Therefore, if the file identifier to be used does not exist in the second data structure, it means that the file identifier to be used has been used before, and the file structure information has already been filled into the file identifier. Thus, the corresponding target file can be accessed directly using the file structure information.
[0104] In an optional embodiment of the present invention, the method further includes:
[0105] Step S31: When a file identifier closing operation is detected, obtain the file identifier to be closed corresponding to the file identifier closing operation;
[0106] Step S32: Detect whether the file identifier to be closed exists in the first data structure;
[0107] Step S33: If the file identifier to be closed exists in the first data structure, then detect whether there is a file identifier pointing to the file identifier to be closed in the second data structure;
[0108] Step S34: If there is at least one file identifier in the second data structure that points to the file identifier to be closed, then obtain the file identifier in the second data structure that points to the file identifier to be closed.
[0109] Step S35: Perform a backfilling operation on the file identifier in the second data structure that points to the file identifier to be closed;
[0110] Step S36: Perform a closing operation on the file identifier to be closed, and clear the file identifier to be closed in the first data structure.
[0111] When the operating system needs to close a file, it can do so by manipulating the file identifier. Closing the file identifier means setting that file identifier so that it will not be reused in any file opening or creation operations. The operating system can perform this closing operation on the file identifier by calling a close function, such as the `close` function.
[0112] In this embodiment of the invention, if a file identifier closing operation is detected, the file identifier to be closed corresponding to that file identifier closing operation is obtained, and it is checked whether the file identifier to be closed exists in the first data structure. If the file identifier to be closed exists in the first data structure, it means that the file identifier to be closed has been copied. Let the file identifier to be closed be file identifier f3. Then, there may be a file identifier f4 in the process that has been copied but not yet filled back. If file identifier f3 is closed at this time, then when file identifier f4 is used for the first time, it will be unable to be filled back due to the lack of a target.
[0113] In this embodiment of the invention, if it is determined that there is a file identifier to be closed in the first data structure, it further detects whether there is a file identifier pointing to the file identifier to be closed in the second data structure. That is, it determines whether the file identifier f4 obtained after copying the file identifier f3 has not been used. If the file identifier f4 has not been used, then the file identifier f4 points to the file identifier f3.
[0114] If the second data structure contains file identifiers pointing to the file identifier to be closed, then all file identifiers pointing to that file identifier in the second data structure need to be retrieved. Assuming the second data structure contains three file identifiers pointing to the file identifier f3 to be closed, namely file identifiers f4, f5, and f6, then file identifiers f4, f5, and f6 are retrieved, and backfilling operations are performed on file identifiers f4, f5, and f6 sequentially.
[0115] Optionally, the backfilling operation on the file identifiers pointing to the file identifier to be closed in the second data structure includes: obtaining the file identifier to be closed pointed to by the file identifier according to the identifier information in the file identifier; obtaining the file structure information of the target file according to the file identifier to be closed; filling the file structure information into the file identifier, and clearing the file identifier in the second data structure. File identifiers f4, f5, and f6 in the second data structure have not yet been used after copying, and at this time, the identifier information corresponding to the file identifier f3 to be closed is filled into file identifiers f4, f5, and f6. During the backfilling operation, the file identifier f3 to be closed can be obtained sequentially according to the identifier information filled in the file identifier, thereby obtaining the file structure information of the target file according to the file identifier f3 to be closed, and filling the obtained file structure information into file identifiers f4, f5, and f6, and clearing f4, f5, and f6 in the second data structure. For a detailed explanation, please refer to the aforementioned steps S23 to S25; this embodiment of the invention will not be further elaborated here.
[0116] Finally, after closing all file identifiers pointing to the file identifier to be closed in the second data structure, the file identifier to be closed is closed, and the file identifier to be closed is cleared from the first data structure.
[0117] In this embodiment of the invention, when performing a closing operation on a file identifier to be closed, a backfilling operation is uniformly performed on file identifiers that have been copied but not yet used. This ensures that closing the file identifier to be closed will not affect the normal use of other file identifiers that point to the file identifier to be closed, which is beneficial to enhancing the locality of the software system.
[0118] In an optional embodiment of the present invention, after detecting whether the file identifier to be closed exists in the first data structure, the method further includes:
[0119] Step S41: If the file identifier to be closed does not exist in the first data structure, then check whether the file identifier to be closed exists in the second data structure;
[0120] Step S42: If the file identifier to be closed exists in the second data structure, then perform a closing operation on the file identifier to be closed and clear the file identifier to be closed from the second data structure.
[0121] If the file identifier to be closed does not exist in the first data structure, there are two possibilities: 1) The file identifier to be closed has not been copied, nor is it a file identifier generated by copying; 2) The file identifier to be closed is a file identifier generated by copying.
[0122] In the first case, the closing operation can be performed directly on the file identifier to be closed. The file identifier to be closed does not exist in either the first data structure or the second data structure, so there is no need to perform a clearing operation.
[0123] If it is the second case, it is necessary to further determine whether the file identifier to be closed has been used. If the file identifier to be closed has not been used, in this embodiment of the invention, the file identifier to be closed will be recorded in the second data structure. Therefore, after performing the closing operation on the file identifier to be closed, it is necessary to further clear the file identifier to be closed in the second data structure to avoid data redundancy.
[0124] In summary, this invention provides a file identifier management method. This method can copy a file identifier to be copied to obtain a target file identifier. The target file identifier is filled with the identifier information of the file identifier to be copied, and the target file identifier points to the file identifier to be copied. If there are a large number of concurrent file identifier copying requests in the operating system, using the file identifier management method provided by this invention, different processes only need to access the file identifier to be copied within the process to obtain the identifier information. This avoids the situation where different processes access the same file structure simultaneously, thereby reducing system consistency overhead.
[0125] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.
[0126] Device Examples
[0127] Reference Figure 2 The diagram illustrates a structural block diagram of an embodiment of a file identifier management device according to the present invention. The device may specifically include:
[0128] The first acquisition module 201 is used to acquire the file identifier to be copied corresponding to the file identifier copy operation when a file identifier copy operation is detected.
[0129] The second acquisition module 202 is used to acquire the identifier information of the identifier of the file to be copied;
[0130] Create module 203 to create a new file identifier in the file identifier table;
[0131] The copy module 204 is used to fill the identifier information of the file identifier to be copied into the new file identifier to obtain the target file identifier; the target file identifier points to the file identifier to be copied.
[0132] Optionally, the device further includes:
[0133] A data structure creation module is used to create a first data structure and a second data structure, and associate the first data structure and the second data structure with a target process. The first data structure is used to record file identifiers that have been copied in the target process, and the second data structure is used to record file identifiers that have been copied but not yet used in the target process.
[0134] The recording module is used to record the identifier of the file to be copied in the first data structure and the identifier of the target file in the second data structure.
[0135] Optionally, the device further includes:
[0136] The third acquisition module is used to acquire the file identifier to be used corresponding to the file identifier use operation when a file identifier use operation is detected;
[0137] The first detection module is used to detect whether the file identifier to be used exists in the second data structure;
[0138] The fourth acquisition module is used to acquire the original file identifier corresponding to the file identifier to be used based on the identifier information in the file identifier to be used if the file identifier to be used exists in the second data structure.
[0139] The fifth acquisition module is used to access the target file and obtain the file structure information of the target file based on the original file identifier, wherein the original file identifier points to the target file;
[0140] The clearing module is used to fill the file structure information into the file identifier to be used and to clear the file identifier to be used in the second data structure.
[0141] Optionally, the clearing module includes:
[0142] The clearing submodule is used to set the flag position corresponding to the file identifier to be used in the second data structure to 0.
[0143] Optionally, the device further includes:
[0144] The sixth acquisition module is used to acquire the file identifier to be closed corresponding to the file identifier closing operation when a file identifier closing operation is detected;
[0145] The second detection module is used to detect whether the file identifier to be closed exists in the first data structure;
[0146] The third detection module is used to detect whether there is a file identifier pointing to the file identifier to be closed in the second data structure if the file identifier to be closed exists in the first data structure.
[0147] The seventh acquisition module is used to acquire the file identifier pointing to the file identifier to be closed in the second data structure if there is at least one file identifier pointing to the file identifier to be closed in the second data structure.
[0148] The backfill module is used to perform a backfill operation on the file identifier in the second data structure that points to the file identifier to be closed;
[0149] The first closing module is used to perform a closing operation on the file identifier to be closed and to clear the file identifier to be closed in the first data structure.
[0150] Optionally, the device further includes:
[0151] The fourth detection module is used to detect whether the file identifier to be closed exists in the second data structure if the file identifier to be closed does not exist in the first data structure.
[0152] The second closing module is used to perform a closing operation on the file identifier to be closed if the file identifier to be closed exists in the second data structure, and to clear the file identifier to be closed from the second data structure.
[0153] This invention provides a file identifier management device. This device can copy a file identifier to be copied to obtain a target file identifier. The target file identifier contains the identifier information of the file identifier to be copied, and the target file identifier points to the file identifier to be copied. If there are a large number of concurrent file identifier copying requests in the operating system for executing a file, the file identifier management method provided in this invention allows different processes to access only the file identifier to be copied within that process to obtain the identifier information. This avoids the situation where different processes access the same file structure simultaneously, thereby reducing system consistency overhead.
[0154] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0155] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0156] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0157] This invention provides an electronic device for managing file identifiers. The electronic device includes a memory and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by one or more processors. The one or more programs contain instructions for performing the following operations:
[0158] A11. When a file identifier copy operation is detected, obtain the file identifier to be copied corresponding to the file identifier copy operation;
[0159] A12. Obtain the identifier information of the identifier of the file to be copied;
[0160] A13. Create a new file identifier in the file identifier table;
[0161] A14. Fill the identifier information of the file identifier to be copied into the new file identifier to obtain the target file identifier; the target file identifier points to the file identifier to be copied.
[0162] Optionally, the electronic device is further configured to have one or more processors execute the one or more programs containing instructions for performing the following operations:
[0163] Create a first data structure and a second data structure, and associate the first data structure and the second data structure with the target process. The first data structure is used to record the file identifiers that have been copied in the target process, and the second data structure is used to record the file identifiers that have been copied but not yet used in the target process.
[0164] The identifier of the file to be copied is recorded in the first data structure, and the identifier of the target file is recorded in the second data structure.
[0165] Optionally, the electronic device is further configured to have one or more processors execute the one or more programs containing instructions for performing the following operations:
[0166] When a file identifier usage operation is detected, the file identifier to be used corresponding to the file identifier usage operation is obtained;
[0167] Detect whether the file identifier to be used exists in the second data structure;
[0168] If the file identifier to be used exists in the second data structure, then the original file identifier corresponding to the file identifier to be used is obtained according to the identifier information in the file identifier to be used;
[0169] The target file is accessed based on the original file identifier to obtain the file structure information of the target file, wherein the original file identifier points to the target file;
[0170] The file structure information is filled into the file identifier to be used, and the file identifier to be used is cleared in the second data structure.
[0171] Optionally, clearing the file identifier to be used in the second data structure includes:
[0172] Set the flag corresponding to the file identifier to be used in the second data structure to 0.
[0173] Optionally, the electronic device is further configured to have one or more processors execute the one or more programs containing instructions for performing the following operations:
[0174] When a file identifier close operation is detected, the file identifier to be closed corresponding to the file identifier close operation is obtained;
[0175] Detect whether the file identifier to be closed exists in the first data structure;
[0176] If the file identifier to be closed exists in the first data structure, then check if there is a file identifier pointing to the file identifier to be closed in the second data structure;
[0177] If the second data structure contains at least one file identifier that points to the file identifier to be closed, then obtain the file identifier that points to the file identifier to be closed from the second data structure;
[0178] Perform a backfilling operation on the file identifier in the second data structure that points to the file identifier to be closed;
[0179] Perform a close operation on the file identifier to be closed, and clear the file identifier to be closed from the first data structure.
[0180] Optionally, after detecting whether the file identifier to be closed exists in the first data structure, the electronic device is further configured to have one or more processors execute the one or more programs containing instructions for performing the following operations:
[0181] If the file identifier to be closed does not exist in the first data structure, then check if the file identifier to be closed exists in the second data structure.
[0182] If the file identifier to be closed exists in the second data structure, then a closing operation is performed on the file identifier to be closed, and the file identifier to be closed is cleared from the second data structure.
[0183] Figure 3 This is a structural block diagram illustrating an electronic device 300 for managing file identifiers according to an exemplary embodiment. For example, the electronic device 300 may be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.
[0184] Reference Figure 3 The electronic device 300 may include one or more of the following components: processing component 302, memory 304, power supply component 306, multimedia component 308, audio component 310, input / output (I / O) interface 312, sensor component 314, and communication component 316.
[0185] Processing component 302 typically controls the overall operation of electronic device 300, such as operations associated with display, telephone calls, data communication, camera operation, and recording operations. Processing component 302 may include one or more processors 320 to execute instructions to complete all or part of the steps of the methods described above. Furthermore, processing component 302 may include one or more modules to facilitate interaction between processing component 302 and other components. For example, processing component 302 may include a multimedia module to facilitate interaction between multimedia component 308 and processing component 302.
[0186] Memory 304 is configured to store various types of data to support the operation of electronic device 300. Examples of such data include instructions for any application or method operating on electronic device 300, contact data, phonebook data, messages, pictures, videos, etc. Memory 304 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0187] Power supply component 306 provides power to various components of electronic device 300. Power supply component 306 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to electronic device 300.
[0188] Multimedia component 308 includes a screen that provides an output interface between the electronic device 300 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 308 includes a front-facing camera and / or a rear-facing camera. When the electronic device 300 is in an operating mode, such as a shooting mode or a video mode, the front-facing camera and / or the rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0189] Audio component 310 is configured to output and / or input audio signals. For example, audio component 310 includes a microphone (MIC) configured to receive external audio signals when electronic device 300 is in an operating mode, such as call mode, recording mode, and voice information processing mode. The received audio signals may be further stored in memory 304 or transmitted via communication component 316. In some embodiments, audio component 310 also includes a speaker for outputting audio signals.
[0190] I / O interface 312 provides an interface between processing component 302 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0191] Sensor assembly 314 includes one or more sensors for providing state assessments of various aspects of electronic device 300. For example, sensor assembly 314 may detect the on / off state of electronic device 300, the relative positioning of components such as the display and keypad of device 300, changes in position of electronic device 300 or a component of electronic device 300, the presence or absence of user contact with electronic device 300, orientation or acceleration / deceleration of electronic device 300, and temperature changes of electronic device 300. Sensor assembly 314 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 314 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 314 may also include an accelerometer, gyroscope, magnetometer, pressure sensor, or temperature sensor.
[0192] Communication component 316 is configured to facilitate wired or wireless communication between electronic device 300 and other devices. Electronic device 300 can access wireless networks based on communication standards, such as WiFi, 2G, or 3G, or combinations thereof. In one exemplary embodiment, communication component 316 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 316 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency information processing (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0193] In an exemplary embodiment, the electronic device 300 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the methods described above.
[0194] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 304 including instructions, which can be executed by a processor 320 of an electronic device 300 to perform the above-described method. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0195] A non-transitory computer-readable storage medium that, when instructions in the storage medium are executed by a processor of an electronic device (server or terminal), enables the processor to perform... Figure 1 The document illustrates the method for managing file identifiers.
[0196] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0197] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0198] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0199] These computer program instructions may also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing terminal device to operate in a predictive manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0200] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0201] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.
[0202] Finally, 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 terminal device 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 terminal device. 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 terminal device that includes said element.
[0203] The foregoing has provided a detailed description of a file identifier management method, apparatus, and electronic device provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for managing file identifiers, characterized in that, The method includes: When a file identifier copy operation is detected, the file identifier to be copied corresponding to the file identifier copy operation is obtained; Obtain the identifier information of the file identifier to be copied; the identifier information of the file identifier to be copied is the process to which the file identifier to be copied belongs and the file identifier ID of the file identifier to be copied; Create a new file identifier in the file identifier table; The identifier information of the file identifier to be copied is filled into the new file identifier to obtain the target file identifier; the target file identifier points to the file identifier to be copied; the backfilling operation of the target file identifier is postponed until the first time the target file identifier is used; The method further includes: creating a first data structure for recording file identifiers that have been copied in the target process, and creating a second data structure for recording file identifiers that have been copied but not yet used in the target process; When a file identifier usage operation is detected, if the file identifier to be used is located in the second data structure, the original file identifier corresponding to the file identifier to be used is obtained according to the identifier information in the file identifier to be used, and the file structure information is obtained according to the original file identifier and filled into the file identifier to be used. When a file identifier closing operation is detected, if the file identifier to be closed is located in the first data structure, then a backfilling operation is performed on all file identifiers in the second data structure that point to the file identifier to be closed, and then the file identifier to be closed is closed.
2. The method according to claim 1, characterized in that, The method further includes: Create a first data structure and a second data structure, and associate the first data structure and the second data structure with the target process. The first data structure is used to record the file identifiers that have been copied in the target process, and the second data structure is used to record the file identifiers that have been copied but not yet used in the target process. The identifier of the file to be copied is recorded in the first data structure, and the identifier of the target file is recorded in the second data structure.
3. The method according to claim 2, characterized in that, The method further includes: When a file identifier usage operation is detected, the file identifier to be used corresponding to the file identifier usage operation is obtained; Detect whether the file identifier to be used exists in the second data structure; If the file identifier to be used exists in the second data structure, then the original file identifier corresponding to the file identifier to be used is obtained according to the identifier information in the file identifier to be used; The target file is accessed based on the original file identifier to obtain the file structure information of the target file, wherein the original file identifier points to the target file; The file structure information is filled into the file identifier to be used, and the file identifier to be used is cleared in the second data structure.
4. The method according to claim 3, characterized in that, The step of clearing the unused file identifier in the second data structure includes: Set the flag corresponding to the file identifier to be used in the second data structure to 0.
5. The method according to claim 2, characterized in that, The method further includes: When a file identifier close operation is detected, the file identifier to be closed corresponding to the file identifier close operation is obtained; Detect whether the file identifier to be closed exists in the first data structure; If the file identifier to be closed exists in the first data structure, then check if there is a file identifier pointing to the file identifier to be closed in the second data structure; If the second data structure contains at least one file identifier that points to the file identifier to be closed, then obtain the file identifier that points to the file identifier to be closed from the second data structure; Perform a backfilling operation on the file identifier in the second data structure that points to the file identifier to be closed; Perform a close operation on the file identifier to be closed, and clear the file identifier to be closed from the first data structure.
6. The method according to claim 5, characterized in that, After detecting whether the file identifier to be closed exists in the first data structure, the method further includes: If the file identifier to be closed does not exist in the first data structure, then check if the file identifier to be closed exists in the second data structure. If the file identifier to be closed exists in the second data structure, then a closing operation is performed on the file identifier to be closed, and the file identifier to be closed is cleared from the second data structure.
7. A file identifier management device, characterized in that, The device includes: The first acquisition module is used to acquire the file identifier to be copied corresponding to the file identifier copy operation when a file identifier copy operation is detected. The second acquisition module is used to acquire the identifier information of the file identifier to be copied; the identifier information of the file identifier to be copied is the process to which the file identifier to be copied belongs and the file identifier ID of the file identifier to be copied. Create a module to create a new file identifier in the file identifier table; The copy module is used to fill the identifier information of the file identifier to be copied into the new file identifier to obtain the target file identifier; the target file identifier points to the file identifier to be copied; the backfilling operation of the target file identifier is delayed until the first time the target file identifier is used; The apparatus further includes: creating a first data structure for recording file identifiers that have been copied in the target process, and creating a second data structure for recording file identifiers that have been copied but not yet used in the target process; When a file identifier usage operation is detected, if the file identifier to be used is located in the second data structure, the original file identifier corresponding to the file identifier to be used is obtained according to the identifier information in the file identifier to be used, and the file structure information is obtained according to the original file identifier and filled into the file identifier to be used. When a file identifier closing operation is detected, if the file identifier to be closed is located in the first data structure, then a backfilling operation is performed on all file identifiers in the second data structure that point to the file identifier to be closed, and then the file identifier to be closed is closed.
8. The apparatus according to claim 7, characterized in that, The device further includes: A data structure creation module is used to create a first data structure and a second data structure, and associate the first data structure and the second data structure with a target process. The first data structure is used to record file identifiers that have been copied in the target process, and the second data structure is used to record file identifiers that have been copied but not yet used in the target process. The recording module is used to record the identifier of the file to be copied in the first data structure and the identifier of the target file in the second data structure.
9. An electronic device, characterized in that, The electronic device includes a memory and one or more programs, wherein one or more programs are stored in the memory and configured to be executed by one or more processors using the file identifier management method as described in any one of claims 1 to 6.
10. A readable storage medium, characterized in that, When the instructions in the storage medium are executed by the processor of the electronic device, the processor is enabled to perform the file identifier management method as described in any one of claims 1 to 6.