Universal serial bus (USB) flash disk multi-partition identification and data transmission method of one-way transmission equipment

By realizing the multi-partition recognition and data transmission method of USB disk in a one-way transmission device, the problem that existing devices cannot recognize and transmit multi-partition U disk data is solved, and support for multi-disk and multi-partition type U disk is realized, which improves the adaptability and convenience of the device.

CN119987667APending Publication Date: 2025-05-13SHANDONG SINOCHIP SEMICON CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510074758.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-17
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

Existing one-way transmission devices only support a single partition USB disk, and cannot recognize and transmit data in multi-partition USB disk, resulting in inconvenience to users.

Method used

By realizing multi-partition recognition and data transmission methods of USB disk in a one-way transmission device, including USB disk recognition, disk partition information acquisition, file system mount, file transfer and file system uninstallation, it supports multi-disk and multi-partition type USB disks, and supports different file system formats.

Benefits of technology

It realizes file system identification and data transmission of multi-partition USB disks, improves the device's support ability for diversified USB disks, meets the needs of different application scenarios, and enhances the adaptability of the device.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119987667A_ABST
    Figure CN119987667A_ABST
Patent Text Reader

Abstract

The invention relates to the field of storage, in particular to a U disk multi-partition identification and data transmission method for one-way transmission equipment, which comprises the following steps of: identifying a U disk, acquiring the number of disks and the size of a sector, traversing each disk, acquiring the number of partitions and an initial LBA (Local Block Architecture), establishing a file system for each partition, searching a sending folder, and sending a file to an LSAVE end through an optical module; and unloading the file system and releasing the resources after the sending is finished. The method supports multi-disk and multi-partition type USB flash disks and GPT and MBR partition type USB flash disks; fat, exFAT, NTFS and EXT2 / 3 / 4 file system formats are supported, and mounting of file systems of all the partitions is achieved according to the initial LBA addresses of the partitions; and transmission is carried out by traversing and searching the specified folder, so that the high efficiency of transmission is ensured. According to the invention, the problems of file system identification and file transmission of the multi-partition USB flash disk are solved, and the diversity of equipment support is improved so as to meet the requirements of different application scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of storage, and in particular to a method for identifying multiple partitions of a USB flash drive and transmitting data using a one-way transmission device. Background Art

[0002] In today's digital age, USB flash drives have become an indispensable storage device in our daily lives. There are many types of USB flash drives. In terms of partition types, there are not only GPT partition types, but also MBR partition types; in terms of the number of partitions, some have one partition, and some have multiple partitions; in terms of disk types, there are single-disk multi-partition types, and multi-disk single-partition types; in terms of disk file system formats, there are FAT, FAT32, NTFS, exFAT, and ext2 / 3 / 4.

[0003] Currently, the one-way transmission manufacturer's device solution supports a single partition, supports few file system types, and does not support USB flash drives with multiple disks and partitions. When a multi-partition USB flash drive is inserted, the device only recognizes the first partition of the first disk. The data stored in other partitions by the user needs to be copied to the first partition before the data can be recognized, which is very inconvenient to use. Therefore, one-way transmission devices that only support a single partition can no longer meet the needs of diversified user scenarios. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a method for identifying and transmitting multiple partitions of a USB flash drive of a one-way transmission device, which solves the file system identification and file transmission problems of a multi-partition USB flash drive and improves the diversity of device support to meet the needs of different application scenarios.

[0005] In order to solve the technical problem, the technical solution adopted by the present invention is: a method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device, comprising the following steps: S01. The USB flash drive identifies and obtains the number of disks and sector size. The HOST end of the one-way transmission device security chip uses the host mode to send a request to the connected USB flash drive to set the address, obtain the device descriptor, and obtain the number of disks. For each disk, the maximum LBA information and sector size of the disk are obtained in turn and filled into the data structure. S02. Traverse each disk and obtain the number of partitions of each disk and the starting LBA of each partition: S03, file system mounting, according to the number of partitions found and the starting LBA of the partitions, mount the FAT, exFAT, NTFS, EXT2 / 3 / 4 file systems for each partition in the USB flash drive in turn; S04, searching for a sending folder and sending a file, first searching whether a specified folder exists in the root directory of each partition, and transferring the file to the partition where the specified folder is found; S05, unloading the file system. After the file is sent, the file system is unloaded to release stack resources.

[0006] Furthermore, step S02 is specifically as follows: S21, determine whether it is an NTFS file system: obtain the 0th sector of the disk partition, determine whether the 0th sector is an NTFS file system, if so, record the partition number as 1, the partition start LBA as 0, and end the process; if not, proceed to step S22; S22, determine whether it is an EXT file system: read the second sector of the disk partition, determine whether the second sector is an EXT file system, if so, record the partition number as 1, the partition start LBA as 0, and end the process; if not, proceed to step S23; S23, determine whether it is a GPT file system: determine whether the partition type of the partition table of the 0th sector is 0xEE, if so, read the first sector and determine whether it conforms to the GPT header signature, if it conforms, record it as the GPT partition format, and then read the starting LBA of the partition table item, the number of partition item items and the number of bytes occupied by the partition table item; loop to determine whether the partition table item has a valid value, if it does, continue to determine whether it is an ESP or MSR partition, if it is not one of these two partitions, record it as a valid partition, and record the starting LBA of the partition, if it is an ESP or MSR partition, continue to determine whether the partition table item has a valid value; if the partition table item does not have a valid value, end the process; S24, when the partition type of the 0th sector is not 0xEE or the first sector does not conform to the GPT header signature, it is recorded as the MBR partition format. First, it is determined whether the boot flag of the 0th sector is 0x33. If so, this sector is the master boot record MBR sector. Then, it is determined in a loop whether each partition table entry in the primary partition table has a valid value. If so, it is recorded as a valid partition and the starting LBA of the partition is recorded. If no valid value exists, the process ends. S25. If the boot flag of the 0th sector is not 0x33, continue to determine whether the boot flag of the 0th sector is 0xEB. If so, this sector is a partition boot record DBR sector, the number of partitions is 1, and the partition starting LBA is 0, and the process ends; if not, loop to determine whether the boot flag at the 0x1BE position of the 0th sector has a valid value. If so, record it as a valid partition and record the starting LBA of the partition. If not, the number of partitions is 1, the partition starting LBA is 0, and the process ends.

[0007] Furthermore, in step S21, whether it is an NTFS file system is determined by determining whether the 8 bytes starting from the 0th sector data offset 0x03 are NTFS identifiers. If it is an NTFS identifier, it is an NTFS file system, otherwise it is not an NTFS file system.

[0008] Further, in step S22, whether it is an EXT file system is determined by determining whether the two bytes starting from the second sector data offset 0x38 are EXT identifiers. If it is an EXT identifier, it is an EXT file system, otherwise it is not an EXT file system.

[0009] Furthermore, the process of cyclically judging whether there is a valid value in the partition table entry in step S23 is as follows: judging how many partition table entries exist in each sector according to the ratio of the sector size to the number of bytes occupied by the partition table entry, reading all partition items, and judging in turn whether the partition table entry is empty. If it is empty, there is no valid value, and if it is not empty, there is a valid value.

[0010] Further, in step S24, the startup flag is located at the offset 0x00 position of the 0th sector, and the process of cyclically judging whether each partition table entry of the main partition table has a valid value is as follows: if the startup flag is 0x33, the data offset 0x1BE position starts as the main partition table DPT, and the main partition table DPT is traversed. If the partition entry is not empty, it is considered that there is a valid value.

[0011] Furthermore, in step S25, the process of cyclically judging whether the startup flag at the 0x1BE position of the 0th sector has a valid value is as follows: traverse the 0x1BE position of the 0th sector, and if the data is not empty, then judge the startup mark, if the data is 0x80 or 0x00, 0x80 represents that the 0th sector is an active partition, and 0x00 represents that the 0th sector is an inactive partition, then record it as a valid partition and record the starting LBA value of the partition.

[0012] Furthermore, in step S01, the number of disks is obtained by obtaining the maximum logical unit request GET MAX LUN.

[0013] Furthermore, during the mounting of the file system, the reading operation of the internal sectors of the partition needs to add the partition starting LBA offset on the basis of the sector address before reading; after the file system is mounted successfully, the internal file information can be traversed.

[0014] Furthermore, in step S04, the file transfer flow chart: first read the file names in the folder in sequence, and read the file contents in sequence according to each 32K segment, and send the read file names and file contents from the HOST end to the SLAVE end via the optical module; the host program starts a thread to receive SLAVE end data, and the HOST data received by the SLAVE end is then forwarded to the host program; after receiving the file name, the host program first creates a file, and saves the subsequent read file content into the file.

[0015] Beneficial effects of the present invention: In terms of U disk types, the present invention not only supports multi-disk and multi-partition type U disks, but also supports GPT and MBR partition type U disks; in terms of file system mounting, it supports different file system formats such as Fat, exFAT, NTFS, EXT2 / 3 / 4, and realizes the mounting of each partition file system according to the starting LBA address of the partition; in terms of data transmission, transmission is performed by traversing and searching for the specified folder to ensure the high efficiency of transmission. In summary, the present invention can realize that U disks of different types and formats can be recognized by the HOST end of the one-way transmission device and the file system can be built, so as to complete the file reading and transmission operations, so as to be compatible with more usage scenarios and improve the adaptability of the one-way transmission device. The present invention achieves the purpose of supporting multiple types of U disks and can be applied to application environments with high reliability and high confidentiality. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 It is a schematic diagram of the working scenario of a one-way transmission device; Figure 2 A flowchart of the method is shown in FIG. Figure 3 To obtain the flow chart of valid partition and starting LBA. DETAILED DESCRIPTION

[0017] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.

[0018] Example 1 This embodiment discloses a method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device, which is applied to a one-way transmission device, such as Figure 1 As shown in the figure, the one-way transmission device consists of two security chips and optical fiber modules that realize the functions of the sending end (HOST) and the receiving end (SLAVE). The HOST end realizes the mounting of the USB disk and the analysis of the file system in the disk, and sends the data of the files in the USB disk to the SLAVE end through a single-channel path; the SLAVE end transfers the received files to the PC host through the host USB port.

[0019] like Figure 2 As shown, the method comprises the following steps: S01. The USB flash drive identifies and obtains the number of disks and sector size. The HOST end of the security chip uses the host (HOST) mode to send a set address to the connected USB flash drive, obtain the device descriptor, and obtain the number of disks by obtaining the maximum logical unit request GET MAX LUN. For each disk, the key information such as the maximum LBA information of the disk and the sector size is obtained in turn, and filled into the data structure.

[0020] S02, traverse each disk, obtain the number of partitions of each disk and the starting LBA (sector address) of each partition, such as Figure 3As shown in the figure, the process of obtaining the number of partitions of each disk and the starting LBA of each partition is as follows: S21. Determine whether it is an NTFS file system: obtain the 0th sector of the disk partition, and determine whether the 0th sector is an NTFS file system. If so, record the DBR sector for the partition boot, record the partition number as 1, and the partition starting LBA as 0, and end the process; if not, proceed to step S22.

[0021] In this embodiment, whether it is an NTFS file system is determined by determining whether the 8 bytes starting from the 0th sector data offset 0x03 are NTFS identifiers. If it is an NTFS identifier, it is an NTFS file system, otherwise it is not an NTFS file system.

[0022] S22, determine whether it is an EXT file system: read the second sector of the disk partition, determine whether the second sector is an EXT file system, if so, record the DBR sector for the partition boot, record the partition number as 1, and the partition start LBA as 0, and end the process; if not, proceed to step S23. The second sector is directly used here because the EXT file system structure is defined in this way and is stored in the second sector.

[0023] In this embodiment, whether it is an EXT file system is determined by determining whether the two bytes starting from the second sector data offset 0x38 are EXT identifiers. If it is an EXT identifier, it is an EXT file system, otherwise it is not an EXT file system.

[0024] S23, determine whether it is a GPT file system: determine whether the partition type of the partition table of the 0th sector is 0xEE, if so, read the first sector (EFI information area, also known as the GPT header, used to determine the starting sector number and the number of partitions of the GPT partition table) and determine whether it conforms to the GPT header signature. The judgment process is: read the first 8 bytes of the first sector and determine whether the data is "EFI PART", if so, it conforms to the GPT header signature, if it conforms, it is recorded as a GPT partition format, and then read the starting LBA of the partition table item, the number of partition item items and the number of bytes occupied by the partition table item; loop to determine whether there is a valid value in the partition table item, if there is a valid value, continue to determine whether it is an EFI system partition (ESP) or a Microsoft Reserved Partition (MSR), if it is neither of these two partitions, record it as a valid partition, and record the starting LBA of the partition, if it is an ESP or MSR partition, continue to determine whether there is a valid value in the partition table item; if there is no valid value in the partition table item, end the process.

[0025] In this embodiment, the process of cyclically determining whether a partition table entry has a valid value is as follows: according to the ratio of the sector size to the number of bytes occupied by the partition table entry, determine how many partition table entries exist in each sector, read all partition items, and determine in turn whether the partition table entry is empty. If it is empty, there is no valid value, and if it is not empty, there is a valid value.

[0026] S24, when the partition type of the 0th sector is not 0xEE or the first sector does not conform to the GPT header signature, it is recorded as the MBR partition format. First, it is determined whether the boot flag of the 0th sector is 0x33. If so, this sector is the master boot record MBR sector. Then, it is determined in a loop whether each partition table entry in the primary partition table has a valid value. If so, it is recorded as a valid partition and the starting LBA of the partition is recorded. If no valid value exists, the process ends.

[0027] In this embodiment, the startup flag is located at the offset 0x00 position of the 0th sector. The process of looping to determine whether each partition table entry of the primary partition table has a valid value is as follows: if the startup flag is 0x33, the data offset 0x1BE position is the primary partition table DPT (64 bytes, representing 4 partitions. The primary partition table DPT is traversed. If the partition entry is not empty, it is considered that there is a valid value.

[0028] S25. If the boot flag of the 0th sector is not 0x33, continue to determine whether the boot flag of the 0th sector is 0xEB. If so, this sector is a partition boot record DBR sector, the number of partitions is 1, and the partition starting LBA is 0, and the process ends; if not, loop to determine whether the boot flag at the 0x1BE position of the 0th sector has a valid value. If so, record it as a valid partition and record the starting LBA of the partition. If not, the number of partitions is 1, the partition starting LBA is 0, and the process ends.

[0029] In this embodiment, the process of cyclically judging whether the startup flag at the 0x1BE position of the 0th sector has a valid value is as follows: traverse the 0x1BE position of the 0th sector, if the data is not empty, then judge the startup mark, if the data is 0x80 or 0x00, 0x80 represents that the 0th sector is an active partition, 0x00 represents that the 0th sector is an inactive partition, then record it as a valid partition and record the starting LBA value of the partition.

[0030] S03, file system mounting, according to the number of partitions found and the starting LBA of the partition, mount the FAT, exFAT, NTFS, EXT2 / 3 / 4 file systems for each partition in the USB flash drive in turn. During the file system mounting process, the reading operation of the internal sectors of the partition needs to add the starting LBA offset of the partition on the basis of the sector address before reading. After the mounting is successful, the internal file information can be traversed.

[0031] In this embodiment, if there are multiple partitions, the file systems FAT, exFAT, NTFS, EXT2 / 3 / 4 are mounted in sequence. After mounting these file systems in sequence in multiple partitions, it is found which partition has a "send folder". Only the partition with a "send folder" will upload the folder, and the file will be uninstalled after it is uploaded. If it does not exist, it will be uninstalled directly.

[0032] S04, search for the sending folder and send the file. First, search whether there is a specified folder (such as "SEND") in the root directory of each partition. For the partition where the specified folder is found, transfer the file. According to the description of step S03, after mounting each file system, search for the specified folder according to the format of "root directory\\file name". If the specified folder is found, the search ends and the file in the specified folder of the partition is transferred; if the specified folder is not found in each partition, execute step S05.

[0033] The file transfer process is as follows: first read the file names in the folder in sequence, and then read the file contents in each 32K segment in sequence, and send the read file names and file contents from the HOST end to the SLAVE end through the optical module. The host program starts a thread to receive data from the SLAVE end, and the HOST data received by the SLAVE end is then forwarded to the host program. After receiving the file name, the host program first creates a file and saves the subsequent read file contents into the file.

[0034] S05, unloading the file system. After the file is sent, the file system is unloaded to release stack resources.

[0035] The present invention proposes a method for identifying and transmitting multiple partitions of a USB flash drive for a one-way transmission device. USB flash drives of different types and formats can be identified by the host end and a file system can be built to complete file reading and transmission operations, so as to be compatible with more usage scenarios and improve the adaptability of the one-way transmission device. The present invention achieves the purpose of supporting multiple types of USB flash drives and can be applied to application environments with high reliability and high confidentiality.

[0036] The above description is only the basic principle and preferred embodiments of the present invention. Improvements and substitutions made by those skilled in the art based on the present invention belong to the protection scope of the present invention.

Claims

1. A method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device, characterized in that: The following steps are involved: S01. The USB flash drive identifies and obtains the number of disks and sector size. The HOST end of the one-way transmission device security chip uses the host mode to send a request to the connected USB flash drive to set the address, obtain the device descriptor, and obtain the number of disks. For each disk, the maximum LBA information and sector size of the disk are obtained in turn and filled into the data structure. S02. Traverse each disk and obtain the number of partitions of each disk and the starting LBA of each partition: S03, file system mounting, according to the number of partitions found and the starting LBA of the partitions, mount the FAT, exFAT, NTFS, EXT2 / 3 / 4 file systems for each partition in the USB flash drive in turn; S04, searching for a sending folder and sending a file, first searching whether a specified folder exists in the root directory of each partition, and transferring the file to the partition where the specified folder is found; S05, unloading the file system. After the file is sent, the file system is unloaded to release stack resources.

2. The method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device according to claim 1, characterized in that: Step S02 is specifically as follows: S21, determine whether it is an NTFS file system: obtain the 0th sector of the disk partition, determine whether the 0th sector is an NTFS file system, if so, record the partition number as 1, the partition start LBA as 0, and end the process; if not, proceed to step S22; S22, determine whether it is an EXT file system: read the second sector of the disk partition, determine whether the second sector is an EXT file system, if so, record the partition number as 1, the partition start LBA as 0, and end the process; if not, proceed to step S23; S23, determine whether it is a GPT file system: determine whether the partition type of the partition table of the 0th sector is 0xEE, if so, read the first sector and determine whether it conforms to the GPT header signature, if it conforms, record it as the GPT partition format, then read the partition table entry starting LBA, the number of partition entry items and the number of bytes occupied by the partition table entry; loop to determine whether the partition table entry has a valid value, if so, continue to determine whether it is an ESP or MSR partition, if not, record it as a valid partition, and record the starting LBA of the partition, if it is an ESP or MSR partition, continue to determine whether the partition table entry has a valid value; If there is no valid value for the partition table entry, the process ends; S24, when the partition type of the 0th sector is not 0xEE or the first sector does not conform to the GPT header signature, it is recorded as the MBR partition format. First, it is determined whether the boot flag of the 0th sector is 0x33. If so, this sector is the master boot record MBR sector. Then, it is determined in a loop whether each partition table entry in the primary partition table has a valid value. If so, it is recorded as a valid partition and the starting LBA of the partition is recorded. If no valid value exists, the process ends. S25. If the boot flag of the 0th sector is not 0x33, continue to determine whether the boot flag of the 0th sector is 0xEB. If so, this sector is a partition boot record DBR sector, the number of partitions is 1, and the partition starting LBA is 0, and the process ends; if not, loop to determine whether the boot flag at the 0x1BE position of the 0th sector has a valid value. If so, record it as a valid partition and record the starting LBA of the partition. If not, the number of partitions is 1, the partition starting LBA is 0, and the process ends.

3. The method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device according to claim 2, characterized in that: In step S21, whether it is an NTFS file system is determined by determining whether the 8 bytes starting from the 0th sector data offset 0x03 are NTFS identifiers. If it is an NTFS identifier, it is an NTFS file system, otherwise it is not an NTFS file system.

4. The method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device according to claim 2, characterized in that: In step S22, whether it is an EXT file system is determined by determining whether the two bytes starting from the second sector data offset 0x38 are EXT identifiers. If it is an EXT identifier, it is an EXT file system, otherwise it is not an EXT file system.

5. The method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device according to claim 2, characterized in that: The process of cyclically judging whether there is a valid value in the partition table entry in step S23 is as follows: according to the ratio of the sector size to the number of bytes occupied by the partition table entry, judge how many partition table entries exist in each sector, read all partition items, and judge whether the partition table entry is empty in turn. If it is empty, there is no valid value, and if it is not empty, there is a valid value.

6. The USB disk multi-partition identification and data transmission method of a one-way transmission device according to claim 2, characterized in that: In step S24, the startup flag is located at the offset 0x00 position of the 0th sector, and the process of looping to determine whether each partition table entry of the main partition table has a valid value is: if the startup flag is 0x33, the data offset 0x1BE position starts from the main partition table DPT, and the main partition table DPT is traversed. If the partition entry is not empty, it is considered that there is a valid value.

7. The method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device according to claim 2, characterized in that: In step S25, the process of looping to determine whether the startup flag at the 0x1BE position of the 0th sector has a valid value is as follows: traverse the 0x1BE position of the 0th sector, if the data is not empty, then determine the startup mark, if the data is 0x80 or 0x00, 0x80 represents that the 0th sector is an active partition, 0x00 represents that the 0th sector is an inactive partition, then record it as a valid partition and record the starting LBA value of the partition.

8. The method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device according to claim 1, characterized in that: In step S01, the number of disks is obtained by obtaining the maximum logical unit request GET MAX LUN.

9. The method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device according to claim 1, characterized in that: During the file system mounting process, the reading operation of the partition's internal sectors needs to add the partition's starting LBA offset based on the sector address before reading; after the file system is successfully mounted, the internal file information can be traversed.

10. The method for identifying multiple partitions of a USB flash drive and transmitting data in a one-way transmission device according to claim 1, characterized in that: In step S04, the file transfer flow chart is as follows: first, the file names under the folder are read in sequence, and the file contents are read in sequence according to each 32K segment, and the read file names and file contents are sent from the HOST end to the SLAVE end via the optical module; the host program starts a thread to receive SLAVE end data, and the HOST data received by the SLAVE end is then forwarded to the host program; after receiving the file name, the host program first creates a file, and saves the subsequent read file content into the file.

Citation Information

Patent Citations

  • Method for automatically mounting USB storage device under embedded Linux

    CN101847101A

  • Method for recovering GPT of NTFS

    CN105278881A

  • Data traceless deletion method and system in FAT32 file system

    CN113190178A

  • Method and device for reading data in storage medium, electronic equipment and medium

    CN114968121A