Method for accessing hard disk based on YAFFS file system

By introducing hook functions and driver functions in the YAFFS file system, the hard disk is simulated as nand flash, which solves the problem of difficulty in taking advantage of the YAFFS file system on the hard disk, and realizes efficient access to the hard disk and the advantage of the YAFFS file system.

CN119556853APending Publication Date: 2025-03-04SUZHOU LANBO CONTROL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411511163.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-03-04

AI Technical Summary

Technical Problem

The prior art is difficult to effectively utilize the advantages of the YAFFS file system on the hard disk, because the YAFFS file system is mainly designed for nand flash, while the file system used by the hard disk does not have the advantages of YAFFS.

Method used

By introducing hook functions and driver functions in the YAFFS file system, the hard disk is simulated as nand flash, and the driver function is used to convert access parameters for nand flash into access parameters for hard disk, thereby realizing access to the hard disk by the YAFFS file system.

Benefits of technology

It realizes the simulation of the hard disk as nand flash for access, taking advantage of the advantages of the YAFFS file system, such as low memory usage and fast boot speed, which is suitable for situations where only hard disks are available in the hardware architecture.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119556853A_ABST
    Figure CN119556853A_ABST
Patent Text Reader

Abstract

The invention provides a method for accessing a hard disk based on a YAFFS file system. The YAFFS file system comprises a hook function and a driving function. The hook function receives an access instruction issued by the YAFFS file system and calls the driving function; the hook function has an access parameter aiming at the nand flash, and the driving function converts the access parameter aiming at the nand flash into an access parameter aiming at the hard disk, so that the hard disk is simulated as the nand flash for access. According to the access method for the hard disk based on the YAFFS file system, the access parameter aiming at the nand flash is converted into the access parameter aiming at the hard disk through the driving function, and the hard disk is simulated to be the nand flash for access.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a method for accessing a hard disk based on a YAFFS file system. Background Art

[0002] YAFFS file system is an embedded log file system designed for nand flash (flash memory), which has the advantages of small memory usage and fast startup speed. For hard disks, although there are many commonly used file systems, such as FAT32, dosFs, ext3, ext4, etc., they do not have these advantages. In some application scenarios, there is only a hard disk in the hardware architecture, and no flash memory is configured. At this time, if the hard disk can be accessed based on the YAFFS file system, the system with such hardware architecture can also take advantage of the above advantages. Summary of the invention

[0003] The purpose of the present invention is to provide a method for accessing a hard disk based on a YAFFS file system, which can access the hard disk based on the YAFFS file system.

[0004] To achieve the above object, the present invention provides the following technical solutions: The present invention provides a method for accessing a hard disk based on a YAFFS file system. The YAFFS file system comprises a hook function and a driver function. The hook function receives an access instruction issued by the YAFFS file system and calls the driver function. The hook function has access parameters for nand flash, and the driver function converts the access parameters for nand flash into access parameters for a hard disk, thereby simulating the hard disk as a nand flash for access.

[0005] In one embodiment, the driver function converts the access parameters for the nand flash into access parameters for the hard disk, including converting the bytes of the page of the block of the nand flash to the bytes of the sector of the hard disk.

[0006] In one embodiment, the driver function converts the access parameter for the nand flash into the access parameter for the hard disk according to the following formula: startSector = n1, the n1th sector in the hard disk is used as the starting position of the simulated nand flash corresponding to the YAFFS file system, n1 is an integer greater than or equal to 0, and can be set arbitrarily according to needs; blockNum = n2, the number of blocks in the simulated nand flash, n2 is an integer greater than or equal to 1, and can be set arbitrarily as needed; pageNum = n3, the number of pages in each block in the simulated nand flash, n3 is an integer greater than or equal to 1, and can be set arbitrarily as needed; dataHasSectorNum = dataSize / sectorSize = n4, the number of sectors of the hard disk occupied by the data area of ​​each page in the simulated nand flash, and rounded up, dataSize is the size of the data area of ​​each page in the simulated nand flash, and sectorSize is the size of each sector of the hard disk; oobHasSectorNum = oobSize / sectorSize = n5, the number of sectors of the hard disk occupied by the oob area of ​​each page in the simulated nand flash, rounded up, oobSize is the size of the oob area of ​​each page in the simulated nand flash; block[i].page[j].data = startSector + i * n3 * (n4 + n5) + j * (n4 +n5), the starting sector number of the hard disk corresponding to the data area of ​​page j in block i in the simulated nand flash, i and j are both integers greater than or equal to 0, and i is less than n2, and j is less than n3; block[i].page[j].oob = startSector + i * n3 * (n4 + n5) + j * (n4 +n5) + n4, the starting sector number of the hard disk corresponding to the oob area of ​​page j in block i in the simulated nand flash.

[0007] In one embodiment, n1 = 100, n2 = 1024, n3 = 64, n4 = 4, n5 = 1, dataSize = 2KByte, oobSize = 64byte, sectorSize = 512 byte.

[0008] In one embodiment, the driver function converts the access parameter for the nand flash into the access parameter for the hard disk according to the following formula: startSector = n1, the n1th sector in the hard disk is used as the starting position of the simulated nand flash corresponding to the YAFFS file system, n1 is an integer greater than or equal to 0, and can be set arbitrarily according to needs; blockNum = n2, the number of blocks in the simulated nand flash, n2 is an integer greater than or equal to 1, and can be set arbitrarily as needed; pageNum = n3, the number of pages in each block in the simulated nand flash, n3 is an integer greater than or equal to 1, and can be set arbitrarily as needed; dataHasSectorNum = dataSize / sectorSize = n4, the number of sectors of the hard disk occupied by the data area of ​​each page in the simulated nand flash, and rounded up, dataSize is the size of the data area of ​​each page in the simulated nand flash, and sectorSize is the size of each sector of the hard disk; oobHasSectorNum = oobSize / sectorSize = n5, the number of sectors of the hard disk occupied by the oob area of ​​each page in the simulated nand flash, rounded up, oobSize is the size of the oob area of ​​each page in the simulated nand flash; block[i].page[j].data = startSector + i * n3 * n4 + j * n4, the starting sector number of the hard disk corresponding to the data area of ​​the page numbered j in the block numbered i in the simulated nandflash, i and j are both integers greater than or equal to 0, and i is less than n2, and j is less than n3; block[i].page[j].oob = startSector + n2 * n3 * n4 + reservedSector +i * n3 + j * n5, the starting sector number of the hard disk corresponding to the oob area of ​​page numbered j in block numbered i in the simulated nand flash; reservedSector is the free area between all data areas and all oob areas, which is an integer greater than or equal to 0 and can be set arbitrarily as needed.

[0009] In one implementation, the driving function further calls an operating function for driving the hard disk.

[0010] In one implementation, the hook function includes a read function, a write function, an erase function, and a bad block management function.

[0011] Compared with the prior art, the technical solution of the present invention has the following beneficial effects: The method for accessing a hard disk based on the YAFFS file system of the present invention converts access parameters for nand flash into access parameters for a hard disk through a driver function, thereby simulating the hard disk as a nand flash for access. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0013] Figure 1 The present invention is a schematic diagram of the structure of a nand flash involved in the method for accessing a hard disk based on the YAFFS file system. DETAILED DESCRIPTION

[0014] The technical solutions in the embodiments of the present invention will be described clearly and completely below. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by those skilled in the art without creative work belong to the scope of protection of the present invention. It should be noted that the description order of the following embodiments is not used as a limitation on the preferred order of the embodiments of the present invention. In the following embodiments, the description of each embodiment has its own emphasis. For the parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0015] See also Figure 1 As shown, the first embodiment of the present invention provides a method for accessing a hard disk based on a YAFFS file system, wherein the YAFFS file system includes a hook function and a driver function; the hook function receives an access instruction issued by the YAFFS file system and calls the driver function; the hook function has access parameters for nand flash, and the driver function converts the access parameters for nand flash into access parameters for the hard disk, thereby simulating the hard disk as nand flash for access.

[0016] As described in the background technology, the YAFFS file system is an embedded log-type file system designed for nand flash (flash memory), and is mainly divided into two layers when accessing nand flash. The first layer is that the YAFFS file system sends the access instruction to the hook function. The hook function includes a read function, a write function, an erase function, a bad block management function, etc. These hook functions do not care what the actual nand flash medium is like, and treat all nand flashes equally, calling the second layer driver function, and having access parameters for nand flash. The access parameters for nand flash are recognizable by nand flash, such as the read function, whose access parameters include how many bytes of the page of the block to read. The driver function can access nand flash based on these access parameters. However, these driver functions cannot directly access the hard disk. Therefore, the present invention adjusts the driver function of the original YAFFS file system. The driver function of the present invention can convert the access parameters for the nand flash into access parameters for the hard disk, and convert the bytes of the page of the block of the nand flash to the bytes of the sector of the hard disk, thereby simulating the hard disk as the nand flash for access.

[0017] The following will introduce the conversion method and corresponding principles in detail.

[0018] See also Figure 1 As shown in the figure, the general storage structure of nand flash is: a nand flash consists of multiple blocks, a block consists of multiple pages, and a page is divided into a data area and an oob area. The data area is also called the data area, which is mainly used to store specific data. The oob area is also called the spare area (space area, spare area, additional area), which is mainly used to store ECC checksums, bad block marks, and file system organization information. Figure 1 In the specific embodiment shown, the nand flash has a total of 1024 blocks, each block has 64 pages, the size of the data area in each page is 2KByte, the size of the oob area is 64byte, so the total capacity of the nand flash is: 1024 * 64 * (2KByte + 64byte) = 128KByte.

[0019] The smallest unit of a hard disk is a sector, and the size of a sector is usually 512 bytes (of course, as the size of the disk continues to increase, some manufacturers also set the size of each sector to 4096 bytes. The present invention takes 512 bytes as an example). The hard disk is composed of many sectors, and some sectors of the hard disk can be simulated into the storage structure of nand flash as needed. For example, for a 2GB hard disk, select part of it and simulate it into a 128M nand flash (the size can be selected according to actual needs). A 2GB hard disk contains a total number of sectors: 2 * 1024 * 1024 *1024 = 4194304. Some sectors can be intercepted from it, for example, starting from sector 100, and the subsequent sectors can be simulated into nand flash. For the simulated nand flash, it is assumed that the blocks are numbered from 0, block0, block1, ..., block1023, and the pages are also numbered from 0. The size of the data area of ​​each page is 2048 bytes, and the size of the oob area is 64 bytes. So, for page[0] of block[0], the sectors occupied by the data area are sector

[100] to sector

[103] . Because the size of the data area (2048 bytes) divided by the size of the sector (512 bytes) is equal to 4 (rounded up if it is not an integer), it occupies 4 sectors: sector

[100] , sector

[101] , sector

[102] , and sector

[103] . The oob area is sector

[104] . The size of the oob area (64 bytes) divided by the size of the sector (512 bytes) is equal to 1 (rounded up if it is not an integer). Of the 512 bytes of a sector, only the first 64 bytes of the sector are actually used as the oob area, and the remaining 448 bytes are not used. Therefore, the total number of sectors occupied by a page is 5. By analogy, the data area of ​​page[1] of block[0] occupies sectors

[105] -sector

[108] , and the oob area occupies sector

[109] . The following formula can be inferred: block[i].page[j].data = 100 + i * 64 * 5 + j * 5, the starting sector number of the hard disk corresponding to the data area of ​​page j in block i; block[i].page[j].oob = 100 + i * 64 * 5 + j * 5 + 4, the starting sector number of the hard disk corresponding to the oob area of ​​page j in block i; Both i and j are integers greater than or equal to 0, and i is less than 1024, and j is less than 64.

[0020] Then, a general formula can be summarized. The driver function converts the access parameters for the nand flash into the access parameters for the hard disk according to the following formula: startSector = n1, the n1th sector in the hard disk is used as the starting position of the simulated nand flash corresponding to the YAFFS file system, n1 is an integer greater than or equal to 0, and can be set arbitrarily according to needs; blockNum = n2, the number of blocks in the simulated nand flash, n2 is an integer greater than or equal to 1, and can be set arbitrarily as needed; pageNum = n3, the number of pages in each block in the simulated nand flash, n3 is an integer greater than or equal to 1, and can be set arbitrarily as needed; dataHasSectorNum = dataSize / sectorSize = n4, the number of sectors of the hard disk occupied by the data area of ​​each page in the simulated nand flash, and rounded up, dataSize is the size of the data area of ​​each page in the simulated nand flash, and sectorSize is the size of each sector of the hard disk; oobHasSectorNum = oobSize / sectorSize = n5, the number of sectors of the hard disk occupied by the oob area of ​​each page in the simulated nand flash, rounded up, oobSize is the size of the oob area of ​​each page in the simulated nand flash; block[i].page[j].data = startSector + i * n3 * (n4 + n5) + j * (n4 +n5), the starting sector number of the hard disk corresponding to the data area of ​​page j in block i in the simulated nand flash, i and j are both integers greater than or equal to 0, and i is less than n2, and j is less than n3; block[i].page[j].oob = startSector + i * n3 * (n4 + n5) + j * (n4 +n5) + n4, the starting sector number of the hard disk corresponding to the oob area of ​​page j in block i in the simulated nand flash.

[0021] Under this general formula, the data of the above specific examples are: n1 = 100, n2 = 1024, n3 = 64, n4 = 4, n5 = 1, dataSize = 2KByte, oobSize = 64byte, sectorSize = 512 byte.

[0022] In the simulated NAND flash described above, the blocks, pages, data areas, and oob areas are arranged on the hard disk in the order of sectors, specifically: data[block0.page0], oob[block0.page0], data[block0.page1], oob[block0.page1], data[block0.page2], oob[block0.page2], ..., data[block1023.page63]oob[block1023.page63].

[0023] Of course, the arrangement of each block, page, data area, and oob area on the hard disk can also be to first arrange each block, page, and data area in sequence in the order of sectors, and then arrange each block, page, and oob area in sequence in the order of sectors, specifically: data[block0.page0], data[block0.page1], data[block0.page2], ..., data[block1023.page63], oob[block0.page0], oob[block0.page1], oob[block0.page2], ..., oob[block1023.page63]. Moreover, some free areas can be reserved between all the data areas and all the oob areas.

[0024] At this time, the above formula also needs to be adjusted as follows: The driver function converts the access parameters for the nand flash into the access parameters for the hard disk according to the following formula: startSector = n1, the n1th sector in the hard disk is used as the starting position of the simulated nand flash corresponding to the YAFFS file system, n1 is an integer greater than or equal to 0, and can be set arbitrarily according to needs; blockNum = n2, the number of blocks in the simulated nand flash, n2 is an integer greater than or equal to 1, and can be set arbitrarily as needed; pageNum = n3, the number of pages in each block in the simulated nand flash, n3 is an integer greater than or equal to 1, and can be set arbitrarily as needed; dataHasSectorNum = dataSize / sectorSize = n4, the number of sectors of the hard disk occupied by the data area of ​​each page in the simulated nand flash, and rounded up, dataSize is the size of the data area of ​​each page in the simulated nand flash, and sectorSize is the size of each sector of the hard disk; oobHasSectorNum = oobSize / sectorSize = n5, the number of sectors of the hard disk occupied by the oob area of ​​each page in the simulated nand flash, rounded up, oobSize is the size of the oob area of ​​each page in the simulated nand flash; block[i].page[j].data = startSector + i * n3 * n4 + j * n4, the starting sector number of the hard disk corresponding to the data area of ​​the page numbered j in the block numbered i in the simulated nandflash, i and j are both integers greater than or equal to 0, and i is less than n2, and j is less than n3; block[i].page[j].oob = startSector + n2 * n3 * n4 + reservedSector +i * n3 + j * n5, the starting sector number of the hard disk corresponding to the oob area of ​​page numbered j in block numbered i in the simulated nand flash; reservedSector is the free area between all data areas and all oob areas, which is an integer greater than or equal to 0 and can be set arbitrarily as needed.

[0025] You can continue to use the parameter data in the previous example to understand, only the arrangement is different. For example, the data area is still started from the 100th sector, because the size of the data area is 1024 * 64 * 2048 = 134217728 bytes, and the total number of sectors required on the hard disk is 134217728 / 512 = 262144. Therefore, the number of the first sector in the data area is 100, and the number of the last sector is 100 + 262144-1 = 262243. The sector distribution space occupied by the data area is [100, 262243]. The number of the starting sector of the oob area is 262244, and the total number of sectors occupied by the oob area is 1024 * 64 = 65536. Because the obb of each page is only 64 bytes, and the size of a sector on the hard disk is 512 bytes, if there is less than a sector, a sector is directly occupied, and the remaining bytes are not used. The total number of sectors required for the oob area is: 65536, and the number of the last sector in the oob area is 262244 + 65536-1= 327779. Therefore, the sector distribution space occupied by the oob area is [262244, 327779].

[0026] Assume that blocks are numbered from 0, block0, block1, ..., block1023, and pages are also numbered from 0. The size of the data area of ​​each page is 2048 bytes. Then the data area of ​​page[0] of block[0] occupies sectors

[100] to sector

[103] , occupying 4 sectors. Because all data areas are arranged continuously at this time, the data area of ​​page[1] of block[0] occupies sectors

[104] -sector

[107] by analogy. Therefore, the following formula can be inferred: block[i].page[j].data = 100 + i * 64 * 4 + j * 4, the starting sector number of the hard disk corresponding to the data area of ​​page j in block i; After all the data areas are arranged, the oob areas are arranged. Based on the above, the following formula can be inferred to calculate the sector number corresponding to the oob area: block[i].page[j].oob = 100 + 1024 * 64 * 4 + reservedSector + i * 64+ j * 1; Among them, reservedSector represents the number of idle sectors left after the sectors occupied by the data area are completed. If all oob areas are arranged continuously following all data areas, the value is 0.

[0027] Both i and j are integers greater than or equal to 0, and i is less than 1024, and j is less than 64.

[0028] Of course, each block, each page, each data area, and each oob area can also be completely shuffled and arranged arbitrarily as needed, which should be included in the protection scope of the present invention. The above two specific arrangement methods provided by the present invention are relatively simpler, clearer, easier to implement, and have better actual performance.

[0029] Finally, the driving function calls the operating function of the driving hard disk to access the hard disk.

[0030] Compared with the prior art, the technical solution of the present invention has the following beneficial effects: The method for accessing a hard disk based on the YAFFS file system of the present invention converts access parameters for nand flash into access parameters for a hard disk through a driver function, thereby simulating the hard disk as a nand flash for access.

[0031] The above is only a specific implementation of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims. In addition, the specification uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. The content of this specification should not be understood as a limitation on the present invention.

Claims

1. A method for accessing a hard disk based on a YAFFS file system, characterized in that: The YAFFS file system includes a hook function and a driver function; the hook function receives the access instruction issued by the YAFFS file system and calls the driver function; the hook function has access parameters for nand flash, and the driver function converts the access parameters for nand flash into access parameters for hard disk, so as to simulate the hard disk as nand flash for access; The driver function converts the access parameters for the nand flash into the access parameters for the hard disk according to the following formula: startSector = n1, the n1th sector in the hard disk is used as the starting position of the simulated nand flash corresponding to the YAFFS file system, n1 is an integer greater than or equal to 0, and can be set arbitrarily according to needs; blockNum = n2, the number of blocks in the simulated nand flash, n2 is an integer greater than or equal to 1, and can be set as needed; pageNum = n3, the number of pages in each block in the simulated nand flash, n3 is an integer greater than or equal to 1, and can be set arbitrarily as needed; dataHasSectorNum = dataSize / sectorSize = n4, the number of sectors of the hard disk occupied by the data area of ​​each page in the simulated nand flash, and rounded up, dataSize is the size of the data area of ​​each page in the simulated nand flash, and sectorSize is the size of each sector of the hard disk; oobHasSectorNum = oobSize / sectorSize = n5, the number of sectors of the hard disk occupied by the oob area of ​​each page in the simulated nand flash, rounded up, oobSize is the size of the oob area of ​​each page in the simulated nand flash; block[i].page[j].data = startSector + i * n3 * (n4 + n5) + j * (n4 + n5), the starting sector number of the hard disk corresponding to the data area of ​​page j in block i in the simulated nand flash, i and j are both integers greater than or equal to 0, and i is less than n2, and j is less than n3; block[i].page[j].oob = startSector + i * n3 * (n4 + n5) + j * (n4 + n5) +n4, the starting sector number of the hard disk corresponding to the oob area of ​​page j in block i in the simulated nand flash.

2. The method for accessing a hard disk based on the YAFFS file system according to claim 1, characterized in that: n1 =100, n2 = 1024, n3 = 64, n4 = 4, n5 = 1, dataSize = 2KByte, oobSize = 64byte, sectorSize = 512 byte.

3. The method for accessing a hard disk based on the YAFFS file system according to claim 1, characterized in that: The driver function converts the access parameters for the nand flash into access parameters for the hard disk, including converting the bytes of the page of the block of the nand flash to the bytes of the sector of the hard disk.

4. The method for accessing a hard disk based on the YAFFS file system according to claim 1, characterized in that: The driver function converts the access parameters for the nand flash into access parameters for the hard disk or converts them according to the following formula: startSector = n1, the n1th sector in the hard disk is used as the starting position of the simulated nand flash corresponding to the YAFFS file system, n1 is an integer greater than or equal to 0, and can be set arbitrarily according to needs; blockNum = n2, the number of blocks in the simulated nand flash, n2 is an integer greater than or equal to 1, and can be set as needed; pageNum = n3, the number of pages in each block in the simulated nand flash, n3 is an integer greater than or equal to 1, and can be set arbitrarily as needed; dataHasSectorNum = dataSize / sectorSize = n4, the number of sectors of the hard disk occupied by the data area of ​​each page in the simulated nand flash, and rounded up, dataSize is the size of the data area of ​​each page in the simulated nand flash, and sectorSize is the size of each sector of the hard disk; oobHasSectorNum = oobSize / sectorSize = n5, the number of sectors of the hard disk occupied by the oob area of ​​each page in the simulated nand flash, rounded up, oobSize is the size of the oob area of ​​each page in the simulated nand flash; block[i].page[j].data = startSector + i * n3 * n4 + j * n4, the starting sector number of the hard disk corresponding to the data area of ​​the page numbered j in the block numbered i in the simulated nandflash, i and j are both integers greater than or equal to 0, and i is less than n2, and j is less than n3; block[i].page[j].oob = startSector + n2 * n3 * n4 + reservedSector + i *n3 + j * n5, the starting sector number of the hard disk corresponding to the oob area of ​​page numbered j in block numbered i in the simulated nand flash; reservedSector is the free area between all data areas and all oob areas, which is an integer greater than or equal to 0 and can be set arbitrarily as needed.

5. The method for accessing a hard disk based on the YAFFS file system according to claim 1, characterized in that: The driving function also calls an operating function for driving the hard disk.

6. The method for accessing a hard disk based on the YAFFS file system according to claim 1, characterized in that: The hook functions include a read function, a write function, an erase function, and a bad block management function.