FatFs

Started by tha, May 05, 2022, 10:00:40 AM

Previous topic - Next topic

tha

http://elm-chan.org/fsw/ff/00index_e.html

FatFs - Generic FAT Filesystem Module

FatFs คือ a generic FAT/exFAT filesystem module สำหรับ small embedded systems. The FatFs module ถูกเขียนสอดคล้องกับ ANSI C (C89) และแยกออก the disk I/O layer โดยสิ้นเชิง. ดังนั้นมันจึงไม่ขึ้นกับแพลตฟอร์ม. มันสามารถถูกรวมลงใน small microcontrollers ที่มีทรัพยากรจำกัด, อย่างเช่น 8051, PIC, AVR, ARM, Z80, RX และอื่นๆ. นอกจากนี้ยังมี Petit FatFs module สำหรับ tiny microcontrollers มีให้ใช้ประโยชน์ที่นี่.

tha

Features

•   DOS/Windows Compatible FAT/exFAT Filesystem.
•   Platform Independent. Easy to port.
•   Very Small Footprint for Program Code and Work Area.
•   Various Configuration Options to Support for:
     •   Long File Name in ANSI/OEM or Unicode.
     •   exFAT Filesystem, 64-bit LBA and GPT for Huge Storages.
     •   Thread Safe for RTOS.
     •   Multiple Volumes. (Physical Drives and Partitions)
     •   Variable Sector Size.
     •   Multiple Code Pages Including DBCS.
     •   Read-only, Optional APIs, I/O Buffer and etc...

tha



tha

http://elm-chan.org/fsw/ff/doc/open.html



Parameters
   fp
       ตัวชี้ไปยัง the blank file object structure.
   path
       ตัวชี้ไปยัง the null-terminated string ที่ระบุ the file name เพื่อเปิดหรือสร้าง.
  mode
     Mode flags ที่ระบุประเภทของ access and open method สำหรับ the file. มันถูกระบุโดยการรวมของ flags ต่อไปนี้.


Mode flags ใน POSIX fopen() function ตรงกันกับ FatFs mode flags ดังต่อไปนี้:


Return Values
FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILE, FR_NO_PATH, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_INVALID_OBJECT, FR_WRITE_PROTECTED, FR_INVALID_DRIVE, FR_NOT_ENABLED, FR_NO_FILESYSTEM, FR_TIMEOUT, FR_LOCKED, FR_NOT_ENOUGH_CORE, FR_TOO_MANY_OPEN_FILES

Description
The f_open function เปิด a file และสร้าง a file object. The file object เป็น an identifier สำหรับการดำเนินการที่ตามมาของ the file. Open file ควรถูกปิดด้วย f_close function หลังจาก the session ของ the file access. ถ้าการเปลี่ยนแปลงใดๆกับ the file ถูกทำแล้วและไม่ถูกปิดก่อน power off, media removal หรือ re-mount, หรือ the file สามารถถูกพังลง.
ถ้า duplicated file open ถูกต้องการ, โปรดอ่านที่นี่อย่างละเอียด. อย่างไรก็ตาม duplicated open of a file ด้วย any write mode flag ถูกห้ามเสมอ.

QuickInfo
มีให้ใช้ประโยชน์เสมอ. มีเพียง FA_READ and FA_OPEN_EXISTING มีให้ใช้ประโยชน์สำหรับ the mode flags เมื่อ FF_FS_READONLY == 1.

Example
(ตัวอย่างโค้ดดูในลิ้งค์เอานะครับ)

See Also
f_read, f_write, f_close, FIL, FATFS

tha

http://elm-chan.org/fsw/ff/doc/close.html



Parameter
   fp
       ตัวชี้ไปยัง the open file object structure ที่จะถูกปิด.

Return Values
FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_INVALID_OBJECT, FR_TIMEOUT

Description
The f_close function จะปิด an open file object. ถ้า the file ถูกเปลี่ยนแปลงแล้ว, the cached information of the file จะถูกเขียนกลับไปยัง the volume. หลังจาก the function สำเร็จลง, the file object จะไม่ใช้ได้อีกต่อไปและมันสามารถถูกทิ้งได้.
โปรดทราบว่า the file object อยู่ใน read-only mode และ FF_FS_LOCK ไม่ถูกเปิดใช้งาน, the file object สามารถถูกทิ้งได้ด้วยโดยไม่มีขบวนการนี้. อย่างไรก็ตาม ไม่แนะนำสำหรับความเข้ากันได้ในอนาคต.

QuickInfo
มีให้ใช้ประโยชน์เสมอ.

See Also
f_open, f_read, f_write, f_sync, FIL, FATFS

tha

http://elm-chan.org/fsw/ff/doc/read.html



Parameters
   fp
       ตัวชี้ไปยัง the open file object.
   buff
       ตัวชี้ไปยัง the buffer เพื่อเก็บ the read data.
   btr
       จำนวนของ bytes ที่อ่านในช่วงของ UINT type. ถ้า the file จำเป็นต้องถูกอ่านเร็ว, มันควรถูกอ่านเป็นกลุ่มที่ใหญ่ที่สุดเท่าที่เป็นได้.
   br
       ตัวชี้ไปยัง the UINT variable ที่รับจำนวนของ bytes ที่อ่าน. ค่านี้ใช้ได้เสมอหลังจาก the function call โดยไม่คำนึงถึง the
       function return code. ถ้า the return value เท่ากันกับ btr, the function return code ควรเป็น FR_OK.

Description
The function สตาร์ทเพื่ออ่าน data จาก the file ที่ the file offset ที่ชี้โดย read/write pointer. The read/write pointer จะเลื่อนไปข้างหน้าตามจำนวนของ bytes ที่อ่าน. หลังจาก the function สำเร็จลง, *br ควรถูกเช็คเพื่อตรวจหา end of the file. ในกรณีของ *br < btr, มันหมายความว่า the read/write pointer ถึง end of the file ในระหว่าง read operation.

QuickInfo
มีให้ใช้ประโยชน์เสมอ.

Example
ดูตัวอย่างใน f_open.

See Also
f_open, fgets, f_write, f_close, FIL

tha

http://elm-chan.org/fsw/ff/doc/write.html



Parameters
   fp
       ตัวชี้ไปยัง the open file object structure.
   buff
       ตัวชี้ไปยัง the data ที่จะถูกเขียน.
   btw
       ระบุจำนวนของ bytes เพื่อเขียนในช่วงของ UINT type. ถ้า the file จำเป็นต้องถูกเขียนเร็ว, มันควรถูกเขียนเป็นกลุ่มที่ใหญ่ที่สุดเท่าที่
       เป็นได้.
   bw
       ตัวชี้ไปยัง the UINT variable ที่รับ the number of bytes ที่เขียน. ค่านี้ใช้ได้เสมอหลังจาก the function call โดยไม่คำนึงถึง
       the function return code. ถ้า the return value เท่ากันกับ btw, the function return code ควรเป็น FR_OK.

Return Values
FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_DENIED, FR_INVALID_OBJECT, FR_TIMEOUT

Description
The function สตาร์ทเพื่อเขียน data ไปยัง the file ที่ the file offset ที่ชี้โดย read/write pointer. The read/write pointer จะเลื่อนไปข้างหน้าตามจำนวนของ bytes ที่เขียน. หลังจาก the function สำเร็จลง, *bw ควรถูกเช็คเพื่อตรวจหา the disk full. ในกรณีของ *bw < btw, มันหมายความว่า the volume เต็มในระหว่าง the write operation. ฟังก์ชันอาจใช้เวลาเมื่อไดรฟ์ข้อมูลเต็มหรือใกล้เต็ม.

QuickInfo
มีให้ใช้ประโยชน์เมื่อ FF_FS_READONLY == 0.

Example
ดูตัวอย่างใน f_open.

See Also
f_open, f_read, fputc, fputs, fprintf, f_close, FIL

tha

http://elm-chan.org/fsw/ff/doc/lseek.html


The f_lseek function ย้าย the file read/write pointer ของ an open file object. มันสามารถถูกใช้ขยาย the file size (cluster pre-allocation)ด้วย.


Parameters
   fp
       ตัวชี้ไปยัง the open file object.
   ofs
      Byte ที่อ็อปเซ็ต(ระยะห่าง)จากบนสุดของ the file เพื่อเซ็ต read/write pointer. The data type FSIZE_t คือนามแฝงของอย่าง
      ใดอย่างหนึ่ง DWORD(32-bit) หรือ QWORD(64-bit) ขึ้นอยู่กับ the configuration option FF_FS_EXFAT.

Return Values
FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_INVALID_OBJECT, FR_TIMEOUT