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

📄 fs.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
    // If the file was not opened for reading, then return an error.    //    if(!(pFile->ucFlags & FS_OPEN_READ))    {        return(0);    }#ifdef SUPPORT_RIGHTS_PD    //    // See if this is a DigiFile.    //    if(pFile->ulHeaderSize != 0)    {        //        // Read data from the file, which will also decrypt the bytes.        //        ulCount = FSRead(pFile, pvBuffer, ulNumBytes);        //        // Byte swap the bytes.        //        for(pulPtr = (unsigned long *)pvBuffer, ulIdx = 0;            ulIdx < (ulCount / 4); )        {            //            // Read the next word.            //            ulData = pulPtr[ulIdx];            //            // Write back the byte swapped word.            //            pulPtr[ulIdx++] = (((ulData << 24) & 0xff000000) |                               ((ulData << 8) & 0x00ff0000) |                               ((ulData >> 8) & 0x0000ff00) |                               ((ulData >> 24) & 0x000000ff));        }        //        // Return the number of bytes read.        //        return(ulCount);    }    else#endif    {        //        // Pass the read request to the entry point for the specified drive.        //        return((pfnIoctl[pFile->ucDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                          IOCTL_FS_READ_BS,                                          (unsigned long)&pFile->uInternal,                                          (unsigned long)pvBuffer,                                          ulNumBytes));    }}//****************************************************************************//// FSWrite writes data to the opened file.////****************************************************************************unsigned longFSWrite(tFile *pFile, void *pvBuffer, unsigned long ulNumBytes){    //    // If the file was not opened for writing, then return an error.    //    if(!(pFile->ucFlags & FS_OPEN_WRITE))    {        return(0);    }    //    // Pass the write request to the entry point for the specified drive.    //    return((pfnIoctl[pFile->ucDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                      IOCTL_FS_WRITE,                                      (unsigned long)&pFile->uInternal,                                      (unsigned long)pvBuffer, ulNumBytes));}//****************************************************************************//// FSSeek moves the read/write pointer for the opened file to the specified// position.////****************************************************************************unsigned longFSSeek(tFile *pFile, unsigned long ulPos){    //    // Pass the seek request to the entry point for the specified drive.    //    return((pfnIoctl[pFile->ucDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                      IOCTL_FS_SEEK,                                      (unsigned long)&pFile->uInternal,#ifdef SUPPORT_RIGHTS_PD                                      ulPos + pFile->ulHeaderSize,#else                                      ulPos,#endif                                      pFile->ucFlags));}//****************************************************************************//// FSDriveNum returns the number of the drive on which the currently opened// file resides.////****************************************************************************unsigned longFSDriveNum(tFile *pFile){    //    // Return the drive number.    //    return(pFile->ucDrive);}//****************************************************************************//// FSTell returns the current read/write for the opened file.////****************************************************************************unsigned longFSTell(tFile *pFile){    unsigned long ulPos;    //    // Pass the pointer position request to the entry point for the specified    // drive.    //    ulPos = (pfnIoctl[pFile->ucDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                       IOCTL_FS_TELL,                                       (unsigned long)&pFile->uInternal, 0, 0);    //    // Return the current file pointer.    //#ifdef SUPPORT_RIGHTS_PD    return(ulPos - pFile->ulHeaderSize);#else    return(ulPos);#endif}//****************************************************************************//// FSLength returns the length of the currently opened file.////****************************************************************************unsigned longFSLength(tFile *pFile){    unsigned long ulLength;    //    // Pass the length request to the entry point for the specified drive.    //    ulLength = (pfnIoctl[pFile->ucDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                          IOCTL_FS_LENGTH,                                          (unsigned long)&pFile->uInternal, 0,                                          0);    //    // Return the length of the file.    //#ifdef SUPPORT_RIGHTS_PD    return(ulLength - pFile->ulHeaderSize);#else    return(ulLength);#endif}//****************************************************************************//// FSGetDate returns the modification date/time of the currently opened file.////****************************************************************************unsigned longFSGetDate(tFile *pFile){    //    // Pass the modification date/time request to the entry point for the    // specified drive.    //    return((pfnIoctl[pFile->ucDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                      IOCTL_FS_GETDATE,                                      (unsigned long)&pFile->uInternal, 0, 0));}//****************************************************************************//// FSClose closes the currently opened file.////****************************************************************************unsigned longFSClose(tFile *pFile){    unsigned long ulRet;#ifdef SUPPORT_RIGHTS_PD    //    // See if this is a DigiFile.    //    if(pFile->ulHeaderSize != 0)    {        //        // Close the Rights/PD library.        //        RPDLib_Close(pFile);    }#endif    //    // Pass the close request to the entry point for the specified drive.    //    ulRet = (pfnIoctl[pFile->ucDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                       IOCTL_FS_CLOSE,                                       (unsigned long)&pFile->uInternal,                                       pFile->ucFlags, 0);    //    // If the close succeeded, then decrement the count of opened files.    //    if(ulRet)    {        sFS.usNumFiles--;    }    //    // Return the result to the caller.    //    return(ulRet);}//****************************************************************************//// FSDelete removes the specified file from the file system.////****************************************************************************unsigned longFSDelete(unsigned long ulDrive, const unsigned short *pusFileName){    //    // If there is a file opened, then return an error.  This is to simplify    // file system code development since it does not have to handle the case    // of deleting a currently opened file.    //    if(sFS.usNumFiles)    {        return(0);    }    //    // If the drive number is invalid, then return a failure.    //    if(ulDrive >= NUMFS)    {        return(0);    }    //    // Pass the delete request to the entry point for the specified drive.    //    return((pfnIoctl[ulDrive])(sFS.ucScratch, sFS.pucWriteScratch,                               IOCTL_FS_DELETE, 0, (unsigned long)pusFileName,                               0));}//****************************************************************************//// FSOpenDir opens the specified directory on the specified drive.////****************************************************************************unsigned longFSOpenDir(tDir *pDir, unsigned long ulDrive, const unsigned short *pusDirName){    unsigned long ulRet;    //    // If the drive number is invalid, then return a failure.    //    if(ulDrive >= NUMFS)    {        return(0);    }    //    // Pass the open directory request to the entry point for the specified    // drive.    //    ulRet = (pfnIoctl[ulDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                IOCTL_FS_OPENDIR,                                (unsigned long)&pDir->uInternal,                                (unsigned long)pusDirName, 0);    //    // If the open directory succeeded, then increment the count of opened    // directories.    //    if(ulRet)    {        //        // Remember the drive on which this directory resides.        //        pDir->ucDrive = ulDrive;        //        // Increment the count of opened directories.        //        sFS.usNumDirs++;    }    //    // Return the result to the caller.    //    return(ulRet);}//****************************************************************************//// FSReadDir reads the next directory entry from the currently opened// directory.////****************************************************************************unsigned longFSReadDir(tDir *pDir, unsigned short *pusFileName, unsigned long ulType){    //    // Pass the read directory request to the entry point for the specified    // drive.    //    return((pfnIoctl[pDir->ucDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                     IOCTL_FS_READDIR,                                     (unsigned long)&pDir->uInternal,                                     (unsigned long)pusFileName, ulType));}//****************************************************************************//// FSCloseDir closes the currently opened directory.////****************************************************************************unsigned longFSCloseDir(tDir *pDir){    unsigned long ulRet;    //    // Pass the close directory request to the entry point for the specified    // drive.    //    ulRet = (pfnIoctl[pDir->ucDrive])(sFS.ucScratch, sFS.pucWriteScratch,                                      IOCTL_FS_CLOSEDIR,                                      (unsigned long)&pDir->uInternal, 0, 0);    //    // If the close directory succeeded, then decrement the count of opened    // directories.    //    if(ulRet)    {        sFS.usNumDirs--;    }    //    // Return the result to the caller.    //    return(ulRet);}//****************************************************************************//// FSMakeDir creates the specified directory on the specified drive.  This// will create any/all directories in the specified path.////****************************************************************************unsigned longFSMakeDir(unsigned long ulDrive, const unsigned short *pusDirName){    //    // If the drive number is invalid, then return a failure.    //    if(ulDrive >= NUMFS)    {        return(0);    }    //    // Pass the create directory request to the entry point for the specified    // drive.    //    return((pfnIoctl[ulDrive])(sFS.ucScratch, sFS.pucWriteScratch,                               IOCTL_FS_MAKEDIR, 0, (unsigned long)pusDirName,                               0));}//****************************************************************************//// FSRemoveDir removes the specified directry from the specified drive.////****************************************************************************unsigned longFSRemoveDir(unsigned long ulDrive, const unsigned short *pusDirName){    //    // Do not allow directories to be removed if a directory scan is in    // progress (to avoid removing the directory that is currently being    // scanned).    //    if(sFS.usNumDirs)    {        return(0);    }    //    // If the drive number is invalid, then return a failure.    //    if(ulDrive >= NUMFS)    {        return(0);    }    //    // Pass the remove directory request to the entry point for the specified    // drive.    //    return((pfnIoctl[ulDrive])(sFS.ucScratch, sFS.pucWriteScratch,                               IOCTL_FS_REMOVEDIR, 0,                               (unsigned long)pusDirName, 0));}//****************************************************************************//// FSTotalSpace returns the total capacity of the specified drive.////****************************************************************************unsigned longFSTotalSpace(unsigned long ulDrive){    //    // If the drive number is invalid, then return a failure.    //    if(ulDrive >= NUMFS)    {        return(0);    }    //    // Pass the total space request to the entry point for the specified drive.    //    return((pfnIoctl[ulDrive])(sFS.ucScratch, sFS.pucWriteScratch,                               IOCTL_FS_TOTALSPACE, 0, 0, 0));}//****************************************************************************//// FSFreeSpace returns the currently available capacity on the specified// drive.////****************************************************************************unsigned longFSFreeSpace(unsigned long ulDrive){    //    // If the drive number is invalid, then return a failure.    //    if(ulDrive >= NUMFS)    {        return(0);    }    //    // Pass the free space request to the entry point for the specified drive.    //    return((pfnIoctl[ulDrive])(sFS.ucScratch, sFS.pucWriteScratch,                               IOCTL_FS_FREESPACE, 0, 0, 0));}//****************************************************************************//// FSFormat formats the specified drive.////****************************************************************************unsigned longFSFormat(unsigned long ulDrive){    //    // If there is a file or directory opened, then return a failure.    //    if(sFS.usNumFiles || sFS.usNumDirs)    {        return(0);    }    //    // If the drive number is invalid, then return a failure.    //    if(ulDrive >= NUMFS)    {        return(0);    }    //    // Pass the format request to the entry point for the specified drive.    //    return((pfnIoctl[ulDrive])(sFS.ucScratch, sFS.pucWriteScratch,                               IOCTL_FS_FORMAT, 0, 0, 0));}

⌨️ 快捷键说明

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