diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt new file mode 100644 index 0000000..fb3b79e --- /dev/null +++ b/.github/.cSpellWords.txt @@ -0,0 +1,219 @@ +ACDM +ACMD +Adma +AMCD +Appli +ARGMT +ARMA +ARMR +ASSD +Atmel +ATSAM +blocknr +BTST +capitalised +cbmc +CBMC +cbor +CBOR +CCRC +CCRCFAIL +CEATA +CEATAEND +Chrs +CLKCR +CLKEN +clks +CLUS +cmock +Cmock +CMock +CMOCK +CNTR +Comd +coremqtt +coverity +Coverity +Cplt +CPSECURE +CPSM +CREATELFNS +CSDK +cstrntowcs +ctest +DBCKEND +DBLOCKSIZE +DCMAKE +DCMOCK +DCOUNT +DCRC +DCRCE +DCRCFAIL +DCTRL +Defl +DESEL +DESTROYIOMAN +DFREERTOS +DIREC +DMAEN +DNDEBUG +DPSM +DTDIR +DTIMER +DTMODE +DTOE +DUNITY +ECAPS +EMIO +EMMC +ENCMDCOMPL +ENMFILE +evsetup +EXTI +ffconfig +FFERRTAB +FFFUNCTIONTAB +FFMODULETAB +FSEL +fwrev +getpacketid +GPIO +GPIOC +GPIOD +hdma +hdmarx +hdmatx +Hein +Hidd +hsdio +HSMCI +HWFC +hwreset +hwrev +IDEN +ILGL +INSRT +ioman +IRAM +ISEOF +isystem +ITAPCHGWIN +ITAPDLY +ITAPDLYENA +ITAPDLYSEL +lcov +MBURST +MINC +misra +Misra +MISRA +MISRAC +MMCA +MMIO +MQTT +msdelay +msdely +MSMCI +MSWIN +mypy +mytoken +NIEN +NODISK +NOINIT +NOMEDIUM +NSAC +NVIC +oemid +optimise +OPTIMISE +optimised +Optimised +optimising +OTAPDLY +OTAPDLYENA +OTAPDLYSEL +OVRE +OVRWR +PBURST +PCLK +Periph +PERIPH +PFCTRL +PINC +PTABLE +PTBL +PWRCTRL +PWRSAV +PWRUP +pxhandle +pylint +pytest +pyyaml +REGD +Resvd +RPBM +RPMB +Rsvd +RTOSFAT +RWMOD +RWSTART +RWSTOP +RXACT +RXBUFF +RXDAVL +RXFIFOE +RXFIFOF +RXFIFOHF +RXOVERR +SCUGIC +SDCLK +SDCOMBO +sddisk +SDHC +SDHS +SDID +SDIDCOUNT +SDIF +SDIO +SDIOCK +SDIOCLK +SDIOEN +SDIOIT +SDIOSUSPEND +SDMA +SDMMC +SDMMCCLK +SDPS +SDSC +sdtype +SDXC +sinclude +sinit +STBITERR +STBY +SWRST +TAAC +tacc +TFXFIFOHE +Tibosch +tobe +TPASTE +TXACT +TXBUFF +TXDAVL +TXFIFOE +TXFIFOF +TXFIFOHE +TXUNDERR +UNACKED +UNRE +UNSTUFF +utest +VSEL +Walmsley +Wunused +xilffs +XPAR +xsdps +Zynd +ZYNQ diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 68f0e0b..ae3e13e 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,70 +1,111 @@ # Contribution guidelines -Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, code, or -documentation, we welcome our community to be involved in this project. +Thank you for your interest in contributing to our project. Whether it's a bug +report, new feature, code, or documentation, we welcome our community to be +involved in this project. -Please read through this document before submitting any issues or pull requests to ensure we are able to help you and all members of the community as effectively as possible. +Please read through this document before submitting any issues or pull requests +to ensure we are able to help you and all members of the community as +effectively as possible. ## Code of conduct -This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). -For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact -opensource-codeofconduct@amazon.com with any additional questions or comments. +This project has adopted the +[Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). +For more information see the +[Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact +opensource-codeofconduct@amazon.com with any additional questions or comments. ## Security issue notifications -If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. +If you discover a potential security issue in this project we ask that you +notify AWS/Amazon Security via our +[vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). +Please do **not** create a public github issue. ## Submitting a bugs/feature request + Have a bug to report or feature to request? Follow these steps: -1. Search on the [FreeRTOS Community Support Forums](https://forums.freertos.org/), [FreeRTOS-Plus-FAT issue tracker](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT/issues?utf8=%E2%9C%93&q=is%3Aissue) and [FreeRTOS GitHub issue tracker](https://github.com/FreeRTOS/FreeRTOS/issues?utf8=%E2%9C%93&q=is%3Aissue) to be sure this hasn't been already reported or discussed. -2. If your search turns up empty, create a new topic in the [forums](https://forums.freertos.org/) and work with the community to help clarify issues or refine the idea. Include as many of the details listed below. -3. Once the community has had time to discuss and digest, we welcome you to create an [issue](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT/issues) to report bugs or suggest features. + +1. Search on the +[FreeRTOS Community Support Forums](https://forums.freertos.org/), +[FreeRTOS-Plus-FAT issue tracker](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT/issues?utf8=%E2%9C%93&q=is%3Aissue) +and +[FreeRTOS GitHub issue tracker](https://github.com/FreeRTOS/FreeRTOS/issues?utf8=%E2%9C%93&q=is%3Aissue) +to be sure this hasn't been already reported or discussed. +2. If your search turns up empty, create a new topic in the +[forums](https://forums.freertos.org/) and work with the community to help +clarify issues or refine the idea. Include as many of the details listed below. +3. Once the community has had time to discuss and digest, we welcome you to +create an [issue](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT/issues) +to report bugs or suggest features. When creating a new topic on the forums or filing an issue, please include as many relevant details as possible. Examples include: -* A clear description of the situation — what you observe, what you expect, and your view on how the two differ. +* A clear description of the situation — what you observe, what you expect, +and your view on how the two differ. * A reproducible test case or sequence of steps. * The version of our code being used. * Any modifications you've made relevant to the bug. * Details of your environment or deployment. Highlight anything unusual. - ## Contributing via pull request -Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: -1. You are working against the latest source on the *master* branch. -2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. -3. You open an issue to discuss any significant work - we would hate for your time to be wasted. +Contributions via pull requests are much appreciated. Before sending us a pull +request, please ensure that: + +1. You are working against the latest source on the *main* branch. +2. You check existing open, and recently merged, pull requests to make sure +someone else hasn't addressed the problem already. +3. You open an issue to discuss any significant work - we would hate for your +time to be wasted. To send us a pull request, please: 1. Fork the repository. -2. Modify the source; focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. -3. Follow the [coding style guide](https://www.freertos.org/FreeRTOS-Coding-Standard-and-Style-Guide.html). +2. Modify the source; focus on the specific change you are contributing. +If you also reformat all the code, it will be hard for us to focus on your +change. +3. Follow the +[coding style guide](https://www.freertos.org/FreeRTOS-Coding-Standard-and-Style-Guide.html). 4. Commit to your fork using clear commit messages. 5. Send us a pull request, answering any default questions in the pull request interface. NOTE: Please make sure the default option (Allow edits from maintainers) is left checked. 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. -GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and +GitHub provides additional document on +[forking a repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). ## Coding style -* Please ensure that your code complies to the [FreeRTOS coding style guidelines](https://www.freertos.org/FreeRTOS-Coding-Standard-and-Style-Guide.html). +* Please ensure that your code complies to the +[FreeRTOS coding style guidelines](https://www.freertos.org/FreeRTOS-Coding-Standard-and-Style-Guide.html). ## Getting your pull request merged -All pull requests must be approved by our review team before it can be merged in. We appreciate your patience while pull requests are reviewed. The time it takes to review will depend on complexity and consideration of wider implications. +All pull requests must be approved by our review team before it can be merged +in. We appreciate your patience while pull requests are reviewed. The time it +takes to review will depend on complexity and consideration of wider +implications. ## Finding contributions to work on -Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), tackling open 'help wanted' issues is a great place to start. +Looking at the existing issues is a great way to find something to contribute +on. As our projects, by default, use the default GitHub issue labels +(enhancement/ bug/duplicate/help wanted/invalid/question/wontfix), tackling open +'help wanted' issues is a great place to start. ## Licensing -The FreeRTOS-Plus-FAT library is released under the MIT open source license, the text of which can be found [here](https://github.com/FreeRTOS/FreeRTOS-Plus-FAT/blob/master/LICENSE.md) -Additional license files can be found in the folders containing any supplementary libraries licensed by their respective copyright owners where applicable. +The FreeRTOS-Plus-FAT library is released under the MIT open source license, +the text of which can be found +[here](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT/blob/main/LICENSE.md) + +Additional license files can be found in the folders containing any +supplementary libraries licensed by their respective copyright owners where +applicable. -We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. +We may ask you to sign a +[Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) +for larger changes. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea56938..396eb33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,41 +9,33 @@ on: jobs: # Currently no unit tests - # Currently no spell-check - formatting: runs-on: ubuntu-20.04 - container: ubuntu:18.04 steps: - uses: actions/checkout@v3 - - name: Install Uncrustify - run: apt-get update && apt-get install uncrustify - - name: Run Uncrustify - run: | - uncrustify --version - find . -iname "*.[hc]" -exec uncrustify --check -c tools/uncrustify.cfg {} + - if [ "$?" = "0" ]; then - exit 0 - else - echo -e "\033[31;1;43mFormatting check (using Uncrustify) failed...\033[0m" - echo -e "\033[32;3mTo have the code uncrustified for you, please comment '/bot run uncrustify' (without the quotes) on the Pull Request.\033[0m" - exit 1 - fi - - name: Check For Trailing Whitespace - run: | - set +e - grep --exclude="README.md" -rnI -e "[[:blank:]]$" . - if [ "$?" = "0" ]; then - echo "Files have trailing whitespace." - exit 1 - else - exit 0 - fi + - name: Check Formatting of Files + uses: FreeRTOS/CI-CD-Github-Actions/formatting@main + + spell-check: + runs-on: ubuntu-latest + steps: + - name: Clone This Repo + uses: actions/checkout@v3 + - name: Run spellings check + uses: FreeRTOS/CI-CD-Github-Actions/spellings@main + + link-verifier: + runs-on: ubuntu-latest + steps: + - name: Clone This Repo + uses: actions/checkout@v3 + - name: Link Verification + uses: FreeRTOS/CI-CD-Github-Actions/link-verifier@main # doxygen: - # runs-on: ubuntu-20.04 + # runs-on: ubuntu-latest # steps: - # - uses: actions/checkout@v2 + # - uses: actions/checkout@v3 # - name: Run doxygen build # uses: FreeRTOS/CI-CD-Github-Actions/doxygen@main # with: @@ -52,7 +44,7 @@ jobs: build-checks: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Build checks (Default configuration) run: | cmake -S . -B build -DFREERTOS_PLUS_FAT_TEST_CONFIGURATION=DEFAULT_CONF @@ -61,7 +53,7 @@ jobs: # complexity: # runs-on: ubuntu-latest # steps: - # - uses: actions/checkout@v2 + # - uses: actions/checkout@v3 # - name: Setup # run: sudo apt-get install complexity # - name: Install Uncrustify @@ -92,11 +84,11 @@ jobs: git-secrets: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - name: Checkout awslabs/git-secrets - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: awslabs/git-secrets ref: master diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml new file mode 100644 index 0000000..14d41c9 --- /dev/null +++ b/.github/workflows/formatting.yml @@ -0,0 +1,25 @@ +name: Format Pull Request Files + +on: + issue_comment: + types: [created] + +env: + bashPass: \033[32;1mPASSED - + bashInfo: \033[33;1mINFO - + bashFail: \033[31;1mFAILED - + bashEnd: \033[0m + +jobs: + Formatting: + name: Run Formatting Check + if: ${{ github.event.issue.pull_request && + ( ( github.event.comment.body == '/bot run uncrustify' ) || + ( github.event.comment.body == '/bot run formatting' ) ) }} + runs-on: ubuntu-20.04 + steps: + - name: Apply Formatting Fix + id: check-formatting + uses: FreeRTOS/CI-CD-Github-Actions/formatting-bot@main + with: + exclude-dirs: portable diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml deleted file mode 100644 index 1165fc9..0000000 --- a/.github/workflows/uncrustify.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Uncrustify the source code - -on: - issue_comment: - types: [created] - -jobs: - Uncrustify: - name: Run_Uncrustify - if: ${{ github.event.issue.pull_request && github.event.comment.body == '/bot run uncrustify' }} - runs-on: ubuntu-20.04 - container: ubuntu:18.04 - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Install Utils - run: | - apt-get update && apt-get --assume-yes install software-properties-common curl jq sed - add-apt-repository ppa:git-core/ppa - apt-get update && apt-get --assume-yes install git - git --version - - name: get pullrequest url - run: | - echo ${{ github.event.issue.pull_request.url }} - - name: get upstream repo - id: upstreamrepo - run: | - echo "RemoteRepo=$(curl -H "Accept: application/vnd.github.sailor-v-preview+json" --url ${{ github.event.issue.pull_request.url }} | jq '.head.repo.full_name' | sed 's/\"//g')" >> $GITHUB_OUTPUT - - name: get upstream branch - id: upstreambranch - run: | - echo "branchname=$(curl -H "Accept: application/vnd.github.sailor-v-preview+json" --url ${{ github.event.issue.pull_request.url }} | jq '.head.ref' | sed 's/\"//g')" >> $GITHUB_OUTPUT - - name: echo upstream repo:branch - run: | - echo ${{ steps.upstreamrepo.outputs.RemoteRepo }}:${{ steps.upstreambranch.outputs.branchname }} - - name: Checkout upstream repo - uses: actions/checkout@v3 - with: - repository: ${{ steps.upstreamrepo.outputs.RemoteRepo }} - ref: ${{ steps.upstreambranch.outputs.branchname }} - - name: Install Uncrustify - run: apt-get update && apt-get --assume-yes install uncrustify - - name: Run Uncrustify - run: | - uncrustify --version - find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + - find . -iname "*.[hc]" -exec uncrustify -c tools/uncrustify.cfg --no-backup --replace {} + - - name: Push changes to upstream repository - run: | - git config --global --add safe.directory '*' - git config --global user.name 'GitHub Action' - git config --global user.email 'action@github.com' - git add -A - git commit -m "Uncrustify: triggered by comment." - git push diff --git a/CMakeLists.txt b/CMakeLists.txt index 5519b31..7923413 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ endif() # - when OFF - device support is disabled and not used. # - When ON - device support is enabled and the ff_devices.h API is used. # Optional: FREERTOS_PLUS_FAT_PORT -# - When not defined - identifies native platform Linxu or MinGW and uses that port. +# - When not defined - identifies native platform Linux or MinGW and uses that port. # - When defined as A_CUSTOM_PORT - the port library must be defined in advance. # - When any of the other supported ports - the port library is defined by portable source files. option(FREERTOS_PLUS_FAT_DEV_SUPPORT "FreeRTOS Plus FAT Device selection support" OFF) @@ -119,7 +119,7 @@ endif() # - When ON - FreeRTOS-kernel will be fetch using CMake FetchContent_Declare function. # Optional: FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_REPO # Optional: FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_TAG -option(FREERTOS_PLUS_FAT_FETCH_FREERTOS "FreeRTOS-Kernel automatic fecth support" ON) +option(FREERTOS_PLUS_FAT_FETCH_FREERTOS "FreeRTOS-Kernel automatic fetch support" ON) set(FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_REPO "https://github.com/FreeRTOS/FreeRTOS-Kernel.git" CACHE STRING "") set(FREERTOS_PLUS_FAT_FETCH_FREERTOS_GIT_TAG "main" CACHE STRING "") @@ -219,6 +219,13 @@ target_link_libraries( freertos_plus_fat add_subdirectory(portable) add_subdirectory(test) +# This library requires access to a heap +# FreeRTOS/FreeRTOS-Kernel previously defaulted to heap_4.c +if(NOT DEFINED FREERTOS_HEAP) + message(STATUS "FREERTOS_HEAP not set, setting FREERTOS_HEAP=4") + set(FREERTOS_HEAP 4) +endif() + if(FREERTOS_PLUS_FAT_FETCH_FREERTOS) FetchContent_MakeAvailable(freertos_kernel) endif() diff --git a/History.txt b/History.txt old mode 100755 new mode 100644 diff --git a/README.md b/README.md index 4b31070..9651419 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,30 @@ -## FreeRTOS+FAT: DOS Compatible Embedded FAT File System +# FreeRTOS+FAT: DOS Compatible Embedded FAT File System -FreeRTOS+FAT is an open source, thread aware and scalable FAT12/FAT16/FAT32 DOS/Windows compatible embedded FAT file system which was recently acquired by [Real Time Engineers ltd](). for use with and without the RTOS. +FreeRTOS+FAT is an open source, thread aware and scalable FAT12/FAT16/FAT32 DOS +/Windows compatible embedded FAT file system which was recently acquired by +[Real Time Engineers ltd](). for use with and without FreeRTOS. -FreeRTOS+FAT is already used in commercial products, and is the file system used in the [FTP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FTP_Server.html) and [HTTP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/HTTP_web_Server.html) server examples that are documented on the [FreeRTOS+TCP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html) pages. +FreeRTOS+FAT is already used in commercial products, and is the file system +used in the +[FTP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/FTP_Server.html) +and +[HTTP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/HTTP_web_Server.html) +server examples that are documented on the +[FreeRTOS+TCP](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html) +pages. -The [standard C library style API](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/Standard_File_System_API.html) includes a thread local errno value, and the lower level native API provides a rich set of detailed error codes. +The +[standard C library style API](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/Standard_File_System_API.html) +includes a thread local errno value, and the lower level native API provides a +rich set of detailed error codes. -For more details, please visit [FreeRTOS+FAT](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/index.html) page. +For more details, please visit +[FreeRTOS+FAT](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/index.html) page. ## To consume FreeRTOS+FAT ### Consume with CMake + If using CMake, it is recommended to use this repository using FetchContent. Add the following into your project's main or a subdirectory's `CMakeLists.txt`: @@ -37,10 +51,15 @@ endif() FetchContent_MakeAvailable(freertos_plus_fat) ``` -If you already have FreeRTOS in your project, you may skip the fetch content by setting `FREERTOS_PLUS_FAT_FETCH_FREERTOS` to `OFF`. +If you already have FreeRTOS in your project, you may skip the fetch content by setting +`FREERTOS_PLUS_FAT_FETCH_FREERTOS` to `OFF`. ### Consuming stand-alone -It is recommended to use this repository as a submodule. Please refer to [Git Tools — Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). + +It is recommended to use this repository as a submodule. Please refer to +[Git Tools — Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). ## Notes -This project is undergoing optimizations or refactorization to improve memory usage, modularity, documentation, demo usability, or test coverage. \ No newline at end of file + +This project is undergoing optimizations or refactoring to improve memory usage, +modularity, documentation, demo usability, or test coverage. diff --git a/ReadMe.url b/ReadMe.url old mode 100755 new mode 100644 diff --git a/cspell.config.yaml b/cspell.config.yaml new file mode 100644 index 0000000..911ce1d --- /dev/null +++ b/cspell.config.yaml @@ -0,0 +1,31 @@ +--- +$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json +version: '0.2' +# Allows things like stringLength +allowCompoundWords: true + +# Read files not to spell check from the git ignore +useGitignore: true + +# Language settings for C +languageSettings: + - caseSensitive: false + enabled: true + languageId: c + locale: "*" + +# Add a dictionary, and the path to the word list +dictionaryDefinitions: + - name: freertos-words + path: '.github/.cSpellWords.txt' + addWords: true + +dictionaries: + - freertos-words + +# Paths and files to ignore +ignorePaths: + - 'dependency' + - 'docs' + - 'ThirdParty' + - 'History.txt' diff --git a/ff_crc.c b/ff_crc.c old mode 100755 new mode 100644 index baebb48..ce0650f --- a/ff_crc.c +++ b/ff_crc.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/ff_dev_support.c b/ff_dev_support.c old mode 100755 new mode 100644 index 11a0ea5..26a8ea2 --- a/ff_dev_support.c +++ b/ff_dev_support.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/ff_dir.c b/ff_dir.c index f422e56..04cf851 100644 --- a/ff_dir.c +++ b/ff_dir.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -49,7 +49,7 @@ #include #endif -/* Calculate a simple LFN checmsum. */ +/* Calculate a simple LFN checksum. */ static uint8_t FF_CreateChkSum( const uint8_t * pa_pShortName ); static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, @@ -211,27 +211,27 @@ static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, *pxError = FF_ERR_NONE; #if ( ffconfigHASH_CACHE != 0 ) + { + if( !FF_DirHashed( pxIOManager, ulDirCluster ) ) { - if( !FF_DirHashed( pxIOManager, ulDirCluster ) ) - { - /* Hash the directory. */ - FF_HashDir( pxIOManager, ulDirCluster ); - } + /* Hash the directory. */ + FF_HashDir( pxIOManager, ulDirCluster ); + } - #if ffconfigHASH_FUNCTION == CRC16 - { - ulHash = ( uint32_t ) FF_GetCRC16( ( uint8_t * ) pcShortName, ( uint32_t ) strlen( pcShortName ) ); - } - #else /* ffconfigHASH_FUNCTION == CRC8 */ - { - ulHash = ( uint32_t ) FF_GetCRC8( ( uint8_t * ) pcShortName, ( uint32_t ) strlen( pcShortName ) ); - } - #endif - { - /* FF_CheckDirentHash result: 0 not found, 1 found, -1 directory not hashed */ - xResult = FF_CheckDirentHash( pxIOManager, ulDirCluster, ulHash ); - } + #if ffconfigHASH_FUNCTION == CRC16 + { + ulHash = ( uint32_t ) FF_GetCRC16( ( uint8_t * ) pcShortName, ( uint32_t ) strlen( pcShortName ) ); + } + #else /* ffconfigHASH_FUNCTION == CRC8 */ + { + ulHash = ( uint32_t ) FF_GetCRC8( ( uint8_t * ) pcShortName, ( uint32_t ) strlen( pcShortName ) ); } + #endif + { + /* FF_CheckDirentHash result: 0 not found, 1 found, -1 directory not hashed */ + xResult = FF_CheckDirentHash( pxIOManager, ulDirCluster, ulHash ); + } + } #endif /* if ( ffconfigHASH_CACHE != 0 ) */ if( xResult < 0 ) @@ -354,19 +354,19 @@ static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, #endif /* ffconfigLFN_SUPPORT */ #if ( ffconfigLFN_SUPPORT != 0 ) - { - #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - BaseType_t NameLen = ( BaseType_t ) wcslen( ( const char * ) pcName ); - #else - BaseType_t NameLen = ( BaseType_t ) strlen( ( const char * ) pcName ); - #endif - /* Find enough places for the LFNs and the ShortName. */ - entriesNeeded = ( uint8_t ) ( ( NameLen + 12 ) / 13 ) + 1; - } + { + #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) + BaseType_t NameLen = ( BaseType_t ) wcslen( ( const char * ) pcName ); + #else + BaseType_t NameLen = ( BaseType_t ) strlen( ( const char * ) pcName ); + #endif + /* Find enough places for the LFNs and the ShortName. */ + entriesNeeded = ( uint8_t ) ( ( NameLen + 12 ) / 13 ) + 1; + } #else - { - entriesNeeded = 1; - } + { + entriesNeeded = 1; + } #endif /* ffconfigLFN_SUPPORT */ if( ( pxFindParams->ulFlags & FIND_FLAG_FITS_SHORT_OK ) == FIND_FLAG_FITS_SHORT_OK ) @@ -438,9 +438,9 @@ static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, /* The current entry is in use, so reset the free-entry-counter */ freeCount = 0; #if ( ffconfigLFN_SUPPORT != 0 ) - { - lastAttrib = pxDirEntry->ucAttrib; - } + { + lastAttrib = pxDirEntry->ucAttrib; + } #endif pxDirEntry->ucAttrib = FF_getChar( src, FF_FAT_DIRENT_ATTRIB ); @@ -449,122 +449,122 @@ static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, { /* LFN Processing. */ #if ( ffconfigLFN_SUPPORT != 0 ) + { + if( ( xLFNCount == 0 ) || ( ( lastAttrib & FF_FAT_ATTR_LFN ) != FF_FAT_ATTR_LFN ) ) { - if( ( xLFNCount == 0 ) || ( ( lastAttrib & FF_FAT_ATTR_LFN ) != FF_FAT_ATTR_LFN ) ) - { - xLFNTotal = xLFNCount = ( BaseType_t ) ( src[ 0 ] & ~0x40 ); - lfnItem = pxDirEntry->usCurrentItem; - ucCheckSum = FF_getChar( src, FF_FAT_LFN_CHECKSUM ); - pcLastPtr[ -1 ] = '\0'; - } + xLFNTotal = xLFNCount = ( BaseType_t ) ( src[ 0 ] & ~0x40 ); + lfnItem = pxDirEntry->usCurrentItem; + ucCheckSum = FF_getChar( src, FF_FAT_LFN_CHECKSUM ); + pcLastPtr[ -1 ] = '\0'; + } - if( xLFNCount != 0 ) + if( xLFNCount != 0 ) + { + xLFNCount--; + pcCurPtr = pxDirEntry->pcFileName + ( xLFNCount * 13 ); + + /* + * This section needs to extract the name and do the comparison + * dependent on UNICODE settings in the FreeRTOSFATConfig.h file. + */ + #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) { - xLFNCount--; - pcCurPtr = pxDirEntry->pcFileName + ( xLFNCount * 13 ); + /* Add UTF-16 Routine here. */ + /* Copy first 5 UTF-16 chars ( 10 bytes ). */ + memcpy( pcCurPtr, &src[ FF_FAT_LFN_NAME_1 ], 10 ); + /* Increment Filename pointer 5 utf16 chars. */ + pcCurPtr += 5; + + /* Copy next 6 chars ( 12 bytes ). */ + memcpy( pcCurPtr, &src[ FF_FAT_LFN_NAME_2 ], 12 ); + pcCurPtr += 6; + + /* You're getting the idea by now! */ + memcpy( pcCurPtr, &src[ FF_FAT_LFN_NAME_3 ], 4 ); + pcCurPtr += 2; + } /* ffconfigUNICODE_UTF16_SUPPORT */ + #elif ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) + { + /* UTF-8 Routine here. */ + for( xIndex = 0; ( xIndex < 5 ) && ( pcCurPtr < pcLastPtr ); xIndex++ ) + { + /* Was there a surrogate sequence? -- Add handling here. */ + utf8Error = FF_Utf16ctoUtf8c( ( uint8_t * ) pcCurPtr, ( uint16_t * ) &src[ FF_FAT_LFN_NAME_1 + ( 2 * xIndex ) ], pcLastPtr - pcCurPtr ); - /* - * This section needs to extract the name and do the comparison - * dependent on UNICODE settings in the FreeRTOSFATConfig.h file. - */ - #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) + if( utf8Error > 0 ) { - /* Add UTF-16 Routine here. */ - /* Copy first 5 UTF-16 chars ( 10 bytes ). */ - memcpy( pcCurPtr, &src[ FF_FAT_LFN_NAME_1 ], 10 ); - /* Increment Filename pointer 5 utf16 chars. */ - pcCurPtr += 5; - - /* Copy next 6 chars ( 12 bytes ). */ - memcpy( pcCurPtr, &src[ FF_FAT_LFN_NAME_2 ], 12 ); - pcCurPtr += 6; - - /* You're getting the idea by now! */ - memcpy( pcCurPtr, &src[ FF_FAT_LFN_NAME_3 ], 4 ); - pcCurPtr += 2; - } /* ffconfigUNICODE_UTF16_SUPPORT */ - #elif ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) + pcCurPtr += utf8Error; + } + else { - /* UTF-8 Routine here. */ - for( xIndex = 0; ( xIndex < 5 ) && ( pcCurPtr < pcLastPtr ); xIndex++ ) + if( FF_GETERROR( utf8Error ) == FF_ERR_UNICODE_INVALID_SEQUENCE ) { - /* Was there a surrogate sequence? -- Add handling here. */ - utf8Error = FF_Utf16ctoUtf8c( ( uint8_t * ) pcCurPtr, ( uint16_t * ) &src[ FF_FAT_LFN_NAME_1 + ( 2 * xIndex ) ], pcLastPtr - pcCurPtr ); - - if( utf8Error > 0 ) - { - pcCurPtr += utf8Error; - } - else - { - if( FF_GETERROR( utf8Error ) == FF_ERR_UNICODE_INVALID_SEQUENCE ) - { - /* Handle potential surrogate sequence across entries. */ - } - } + /* Handle potential surrogate sequence across entries. */ } + } + } - for( xIndex = 0; xIndex < 6 && pcCurPtr < pcLastPtr; xIndex++ ) - { - /* Was there a surrogate sequence? -- To add handling here. */ - utf8Error = FF_Utf16ctoUtf8c( ( uint8_t * ) pcCurPtr, ( uint16_t * ) &src[ FF_FAT_LFN_NAME_2 + ( 2 * xIndex ) ], pcLastPtr - pcCurPtr ); - - if( utf8Error > 0 ) - { - pcCurPtr += utf8Error; - } - else - { - if( FF_GETERROR( utf8Error ) == FF_ERR_UNICODE_INVALID_SEQUENCE ) - { - /* Handle potential surrogate sequence across entries. */ - } - } - } + for( xIndex = 0; xIndex < 6 && pcCurPtr < pcLastPtr; xIndex++ ) + { + /* Was there a surrogate sequence? -- To add handling here. */ + utf8Error = FF_Utf16ctoUtf8c( ( uint8_t * ) pcCurPtr, ( uint16_t * ) &src[ FF_FAT_LFN_NAME_2 + ( 2 * xIndex ) ], pcLastPtr - pcCurPtr ); - for( xIndex = 0; xIndex < 2 && pcCurPtr < pcLastPtr; xIndex++ ) - { - /* Was there a surrogate sequence? -- To add handling here. */ - utf8Error = FF_Utf16ctoUtf8c( ( uint8_t * ) pcCurPtr, ( uint16_t * ) &src[ FF_FAT_LFN_NAME_3 + ( 2 * xIndex ) ], pcLastPtr - pcCurPtr ); - - if( utf8Error > 0 ) - { - pcCurPtr += utf8Error; - } - else - { - if( FF_GETERROR( utf8Error ) == FF_ERR_UNICODE_INVALID_SEQUENCE ) - { - /* Handle potential surrogate sequence across entries. */ - } - } - } - } /* ffconfigUNICODE_UTF8_SUPPORT */ - #else /* if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) */ - { /* use ASCII notation. */ - for( xIndex = 0; ( xIndex < 10 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) + if( utf8Error > 0 ) + { + pcCurPtr += utf8Error; + } + else + { + if( FF_GETERROR( utf8Error ) == FF_ERR_UNICODE_INVALID_SEQUENCE ) { - *( pcCurPtr++ ) = ( char ) src[ FF_FAT_LFN_NAME_1 + xIndex ]; + /* Handle potential surrogate sequence across entries. */ } + } + } - for( xIndex = 0; ( xIndex < 12 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) - { - *( pcCurPtr++ ) = ( char ) src[ FF_FAT_LFN_NAME_2 + xIndex ]; - } + for( xIndex = 0; xIndex < 2 && pcCurPtr < pcLastPtr; xIndex++ ) + { + /* Was there a surrogate sequence? -- To add handling here. */ + utf8Error = FF_Utf16ctoUtf8c( ( uint8_t * ) pcCurPtr, ( uint16_t * ) &src[ FF_FAT_LFN_NAME_3 + ( 2 * xIndex ) ], pcLastPtr - pcCurPtr ); - for( xIndex = 0; ( xIndex < 4 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) + if( utf8Error > 0 ) + { + pcCurPtr += utf8Error; + } + else + { + if( FF_GETERROR( utf8Error ) == FF_ERR_UNICODE_INVALID_SEQUENCE ) { - *( pcCurPtr++ ) = ( char ) src[ FF_FAT_LFN_NAME_3 + xIndex ]; + /* Handle potential surrogate sequence across entries. */ } } - #endif /* ( ffconfigUNICODE_UTF16_SUPPORT == 0 ) && !( ffconfigUNICODE_UTF8_SUPPORT == 0 ) */ + } + } /* ffconfigUNICODE_UTF8_SUPPORT */ + #else /* if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) */ + { /* use ASCII notation. */ + for( xIndex = 0; ( xIndex < 10 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) + { + *( pcCurPtr++ ) = ( char ) src[ FF_FAT_LFN_NAME_1 + xIndex ]; + } - if( ( xLFNCount == xLFNTotal - 1 ) && ( pcCurPtr < pcLastPtr ) ) + for( xIndex = 0; ( xIndex < 12 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) { - *pcCurPtr = '\0'; /* Important when name len is multiple of 13. */ + *( pcCurPtr++ ) = ( char ) src[ FF_FAT_LFN_NAME_2 + xIndex ]; } - } /* if( xLFNCount ) */ - } + + for( xIndex = 0; ( xIndex < 4 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) + { + *( pcCurPtr++ ) = ( char ) src[ FF_FAT_LFN_NAME_3 + xIndex ]; + } + } + #endif /* ( ffconfigUNICODE_UTF16_SUPPORT == 0 ) && !( ffconfigUNICODE_UTF8_SUPPORT == 0 ) */ + + if( ( xLFNCount == xLFNTotal - 1 ) && ( pcCurPtr < pcLastPtr ) ) + { + *pcCurPtr = '\0'; /* Important when name len is multiple of 13. */ + } + } /* if( xLFNCount ) */ + } #endif /* ffconfigLFN_SUPPORT */ continue; } @@ -572,9 +572,9 @@ static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, if( ( pxDirEntry->ucAttrib & FF_FAT_ATTR_VOLID ) == FF_FAT_ATTR_VOLID ) { #if ( ffconfigLFN_SUPPORT != 0 ) - { - xLFNTotal = 0; - } + { + xLFNTotal = 0; + } #endif /* ffconfigLFN_SUPPORT */ continue; } @@ -588,16 +588,16 @@ static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, memcpy( pxDirEntry->pcFileName, src, 11 ); FF_ProcessShortName( ( char * ) pxDirEntry->pcFileName ); #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - { - /* FileName now contains a 8-bit short name - * Expand it to a FF_T_WCHAR string. */ - FF_ShortNameExpand( pxDirEntry->pcFileName ); - } + { + /* FileName now contains a 8-bit short name + * Expand it to a FF_T_WCHAR string. */ + FF_ShortNameExpand( pxDirEntry->pcFileName ); + } #endif /* ffconfigUNICODE_UTF16_SUPPORT */ #if ( ffconfigLFN_SUPPORT != 0 ) - { - xLFNTotal = 0; - } + { + xLFNTotal = 0; + } #endif /* ffconfigLFN_SUPPORT */ } @@ -648,9 +648,9 @@ static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, } #if ( ffconfigLFN_SUPPORT != 0 ) - { - xLFNTotal = 0; - } + { + xLFNTotal = 0; + } #endif } /* for( ; pxDirEntry->usCurrentItem < FF_MAX_ENTRIES_PER_DIRECTORY; pxDirEntry->usCurrentItem++ ) */ @@ -748,29 +748,29 @@ static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, xFound = pdFALSE; - #if ( ffconfigPATH_CACHE != 0 ) /* Is the requested pcPath in the PATH CACHE? */ + #if ( ffconfigPATH_CACHE != 0 ) /* Is the requested pcPath in the PATH CACHE? */ + { + FF_PendSemaphore( pxIOManager->pvSemaphore ); /* Thread safety on shared object! */ { - FF_PendSemaphore( pxIOManager->pvSemaphore ); /* Thread safety on shared object! */ + for( xIndex = 0; xIndex < ffconfigPATH_CACHE_DEPTH; xIndex++ ) { - for( xIndex = 0; xIndex < ffconfigPATH_CACHE_DEPTH; xIndex++ ) + #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) + if( wcslen( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath ) == ( size_t ) pathLen ) + #else + if( strlen( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath ) == ( size_t ) pathLen ) + #endif { - #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - if( wcslen( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath ) == ( size_t ) pathLen ) - #else - if( strlen( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath ) == ( size_t ) pathLen ) - #endif + if( FF_strmatch( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath, pcPath, pathLen ) ) { - if( FF_strmatch( pxIOManager->xPartition.pxPathCache[ xIndex ].pcPath, pcPath, pathLen ) ) - { - xFindParams.ulDirCluster = pxIOManager->xPartition.pxPathCache[ xIndex ].ulDirCluster; - xFound = pdTRUE; - break; - } + xFindParams.ulDirCluster = pxIOManager->xPartition.pxPathCache[ xIndex ].ulDirCluster; + xFound = pdTRUE; + break; } } } - FF_ReleaseSemaphore( pxIOManager->pvSemaphore ); } + FF_ReleaseSemaphore( pxIOManager->pvSemaphore ); + } #endif /* ffconfigPATH_CACHE */ } @@ -798,38 +798,38 @@ static BaseType_t FF_ShortNameExists( FF_IOManager_t * pxIOManager, } #if ( ffconfigPATH_CACHE != 0 ) /* Update the PATH CACHE with a new PATH. */ + { + /* Only cache if the dir was actually found! */ + if( ( FF_isERR( xError ) == pdFALSE ) && ( xFindParams.ulDirCluster != 0ul ) ) { - /* Only cache if the dir was actually found! */ - if( ( FF_isERR( xError ) == pdFALSE ) && ( xFindParams.ulDirCluster != 0ul ) ) + FF_PendSemaphore( pxIOManager->pvSemaphore ); { - FF_PendSemaphore( pxIOManager->pvSemaphore ); + if( pathLen < ffconfigMAX_FILENAME ) /* Ensure the PATH won't cause a buffer overrun. */ { - if( pathLen < ffconfigMAX_FILENAME ) /* Ensure the PATH won't cause a buffer overrun. */ + #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) { - #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - { - memcpy( pxIOManager->xPartition.pxPathCache[ pxIOManager->xPartition.ulPCIndex ].pcPath, pcPath, pathLen * sizeof( FF_T_WCHAR ) ); - } - #else - { - memcpy( pxIOManager->xPartition.pxPathCache[ pxIOManager->xPartition.ulPCIndex ].pcPath, pcPath, pathLen ); - } - #endif + memcpy( pxIOManager->xPartition.pxPathCache[ pxIOManager->xPartition.ulPCIndex ].pcPath, pcPath, pathLen * sizeof( FF_T_WCHAR ) ); + } + #else + { + memcpy( pxIOManager->xPartition.pxPathCache[ pxIOManager->xPartition.ulPCIndex ].pcPath, pcPath, pathLen ); + } + #endif - pxIOManager->xPartition.pxPathCache[ pxIOManager->xPartition.ulPCIndex ].pcPath[ pathLen ] = '\0'; - pxIOManager->xPartition.pxPathCache[ pxIOManager->xPartition.ulPCIndex ].ulDirCluster = xFindParams.ulDirCluster; + pxIOManager->xPartition.pxPathCache[ pxIOManager->xPartition.ulPCIndex ].pcPath[ pathLen ] = '\0'; + pxIOManager->xPartition.pxPathCache[ pxIOManager->xPartition.ulPCIndex ].ulDirCluster = xFindParams.ulDirCluster; - pxIOManager->xPartition.ulPCIndex += 1; + pxIOManager->xPartition.ulPCIndex += 1; - if( pxIOManager->xPartition.ulPCIndex >= ffconfigPATH_CACHE_DEPTH ) - { - pxIOManager->xPartition.ulPCIndex = 0; - } + if( pxIOManager->xPartition.ulPCIndex >= ffconfigPATH_CACHE_DEPTH ) + { + pxIOManager->xPartition.ulPCIndex = 0; } } - FF_ReleaseSemaphore( pxIOManager->pvSemaphore ); } + FF_ReleaseSemaphore( pxIOManager->pvSemaphore ); } + } #endif /* ffconfigPATH_CACHE */ } /* if( pathLen > 1 ) */ @@ -1130,7 +1130,7 @@ FF_Error_t FF_CleanupEntryFetch( FF_IOManager_t * pxIOManager, * * Side effects: * - pxContext->ulCurrentClusterNum : relative cluster number ( 0 <= Num < ulChainLength ) - * - pxContext->ulCurrentClusterLCN : fysical cluster on the partition + * - pxContext->ulCurrentClusterLCN : physical cluster on the partition **/ static FF_Error_t FF_Traverse( FF_IOManager_t * pxIOManager, @@ -1413,147 +1413,147 @@ FF_Error_t FF_PopulateLongDirent( FF_IOManager_t * pxIOManager, ucCheckSum = FF_getChar( pucEntryBuffer, FF_FAT_LFN_CHECKSUM ); #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) + { + /* UTF-16 Can simply get segments of the UTF-16 sequence + * going forward in the directory entries ( but reversed order ). */ + while( xNumLFNs > 0 ) { - /* UTF-16 Can simply get segments of the UTF-16 sequence - * going forward in the directory entries ( but reversed order ). */ - while( xNumLFNs > 0 ) - { - /* Avoid stack intensive use of a UTF-16 buffer. Stream direct to FileName dirent field in correct format. */ - /* memcpy direct! -UTF-16 support. */ - memcpy( pxDirEntry->pcFileName + ( ( xNumLFNs - 1 ) * 13 ) + 0, &( pucEntryBuffer[ FF_FAT_LFN_NAME_1 ] ), 10 ); - memcpy( pxDirEntry->pcFileName + ( ( xNumLFNs - 1 ) * 13 ) + 5, &( pucEntryBuffer[ FF_FAT_LFN_NAME_2 ] ), 12 ); - memcpy( pxDirEntry->pcFileName + ( ( xNumLFNs - 1 ) * 13 ) + 11, &( pucEntryBuffer[ FF_FAT_LFN_NAME_3 ] ), 4 ); - uiLfnLength += 13; + /* Avoid stack intensive use of a UTF-16 buffer. Stream direct to FileName dirent field in correct format. */ + /* memcpy direct! -UTF-16 support. */ + memcpy( pxDirEntry->pcFileName + ( ( xNumLFNs - 1 ) * 13 ) + 0, &( pucEntryBuffer[ FF_FAT_LFN_NAME_1 ] ), 10 ); + memcpy( pxDirEntry->pcFileName + ( ( xNumLFNs - 1 ) * 13 ) + 5, &( pucEntryBuffer[ FF_FAT_LFN_NAME_2 ] ), 12 ); + memcpy( pxDirEntry->pcFileName + ( ( xNumLFNs - 1 ) * 13 ) + 11, &( pucEntryBuffer[ FF_FAT_LFN_NAME_3 ] ), 4 ); + uiLfnLength += 13; - xError = FF_FetchEntryWithContext( pxIOManager, usEntry++, pxFetchContext, pucEntryBuffer ); - - if( FF_isERR( xError ) ) - { - break; - } - - xNumLFNs--; - } + xError = FF_FetchEntryWithContext( pxIOManager, usEntry++, pxFetchContext, pucEntryBuffer ); if( FF_isERR( xError ) ) { break; } - pxDirEntry->pcFileName[ uiLfnLength ] = '\0'; + xNumLFNs--; + } + + if( FF_isERR( xError ) ) + { + break; } + + pxDirEntry->pcFileName[ uiLfnLength ] = '\0'; + } #endif /* ffconfigUNICODE_UTF16_SUPPORT */ #if ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) + { + /* UTF-8 Sequence, we can only convert this from the beginning, must receive entries in reverse. */ + nLfnBegin = usEntry - 1; + + for( xIndex = 0; xIndex < xNumLFNs; xIndex++ ) { - /* UTF-8 Sequence, we can only convert this from the beginning, must receive entries in reverse. */ - nLfnBegin = usEntry - 1; + xError = FF_FetchEntryWithContext( pxIOManager, ( nLfnBegin + ( xNumLFNs - 1 ) - xIndex ), pxFetchContext, pucEntryBuffer ); - for( xIndex = 0; xIndex < xNumLFNs; xIndex++ ) + if( FF_isERR( xError ) ) { - xError = FF_FetchEntryWithContext( pxIOManager, ( nLfnBegin + ( xNumLFNs - 1 ) - xIndex ), pxFetchContext, pucEntryBuffer ); + break; + } - if( FF_isERR( xError ) ) - { - break; - } + /* Now have the first part of the UTF-16 sequence. Stream into a UTF-8 sequence. */ + for( y = 0; y < 5; y++ ) + { + xError = FF_Utf16ctoUtf8c( ( uint8_t * ) &pxDirEntry->pcFileName[ usUtf8Len ], + ( uint16_t * ) &pucEntryBuffer[ FF_FAT_LFN_NAME_1 + ( y * 2 ) ], sizeof( pxDirEntry->pcFileName ) - usUtf8Len ); - /* Now have the first part of the UTF-16 sequence. Stream into a UTF-8 sequence. */ - for( y = 0; y < 5; y++ ) + if( xError > 0 ) { - xError = FF_Utf16ctoUtf8c( ( uint8_t * ) &pxDirEntry->pcFileName[ usUtf8Len ], - ( uint16_t * ) &pucEntryBuffer[ FF_FAT_LFN_NAME_1 + ( y * 2 ) ], sizeof( pxDirEntry->pcFileName ) - usUtf8Len ); - - if( xError > 0 ) - { - usUtf8Len += ( uint16_t ) xError; - } + usUtf8Len += ( uint16_t ) xError; } + } - for( y = 0; y < 6; y++ ) - { - xError = FF_Utf16ctoUtf8c( ( uint8_t * ) &pxDirEntry->pcFileName[ usUtf8Len ], - ( uint16_t * ) &pucEntryBuffer[ FF_FAT_LFN_NAME_2 + ( y * 2 ) ], sizeof( pxDirEntry->pcFileName ) - usUtf8Len ); - - if( xError > 0 ) - { - usUtf8Len += ( uint16_t ) xError; - } - } + for( y = 0; y < 6; y++ ) + { + xError = FF_Utf16ctoUtf8c( ( uint8_t * ) &pxDirEntry->pcFileName[ usUtf8Len ], + ( uint16_t * ) &pucEntryBuffer[ FF_FAT_LFN_NAME_2 + ( y * 2 ) ], sizeof( pxDirEntry->pcFileName ) - usUtf8Len ); - for( y = 0; y < 2; y++ ) + if( xError > 0 ) { - xError = FF_Utf16ctoUtf8c( ( uint8_t * ) &pxDirEntry->pcFileName[ usUtf8Len ], - ( uint16_t * ) &pucEntryBuffer[ FF_FAT_LFN_NAME_3 + ( y * 2 ) ], sizeof( pxDirEntry->pcFileName ) - usUtf8Len ); - - if( xError > 0 ) - { - usUtf8Len += ( uint16_t ) xError; - } + usUtf8Len += ( uint16_t ) xError; } - - usEntry++; } - if( FF_isERR( xError ) ) + for( y = 0; y < 2; y++ ) { - break; + xError = FF_Utf16ctoUtf8c( ( uint8_t * ) &pxDirEntry->pcFileName[ usUtf8Len ], + ( uint16_t * ) &pucEntryBuffer[ FF_FAT_LFN_NAME_3 + ( y * 2 ) ], sizeof( pxDirEntry->pcFileName ) - usUtf8Len ); + + if( xError > 0 ) + { + usUtf8Len += ( uint16_t ) xError; + } } - pxDirEntry->pcFileName[ usUtf8Len ] = '\0'; + usEntry++; + } - /* Put Entry context to correct position. */ - xError = FF_FetchEntryWithContext( pxIOManager, usEntry - 1, pxFetchContext, pucEntryBuffer ); + if( FF_isERR( xError ) ) + { + break; + } - if( FF_isERR( xError ) ) - { - break; - } + pxDirEntry->pcFileName[ usUtf8Len ] = '\0'; + + /* Put Entry context to correct position. */ + xError = FF_FetchEntryWithContext( pxIOManager, usEntry - 1, pxFetchContext, pucEntryBuffer ); + + if( FF_isERR( xError ) ) + { + break; } + } #endif /* ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) */ #if ( ffconfigUNICODE_UTF16_SUPPORT == 0 ) && ( ffconfigUNICODE_UTF8_SUPPORT == 0 ) /* No Unicode, simple ASCII. */ + { + pcLastPtr[ -1 ] = '\0'; + y = xNumLFNs; + + while( xNumLFNs-- ) { - pcLastPtr[ -1 ] = '\0'; - y = xNumLFNs; + pcCurPtr = pxDirEntry->pcFileName + ( xNumLFNs * 13 ); - while( xNumLFNs-- ) + for( xIndex = 0; ( xIndex < 10 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) { - pcCurPtr = pxDirEntry->pcFileName + ( xNumLFNs * 13 ); - - for( xIndex = 0; ( xIndex < 10 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) - { - *( pcCurPtr++ ) = ( char ) pucEntryBuffer[ FF_FAT_LFN_NAME_1 + xIndex ]; - } - - for( xIndex = 0; ( xIndex < 12 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) - { - *( pcCurPtr++ ) = ( char ) pucEntryBuffer[ FF_FAT_LFN_NAME_2 + xIndex ]; - } - - for( xIndex = 0; ( xIndex < 4 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) - { - *( pcCurPtr++ ) = ( char ) pucEntryBuffer[ FF_FAT_LFN_NAME_3 + xIndex ]; - } + *( pcCurPtr++ ) = ( char ) pucEntryBuffer[ FF_FAT_LFN_NAME_1 + xIndex ]; + } - if( ( xNumLFNs == ( y - 1 ) ) && ( pcCurPtr < pcLastPtr ) ) - { - *pcCurPtr = '\0'; - } + for( xIndex = 0; ( xIndex < 12 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) + { + *( pcCurPtr++ ) = ( char ) pucEntryBuffer[ FF_FAT_LFN_NAME_2 + xIndex ]; + } - xError = FF_FetchEntryWithContext( pxIOManager, usEntry++, pxFetchContext, pucEntryBuffer ); + for( xIndex = 0; ( xIndex < 4 ) && ( pcCurPtr < pcLastPtr ); xIndex += 2 ) + { + *( pcCurPtr++ ) = ( char ) pucEntryBuffer[ FF_FAT_LFN_NAME_3 + xIndex ]; + } - if( FF_isERR( xError ) ) - { - break; - } + if( ( xNumLFNs == ( y - 1 ) ) && ( pcCurPtr < pcLastPtr ) ) + { + *pcCurPtr = '\0'; } + xError = FF_FetchEntryWithContext( pxIOManager, usEntry++, pxFetchContext, pucEntryBuffer ); + if( FF_isERR( xError ) ) { break; } } + + if( FF_isERR( xError ) ) + { + break; + } + } #endif /* ( ffconfigUNICODE_UTF16_SUPPORT == 0 ) && ( ffconfigUNICODE_UTF8_SUPPORT == 0 ) */ /* Process the Shortname. -- LFN Transformation is now complete. @@ -1561,11 +1561,11 @@ FF_Error_t FF_PopulateLongDirent( FF_IOManager_t * pxIOManager, /* if SHORTNAMES must be included, simple byte copy into shortname buffer. */ #if ( ffconfigLFN_SUPPORT != 0 ) && ( ffconfigINCLUDE_SHORT_NAME != 0 ) - { - memcpy( pxDirEntry->pcShortName, pucEntryBuffer, 11 ); - pxDirEntry->pcShortName[ 11 ] = '\0'; - FF_ProcessShortName( pxDirEntry->pcShortName ); - } + { + memcpy( pxDirEntry->pcShortName, pucEntryBuffer, 11 ); + pxDirEntry->pcShortName[ 11 ] = '\0'; + FF_ProcessShortName( pxDirEntry->pcShortName ); + } #endif /* ( != 0 ffconfigLFN_SUPPORT ) && ( ffconfigINCLUDE_SHORT_NAME != 0 ) */ memcpy( pcShortName, pucEntryBuffer, 11 ); @@ -1575,9 +1575,9 @@ FF_Error_t FF_PopulateLongDirent( FF_IOManager_t * pxIOManager, { strcpy( pxDirEntry->pcFileName, pcShortName ); #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - { - FF_ShortNameExpand( pxDirEntry->pcFileName ); - } + { + FF_ShortNameExpand( pxDirEntry->pcFileName ); + } #endif /* ffconfigUNICODE_UTF16_SUPPORT */ } @@ -1587,21 +1587,21 @@ FF_Error_t FF_PopulateLongDirent( FF_IOManager_t * pxIOManager, ( uint32_t ) FF_getShort( pucEntryBuffer, FF_FAT_DIRENT_CLUS_LOW ); #if ( ffconfigTIME_SUPPORT != 0 ) - { - /* Get the creation Time & Date. */ - FF_GetTime( &pxDirEntry->xCreateTime, pucEntryBuffer, FF_FAT_DIRENT_CREATE_TIME ); - FF_GetDate( &pxDirEntry->xCreateTime, pucEntryBuffer, FF_FAT_DIRENT_CREATE_DATE ); - /* Get the modified Time & Date. */ - /* HT Here xCreateTime has become xModifiedTime, as it should: */ - FF_GetTime( &pxDirEntry->xModifiedTime, pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_TIME ); - FF_GetDate( &pxDirEntry->xModifiedTime, pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_DATE ); - /* Get the last accessed Date. */ - FF_GetDate( &pxDirEntry->xAccessedTime, pucEntryBuffer, FF_FAT_DIRENT_LASTACC_DATE ); - /* HT Why should these times be zero'd ? */ - pxDirEntry->xAccessedTime.Hour = 0; - pxDirEntry->xAccessedTime.Minute = 0; - pxDirEntry->xAccessedTime.Second = 0; - } + { + /* Get the creation Time & Date. */ + FF_GetTime( &pxDirEntry->xCreateTime, pucEntryBuffer, FF_FAT_DIRENT_CREATE_TIME ); + FF_GetDate( &pxDirEntry->xCreateTime, pucEntryBuffer, FF_FAT_DIRENT_CREATE_DATE ); + /* Get the modified Time & Date. */ + /* HT Here xCreateTime has become xModifiedTime, as it should: */ + FF_GetTime( &pxDirEntry->xModifiedTime, pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_TIME ); + FF_GetDate( &pxDirEntry->xModifiedTime, pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_DATE ); + /* Get the last accessed Date. */ + FF_GetDate( &pxDirEntry->xAccessedTime, pucEntryBuffer, FF_FAT_DIRENT_LASTACC_DATE ); + /* HT Why should these times be zero'd ? */ + pxDirEntry->xAccessedTime.Hour = 0; + pxDirEntry->xAccessedTime.Minute = 0; + pxDirEntry->xAccessedTime.Second = 0; + } #endif /* ffconfigTIME_SUPPORT */ /* Get the filesize. */ @@ -1691,49 +1691,49 @@ FF_Error_t FF_PopulateLongDirent( FF_IOManager_t * pxIOManager, else { #if ( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 ) - { - pxDirEntry->pcWildCard[ 0 ] = '\0'; /* WildCard blank if its not a wildCard. */ + { + pxDirEntry->pcWildCard[ 0 ] = '\0'; /* WildCard blank if its not a wildCard. */ - pcWildCard = &pcPath[ PathLen - 1 ]; + pcWildCard = &pcPath[ PathLen - 1 ]; - if( PathLen != 0 ) + if( PathLen != 0 ) + { + /* Open the dir of the last token. */ + while( ( *pcWildCard != '\\' ) && ( *pcWildCard != '/' ) ) { - /* Open the dir of the last token. */ - while( ( *pcWildCard != '\\' ) && ( *pcWildCard != '/' ) ) - { - xIndex++; - pcWildCard--; + xIndex++; + pcWildCard--; - if( PathLen == xIndex ) - { - break; - } + if( PathLen == xIndex ) + { + break; } } + } - pxDirEntry->ulDirCluster = FF_FindDir( pxIOManager, pcPath, PathLen - xIndex, &xError ); + pxDirEntry->ulDirCluster = FF_FindDir( pxIOManager, pcPath, PathLen - xIndex, &xError ); - if( FF_isERR( xError ) == pdFALSE ) + if( FF_isERR( xError ) == pdFALSE ) + { + if( pxDirEntry->ulDirCluster != 0 ) { - if( pxDirEntry->ulDirCluster != 0 ) - { - /* Valid Dir found, copy the wildCard to filename! */ - STRNCPY( pxDirEntry->pcWildCard, ++pcWildCard, ffconfigMAX_FILENAME - 1 ); - pxDirEntry->pcWildCard[ ffconfigMAX_FILENAME - 1 ] = 0; + /* Valid Dir found, copy the wildCard to filename! */ + STRNCPY( pxDirEntry->pcWildCard, ++pcWildCard, ffconfigMAX_FILENAME - 1 ); + pxDirEntry->pcWildCard[ ffconfigMAX_FILENAME - 1 ] = 0; - if( pxDirEntry->pcWildCard[ xIndex - 1 ] == ':' ) - { - pxDirEntry->xInvertWildCard = pdTRUE; - pxDirEntry->pcWildCard[ xIndex - 1 ] = '\0'; - } + if( pxDirEntry->pcWildCard[ xIndex - 1 ] == ':' ) + { + pxDirEntry->xInvertWildCard = pdTRUE; + pxDirEntry->pcWildCard[ xIndex - 1 ] = '\0'; } } } + } #else /* ffconfigFINDAPI_ALLOW_WILDCARDS */ - { - /* Get the directory cluster, if it exists. */ - pxDirEntry->ulDirCluster = FF_FindDir( pxIOManager, pcPath, PathLen, &xError ); - } + { + /* Get the directory cluster, if it exists. */ + pxDirEntry->ulDirCluster = FF_FindDir( pxIOManager, pcPath, PathLen, &xError ); + } #endif /* ffconfigFINDAPI_ALLOW_WILDCARDS */ if( FF_isERR( xError ) == pdFALSE ) @@ -1846,83 +1846,83 @@ FF_Error_t FF_FindNext( FF_IOManager_t * pxIOManager, xLFNCount = ( BaseType_t ) ( pucEntryBuffer[ 0 ] & ~0x40 ); /* Get the shortname and check if it is marked deleted. */ #if ( ffconfigLFN_SUPPORT != 0 ) + { + /* Reserve 32 bytes to hold one directory entry. */ + uint8_t Buffer[ FF_SIZEOF_DIRECTORY_ENTRY ]; + + /* Fetch the shortname, and get it's checksum, or for a deleted item with + * orphaned LFN entries. */ + xError = FF_FetchEntryWithContext( pxIOManager, ( uint32_t ) ( pxDirEntry->usCurrentItem + xLFNCount ), &pxDirEntry->xFetchContext, Buffer ); + + if( FF_isERR( xError ) ) { - /* Reserve 32 bytes to hold one directory entry. */ - uint8_t Buffer[ FF_SIZEOF_DIRECTORY_ENTRY ]; + break; + } - /* Fetch the shortname, and get it's checksum, or for a deleted item with - * orphaned LFN entries. */ - xError = FF_FetchEntryWithContext( pxIOManager, ( uint32_t ) ( pxDirEntry->usCurrentItem + xLFNCount ), &pxDirEntry->xFetchContext, Buffer ); + if( FF_isDeleted( Buffer ) == pdFALSE ) + { + xError = FF_PopulateLongDirent( pxIOManager, pxDirEntry, pxDirEntry->usCurrentItem, &pxDirEntry->xFetchContext ); if( FF_isERR( xError ) ) { break; } - if( FF_isDeleted( Buffer ) == pdFALSE ) + #if ( ffconfigINCLUDE_SHORT_NAME != 0 ) { - xError = FF_PopulateLongDirent( pxIOManager, pxDirEntry, pxDirEntry->usCurrentItem, &pxDirEntry->xFetchContext ); - - if( FF_isERR( xError ) ) - { - break; - } + pxDirEntry->ucAttrib |= FF_FAT_ATTR_IS_LFN; + } + #endif - #if ( ffconfigINCLUDE_SHORT_NAME != 0 ) - { - pxDirEntry->ucAttrib |= FF_FAT_ATTR_IS_LFN; - } + #if ( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 ) + { + #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) + if( wcscmp( pxDirEntry->pcWildCard, L"" ) ) + #else + if( pxDirEntry->pcWildCard[ 0 ] ) #endif + { + b = FF_wildcompare( pxDirEntry->pcWildCard, pxDirEntry->pcFileName ); - #if ( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 ) + if( pxDirEntry->xInvertWildCard != pdFALSE ) { - #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - if( wcscmp( pxDirEntry->pcWildCard, L"" ) ) - #else - if( pxDirEntry->pcWildCard[ 0 ] ) - #endif - { - b = FF_wildcompare( pxDirEntry->pcWildCard, pxDirEntry->pcFileName ); - - if( pxDirEntry->xInvertWildCard != pdFALSE ) - { - b = !b; - } - - if( b != 0 ) - { - break; - } - - /* 'usCurrentItem' has already incremented by FF_PopulateLongDirent(), - * this loop will incremente it again. */ - pxDirEntry->usCurrentItem -= 1; - - /* xFetchContext/usCurrentItem have changed. Update - * 'pucEntryBuffer' to point to the current buffer position. */ - pucEntryBuffer = pxDirEntry->xFetchContext.pxBuffer->pucBuffer + - ( FF_SIZEOF_DIRECTORY_ENTRY * ( pxDirEntry->usCurrentItem % ( pxIOManager->usSectorSize / FF_SIZEOF_DIRECTORY_ENTRY ) ) ); - } - else - { - break; - } + b = !b; } - #else /* ffconfigFINDAPI_ALLOW_WILDCARDS == 0 */ + + if( b != 0 ) { - /* usCurrentItem has been incremented by FF_PopulateLongDirent(). - * Entry will be returned. */ break; } - #endif /* if ( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 ) */ + + /* 'usCurrentItem' has already incremented by FF_PopulateLongDirent(), + * this loop will increment it again. */ + pxDirEntry->usCurrentItem -= 1; + + /* xFetchContext/usCurrentItem have changed. Update + * 'pucEntryBuffer' to point to the current buffer position. */ + pucEntryBuffer = pxDirEntry->xFetchContext.pxBuffer->pucBuffer + + ( FF_SIZEOF_DIRECTORY_ENTRY * ( pxDirEntry->usCurrentItem % ( pxIOManager->usSectorSize / FF_SIZEOF_DIRECTORY_ENTRY ) ) ); + } + else + { + break; + } } + #else /* ffconfigFINDAPI_ALLOW_WILDCARDS == 0 */ + { + /* usCurrentItem has been incremented by FF_PopulateLongDirent(). + * Entry will be returned. */ + break; + } + #endif /* if ( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 ) */ } + } #else /* ffconfigLFN_SUPPORT */ - { - /* Increment 'usCurrentItem' with (xLFNCount-1), - * the loop will do an extra increment. */ - pxDirEntry->usCurrentItem += ( xLFNCount - 1 ); - } + { + /* Increment 'usCurrentItem' with (xLFNCount-1), + * the loop will do an extra increment. */ + pxDirEntry->usCurrentItem += ( xLFNCount - 1 ); + } #endif /* ffconfigLFN_SUPPORT */ } /* ( ( pxDirEntry->ucAttrib & FF_FAT_ATTR_LFN ) == FF_FAT_ATTR_LFN ) */ else if( ( pxDirEntry->ucAttrib & FF_FAT_ATTR_VOLID ) != FF_FAT_ATTR_VOLID ) @@ -1930,40 +1930,40 @@ FF_Error_t FF_FindNext( FF_IOManager_t * pxIOManager, /* If it's not a LFN entry, neither a Volume ID, it is a normal short name entry. */ FF_PopulateShortDirent( pxIOManager, pxDirEntry, pucEntryBuffer ); #if ( ffconfigSHORTNAME_CASE != 0 ) - { - /* Apply NT/XP+ bits to get correct case. */ - FF_CaseShortName( pxDirEntry->pcFileName, FF_getChar( pucEntryBuffer, FF_FAT_CASE_OFFS ) ); - } + { + /* Apply NT/XP+ bits to get correct case. */ + FF_CaseShortName( pxDirEntry->pcFileName, FF_getChar( pucEntryBuffer, FF_FAT_CASE_OFFS ) ); + } #endif #if ( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 ) + { + if( pxDirEntry->pcWildCard[ 0 ] ) { - if( pxDirEntry->pcWildCard[ 0 ] ) - { - b = FF_wildcompare( pxDirEntry->pcWildCard, pxDirEntry->pcFileName ); - - if( pxDirEntry->xInvertWildCard != pdFALSE ) - { - b = !b; - } + b = FF_wildcompare( pxDirEntry->pcWildCard, pxDirEntry->pcFileName ); - if( b != 0 ) - { - pxDirEntry->usCurrentItem += 1; - break; - } + if( pxDirEntry->xInvertWildCard != pdFALSE ) + { + b = !b; } - else + + if( b != 0 ) { pxDirEntry->usCurrentItem += 1; break; } } - #else /* ffconfigFINDAPI_ALLOW_WILDCARDS */ + else { pxDirEntry->usCurrentItem += 1; break; } + } + #else /* ffconfigFINDAPI_ALLOW_WILDCARDS */ + { + pxDirEntry->usCurrentItem += 1; + break; + } #endif /* if ( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 ) */ } } /* for ( ; pxDirEntry->usCurrentItem < FF_MAX_ENTRIES_PER_DIRECTORY; pxDirEntry->usCurrentItem++ ) */ @@ -2145,15 +2145,15 @@ FF_Error_t FF_PutEntry( FF_IOManager_t * pxIOManager, FF_putShort( pucEntryBuffer, FF_FAT_DIRENT_CLUS_LOW, ( uint32_t ) ( pxDirEntry->ulObjectCluster ) ); FF_putLong( pucEntryBuffer, FF_FAT_DIRENT_FILESIZE, pxDirEntry->ulFileSize ); #if ( ffconfigTIME_SUPPORT != 0 ) - { - FF_GetSystemTime( &pxDirEntry->xAccessedTime ); /*/< Date of Last Access. */ - FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_LASTACC_DATE, &pxDirEntry->xAccessedTime ); - FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_LASTACC_DATE, &pxDirEntry->xAccessedTime ); /* Last accessed date. */ - FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_CREATE_TIME, &pxDirEntry->xCreateTime ); - FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_CREATE_DATE, &pxDirEntry->xCreateTime ); - FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_TIME, &pxDirEntry->xModifiedTime ); - FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_DATE, &pxDirEntry->xModifiedTime ); - } + { + FF_GetSystemTime( &pxDirEntry->xAccessedTime ); /*/< Date of Last Access. */ + FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_LASTACC_DATE, &pxDirEntry->xAccessedTime ); + FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_LASTACC_DATE, &pxDirEntry->xAccessedTime ); /* Last accessed date. */ + FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_CREATE_TIME, &pxDirEntry->xCreateTime ); + FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_CREATE_DATE, &pxDirEntry->xCreateTime ); + FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_TIME, &pxDirEntry->xModifiedTime ); + FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_DATE, &pxDirEntry->xModifiedTime ); + } #endif /* ffconfigTIME_SUPPORT */ xError = FF_PushEntryWithContext( pxIOManager, usEntry, &xFetchContext, pucEntryBuffer ); } @@ -2202,13 +2202,13 @@ static BaseType_t FF_ValidShortChar( char cChar ) pxFindParams->ulFlags |= FIND_FLAG_SHORTNAME_SET | FIND_FLAG_FITS_SHORT | FIND_FLAG_SIZE_OK; #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - { - NameLen = ( uint16_t ) wcslen( pcLongName ); - } + { + NameLen = ( uint16_t ) wcslen( pcLongName ); + } #else - { - NameLen = ( uint16_t ) strlen( pcLongName ); - } + { + NameLen = ( uint16_t ) strlen( pcLongName ); + } #endif /* Does pcLongName fit a shortname? */ @@ -2267,9 +2267,9 @@ static BaseType_t FF_ValidShortChar( char cChar ) } #if ( ffconfigSHORTNAME_CASE != 0 ) - { - testAttrib = FF_FAT_CASE_ATTR_EXT; - } + { + testAttrib = FF_FAT_CASE_ATTR_EXT; + } #endif } else @@ -2288,9 +2288,9 @@ static BaseType_t FF_ValidShortChar( char cChar ) ch = ( int8_t ) pcLongName[ ++xPosition ]; #if ( ffconfigSHORTNAME_CASE != 0 ) - { - testAttrib = FF_FAT_CASE_ATTR_EXT; - } + { + testAttrib = FF_FAT_CASE_ATTR_EXT; + } #endif } } @@ -2302,37 +2302,37 @@ static BaseType_t FF_ValidShortChar( char cChar ) } #if ( ffconfigSHORTNAME_CASE != 0 ) + { + if( ( ch >= 'a' ) && ( ch <= 'z' ) ) { - if( ( ch >= 'a' ) && ( ch <= 'z' ) ) - { - ch -= 0x20; + ch -= 0x20; - if( testAttrib ) - { - pxFindParams->ucCaseAttrib |= testAttrib; - } - else - { - pxFindParams->ulFlags &= ~FIND_FLAG_FITS_SHORT; /* We had capital: does not fit. */ - } + if( testAttrib ) + { + pxFindParams->ucCaseAttrib |= testAttrib; } - else if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) + else { - if( ( pxFindParams->ucCaseAttrib & testAttrib ) != 0 ) - { - pxFindParams->ulFlags &= ~FIND_FLAG_FITS_SHORT; /* We had lower-case: does not fit. */ - } - - testAttrib = 0; + pxFindParams->ulFlags &= ~FIND_FLAG_FITS_SHORT; /* We had capital: does not fit. */ } } - #else /* if ( ffconfigSHORTNAME_CASE != 0 ) */ + else if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) { - if( ( ch >= 'a' ) && ( ch <= 'z' ) ) + if( ( pxFindParams->ucCaseAttrib & testAttrib ) != 0 ) { - ch -= 0x20; + pxFindParams->ulFlags &= ~FIND_FLAG_FITS_SHORT; /* We had lower-case: does not fit. */ } + + testAttrib = 0; + } + } + #else /* if ( ffconfigSHORTNAME_CASE != 0 ) */ + { + if( ( ch >= 'a' ) && ( ch <= 'z' ) ) + { + ch -= 0x20; } + } #endif /* ffconfigSHORTNAME_CASE */ pxFindParams->pcEntryBuffer[ xIndex++ ] = ch; } @@ -2404,10 +2404,10 @@ int32_t FF_FindShortName( FF_IOManager_t * pxIOManager, else { #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - { - memcpy( pcFileName, pcMyShortName, sizeof( pcMyShortName ) ); - FF_ShortNameExpand( pcFileName ); - } + { + memcpy( pcFileName, pcMyShortName, sizeof( pcMyShortName ) ); + FF_ShortNameExpand( pcFileName ); + } #endif ulCluster = FF_FindEntryInDir( pxIOManager, pxFindParams, pcFileName, 0x00, &xMyDirectory, &xResult ); @@ -2436,44 +2436,44 @@ int32_t FF_FindShortName( FF_IOManager_t * pxIOManager, if( xIndex != 0 ) { #if ( ipconfigQUICK_SHORT_FILENAME_CREATION != 0 ) + { + /* In the first round, check if the original name can be used + * Makefile will be stored as "makefile" and not as "makefi~1". */ + + /* This method saves a lot of time when creating directories with + * many similar file names: when the short name version of a LFN already + * exists, try at most 3 entries with a tilde: + * README~1.TXT + * README~2.TXT + * README~3.TXT + * After that create entries with pseudo-random 4-digit hex digits: + * REA~E7BB.TXT + * REA~BA32.TXT + * REA~D394.TXT + */ + if( xIndex <= 4 ) { - /* In the first round, check if the original name can be used - * Makefile will be stored as "makefile" and not as "makefi~1". */ - - /* This method saves a lot of time when creating directories with - * many similar file names: when the short name version of a LFN already - * exists, try at most 3 entries with a tilde: - * README~1.TXT - * README~2.TXT - * README~3.TXT - * After that create entries with pseudo-random 4-digit hex digits: - * REA~E7BB.TXT - * REA~BA32.TXT - * REA~D394.TXT - */ - if( xIndex <= 4 ) + snprintf( pcNumberBuf, sizeof( pcNumberBuf ), "%d", ( int ) xIndex ); + } + else + { + if( ulRand == 0ul ) { - snprintf( pcNumberBuf, sizeof( pcNumberBuf ), "%d", ( int ) xIndex ); + ulRand = pxIOManager->xPartition.ulLastFreeCluster; + usShortHash = FF_GetCRC16( ( uint8_t * ) &ulRand, sizeof( ulRand ) ); } else { - if( ulRand == 0ul ) - { - ulRand = pxIOManager->xPartition.ulLastFreeCluster; - usShortHash = FF_GetCRC16( ( uint8_t * ) &ulRand, sizeof( ulRand ) ); - } - else - { - usShortHash = FF_GetCRC16( ( uint8_t * ) &usShortHash, sizeof( usShortHash ) ); - } - - snprintf( pcNumberBuf, sizeof( pcNumberBuf ), "%04X", ( int ) usShortHash ); + usShortHash = FF_GetCRC16( ( uint8_t * ) &usShortHash, sizeof( usShortHash ) ); } + + snprintf( pcNumberBuf, sizeof( pcNumberBuf ), "%04X", ( int ) usShortHash ); } + } #else /* if ( ipconfigQUICK_SHORT_FILENAME_CREATION != 0 ) */ - { - snprintf( pcNumberBuf, sizeof( pcNumberBuf ), "%d", ( int ) xIndex ); - } + { + snprintf( pcNumberBuf, sizeof( pcNumberBuf ), "%d", ( int ) xIndex ); + } #endif /* if ( ipconfigQUICK_SHORT_FILENAME_CREATION != 0 ) */ NameLen = ( uint16_t ) strlen( pcNumberBuf ); @@ -2548,9 +2548,9 @@ int32_t FF_FindShortName( FF_IOManager_t * pxIOManager, { pucEntryBuffer[ x ] = *( pcName++ ); #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) || ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) - { - pucEntryBuffer[ x + 1 ] = *( pcName++ ); - } + { + pucEntryBuffer[ x + 1 ] = *( pcName++ ); + } #endif } else if( uxIndex > uxNameLength ) @@ -2567,9 +2567,9 @@ int32_t FF_FindShortName( FF_IOManager_t * pxIOManager, { pucEntryBuffer[ x ] = *( pcName++ ); #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) || ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) - { - pucEntryBuffer[ x + 1 ] = *( pcName++ ); - } + { + pucEntryBuffer[ x + 1 ] = *( pcName++ ); + } #endif } else if( uxIndex > uxNameLength ) @@ -2586,9 +2586,9 @@ int32_t FF_FindShortName( FF_IOManager_t * pxIOManager, { pucEntryBuffer[ x ] = *( pcName++ ); #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) || ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) - { - pucEntryBuffer[ x + 1 ] = *( pcName++ ); - } + { + pucEntryBuffer[ x + 1 ] = *( pcName++ ); + } #endif } else if( uxIndex > uxNameLength ) @@ -2642,64 +2642,31 @@ int32_t FF_FindShortName( FF_IOManager_t * pxIOManager, #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) + { + #if WCHAR_MAX <= 0xFFFF { - #if WCHAR_MAX <= 0xFFFF - { - y = wcslen( pcName ); - - if( y > ffconfigMAX_FILENAME ) - { - xError = FF_createERR( FF_ERR_DIR_NAME_TOO_LONG, FF_CREATELFNS ); - } - else - { - wcsncpy( usUtf16Name, pcName, ffconfigMAX_FILENAME - 1 ); - usUtf16Name[ ffconfigMAX_FILENAME - 1 ] = 0; - } - } - #else /* if WCHAR_MAX <= 0xFFFF */ - { - xIndex = 0; - y = 0; - - while( pcName[ xIndex ] ) - { - FF_Utf32ctoUtf16c( &usUtf16Name[ y ], ( uint32_t ) pcName[ xIndex ], ffconfigMAX_FILENAME - xIndex ); - y += FF_GetUtf16SequenceLen( usUtf16Name[ y ] ); - xIndex++; + y = wcslen( pcName ); - if( y > ffconfigMAX_FILENAME ) - { - xError = FF_createERR( FF_ERR_DIR_NAME_TOO_LONG, FF_CREATELFNS ); - break; - } - } - } - #endif /* if WCHAR_MAX <= 0xFFFF */ + if( y > ffconfigMAX_FILENAME ) + { + xError = FF_createERR( FF_ERR_DIR_NAME_TOO_LONG, FF_CREATELFNS ); + } + else + { + wcsncpy( usUtf16Name, pcName, ffconfigMAX_FILENAME - 1 ); + usUtf16Name[ ffconfigMAX_FILENAME - 1 ] = 0; + } } - #endif /* ffconfigUNICODE_UTF16_SUPPORT */ - - /* Convert the name into UTF-16 format. */ - #if ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) + #else /* if WCHAR_MAX <= 0xFFFF */ { - /* Simply convert the UTF8 to UTF16 and be done with it. */ xIndex = 0; y = 0; - while( pcName[ xIndex ] != 0 ) + while( pcName[ xIndex ] ) { - slRetVal = FF_Utf8ctoUtf16c( &( usUtf16Name[ y ] ), ( uint8_t * ) &( pcName[ xIndex ] ), ffconfigMAX_FILENAME - xIndex ); - - if( slRetVal > 0 ) - { - xIndex += slRetVal; - } - else - { - break; /* No more space in the UTF-16 buffer, simply truncate for safety. */ - } - + FF_Utf32ctoUtf16c( &usUtf16Name[ y ], ( uint32_t ) pcName[ xIndex ], ffconfigMAX_FILENAME - xIndex ); y += FF_GetUtf16SequenceLen( usUtf16Name[ y ] ); + xIndex++; if( y > ffconfigMAX_FILENAME ) { @@ -2708,19 +2675,52 @@ int32_t FF_FindShortName( FF_IOManager_t * pxIOManager, } } } - #elif ( ffconfigUNICODE_UTF16_SUPPORT == 0 ) + #endif /* if WCHAR_MAX <= 0xFFFF */ + } + #endif /* ffconfigUNICODE_UTF16_SUPPORT */ + + /* Convert the name into UTF-16 format. */ + #if ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) + { + /* Simply convert the UTF8 to UTF16 and be done with it. */ + xIndex = 0; + y = 0; + + while( pcName[ xIndex ] != 0 ) { - /* Just check the length. */ - y = strlen( pcName ); + slRetVal = FF_Utf8ctoUtf16c( &( usUtf16Name[ y ] ), ( uint8_t * ) &( pcName[ xIndex ] ), ffconfigMAX_FILENAME - xIndex ); + + if( slRetVal > 0 ) + { + xIndex += slRetVal; + } + else + { + break; /* No more space in the UTF-16 buffer, simply truncate for safety. */ + } + + y += FF_GetUtf16SequenceLen( usUtf16Name[ y ] ); if( y > ffconfigMAX_FILENAME ) { xError = FF_createERR( FF_ERR_DIR_NAME_TOO_LONG, FF_CREATELFNS ); + break; } } + } + #elif ( ffconfigUNICODE_UTF16_SUPPORT == 0 ) + { + /* Just check the length. */ + y = strlen( pcName ); + + if( y > ffconfigMAX_FILENAME ) + { + xError = FF_createERR( FF_ERR_DIR_NAME_TOO_LONG, FF_CREATELFNS ); + } + } #endif /* if ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) */ - /* Whole name is now in a valid UTF-16 format. Lets go make thos LFN's. + /* Whole name is now in a valid UTF-16 format. Lets go make those LFN's. * At this point, it should a be the length of the name. */ if( FF_isERR( xError ) == pdFALSE ) { @@ -2741,17 +2741,17 @@ int32_t FF_FindShortName( FF_IOManager_t * pxIOManager, if( FF_isERR( xError ) == pdFALSE ) { #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - { - NamePtr = ( int16_t * ) ( usUtf16Name + 13 * ( xNumLFNs - 1 ) ); - } + { + NamePtr = ( int16_t * ) ( usUtf16Name + 13 * ( xNumLFNs - 1 ) ); + } #elif ( ffconfigUNICODE_UTF8_SUPPORT != 0 ) - { - NamePtr = ( char * ) ( usUtf16Name + 13 * ( xNumLFNs - 1 ) ); - } + { + NamePtr = ( char * ) ( usUtf16Name + 13 * ( xNumLFNs - 1 ) ); + } #else - { - NamePtr = pcName + 13 * ( xNumLFNs - 1 ); - } + { + NamePtr = pcName + 13 * ( xNumLFNs - 1 ); + } #endif /* if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) */ /* After this point, xIndex is no longer the length of the Filename in UTF-16 units. */ @@ -2942,26 +2942,26 @@ FF_Error_t FF_CreateDirent( FF_IOManager_t * pxIOManager, xLFNCount = ( BaseType_t ) ( ( NameLen + 12 ) / 13 ); #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - { - FF_MakeNameCompliant( pxDirEntry->pcFileName ); /* Ensure we don't break the Dir tables. */ - } + { + FF_MakeNameCompliant( pxDirEntry->pcFileName ); /* Ensure we don't break the Dir tables. */ + } #else - { - FF_MakeNameCompliant( pxDirEntry->pcFileName ); /* Ensure we don't break the Dir tables. */ - } + { + FF_MakeNameCompliant( pxDirEntry->pcFileName ); /* Ensure we don't break the Dir tables. */ + } #endif memset( pucEntryBuffer, 0, sizeof( pucEntryBuffer ) ); #if ( ffconfigLFN_SUPPORT != 0 ) - { - /* Create and push the LFN's. */ - /* Find enough places for the LFNs and the ShortName. */ - xEntryCount = xLFNCount + 1; - } + { + /* Create and push the LFN's. */ + /* Find enough places for the LFNs and the ShortName. */ + xEntryCount = xLFNCount + 1; + } #else - { - xEntryCount = 1; - } + { + xEntryCount = 1; + } #endif /* Create the ShortName. */ @@ -3003,31 +3003,31 @@ FF_Error_t FF_CreateDirent( FF_IOManager_t * pxIOManager, } #if ( ffconfigLFN_SUPPORT != 0 ) + { + if( xLFNCount > 0 ) { - if( xLFNCount > 0 ) - { - ucCheckSum = FF_CreateChkSum( pucEntryBuffer ); - xReturn = FF_CreateLFNs( pxIOManager, ulDirCluster, pxDirEntry->pcFileName, ucCheckSum, ( uint16_t ) lFreeEntry ); - } + ucCheckSum = FF_CreateChkSum( pucEntryBuffer ); + xReturn = FF_CreateLFNs( pxIOManager, ulDirCluster, pxDirEntry->pcFileName, ucCheckSum, ( uint16_t ) lFreeEntry ); } + } #else - { - xLFNCount = 0; - } + { + xLFNCount = 0; + } #endif /* ffconfigLFN_SUPPORT */ if( FF_isERR( xReturn ) == pdFALSE ) { #if ( ffconfigTIME_SUPPORT != 0 ) - { - FF_GetSystemTime( &pxDirEntry->xCreateTime ); /* Date and Time Created. */ - pxDirEntry->xModifiedTime = pxDirEntry->xCreateTime; /* Date and Time Modified. */ - pxDirEntry->xAccessedTime = pxDirEntry->xCreateTime; /* Date of Last Access. */ - FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_CREATE_TIME, &pxDirEntry->xCreateTime ); - FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_CREATE_DATE, &pxDirEntry->xCreateTime ); - FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_TIME, &pxDirEntry->xModifiedTime ); - FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_DATE, &pxDirEntry->xModifiedTime ); - } + { + FF_GetSystemTime( &pxDirEntry->xCreateTime ); /* Date and Time Created. */ + pxDirEntry->xModifiedTime = pxDirEntry->xCreateTime; /* Date and Time Modified. */ + pxDirEntry->xAccessedTime = pxDirEntry->xCreateTime; /* Date of Last Access. */ + FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_CREATE_TIME, &pxDirEntry->xCreateTime ); + FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_CREATE_DATE, &pxDirEntry->xCreateTime ); + FF_PlaceTime( pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_TIME, &pxDirEntry->xModifiedTime ); + FF_PlaceDate( pucEntryBuffer, FF_FAT_DIRENT_LASTMOD_DATE, &pxDirEntry->xModifiedTime ); + } #endif /* ffconfigTIME_SUPPORT */ FF_putChar( pucEntryBuffer, FF_FAT_DIRENT_ATTRIB, pxDirEntry->ucAttrib ); @@ -3064,25 +3064,25 @@ FF_Error_t FF_CreateDirent( FF_IOManager_t * pxIOManager, } #if ( ffconfigHASH_CACHE != 0 ) + { + if( FF_DirHashed( pxIOManager, ulDirCluster ) == pdFALSE ) { - if( FF_DirHashed( pxIOManager, ulDirCluster ) == pdFALSE ) - { - /* Hash the directory. */ - FF_HashDir( pxIOManager, ulDirCluster ); - } + /* Hash the directory. */ + FF_HashDir( pxIOManager, ulDirCluster ); + } - memcpy( pcShortName, pucEntryBuffer, 11 ); - FF_ProcessShortName( pcShortName ); /* Format the shortname to 8.3. */ - #if ( ffconfigHASH_FUNCTION == CRC16 ) - { - FF_AddDirentHash( pxIOManager, ulDirCluster, ( uint32_t ) FF_GetCRC16( ( uint8_t * ) pcShortName, ( uint32_t ) strlen( pcShortName ) ) ); - } - #elif ( ffconfigHASH_FUNCTION == CRC8 ) - { - FF_AddDirentHash( pxIOManager, ulDirCluster, ( uint32_t ) FF_GetCRC8( ( uint8_t * ) pcShortName, strlen( pcShortName ) ) ); - } - #endif /* ffconfigHASH_FUNCTION */ + memcpy( pcShortName, pucEntryBuffer, 11 ); + FF_ProcessShortName( pcShortName ); /* Format the shortname to 8.3. */ + #if ( ffconfigHASH_FUNCTION == CRC16 ) + { + FF_AddDirentHash( pxIOManager, ulDirCluster, ( uint32_t ) FF_GetCRC16( ( uint8_t * ) pcShortName, ( uint32_t ) strlen( pcShortName ) ) ); + } + #elif ( ffconfigHASH_FUNCTION == CRC8 ) + { + FF_AddDirentHash( pxIOManager, ulDirCluster, ( uint32_t ) FF_GetCRC8( ( uint8_t * ) pcShortName, strlen( pcShortName ) ) ); } + #endif /* ffconfigHASH_FUNCTION */ + } #endif /* ffconfigHASH_CACHE*/ } } @@ -3236,13 +3236,13 @@ FF_Error_t FF_CreateDirent( FF_IOManager_t * pxIOManager, #endif /* ffconfigREMOVABLE_MEDIA */ #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - { - xIndex = ( BaseType_t ) wcslen( pcPath ); - } + { + xIndex = ( BaseType_t ) wcslen( pcPath ); + } #else - { - xIndex = ( BaseType_t ) strlen( pcPath ); - } + { + xIndex = ( BaseType_t ) strlen( pcPath ); + } #endif /* Find the last slash in the path. */ @@ -3311,10 +3311,10 @@ FF_Error_t FF_CreateDirent( FF_IOManager_t * pxIOManager, /* Give all entries a proper time stamp, looks nicer than 1 Jan 1970 */ #if ( ffconfigTIME_SUPPORT != 0 ) - { - FF_GetSystemTime( &xMyDirectory.xCreateTime ); - FF_GetSystemTime( &xMyDirectory.xModifiedTime ); - } + { + FF_GetSystemTime( &xMyDirectory.xCreateTime ); + FF_GetSystemTime( &xMyDirectory.xModifiedTime ); + } #endif if( FF_isERR( xError ) ) @@ -3523,13 +3523,13 @@ FF_Error_t FF_RmLFNs( FF_IOManager_t * pxIOManager, /* Generate the Hash. */ #if ( ffconfigHASH_FUNCTION == CRC16 ) - { - ulHash = FF_GetCRC16( ( uint8_t * ) pcMyShortName, ( uint32_t ) strlen( pcMyShortName ) ); - } + { + ulHash = FF_GetCRC16( ( uint8_t * ) pcMyShortName, ( uint32_t ) strlen( pcMyShortName ) ); + } #else /* ffconfigHASH_FUNCTION == CRC8 */ - { - ulHash = FF_GetCRC8( pcMyShortName, strlen( pcMyShortName ) ); - } + { + ulHash = FF_GetCRC8( pcMyShortName, strlen( pcMyShortName ) ); + } #endif FF_SetHash( pxHashCache, ulHash ); } diff --git a/ff_error.c b/ff_error.c old mode 100755 new mode 100644 index 5217a77..b1fe809 --- a/ff_error.c +++ b/ff_error.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -160,76 +160,76 @@ #define TPASTE2( a, b ) a ## b #if ( ffconfigLONG_ERR_MSG != 0 ) - /* To get the full error msg: "Not enough memory (malloc( ) returned NULL )" */ + /* To get the full error msg: "Not enough memory (malloc( ) returned NULL )" */ #define ERR_ENTRY( M, E ) { M, TPASTE2( FF_ERR_, E ) } #else - /* To get a shorter msg: "NOT_ENOUGH_MEMORY" */ + /* To get a shorter msg: "NOT_ENOUGH_MEMORY" */ #define ERR_ENTRY( M, E ) { # E, TPASTE2( FF_ERR_, E ) } #endif /* ffconfigLONG_ERR_MSG */ - const struct _FFERRTAB - { - const char * const strErrorString; - const uint8_t ucErrorCode; /* Currently there are less then 256 errors, so lets keep this table small. */ - } - xFreeRTOSFATErrorTable[] = - { - { "Unknown or Generic Error!", 1 }, - ERR_ENTRY( "No Error", NONE ), - ERR_ENTRY( "Null Pointer provided, (probably for IOMAN)", NULL_POINTER ), - ERR_ENTRY( "Not enough memory (malloc() returned NULL)", NOT_ENOUGH_MEMORY ), - ERR_ENTRY( "Device Driver returned a FATAL error!", DEVICE_DRIVER_FAILED ), - ERR_ENTRY( "The blocksize is not 512 multiple", IOMAN_BAD_BLKSIZE ), - ERR_ENTRY( "The memory size, is not a multiple of the blocksize. (Atleast 2 Blocks)", IOMAN_BAD_MEMSIZE ), - ERR_ENTRY( "Device is already registered, use FF_UnregisterBlkDevice() first", IOMAN_DEV_ALREADY_REGD ), - ERR_ENTRY( "No mountable partition was found on the specified device", IOMAN_NO_MOUNTABLE_PARTITION ), - ERR_ENTRY( "The format of the MBR was unrecognised", IOMAN_INVALID_FORMAT ), - ERR_ENTRY( "The provided partition number is out-of-range (0 - 3)", IOMAN_INVALID_PARTITION_NUM ), - ERR_ENTRY( "The selected partition / volume doesn't appear to be FAT formatted", IOMAN_NOT_FAT_FORMATTED ), - ERR_ENTRY( "Cannot register device. (BlkSize not a multiple of 512)", IOMAN_DEV_INVALID_BLKSIZE ), - ERR_ENTRY( "Cannot unregister device, a partition is still mounted", IOMAN_PARTITION_MOUNTED ), - ERR_ENTRY( "Cannot unmount the partition while there are active FILE handles", IOMAN_ACTIVE_HANDLES ), - ERR_ENTRY( "The GPT partition header appears to be corrupt, refusing to mount", IOMAN_GPT_HEADER_CORRUPT ), - ERR_ENTRY( "Disk full", IOMAN_NOT_ENOUGH_FREE_SPACE ), - ERR_ENTRY( "Attempted to Read a sector out of bounds", IOMAN_OUT_OF_BOUNDS_READ ), - ERR_ENTRY( "Attempted to Write a sector out of bounds", IOMAN_OUT_OF_BOUNDS_WRITE ), - ERR_ENTRY( "I/O driver is busy", IOMAN_DRIVER_BUSY ), - ERR_ENTRY( "I/O driver returned fatal error", IOMAN_DRIVER_FATAL_ERROR ), - ERR_ENTRY( "I/O driver returned \"no medium error\"", IOMAN_DRIVER_NOMEDIUM ), +const struct _FFERRTAB +{ + const char * const strErrorString; + const uint8_t ucErrorCode; /* Currently there are less then 256 errors, so lets keep this table small. */ +} +xFreeRTOSFATErrorTable[] = +{ + { "Unknown or Generic Error!", 1 }, + ERR_ENTRY( "No Error", NONE ), + ERR_ENTRY( "Null Pointer provided, (probably for IOMAN)", NULL_POINTER ), + ERR_ENTRY( "Not enough memory (malloc() returned NULL)", NOT_ENOUGH_MEMORY ), + ERR_ENTRY( "Device Driver returned a FATAL error!", DEVICE_DRIVER_FAILED ), + ERR_ENTRY( "The blocksize is not 512 multiple", IOMAN_BAD_BLKSIZE ), + ERR_ENTRY( "The memory size, is not a multiple of the blocksize. (Atleast 2 Blocks)", IOMAN_BAD_MEMSIZE ), + ERR_ENTRY( "Device is already registered, use FF_UnregisterBlkDevice() first", IOMAN_DEV_ALREADY_REGD ), + ERR_ENTRY( "No mountable partition was found on the specified device", IOMAN_NO_MOUNTABLE_PARTITION ), + ERR_ENTRY( "The format of the MBR was unrecognised", IOMAN_INVALID_FORMAT ), + ERR_ENTRY( "The provided partition number is out-of-range (0 - 3)", IOMAN_INVALID_PARTITION_NUM ), + ERR_ENTRY( "The selected partition / volume doesn't appear to be FAT formatted", IOMAN_NOT_FAT_FORMATTED ), + ERR_ENTRY( "Cannot register device. (BlkSize not a multiple of 512)", IOMAN_DEV_INVALID_BLKSIZE ), + ERR_ENTRY( "Cannot unregister device, a partition is still mounted", IOMAN_PARTITION_MOUNTED ), + ERR_ENTRY( "Cannot unmount the partition while there are active FILE handles", IOMAN_ACTIVE_HANDLES ), + ERR_ENTRY( "The GPT partition header appears to be corrupt, refusing to mount", IOMAN_GPT_HEADER_CORRUPT ), + ERR_ENTRY( "Disk full", IOMAN_NOT_ENOUGH_FREE_SPACE ), + ERR_ENTRY( "Attempted to Read a sector out of bounds", IOMAN_OUT_OF_BOUNDS_READ ), + ERR_ENTRY( "Attempted to Write a sector out of bounds", IOMAN_OUT_OF_BOUNDS_WRITE ), + ERR_ENTRY( "I/O driver is busy", IOMAN_DRIVER_BUSY ), + ERR_ENTRY( "I/O driver returned fatal error", IOMAN_DRIVER_FATAL_ERROR ), + ERR_ENTRY( "I/O driver returned \"no medium error\"", IOMAN_DRIVER_NOMEDIUM ), - ERR_ENTRY( "Cannot open the file, file already in use", FILE_ALREADY_OPEN ), - ERR_ENTRY( "The specified file could not be found", FILE_NOT_FOUND ), - ERR_ENTRY( "Cannot open a Directory", FILE_OBJECT_IS_A_DIR ), - ERR_ENTRY( "Cannot open for writing: File is marked as Read-Only", FILE_IS_READ_ONLY ), - ERR_ENTRY( "Path not found", FILE_INVALID_PATH ), - ERR_ENTRY( "File operation failed - the file was not opened for writing", FILE_NOT_OPENED_IN_WRITE_MODE ), - ERR_ENTRY( "File operation failed - the file was not opened for reading", FILE_NOT_OPENED_IN_READ_MODE ), - ERR_ENTRY( "File operation failed - could not extend file", FILE_EXTEND_FAILED ), - ERR_ENTRY( "Destination file already exists", FILE_DESTINATION_EXISTS ), - ERR_ENTRY( "Source file was not found", FILE_SOURCE_NOT_FOUND ), - ERR_ENTRY( "Destination path (dir) was not found", FILE_DIR_NOT_FOUND ), - ERR_ENTRY( "Failed to create the directory Entry", FILE_COULD_NOT_CREATE_DIRENT ), - ERR_ENTRY( "A file handle was invalid", FILE_BAD_HANDLE ), - #if ( ffconfigREMOVABLE_MEDIA != 0 ) - ERR_ENTRY( "File handle got invalid because media was removed", FILE_MEDIA_REMOVED ), - #endif /* ffconfigREMOVABLE_MEDIA */ - ERR_ENTRY( "A file or folder of the same name already exists", DIR_OBJECT_EXISTS ), - ERR_ENTRY( "DIR_DIRECTORY_FULL", DIR_DIRECTORY_FULL ), - ERR_ENTRY( "DIR_END_OF_DIR", DIR_END_OF_DIR ), - ERR_ENTRY( "The directory is not empty", DIR_NOT_EMPTY ), - ERR_ENTRY( "Could not extend File or Folder - No Free Space!", FAT_NO_FREE_CLUSTERS ), - ERR_ENTRY( "Could not find the directory specified by the path", DIR_INVALID_PATH ), - ERR_ENTRY( "The Root Dir is full, and cannot be extended on Fat12 or 16 volumes", DIR_CANT_EXTEND_ROOT_DIR ), - ERR_ENTRY( "Not enough space to extend the directory.", DIR_EXTEND_FAILED ), - ERR_ENTRY( "Name exceeds the number of allowed characters for a filename", DIR_NAME_TOO_LONG ), + ERR_ENTRY( "Cannot open the file, file already in use", FILE_ALREADY_OPEN ), + ERR_ENTRY( "The specified file could not be found", FILE_NOT_FOUND ), + ERR_ENTRY( "Cannot open a Directory", FILE_OBJECT_IS_A_DIR ), + ERR_ENTRY( "Cannot open for writing: File is marked as Read-Only", FILE_IS_READ_ONLY ), + ERR_ENTRY( "Path not found", FILE_INVALID_PATH ), + ERR_ENTRY( "File operation failed - the file was not opened for writing", FILE_NOT_OPENED_IN_WRITE_MODE ), + ERR_ENTRY( "File operation failed - the file was not opened for reading", FILE_NOT_OPENED_IN_READ_MODE ), + ERR_ENTRY( "File operation failed - could not extend file", FILE_EXTEND_FAILED ), + ERR_ENTRY( "Destination file already exists", FILE_DESTINATION_EXISTS ), + ERR_ENTRY( "Source file was not found", FILE_SOURCE_NOT_FOUND ), + ERR_ENTRY( "Destination path (dir) was not found", FILE_DIR_NOT_FOUND ), + ERR_ENTRY( "Failed to create the directory Entry", FILE_COULD_NOT_CREATE_DIRENT ), + ERR_ENTRY( "A file handle was invalid", FILE_BAD_HANDLE ), + #if ( ffconfigREMOVABLE_MEDIA != 0 ) + ERR_ENTRY( "File handle got invalid because media was removed", FILE_MEDIA_REMOVED ), + #endif /* ffconfigREMOVABLE_MEDIA */ + ERR_ENTRY( "A file or folder of the same name already exists", DIR_OBJECT_EXISTS ), + ERR_ENTRY( "DIR_DIRECTORY_FULL", DIR_DIRECTORY_FULL ), + ERR_ENTRY( "DIR_END_OF_DIR", DIR_END_OF_DIR ), + ERR_ENTRY( "The directory is not empty", DIR_NOT_EMPTY ), + ERR_ENTRY( "Could not extend File or Folder - No Free Space!", FAT_NO_FREE_CLUSTERS ), + ERR_ENTRY( "Could not find the directory specified by the path", DIR_INVALID_PATH ), + ERR_ENTRY( "The Root Dir is full, and cannot be extended on Fat12 or 16 volumes", DIR_CANT_EXTEND_ROOT_DIR ), + ERR_ENTRY( "Not enough space to extend the directory.", DIR_EXTEND_FAILED ), + ERR_ENTRY( "Name exceeds the number of allowed characters for a filename", DIR_NAME_TOO_LONG ), - #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) - ERR_ENTRY( "An invalid Unicode character was provided!", UNICODE_INVALID_CODE ), - ERR_ENTRY( "Not enough space in the UTF-16 buffer to encode the entire sequence", UNICODE_DEST_TOO_SMALL ), - ERR_ENTRY( "An invalid UTF-16 sequence was encountered", UNICODE_INVALID_SEQUENCE ), - ERR_ENTRY( "Filename exceeds MAX long-filename length when converted to UTF-16", UNICODE_CONVERSION_EXCEEDED ), - #endif /* ffconfigUNICODE_UTF16_SUPPORT */ - }; + #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 ) + ERR_ENTRY( "An invalid Unicode character was provided!", UNICODE_INVALID_CODE ), + ERR_ENTRY( "Not enough space in the UTF-16 buffer to encode the entire sequence", UNICODE_DEST_TOO_SMALL ), + ERR_ENTRY( "An invalid UTF-16 sequence was encountered", UNICODE_INVALID_SEQUENCE ), + ERR_ENTRY( "Filename exceeds MAX long-filename length when converted to UTF-16", UNICODE_CONVERSION_EXCEEDED ), + #endif /* ffconfigUNICODE_UTF16_SUPPORT */ +}; /** * @public @@ -240,79 +240,79 @@ * @return Pointer to a string describing the error. * **/ - const char * FF_GetErrMessage( FF_Error_t iErrorCode ) - { - uint32_t stCount = ARRAY_SIZE( xFreeRTOSFATErrorTable ); +const char * FF_GetErrMessage( FF_Error_t iErrorCode ) +{ + uint32_t stCount = ARRAY_SIZE( xFreeRTOSFATErrorTable ); - while( stCount-- ) + while( stCount-- ) + { + if( ( ( UBaseType_t ) xFreeRTOSFATErrorTable[ stCount ].ucErrorCode ) == FF_GETERROR( iErrorCode ) ) { - if( ( ( UBaseType_t ) xFreeRTOSFATErrorTable[ stCount ].ucErrorCode ) == FF_GETERROR( iErrorCode ) ) - { - break; - } + break; } - - return xFreeRTOSFATErrorTable[ stCount ].strErrorString; } - const char * FF_GetErrModule( FF_Error_t iErrorCode ) - { - uint32_t stCount = ARRAY_SIZE( xFreeRTOSFATModuleTable ); + return xFreeRTOSFATErrorTable[ stCount ].strErrorString; +} - while( stCount-- ) +const char * FF_GetErrModule( FF_Error_t iErrorCode ) +{ + uint32_t stCount = ARRAY_SIZE( xFreeRTOSFATModuleTable ); + + while( stCount-- ) + { + if( xFreeRTOSFATModuleTable[ stCount ].ucModuleID == ( uint8_t ) FF_GETMODULE( iErrorCode ) ) { - if( xFreeRTOSFATModuleTable[ stCount ].ucModuleID == ( uint8_t ) FF_GETMODULE( iErrorCode ) ) - { - break; - } + break; } - - return xFreeRTOSFATModuleTable[ stCount ].strModuleName; } + return xFreeRTOSFATModuleTable[ stCount ].strModuleName; +} + #if ( ffconfigHAS_FUNCTION_TAB != 0 ) - const char * FF_GetErrFunction( FF_Error_t iErrorCode ) - { - uint32_t stCount = ARRAY_SIZE( xFreeRTOSFATFunctionTable ); - uint16_t ModuleFunc = FF_GETMOD_FUNC( iErrorCode ); - static char funcCode[ 32 ]; + const char * FF_GetErrFunction( FF_Error_t iErrorCode ) + { + uint32_t stCount = ARRAY_SIZE( xFreeRTOSFATFunctionTable ); + uint16_t ModuleFunc = FF_GETMOD_FUNC( iErrorCode ); + static char funcCode[ 32 ]; - while( stCount-- != 0 ) + while( stCount-- != 0 ) + { + if( xFreeRTOSFATFunctionTable[ stCount ].ucFunctionID == ModuleFunc ) { - if( xFreeRTOSFATFunctionTable[ stCount ].ucFunctionID == ModuleFunc ) - { - return xFreeRTOSFATFunctionTable[ stCount ].strFunctionName; - } + return xFreeRTOSFATFunctionTable[ stCount ].strFunctionName; } - - snprintf( funcCode, sizeof( funcCode ), "Func %X", ModuleFunc ); - return ( const char * ) funcCode; } + + snprintf( funcCode, sizeof( funcCode ), "Func %X", ModuleFunc ); + return ( const char * ) funcCode; + } #endif /* ffconfigHAS_FUNCTION_TAB */ - const char * FF_GetErrDescription( FF_Error_t iErrorCode, - char * apBuf, - int aMaxlen ) +const char * FF_GetErrDescription( FF_Error_t iErrorCode, + char * apBuf, + int aMaxlen ) +{ + if( FF_isERR( iErrorCode ) ) { - if( FF_isERR( iErrorCode ) ) - { - #if ( ffconfigHAS_FUNCTION_TAB != 0 ) - snprintf( apBuf, ( size_t ) aMaxlen, "%s::%s::%s", - FF_GetErrModule( iErrorCode ), - FF_GetErrFunction( iErrorCode ), - FF_GetErrMessage( iErrorCode ) ); - #else - snprintf( apBuf, ( size_t ) aMaxlen, "%s::%s", - FF_GetErrModule( iErrorCode ), - FF_GetErrMessage( iErrorCode ) ); - #endif /* ffconfigHAS_FUNCTION_TAB */ - } - else - { - snprintf( apBuf, ( size_t ) aMaxlen, "No error" ); - } - - return apBuf; + #if ( ffconfigHAS_FUNCTION_TAB != 0 ) + snprintf( apBuf, ( size_t ) aMaxlen, "%s::%s::%s", + FF_GetErrModule( iErrorCode ), + FF_GetErrFunction( iErrorCode ), + FF_GetErrMessage( iErrorCode ) ); + #else + snprintf( apBuf, ( size_t ) aMaxlen, "%s::%s", + FF_GetErrModule( iErrorCode ), + FF_GetErrMessage( iErrorCode ) ); + #endif /* ffconfigHAS_FUNCTION_TAB */ } + else + { + snprintf( apBuf, ( size_t ) aMaxlen, "No error" ); + } + + return apBuf; +} #endif /* ffconfigDEBUG != 0 */ diff --git a/ff_fat.c b/ff_fat.c index 0e96760..99e144d 100644 --- a/ff_fat.c +++ b/ff_fat.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -265,9 +265,9 @@ FF_Error_t FF_ReleaseFATBuffers( FF_IOManager_t * pxIOManager, } #if ffconfigFAT_USES_STAT - { - fatStat.clearCount++; - } + { + fatStat.clearCount++; + } #endif /* ffconfigFAT_USES_STAT */ return xError; @@ -305,9 +305,9 @@ FF_Buffer_t * prvGetFromFATBuffers( FF_IOManager_t * pxIOManager, * write-permission is not required OR the buffer has write permission: * it can be reused. */ #if ffconfigFAT_USES_STAT - { - fatStat.reuseCount[ ( ucMode & FF_MODE_WRITE ) ? 1 : 0 ]++; - } + { + fatStat.reuseCount[ ( ucMode & FF_MODE_WRITE ) ? 1 : 0 ]++; + } #endif /* ffconfigFAT_USES_STAT */ } else @@ -315,18 +315,18 @@ FF_Buffer_t * prvGetFromFATBuffers( FF_IOManager_t * pxIOManager, xError = FF_ReleaseBuffer( pxIOManager, pxBuffer ); pxBuffer = NULL; #if ffconfigFAT_USES_STAT - { - fatStat.missCount[ ( ucMode & FF_MODE_WRITE ) ? 1 : 0 ]++; - } + { + fatStat.missCount[ ( ucMode & FF_MODE_WRITE ) ? 1 : 0 ]++; + } #endif /* ffconfigFAT_USES_STAT */ } } else { #if ffconfigFAT_USES_STAT - { - fatStat.getCount[ ( ucMode & FF_MODE_WRITE ) ? 1 : 0 ]++; - } + { + fatStat.getCount[ ( ucMode & FF_MODE_WRITE ) ? 1 : 0 ]++; + } #endif /* ffconfigFAT_USES_STAT */ } } @@ -1097,31 +1097,31 @@ uint32_t FF_FindFreeCluster( FF_IOManager_t * pxIOManager, #endif { #if ( ffconfigFSINFO_TRUSTED != 0 ) + { + /* If 'ffconfigFSINFO_TRUSTED', the contents of the field 'ulLastFreeCluster' is trusted. + * Only ready it in case of FAT32 and only during the very first time, i.e. when + * ulLastFreeCluster is still zero. */ + if( ( pxIOManager->xPartition.ucType == FF_T_FAT32 ) && ( pxIOManager->xPartition.ulLastFreeCluster == 0ul ) ) { - /* If 'ffconfigFSINFO_TRUSTED', the contents of the field 'ulLastFreeCluster' is trusted. - * Only ready it in case of FAT32 and only during the very first time, i.e. when - * ulLastFreeCluster is still zero. */ - if( ( pxIOManager->xPartition.ucType == FF_T_FAT32 ) && ( pxIOManager->xPartition.ulLastFreeCluster == 0ul ) ) - { - pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFSInfoLBA, FF_MODE_READ ); + pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFSInfoLBA, FF_MODE_READ ); - if( pxBuffer == NULL ) + if( pxBuffer == NULL ) + { + xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_FINDFREECLUSTER ); + } + else + { + if( ( FF_getLong( pxBuffer->pucBuffer, 0 ) == 0x41615252 ) && + ( FF_getLong( pxBuffer->pucBuffer, 484 ) == 0x61417272 ) ) { - xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_FINDFREECLUSTER ); + ulCluster = FF_getLong( pxBuffer->pucBuffer, 492 ); } - else - { - if( ( FF_getLong( pxBuffer->pucBuffer, 0 ) == 0x41615252 ) && - ( FF_getLong( pxBuffer->pucBuffer, 484 ) == 0x61417272 ) ) - { - ulCluster = FF_getLong( pxBuffer->pucBuffer, 492 ); - } - xError = FF_ReleaseBuffer( pxIOManager, pxBuffer ); - pxBuffer = NULL; - } + xError = FF_ReleaseBuffer( pxIOManager, pxBuffer ); + pxBuffer = NULL; } } + } #endif /* if ( ffconfigFSINFO_TRUSTED != 0 ) */ if( FF_isERR( xError ) == pdFALSE ) @@ -1479,43 +1479,43 @@ uint32_t FF_CountFreeClusters( FF_IOManager_t * pxIOManager, { /* For FAT16 and FAT32 */ #if ( ffconfigFSINFO_TRUSTED != 0 ) + { + /* If 'ffconfigFSINFO_TRUSTED', the contents of the field 'ulFreeClusterCount' is trusted. */ + if( pxIOManager->xPartition.ucType == FF_T_FAT32 ) { - /* If 'ffconfigFSINFO_TRUSTED', the contents of the field 'ulFreeClusterCount' is trusted. */ - if( pxIOManager->xPartition.ucType == FF_T_FAT32 ) - { - pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFSInfoLBA, FF_MODE_READ ); + pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFSInfoLBA, FF_MODE_READ ); - if( pxBuffer == NULL ) - { - xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_COUNTFREECLUSTERS ); - } - else + if( pxBuffer == NULL ) + { + xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_COUNTFREECLUSTERS ); + } + else + { + if( ( FF_getLong( pxBuffer->pucBuffer, 0 ) == 0x41615252 ) && + ( FF_getLong( pxBuffer->pucBuffer, 484 ) == 0x61417272 ) ) { - if( ( FF_getLong( pxBuffer->pucBuffer, 0 ) == 0x41615252 ) && - ( FF_getLong( pxBuffer->pucBuffer, 484 ) == 0x61417272 ) ) - { - ulFreeClusters = FF_getLong( pxBuffer->pucBuffer, 488 ); + ulFreeClusters = FF_getLong( pxBuffer->pucBuffer, 488 ); - if( ulFreeClusters != ~0ul ) - { - xInfoKnown = pdTRUE; - } - else - { - ulFreeClusters = 0ul; - } + if( ulFreeClusters != ~0ul ) + { + xInfoKnown = pdTRUE; } - - xError = FF_ReleaseBuffer( pxIOManager, pxBuffer ); - pxBuffer = NULL; - - if( xInfoKnown != pdFALSE ) + else { - pxIOManager->xPartition.ulFreeClusterCount = ulFreeClusters; + ulFreeClusters = 0ul; } } + + xError = FF_ReleaseBuffer( pxIOManager, pxBuffer ); + pxBuffer = NULL; + + if( xInfoKnown != pdFALSE ) + { + pxIOManager->xPartition.ulFreeClusterCount = ulFreeClusters; + } } } + } #endif /* if ( ffconfigFSINFO_TRUSTED != 0 ) */ if( ( xInfoKnown == pdFALSE ) && ( pxIOManager->xPartition.usBlkSize != 0 ) ) @@ -1540,15 +1540,15 @@ uint32_t FF_CountFreeClusters( FF_IOManager_t * pxIOManager, } #if USE_SOFT_WDT - { - /* _HT_ : FF_CountFreeClusters was a little too busy, have it call the WDT and sleep */ - clearWDT(); + { + /* _HT_ : FF_CountFreeClusters was a little too busy, have it call the WDT and sleep */ + clearWDT(); - if( ( ( ulIndex + 1 ) % 32 ) == 0 ) - { - FF_Sleep( 1 ); - } + if( ( ( ulIndex + 1 ) % 32 ) == 0 ) + { + FF_Sleep( 1 ); } + } #endif for( x = 0; x < ulEntriesPerSector; x++ ) diff --git a/ff_file.c b/ff_file.c index b7c615b..3ad033a 100644 --- a/ff_file.c +++ b/ff_file.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -142,26 +142,26 @@ static FF_FILE * prvAllocFileHandle( FF_IOManager_t * pxIOManager, memset( pxFile, 0, sizeof( *pxFile ) ); #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) - { - pxFile->pucBuffer = ( uint8_t * ) ffconfigMALLOC( pxIOManager->usSectorSize ); + { + pxFile->pucBuffer = ( uint8_t * ) ffconfigMALLOC( pxIOManager->usSectorSize ); - if( pxFile->pucBuffer != NULL ) - { - memset( pxFile->pucBuffer, 0, pxIOManager->usSectorSize ); - } - else - { - *pxError = FF_createERR( FF_ERR_NOT_ENOUGH_MEMORY, FF_OPEN ); - ffconfigFREE( pxFile ); - /* Make sure that NULL will be returned. */ - pxFile = NULL; - } + if( pxFile->pucBuffer != NULL ) + { + memset( pxFile->pucBuffer, 0, pxIOManager->usSectorSize ); } - #else /* if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) */ + else { - /* Remove compiler warnings. */ - ( void ) pxIOManager; + *pxError = FF_createERR( FF_ERR_NOT_ENOUGH_MEMORY, FF_OPEN ); + ffconfigFREE( pxFile ); + /* Make sure that NULL will be returned. */ + pxFile = NULL; } + } + #else /* if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) */ + { + /* Remove compiler warnings. */ + ( void ) pxIOManager; + } #endif /* if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) */ } @@ -246,12 +246,12 @@ static FF_FILE * prvAllocFileHandle( FF_IOManager_t * pxIOManager, #endif #if ( ffconfigPROTECT_FF_FOPEN_WITH_SEMAPHORE == 1 ) + { + if( ( ucMode & FF_MODE_CREATE ) != 0U ) { - if( ( ucMode & FF_MODE_CREATE ) != 0U ) - { - FF_PendSemaphore( pxIOManager->pvSemaphoreOpen ); - } + FF_PendSemaphore( pxIOManager->pvSemaphoreOpen ); } + } #endif memset( &xFindParams, '\0', sizeof( xFindParams ) ); @@ -465,9 +465,9 @@ static FF_FILE * prvAllocFileHandle( FF_IOManager_t * pxIOManager, if( pxFile != NULL ) { #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) - { - ffconfigFREE( pxFile->pucBuffer ); - } + { + ffconfigFREE( pxFile->pucBuffer ); + } #endif ffconfigFREE( pxFile ); } @@ -476,12 +476,12 @@ static FF_FILE * prvAllocFileHandle( FF_IOManager_t * pxIOManager, } #if ( ffconfigPROTECT_FF_FOPEN_WITH_SEMAPHORE == 1 ) + { + if( ( ucMode & FF_MODE_CREATE ) != 0U ) { - if( ( ucMode & FF_MODE_CREATE ) != 0U ) - { - FF_ReleaseSemaphore( pxIOManager->pvSemaphoreOpen ); - } + FF_ReleaseSemaphore( pxIOManager->pvSemaphoreOpen ); } + } #endif if( pxError != NULL ) @@ -636,11 +636,11 @@ static FF_FILE * prvAllocFileHandle( FF_IOManager_t * pxIOManager, FF_LockFAT( pxIOManager ); #if ( ffconfigHASH_CACHE != 0 ) - { - /* A directory is removed so invalidate any hash table - * referring to this directory. */ - FF_UnHashDir( pxIOManager, pxFile->ulObjectCluster ); - } + { + /* A directory is removed so invalidate any hash table + * referring to this directory. */ + FF_UnHashDir( pxIOManager, pxFile->ulObjectCluster ); + } #endif /* ffconfigHASH_CACHE */ { /* Add parameter 0 to delete the entire chain! @@ -665,11 +665,11 @@ static FF_FILE * prvAllocFileHandle( FF_IOManager_t * pxIOManager, } #if ( ffconfigHASH_CACHE != 0 ) - { - /* Invalidate any hash table of the parent directory - * as well. */ - FF_UnHashDir( pxIOManager, pxFile->ulDirCluster ); - } + { + /* Invalidate any hash table of the parent directory + * as well. */ + FF_UnHashDir( pxIOManager, pxFile->ulDirCluster ); + } #endif /* ffconfigHASH_CACHE */ /* Edit the Directory Entry, so it will show as deleted. @@ -699,12 +699,12 @@ static FF_FILE * prvAllocFileHandle( FF_IOManager_t * pxIOManager, } #if ( ffconfigPATH_CACHE != 0 ) - { - /* We're removing a directory which might contain - * subdirectories. Instead of iterating through all - * subdirectories, just clear the path cache. */ - FF_RmPathCache( pxIOManager, pcPath ); - } + { + /* We're removing a directory which might contain + * subdirectories. Instead of iterating through all + * subdirectories, just clear the path cache. */ + FF_RmPathCache( pxIOManager, pcPath ); + } #endif } while( pdFALSE ); @@ -799,9 +799,9 @@ static FF_FILE * prvAllocFileHandle( FF_IOManager_t * pxIOManager, } #if ( ffconfigHASH_CACHE != 0 ) - { - FF_UnHashDir( pxIOManager, pxFile->ulDirCluster ); - } + { + FF_UnHashDir( pxIOManager, pxFile->ulDirCluster ); + } #endif /* ffconfigHASH_CACHE */ /* Remove LFN entries, if any. */ xError = FF_RmLFNs( pxIOManager, ( uint16_t ) pxFile->usDirEntry, &xFetchContext ); @@ -1047,15 +1047,15 @@ static FF_FILE * prvAllocFileHandle( FF_IOManager_t * pxIOManager, } #if ( ffconfigPATH_CACHE != 0 ) + { + if( xIsDirectory != 0 ) { - if( xIsDirectory != 0 ) - { - /* We've renamed a directory which might contain - * subdirectories. To avoid having false entries, clear - * the path cache. */ - FF_RmPathCache( pxIOManager, szSourceFile ); - } + /* We've renamed a directory which might contain + * subdirectories. To avoid having false entries, clear + * the path cache. */ + FF_RmPathCache( pxIOManager, szSourceFile ); } + } #endif } else /* ulDirCluster == 0ul */ @@ -1454,16 +1454,16 @@ static FF_Error_t FF_ExtendFile( FF_FILE * pxFile, * speed of writing to disk. */ #if ( ffconfigFILE_EXTEND_FLUSHES_BUFFERS != 0 ) - { - FF_Error_t xTempError; + { + FF_Error_t xTempError; - xTempError = FF_FlushCache( pxIOManager ); + xTempError = FF_FlushCache( pxIOManager ); - if( FF_isERR( xError ) == pdFALSE ) - { - xError = xTempError; - } + if( FF_isERR( xError ) == pdFALSE ) + { + xError = xTempError; } + } #endif /* ffconfigFILE_EXTEND_FLUSHES_BUFFERS */ if( pxFile->ulFilePointer == pxFile->ulFileSize ) @@ -1591,7 +1591,7 @@ static uint32_t FF_FileLBA( FF_FILE * pxFile ) * * Side effects: * - pxFile->ulCurrentCluster : relative cluster number (0 <= Num < ulChainLength) - * - pxFile->ulAddrCurrentCluster : fysical cluster on the partition + * - pxFile->ulAddrCurrentCluster : physical cluster on the partition **/ static uint32_t FF_SetCluster( FF_FILE * pxFile, FF_Error_t * pxError ) @@ -1651,78 +1651,78 @@ static uint32_t FF_ReadPartial( FF_FILE * pxFile, /* Bytes to read are within a block and less than a block size. */ #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) + { + BaseType_t xLastRead; + + /* Optimised method: each file handle holds one data block + * in cache: 'pxFile->pucBuffer'. */ + /* See if the current block will be accessed after this read: */ + if( ( ulRelBlockPos + ulCount ) >= ( uint32_t ) pxFile->pxIOManager->usSectorSize ) + { + /* After this read, ulFilePointer will point to the next block/sector. */ + xLastRead = pdTRUE; + } + else { - BaseType_t xLastRead; + /* It is not the last read within this block/sector. */ + xLastRead = pdFALSE; + } - /* Optimised method: each file handle holds one data block - * in cache: 'pxFile->pucBuffer'. */ - /* See if the current block will be accessed after this read: */ - if( ( ulRelBlockPos + ulCount ) >= ( uint32_t ) pxFile->pxIOManager->usSectorSize ) - { - /* After this read, ulFilePointer will point to the next block/sector. */ - xLastRead = pdTRUE; - } - else - { - /* It is not the last read within this block/sector. */ - xLastRead = pdFALSE; - } + if( ( pxFile->ucState & FF_BUFSTATE_VALID ) == 0 ) + { + xError = FF_BlockRead( pxFile->pxIOManager, ulItemLBA, 1, pxFile->pucBuffer, pdFALSE ); - if( ( pxFile->ucState & FF_BUFSTATE_VALID ) == 0 ) + if( FF_isERR( xError ) == pdFALSE ) { - xError = FF_BlockRead( pxFile->pxIOManager, ulItemLBA, 1, pxFile->pucBuffer, pdFALSE ); - - if( FF_isERR( xError ) == pdFALSE ) - { - pxFile->ucState = FF_BUFSTATE_VALID; - } + pxFile->ucState = FF_BUFSTATE_VALID; } + } - if( ( pxFile->ucState & FF_BUFSTATE_VALID ) != 0 ) - { - memcpy( pucBuffer, pxFile->pucBuffer + ulRelBlockPos, ulCount ); - pxFile->ulFilePointer += ulCount; - ulBytesRead = ulCount; + if( ( pxFile->ucState & FF_BUFSTATE_VALID ) != 0 ) + { + memcpy( pucBuffer, pxFile->pucBuffer + ulRelBlockPos, ulCount ); + pxFile->ulFilePointer += ulCount; + ulBytesRead = ulCount; - if( ( xLastRead == pdTRUE ) && ( ( pxFile->ucState & FF_BUFSTATE_WRITTEN ) != 0 ) ) - { - /* If the data was changed (file in 'update' mode), store the changes: */ - xError = FF_BlockWrite( pxFile->pxIOManager, ulItemLBA, 1, pxFile->pucBuffer, pdFALSE ); - } - } - else + if( ( xLastRead == pdTRUE ) && ( ( pxFile->ucState & FF_BUFSTATE_WRITTEN ) != 0 ) ) { - ulBytesRead = 0ul; + /* If the data was changed (file in 'update' mode), store the changes: */ + xError = FF_BlockWrite( pxFile->pxIOManager, ulItemLBA, 1, pxFile->pucBuffer, pdFALSE ); } + } + else + { + ulBytesRead = 0ul; + } - if( xLastRead == pdTRUE ) - { - /* As the next FF_Read() will go passed the current block, invalidate the buffer now. */ - pxFile->ucState = FF_BUFSTATE_INVALID; - } + if( xLastRead == pdTRUE ) + { + /* As the next FF_Read() will go passed the current block, invalidate the buffer now. */ + pxFile->ucState = FF_BUFSTATE_INVALID; } + } #else /* if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) */ - { - FF_Buffer_t * pxBuffer; - /* Reading in the standard way, using FF_Buffer_t. */ - pxBuffer = FF_GetBuffer( pxFile->pxIOManager, ulItemLBA, FF_MODE_READ ); + { + FF_Buffer_t * pxBuffer; + /* Reading in the standard way, using FF_Buffer_t. */ + pxBuffer = FF_GetBuffer( pxFile->pxIOManager, ulItemLBA, FF_MODE_READ ); - if( pxBuffer == NULL ) - { - xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_READ ); - ulBytesRead = 0ul; - } - else - { - memcpy( pucBuffer, pxBuffer->pucBuffer + ulRelBlockPos, ulCount ); + if( pxBuffer == NULL ) + { + xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_READ ); + ulBytesRead = 0ul; + } + else + { + memcpy( pucBuffer, pxBuffer->pucBuffer + ulRelBlockPos, ulCount ); - /* Releasing a buffer in FF_MODE_READ mode will not lead to an error, - * because no disk access is needed. */ - xError = FF_ReleaseBuffer( pxFile->pxIOManager, pxBuffer ); - pxFile->ulFilePointer += ulCount; - ulBytesRead = ulCount; - } + /* Releasing a buffer in FF_MODE_READ mode will not lead to an error, + * because no disk access is needed. */ + xError = FF_ReleaseBuffer( pxFile->pxIOManager, pxBuffer ); + pxFile->ulFilePointer += ulCount; + ulBytesRead = ulCount; } + } #endif /* if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) */ *pxError = xError; @@ -2118,81 +2118,81 @@ static uint32_t FF_WritePartial( FF_FILE * pxFile, uint32_t ulBytesWritten; #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) + { + BaseType_t xLastRead; + + if( ( ulRelBlockPos + ulCount ) >= ( uint32_t ) pxFile->pxIOManager->usSectorSize ) + { + /* After this read, ulFilePointer will point to the next block/sector. */ + xLastRead = pdTRUE; + } + else { - BaseType_t xLastRead; + /* It is not the last read within this block/sector. */ + xLastRead = pdFALSE; + } - if( ( ulRelBlockPos + ulCount ) >= ( uint32_t ) pxFile->pxIOManager->usSectorSize ) - { - /* After this read, ulFilePointer will point to the next block/sector. */ - xLastRead = pdTRUE; - } - else - { - /* It is not the last read within this block/sector. */ - xLastRead = pdFALSE; - } + if( ( ( pxFile->ucState & FF_BUFSTATE_VALID ) == 0 ) && + ( ( ulRelBlockPos != 0 ) || ( pxFile->ulFilePointer < pxFile->ulFileSize ) ) ) + { + xError = FF_BlockRead( pxFile->pxIOManager, ulItemLBA, 1, pxFile->pucBuffer, pdFALSE ); + /* pxFile->ucState will be set later on. */ + } + else + { + xError = FF_ERR_NONE; - if( ( ( pxFile->ucState & FF_BUFSTATE_VALID ) == 0 ) && - ( ( ulRelBlockPos != 0 ) || ( pxFile->ulFilePointer < pxFile->ulFileSize ) ) ) - { - xError = FF_BlockRead( pxFile->pxIOManager, ulItemLBA, 1, pxFile->pucBuffer, pdFALSE ); - /* pxFile->ucState will be set later on. */ - } - else - { - xError = FF_ERR_NONE; + /* the buffer is valid or a whole block/sector will be written, so it is + * not necessary to read the contents first. */ + } - /* the buffer is valid or a whole block/sector will be written, so it is - * not necessary to read the contents first. */ - } + if( FF_isERR( xError ) == pdFALSE ) + { + memcpy( pxFile->pucBuffer + ulRelBlockPos, pucBuffer, ulCount ); - if( FF_isERR( xError ) == pdFALSE ) + if( xLastRead == pdTRUE ) { - memcpy( pxFile->pucBuffer + ulRelBlockPos, pucBuffer, ulCount ); - - if( xLastRead == pdTRUE ) - { - xError = FF_BlockWrite( pxFile->pxIOManager, ulItemLBA, 1, pxFile->pucBuffer, pdFALSE ); - pxFile->ucState = FF_BUFSTATE_INVALID; - } - else - { - pxFile->ucState |= FF_BUFSTATE_WRITTEN | FF_BUFSTATE_VALID; - } + xError = FF_BlockWrite( pxFile->pxIOManager, ulItemLBA, 1, pxFile->pucBuffer, pdFALSE ); + pxFile->ucState = FF_BUFSTATE_INVALID; } else { - pxFile->ucState = FF_BUFSTATE_INVALID; + pxFile->ucState |= FF_BUFSTATE_WRITTEN | FF_BUFSTATE_VALID; } } - #else /* if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) */ + else { - FF_Buffer_t * pxBuffer; + pxFile->ucState = FF_BUFSTATE_INVALID; + } + } + #else /* if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) */ + { + FF_Buffer_t * pxBuffer; - if( ( ulRelBlockPos == 0 ) && ( pxFile->ulFilePointer >= pxFile->ulFileSize ) ) - { - /* An entire sector will be written. */ - pxBuffer = FF_GetBuffer( pxFile->pxIOManager, ulItemLBA, FF_MODE_WR_ONLY ); - } - else - { - /* A partial write will be done, make sure to read the contents before - * changing anything. */ - pxBuffer = FF_GetBuffer( pxFile->pxIOManager, ulItemLBA, FF_MODE_WRITE ); - } + if( ( ulRelBlockPos == 0 ) && ( pxFile->ulFilePointer >= pxFile->ulFileSize ) ) + { + /* An entire sector will be written. */ + pxBuffer = FF_GetBuffer( pxFile->pxIOManager, ulItemLBA, FF_MODE_WR_ONLY ); + } + else + { + /* A partial write will be done, make sure to read the contents before + * changing anything. */ + pxBuffer = FF_GetBuffer( pxFile->pxIOManager, ulItemLBA, FF_MODE_WRITE ); + } - if( pxBuffer == NULL ) - { - xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_WRITE ); - } - else - { - /* Here we copy to the sector boundary. */ - memcpy( ( pxBuffer->pucBuffer + ulRelBlockPos ), pucBuffer, ulCount ); + if( pxBuffer == NULL ) + { + xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_WRITE ); + } + else + { + /* Here we copy to the sector boundary. */ + memcpy( ( pxBuffer->pucBuffer + ulRelBlockPos ), pucBuffer, ulCount ); - xError = FF_ReleaseBuffer( pxFile->pxIOManager, pxBuffer ); - } + xError = FF_ReleaseBuffer( pxFile->pxIOManager, pxBuffer ); } + } #endif /* if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) */ if( FF_isERR( xError ) == pdFALSE ) @@ -2482,7 +2482,7 @@ int32_t FF_PutC( FF_FILE * pxFile, FF_Error_t xResult; if( pxFile == NULL ) - { /* Ensure we don't have a Null file pointer on a Public interface. */ + { /* Ensure we don't have a Null file pointer on a Public interface. */ xResult = FF_createERR( FF_ERR_NULL_POINTER, FF_PUTC ); } else if( ( pxFile->ucMode & FF_MODE_WRITE ) == 0 ) @@ -2547,7 +2547,7 @@ int32_t FF_PutC( FF_FILE * pxFile, * @param lOffset An integer (+/-) to seek to, from the specified origin. * @param xOrigin Where to seek from. (FF_SEEK_SET seek from start, FF_SEEK_CUR seek from current position, or FF_SEEK_END seek from end of file). * - * @retval 0 on Sucess, + * @retval 0 on Success, * @retval -2 if offset results in an invalid position in the file. * @retval FF_ERR_NULL_POINTER if a FF_FILE pointer was not received. * @retval -3 if an invalid origin was provided. @@ -2567,19 +2567,19 @@ FF_Error_t FF_Seek( FF_FILE * pxFile, xError = FF_FlushCache( pxFile->pxIOManager ); #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) + { + if( FF_isERR( xError ) == pdFALSE ) { - if( FF_isERR( xError ) == pdFALSE ) + /* Here we must ensure that if the user tries to seek, and we had data in the file's + * write buffer that this is written to disk. */ + if( ( pxFile->ucState & FF_BUFSTATE_WRITTEN ) != 0 ) { - /* Here we must ensure that if the user tries to seek, and we had data in the file's - * write buffer that this is written to disk. */ - if( ( pxFile->ucState & FF_BUFSTATE_WRITTEN ) != 0 ) - { - xError = FF_BlockWrite( pxFile->pxIOManager, FF_FileLBA( pxFile ), 1, pxFile->pucBuffer, pdFALSE ); - } - - pxFile->ucState = FF_BUFSTATE_INVALID; + xError = FF_BlockWrite( pxFile->pxIOManager, FF_FileLBA( pxFile ), 1, pxFile->pucBuffer, pdFALSE ); } + + pxFile->ucState = FF_BUFSTATE_INVALID; } + } #endif /* ffconfigOPTIMISE_UNALIGNED_ACCESS */ if( FF_isERR( xError ) == pdFALSE ) @@ -2610,7 +2610,7 @@ FF_Error_t FF_Seek( FF_FILE * pxFile, else { xError = FF_createERR( FF_ERR_FILE_SEEK_INVALID_ORIGIN, FF_SEEK ); - /* To supress a compiler warning. */ + /* To suppress a compiler warning. */ ulPosition = ( uint32_t ) 0u; } @@ -2692,7 +2692,7 @@ FF_Error_t FF_Seek( FF_FILE * pxFile, * * @param pxFile FF_FILE object that was created by FF_Open(). * - * @retval 0 on sucess. + * @retval 0 on success. * @retval FF_ERR_NULL_POINTER if a null pointer was provided. * @retval FF_ERR_FILE_BAD_HANDLE if handle is not recognized * @retval FF_ERR_FILE_MEDIA_REMOVED please call FF_Close @@ -2802,7 +2802,7 @@ FF_Error_t FF_CheckValid( FF_FILE * pxFile ) if( FF_isERR( xError ) == pdFALSE ) { - xError = FF_FlushCache( pxFile->pxIOManager ); /* Ensure all modfied blocks are flushed to disk! */ + xError = FF_FlushCache( pxFile->pxIOManager ); /* Ensure all modifed blocks are flushed to disk! */ } } } @@ -3016,7 +3016,7 @@ FF_Error_t FF_CheckValid( FF_FILE * pxFile ) if( FF_isERR( xError ) == pdFALSE ) { - xError = FF_FlushCache( pxIOManager ); /* Ensure all modfied blocks are flushed to disk! */ + xError = FF_FlushCache( pxIOManager ); /* Ensure all modifed blocks are flushed to disk! */ } } while( pdFALSE ); @@ -3030,7 +3030,7 @@ FF_Error_t FF_CheckValid( FF_FILE * pxFile ) * * @param pxFile FF_FILE object that was created by FF_Open(). * - * @retval 0 on sucess. + * @retval 0 on success. * @retval -1 if a null pointer was provided. * **/ @@ -3054,43 +3054,43 @@ FF_Error_t FF_Close( FF_FILE * pxFile ) xError = FF_CheckValid( pxFile ); #if ( ffconfigREMOVABLE_MEDIA != 0 ) + { + if( FF_GETERROR( xError ) == FF_ERR_FILE_MEDIA_REMOVED ) { - if( FF_GETERROR( xError ) == FF_ERR_FILE_MEDIA_REMOVED ) + FF_PendSemaphore( pxFile->pxIOManager->pvSemaphore ); { - FF_PendSemaphore( pxFile->pxIOManager->pvSemaphore ); - { - pxFileChain = ( FF_FILE * ) pxFile->pxIOManager->FirstFile; + pxFileChain = ( FF_FILE * ) pxFile->pxIOManager->FirstFile; - if( pxFileChain == pxFile ) - { - pxFile->pxIOManager->FirstFile = pxFile->pxNext; - } - else + if( pxFileChain == pxFile ) + { + pxFile->pxIOManager->FirstFile = pxFile->pxNext; + } + else + { + while( pxFileChain ) { - while( pxFileChain ) + if( pxFileChain->pxNext == pxFile ) { - if( pxFileChain->pxNext == pxFile ) - { - pxFileChain->pxNext = pxFile->pxNext; - break; - } - - pxFileChain = pxFileChain->pxNext; /* Forgot this one */ + pxFileChain->pxNext = pxFile->pxNext; + break; } - } - } /* Semaphore released, linked list was shortened! */ - FF_ReleaseSemaphore( pxFile->pxIOManager->pvSemaphore ); - #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) - { - ffconfigFREE( pxFile->pucBuffer ); + pxFileChain = pxFileChain->pxNext; /* Forgot this one */ } - #endif /* ffconfigOPTIMISE_UNALIGNED_ACCESS */ - ffconfigFREE( pxFile ); /* So at least we have freed the pointer. */ - xError = FF_ERR_NONE; - break; + } + } /* Semaphore released, linked list was shortened! */ + + FF_ReleaseSemaphore( pxFile->pxIOManager->pvSemaphore ); + #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) + { + ffconfigFREE( pxFile->pucBuffer ); } + #endif /* ffconfigOPTIMISE_UNALIGNED_ACCESS */ + ffconfigFREE( pxFile ); /* So at least we have freed the pointer. */ + xError = FF_ERR_NONE; + break; } + } #endif /* ffconfigREMOVABLE_MEDIA */ if( FF_isERR( xError ) ) @@ -3140,7 +3140,7 @@ FF_Error_t FF_Close( FF_FILE * pxFile ) /* Handle Linked list! */ FF_PendSemaphore( pxFile->pxIOManager->pvSemaphore ); - { /* Semaphore is required, or linked list could become corrupted. */ + { /* Semaphore is required, or linked list could become corrupted. */ pxFileChain = ( FF_FILE * ) pxFile->pxIOManager->FirstFile; if( pxFileChain == pxFile ) @@ -3165,25 +3165,25 @@ FF_Error_t FF_Close( FF_FILE * pxFile ) FF_ReleaseSemaphore( pxFile->pxIOManager->pvSemaphore ); #if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) + { + if( pxFile->pucBuffer != NULL ) { - if( pxFile->pucBuffer != NULL ) + /* Ensure any unaligned points are pushed to the disk! */ + if( pxFile->ucState & FF_BUFSTATE_WRITTEN ) { - /* Ensure any unaligned points are pushed to the disk! */ - if( pxFile->ucState & FF_BUFSTATE_WRITTEN ) - { - FF_Error_t xTempError; + FF_Error_t xTempError; - xTempError = FF_BlockWrite( pxFile->pxIOManager, FF_FileLBA( pxFile ), 1, pxFile->pucBuffer, pdFALSE ); + xTempError = FF_BlockWrite( pxFile->pxIOManager, FF_FileLBA( pxFile ), 1, pxFile->pucBuffer, pdFALSE ); - if( FF_isERR( xError ) == pdFALSE ) - { - xError = xTempError; - } + if( FF_isERR( xError ) == pdFALSE ) + { + xError = xTempError; } - - ffconfigFREE( pxFile->pucBuffer ); } + + ffconfigFREE( pxFile->pucBuffer ); } + } #endif /* if ( ffconfigOPTIMISE_UNALIGNED_ACCESS != 0 ) */ if( FF_isERR( xError ) == pdFALSE ) @@ -3204,7 +3204,7 @@ FF_Error_t FF_Close( FF_FILE * pxFile ) * * @param pxFile FF_FILE object that was created by FF_Open(). * - * @retval 0 on sucess. + * @retval 0 on success. * @retval negative if some error occurred * **/ @@ -3241,7 +3241,7 @@ FF_Error_t FF_SetEof( FF_FILE * pxFile ) * * @param pxFile FF_FILE object that was created by FF_Open(). * - * @retval 0 on sucess. + * @retval 0 on success. * @retval negative if some error occurred * **/ diff --git a/ff_format.c b/ff_format.c index 5aaffed..f235330 100644 --- a/ff_format.c +++ b/ff_format.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -25,11 +25,11 @@ */ /** - * @file ff_format.c - * @ingroup FORMAT + * @file ff_format.c + * @ingroup FORMAT * - * @defgroup FAT Fat File-System - * @brief Format a drive, given the number of sectors. + * @defgroup FAT Fat File-System + * @brief Format a drive, given the number of sectors. * **/ @@ -69,7 +69,7 @@ #define OFS_BPB_jmpBoot_24 0x000 /* uchar jmpBoot[3] "0xEB 0x00 0x90" */ #define OFS_BPB_OEMName_64 0x003 /* uchar BS_OEMName[8] "MSWIN4.1" */ -#define OFS_BPB_BytsPerSec_16 0x00B /* Only 512, 1024, 2048 or 4096 */ +#define OFS_BPB_BytesPerSec_16 0x00B /* Only 512, 1024, 2048 or 4096 */ #define OFS_BPB_SecPerClus_8 0x00D /* Only 1, 2, 4, 8, 16, 32, 64, 128 */ #define OFS_BPB_ResvdSecCnt_16 0x00E /* ulFATReservedSectors, e.g. 1 (FAT12/16) or 32 (FAT32) */ @@ -81,7 +81,7 @@ #define OFS_BPB_FATSz16_16 0x016 #define OFS_BPB_SecPerTrk_16 0x018 /* n.a. CF has no tracks */ #define OFS_BPB_NumHeads_16 0x01A /* n.a. 1 ? */ -#define OFS_BPB_HiddSec_32 0x01C /* n.a. 0 for nonparitioned volume */ +#define OFS_BPB_HiddSec_32 0x01C /* n.a. 0 for non-partitioned volume */ #define OFS_BPB_TotSec32_32 0x020 /* >= 0x10000 */ #define OFS_BPB_16_DrvNum_8 0x024 /* n.a. */ @@ -357,7 +357,7 @@ static FF_Error_t prvFormatWriteBPB( struct xFormatSet * pxSet, ( void ) memcpy( pxSet->pucSectorBuffer + OFS_BPB_jmpBoot_24, "\xEB\x00\x90" "FreeRTOS", 11 ); /* Includes OFS_BPB_OEMName_64 */ - FF_putShort( pxSet->pucSectorBuffer, OFS_BPB_BytsPerSec_16, pxSet->pxIOManager->usSectorSize ); /* 0x00B / Only 512, 1024, 2048 or 4096 */ + FF_putShort( pxSet->pucSectorBuffer, OFS_BPB_BytesPerSec_16, pxSet->pxIOManager->usSectorSize ); /* 0x00B / Only 512, 1024, 2048 or 4096 */ FF_putShort( pxSet->pucSectorBuffer, OFS_BPB_ResvdSecCnt_16, ( uint32_t ) pxSet->ulFATReservedSectors ); /* 0x00E / 1 (FAT12/16) or 32 (FAT32) */ FF_putChar( pxSet->pucSectorBuffer, OFS_BPB_NumFATs_8, 2 ); /* 0x010 / 2 recommended */ @@ -370,7 +370,7 @@ static FF_Error_t prvFormatWriteBPB( struct xFormatSet * pxSet, FF_putShort( pxSet->pucSectorBuffer, OFS_BPB_SecPerTrk_16, 0x3F ); /* 0x18 n.a. CF has no tracks */ FF_putShort( pxSet->pucSectorBuffer, OFS_BPB_NumHeads_16, 255 ); /* 0x01A / n.a. 1 ? */ - FF_putLong( pxSet->pucSectorBuffer, OFS_BPB_HiddSec_32, ( uint32_t ) pxSet->ulHiddenSectors ); /* 0x01C / n.a. 0 for nonparitioned volume */ + FF_putLong( pxSet->pucSectorBuffer, OFS_BPB_HiddSec_32, ( uint32_t ) pxSet->ulHiddenSectors ); /* 0x01C / n.a. 0 for non-partitioned volume */ FF_putChar( pxSet->pucSectorBuffer, OFS_BPB_SecPerClus_8, ( uint32_t ) pxSet->ulSectorsPerCluster ); /* 0x00D / Only 1, 2, 4, 8, 16, 32, 64, 128 */ FF_PRINTF( "FF_Format: SecCluster %u DatSec %u DataClus %u pxSet->ulClusterBeginLBA %lu\n", @@ -687,12 +687,12 @@ FF_Error_t FF_FormatDisk( FF_Disk_t * pxDisk, ( void ) memset( xSet.pucSectorBuffer, 0, xSet.pxIOManager->usSectorSize ); FF_putLong( xSet.pucSectorBuffer, OFS_FSI_32_LeadSig, 0x41615252 ); /* to validate that this is in fact an FSInfo sector. */ - /* OFS_FSI_32_Reserved1 0x004 / 480 times 0 */ + /* OFS_FSI_32_Reserved1 0x004 / 480 times 0 */ FF_putLong( xSet.pucSectorBuffer, OFS_FSI_32_StrucSig, 0x61417272 ); /* Another signature that is more localized in the */ /* sector to the location of the fields that are used. */ FF_putLong( xSet.pucSectorBuffer, OFS_FSI_32_Free_Count, xSet.ulUsableDataClusters ); /* last known free cluster count on the volume, ~0 for unknown */ FF_putLong( xSet.pucSectorBuffer, OFS_FSI_32_Nxt_Free, 2 ); /* cluster number at which the driver should start looking for free clusters */ - /* OFS_FSI_32_Reserved2 0x1F0 / zero's */ + /* OFS_FSI_32_Reserved2 0x1F0 / zero's */ FF_putLong( xSet.pucSectorBuffer, OFS_FSI_32_TrailSig, 0xAA550000 ); /* Will correct for endianness */ FF_BlockWrite( xSet.pxIOManager, xSet.ulHiddenSectors + xSet.ulFSInfo, 1, xSet.pucSectorBuffer, pdFALSE ); @@ -713,22 +713,22 @@ FF_Error_t FF_FormatDisk( FF_Disk_t * pxDisk, /*****************************/ lDirectoryBegin = lFatBeginLBA + ( int32_t ) ( 2 * xSet.ulSectorsPerFAT ); #if ( ffconfigTIME_SUPPORT != 0 ) - { - FF_SystemTime_t str_t; - uint16_t myShort; + { + FF_SystemTime_t str_t; + uint16_t myShort; - FF_GetSystemTime( &str_t ); + FF_GetSystemTime( &str_t ); - myShort = ( ( uint16_t ) ( str_t.Hour << 11U ) & 0xF800U ) | - ( ( uint16_t ) ( str_t.Minute << 5U ) & 0x07E0U ) | - ( ( uint16_t ) ( str_t.Second / 2U ) & 0x001FU ); - FF_putShort( xSet.pucSectorBuffer, 22, ( uint32_t ) myShort ); + myShort = ( ( uint16_t ) ( str_t.Hour << 11U ) & 0xF800U ) | + ( ( uint16_t ) ( str_t.Minute << 5U ) & 0x07E0U ) | + ( ( uint16_t ) ( str_t.Second / 2U ) & 0x001FU ); + FF_putShort( xSet.pucSectorBuffer, 22, ( uint32_t ) myShort ); - myShort = ( ( uint16_t ) ( ( str_t.Year - 1980 ) << 9U ) & 0xFE00U ) | - ( ( uint16_t ) ( str_t.Month << 5U ) & 0x01E0U ) | - ( ( uint16_t ) ( str_t.Day & 0x001FU ) ); - FF_putShort( xSet.pucSectorBuffer, 24, ( uint32_t ) myShort ); - } + myShort = ( ( uint16_t ) ( ( str_t.Year - 1980 ) << 9U ) & 0xFE00U ) | + ( ( uint16_t ) ( str_t.Month << 5U ) & 0x01E0U ) | + ( ( uint16_t ) ( str_t.Day & 0x001FU ) ); + FF_putShort( xSet.pucSectorBuffer, 24, ( uint32_t ) myShort ); + } #endif /* ffconfigTIME_SUPPORT */ /* Initialise and clear the root directory. */ diff --git a/ff_ioman.c b/ff_ioman.c index 31b15e0..a2d7b1c 100644 --- a/ff_ioman.c +++ b/ff_ioman.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -190,7 +190,7 @@ FF_IOManager_t * FF_CreateIOManager( FF_CreationParameters_t * pxParameters, if( pxIOManager->pvSemaphoreOpen == NULL ) { - /* Tell the user that there was not enough mmory. */ + /* Tell the user that there was not enough memory. */ xError = FF_createERR( FF_ERR_NOT_ENOUGH_MEMORY, FF_CREATEIOMAN ); } else @@ -235,7 +235,7 @@ FF_IOManager_t * FF_CreateIOManager( FF_CreationParameters_t * pxParameters, * * @param pxIOManager Pointer to an FF_IOManager_t object, as returned from FF_CreateIOManager. * - * @return FF_ERR_NONE on sucess, or a documented error code on failure. (FF_ERR_NULL_POINTER) + * @return FF_ERR_NONE on success, or a documented error code on failure. (FF_ERR_NULL_POINTER) * **/ FF_Error_t FF_DeleteIOManager( FF_IOManager_t * pxIOManager ) @@ -264,12 +264,12 @@ FF_Error_t FF_DeleteIOManager( FF_IOManager_t * pxIOManager ) } #if ( ffconfigPROTECT_FF_FOPEN_WITH_SEMAPHORE == 1 ) + { + if( pxIOManager->pvSemaphoreOpen != NULL ) { - if( pxIOManager->pvSemaphoreOpen != NULL ) - { - vSemaphoreDelete( pxIOManager->pvSemaphoreOpen ); - } + vSemaphoreDelete( pxIOManager->pvSemaphoreOpen ); } + } #endif /* Delete the event group object within the IO manager before deleting @@ -654,7 +654,7 @@ int32_t FF_BlockWrite( FF_IOManager_t * pxIOManager, if( ( slRetVal == 0ul ) && ( pxIOManager->xBlkDevice.fnpWriteBlocks != NULL ) ) { do - { /* Make sure we don't execute a NULL. */ + { /* Make sure we don't execute a NULL. */ if( ( xSemLocked == pdFALSE ) && ( ( pxIOManager->ucFlags & FF_IOMAN_BLOCK_DEVICE_IS_REENTRANT ) == pdFALSE ) ) { @@ -796,30 +796,30 @@ static FF_Error_t prvDetermineFatType( FF_IOManager_t * pxIOManager ) /* FAT 16 */ pxPartition->ucType = FF_T_FAT16; #if ( ffconfigFAT_CHECK != 0 ) - { - /* Keep bits 4..15 */ - ulFirstCluster &= 0xFFF8U; + { + /* Keep bits 4..15 */ + ulFirstCluster &= 0xFFF8U; - if( ulFirstCluster == 0xFFF8U ) + if( ulFirstCluster == 0xFFF8U ) + { + /* FAT16 entry OK. */ + xError = FF_ERR_NONE; + } + else + { + if( ( ulFirstCluster & 0xFF8U ) == 0xFF8U ) { - /* FAT16 entry OK. */ - xError = FF_ERR_NONE; + FF_PRINTF( "FAT_CHECK: FAT16 Part at %lu is probably a FAT12\n", pxIOManager->xPartition.ulFATBeginLBA ); } else { - if( ( ulFirstCluster & 0xFF8U ) == 0xFF8U ) - { - FF_PRINTF( "FAT_CHECK: FAT16 Part at %lu is probably a FAT12\n", pxIOManager->xPartition.ulFATBeginLBA ); - } - else - { - FF_PRINTF( "FAT_CHECK: FAT16 Partition has unexpected FAT data %08lX\n", - ulFirstCluster ); - } - - xError = FF_createERR( FF_ERR_IOMAN_INVALID_FORMAT, FF_DETERMINEFATTYPE ); + FF_PRINTF( "FAT_CHECK: FAT16 Partition has unexpected FAT data %08lX\n", + ulFirstCluster ); } + + xError = FF_createERR( FF_ERR_IOMAN_INVALID_FORMAT, FF_DETERMINEFATTYPE ); } + } #endif /* ffconfigFAT_CHECK */ } else @@ -1424,29 +1424,29 @@ FF_Error_t FF_Mount( FF_Disk_t * pxDisk, pxPartition = &( pxIOManager->xPartition ); #if ( ffconfigREMOVABLE_MEDIA != 0 ) - { - pxIOManager->ucFlags &= ( uint8_t ) ( ~( FF_IOMAN_DEVICE_IS_EXTRACTED ) ); - } + { + pxIOManager->ucFlags &= ( uint8_t ) ( ~( FF_IOMAN_DEVICE_IS_EXTRACTED ) ); + } #endif /* ffconfigREMOVABLE_MEDIA */ /* FF_IOMAN_InitBufferDescriptors will clear 'pxBuffers' */ memset( pxIOManager->pucCacheMem, '\0', ( size_t ) pxIOManager->usSectorSize * pxIOManager->usCacheSize ); #if ( ffconfigHASH_CACHE != 0 ) - { - memset( pxIOManager->xHashCache, '\0', sizeof( pxIOManager->xHashCache ) ); + { + memset( pxIOManager->xHashCache, '\0', sizeof( pxIOManager->xHashCache ) ); - for( i = 0; i < ffconfigHASH_CACHE_DEPTH; i++ ) - { - /* _HT_ Check why did JW put it to 100? */ - pxIOManager->xHashCache[ i ].ulMisses = 100; - } + for( i = 0; i < ffconfigHASH_CACHE_DEPTH; i++ ) + { + /* _HT_ Check why did JW put it to 100? */ + pxIOManager->xHashCache[ i ].ulMisses = 100; } + } #endif #if ( ffconfigPATH_CACHE != 0 ) - { - memset( pxPartition->pxPathCache, '\0', sizeof( pxPartition->pxPathCache ) ); - } + { + memset( pxPartition->pxPathCache, '\0', sizeof( pxPartition->pxPathCache ) ); + } #endif FF_IOMAN_InitBufferDescriptors( pxIOManager ); pxIOManager->FirstFile = 0; @@ -1528,7 +1528,7 @@ FF_Error_t FF_Mount( FF_Disk_t * pxDisk, } if( pxPartition->ulSectorsPerFAT == 0 ) - { /* FAT32 */ + { /* FAT32 */ pxPartition->ulSectorsPerFAT = FF_getLong( pxBuffer->pucBuffer, FF_FAT_32_SECTORS_PER_FAT ); pxPartition->ulRootDirCluster = FF_getLong( pxBuffer->pucBuffer, FF_FAT_ROOT_DIR_CLUSTER ); memcpy( pxPartition->pcVolumeLabel, pxBuffer->pucBuffer + FF_FAT_32_VOL_LABEL, sizeof( pxPartition->pcVolumeLabel ) - 1 ); @@ -1541,9 +1541,9 @@ FF_Error_t FF_Mount( FF_Disk_t * pxDisk, pxPartition->ulClusterBeginLBA = pxPartition->ulFATBeginLBA + ( pxPartition->ucNumFATS * pxPartition->ulSectorsPerFAT ); #if ( ffconfigWRITE_FREE_COUNT != 0 ) || ( ffconfigFSINFO_TRUSTED != 0 ) - { - pxPartition->ulFSInfoLBA = pxPartition->ulBeginLBA + FF_getShort( pxBuffer->pucBuffer, 48 ); - } + { + pxPartition->ulFSInfoLBA = pxPartition->ulBeginLBA + FF_getShort( pxBuffer->pucBuffer, 48 ); + } #endif FF_ReleaseBuffer( pxIOManager, pxBuffer ); /* Release the buffer finally! */ @@ -1594,37 +1594,37 @@ FF_Error_t FF_Mount( FF_Disk_t * pxDisk, pxPartition->ucPartitionMounted = pdTRUE; pxPartition->ulLastFreeCluster = 0; #if ( ffconfigMOUNT_FIND_FREE != 0 ) + { + FF_LockFAT( pxIOManager ); { - FF_LockFAT( pxIOManager ); - { - /* The parameter 'pdFALSE' means: do not claim the free cluster found. */ - pxPartition->ulLastFreeCluster = FF_FindFreeCluster( pxIOManager, &xError, pdFALSE ); - } - FF_UnlockFAT( pxIOManager ); + /* The parameter 'pdFALSE' means: do not claim the free cluster found. */ + pxPartition->ulLastFreeCluster = FF_FindFreeCluster( pxIOManager, &xError, pdFALSE ); + } + FF_UnlockFAT( pxIOManager ); - if( FF_isERR( xError ) ) + if( FF_isERR( xError ) ) + { + if( FF_GETERROR( xError ) == FF_ERR_IOMAN_NOT_ENOUGH_FREE_SPACE ) { - if( FF_GETERROR( xError ) == FF_ERR_IOMAN_NOT_ENOUGH_FREE_SPACE ) - { - pxPartition->ulLastFreeCluster = 0; - } - else - { - break; - } + pxPartition->ulLastFreeCluster = 0; } - - pxPartition->ulFreeClusterCount = FF_CountFreeClusters( pxIOManager, &xError ); - - if( FF_isERR( xError ) ) + else { break; } } - #else /* if ( ffconfigMOUNT_FIND_FREE != 0 ) */ + + pxPartition->ulFreeClusterCount = FF_CountFreeClusters( pxIOManager, &xError ); + + if( FF_isERR( xError ) ) { - pxPartition->ulFreeClusterCount = 0; + break; } + } + #else /* if ( ffconfigMOUNT_FIND_FREE != 0 ) */ + { + pxPartition->ulFreeClusterCount = 0; + } #endif /* ffconfigMOUNT_FIND_FREE */ } while( pdFALSE ); @@ -1728,29 +1728,29 @@ FF_Error_t FF_Unmount( FF_Disk_t * pxDisk ) pxIOManager->xPartition.ucPartitionMounted = pdFALSE; #if ( ffconfigMIRROR_FATS_UMOUNT != 0 ) + { + FF_ReleaseSemaphore( pxIOManager->pvSemaphore ); + + for( uxIndex = 0; uxIndex < pxIOManager->xPartition.ulSectorsPerFAT; uxIndex++ ) { - FF_ReleaseSemaphore( pxIOManager->pvSemaphore ); + pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFATBeginLBA + uxIndex, FF_MODE_READ ); - for( uxIndex = 0; uxIndex < pxIOManager->xPartition.ulSectorsPerFAT; uxIndex++ ) + if( !pxBuffer ) { - pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFATBeginLBA + uxIndex, FF_MODE_READ ); - - if( !pxBuffer ) - { - xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_UNMOUNT ); - break; - } - - for( y = 0; y < pxIOManager->xPartition.ucNumFATS; y++ ) - { - FF_BlockWrite( pxIOManager, - pxIOManager->xPartition.ulFATBeginLBA + ( y * pxIOManager->xPartition.ulSectorsPerFAT ) + uxIndex, 1, - pxBuffer->pucBuffer, pdFALSE ); - } + xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_UNMOUNT ); + break; } - FF_PendSemaphore( pxIOManager->pvSemaphore ); + for( y = 0; y < pxIOManager->xPartition.ucNumFATS; y++ ) + { + FF_BlockWrite( pxIOManager, + pxIOManager->xPartition.ulFATBeginLBA + ( y * pxIOManager->xPartition.ulSectorsPerFAT ) + uxIndex, 1, + pxBuffer->pucBuffer, pdFALSE ); + } } + + FF_PendSemaphore( pxIOManager->pvSemaphore ); + } #endif /* if ( ffconfigMIRROR_FATS_UMOUNT != 0 ) */ } } @@ -1819,37 +1819,37 @@ FF_Error_t FF_IncreaseFreeClusters( FF_IOManager_t * pxIOManager, } #if ( ffconfigWRITE_FREE_COUNT != 0 ) + { + /* FAT32 updates the FSINFO sector. */ + if( pxIOManager->xPartition.ucType == FF_T_FAT32 ) { - /* FAT32 updates the FSINFO sector. */ - if( pxIOManager->xPartition.ucType == FF_T_FAT32 ) + /* Find the FSINFO sector. */ + pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFSInfoLBA, FF_MODE_WRITE ); + + if( pxBuffer == NULL ) { - /* Find the FSINFO sector. */ - pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFSInfoLBA, FF_MODE_WRITE ); + xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_INCREASEFREECLUSTERS ); + } + else + { + uint32_t ulSignature1; + uint32_t ulSignature2; - if( pxBuffer == NULL ) + ulSignature1 = FF_getLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_SIGNATURE1_000 ); + ulSignature2 = FF_getLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_SIGNATURE2_484 ); + + if( ( ulSignature1 == FS_INFO_SIGNATURE1_0x41615252 ) && + ( ulSignature2 == FS_INFO_SIGNATURE2_0x61417272 ) ) { - xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_INCREASEFREECLUSTERS ); + /* FSINFO sector magic numbers we're verified. Safe to write. */ + FF_putLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_FREE_COUNT_488, pxIOManager->xPartition.ulFreeClusterCount ); + FF_putLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_FREE_CLUSTER_492, pxIOManager->xPartition.ulLastFreeCluster ); } - else - { - uint32_t ulSignature1; - uint32_t ulSignature2; - ulSignature1 = FF_getLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_SIGNATURE1_000 ); - ulSignature2 = FF_getLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_SIGNATURE2_484 ); - - if( ( ulSignature1 == FS_INFO_SIGNATURE1_0x41615252 ) && - ( ulSignature2 == FS_INFO_SIGNATURE2_0x61417272 ) ) - { - /* FSINFO sector magic numbers we're verified. Safe to write. */ - FF_putLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_FREE_COUNT_488, pxIOManager->xPartition.ulFreeClusterCount ); - FF_putLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_FREE_CLUSTER_492, pxIOManager->xPartition.ulLastFreeCluster ); - } - - xError = FF_ReleaseBuffer( pxIOManager, pxBuffer ); - } + xError = FF_ReleaseBuffer( pxIOManager, pxBuffer ); } } + } #endif /* if ( ffconfigWRITE_FREE_COUNT != 0 ) */ } while( pdFALSE ); @@ -1893,31 +1893,31 @@ FF_Error_t FF_DecreaseFreeClusters( FF_IOManager_t * pxIOManager, if( FF_isERR( xError ) == pdFALSE ) { #if ( ffconfigWRITE_FREE_COUNT != 0 ) + { + /* FAT32 update the FSINFO sector. */ + if( pxIOManager->xPartition.ucType == FF_T_FAT32 ) { - /* FAT32 update the FSINFO sector. */ - if( pxIOManager->xPartition.ucType == FF_T_FAT32 ) - { - /* Find the FSINFO sector. */ - pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFSInfoLBA, FF_MODE_WRITE ); + /* Find the FSINFO sector. */ + pxBuffer = FF_GetBuffer( pxIOManager, pxIOManager->xPartition.ulFSInfoLBA, FF_MODE_WRITE ); - if( pxBuffer == NULL ) + if( pxBuffer == NULL ) + { + xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_DECREASEFREECLUSTERS ); + } + else + { + if( ( FF_getLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_SIGNATURE1_000 ) == FS_INFO_SIGNATURE1_0x41615252 ) && + ( FF_getLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_SIGNATURE2_484 ) == FS_INFO_SIGNATURE2_0x61417272 ) ) { - xError = FF_createERR( FF_ERR_DEVICE_DRIVER_FAILED, FF_DECREASEFREECLUSTERS ); + /* FSINFO sector magic nums we're verified. Safe to write. */ + FF_putLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_FREE_COUNT_488, pxIOManager->xPartition.ulFreeClusterCount ); + FF_putLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_FREE_CLUSTER_492, pxIOManager->xPartition.ulLastFreeCluster ); } - else - { - if( ( FF_getLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_SIGNATURE1_000 ) == FS_INFO_SIGNATURE1_0x41615252 ) && - ( FF_getLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_SIGNATURE2_484 ) == FS_INFO_SIGNATURE2_0x61417272 ) ) - { - /* FSINFO sector magic nums we're verified. Safe to write. */ - FF_putLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_FREE_COUNT_488, pxIOManager->xPartition.ulFreeClusterCount ); - FF_putLong( pxBuffer->pucBuffer, FS_INFO_OFFSET_FREE_CLUSTER_492, pxIOManager->xPartition.ulLastFreeCluster ); - } - xError = FF_ReleaseBuffer( pxIOManager, pxBuffer ); - } + xError = FF_ReleaseBuffer( pxIOManager, pxBuffer ); } } + } #endif /* if ( ffconfigWRITE_FREE_COUNT != 0 ) */ } diff --git a/ff_locking.c b/ff_locking.c index cc62cc1..439bd34 100644 --- a/ff_locking.c +++ b/ff_locking.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/ff_memory.c b/ff_memory.c old mode 100755 new mode 100644 index 01d93af..0d45dcf --- a/ff_memory.c +++ b/ff_memory.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/ff_stdio.c b/ff_stdio.c index b6881a4..38b1f46 100644 --- a/ff_stdio.c +++ b/ff_stdio.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -160,22 +160,22 @@ FF_FILE * ff_fopen( const char * pcFile, stdioSET_ERRNO( prvFFErrorToErrno( xError ) ); #if ( ffconfigUSE_NOTIFY != 0 ) + { + if( ( pxStream != NULL ) && ( ( ucMode & ( FF_MODE_WRITE | FF_MODE_APPEND ) ) != 0 ) ) { - if( ( pxStream != NULL ) && ( ( ucMode & ( FF_MODE_WRITE | FF_MODE_APPEND ) ) != 0 ) ) - { - /*_RB_ Function name needs updating. */ - callFileEvents( pcFile, eFileCreate ); - } + /*_RB_ Function name needs updating. */ + callFileEvents( pcFile, eFileCreate ); } + } #endif /* ffconfigUSE_NOTIFY */ #if ( ffconfigDEV_SUPPORT != 0 ) + { + if( pxStream != NULL ) { - if( pxStream != NULL ) - { - FF_Device_Open( pcFile, pxStream ); - } + FF_Device_Open( pcFile, pxStream ); } + } #endif /* ffconfigDEV_SUPPORT */ } @@ -189,15 +189,15 @@ int ff_fclose( FF_FILE * pxStream ) int iReturn, ff_errno; #if ( ffconfigDEV_SUPPORT != 0 ) + { + /* Currently device support is in an experimental state. It will allow + * to create virtual files. The I/O data to those files will be redirected + * to their connected "drivers". */ + if( pxStream != NULL ) { - /* Currently device support is in an experimental state. It will allow - * to create virtual files. The I/O data to those files will be redirected - * to their connected "drivers". */ - if( pxStream != NULL ) - { - FF_Device_Close( pxStream ); - } + FF_Device_Close( pxStream ); } + } #endif xError = FF_Close( pxStream ); @@ -880,12 +880,12 @@ int ff_remove( const char * pcPath ) ff_errno = prvFFErrorToErrno( xError ); #if ffconfigUSE_NOTIFY + { + if( FF_isERR( xError ) == pdFALSE ) { - if( FF_isERR( xError ) == pdFALSE ) - { - callFileEvents( pcPath, eFileRemove ); - } + callFileEvents( pcPath, eFileRemove ); } + } #endif if( ff_errno == 0 ) @@ -930,25 +930,25 @@ int ff_rename( const char * pcOldName, else { #if ( ffconfigHAS_CWD != 0 ) - { - xSize = strlen( xHandlers[ 0 ].pcPath ) + 1; - pcOldCopy = ( char * ) ffconfigMALLOC( xSize ); + { + xSize = strlen( xHandlers[ 0 ].pcPath ) + 1; + pcOldCopy = ( char * ) ffconfigMALLOC( xSize ); - if( pcOldCopy == NULL ) - { - /* Could not allocate space to store a file name. */ - ff_errno = pdFREERTOS_ERRNO_ENOMEM; - xError = FF_createERR( FF_ERR_NOT_ENOUGH_MEMORY, FF_MOVE ); - } - else - { - /* The function prvABSPath() returns a pointer to the task - * storage space. Rename needs to call it twice and therefore the - * path must be stored before it gets overwritten. */ - memcpy( pcOldCopy, xHandlers[ 0 ].pcPath, xSize ); - xHandlers[ 0 ].pcPath = pcOldCopy; - } + if( pcOldCopy == NULL ) + { + /* Could not allocate space to store a file name. */ + ff_errno = pdFREERTOS_ERRNO_ENOMEM; + xError = FF_createERR( FF_ERR_NOT_ENOUGH_MEMORY, FF_MOVE ); + } + else + { + /* The function prvABSPath() returns a pointer to the task + * storage space. Rename needs to call it twice and therefore the + * path must be stored before it gets overwritten. */ + memcpy( pcOldCopy, xHandlers[ 0 ].pcPath, xSize ); + xHandlers[ 0 ].pcPath = pcOldCopy; } + } #endif /* ffconfigHAS_CWD != 0 */ #if ( ffconfigHAS_CWD != 0 ) @@ -976,19 +976,19 @@ int ff_rename( const char * pcOldName, ff_errno = prvFFErrorToErrno( xError ); #if ffconfigUSE_NOTIFY + { + if( FF_isERR( xError ) == pdFALSE ) { - if( FF_isERR( xError ) == pdFALSE ) - { - callFileEvents( pcNewName, eFileChange ); - } + callFileEvents( pcNewName, eFileChange ); } + } #endif } #if ( ffconfigHAS_CWD != 0 ) - { - ffconfigFREE( pcOldCopy ); - } + { + ffconfigFREE( pcOldCopy ); + } #endif } } @@ -1119,14 +1119,14 @@ int ff_stat( const char * pcName, } #if ( ffconfigDEV_SUPPORT != 0 ) - { - BaseType_t bIsDeviceDir = xCheckDevicePath( pcFileName ); + { + BaseType_t bIsDeviceDir = xCheckDevicePath( pcFileName ); - if( bIsDeviceDir != pdFALSE ) - { - FF_Device_GetDirEnt( xHandler.pcPath, &( xDirEntry ) ); - } + if( bIsDeviceDir != pdFALSE ) + { + FF_Device_GetDirEnt( xHandler.pcPath, &( xDirEntry ) ); } + } #endif /* Despite the warning output by MSVC - it is not possible to get here @@ -1136,11 +1136,11 @@ int ff_stat( const char * pcName, pxStatBuffer->st_dev = ( uint16_t ) xHandler.xFSIndex; #if ( ffconfigTIME_SUPPORT == 1 ) - { - pxStatBuffer->ff_atime = prvFileTime( &( xDirEntry.xAccessedTime ) ); - pxStatBuffer->ff_mtime = prvFileTime( &( xDirEntry.xModifiedTime ) ); - pxStatBuffer->ff_ctime = prvFileTime( &( xDirEntry.xCreateTime ) ); - } + { + pxStatBuffer->ff_atime = prvFileTime( &( xDirEntry.xAccessedTime ) ); + pxStatBuffer->ff_mtime = prvFileTime( &( xDirEntry.xModifiedTime ) ); + pxStatBuffer->ff_ctime = prvFileTime( &( xDirEntry.xCreateTime ) ); + } #endif } @@ -1309,9 +1309,9 @@ int ff_findfirst( const char * pcPath, if( iReturn == 0 ) { #if ( ffconfigDEV_SUPPORT != 0 ) - { - pxFindData->bIsDeviceDir = xCheckDevicePath( pcDirectory ); - } + { + pxFindData->bIsDeviceDir = xCheckDevicePath( pcDirectory ); + } #endif if( iIsRootDir != pdFALSE ) @@ -1378,12 +1378,12 @@ int ff_findnext( FF_FindData_t * pxFindData ) } #if ( ffconfigDEV_SUPPORT != 0 ) + { + if( pxFindData->bIsDeviceDir != pdFALSE ) { - if( pxFindData->bIsDeviceDir != pdFALSE ) - { - FF_Device_GetDirEnt( pxFindData->xDirectoryHandler.pcPath, &( pxFindData->xDirectoryEntry ) ); - } + FF_Device_GetDirEnt( pxFindData->xDirectoryHandler.pcPath, &( pxFindData->xDirectoryEntry ) ); } + } #endif } @@ -1399,11 +1399,11 @@ int ff_findnext( FF_FindData_t * pxFindData ) /* This is a directory "..". Clear the flag for DOT_2. */ pxFindData->xDirectoryHandler.u.bits.bAddDotEntries &= stdioDIR_ENTRY_DOT_1; #if ( ffconfigTIME_SUPPORT != 0 ) - { - /* The dot-entries do not have a proper time stamp, add - * it here. */ - xSetTime = pdTRUE; - } + { + /* The dot-entries do not have a proper time stamp, add + * it here. */ + xSetTime = pdTRUE; + } #endif /* ffconfigTIME_SUPPORT */ } else if( pxFindData->xDirectoryEntry.pcFileName[ 1 ] == '\0' ) @@ -1411,9 +1411,9 @@ int ff_findnext( FF_FindData_t * pxFindData ) /* This is a directory ".". Clear the flag for DOT_1. */ pxFindData->xDirectoryHandler.u.bits.bAddDotEntries &= stdioDIR_ENTRY_DOT_2; #if ( ffconfigTIME_SUPPORT != 0 ) - { - xSetTime = pdTRUE; - } + { + xSetTime = pdTRUE; + } #endif /* ffconfigTIME_SUPPORT */ } } @@ -1466,9 +1466,9 @@ int ff_findnext( FF_FindData_t * pxFindData ) pxFindData->xDirectoryEntry.ucAttrib = FF_FAT_ATTR_READONLY | FF_FAT_ATTR_DIR; pxFindData->xDirectoryEntry.ulFileSize = stdioDOT_ENTRY_FILE_SIZE; #if ( ffconfigTIME_SUPPORT != 0 ) - { - xSetTime = pdTRUE; - } + { + xSetTime = pdTRUE; + } #endif /* ffconfigTIME_SUPPORT */ xError = FF_ERR_NONE; @@ -1477,31 +1477,31 @@ int ff_findnext( FF_FindData_t * pxFindData ) } #if ( ffconfigTIME_SUPPORT != 0 ) + { + if( xSetTime != pdFALSE ) { - if( xSetTime != pdFALSE ) - { - FF_TimeStruct_t xTimeStruct; - time_t xSeconds; - - xSeconds = FreeRTOS_time( NULL ); - FreeRTOS_gmtime_r( &xSeconds, &xTimeStruct ); - - pxFindData->xDirectoryEntry.xCreateTime.Year = ( uint16_t ) ( xTimeStruct.tm_year + 1900 ); /* Year (e.g. 2009). */ - pxFindData->xDirectoryEntry.xCreateTime.Month = ( uint16_t ) ( xTimeStruct.tm_mon + 1 ); /* Month (e.g. 1 = Jan, 12 = Dec). */ - pxFindData->xDirectoryEntry.xCreateTime.Day = ( uint16_t ) xTimeStruct.tm_mday; /* Day (1 - 31). */ - pxFindData->xDirectoryEntry.xCreateTime.Hour = ( uint16_t ) xTimeStruct.tm_hour; /* Hour (0 - 23). */ - pxFindData->xDirectoryEntry.xCreateTime.Minute = ( uint16_t ) xTimeStruct.tm_min; /* Min (0 - 59). */ - pxFindData->xDirectoryEntry.xCreateTime.Second = ( uint16_t ) xTimeStruct.tm_sec; /* Second (0 - 59). */ - /* Date and Time Modified. */ - memcpy( &( pxFindData->xDirectoryEntry.xModifiedTime ), - &( pxFindData->xDirectoryEntry.xCreateTime ), - sizeof( pxFindData->xDirectoryEntry.xModifiedTime ) ); - /* Date of Last Access. */ - memcpy( &( pxFindData->xDirectoryEntry.xAccessedTime ), - &( pxFindData->xDirectoryEntry.xCreateTime ), - sizeof( pxFindData->xDirectoryEntry.xAccessedTime ) ); - } + FF_TimeStruct_t xTimeStruct; + time_t xSeconds; + + xSeconds = FreeRTOS_time( NULL ); + FreeRTOS_gmtime_r( &xSeconds, &xTimeStruct ); + + pxFindData->xDirectoryEntry.xCreateTime.Year = ( uint16_t ) ( xTimeStruct.tm_year + 1900 ); /* Year (e.g. 2009). */ + pxFindData->xDirectoryEntry.xCreateTime.Month = ( uint16_t ) ( xTimeStruct.tm_mon + 1 ); /* Month (e.g. 1 = Jan, 12 = Dec). */ + pxFindData->xDirectoryEntry.xCreateTime.Day = ( uint16_t ) xTimeStruct.tm_mday; /* Day (1 - 31). */ + pxFindData->xDirectoryEntry.xCreateTime.Hour = ( uint16_t ) xTimeStruct.tm_hour; /* Hour (0 - 23). */ + pxFindData->xDirectoryEntry.xCreateTime.Minute = ( uint16_t ) xTimeStruct.tm_min; /* Min (0 - 59). */ + pxFindData->xDirectoryEntry.xCreateTime.Second = ( uint16_t ) xTimeStruct.tm_sec; /* Second (0 - 59). */ + /* Date and Time Modified. */ + memcpy( &( pxFindData->xDirectoryEntry.xModifiedTime ), + &( pxFindData->xDirectoryEntry.xCreateTime ), + sizeof( pxFindData->xDirectoryEntry.xModifiedTime ) ); + /* Date of Last Access. */ + memcpy( &( pxFindData->xDirectoryEntry.xAccessedTime ), + &( pxFindData->xDirectoryEntry.xCreateTime ), + sizeof( pxFindData->xDirectoryEntry.xAccessedTime ) ); } + } #endif /* ffconfigTIME_SUPPORT */ if( FF_GETERROR( xError ) == FF_ERR_DIR_END_OF_DIR ) diff --git a/ff_string.c b/ff_string.c index 1e8ca00..6660eb1 100644 --- a/ff_string.c +++ b/ff_string.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/ff_sys.c b/ff_sys.c old mode 100755 new mode 100644 index 62406c0..632b711 --- a/ff_sys.c +++ b/ff_sys.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -228,9 +228,10 @@ int FF_FS_Find( const char * pcPath, for( xUseIndex = 1; xUseIndex < file_systems.xFileSystemCount; xUseIndex++, pxSubSystem++ ) { + /* System "/ram" should not match with "/ram/etc". */ if( ( uxPathLength >= ( size_t ) pxSubSystem->xPathlen ) && ( memcmp( pxSubSystem->pcPath, pcPath, ( size_t ) pxSubSystem->xPathlen ) == 0 ) && - ( ( pcPath[ pxSubSystem->xPathlen ] == '\0' ) || ( pcPath[ pxSubSystem->xPathlen ] == '/' ) ) ) /* System "/ram" should not match with "/ramc/etc". */ + ( ( pcPath[ pxSubSystem->xPathlen ] == '\0' ) || ( pcPath[ pxSubSystem->xPathlen ] == '/' ) ) ) { if( pcPath[ pxSubSystem->xPathlen ] == '\0' ) { diff --git a/ff_time.c b/ff_time.c index 3a39b77..7cce19a 100644 --- a/ff_time.c +++ b/ff_time.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -96,7 +96,7 @@ /* The first weekday in 'FF_TimeStruct_t' is Sunday. */ #define WEEK_DAY_SUNDAY 0 - #define WEEK_DAY_MONNDAY 1 + #define WEEK_DAY_MONDAY 1 #define WEEK_DAY_TUESDAY 2 #define WEEK_DAY_WEDNESDAY 3 #define WEEK_DAY_THURSDAY 4 diff --git a/include/FreeRTOSFATConfigDefaults.h b/include/FreeRTOSFATConfigDefaults.h index 21e29ae..8bc4836 100644 --- a/include/FreeRTOSFATConfigDefaults.h +++ b/include/FreeRTOSFATConfigDefaults.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -508,7 +508,7 @@ #endif #ifndef FF_NOSTRCASECMP - /* When zero, the function 'strcasecmp()' will be dfined. */ + /* When zero, the function 'strcasecmp()' will be defined. */ #define FF_NOSTRCASECMP 0 #endif diff --git a/include/FreeRTOS_errno_FAT.h b/include/FreeRTOS_errno_FAT.h old mode 100755 new mode 100644 index fd88f74..8bf3000 --- a/include/FreeRTOS_errno_FAT.h +++ b/include/FreeRTOS_errno_FAT.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/include/ff_crc.h b/include/ff_crc.h old mode 100755 new mode 100644 index bbcb2dc..57c65f5 --- a/include/ff_crc.h +++ b/include/ff_crc.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/include/ff_devices.h b/include/ff_devices.h old mode 100755 new mode 100644 index 854370e..6147030 --- a/include/ff_devices.h +++ b/include/ff_devices.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -35,7 +35,7 @@ #endif #ifdef __cplusplus - extern "C" { + extern "C" { #endif #define FF_DEV_NO_DEV 0 @@ -68,7 +68,7 @@ FF_DirEnt_t * pxDirEnt ); #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif #endif /* FF_DEVICES_H */ diff --git a/include/ff_dir.h b/include/ff_dir.h old mode 100755 new mode 100644 index cffa5e6..7169f7d --- a/include/ff_dir.h +++ b/include/ff_dir.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/include/ff_error.h b/include/ff_error.h index ee0bdb6..18ff2f1 100644 --- a/include/ff_error.h +++ b/include/ff_error.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/include/ff_fat.h b/include/ff_fat.h old mode 100755 new mode 100644 index 4be06df..54a1996 --- a/include/ff_fat.h +++ b/include/ff_fat.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -159,9 +159,9 @@ static portINLINE void FF_InitFATBuffers( FF_FATBuffers_t * pxFATBuffers, #endif pxFATBuffers->ucMode = ucMode; /* FF_MODE_READ/WRITE */ #if ffconfigFAT_USES_STAT - { - fatStat.initCount++; - } + { + fatStat.initCount++; + } #endif } diff --git a/include/ff_fatdef.h b/include/ff_fatdef.h old mode 100755 new mode 100644 index c4651c9..cd816b0 --- a/include/ff_fatdef.h +++ b/include/ff_fatdef.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/include/ff_file.h b/include/ff_file.h old mode 100755 new mode 100644 index 6678e25..d70e915 --- a/include/ff_file.h +++ b/include/ff_file.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/include/ff_format.h b/include/ff_format.h old mode 100755 new mode 100644 index 72165c3..0a4b5d9 --- a/include/ff_format.h +++ b/include/ff_format.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -35,7 +35,7 @@ #define _FF_FORMAT_H_ #ifdef __cplusplus - extern "C" { + extern "C" { #endif @@ -81,7 +81,7 @@ /* Private : */ #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif #endif /* ifndef _FF_FORMAT_H_ */ diff --git a/include/ff_headers.h b/include/ff_headers.h old mode 100755 new mode 100644 index 058b1b7..b5e3873 --- a/include/ff_headers.h +++ b/include/ff_headers.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -30,7 +30,7 @@ #include #ifdef __cplusplus - extern "C" { + extern "C" { #endif #include "FreeRTOS.h" @@ -56,7 +56,7 @@ #include "ff_old_config_defines.h" #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif #endif /* ifndef PLUS_FAT_H */ diff --git a/include/ff_ioman.h b/include/ff_ioman.h old mode 100755 new mode 100644 index f1ef8c8..103b279 --- a/include/ff_ioman.h +++ b/include/ff_ioman.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -33,7 +33,7 @@ #define _FF_IOMAN_H_ #ifdef __cplusplus - extern "C" { + extern "C" { #endif #include /* Use of malloc() */ @@ -411,7 +411,7 @@ void FF_IOMAN_InitBufferDescriptors( FF_IOManager_t * pxIOManager ); #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif #endif /* ifndef _FF_IOMAN_H_ */ diff --git a/include/ff_locking.h b/include/ff_locking.h old mode 100755 new mode 100644 index f79965f..3dd26a4 --- a/include/ff_locking.h +++ b/include/ff_locking.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -33,7 +33,7 @@ #define _FF_LOCKING_H_ #ifdef __cplusplus - extern "C" { + extern "C" { #endif #include @@ -88,7 +88,7 @@ uint32_t aBits ); #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif #endif /* _FF_LOCKING_H_ */ diff --git a/include/ff_memory.h b/include/ff_memory.h old mode 100755 new mode 100644 index 87ef02e..59047ae --- a/include/ff_memory.h +++ b/include/ff_memory.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/include/ff_old_config_defines.h b/include/ff_old_config_defines.h old mode 100755 new mode 100644 index 6b17996..a477e27 --- a/include/ff_old_config_defines.h +++ b/include/ff_old_config_defines.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -27,7 +27,7 @@ /* * As of 15/3/2015 all +FAT configuration items changed their prefix, * e.g. FF_LITTLE_ENDIAN has become ffconfigLITTLE_ENDIAN - * This tempoary header file checks for the presence old configuration items + * This temporary header file checks for the presence old configuration items * and issue a compiler error if any is defined. */ diff --git a/include/ff_stdio.h b/include/ff_stdio.h old mode 100755 new mode 100644 index dda075b..9dd3be9 --- a/include/ff_stdio.h +++ b/include/ff_stdio.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -50,7 +50,7 @@ #endif #ifdef __cplusplus - extern "C" { + extern "C" { #endif /* Error return from some functions. */ @@ -402,7 +402,7 @@ eFileAction_t aAction ); #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif #endif /* FF_STDIO_H */ diff --git a/include/ff_string.h b/include/ff_string.h old mode 100755 new mode 100644 index 21a068d..ebda437 --- a/include/ff_string.h +++ b/include/ff_string.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/include/ff_sys.h b/include/ff_sys.h old mode 100755 new mode 100644 index 129575c..752ad9d --- a/include/ff_sys.h +++ b/include/ff_sys.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -49,7 +49,7 @@ #define FF_SYS_H #ifdef __cplusplus - extern "C" { + extern "C" { #endif typedef struct FILE_SUB_SYSTEM @@ -106,7 +106,7 @@ /* * Internally used by ff_stdio: - * The ff_dir_handler helps to iterate through a mounte directory + * The ff_dir_handler helps to iterate through a mounted directory * * FF_FS_Find() will find a ff_dir_handler for a given path */ @@ -127,7 +127,7 @@ int FF_FS_Count( void ); #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif #endif /* FF_SYS_H */ diff --git a/include/ff_time.h b/include/ff_time.h old mode 100755 new mode 100644 index c34eac8..3533f58 --- a/include/ff_time.h +++ b/include/ff_time.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in diff --git a/portable/ATSAM4E/ff_sddisk.c b/portable/ATSAM4E/ff_sddisk.c index d5b5cd8..3f53938 100644 --- a/portable/ATSAM4E/ff_sddisk.c +++ b/portable/ATSAM4E/ff_sddisk.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -69,7 +69,7 @@ HSMCI_IER_OVRE | \ HSMCI_IER_DTOE | \ HSMCI_IER_DCRCE | \ - HSMCI_IER_TXBUFE | \ + HSMCI_IER_TXBUFF | \ HSMCI_IER_RXBUFF | \ HSMCI_IER_XFRDONE @@ -328,18 +328,18 @@ FF_Disk_t * FF_SDDiskInit( const char * pcName ) FF_Disk_t * pxDisk; #if ( ffconfigSDIO_DRIVER_USES_INTERRUPT != 0 ) + { + NVIC_SetPriority( HSMCI_IRQn, configHSMCI_INTERRUPT_PRIORITY ); + NVIC_EnableIRQ( HSMCI_IRQn ); + #if ( sdMSMCI_USE_SEMAPHORE != 0 ) { - NVIC_SetPriority( HSMCI_IRQn, configHSMCI_INTERRUPT_PRIORITY ); - NVIC_EnableIRQ( HSMCI_IRQn ); - #if ( sdMSMCI_USE_SEMAPHORE != 0 ) - { - if( xSDSemaphore == NULL ) - { - xSDSemaphore = xSemaphoreCreateBinary(); - } - } - #endif /* sdMSMCI_USE_SEMAPHORE */ + if( xSDSemaphore == NULL ) + { + xSDSemaphore = xSemaphoreCreateBinary(); + } } + #endif /* sdMSMCI_USE_SEMAPHORE */ + } #endif /* ffconfigSDIO_DRIVER_USES_INTERRUPT */ xSDCardStatus = prvSDMMCInit( 0 ); @@ -627,7 +627,7 @@ BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pxDisk ) FF_PRINTF( "TotalSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulTotalSectors ); FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); FF_PRINTF( "Size %8u MB\n", ( unsigned ) ulTotalSizeMB ); - FF_PRINTF( "FreeSize %8u MB ( %d perc free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); + FF_PRINTF( "FreeSize %8u MB ( %d percent free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); } return xReturn; @@ -743,19 +743,19 @@ static BaseType_t prvSDMMCInit( BaseType_t xDriveNumber ) HSMCI->HSMCI_IDR = ulSR; ulSDInterruptStatus |= ulSR; #if ( sdMSMCI_USE_SEMAPHORE != 0 ) + { + if( xSDSemaphore != NULL ) { - if( xSDSemaphore != NULL ) - { - xSemaphoreGiveFromISR( xSDSemaphore, &xSwitchRequired ); - } + xSemaphoreGiveFromISR( xSDSemaphore, &xSwitchRequired ); } + } #else + { + if( xSDTaskHandle != NULL ) { - if( xSDTaskHandle != NULL ) - { - vTaskNotifyGiveFromISR( xSDTaskHandle, ( BaseType_t * ) &xSwitchRequired ); - } + vTaskNotifyGiveFromISR( xSDTaskHandle, ( BaseType_t * ) &xSwitchRequired ); } + } #endif /* if ( sdMSMCI_USE_SEMAPHORE != 0 ) */ if( xSwitchRequired != pdFALSE ) @@ -772,9 +772,9 @@ static BaseType_t prvSDMMCInit( BaseType_t xDriveNumber ) iWaitForWriting = iForWriting != 0; #if ( sdMSMCI_USE_SEMAPHORE == 0 ) - { - xSDTaskHandle = xTaskGetCurrentTaskHandle(); - } + { + xSDTaskHandle = xTaskGetCurrentTaskHandle(); + } #endif ulSDInterruptStatus = 0; HSMCI->HSMCI_IER = sdHSMCI_INTERRUPT_FLAGS; @@ -791,9 +791,9 @@ static BaseType_t prvSDMMCInit( BaseType_t xDriveNumber ) void vMCIEventReadyFunction() { #if ( sdMSMCI_USE_SEMAPHORE == 0 ) - { - xSDTaskHandle = NULL; - } + { + xSDTaskHandle = NULL; + } #endif ulSDInterruptStatus = 0; HSMCI->HSMCI_IDR = sdHSMCI_INTERRUPT_FLAGS; @@ -823,19 +823,19 @@ static BaseType_t prvSDMMCInit( BaseType_t xDriveNumber ) { /* The timeout has not been reached yet, block on the semaphore. */ #if ( sdMSMCI_USE_SEMAPHORE != 0 ) + { + if( ( ulSDInterruptStatus & ulMask ) == 0ul ) { - if( ( ulSDInterruptStatus & ulMask ) == 0ul ) - { - xSemaphoreTake( xSDSemaphore, xDMARemainingTime ); - } + xSemaphoreTake( xSDSemaphore, xDMARemainingTime ); } + } #else + { + if( ( ulSDInterruptStatus & ulMask ) == 0ul ) { - if( ( ulSDInterruptStatus & ulMask ) == 0ul ) - { - ulTaskNotifyTake( pdFALSE, xDMARemainingTime ); - } + ulTaskNotifyTake( pdFALSE, xDMARemainingTime ); } + } #endif /* if ( sdMSMCI_USE_SEMAPHORE != 0 ) */ if( xTaskCheckForTimeOut( &xDMATimeOut, &xDMARemainingTime ) != pdFALSE ) diff --git a/portable/ATSAM4E/ff_sddisk_r.c b/portable/ATSAM4E/ff_sddisk_r.c index f75367d..00c41b8 100644 --- a/portable/ATSAM4E/ff_sddisk_r.c +++ b/portable/ATSAM4E/ff_sddisk_r.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -471,7 +471,7 @@ BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pxDisk ) FF_PRINTF( "TotalSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulTotalSectors ); FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); FF_PRINTF( "Size %8u MB\n", ( unsigned ) ulTotalSizeMB ); - FF_PRINTF( "FreeSize %8u MB ( %d perc free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); + FF_PRINTF( "FreeSize %8u MB ( %d percent free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); } return xReturn; diff --git a/portable/STM32F4xx/ff_sddisk.c b/portable/STM32F4xx/ff_sddisk.c index 6b84ac3..ac48ee2 100644 --- a/portable/STM32F4xx/ff_sddisk.c +++ b/portable/STM32F4xx/ff_sddisk.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -196,57 +196,57 @@ static int32_t prvFFRead( uint8_t * pucBuffer, ullReadAddr = 512ull * ( uint64_t ) ulSectorNumber; #if ( SDIO_USES_DMA == 0 ) - { - sd_result = HAL_SD_ReadBlocks( &xSDHandle, ( uint32_t * ) pucBuffer, ullReadAddr, 512ul, ulSectorCount ); - } + { + sd_result = HAL_SD_ReadBlocks( &xSDHandle, ( uint32_t * ) pucBuffer, ullReadAddr, 512ul, ulSectorCount ); + } #else + { + if( ( ( ( size_t ) pucBuffer ) & ( sizeof( size_t ) - 1 ) ) == 0 ) { - if( ( ( ( size_t ) pucBuffer ) & ( sizeof( size_t ) - 1 ) ) == 0 ) - { - /* The buffer is word-aligned, call DMA read directly. */ - sd_result = HAL_SD_ReadBlocks_DMA( &xSDHandle, ( uint32_t * ) pucBuffer, ullReadAddr, 512ul, ulSectorCount ); + /* The buffer is word-aligned, call DMA read directly. */ + sd_result = HAL_SD_ReadBlocks_DMA( &xSDHandle, ( uint32_t * ) pucBuffer, ullReadAddr, 512ul, ulSectorCount ); - if( sd_result == SD_OK ) - { - sd_result = HAL_SD_CheckReadOperation( &xSDHandle, sdMAX_TIME_TICKS ); - } + if( sd_result == SD_OK ) + { + sd_result = HAL_SD_CheckReadOperation( &xSDHandle, sdMAX_TIME_TICKS ); } - else + } + else + { + uint32_t ulSector; + uint8_t * pucDMABuffer = ffconfigMALLOC( 512ul ); + + /* The buffer is NOT word-aligned, copy first to an aligned buffer. */ + if( pucDMABuffer != NULL ) { - uint32_t ulSector; - uint8_t * pucDMABuffer = ffconfigMALLOC( 512ul ); + sd_result = SD_OK; - /* The buffer is NOT word-aligned, copy first to an aligned buffer. */ - if( pucDMABuffer != NULL ) + for( ulSector = 0; ulSector < ulSectorCount; ulSector++ ) { - sd_result = SD_OK; + ullReadAddr = 512ull * ( ( uint64_t ) ulSectorNumber + ( uint64_t ) ulSector ); + sd_result = HAL_SD_ReadBlocks_DMA( &xSDHandle, ( uint32_t * ) pucDMABuffer, ullReadAddr, 512ul, 1 ); - for( ulSector = 0; ulSector < ulSectorCount; ulSector++ ) + if( sd_result == SD_OK ) { - ullReadAddr = 512ull * ( ( uint64_t ) ulSectorNumber + ( uint64_t ) ulSector ); - sd_result = HAL_SD_ReadBlocks_DMA( &xSDHandle, ( uint32_t * ) pucDMABuffer, ullReadAddr, 512ul, 1 ); + sd_result = HAL_SD_CheckReadOperation( &xSDHandle, sdMAX_TIME_TICKS ); - if( sd_result == SD_OK ) + if( sd_result != SD_OK ) { - sd_result = HAL_SD_CheckReadOperation( &xSDHandle, sdMAX_TIME_TICKS ); - - if( sd_result != SD_OK ) - { - break; - } - - memcpy( pucBuffer + 512ul * ulSector, pucDMABuffer, 512ul ); + break; } - } - ffconfigFREE( pucDMABuffer ); - } - else - { - sd_result = SD_INVALID_PARAMETER; + memcpy( pucBuffer + 512ul * ulSector, pucDMABuffer, 512ul ); + } } + + ffconfigFREE( pucDMABuffer ); + } + else + { + sd_result = SD_INVALID_PARAMETER; } } + } #endif /* SDIO_USES_DMA */ if( sd_result == SD_OK ) @@ -266,7 +266,7 @@ static int32_t prvFFRead( uint8_t * pucBuffer, if( pxDisk->xStatus.bIsInitialised != pdFALSE ) { - FF_PRINTF( "prvFFRead: warning: %u + %u > %u\n", ( unsigned ) ulSectorNumber, ( unsigned ) ulSectorCount, ( unsinged ) pxDisk->ulNumberOfSectors ); + FF_PRINTF( "prvFFRead: warning: %u + %u > %u\n", ( unsigned ) ulSectorNumber, ( unsigned ) ulSectorCount, ( unsigned ) pxDisk->ulNumberOfSectors ); } } @@ -293,57 +293,57 @@ static int32_t prvFFWrite( uint8_t * pucBuffer, ullWriteAddr = 512ull * ulSectorNumber; #if ( SDIO_USES_DMA == 0 ) - { - sd_result = HAL_SD_WriteBlocks( &xSDHandle, ( uint32_t * ) pucBuffer, ullWriteAddr, 512ul, ulSectorCount ); - } + { + sd_result = HAL_SD_WriteBlocks( &xSDHandle, ( uint32_t * ) pucBuffer, ullWriteAddr, 512ul, ulSectorCount ); + } #else + { + if( ( ( ( size_t ) pucBuffer ) & ( sizeof( size_t ) - 1 ) ) == 0 ) { - if( ( ( ( size_t ) pucBuffer ) & ( sizeof( size_t ) - 1 ) ) == 0 ) - { - /* The buffer is word-aligned, call DMA reawrite directly. */ - sd_result = HAL_SD_WriteBlocks_DMA( &xSDHandle, ( uint32_t * ) pucBuffer, ullWriteAddr, 512ul, ulSectorCount ); + /* The buffer is word-aligned, call DMA re-write directly. */ + sd_result = HAL_SD_WriteBlocks_DMA( &xSDHandle, ( uint32_t * ) pucBuffer, ullWriteAddr, 512ul, ulSectorCount ); - if( sd_result == SD_OK ) - { - sd_result = HAL_SD_CheckWriteOperation( &xSDHandle, sdMAX_TIME_TICKS ); - } + if( sd_result == SD_OK ) + { + sd_result = HAL_SD_CheckWriteOperation( &xSDHandle, sdMAX_TIME_TICKS ); } - else + } + else + { + uint32_t ulSector; + uint8_t * pucDMABuffer = ffconfigMALLOC( 512ul ); + + /* The buffer is NOT word-aligned, read to an aligned buffer and then + * copy the data to the user provided buffer. */ + if( pucDMABuffer != NULL ) { - uint32_t ulSector; - uint8_t * pucDMABuffer = ffconfigMALLOC( 512ul ); + sd_result = SD_OK; - /* The buffer is NOT word-aligned, read to an aligned buffer and then - * copy the data to the user provided buffer. */ - if( pucDMABuffer != NULL ) + for( ulSector = 0; ulSector < ulSectorCount; ulSector++ ) { - sd_result = SD_OK; + memcpy( pucDMABuffer, pucBuffer + 512ul * ulSector, 512ul ); + ullWriteAddr = 512ull * ( ulSectorNumber + ulSector ); + sd_result = HAL_SD_WriteBlocks_DMA( &xSDHandle, ( uint32_t * ) pucDMABuffer, ullWriteAddr, 512ul, 1 ); - for( ulSector = 0; ulSector < ulSectorCount; ulSector++ ) + if( sd_result == SD_OK ) { - memcpy( pucDMABuffer, pucBuffer + 512ul * ulSector, 512ul ); - ullWriteAddr = 512ull * ( ulSectorNumber + ulSector ); - sd_result = HAL_SD_WriteBlocks_DMA( &xSDHandle, ( uint32_t * ) pucDMABuffer, ullWriteAddr, 512ul, 1 ); + sd_result = HAL_SD_CheckWriteOperation( &xSDHandle, sdMAX_TIME_TICKS ); - if( sd_result == SD_OK ) + if( sd_result != SD_OK ) { - sd_result = HAL_SD_CheckWriteOperation( &xSDHandle, sdMAX_TIME_TICKS ); - - if( sd_result != SD_OK ) - { - break; - } + break; } } - - ffconfigFREE( pucDMABuffer ); - } - else - { - sd_result = SD_INVALID_PARAMETER; } + + ffconfigFREE( pucDMABuffer ); + } + else + { + sd_result = SD_INVALID_PARAMETER; } } + } #endif /* SDIO_USES_DMA */ if( sd_result == SD_OK ) @@ -398,13 +398,13 @@ static void vGPIO_SD_Init( SD_HandleTypeDef * xSDHandle ) */ __HAL_RCC_GPIOC_CLK_ENABLE(); #if ( BUS_4BITS != 0 ) - { - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; - } + { + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; + } #else - { - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_12; - } + { + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_12; + } #endif GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; @@ -723,7 +723,7 @@ BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pxDisk ) FF_PRINTF( "TotalSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulTotalSectors ); FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); FF_PRINTF( "Size %8u MB\n", ( unsigned ) ulTotalSizeMB ); - FF_PRINTF( "FreeSize %8u MB ( %d perc free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); + FF_PRINTF( "FreeSize %8u MB ( %d percent free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); } return xReturn; @@ -747,15 +747,15 @@ static void prvSDIO_SD_Init( void ) xSDHandle.Init.ClockDiv = 32; #if ( SDIO_USES_DMA != 0 ) - { - xSDHandle.EventSetupFunction = prvEventSetupFunction; - xSDHandle.EventWaitFunction = prvEventWaitFunction; - } + { + xSDHandle.EventSetupFunction = prvEventSetupFunction; + xSDHandle.EventWaitFunction = prvEventWaitFunction; + } #else - { - xSDHandle.EventSetupFunction = NULL; - xSDHandle.EventWaitFunction = NULL; - } + { + xSDHandle.EventSetupFunction = NULL; + xSDHandle.EventWaitFunction = NULL; + } #endif __HAL_RCC_SDIO_CLK_ENABLE(); } @@ -840,9 +840,9 @@ static BaseType_t prvSDMMCInit( BaseType_t xDriveNumber ) vGPIO_SD_Init( &xSDHandle ); #if ( SDIO_USES_DMA != 0 ) - { - prvSDIO_DMA_Init(); - } + { + prvSDIO_DMA_Init(); + } #endif int SD_state = SD_OK; @@ -860,20 +860,20 @@ static BaseType_t prvSDMMCInit( BaseType_t xDriveNumber ) /* Initialise the SDIO device and read the card parameters. */ SD_state = HAL_SD_Init( &xSDHandle, &xSDCardInfo ); #if ( BUS_4BITS != 0 ) + { + if( SD_state == SD_OK ) { - if( SD_state == SD_OK ) - { - HAL_SD_ErrorTypedef rc; + HAL_SD_ErrorTypedef rc; - xSDHandle.Init.BusWide = SDIO_BUS_WIDE_4B; - rc = HAL_SD_WideBusOperation_Config( &xSDHandle, SDIO_BUS_WIDE_4B ); + xSDHandle.Init.BusWide = SDIO_BUS_WIDE_4B; + rc = HAL_SD_WideBusOperation_Config( &xSDHandle, SDIO_BUS_WIDE_4B ); - if( rc != SD_OK ) - { - FF_PRINTF( "HAL_SD_WideBus: %d: %s\n", rc, prvSDCodePrintable( ( uint32_t ) rc ) ); - } + if( rc != SD_OK ) + { + FF_PRINTF( "HAL_SD_WideBus: %d: %s\n", rc, prvSDCodePrintable( ( uint32_t ) rc ) ); } } + } #endif /* if ( BUS_4BITS != 0 ) */ FF_PRINTF( "HAL_SD_Init: %d: %s type: %s Capacity: %u MB\n", SD_state, diff --git a/portable/STM32F4xx/stm32f4xx_hal_sd.c b/portable/STM32F4xx/stm32f4xx_hal_sd.c old mode 100755 new mode 100644 index b444502..dc4ff82 --- a/portable/STM32F4xx/stm32f4xx_hal_sd.c +++ b/portable/STM32F4xx/stm32f4xx_hal_sd.c @@ -371,13 +371,13 @@ tmpinit.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE; tmpinit.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; #if ( BUS_4BITS != 0 ) - { - tmpinit.BusWide = SDIO_BUS_WIDE_4B; - } + { + tmpinit.BusWide = SDIO_BUS_WIDE_4B; + } #else - { - tmpinit.BusWide = SDIO_BUS_WIDE_1B; - } + { + tmpinit.BusWide = SDIO_BUS_WIDE_1B; + } #endif tmpinit.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; tmpinit.ClockDiv = SDIO_INIT_CLK_DIV; @@ -685,7 +685,7 @@ SDIO_CmdInitTypeDef sdmmc_cmdinitstructure; /*SDIO_DataInitTypeDef sdmmc_datainitstructure; */ HAL_SD_ErrorTypedef errorstate = SD_OK; - uint32_t totalnumberofbytes, bytesRemaining; + uint32_t totalNumberOfBytes, bytesRemaining; uint32_t tmpreg; uint32_t last_sta; uint32_t * tempbuff = ( uint32_t * ) pWriteBuffer; @@ -750,8 +750,8 @@ ulHasHWFlowControl = ( hsd->Instance->CLKCR & SDIO_HARDWARE_FLOW_CONTROL_ENABLE ) != 0; /* Set total number of bytes to write */ - totalnumberofbytes = NumberOfBlocks * BlockSize; - bytesRemaining = 4 * ( ( totalnumberofbytes + 3 ) / 4 ); + totalNumberOfBytes = NumberOfBlocks * BlockSize; + bytesRemaining = 4 * ( ( totalNumberOfBytes + 3 ) / 4 ); /* Configure the SD DPSM (Data Path State Machine) */ @@ -847,7 +847,7 @@ if( ( ( last_sta & SDIO_FLAG_TXUNDERR ) != 0 ) || ( bytesRemaining != 0 ) ) { - FF_PRINTF( "TX underflow %lu < %lu\n", bytesRemaining, totalnumberofbytes ); + FF_PRINTF( "TX underflow %lu < %lu\n", bytesRemaining, totalNumberOfBytes ); } /* Send stop transmission command in case of multiblock write */ @@ -1771,7 +1771,7 @@ /* Byte 14 */ tmp = ( uint8_t ) ( ( hsd->CSD[ 3 ] & 0x0000FF00 ) >> 8 ); - pCardInfo->SD_csd.FileFormatGrouop = ( tmp & 0x80 ) >> 7; + pCardInfo->SD_csd.FileFormatGroup = ( tmp & 0x80 ) >> 7; pCardInfo->SD_csd.CopyFlag = ( tmp & 0x40 ) >> 6; pCardInfo->SD_csd.PermWrProtect = ( tmp & 0x20 ) >> 5; pCardInfo->SD_csd.TempWrProtect = ( tmp & 0x10 ) >> 4; diff --git a/portable/STM32F4xx/stm32f4xx_hal_sd.h b/portable/STM32F4xx/stm32f4xx_hal_sd.h old mode 100755 new mode 100644 index 71950be..f181740 --- a/portable/STM32F4xx/stm32f4xx_hal_sd.h +++ b/portable/STM32F4xx/stm32f4xx_hal_sd.h @@ -40,7 +40,7 @@ #define __STM32F4xx_HAL_SD_H #ifdef __cplusplus - extern "C" { + extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -147,7 +147,7 @@ __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */ __IO uint8_t Reserved3; /*!< Reserved */ __IO uint8_t ContentProtectAppli; /*!< Content protection application */ - __IO uint8_t FileFormatGrouop; /*!< File format group */ + __IO uint8_t FileFormatGroup; /*!< File format group */ __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */ __IO uint8_t PermWrProtect; /*!< Permanent write protection */ __IO uint8_t TempWrProtect; /*!< Temporary write protection */ @@ -837,7 +837,7 @@ */ #ifdef __cplusplus - } +} #endif #endif /* __STM32F4xx_HAL_SD_H */ diff --git a/portable/STM32F4xx/stm32f4xx_ll_sdmmc.h b/portable/STM32F4xx/stm32f4xx_ll_sdmmc.h index ae08fb9..15d2a7b 100644 --- a/portable/STM32F4xx/stm32f4xx_ll_sdmmc.h +++ b/portable/STM32F4xx/stm32f4xx_ll_sdmmc.h @@ -40,7 +40,7 @@ #define __STM32F4xx_LL_SDMMC_H #ifdef __cplusplus - extern "C" { + extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -301,7 +301,7 @@ * @} */ -/** @defgroup SDIO_Data_Length Data Lenght +/** @defgroup SDIO_Data_Length Data Length * @{ */ #define IS_SDIO_DATA_LENGTH( LENGTH ) ( ( LENGTH ) <= 0x01FFFFFF ) @@ -949,7 +949,7 @@ */ #ifdef __cplusplus - } +} #endif #endif /* __STM32F4xx_LL_SDMMC_H */ diff --git a/portable/STM32F7xx/ff_sddisk.c b/portable/STM32F7xx/ff_sddisk.c index 71f47d8..eb2aad3 100644 --- a/portable/STM32F7xx/ff_sddisk.c +++ b/portable/STM32F7xx/ff_sddisk.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -188,7 +188,7 @@ static BaseType_t prvSDMMCInit( BaseType_t xDriveNumber ); static void prvCacheInvalidate( uint32_t * pulAddress, int32_t ulSize ); #else - /* No cache: empty macro's. */ +/* No cache: empty macro's. */ #define prvCacheClean( pulAddress, ulSize ) do {} while( 0 ) #define prvCacheInvalidate( pulAddress, ulSize ) do {} while( 0 ) #endif @@ -237,7 +237,7 @@ static __attribute__( ( section( ".first_data" ) ) ) uint8_t pucDMABuffer[ 512 ] /*-----------------------------------------------------------*/ #ifdef STM32F7xx - static BaseType_t xIsCachable( uint32_t ulAddress ) + static BaseType_t xIsCacheable( uint32_t ulAddress ) { BaseType_t xReturn = pdFALSE; @@ -254,7 +254,7 @@ static __attribute__( ( section( ".first_data" ) ) ) uint8_t pucDMABuffer[ 512 ] return xReturn; } #else /* ifdef STM32F7xx */ - static BaseType_t xIsCachable( uint32_t ulAddress ) + static BaseType_t xIsCacheable( uint32_t ulAddress ) { return pdFALSE; } @@ -281,58 +281,58 @@ static int32_t prvFFRead( uint8_t * pucBuffer, ullReadAddr = ( uint64_t ) 512U * ( uint64_t ) ulSectorNumber; #if ( SDIO_USES_DMA == 0 ) - { - sd_result = HAL_SD_ReadBlocks( &xSDHandle, ( uint32_t * ) pucBuffer, ullReadAddr, ulSectorCount ); - } + { + sd_result = HAL_SD_ReadBlocks( &xSDHandle, ( uint32_t * ) pucBuffer, ullReadAddr, ulSectorCount ); + } #else + { + /* Is the buffer aligned with a cache line? */ + if( ( ( ( size_t ) pucBuffer ) & CACHE_LINE_BITS ) == 0U ) { - /* Is the buffer aligned with a cache line? */ - if( ( ( ( size_t ) pucBuffer ) & CACHE_LINE_BITS ) == 0U ) + /* The buffer is word-aligned, call DMA read directly. */ + sd_result = HAL_SD_ReadBlocks_DMA( &xSDHandle, ( uint32_t * ) pucBuffer, ullReadAddr, ulSectorCount ); + + if( sd_result == SD_OK ) { - /* The buffer is word-aligned, call DMA read directly. */ - sd_result = HAL_SD_ReadBlocks_DMA( &xSDHandle, ( uint32_t * ) pucBuffer, ullReadAddr, ulSectorCount ); + sd_result = HAL_SD_CheckReadOperation( &xSDHandle, sdMAX_TIME_TICKS ); - if( sd_result == SD_OK ) + if( xIsCacheable( ( uint32_t ) pucBuffer ) != pdFALSE ) { - sd_result = HAL_SD_CheckReadOperation( &xSDHandle, sdMAX_TIME_TICKS ); - - if( xIsCachable( ( uint32_t ) pucBuffer ) != pdFALSE ) - { - prvCacheInvalidate( ( uint32_t * ) pucBuffer, 512U * ulSectorCount ); - } + prvCacheInvalidate( ( uint32_t * ) pucBuffer, 512U * ulSectorCount ); } } - else - { - uint32_t ulSector; + } + else + { + uint32_t ulSector; + + /* The buffer is NOT word-aligned, copy first to an aligned buffer. */ + sd_result = SD_OK; - /* The buffer is NOT word-aligned, copy first to an aligned buffer. */ - sd_result = SD_OK; + for( ulSector = 0; ulSector < ulSectorCount; ulSector++ ) + { + ullReadAddr = ( uint64_t ) 512U * ( ( uint64_t ) ulSectorNumber + ( uint64_t ) ulSector ); + sd_result = HAL_SD_ReadBlocks_DMA( &xSDHandle, ( uint32_t * ) pucDMABuffer, ullReadAddr, 1U ); - for( ulSector = 0; ulSector < ulSectorCount; ulSector++ ) + if( sd_result == SD_OK ) { - ullReadAddr = ( uint64_t ) 512U * ( ( uint64_t ) ulSectorNumber + ( uint64_t ) ulSector ); - sd_result = HAL_SD_ReadBlocks_DMA( &xSDHandle, ( uint32_t * ) pucDMABuffer, ullReadAddr, 1U ); + sd_result = HAL_SD_CheckReadOperation( &xSDHandle, sdMAX_TIME_TICKS ); - if( sd_result == SD_OK ) + if( sd_result != SD_OK ) { - sd_result = HAL_SD_CheckReadOperation( &xSDHandle, sdMAX_TIME_TICKS ); - - if( sd_result != SD_OK ) - { - break; - } - - if( xIsCachable( ( uint32_t ) pucDMABuffer ) != pdFALSE ) - { - prvCacheInvalidate( ( uint32_t * ) pucDMABuffer, 512U ); - } + break; + } - memcpy( pucBuffer + 512U * ulSector, pucDMABuffer, 512U ); + if( xIsCacheable( ( uint32_t ) pucDMABuffer ) != pdFALSE ) + { + prvCacheInvalidate( ( uint32_t * ) pucDMABuffer, 512U ); } + + memcpy( pucBuffer + 512U * ulSector, pucDMABuffer, 512U ); } } } + } #endif /* SDIO_USES_DMA */ if( sd_result == SD_OK ) @@ -379,59 +379,59 @@ static int32_t prvFFWrite( uint8_t * pucBuffer, ullWriteAddr = ( uint64_t ) 512U * ( uint64_t ) ulSectorNumber; #if ( SDIO_USES_DMA == 0 ) - { - sd_result = HAL_SD_WriteBlocks( &xSDHandle, ( uint32_t * ) pucBuffer, ullWriteAddr, ulSectorCount ); - } + { + sd_result = HAL_SD_WriteBlocks( &xSDHandle, ( uint32_t * ) pucBuffer, ullWriteAddr, ulSectorCount ); + } #else + { + /* Is the buffer aligned with a cache line? */ + if( ( ( ( uintptr_t ) pucBuffer ) & CACHE_LINE_BITS ) == 0U ) { - /* Is the buffer aligned with a cache line? */ - if( ( ( ( uintptr_t ) pucBuffer ) & CACHE_LINE_BITS ) == 0U ) + /* The buffer is word-aligned, call DMA write directly. */ + if( xIsCacheable( ( uint32_t ) pucBuffer ) != pdFALSE ) { - /* The buffer is word-aligned, call DMA write directly. */ - if( xIsCachable( ( uint32_t ) pucBuffer ) != pdFALSE ) - { - prvCacheClean( ( uint32_t * ) pucBuffer, 512U * ulSectorCount ); - } + prvCacheClean( ( uint32_t * ) pucBuffer, 512U * ulSectorCount ); + } - sd_result = HAL_SD_WriteBlocks_DMA( &xSDHandle, ( uint32_t * ) pucBuffer, ullWriteAddr, ulSectorCount ); + sd_result = HAL_SD_WriteBlocks_DMA( &xSDHandle, ( uint32_t * ) pucBuffer, ullWriteAddr, ulSectorCount ); - if( sd_result == SD_OK ) - { - sd_result = HAL_SD_CheckWriteOperation( &xSDHandle, sdMAX_TIME_TICKS ); - } - } - else + if( sd_result == SD_OK ) { - uint32_t ulSector; + sd_result = HAL_SD_CheckWriteOperation( &xSDHandle, sdMAX_TIME_TICKS ); + } + } + else + { + uint32_t ulSector; + + /* The buffer is NOT word-aligned, read to an aligned buffer and then + * copy the data to the user provided buffer. */ + sd_result = SD_OK; - /* The buffer is NOT word-aligned, read to an aligned buffer and then - * copy the data to the user provided buffer. */ - sd_result = SD_OK; + for( ulSector = 0; ulSector < ulSectorCount; ulSector++ ) + { + memcpy( pucDMABuffer, pucBuffer + 512U * ulSector, 512U ); + ullWriteAddr = ( uint64_t ) 512U * ( ulSectorNumber + ulSector ); - for( ulSector = 0; ulSector < ulSectorCount; ulSector++ ) + if( xIsCacheable( ( uint32_t ) pucDMABuffer ) != pdFALSE ) { - memcpy( pucDMABuffer, pucBuffer + 512U * ulSector, 512U ); - ullWriteAddr = ( uint64_t ) 512U * ( ulSectorNumber + ulSector ); + prvCacheClean( ( uint32_t * ) pucDMABuffer, 512U ); + } - if( xIsCachable( ( uint32_t ) pucDMABuffer ) != pdFALSE ) - { - prvCacheClean( ( uint32_t * ) pucDMABuffer, 512U ); - } + sd_result = HAL_SD_WriteBlocks_DMA( &xSDHandle, ( uint32_t * ) pucDMABuffer, ullWriteAddr, 1 ); - sd_result = HAL_SD_WriteBlocks_DMA( &xSDHandle, ( uint32_t * ) pucDMABuffer, ullWriteAddr, 1 ); + if( sd_result == SD_OK ) + { + sd_result = HAL_SD_CheckWriteOperation( &xSDHandle, sdMAX_TIME_TICKS ); - if( sd_result == SD_OK ) + if( sd_result != SD_OK ) { - sd_result = HAL_SD_CheckWriteOperation( &xSDHandle, sdMAX_TIME_TICKS ); - - if( sd_result != SD_OK ) - { - break; - } + break; } } } } + } #endif /* SDIO_USES_DMA */ if( sd_result == SD_OK ) @@ -514,13 +514,13 @@ static void vGPIO_SD_Init( SD_HandleTypeDef * xSDHandle ) /* GPIOC configuration */ #if ( BUS_4BITS != 0 ) - { - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; - } + { + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; + } #else - { - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_12; - } + { + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_12; + } #endif GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; @@ -842,7 +842,7 @@ BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pxDisk ) FF_PRINTF( "TotalSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulTotalSectors ); FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); FF_PRINTF( "Size %8u MB\n", ( unsigned ) ulTotalSizeMB ); - FF_PRINTF( "FreeSize %8u MB ( %d perc free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); + FF_PRINTF( "FreeSize %8u MB ( %d percent free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); } return xReturn; @@ -866,15 +866,15 @@ static void prvSDIO_SD_Init( void ) xSDHandle.Init.ClockDiv = 0U; #if ( SDIO_USES_DMA != 0 ) - { - xSDHandle.EventSetupFunction = prvEventSetupFunction; - xSDHandle.EventWaitFunction = prvEventWaitFunction; - } + { + xSDHandle.EventSetupFunction = prvEventSetupFunction; + xSDHandle.EventWaitFunction = prvEventWaitFunction; + } #else - { - xSDHandle.EventSetupFunction = NULL; - xSDHandle.EventWaitFunction = NULL; - } + { + xSDHandle.EventSetupFunction = NULL; + xSDHandle.EventWaitFunction = NULL; + } #endif __HAL_RCC_SDIO_CLK_ENABLE(); } @@ -959,9 +959,9 @@ static BaseType_t prvSDMMCInit( BaseType_t xDriveNumber ) vGPIO_SD_Init( &xSDHandle ); #if ( SDIO_USES_DMA != 0 ) - { - prvSDIO_DMA_Init(); - } + { + prvSDIO_DMA_Init(); + } #endif int SD_state = SD_OK; @@ -979,20 +979,20 @@ static BaseType_t prvSDMMCInit( BaseType_t xDriveNumber ) /* Initialise the SDIO device and read the card parameters. */ SD_state = HAL_SD_Init( &xSDHandle, &xSDCardInfo ); #if ( BUS_4BITS != 0 ) + { + if( SD_state == SD_OK ) { - if( SD_state == SD_OK ) - { - HAL_SD_ErrorTypedef rc; + HAL_SD_ErrorTypedef rc; - xSDHandle.Init.BusWide = SDIO_BUS_WIDE_4B; - rc = HAL_SD_WideBusOperation_Config( &xSDHandle, SDIO_BUS_WIDE_4B ); + xSDHandle.Init.BusWide = SDIO_BUS_WIDE_4B; + rc = HAL_SD_WideBusOperation_Config( &xSDHandle, SDIO_BUS_WIDE_4B ); - if( rc != SD_OK ) - { - FF_PRINTF( "HAL_SD_WideBus: %d: %s\n", rc, prvSDCodePrintable( ( uint32_t ) rc ) ); - } + if( rc != SD_OK ) + { + FF_PRINTF( "HAL_SD_WideBus: %d: %s\n", rc, prvSDCodePrintable( ( uint32_t ) rc ) ); } } + } #endif /* if ( BUS_4BITS != 0 ) */ FF_PRINTF( "HAL_SD_Init: %d: %s type: %s Capacity: %u MB\n", SD_state, prvSDCodePrintable( ( uint32_t ) SD_state ), diff --git a/portable/STM32F7xx/stm32f7xx_hal_sd.c b/portable/STM32F7xx/stm32f7xx_hal_sd.c old mode 100755 new mode 100644 index e382363..f3038b2 --- a/portable/STM32F7xx/stm32f7xx_hal_sd.c +++ b/portable/STM32F7xx/stm32f7xx_hal_sd.c @@ -461,15 +461,15 @@ tmpinit.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE; tmpinit.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; #if ( BUS_4BITS != 0 ) - { - #warning Four bits - tmpinit.BusWide = SDIO_BUS_WIDE_4B; - } + { + #warning Four bits + tmpinit.BusWide = SDIO_BUS_WIDE_4B; + } #else - { - #warning One bit - tmpinit.BusWide = SDIO_BUS_WIDE_1B; - } + { + #warning One bit + tmpinit.BusWide = SDIO_BUS_WIDE_1B; + } #endif tmpinit.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; tmpinit.ClockDiv = SDIO_INIT_CLK_DIV; @@ -768,7 +768,7 @@ SDIO_CmdInitTypeDef sdmmc_cmdinitstructure; /*SDIO_DataInitTypeDef sdmmc_datainitstructure; */ HAL_SD_ErrorTypedef errorstate = SD_OK; - uint32_t totalnumberofbytes, bytesRemaining; + uint32_t totalNumberOfBytes, bytesRemaining; uint32_t tmpreg; uint32_t last_sta; uint32_t * tempbuff = ( uint32_t * ) pWriteBuffer; @@ -833,8 +833,8 @@ ulHasHWFlowControl = ( hsd->Instance->CLKCR & SDIO_HARDWARE_FLOW_CONTROL_ENABLE ) != 0; /* Set total number of bytes to write */ - totalnumberofbytes = NumberOfBlocks * BlockSize; - bytesRemaining = 4 * ( ( totalnumberofbytes + 3 ) / 4 ); + totalNumberOfBytes = NumberOfBlocks * BlockSize; + bytesRemaining = 4 * ( ( totalNumberOfBytes + 3 ) / 4 ); /* Configure the SD DPSM (Data Path State Machine) */ @@ -930,7 +930,7 @@ if( ( ( last_sta & SDIO_FLAG_TXUNDERR ) != 0 ) || ( bytesRemaining != 0 ) ) { - FF_PRINTF( "TX underflow %lu < %lu\n", bytesRemaining, totalnumberofbytes ); + FF_PRINTF( "TX underflow %lu < %lu\n", bytesRemaining, totalNumberOfBytes ); } /* Send stop transmission command in case of multiblock write */ @@ -1829,7 +1829,7 @@ /* Byte 14 */ tmp = ( uint8_t ) ( ( hsd->CSD[ 3 ] & 0x0000FF00 ) >> 8 ); - pCardInfo->SD_csd.FileFormatGrouop = ( tmp & 0x80 ) >> 7; + pCardInfo->SD_csd.FileFormatGroup = ( tmp & 0x80 ) >> 7; pCardInfo->SD_csd.CopyFlag = ( tmp & 0x40 ) >> 6; pCardInfo->SD_csd.PermWrProtect = ( tmp & 0x20 ) >> 5; pCardInfo->SD_csd.TempWrProtect = ( tmp & 0x10 ) >> 4; @@ -2212,7 +2212,7 @@ sdmmc_datainitstructure.DPSM = SDIO_DPSM_ENABLE; SDIO_DataConfig( hsd->Instance, &sdmmc_datainitstructure ); - /* Send ACMD13 (SD_APP_STAUS) with argument as card's RCA */ + /* Send ACMD13 (SD_APP_STATUS) with argument as card's RCA */ sdmmc_cmdinitstructure.Argument = 0; sdmmc_cmdinitstructure.CmdIndex = SD_CMD_SD_APP_STATUS; SDIO_SendCommand( hsd->Instance, &sdmmc_cmdinitstructure ); diff --git a/portable/STM32F7xx/stm32f7xx_hal_sd.h b/portable/STM32F7xx/stm32f7xx_hal_sd.h old mode 100755 new mode 100644 index aa61dd1..5624a0e --- a/portable/STM32F7xx/stm32f7xx_hal_sd.h +++ b/portable/STM32F7xx/stm32f7xx_hal_sd.h @@ -40,7 +40,7 @@ #define __STM32F7xx_HAL_SD_H #ifdef __cplusplus - extern "C" { + extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -148,7 +148,7 @@ __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */ __IO uint8_t Reserved3; /*!< Reserved */ __IO uint8_t ContentProtectAppli; /*!< Content protection application */ - __IO uint8_t FileFormatGrouop; /*!< File format group */ + __IO uint8_t FileFormatGroup; /*!< File format group */ __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */ __IO uint8_t PermWrProtect; /*!< Permanent write protection */ __IO uint8_t TempWrProtect; /*!< Temporary write protection */ @@ -818,7 +818,7 @@ */ #ifdef __cplusplus - } +} #endif diff --git a/portable/Zynq.2019.3/ff_sddisk.c b/portable/Zynq.2019.3/ff_sddisk.c index da96a95..91ead9e 100644 --- a/portable/Zynq.2019.3/ff_sddisk.c +++ b/portable/Zynq.2019.3/ff_sddisk.c @@ -469,16 +469,16 @@ FF_Disk_t * FF_SDDiskInitWithSettings( const char * pcName, } #if ( ffconfigSDIO_DRIVER_USES_INTERRUPT != 0 ) + { + for( iIndex = 0; iIndex < ARRAY_SIZE( xSDSemaphores ); iIndex++ ) { - for( iIndex = 0; iIndex < ARRAY_SIZE( xSDSemaphores ); iIndex++ ) + if( xSDSemaphores[ iIndex ] == NULL ) { - if( xSDSemaphores[ iIndex ] == NULL ) - { - xSDSemaphores[ iIndex ] = xSemaphoreCreateBinary(); - configASSERT( xSDSemaphores[ iIndex ] != NULL ); - } + xSDSemaphores[ iIndex ] = xSemaphoreCreateBinary(); + configASSERT( xSDSemaphores[ iIndex ] != NULL ); } } + } #endif /* if ( ffconfigSDIO_DRIVER_USES_INTERRUPT != 0 ) */ if( sd_disk_status != XST_SUCCESS ) @@ -777,7 +777,7 @@ BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pxDisk ) FF_PRINTF( "DataSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulDataSectors ); FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); FF_PRINTF( "Size %8u MB\n", ( unsigned ) ulTotalSizeMB ); - FF_PRINTF( "FreeSize %8u MB ( %d perc free )\n", ( unsigned ) ulFreeSizeMB, ( int ) iPercentageFree ); + FF_PRINTF( "FreeSize %8u MB ( %d percent free )\n", ( unsigned ) ulFreeSizeMB, ( int ) iPercentageFree ); FF_PRINTF( "BeginLBA %8u\n", ( unsigned ) pxIOManager->xPartition.ulBeginLBA ); FF_PRINTF( "FATBeginLBA %8u\n", ( unsigned ) pxIOManager->xPartition.ulFATBeginLBA ); } @@ -846,9 +846,9 @@ static int vSDMMC_Init( int iDriveNumber ) } #if ( ffconfigSDIO_DRIVER_USES_INTERRUPT != 0 ) - { - vInstallInterrupt(); - } + { + vInstallInterrupt(); + } #endif /* ffconfigSDIO_DRIVER_USES_INTERRUPT */ iReturnCode = XSdPs_CardInitialize( pxSDCardInstance ); diff --git a/portable/Zynq.2019.3/xsdps.c b/portable/Zynq.2019.3/xsdps.c index ac36a91..7e88da3 100644 --- a/portable/Zynq.2019.3/xsdps.c +++ b/portable/Zynq.2019.3/xsdps.c @@ -55,7 +55,7 @@ * 2.5 sg 07/09/15 Added SD 3.0 features * kvn 07/15/15 Modified the code according to MISRAC-2012. * 2.6 sk 10/12/15 Added support for SD card v1.0 CR# 840601. - * 2.7 sk 11/24/15 Considered the slot type befoe checking CD/WP pins. + * 2.7 sk 11/24/15 Considered the slot type before checking CD/WP pins. * sk 12/10/15 Added support for MMC cards. * sk 02/16/16 Corrected the Tuning logic. * sk 03/01/16 Removed Bus Width check for eMMC. CR# 938311. @@ -1217,7 +1217,7 @@ static s32 XSdPs_IdentifyCard( XSdPs * InstancePtr ) } /* Host High Capacity support & High voltage window */ - /* Midn you, for an SD-card this command should fail. */ + /* Mind you, for an SD-card this command should fail. */ Status = XSdPs_CmdTransfer( InstancePtr, CMD1, XSDPS_ACMD41_HCS | XSDPS_CMD1_HIGH_VOL, 0U ); @@ -1523,7 +1523,7 @@ s32 XSdPs_CmdTransfer( XSdPs * InstancePtr, #if ( ffconfigSDIO_DRIVER_USES_INTERRUPT != 0 ) /* Clear the status bits and tell which status bits - * are ex[ected in the next transaction. */ + * are expected in the next transaction. */ XSdPs_ClearInterrupt( InstancePtr, ulMask ); #endif XSdPs_WriteReg( InstancePtr->Config.BaseAddress, XSDPS_XFER_MODE_OFFSET, diff --git a/portable/Zynq.2019.3/xsdps.h b/portable/Zynq.2019.3/xsdps.h index 52befdb..a2cd46c 100644 --- a/portable/Zynq.2019.3/xsdps.h +++ b/portable/Zynq.2019.3/xsdps.h @@ -42,7 +42,7 @@ * those with response only (using only command line) or * response + data (using command and data lines). * Only one command can be sent at a time. During a data transfer however, - * when dsta lines are in use, certain commands (which use only the command + * when data lines are in use, certain commands (which use only the command * line) can be sent, most often to obtain status. * This driver does not support multi card slots at present. * @@ -114,7 +114,7 @@ * 2.5 sg 07/09/15 Added SD 3.0 features * kvn 07/15/15 Modified the code according to MISRAC-2012. * 2.6 sk 10/12/15 Added support for SD card v1.0 CR# 840601. - * 2.7 sk 11/24/15 Considered the slot type befoe checking CD/WP pins. + * 2.7 sk 11/24/15 Considered the slot type before checking CD/WP pins. * sk 12/10/15 Added support for MMC cards. * 01/08/16 Added workaround for issue in auto tuning mode * of SDR50, SDR104 and HS200. @@ -157,7 +157,7 @@ #define SDPS_H_ #ifdef __cplusplus - extern "C" { + extern "C" { #endif #include "xil_printf.h" @@ -323,7 +323,7 @@ u32 UNSTUFF_BITS( u32 * ulResponse, int iFirst, int iSize ); #ifdef __cplusplus - } +} #endif #endif /* SDPS_H_ */ diff --git a/portable/Zynq.2019.3/xsdps_hw.h b/portable/Zynq.2019.3/xsdps_hw.h index 06bc55a..626d67b 100644 --- a/portable/Zynq.2019.3/xsdps_hw.h +++ b/portable/Zynq.2019.3/xsdps_hw.h @@ -70,7 +70,7 @@ #define SD_HW_H_ #ifdef __cplusplus - extern "C" { + extern "C" { #endif /***************************** Include Files *********************************/ @@ -1346,7 +1346,7 @@ /************************** Variable Definitions *****************************/ #ifdef __cplusplus - } +} #endif #endif /* SD_HW_H_ */ diff --git a/portable/Zynq.2019.3/xsdps_options.c b/portable/Zynq.2019.3/xsdps_options.c index f30d990..cb21345 100644 --- a/portable/Zynq.2019.3/xsdps_options.c +++ b/portable/Zynq.2019.3/xsdps_options.c @@ -761,7 +761,7 @@ s32 XSdPs_Change_BusSpeed( XSdPs * InstancePtr ) * @return None * * @note This API will change clock frequency to the value less than - * or equal to the given value using the permissible dividors. + * or equal to the given value using the permissible dividers. * ******************************************************************************/ s32 XSdPs_Change_ClkFreq( XSdPs * InstancePtr, @@ -1634,7 +1634,7 @@ RETURN_PATH: return Status; XSdPs_WriteReg( XPS_SYS_CTRL_BASEADDR, SD_OTAPDLY, TapDelay ); } #endif /* if EL1_NONSECURE && defined( __aarch64__ ) */ - #ifdef XPAR_PSU_SD_0_DEVICE_ID + #ifdef XPAR_PSU_SD_0_DEVICE_ID } #endif #endif /* versal */ diff --git a/portable/Zynq/ff_sddisk.c b/portable/Zynq/ff_sddisk.c index 1f18016..2d0dedf 100644 --- a/portable/Zynq/ff_sddisk.c +++ b/portable/Zynq/ff_sddisk.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -409,16 +409,16 @@ FF_Disk_t * FF_SDDiskInit( const char * pcName ) pxSDCardInstance = &( pxCacheMem->xSDCardInstance ); #if ( ffconfigSDIO_DRIVER_USES_INTERRUPT != 0 ) + { + for( iIndex = 0; iIndex < ARRAY_SIZE( xSDSemaphores ); iIndex++ ) { - for( iIndex = 0; iIndex < ARRAY_SIZE( xSDSemaphores ); iIndex++ ) + if( xSDSemaphores[ iIndex ] == NULL ) { - if( xSDSemaphores[ iIndex ] == NULL ) - { - xSDSemaphores[ iIndex ] = xSemaphoreCreateBinary(); - configASSERT( xSDSemaphores[ iIndex ] != NULL ); - } + xSDSemaphores[ iIndex ] = xSemaphoreCreateBinary(); + configASSERT( xSDSemaphores[ iIndex ] != NULL ); } } + } #endif /* if ( ffconfigSDIO_DRIVER_USES_INTERRUPT != 0 ) */ vSDMMC_Init( 0 ); @@ -685,7 +685,7 @@ BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pxDisk ) FF_PRINTF( "DataSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulDataSectors ); FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); FF_PRINTF( "Size %8u MB\n", ( unsigned ) ulTotalSizeMB ); - FF_PRINTF( "FreeSize %8u MB ( %d perc free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); + FF_PRINTF( "FreeSize %8u MB ( %d percent free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); FF_PRINTF( "BeginLBA %8u\n", ( unsigned ) pxIOManager->xPartition.ulBeginLBA ); FF_PRINTF( "FATBeginLBA %8u\n", ( unsigned ) pxIOManager->xPartition.ulFATBeginLBA ); } @@ -754,9 +754,9 @@ static int vSDMMC_Init( int iDriveNumber ) } #if ( ffconfigSDIO_DRIVER_USES_INTERRUPT != 0 ) - { - vInstallInterrupt(); - } + { + vInstallInterrupt(); + } #endif /* ffconfigSDIO_DRIVER_USES_INTERRUPT */ iReturnCode = XSdPs_CardInitialize( pxSDCardInstance ); diff --git a/portable/Zynq/xsdps.c b/portable/Zynq/xsdps.c old mode 100755 new mode 100644 diff --git a/portable/Zynq/xsdps.h b/portable/Zynq/xsdps.h old mode 100755 new mode 100644 index 1fa3021..42c375e --- a/portable/Zynq/xsdps.h +++ b/portable/Zynq/xsdps.h @@ -48,11 +48,11 @@ * those with response only (using only command line) or * response + data (using command and data lines). * Only one command can be sent at a time. During a data transfer however, - * when dsta lines are in use, certain commands (which use only the command + * when data lines are in use, certain commands (which use only the command * line) can be sent, most often to obtain status. * This driver does not support multi card slots at present. * - * Intialization: + * Initialization: * This includes initialization on the host controller side to select * clock frequency, bus power and default transfer related parameters. * The default voltage is 3.3V. @@ -80,7 +80,7 @@ * * There is no example for using SD driver without file system at present. * However, the driver can be used without the file system. The glue layer - * in filesytem can be used as reference for the same. The block count + * in file system can be used as reference for the same. The block count * passed to the read/write function in one call is limited by the ADMA2 * descriptor table and hence care will have to be taken to call read/write * API's in a loop for large file sizes. @@ -130,7 +130,7 @@ #define SDPS_H_ #ifdef __cplusplus - extern "C" { + extern "C" { #endif #include "xstatus.h" @@ -233,7 +233,7 @@ u32 Wait ); #ifdef __cplusplus - } +} #endif #endif /* SD_H_ */ diff --git a/portable/Zynq/xsdps_g.c b/portable/Zynq/xsdps_g.c old mode 100755 new mode 100644 diff --git a/portable/Zynq/xsdps_hw.h b/portable/Zynq/xsdps_hw.h old mode 100755 new mode 100644 index 3d22d60..d5d514a --- a/portable/Zynq/xsdps_hw.h +++ b/portable/Zynq/xsdps_hw.h @@ -57,7 +57,7 @@ #define SD_HW_H_ #ifdef __cplusplus - extern "C" { + extern "C" { #endif /***************************** Include Files *********************************/ @@ -496,7 +496,7 @@ /* @} */ -/** @name Maximum Current Capablities Register +/** @name Maximum Current Capabilities Register * * This register is read only register which contains * information about current capabilities at each voltage levels. @@ -552,7 +552,7 @@ #define XSDPS_FE_INTR_ERR_CUR_LMT_MASK 0x0080U /**< Current Limit Error */ #define XSDPS_FE_INTR_ERR_AUTO_CMD_MASK 0x0100U /**< Auto CMD Error */ #define XSDPS_FE_INTR_ERR_ADMA_MASK 0x0200U /**< ADMA Error */ - #define XSDPS_FE_INTR_ERR_TR_MASK 0x1000U /**< Target Reponse */ + #define XSDPS_FE_INTR_ERR_TR_MASK 0x1000U /**< Target Response */ #define XSDPS_FE_INTR_VEND_SPF_ERR_MASK 0xE000U /**< Vendor Specific * Error */ @@ -1189,7 +1189,7 @@ /************************** Variable Definitions *****************************/ #ifdef __cplusplus - } +} #endif #endif /* SD_HW_H_ */ diff --git a/portable/Zynq/xsdps_info.h b/portable/Zynq/xsdps_info.h old mode 100755 new mode 100644 diff --git a/portable/Zynq/xsdps_options.c b/portable/Zynq/xsdps_options.c old mode 100755 new mode 100644 index 3c5a330..455abbc --- a/portable/Zynq/xsdps_options.c +++ b/portable/Zynq/xsdps_options.c @@ -644,7 +644,7 @@ s32 XSdPs_Change_BusSpeed( XSdPs * InstancePtr ) * @return None * * @note This API will change clock frequency to the value less than - * or equal to the given value using the permissible dividors. + * or equal to the given value using the permissible dividers. * ******************************************************************************/ s32 XSdPs_Change_ClkFreq( XSdPs * InstancePtr, diff --git a/portable/Zynq/xsdps_sinit.c b/portable/Zynq/xsdps_sinit.c old mode 100755 new mode 100644 diff --git a/portable/avr32_uc3/ff_flush.c b/portable/avr32_uc3/ff_flush.c old mode 100755 new mode 100644 diff --git a/portable/avr32_uc3/ff_flush.h b/portable/avr32_uc3/ff_flush.h old mode 100755 new mode 100644 index 3caa943..4c7f492 --- a/portable/avr32_uc3/ff_flush.h +++ b/portable/avr32_uc3/ff_flush.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -29,7 +29,7 @@ #define __FF_FLUSH_H__ #ifdef __cplusplus - extern "C" { + extern "C" { #endif /* HT addition: call FF_FlushCache and in addition call cache_write_flush (see secCache.cpp) */ @@ -43,7 +43,7 @@ FF_Error_t FF_StopFlush( FF_IOManager_t * pxIOManager, BaseType_t xFlag ); #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif diff --git a/portable/avr32_uc3/ff_locking.c b/portable/avr32_uc3/ff_locking.c old mode 100755 new mode 100644 index 7a617f7..08aa541 --- a/portable/avr32_uc3/ff_locking.c +++ b/portable/avr32_uc3/ff_locking.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -114,9 +114,9 @@ BaseType_t FF_TrySemaphore( void * pxSemaphore, BaseType_t rc; #if ( FF_DO_TRACE_SEMAPHORE != 0 ) - { - eventLogAdd( "Pend_%s\n", pcName ); - } + { + eventLogAdd( "Pend_%s\n", pcName ); + } #endif /* FF_DO_TRACE_SEMAPHORE */ if( !cMutexWasCreated ) @@ -143,9 +143,9 @@ BaseType_t FF_TrySemaphore( void * pxSemaphore, void FF_PendSemaphore( void * pxSemaphore ) { #if ( FF_DO_TRACE_SEMAPHORE != 0 ) - { - eventLogAdd( "Pend_%s\n", pcName ); - } + { + eventLogAdd( "Pend_%s\n", pcName ); + } #endif /* FF_DO_TRACE_SEMAPHORE */ if( !cMutexWasCreated ) @@ -155,14 +155,14 @@ void FF_PendSemaphore( void * pxSemaphore ) pthread_mutex_lock( &xFATMutex, 120000 ); #if ( FF_DO_TRACE_SEMAPHORE != 0 ) + { + if( mutex_owner[ 0 ] != 0 ) { - if( mutex_owner[ 0 ] != 0 ) - { - logPrintf( "Pend Enter: %s overruled by %s\n", mutex_owner, pcName ); - } - - snprintf( mutex_owner, sizeof mutex_owner, pcName ); + logPrintf( "Pend Enter: %s overruled by %s\n", mutex_owner, pcName ); } + + snprintf( mutex_owner, sizeof mutex_owner, pcName ); + } #endif /* FF_DO_TRACE_SEMAPHORE */ } /*-----------------------------------------------------------*/ @@ -170,16 +170,16 @@ void FF_PendSemaphore( void * pxSemaphore ) void FF_ReleaseSemaphore( void * pxSemaphore ) { #if ( FF_DO_TRACE_SEMAPHORE != 0 ) + { + if( strcmp( pcName, mutex_owner ) != 0 ) { - if( strcmp( pcName, mutex_owner ) != 0 ) - { - /* FF_GetBuffer2 != FF_GetBuffer */ - logPrintf( "Pend Exit: %s owned by %s\n", pcName, mutex_owner ); - } - - eventLogAdd( "Exit_%s\n", pcName ); - mutex_owner[ 0 ] = '\0'; + /* FF_GetBuffer2 != FF_GetBuffer */ + logPrintf( "Pend Exit: %s owned by %s\n", pcName, mutex_owner ); } + + eventLogAdd( "Exit_%s\n", pcName ); + mutex_owner[ 0 ] = '\0'; + } #endif /* FF_DO_TRACE_SEMAPHORE */ if( cMutexWasCreated ) diff --git a/portable/common/ff_ramdisk.c b/portable/common/ff_ramdisk.c index 754ce94..5a947cb 100644 --- a/portable/common/ff_ramdisk.c +++ b/portable/common/ff_ramdisk.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -422,7 +422,7 @@ BaseType_t FF_RAMDiskShowPartition( FF_Disk_t * pxDisk ) FF_PRINTF( "TotalSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulTotalSectors ); FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); FF_PRINTF( "Size %8u KB\n", ( unsigned ) ulTotalSizeKB ); - FF_PRINTF( "FreeSize %8u KB ( %d perc free )\n", ( unsigned ) ulFreeSizeKB, iPercentageFree ); + FF_PRINTF( "FreeSize %8u KB ( %d percent free )\n", ( unsigned ) ulFreeSizeKB, iPercentageFree ); } return xReturn; diff --git a/portable/common/ff_ramdisk.h b/portable/common/ff_ramdisk.h old mode 100755 new mode 100644 index 924e103..e0e2440 --- a/portable/common/ff_ramdisk.h +++ b/portable/common/ff_ramdisk.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -29,7 +29,7 @@ #define __RAMDISK_H__ #ifdef __cplusplus - extern "C" { + extern "C" { #endif #include "ff_headers.h" @@ -47,7 +47,7 @@ BaseType_t FF_RAMDiskShowPartition( FF_Disk_t * pxDisk ); #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif #endif /* __RAMDISK_H__ */ diff --git a/portable/common/ff_sddisk.h b/portable/common/ff_sddisk.h index b7eead0..c5b0a1e 100644 --- a/portable/common/ff_sddisk.h +++ b/portable/common/ff_sddisk.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -31,7 +31,7 @@ #include "ff_headers.h" #ifdef __cplusplus - extern "C" { + extern "C" { #endif /* @brief Initialization settings for more granular control on init. */ @@ -77,11 +77,11 @@ BaseType_t FF_SDDiskInserted( BaseType_t xDriveNr ); /* _RB_ Temporary function - ideally the application would not need the IO - * manageer structure, just a handle to a disk. */ + * manager structure, just a handle to a disk. */ FF_IOManager_t * sddisk_ioman( FF_Disk_t * pxDisk ); #ifdef __cplusplus - } /* extern "C" */ +} /* extern "C" */ #endif #endif /* __SDDISK_H__ */ diff --git a/portable/linux/ff_sddisk.c b/portable/linux/ff_sddisk.c index 28fe3e9..0a7ee82 100644 --- a/portable/linux/ff_sddisk.c +++ b/portable/linux/ff_sddisk.c @@ -247,7 +247,7 @@ BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pxDisk ) FF_PRINTF( "DataSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulDataSectors ); FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); FF_PRINTF( "Size %8u MB\n", ( unsigned ) ulTotalSizeMB ); - FF_PRINTF( "FreeSize %8u MB ( %d perc free )\n", ( unsigned ) ulFreeSizeMB, ( int ) iPercentageFree ); + FF_PRINTF( "FreeSize %8u MB ( %d percent free )\n", ( unsigned ) ulFreeSizeMB, ( int ) iPercentageFree ); FF_PRINTF( "BeginLBA %8u\n", ( unsigned ) pxIOManager->xPartition.ulBeginLBA ); FF_PRINTF( "FATBeginLBA %8u\n", ( unsigned ) pxIOManager->xPartition.ulFATBeginLBA ); } diff --git a/portable/lpc18xx/ff_sddisk.c b/portable/lpc18xx/ff_sddisk.c index e09dbad..c17d574 100644 --- a/portable/lpc18xx/ff_sddisk.c +++ b/portable/lpc18xx/ff_sddisk.c @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -451,7 +451,7 @@ BaseType_t FF_SDDiskShowPartition( FF_Disk_t * pxDisk ) FF_PRINTF( "TotalSectors %8u\n", ( unsigned ) pxIOManager->xPartition.ulTotalSectors ); FF_PRINTF( "SecsPerCluster %8u\n", ( unsigned ) pxIOManager->xPartition.ulSectorsPerCluster ); FF_PRINTF( "Size %8u MB\n", ( unsigned ) ulTotalSizeMB ); - FF_PRINTF( "FreeSize %8u MB ( %d perc free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); + FF_PRINTF( "FreeSize %8u MB ( %d percent free )\n", ( unsigned ) ulFreeSizeMB, iPercentageFree ); } return xReturn; diff --git a/test/build-combination/DefaultConf/FreeRTOSFATConfig.h b/test/build-combination/DefaultConf/FreeRTOSFATConfig.h index 7699f05..6771b22 100644 --- a/test/build-combination/DefaultConf/FreeRTOSFATConfig.h +++ b/test/build-combination/DefaultConf/FreeRTOSFATConfig.h @@ -1,6 +1,6 @@ /* * FreeRTOS+FAT V2.3.3 - * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in