⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme

📁 电子硬盘驱动
💻
📖 第 1 页 / 共 5 页
字号:

     Note: All the data structures in the file flioctl.h are assumed to
           be packed, i.e. all the members of these data structures are
           NOT aligned in any way. For instance, the function
           sizeof(flDiskInfoOutput) should return 55.

     Sections 8.2 - 8.6 provide sample code fragments which illustrate
     how an application can issue IOCTL calls to the TrueFFS driver.


8.2. The following code sample shows how to obtain general information
     about the DiskOnChip's flash array:

        #include <ioLib.h>
        #include <dosFsLib.h>
        #include <stdlib.h>
        #include <stdio.h>
        #include <errno.h>
        #include "fldrvvxw.h"
        #include "flioctl.h"

        flDiskInfoOutput   out;
        int                fd;
        int                status;

        /* open the DiskOnChip raw device (assuming it is "/dev/tffs0/") */
        fd = open ("/dev/tffs0/", O_RDWR, 0);
        if (fd == ERROR) {
          printf ("0x%x error in open()\n", (int) errno);
          return;
        }

        /* issue IOCTL call to the driver */
        status = ioctl (fd, FL_IOCTL_GET_INFO, (int) &out);
        if (status == ERROR) {
          printf ("0x%x error in ioctl()\n", (int) errno);
        }

        (void) close (fd);

        /* check out the out.status */
        printf ("status 0x%x\n", (int) out.status);

        /* reply data is in out.info */


8.3. The following code sample shows how to perform a short cycle of
     the "garbage collection" on the DiskOnChip:

        #include <ioLib.h>
        #include <dosFsLib.h>
        #include <stdlib.h>
        #include <stdio.h>
        #include <errno.h>
        #include "fldrvvxw.h"
        #include "flioctl.h"

        typedef union {
          flDefragInput   in;
          flDefragOutput  out;
        } flDefragReq;


        flDefragReq  ioctl_req;
        int          fd;
        int          status;

        /* request minimal garbage collection */
        ioctl_req.in.requiredNoOfSectors = (long) -1;

        /* open the DiskOnChip raw device (assuming it is "/dev/tffs0/") */
        fd = open ("/dev/tffs0/", O_RDWR, 0);
        if (fd == ERROR) {
          printf ("0x%x error in open()\n", (int) errno);
          return;
        }

        /* issue IOCTL call to the driver */
        status = ioctl (fd, FL_IOCTL_DEFRAGMENT, (int) &ioctl_req);
        if (status == ERROR) {
          printf ("0x%x error in ioctl()\n", (int) errno);
        }

        (void) close (fd);

        /* check out the ioctl_req.out.status */
        printf ("status 0x%x\n", (int) ioctl_req.out.status);

        /* reply data is in ioctl_req.out.actualNoOfSectors */

     ===> NOTE.  The TrueFFS driver also provides the routine tffsRecycle()
                 which can be used instead of the FL_IOCTL_DEFRAGMENT IOCTL
                 call. See Section 7 for details.


8.4. The code sample below shows how to impose write-protection on the
     DiskOnChip.

     *****************************************************************
     *                        WARNING                                *
     *                                                               *
     *  Before executing the code fragment below, make sure that the *
     *  DiskOnChip has been unmounted by dosFsVolUnmount() call.     *
     *  When write-protecting the DiskOnChip, please be aware of the *
     *  fact that ALL the attempts to write data onto the DiskOnChip *
     *  will be rejected, including the write requests which are     *
     *  generated by the filesystem internally for it's own purposes *
     *****************************************************************


     Here is the code sample that write-protects the DiskOnChip:

        #include <ioLib.h>
        #include <dosFsLib.h>
        #include <stdlib.h>
        #include <stdio.h>
        #include <errno.h>
        #include "fldrvvxw.h"
        #include "flioctl.h"

        typedef union {
          flWriteProtectInput   in;
          flOutputStatusRecord  out;
        } flWriteProtectReq;

        flWriteProtectReq  ioctl_req;
        int                fd;
        int                status;

        /* specify type of operation */
        ioctl_req.in.type = (unsigned char) FL_UNPROTECT;

        /* replace the password below with your own */
        ioctl_req.in.password[0] = 0x11223344;
        ioctl_req.in.password[1] = 0x55667788;

        /* open the DiskOnChip raw device (assuming it is "/dev/tffs0/") */
        fd = open ("/dev/tffs0/", O_RDWR, 0);
        if (fd == ERROR) {
          printf ("0x%x error in open()\n", (int) errno);
          return;
        }

        /* issue IOCTL call to the driver */
        status = ioctl (fd, FL_IOCTL_WRITE_PROTECT, (int) &ioctl_req);
        if (status == ERROR) {
          printf ("0x%x error in ioctl()\n", (int) errno);
        }

        (void) close (fd);

        /* check out the ioctl_req.out.status */
        printf ("status 0x%x\n", (int) ioctl_req.out.status);


8.5. The code sample below shows how to access the Binary partition on the
     DiskOnChip.

        #include <ioLib.h>
        #include <dosFsLib.h>
        #include <stdlib.h>
        #include <stdio.h>
        #include <errno.h>
        #include "fldrvvxw.h"
        #include "flioctl.h"

        typedef union {
          flBDKOperationInput   in;
          flOutputStatusRecord  out;
        } flBDKOperationReq;


        flBDKOperationReq  ioctl_req;
        int                fd;
        int                status;
        unsigned char      buf[512];  /* buffer to read BDK data to/write from */

        switch (bdkOperation) {
          case BDK_WRITE:
            ioctl_req.in.type                = (unsigned char) BDK_WRITE;
            ioctl_req.in.bdkStruct.bdkBuffer = buf;
            ioctl_req.in.bdkStruct.length    = sizeof(buf);
            /* place your BDK data to buf[] */
            break;
          case BDK_READ:
            ioctl_req.in.type                = (unsigned char) BDK_READ;
            ioctl_req.in.bdkStruct.bdkBuffer = buf;
            ioctl_req.in.bdkStruct.length    = sizeof(buf);
            break;
          default:   /* add other BDK operations here */
            return;
        }

        /* open the DiskOnChip raw device (assuming it is "/dev/tffs0/") */
        fd = open ("/dev/tffs0/", O_RDWR, 0);
        if (fd == ERROR) {
          printf ("0x%x error in open()\n", (int) errno);
          return;
        }

        /* issue IOCTL call to the driver */
        status = ioctl (fd, FL_IOCTL_BDK_OPERATION, (int) &ioctl_req);
        if (status == ERROR) {
          printf ("0x%x error in ioctl()\n", (int) errno);
        }

        (void) close (fd);

        /* check out the ioctl_req.out.status.status */
        printf ("status 0x%x\n", (int) ioctl_req.out.status);

        if (bdkOperation == BDK_READ) {
          /* the returned BDK data is in buf[] */
        }


8.6. The code sample below shows how to read virtual sectors from a
     source DiskOnChip, and then write these virtual sectors to a
     target DisknChip.

        #include <ioLib.h>
        #include <dosFsLib.h>
        #include <stdlib.h>
        #include <stdio.h>
        #include <errno.h>
        #include "fldrvvxw.h"
        #include "flioctl.h"

        #define FL_SECT_SIZE  512

        typedef union {
          flReadWriteInput   in;
          flReadWriteOutput  out;
        } flReadWriteReq;

        /*
           Assuming :

              char *fromVolName   is the name of the source TrueFFS volume
              char *toVolName     is the name of the target TrueFFS volume

           IMPORTANT: The tffsDevCreate() must be called with FL_DOSFS_LONGNAMES
                      flag in order to make the code below to work. Please see 
                      Section 2.9 for details.
         */

        int                fd1, fd2;
        long               sectors1, sectors2, iSect;
        flDiskInfoOutput   out;
        flReadWriteReq     rwReq;
        char               buf[FL_SECT_SIZE];  /* sector buffer */

        /* get the number of sectors on the source and target TrueFFS
           volumes. Abort is target is smaller then the source
         */
        fd1 = open (fromVolName, O_RDONLY, 0);
        if (fd1 == ERROR)
            return;  /* error */
        if (ioctl (fd1, FL_IOCTL_GET_INFO, (int) &out) == ERROR)
            return;  /* error */
        sectors1      = (long) out.info.logicalSectors;

        fd2 = open (toVolName, O_RDWR, 0);
        if (fd2 == ERROR)
            return;  /* error */
        if (ioctl (fd2, FL_IOCTL_GET_INFO, (int) &out) == ERROR)
            return;  /* error */
        sectors2 = (long) out.info.logicalSectors;

        if (sectors1 > sectors2)
            return;  /* error */

        /* Copy source TrueFFs volume to the target. Sector ## are zero-based. */
        for (iSect = 0; iSect < sectors1; iSect++) {

            /* read the sector from the source volume */
            rwReq.in.firstSector     = iSect;
            rwReq.in.numberOfSectors = (long) 1;
            rwReq.in.buf             = buf;
            if (ioctl (fd1, FL_IOCTL_READ_SECTORS, (int) &rwReq) == ERROR)
                return;  /* error */
	    if ((rwReq.out.numberOfSectors != 1) || (rwReq.out.status != flOK))
                return;  /* error */

            /* write the sector to the target volume */
            rwReq.in.firstSector     = iSect;
            rwReq.in.numberOfSectors = (long) 1;
            rwReq.in.buf             = buf;
            if (ioctl (fd2, FL_IOCTL_WRITE_SECTORS, (int) &rwReq) == ERROR)
                return;  /* error */
	    if ((rwReq.out.numberOfSectors != 1) || (rwReq.out.status != flOK))
                return;  /* error */
        }

        (void) close (fd1);
        (void) close (fd2);




9. Known problems
-----------------

9.1. The VxWorks's routine dosFsMkfs() seems to be incompatible with
     the original MS-DOS FAT volume formats. Please use tffsDevFormat()
     routine instead (see Section 5 above) for creating dosFs file
     system structures on the DiskOnChip.


9.2. If you are experiencing file system corruption symptoms, please 
     check if the support for long filenames (option DOS_OPT_LONGNAMES) is 
     enabled in dosFs. If it is, you will have to pass FL_DOSFS_LONGNAMES 
     flag to tffsDevCreate() (see Section 2.7). Make sure to re-format
     the DiskOnChip with tffsDevFormat() (see Section 5) before calling
     tffsDevCreate().






Appendix A. Formatting the bootable DiskOnChip.
-----------------------------------------------

The code example below shows how to re-format the DiskOnChip in case when
DiskOnChip is used to boot VxWorks.


        /* VxWorks includes */
        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
        #include <dosFsLib.h>
        #include <ioLib.h>
        #include <stat.h>
        
        /* M-Systems includes */
        #include "fldrvvxw.h"
        #include "flioctl.h"
 


        /* DiskOnChip base address */
        #define DOC_ADDR   0xd0000
        
        /* taken from target/config/<x86-bsp>/mkboot.c */
        #define VXSYS_ID	"WINDRIVR"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -