Create a dosfs File System under VxWorks

Source: Internet
Author: User

A file system is a device driver used by an operating system on a disk device according to the directory and file organization, different file systems have different restrictions on directories and files (such as directory name restrictions and file size restrictions ).

VxWorks supports multiple file systems and is important to the following:

1. dosfs: Suitable for block access devices (such as hard disks, floppy disks), and compatible with MS-DOS file systems;

2. rawfs: provides a simple original file system. The file system treats the entire hard disk as a separate large file;

3. cdromfs: allows the system to read the device from the CD-ROM formatted according to the iso9660 standard file system;

Generally, the file system driver is located between the drive of the disk (block access) device and the IO system. This is no exception in VxWorks, But it expands its functions on this basis, that is to say, a cbio (core blocked Io) interface is added below the file system, and the block access device driver is below the cbio, which is as follows:
 


Figure 1 VxWorks I/O system hierarchy

The cbio interface is subdivided into four logical child layers, each of which has functions related to file system creation. After dividing the cbio interface, the VxWorks file system that contains the operation functions of each sub-layer is as follows:

Figure 2 cbio layer internal structure hierarchy

In the figure, the layer 4 in the wireframe is the child layer in the cbio interface layer. For VxWorks with dosfs support configured in the kernel, disk management starts from the driver child layer of the blk_dev API device, the cbio handles created by functions on different sub-layers belong to different layers. The lower-layer cbio handles are affiliated cbio handles of the Upper-layer cbio handles, that is, although they are all cbio_dev_id types, however, they are divided by level based on the layer where the functions are generated. A cbio buffer can have a cbio handle on each sub-layer, or a cbio handle on some sub-layers. The cbio buffer has no handle on the sub-layer of the basic cbio to blk_dev device. The Arrow between functions on the right of the figure shows the relationship between the handles of each sub-layer. In addition, we can see that the header file is organized according to the layer division, which makes the function call level clear.

 

2. Create a dosfs File System on the disk

Taking VxWorks running on Motorola's ppc860 CPU as an example, when configuring the VxWorks kernel, add the IDE/ATA disk device driver. After the system is started, the system is connected to the disk, after the system starts, it will find the disk (Executing command: devs, one of the listed devices/ata0a ), at this time, the device is not accessible (just as the factory hard disk can be found after boot disk boot, but cannot be used). In dos, you need to use the fdisk work area to create partitions, format), and in VxWorks, the system also provides similar operations (2 ).

Before creating a file system, you should initialize the dosfs file system by including the dosfs component in the kernel, that is, let the system load the file system driver and allow the system to create File System devices on Block devices.

Now, after the system is started, the user is directly targeting the blk_devapi Device Driver sub-layer, and all operations start from the top of the layer. To create a partition, format, and use it on a disk, perform the following operations:

2.1 create a block access device:

For disk devices, use the atadevcreate () function to create a pointer PATA pointing to the block access device on the driver child layer of the blk_dev API device:

Blk_dev * atadevcreate (INT Ctrl, intdrive, int nblocks, int blkoffset)

 

Parameter 1 indicates the Controller Number of the disk device, and 0 indicates the primary,

Parameter 2 indicates the drive letter of the disk device, 0 indicates the master,

Parameter 3 indicates the number of blocks on the drive device, and 0 indicates that the entire disk is used,

 

Parameter 4 indicates the number of blocks offset from the start of the drive, and 0 indicates the start of the drive.

The function creates a device for the specified ATA/IDE disk or atapi CDRom and returns a pointer to the block device structure (blk_dev). In Figure 2, PATA = atadevcreate (,) is used here) create a pointer PATA pointing to the block device, which corresponds to the disk primary master and uses all the blocks starting from the beginning of the entire disk. (Do not confuse devices and disks. You can create a part of a disk as a device, that is, a device corresponds to a disk and a block in the disk, the disk is uniquely specified by the Controller and drive letter)

2.2 create a disk high-speed buffer:

This step is optional. Call the dcachedevcreate () function to create a disk high-speed buffer for a block device and generate a cbio handle on the child layer of the cbio to cbio device (dcachecbio. The usage is as follows:

Cbio_dev_id dcachedevcreate (cbio_dev_id subdev, char * pramaddr, int memsize, char * pdesc)

 

Parameter 1 indicates a cbio handle, which serves as a subsidiary cbio handle of the returned cbio to cbio device (dcachecbio) Sub-layer cbio handle, which is composed of the function cbio_dev_id cbiowrapblkdev (blk_dev *) generated on the child layer of the basic cbio to blk_dev device (cbiolib. You can also use Block devices. When a block device is used, the block device is actually converted into a cbio handle on the basic cbio to blk_dev device (cbiolib) Sub-layer as a parameter;

 

Parameter 2 indicates the location of the cbio high-speed buffer in the memory;

 

Parameter 3 indicates the memory used by the cbio high-speed buffer;

Parameter 4 indicates the device description string.

The function creates a cbio-layer high-speed buffer instance for the disk and generates a cbio handle in the sublayer of the cbio to cbio device (dcachecbio). When parameter 2 is null, parameter 3 uses all the memory to buffer disk data, when parameter 2 is 0, parameter 3 uses a default memory size to buffer disk data. Parameter 4 is the device description string and is output as part of the result when dcacheshow is executed. When multiple high-speed buffers are required (16 high-speed buffers are supported ).

When the memory capacity is smaller than the specified buffer size, creation fails.

In Figure 2, cbio = dcachedevcreate (PATA, "cache1") is used to create a default high-speed buffer cbio for block device pata, at the same time, cbio is the cbio handle of the buffer on the child layer of the cbioto cbio device (dcachecbio. Here, Block devices are more intuitive as parameter 1. It is described as "cache1 ". You can also use bcbio = cbiowrapblkdev (PATA) first, and then use cbio = dcachedevcreate (bcbio, "cache1"). At this time, bcbio is the attached handle of cbio.

2.3 create and install a disk partition:

Call usrfdiskpartcreate () to create a partition table on the disk, call dpartdevcreate () to initialize a partitioned disk, and create a cbio handle on the sub-layer of the cbio to cbio device (dpartcbio. As follows:

Statususrfdiskpartcreate (cbio_dev_id cdev, int npart, int size1, int size2, int size3)

Parameter 1 indicates a cbio handle, and the partition table will be created on the block device corresponding to the handle representing the entire disk. Note that this is not subdev, but cdev, indicating that the affiliated cbio handle bcbio is not used, instead, cbio should be used;

Parameter 2 indicates the number of partitions to be created. The default value is 1 and the maximum value is 4;

Parameter 3 indicates the percentage of space occupied by the 2nd partitions;

Parameter 4 indicates the percentage of space occupied by the 3rd partitions;

Parameter 5 indicates the percentage of space occupied by the 4th partitions;

This program is used to create a basic partition table, that is, to create a disk partition. It can only be used to create a primary partition table, that is, MBR. It cannot be used to create a start or extended partition. Returns a status value indicating whether the operation is successful. At this time, the disk only has a partition table and no partitions have been installed. You can use usrfdiskpartshow () to display the created partitions.

 

In Figure 2, usrfdiskpartcreate (cbio,) is used to create two partitions on the block device corresponding to cbio, each occupying half of the disk space.

The operation function dpartdevcreate () used to create a disk partition is as follows:

Cbio_dev_id dpartdevcreate (cbio_dev_idsubdev, int npart, funcptr ppartdecodefunc)

 

Parameter 1 indicates a subsidiary cbio handle, that is, the cbio on the child layer below;

 

Parameter 2 indicates the number of partitions,

Parameter 3 indicates a function that can interpret a partitioned table.

To process a partitioned disk, that is, to install partitions on the disk, you need to use this function. We recommend that you use this function for efficient operations, create a high-speed buffer for the entire disk and share the High-Speed Buffer in different intervals. The npart parameter indicates the maximum number of partitions on a specific disk drive. A maximum of 24 partitions are supported.

Partition Table Interpreter: the function to be implemented is to interpret partition information of Partitioned devices into results in a specific format and write the results into a specific type of table.

In Figure 2, cbio1 = dpartdevcreate (cbio, 2, usrfdiskpartread) is called to initialize the partitioned disk by asking the usrfdiskpartread program to explain the Partition Table of the cbio block device. Usrfdiskpartread is a program provided by the system to explain partition table information. It can be called directly. Now the partition operation is complete. You can use the partition after creating the file system and formatting the partition. Note that the cbio1 returned by the program is of the same type as the cbio. Note that the generated handle cbio1 is located on the child layer of the cbio to cbio device (dpartcbio.

2.4 create a dosfs File System:

The file system is also seen as a device in VxWorks. by calling the dosfsdevcreate () function, you can create a dosfs file system on a specified partition. Dosfsdevcreate () function usage:

Status dosfsdevcreate (char * pdevname, cbio_dev_id cbio, u_int maxfiles, u_int autochklevel)

 

Parameter 1 indicates the volume name of the corresponding partition after the file system is created. The format is "/volume name ";

 

Parameter 2 indicates the cbio handle of a specific partition. In this example, the handle returned by dpartpartget (cbio1, 0) or dpartpartget (cbio1, 1) is used, dpartpartget requires a cbio handle located on the child layer of the cbio to cbio device (dpartcbio) and defines it as a dosfs volume;

Parameter 3 indicates the number of files that can be opened simultaneously on the device;

Parameter 4 indicates whether the volume integrity check is automatically performed when the volume is mounted.

This function creates a dosfs File System on the partition corresponding to a specific cbio handle, defines the information of each disk volume, and adds them to the I/O system. In the figure, dosfsdevcreate ("/Dosa", dpartpartget (cbio1,

0),) install the file system in the first partition (parameter 0 in dpartparget). The volume name is/Dosa, And the integrity check is automatically performed during mounting.

2.5 format disk volumes

Use the dosfsvolformat () function to format disk volumes in DOS format. This step can only be performed once when the disk volume is initialized for the first time. Skip this step if the disk volume in DOS format has been formatted.

The function usage of dosfsvolformat () is:

Status dosfsvolformat (void * device, commanpt, funcptr ppromptfunc)

 

Parameter 1 indicates the name of the volume to be formatted;

Parameter 2 indicates the formatted option, which is a bit ing, that is, a combination of options. 0 indicates that the default option is used. Refer to help;

Parameter 3 indicates a function. This function prompts you to change the volume parameter before formatting. 0 indicates no function;

The function returns the status value of whether the formatting is successful or not. In Figure 2, dosfsvolformat ("/Dosa",) is used to format the volume/dosa.

After formatting, you can use ll "/Dosa" to mount the volume. At this time, you can perform Integrity Detection and use dosfsshow "/Dosa" to display the volume information.

Run-> Devs to find the/Dosa volume. Run-> Cd "/Dosa" to switch the current working directory to the volume and run the mkdir directory name, create a directory on the volume. Run the RM directory name to delete the corresponding directory.

In some functions, the cbio handle parameter can be replaced by the blk_dev variable. In this case, the system automatically performs the conversion.

Now, the file system on the disk device has been created, and you can directly access the disk and perform related operations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.