A method, device, electronic device and medium for reading data in a storage medium
By detecting the logical partition and partition type of the removable storage medium and identifying the file system type, it solves the problem of file system reading that cannot be recognized by Windows and Linux systems, and achieves convenient data reading and security guarantee.
Patent Information
- Application Number
- CN202210631076.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-06
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-06-06
AI Technical Summary
Existing technology cannot effectively identify and read EXT file systems that cannot be recognized by Windows systems and file systems that cannot be recognized by Linux systems, causing users inconvenience when reading data in removable storage media.
By detecting the number and capacity of logical partitions when moving storage media, determine the starting physical sector, determine the partition type, read the identification information to determine the file system type, and then read the files in the file system.
It realizes reading of unrecognized file systems, improves the convenience for users to read data from mobile storage media, and improves data security through virus detection and key matching.
Smart Images

Figure CN114968121B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data storage, and in particular to a method, device, electronic device and medium for reading data in a storage medium. Background Art
[0002] Windows and Linux are two commonly used systems. However, the two systems can recognize different file systems. When using a removable storage medium to store data, the removable storage medium may contain a file system that the Windows system cannot recognize or a file system that the Linux system cannot recognize.
[0003] Currently, when reading files in a mobile storage medium, the mobile storage medium needs to be connected to a computer device. Due to limitations of the computer device system, the computer device cannot recognize a file system that it cannot recognize, and thus cannot read files in that file system. For example, a computer device under a Windows system does not support the EXT file system, and thus cannot read files under the EXT file system in the mobile storage medium, thus causing inconvenience to users in reading data in the mobile storage medium. Summary of the invention
[0004] In order to facilitate reading of files in a file system that cannot be recognized by a computer device, the present application provides a method, device, electronic device and medium for reading data in a storage medium.
[0005] In a first aspect, the present application provides a method for reading data in a storage medium, using the following technical solution:
[0006] A method for reading data in a storage medium, comprising:
[0007] When the mobile storage medium is detected to be connected, the number of logical partitions in the mobile storage medium and the capacity of each logical partition are obtained;
[0008] Determining a starting physical sector of at least one logical partition based on the number of the logical partitions and the capacity of each logical partition;
[0009] determining a partition type of the at least one logical partition based on a starting physical sector of the at least one logical partition;
[0010] Determining a designated physical sector corresponding to the at least one logical partition according to the partition type, wherein identification information is stored in the designated physical sector;
[0011] A file system type corresponding to the at least one logical partition is determined based on the identification information.
[0012] By adopting the above technical solution, when the access of the mobile storage medium is detected, it means that the file in the mobile storage medium is to be read or written, so the number of at least one logical partition and the capacity of at least one logical partition in the mobile storage medium are obtained. After obtaining the capacity of the first logical partition, since the starting physical sector corresponding to the first logical partition starts from the physical sector No. 0, the address of the last physical sector corresponding to the first logical partition can be determined according to the capacity of the first logical partition, that is, when determining the starting physical sector address of the current logical partition, it can be determined according to the last physical sector corresponding to the previous logical partition of the logical partition, so that the corresponding partition type can be determined based on the starting physical sector of each logical partition, and then the identification information can be obtained according to the specified physical sector of each logical partition to determine the file system type of the logical partition, that is, the file in the file system can be read, so that it is convenient for users to read files in the mobile storage medium.
[0013] In another possible implementation, determining the partition type of any logical partition based on the starting physical sector of any logical partition includes:
[0014] Reading a starting physical sector corresponding to any logical partition to obtain first data information of the starting physical sector, wherein the first data information at least includes data of a first specified byte and data of a second specified byte;
[0015] If the data of the first designated byte belongs to the first preset identifier, reading the next physical sector of the starting physical sector to obtain second data information;
[0016] If the data of the designated bytes in the second data information belongs to the second preset identifier, determining whether any of the logical partitions has a sub-logical partition;
[0017] If so, determining that any of the logical partitions belongs to a GPT partition;
[0018] If it does not exist, and the data of the second designated byte is not 0, it is determined that any of the logical partitions belongs to the MBR partition;
[0019] If it does not exist, and the data of the second designated byte is 0, it is determined that any one of the logical partitions is of the non-partition type.
[0020] By adopting the above technical solution, the first data information of the starting physical sector is read, and the first data information includes part of the data representing the partition type, that is, if the data of the first specified byte belongs to the first preset identifier, the logical partition may belong to the GPT partition. The next physical sector of the starting physical sector is read to obtain the second data information, and the second data information includes another part of the data representing the partition type, that is, if the data of the specified byte in the second data information belongs to the second preset identifier, and the data of the first specified byte belongs to the first preset identifier, then it is determined whether the logical partition has a sub-logical partition, and if so, it is determined that the logical partition belongs to the GPT partition.
[0021] If there is no sub-logical partition and the data of the second designated byte is not 0, it is determined that the logical partition belongs to the MBR partition. If there is no sub-logical partition and the data of the second designated byte is 0, it is determined that the logical partition does not belong to the MBR partition, that is, the logical partition belongs to the non-partition type. It is more accurate to judge the partition type by reading the starting physical sector and judging whether the logical partition has a sub-logical partition.
[0022] In another possible implementation, the first data information includes a first identifier, and a designated physical sector corresponding to any logical partition is determined according to the partition type, wherein the designated physical sector stores the identifier information; and determining the file system type corresponding to any logical partition based on the identifier information includes:
[0023] If any of the logical partitions is of the non-partition type, the starting physical sector is determined to be the designated physical sector, and if the first identifier is a first preset file system identifier, the file system type of any of the logical partitions is determined to be a file system type corresponding to the first identifier in the first preset file system identifier, wherein the first preset file system identifier includes: an identifier corresponding to the NTFS file system, an identifier corresponding to the FAT12 file system, an identifier corresponding to the FAT16 file system, an identifier corresponding to the FAT32 file system, and an identifier corresponding to the exFAT file system; or,
[0024] If any of the logical partitions belongs to a GPT partition or an MBR partition, a specified physical sector corresponding to the GPT partition or a specified physical sector corresponding to the MBR partition is read to obtain a starting logical sector address of at least one sub-logical partition and a capacity of at least one sub-logical partition, so as to determine at least one target sub-logical partition;
[0025] Reading the starting logical sector of each target sub-logical partition to obtain a second identifier corresponding to each target sub-logical partition;
[0026] If the second identifier belongs to the first preset file system identifier, determining the file system type of each target sub-logical partition to be the file system type corresponding to the second identifier in the first preset file system identifier;
[0027] If the second identifier does not belong to the first preset file system identifier, reading a designated logical sector other than a starting logical sector corresponding to each target sub-logical partition to obtain a third identifier;
[0028] If the third identifier belongs to the second preset file system identifier, the file system type of each target sub-logical partition is determined to be the file system type corresponding to the third identifier in the second preset file system identifier, and the second preset file system identifier includes: an identifier corresponding to the EXT2 file system, an identifier corresponding to the EXT3 file system, and an identifier corresponding to the EXT4 file system.
[0029] By adopting the above technical solution, if the logical partition is of the non-partition type, it means that the logical partition does not have a sub-logical partition. Therefore, the file system type of the logical partition can be determined according to the first preset file system identifier described in the first identifier in the first data information.
[0030] If the logical partition belongs to an MBR partition or a GPT partition, the specified physical sector is read to obtain the starting logical sector address of at least one sub-logical partition and the capacity of at least one sub-logical partition, so that at least one target sub-logical sector can be determined. In order to determine the file system type of the target sub-logical partition, the starting logical sector of any target sub-logical partition is read to obtain a second identifier. If the second identifier belongs to the first preset file system identifier, it is determined that the target sub-logical partition belongs to one of the identifiers corresponding to the NTFS file system, the identifier corresponding to the FAT12 file system, the identifier corresponding to the FAT16 file system, the identifier corresponding to the FAT32 file system, and the identifier corresponding to the exFAT file system. If the second identifier does not belong to the first preset file system identifier, the specified logical sector other than the starting logical sector is read to obtain a third identifier. If the third identifier belongs to the second preset file system identifier, it is determined that the file system of the target sub-logical partition belongs to one of the EXT2 file system, the EXT3 file system, and the EXT4 file system.
[0031] In another possible implementation manner, the determining the file system type corresponding to the at least one logical partition based on the identification information further includes:
[0032] Obtaining files in the at least one logical partition;
[0033] Storing the file;
[0034] When an instruction to send a file is received, the file is sent.
[0035] By adopting the above technical solution, after the file system type is determined, the files in the logical partition are obtained and stored. When an instruction to send a file is received from a computer device, it means that the computer device allows the file to be sent, and the file can be sent. By receiving an instruction to send a file, the file is sent, making the reading of files in the mobile storage medium more orderly.
[0036] In another possible implementation, the method further includes:
[0037] If a write request instruction is detected, the key information is obtained;
[0038] If the key information matches the preset key information, it is determined that the state of the mobile storage medium is a writing state.
[0039] By adopting the above technical solution, if a write request instruction is received, the key information transmitted by the computer device is obtained, and the key information is matched with the preset key information. If the match is successful, it is determined that the write request operation is legal, and the state of the storage medium is determined to be a write state. By obtaining the key and comparing the obtained key with the preset key, it is determined whether to enter the write state, thereby making the use of the mobile storage medium safer.
[0040] In another possible implementation, when the mobile storage medium is detected to be connected, the method further includes:
[0041] Determine whether there is a target file system type among all file system types of the mobile storage medium, wherein the target file system type includes a file system type that can be recognized by both Windows system and Linux system;
[0042] If so, a signal indicating that the target file system type exists in the mobile storage medium is output.
[0043] By adopting the above technical solution, after the mobile storage medium is connected, it is determined whether the target file system type exists in all file system types in the mobile storage medium. If so, a signal indicating that the target file system type exists in the mobile storage medium is output, so that the computer device knows that the target file system type exists in the mobile storage medium, and it is convenient for users to know that the target file system type exists in the mobile storage medium. Users store files through the target file system type, which makes it convenient to read files when the mobile storage medium is subsequently connected to a Windows system computer device or a Linux system computer device separately, and it is more convenient to read files later.
[0044] In another possible implementation, the method further includes at least one of the following:
[0045] If the mobile storage medium is in a reading state, the file name of the file to be read is obtained, and it is determined whether the file name of the file to be read matches the preset virus name. If so, the reading of the file to be read is stopped;
[0046] If the mobile storage medium is in a writing state, the file name of the file to be written is obtained, and it is determined whether the file name of the file to be written matches the preset virus name. If they match, the file to be written is deleted.
[0047] By adopting the above technical solution, when the mobile storage medium is in a reading state, the file name of the file to be read is obtained. If the file name successfully matches the preset virus name, it means that the file to be read is a virus file, and the control stops reading the file to be read, thereby reducing the possibility of the computer device entering a virus. When the mobile storage medium is in a writing state, the file name to be written is obtained. If the file name successfully matches the preset virus name, it means that the file to be written is a virus file, and the control deletes the file to be written, so that the file cannot be written to the mobile storage medium, reducing the risk of the mobile storage medium being infected with a virus.
[0048] In a second aspect, the present application provides a device for reading data in a storage medium, which adopts the following technical solution:
[0049] A device for reading data in a storage medium, comprising:
[0050] An information acquisition module, used for acquiring the number of logical partitions in the mobile storage medium and the capacity of each logical partition when detecting access to the mobile storage medium;
[0051] A starting physical sector determination module, used to determine a starting physical sector of at least one logical partition based on the number of the logical partitions and the capacity of each logical partition;
[0052] A partition type determination module, configured to determine a partition type of the at least one logical partition based on a starting physical sector of the at least one logical partition;
[0053] an identification determination module, configured to determine, according to the partition type, a designated physical sector corresponding to the at least one logical partition, wherein the designated physical sector stores identification information;
[0054] The file system determination module is used to determine the file system type corresponding to the at least one logical partition based on the identification information.
[0055] By adopting the above technical solution, when the mobile storage medium is detected to be connected, it means that the file in the mobile storage medium is to be read or written, so the information acquisition module obtains the number of at least one logical partition and the capacity of at least one logical partition in the mobile storage medium. After obtaining the capacity of the first logical partition, since the starting physical sector corresponding to the first logical partition starts from the physical sector No. 0, the address of the last physical sector corresponding to the first logical partition can be determined according to the capacity of the first logical partition, that is, the starting physical sector determination module can determine the starting physical sector address of the current logical partition according to the last physical sector corresponding to the previous logical partition of the logical partition, and the partition type determination module can determine the corresponding partition type based on the starting physical sector of each logical partition, and the identification determination module can obtain the identification information according to the specified physical sector of each logical partition, so that the file system determination module can determine the file system type of the logical partition, that is, it can read the files in the file system, and thus facilitate the user to read the files in the mobile storage medium.
[0056] In another possible implementation, when the partition type determination module determines the partition type of any logical partition based on the starting physical sector of any logical partition, it is specifically configured to:
[0057] Reading a starting physical sector corresponding to any logical partition to obtain first data information of the starting physical sector, wherein the first data information at least includes data of a first specified byte and data of a second specified byte;
[0058] If the data of the first designated byte belongs to the first preset identifier, reading the next physical sector of the starting physical sector to obtain second data information;
[0059] If the data of the designated bytes in the second data information belongs to the second preset identifier, determining whether any of the logical partitions has a sub-logical partition;
[0060] If so, determining that any of the logical partitions belongs to a GPT partition;
[0061] If it does not exist, and the data of the second designated byte is not 0, it is determined that any of the logical partitions belongs to the MBR partition;
[0062] If it does not exist, and the data of the second designated byte is 0, it is determined that any one of the logical partitions is of the non-partition type.
[0063] In another possible implementation, the first data information includes a first identifier, and the identifier determination module and the file system determination module determine, according to the partition type, a designated physical sector corresponding to any logical partition, wherein the designated physical sector stores the identifier information; and when determining the file system type corresponding to any logical partition based on the identifier information, are specifically used to:
[0064] If any of the logical partitions is of the non-partition type, the starting physical sector is determined to be the designated physical sector, and if the first identifier is a first preset file system identifier, the file system type of any of the logical partitions is determined to be a file system type corresponding to the first identifier in the first preset file system identifier, wherein the first preset file system identifier includes: an identifier corresponding to the NTFS file system, an identifier corresponding to the FAT12 file system, an identifier corresponding to the FAT16 file system, an identifier corresponding to the FAT32 file system, and an identifier corresponding to the exFAT file system; or,
[0065] If any of the logical partitions belongs to a GPT partition or an MBR partition, a specified physical sector corresponding to the GPT partition or a specified physical sector corresponding to the MBR partition is read to obtain a starting logical sector address of at least one sub-logical partition and a capacity of at least one sub-logical partition, so as to determine at least one target sub-logical partition;
[0066] Reading the starting logical sector of each target sub-logical partition to obtain a second identifier corresponding to each target sub-logical partition;
[0067] If the second identifier belongs to the first preset file system identifier, determining the file system type of each target sub-logical partition to be the file system type corresponding to the second identifier in the first preset file system identifier;
[0068] If the second identifier does not belong to the first preset file system identifier, reading a designated logical sector other than a starting logical sector corresponding to each target sub-logical partition to obtain a third identifier;
[0069] If the third identifier belongs to the second preset file system identifier, the file system type of each target sub-logical partition is determined to be the file system type corresponding to the third identifier in the second preset file system identifier, and the second preset file system identifier includes: an identifier corresponding to the EXT2 file system, an identifier corresponding to the EXT3 file system, and an identifier corresponding to the EXT4 file system.
[0070] In another possible implementation, the device further includes:
[0071] A file acquisition module, used to acquire files in the at least one logical partition;
[0072] A storage module, used for storing the file;
[0073] The file sending module is used to send the file when receiving an instruction to send the file.
[0074] In another possible implementation, the device further includes:
[0075] A key acquisition module, used to acquire key information when a write request instruction is detected;
[0076] The state determination module is used to determine that the state of the mobile storage medium is a writing state when the secret key information matches the preset secret key information.
[0077] In another possible implementation, the device further includes:
[0078] A judging module, used for judging whether there is a target file system type among all file system types of the mobile storage medium, wherein the target file system type includes a file system type that can be recognized by both Windows system and Linux system;
[0079] The signal output module is used to output a signal indicating that a target file system type exists in the mobile storage medium when the signal exists.
[0080] In another possible implementation manner, the device further includes at least one of a control module and a deletion module:
[0081] A control module, used for obtaining the file name of the file to be read when the mobile storage medium is in a reading state, judging whether the file name of the file to be read matches a preset virus name, and if so, controlling to stop reading the file to be read;
[0082] The deletion module is used to obtain the file name of the file to be written when the mobile storage medium is in a writing state, and to determine whether the file name of the file to be written matches the preset virus name. If they match, the file to be written is deleted.
[0083] In a third aspect, the present application provides an electronic device, which adopts the following technical solution:
[0084] An electronic device, comprising:
[0085] one or more processors;
[0086] Memory;
[0087] One or more applications, wherein one or more applications are stored in a memory and configured to be executed by one or more processors, and the one or more applications are configured to: execute a method for reading data in a storage medium as shown in any possible implementation of the first aspect.
[0088] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution:
[0089] A computer-readable storage medium, when the computer program is executed in a computer, causes the computer to execute a method for reading data in a storage medium as described in any one of the first aspects.
[0090] In summary, the present application includes at least one of the following beneficial technical effects:
[0091] 1. When the access of the mobile storage medium is detected, it means that the files in the mobile storage medium are to be read or written, so the number of at least one logical partition and the capacity of at least one logical partition in the mobile storage medium are obtained. After obtaining the capacity of the first logical partition, since the starting physical sector corresponding to the first logical partition starts from physical sector 0, the address of the last physical sector corresponding to the first logical partition can be determined according to the capacity of the first logical partition, that is, when determining the starting physical sector address of the current logical partition, it can be determined according to the last physical sector corresponding to the previous logical partition of the logical partition, so that the corresponding partition type can be determined based on the starting physical sector of each logical partition, and then the identification information can be obtained according to the specified physical sector of each logical partition to determine the file system type of the logical partition, that is, the files in the file system can be read, so that it is convenient for users to read files in the mobile storage medium;
[0092] 2. When the mobile storage medium is in the reading state, the file name of the file to be read is obtained. If the file name matches the preset virus name successfully, it means that the file to be read is a virus file, and the control stops reading the file to be read, thereby reducing the possibility of the computer device entering the virus. When the mobile storage medium is in the writing state, the file name to be written is obtained. If the file name matches the preset virus name successfully, it means that the file to be written is a virus file, and the control deletes the file to be written, so that the file cannot be written to the mobile storage medium, reducing the risk of the mobile storage medium being infected with viruses. BRIEF DESCRIPTION OF THE DRAWINGS
[0093] Figure 1 It is a flowchart of a method for reading data in a storage medium according to an embodiment of the present application.
[0094] Figure 2It is a structural schematic diagram of a device for reading data in a storage medium according to an embodiment of the present application.
[0095] Figure 3 It is a structural schematic diagram of an electronic device according to an embodiment of the present application.
[0096] Figure 4 It is a structural schematic diagram of a mobile storage medium reading system according to an embodiment of the present application. DETAILED DESCRIPTION
[0097] The present application is further described in detail below in conjunction with the accompanying drawings.
[0098] After reading this specification, those skilled in the art may make non-creative modifications to this embodiment as needed, but such modifications are protected by patent law as long as they are within the scope of the claims of this application.
[0099] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0100] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.
[0101] The embodiments of the present application are further described in detail below in conjunction with the drawings in the specification.
[0102] The present application embodiment provides a method for reading data in a storage medium, which is performed by an electronic device, and the electronic device is applied between a computer device and a mobile storage medium, and is respectively connected to the computer device and the mobile storage medium for communication. Figure 1 As shown, the method includes step S101, step S102, step S103, step S104 and step S105, wherein:
[0103] Step S101, when it is detected that a mobile storage medium is connected, the number of logical partitions in the mobile storage medium and the capacity of each logical partition are obtained.
[0104] For the embodiment of the present application, two interfaces can be provided on the electronic device. One interface is connected to the mobile storage medium, and the other interface is connected to the computer device. Both interfaces can be USB interfaces, T-type interfaces, TYPE-C interfaces, etc. When in use, one end of the electronic device is connected to the computer device through the interface, and the other end is connected to the mobile storage medium through the interface. The electronic device can determine whether the mobile storage medium is connected to the electronic device by detecting the electrical level of the interface. When the electronic device detects that the electrical level of the interface changes, it indicates that the electronic device is connected to the mobile storage medium.
[0105] After detecting that the mobile storage medium is connected to the electronic device, the electronic device can send a setup command to the mobile storage medium to enumerate the relevant information of the mobile storage medium. For example, by accessing the chip storing the relevant information in the mobile storage medium, the relevant information of the mobile storage medium, such as the device descriptor, interface descriptor, port descriptor, string descriptor, storage medium configuration and interface, storage medium address and configuration descriptor, etc., can be obtained.
[0106] After the electronic device obtains the relevant information of the mobile storage medium, it can send an instruction to obtain the number of logical partitions to the mobile storage medium. For example, it can send an instruction of A1 FE 00 00 00 00 01 00 to the mobile storage medium to obtain the number of logical partitions in the mobile storage medium. The electronic device sends a standard SCSI command to the mobile storage medium according to the number of logical partitions to obtain the capacity of each logical partition. After obtaining the capacity of each logical partition, it can be convenient to determine the starting physical address of each logical partition in combination with the number of logical partitions.
[0107] Step S102: determining a starting physical sector of at least one logical partition based on the number of logical partitions and the capacity of each logical partition.
[0108] For the embodiment of the present application, the starting physical sector address of each logical partition can be obtained according to the capacity of each logical partition and the number of logical partitions. For example, the mobile storage medium has two logical partitions, and the starting physical sector of the first logical partition is physical sector 0. Assuming that the capacity of the first logical partition is 100 physical sectors, the address of the physical sector at the end of the logical partition is physical sector 99, that is, the starting physical sector of the second logical partition is physical sector 100.
[0109] Step S103: determining the partition type of at least one logical partition based on the starting physical sector of at least one logical partition.
[0110] For the embodiment of the present application, after the electronic device determines the starting physical sector address of each logical partition, since the data in the starting physical sector and the specified physical sector can characterize the partition type of the logical partition, the partition type corresponding to the logical partition can be determined according to the starting physical sector and the specified physical sector. The partition type may include a non-partition type, a GPT partition, and an MBR partition. After determining the partition type corresponding to the logical partition, it is convenient to subsequently determine the file system type in the logical partition.
[0111] Step S104: determining a designated physical sector corresponding to at least one logical partition according to the partition type.
[0112] The identifier is stored in the designated physical sector.
[0113] For the embodiment of the present application, the data about the file system type is recorded in the designated physical sector corresponding to the logical partition. Therefore, after determining the partition type, the designated physical sector corresponding to the partition type is determined according to the partition type corresponding to the logical partition, and the identification information about the file system type can be obtained.
[0114] Step S105: determining a file system type corresponding to at least one logical partition based on the identification information.
[0115] For the embodiment of the present application, the identification information is used to characterize the file system type. Therefore, after obtaining the identification information, the file system type corresponding to the logical partition can be determined according to the identification information. After the electronic device determines the file system type, it means that the electronic device can identify the file system type in the mobile storage medium, and then can read the files in the file system. The electronic device can assist the computer device in identifying the file system in the mobile storage medium that the computer device cannot recognize, thereby achieving the effect of reading files in the unrecognizable file system.
[0116] A possible implementation of the embodiment of the present application is to determine the partition type of any logical partition based on the starting physical sector of any logical partition, specifically including step S1031 (not shown in the figure), step S1032 (not shown in the figure), step S1033 (not shown in the figure), step S1034 (not shown in the figure), step S1035 (not shown in the figure) and step S1036 (not shown in the figure), wherein, when the number of logical partitions is two or more, each logical partition may determine the partition type corresponding to each logical partition in the manner corresponding to the embodiment of steps S1031 to S1035, wherein,
[0117] Step S1031, reading a starting physical sector corresponding to any logical partition to obtain first data information of the starting physical sector.
[0118] The first data information at least includes data of a first specified byte and data of a second specified byte.
[0119] For the embodiment of the present application, part of the data for determining the partition type to which the logical partition belongs is recorded in the starting physical sector. The electronic device reads the starting physical sector to obtain all the data in the starting physical sector, i.e., the first data information. For example, the starting physical sector has a total of 512 bytes, and the first data information includes 512 bytes and data corresponding to each byte. The first designated byte and the second designated byte are both designated bytes of a specific length in the 512 bytes.
[0120] Step S1032: if the data of the first designated byte belongs to the first preset identifier, read the next physical sector of the starting physical sector to obtain the second data information.
[0121] For the embodiment of the present application, taking the starting physical sector with 512 bytes as an example, assuming that the first preset identifier includes "EE" and "55AA", the first designated byte is the 450th byte and the 511th and 512th bytes in the first data information. The electronic device determines whether the data of the first designated byte is "EE, 55 and AA". If the first designated byte belongs to the first preset identifier, it means that the partition type of the logical partition may be a GPT partition.
[0122] If the first data information determines that the partition type of the logical partition may be a GPT partition, in order to further and more accurately determine the partition type, the electronic device reads the next physical sector of the starting physical sector to obtain the second data information. The electronic device further determines whether the partition type of the logical partition is a GPT partition based on the second data information.
[0123] Step S1033: If the data of the designated bytes in the second data information belongs to the second preset identifier, it is determined whether any logical partition has a sub-logical partition.
[0124] Step S1034: If it exists, determine whether any logical partition belongs to a GPT partition.
[0125] For the embodiment of the present application, it is assumed that the second preset identifier is the identifier corresponding to the "EFI PART" character, and the specified bytes of the second data information are the first eight bytes in the second data information. The electronic device determines whether the specified bytes in the second data information belong to the identifier corresponding to the "EFI PART" character. If it does, it means that the partition type of the logical partition is likely to be a GPT partition. The electronic device determines whether the logical partition has a sub-logical partition. If it does, it means that the partition type of the logical partition is a GPT partition. If there is no sub-logical partition, it means that there is no file system type, and further indicates that the logical partition does not belong to a GPT partition.
[0126] The existence of a sub-logical partition can be determined by reading the specified physical sector. For example, if the capacity and the starting physical sector address of the sub-logical partition can be read from the physical sectors 2 to 33, it is determined that the sub-logical partition exists, and the partition type can be determined to be a GPT partition.
[0127] Step S1035: If it does not exist, and the data of the second designated byte is not 0, it is determined that any logical partition belongs to the MBR partition.
[0128] For the embodiment of the present application, when the electronic device determines that there is no sub-logical partition in the logical partition, it determines whether the data of the second designated byte is 0. Assuming that the second designated byte is bytes 459 to 462, bytes 475 to 478, bytes 491 to 494, and bytes 507 to 510 in the first data information, if the data of the second designated bytes are not 0, that is, there is valid data in the second designated bytes, then the partition type of the logical partition is determined to be an MBR partition.
[0129] Step S1036: If it does not exist, and the data of the second designated byte is 0, it is determined that any logical partition is of the non-partition type.
[0130] For the embodiment of the present application, if there is no sub-logical partition in the logical partition and the data of the second specified byte is 0, it is determined that the logical partition does not belong to a GPT partition or an MBR partition, that is, the logical partition is a non-partition type, that is, the file system type of the logical partition can be determined by reading the physical sector.
[0131] In a possible implementation of the embodiment of the present application, the first data information includes a first identifier, and a designated physical sector corresponding to any logical partition is determined according to the partition type, and the designated physical sector stores the identifier information; based on the identifier information, the file system type corresponding to any logical partition is determined, specifically including step SA (not shown in the figure). When the number of logical partitions is two or more, each logical partition can determine the designated physical sector corresponding to each logical partition in the manner of the embodiment corresponding to step SA, wherein:
[0132] Step SA, if any logical partition is of the non-partition type, the starting physical sector is determined to be the specified physical sector; if the first identifier belongs to the first preset file system identifier, the file system type of any logical partition is determined to be the file system type corresponding to the first identifier in the first preset file system identifier.
[0133] Among them, the first preset file system identifier includes: an identifier corresponding to the NTFS file system, an identifier corresponding to the FAT12 file system, an identifier corresponding to the FAT16 file system, an identifier corresponding to the FAT32 file system, and an identifier corresponding to the exFAT file system.
[0134] For the embodiment of the present application, if the partition type of the logical partition is a non-partition type, the electronic device determines the starting physical sector as a specified physical sector, and the first identifier representing the file system type is located in the first data information, so the electronic device determines whether the first identifier belongs to the first preset file system identifier. If it does, it means that the file system of the logical partition is the file system corresponding to the first identifier. The first preset file system identifier includes identifiers corresponding to the NTFS file system and the FAT file system. If the first identifier belongs to the identifier corresponding to the NTFS file system or the identifier corresponding to the FAT file system, it is determined that the file system of the logical partition is the NTFS file system or the FAT file system.
[0135] A possible implementation of the embodiment of the present application is to determine a designated physical sector corresponding to any logical partition according to the partition type, wherein the designated physical sector stores identification information; determine a file system type corresponding to any logical partition based on the identification information, specifically including step SB (not shown in the figure), step SC (not shown in the figure), step SD (not shown in the figure), step SE (not shown in the figure) and step SF (not shown in the figure), wherein when the number of logical partitions is two or more, each logical partition can determine the file system type corresponding to each logical partition in the manner of the corresponding embodiment of steps SB to SF, wherein,
[0136] Step SB, if any logical partition belongs to a GPT partition or an MBR partition, read the specified physical sector corresponding to the GPT partition or the specified physical sector corresponding to the MBR partition, obtain the starting logical sector address of at least one sub-logical partition and the capacity of at least one sub-logical partition, so as to determine at least one target sub-logical partition.
[0137] For the embodiment of the present application, if the logical partition belongs to an MBR partition or a GPT partition, the corresponding designated physical sector needs to be read to obtain the starting physical sector address of at least one sub-logical partition and the capacity of each sub-logical partition. For example, the GPT partition reads the physical sector 2 to the physical sector 33, and the MBR partition reads the physical sector 2 to the physical sector 5.
[0138] The target sub-logical partition is determined according to the starting physical sector address of each sub-logical partition and the capacity of each sub-logical partition. After the target sub-logical partition is determined, the file system type corresponding to each target sub-logical partition can be determined.
[0139] Step SC: read the starting logical sector of each target sub-logical partition to obtain a second identifier corresponding to each target sub-logical partition.
[0140] For the embodiment of the present application, after the target sub-logical partition is determined, the starting logical sector of any target sub-logical partition is read, and the starting logical sector records the identifier of the file system type of the target sub-logical partition, that is, the second identifier.
[0141] Step SD: if the second identifier belongs to the first preset file system identifier, determine the file system type of each target sub-logical partition as the file system type corresponding to the second identifier in the first preset file system identifier.
[0142] For the embodiment of the present application, the electronic device determines whether the second identifier belongs to the first preset file system identifier. Assuming that the second identifier belongs to the identifier corresponding to the NTFS file system, the electronic device can determine that the file system of the target sub-logical partition is the NTFS file system.
[0143] In the embodiment of the present application, if the MSDOS5.0 mark appears in the initial logical sector, it also indicates that the target logical partition belongs to the FAT32 file system. The MSDOS5.0 mark plays an effect of assisting in determining the FAT32 file system.
[0144] Step SE: if the second identifier does not belong to the first preset file system identifier, then read the designated logical sectors corresponding to each target sub-logical partition except the starting logical sector to obtain a third identifier.
[0145] For the embodiment of the present application, the electronic device determines that the second identifier does not belong to the first preset file system identifier. This indicates that the file system of the target sub-logical partition does not belong to the file system corresponding to the first preset file system identifier. The electronic device reads the specified logical sector to obtain the third identifier, for example, reads the third logical sector.
[0146] Step SF: if the third identifier belongs to the second preset file system identifier, determine the file system type of each target sub-logical partition as the file system type corresponding to the third identifier in the second preset file system identifier. The second preset file system identifier includes: an identifier corresponding to the EXT2 file system, an identifier corresponding to the EXT3 file system, and an identifier corresponding to the EXT4 file system.
[0147] For the embodiment of the present application, the electronic device determines whether the third identifier belongs to the second preset file system identifier. The second file system identifier includes an identifier corresponding to the EXT2 file system, an identifier corresponding to the EXT3 file system, and an identifier corresponding to the EXT4 file system. Assuming that the third identifier belongs to an identifier corresponding to the EXT4 file system, the electronic device can determine that the file system of the target sub-logical partition is the EXT4 file system.
[0148] In the embodiment of the present application, if the second identifier does not belong to the first preset file system identifier, and the third identifier does not belong to the second preset file system identifier, it means that there is a file system in the mobile storage medium that cannot be recognized by the electronic device.
[0149] In order to transfer files in a file system that cannot be recognized by a computer device, a possible implementation of an embodiment of the present application includes step S106 (not shown in the figure), step S107 (not shown in the figure) and step S108 (not shown in the figure) after step S105, wherein:
[0150] Step S106, obtaining files in at least one logical partition.
[0151] For the embodiment of the present application, after determining the file system of at least one logical partition, the electronic device can obtain the file from the at least one logical partition according to the path corresponding to the file.
[0152] Step S107, storing the file.
[0153] For the embodiment of the present application, after the electronic device obtains the file in the logical partition, it stores the file, for example, in the local memory of the electronic device. The local memory can be a static random access memory (SRAM) or other types of memory.
[0154] Step S108: When receiving an instruction to send a file, the file is sent.
[0155] For the embodiment of the present application, when the electronic device obtains the send file instruction transmitted by the computer device, it indicates that the user needs to read the file to the computer device for viewing. By obtaining the send file instruction transmitted by the computer device and transmitting the file according to the send file instruction, the file reading is more orderly.
[0156] In a possible implementation manner of the embodiment of the present application, the method further includes step S109 (not shown in the figure) and step S110 (not shown in the figure), wherein step S109 may be performed after step S101, wherein
[0157] Step S109: if a write request instruction is detected, the key information is obtained.
[0158] For the embodiment of the present application, the request to write instruction is an instruction to request to write a file from a computer device to a mobile storage medium. The request to write instruction can be an instruction triggered by a user through an input device such as a mouse or keyboard, and transmitted to the electronic device. The electronic device detects the request to write instruction and obtains the key information transmitted by the computer device. The key information is the information input by the user through an input device such as a mouse, keyboard, and touchpad, and is transmitted from the computer device to the electronic device.
[0159] Step S110: If the key information matches the preset key information, it is determined that the state of the mobile storage medium is a writing state.
[0160] For the embodiment of the present application, assuming that the preset key information is "ABC123", the electronic device compares the obtained key information with the preset key information. If they are consistent, it means that the request for writing is legal, and the electronic device determines that the state of the mobile storage medium is the writing state, so that the file in the computer device can be written to the mobile storage medium. If the key information is inconsistent with the preset key information, it means that the request for writing is illegal, and the mobile storage medium is not allowed to enter the writing state.
[0161] In the embodiment of the present application, a preset comparison number can also be set in the electronic device. Assuming that the preset comparison number is three times, if the key information obtained by the electronic device three times in a row is inconsistent with the preset key information, it means that the number of illegal write operations requested is too many, and the electronic device enters a self-locking state, that is, it cannot read files in the mobile storage medium, nor can it write files to the mobile storage medium, thereby protecting the mobile storage medium and reducing the possibility of illegal intrusion into the mobile storage medium.
[0162] In the above embodiment, all file system types in the mobile storage medium can be identified, that is, no matter whether the mobile storage medium is connected to a computer device of a Windows system or a computer device of a Linux system, all file system types in the mobile storage medium can be identified, and then the files in the file system can be read.
[0163] However, some specific file system types can be recognized by both Windows and Linux systems. Therefore, in order to store files using a file system that can be recognized by both Windows and Linux systems, the convenience of subsequent file reading by users is improved. In a possible implementation of the embodiment of the present application, when a mobile storage medium is detected to be connected, the method also includes step S111 (not shown in the figure) and step S112 (not shown in the figure), wherein step S111 can be executed after step S101, wherein,
[0164] Step S111, determining whether the target file system type exists in all file system types of the mobile storage medium.
[0165] The target file system type includes file system types that can be recognized by both Windows and Linux systems.
[0166] For the embodiment of the present application, some specific file system types can be recognized by the Windows system and the Linux system, for example, the FAT file system. The target file system of the embodiment of the present application takes the FAT file system as an example. After determining that the mobile storage medium is connected to the electronic device, the electronic device determines whether there is a FAT file system from the determined file system.
[0167] Step S112: If it exists, output a signal indicating that the target file system type exists in the mobile storage medium.
[0168] For the embodiment of the present application, if there is a FAT file system, the electronic device outputs a signal indicating that there is a FAT file system in the mobile storage medium, and transmits the signal to the computer device, so that the computer device knows that there is a FAT file system in the mobile storage medium. Then the computer device outputs a prompt message to prompt the user that there is a FAT file system in the mobile storage medium. The user can write the file to the FAT file system first, so that when the user uses the mobile storage medium to read the file later, both the Windows system and the Linux system can read the file, which improves the convenience of reading files.
[0169] In a possible implementation manner of the embodiment of the present application, the method further includes at least one of step S113 (not shown in the figure) and step S114 (not shown in the figure), wherein step S113 may be performed after step S101 or after step S105; step S114 may be performed after step S110, wherein:
[0170] Step S113, if the mobile storage medium is in a reading state, the file name of the file to be read is obtained, and it is determined whether the file name of the file to be read matches the preset virus name. If they match, the reading of the file to be read is stopped.
[0171] For the embodiments of the present application, some specific viruses will be disguised as files and stored in a mobile storage medium, so that the mobile storage medium is infected with the virus, and then the virus may infect other computer devices through the mobile storage medium. When the virus is disguised as a file, there will be a specific file name. Therefore, when reading the file in the mobile storage medium, the file name with the read file is obtained, and the file name is compared with the preset virus name. Assume that the preset virus name is "Autorun.inf". If the electronic device determines that the file name is consistent with the preset virus name, it determines that the file is a virus file, and the electronic device controls to stop reading the virus file. The virus file is intercepted in the electronic device. Or in the mobile storage medium, thereby reducing the possibility of computer equipment being infected with the virus.
[0172] Step S114, if the mobile storage medium is in a writing state, the file name of the file to be written is obtained, and it is determined whether the file name of the file to be written matches the preset virus name. If they match, the file to be written is deleted.
[0173] For the embodiment of the present application, when writing a file to a mobile storage medium, a virus file may be written to the mobile storage medium. Before the electronic device stores the file to be written to the mobile storage medium, it obtains the file name of the file to be written, compares the file name with the preset virus name, and determines whether the file name is consistent with the preset virus name. If they are consistent, the file is determined to be a virus file, and the electronic device deletes the file, so that the virus file cannot be written to the mobile storage medium, and the possibility of the mobile storage medium storing virus files is also reduced.
[0174] In the embodiment of the present application, when the file name is consistent with the preset virus name, the file may not be a virus. When storing the file, the electronic device records the path of the file and determines the location of the physical sector where the file is stored in the mobile storage medium, and marks the physical sector or sets permissions. For example, a specific identifier is written in the physical sector as a mark, and the file in the physical sector is determined to be a suspicious file through the specific identifier.
[0175] When the mobile storage medium is in a reading state again, a signal indicating that the physical sector is abnormal is output according to the mark. The computer device receives the signal to remind the user that the file in the physical sector is a suspicious file, or the permission setting can be to restrict the permission to read the file in the physical sector. When the electronic device receives a specific instruction, the restriction permission of the physical sector is lifted and the file is read.
[0176] The above embodiment introduces a method for reading data in a storage medium from the perspective of a method flow, and the following embodiment introduces a device for reading data in a storage medium from the perspective of a virtual module or a virtual unit. For details, please refer to the following embodiment.
[0177] The present application embodiment provides a device 20 for reading data in a storage medium, such as Figure 2 As shown, the device 20 for reading data in the storage medium may specifically include:
[0178] The information acquisition module 201 is used to acquire the number of logical partitions in the mobile storage medium and the capacity of each logical partition when the mobile storage medium is detected to be connected;
[0179] A starting physical sector determination module 202, configured to determine a starting physical sector of at least one logical partition based on the number of logical partitions and the capacity of each logical partition;
[0180] A partition type determination module 203, configured to determine a partition type of at least one logical partition based on a starting physical sector of at least one logical partition;
[0181] The identification determination module 204 is used to determine a designated physical sector corresponding to at least one logical partition according to the partition type, wherein the designated physical sector stores identification information;
[0182] The file system determination module 205 is used to determine the file system type corresponding to at least one logical partition based on the identification information.
[0183] The embodiment of the present application provides a device 20 for reading data in a storage medium, wherein when a mobile storage medium is detected to be connected, it indicates that a file in the mobile storage medium is to be read or written, so the information acquisition module 201 acquires the number of at least one logical partition and the capacity of at least one logical partition in the mobile storage medium. After obtaining the capacity of the first logical partition, since the starting physical sector corresponding to the first logical partition starts from the physical sector No. 0, the address of the last physical sector corresponding to the first logical partition can be determined according to the capacity of the first logical partition, that is, the starting physical sector determination module 202 can determine the starting physical sector address of the current logical partition according to the last physical sector corresponding to the previous logical partition of the logical partition, and the partition type determination module 203 can determine the corresponding partition type based on the starting physical sector of each logical partition, and the identification determination module 204 can obtain identification information according to the specified physical sector of each logical partition, so that the file system determination module 205 can determine the file system type of the logical partition, that is, it can read the files in the file system, and thus facilitate the user to read the files in the mobile storage medium.
[0184] In a possible implementation of the embodiment of the present application, when the partition type determination module 203 determines the partition type of any logical partition based on the starting physical sector of any logical partition, it is specifically used to:
[0185] Reading a starting physical sector corresponding to any logical partition to obtain first data information of the starting physical sector, the first data information at least including data of a first specified byte and data of a second specified byte;
[0186] If the data of the first designated byte belongs to the first preset identifier, read the next physical sector of the starting physical sector to obtain the second data information;
[0187] If the data of the designated bytes in the second data information belongs to the second preset identifier, determining whether any logical partition has a sub-logical partition;
[0188] If it exists, it is determined that any logical partition belongs to a GPT partition;
[0189] If it does not exist, and the data of the second specified byte is not 0, it is determined that any logical partition belongs to the MBR partition;
[0190] If it does not exist, and the data of the second designated byte is 0, it is determined that any logical partition is of the non-partition type.
[0191] In a possible implementation of the embodiment of the present application, the first data information includes a first identifier, and the identifier determination module 204 and the file system determination module 205 determine a designated physical sector corresponding to any logical partition according to the partition type, and the designated physical sector stores the identifier information; when determining the file system type corresponding to any logical partition based on the identifier information, it is specifically used to:
[0192] If any logical partition is of the non-partition type, the starting physical sector is determined to be a specified physical sector, and if the first identifier belongs to a first preset file system identifier, the file system type of any logical partition is determined to be a file system type corresponding to the first identifier in the first preset file system identifier, wherein the first preset file system identifier includes: an identifier corresponding to the NTFS file system, an identifier corresponding to the FAT12 file system, an identifier corresponding to the FAT16 file system, an identifier corresponding to the FAT32 file system, and an identifier corresponding to the exFAT file system; or,
[0193] If any of the logical partitions belongs to a GPT partition or an MBR partition, a specified physical sector corresponding to the GPT partition or a specified physical sector corresponding to the MBR partition is read to obtain a starting logical sector address of at least one sub-logical partition and a capacity of at least one sub-logical partition, so as to determine at least one target sub-logical partition;
[0194] Reading the starting logical sector of each target sub-logical partition to obtain a second identifier corresponding to each target sub-logical partition;
[0195] If the second identifier belongs to the first preset file system identifier, determining the file system type of each target sub-logical partition to be the file system type corresponding to the second identifier in the first preset file system identifier;
[0196] If the second identifier does not belong to the first preset file system identifier, reading a designated logical sector other than a starting logical sector corresponding to each target sub-logical partition to obtain a third identifier;
[0197] If the third identifier belongs to the second preset file system identifier, the file system type of each target sub-logical partition is determined to be the file system type corresponding to the third identifier in the second preset file system identifier, and the second preset file system identifier includes: an identifier corresponding to the EXT2 file system, an identifier corresponding to the EXT3 file system, and an identifier corresponding to the EXT4 file system.
[0198] In a possible implementation of the embodiment of the present application, the device 20 further includes:
[0199] A file acquisition module, used to acquire files in at least one logical partition;
[0200] A storage module, used for storing files;
[0201] The file sending module is used to send the file when receiving an instruction to send the file.
[0202] In a possible implementation of the embodiment of the present application, the device 20 further includes:
[0203] A key acquisition module, used to acquire key information when a write request instruction is detected;
[0204] The state determination module is used to determine that the state of the mobile storage medium is a write state when the secret key information matches the preset secret key information.
[0205] In a possible implementation of the embodiment of the present application, the device 20 further includes:
[0206] A judgment module, used for judging whether there is a target file system type among all file system types of the mobile storage medium, where the target file system type includes a file system type that can be recognized by both Windows system and Linux system;
[0207] The signal output module is used to output a signal indicating that a target file system type exists in the mobile storage medium when the signal exists.
[0208] In a possible implementation manner of the embodiment of the present application, the device 20 further includes at least one of a control module and a deletion module:
[0209] The control module is used to obtain the file name of the file to be read when the mobile storage medium is in a reading state, determine whether the file name of the file to be read matches the preset virus name, and if so, control to stop reading the file to be read;
[0210] The deletion module is used to obtain the file name of the file to be written when the mobile storage medium is in a writing state, and to determine whether the file name of the file to be written matches the preset virus name. If so, the file to be written is deleted.
[0211] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device 20 for reading data in a storage medium described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0212] An electronic device is provided in an embodiment of the present application, such as Figure 3 As shown, Figure 3 The electronic device 30 shown includes: a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, such as through a bus 302. Optionally, the electronic device 30 may also include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the electronic device 30 does not constitute a limitation on the embodiments of the present application.
[0213] The processor 301 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. The processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0214] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but it does not mean that there is only one bus or only one type of bus.
[0215] The memory 303 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.
[0216] The memory 303 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the contents shown in the above method embodiment.
[0217] Figure 3 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0218] The present application embodiment provides a system for reading a mobile storage medium, such as Figure 4 As shown, the system includes: a mobile storage medium 401, a reading device 402 and a computer device 403, wherein the reading device 40 is used to read the mobile storage medium 401 (such as a USB flash drive) connected thereto for communication, and send the read file to the computer device 403 (such as a personal computer) connected thereto for communication.
[0219] Furthermore, the reading device 402 includes a file reading chip 4021 capable of reading files, and a forwarding chip 4022 , wherein the forwarding chip 4022 is used to receive a file sent by the file reading chip 4021 and forward the file to the computer device 403 .
[0220] Furthermore, the reading device 40 further includes: an isolation device 4023, which may be a chip with an isolation function or a circuit with an isolation function, which is not limited here. The isolation device 4023 is arranged between the file reading chip 4021 and the forwarding chip 4022, so that the computer device 403 can only read files in the mobile storage medium 401 but cannot write files to the mobile storage medium 401, thereby making the files in the mobile storage medium 401 safer.
[0221] The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored, and when it is run on a computer, the computer can execute the corresponding content in the above method embodiment. Compared with the related art, in the embodiment of the present application, when the mobile storage medium is detected to be connected, it means that the file in the mobile storage medium is to be read or written, so the number of at least one logical partition and the capacity of at least one logical partition in the mobile storage medium are obtained. After obtaining the capacity of the first logical partition, since the starting physical sector corresponding to the first logical partition starts from the physical sector No. 0, the address of the last physical sector corresponding to the first logical partition can be determined according to the capacity of the first logical partition, that is, when determining the starting physical sector address of the current logical partition, it can be determined according to the last physical sector corresponding to the previous logical partition of the logical partition, so that the corresponding partition type can be determined based on the starting physical sector of each logical partition, and then the identification information can be obtained according to the specified physical sector of each logical partition to determine the file system type of the logical partition, that is, the file in the file system can be read, so that it is convenient for users to read files in the mobile storage medium.
[0222] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0223] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for reading data in a storage medium, characterized in that: include: When the mobile storage medium is detected to be connected, the number of logical partitions in the mobile storage medium and the capacity of each logical partition are obtained; Determining a starting physical sector of at least one logical partition based on the number of the logical partitions and the capacity of each logical partition; determining a partition type of the at least one logical partition based on a starting physical sector of the at least one logical partition; Determining a designated physical sector corresponding to the at least one logical partition according to the partition type, wherein identification information is stored in the designated physical sector; Determine the file system type corresponding to the at least one logical partition based on the identification information; Determining the partition type of any logical partition based on the starting physical sector of any logical partition includes: Reading a starting physical sector corresponding to any logical partition to obtain first data information of the starting physical sector, wherein the first data information at least includes data of a first specified byte and data of a second specified byte; If the data of the first designated byte belongs to the first preset identifier, reading the next physical sector of the starting physical sector to obtain second data information; If the data of the designated bytes in the second data information belongs to the second preset identifier, determining whether any of the logical partitions has a sub-logical partition; If so, determining that any of the logical partitions belongs to a GPT partition; If it does not exist, and the data of the second designated byte is not 0, it is determined that any of the logical partitions belongs to the MBR partition; If it does not exist, and the data of the second designated byte is 0, it is determined that any one of the logical partitions is of the non-partition type.
2. A method for reading data in a storage medium according to claim 1, characterized in that: The first data information includes a first identifier, and a designated physical sector corresponding to any logical partition is determined according to the partition type, wherein the designated physical sector stores the identifier information; Determining the file system type corresponding to any one of the logical partitions based on the identification information includes: If any of the logical partitions is of the non-partition type, the starting physical sector is determined to be the designated physical sector, and if the first identifier is a first preset file system identifier, the file system type of any of the logical partitions is determined to be a file system type corresponding to the first identifier in the first preset file system identifier, wherein the first preset file system identifier includes: an identifier corresponding to the NTFS file system, an identifier corresponding to the FAT12 file system, an identifier corresponding to the FAT16 file system, an identifier corresponding to the FAT32 file system, and an identifier corresponding to the exFAT file system; or, If any of the logical partitions belongs to a GPT partition or an MBR partition, a specified physical sector corresponding to the GPT partition or a specified physical sector corresponding to the MBR partition is read to obtain a starting logical sector address of at least one sub-logical partition and a capacity of at least one sub-logical partition, so as to determine at least one target sub-logical partition; Reading the starting logical sector of each target sub-logical partition to obtain a second identifier corresponding to each target sub-logical partition; If the second identifier belongs to the first preset file system identifier, determining the file system type of each target sub-logical partition to be the file system type corresponding to the second identifier in the first preset file system identifier; If the second identifier does not belong to the first preset file system identifier, reading a designated logical sector other than a starting logical sector corresponding to each target sub-logical partition to obtain a third identifier; If the third identifier belongs to the second preset file system identifier, the file system type of each target sub-logical partition is determined to be the file system type corresponding to the third identifier in the second preset file system identifier, and the second preset file system identifier includes: an identifier corresponding to the EXT2 file system, an identifier corresponding to the EXT3 file system, and an identifier corresponding to the EXT4 file system.
3. A method for reading data in a storage medium according to claim 1, characterized in that: The step of determining the file system type corresponding to the at least one logical partition based on the identification information further includes: Obtaining files in the at least one logical partition; Storing the file; When an instruction to send a file is received, the file is sent.
4. A method for reading data in a storage medium according to claim 1, characterized in that: The method further comprises: If a write request instruction is detected, the key information is obtained; If the key information matches the preset key information, it is determined that the state of the mobile storage medium is a writing state.
5. A method for reading data in a storage medium according to claim 1, characterized in that: When the mobile storage medium is detected to be connected, the method further includes: Determine whether there is a target file system type among all file system types of the mobile storage medium, wherein the target file system type includes a file system type that can be recognized by both Windows system and Linux system; If so, a signal indicating that the target file system type exists in the mobile storage medium is output.
6. A method for reading data in a storage medium according to claim 1, characterized in that: The method further comprises at least one of the following: If the mobile storage medium is in a reading state, the file name of the file to be read is obtained, and it is determined whether the file name of the file to be read matches the preset virus name. If they match, the reading of the file to be read is stopped; If the mobile storage medium is in a writing state, the file name of the file to be written is obtained, and it is determined whether the file name of the file to be written matches the preset virus name. If they match, the file to be written is deleted.
7. A device for reading data in a storage medium, characterized in that: include: An information acquisition module, used for acquiring the number of logical partitions in the mobile storage medium and the capacity of each logical partition when detecting access to the mobile storage medium; A starting physical sector determination module, used to determine a starting physical sector of at least one logical partition based on the number of the logical partitions and the capacity of each logical partition; A partition type determination module, configured to determine a partition type of the at least one logical partition based on a starting physical sector of the at least one logical partition; an identification determination module, configured to determine, according to the partition type, a designated physical sector corresponding to the at least one logical partition, wherein the designated physical sector stores identification information; A file system determination module, configured to determine a file system type corresponding to the at least one logical partition based on the identification information; When determining the partition type of any logical partition based on the starting physical sector of any logical partition, the partition type determination module is specifically used to: read the starting physical sector corresponding to any logical partition to obtain first data information of the starting physical sector, wherein the first data information at least includes data of a first specified byte and data of a second specified byte; if the data of the first specified byte belongs to a first preset identifier, read the next physical sector of the starting physical sector to obtain second data information; if the data of the specified byte in the second data information belongs to a second preset identifier, determine whether any logical partition has a sub-logical partition; if so, determine that any logical partition belongs to a GPT partition; If it does not exist and the data of the second designated byte is not 0, it is determined that any of the logical partitions belongs to the MBR partition; if it does not exist and the data of the second designated byte is 0, it is determined that any of the logical partitions belongs to the non-partition type.
8. An electronic device, characterized in that: It includes: One or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to: execute a method for reading data in a storage medium according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed in a computer, the computer is caused to execute the method for reading data in a storage medium as claimed in any one of claims 1 to 6.
Citation Information
Patent Citations
Data write-in method of data storage type flash memory, flash memory and storage medium
CN107391038A
Flash based memory comprising a flash translation layer and method for storing a file therein
US20110238893A1
