FatFs

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

Previous topic - Next topic

tha

Description
File read/write ponter ใน the open file object ชี้ the data byte ที่จะถูกอ่าน/ถูกเขียนที่ next read/write operation. จะเลื่อนไปข้างหน้าตามจำนวนของ bytes ที่อ่าน/ที่เขียน. The f_lseek function ย้าย the file read/write pointer โดยปราศจาก any read/write operation กับ the file. The f_rewind function ถูกจัดให้มีใช้งานเป็น a macro.

ถ้า an offset เกิน the file size ถูกระบุใน write mode, the file size จะถูกขยายถึง the specified offset.  The file data ใน the expanded part ถูกไม่กำหนด, เนื่องจากไม่มี data ถูกเขียนไปยัง the file ในขบวนการนี้. นี้เหมาะเพื่อจัดสรรล่วงหน้า a data area ให้กับ the file อย่างรวดเร็วสำหรับ fast write operation. เมื่อ a contiguous data area จำเป็นต้องถูกจัดสรรให้กับ the file, ใช้ f_expand function แทน. หลังจาก the f_lseek function สำเร็จ, the current read/write pointer ควรถูกตรวจสอบเพื่อให้แน่ใจว่า the read/write pointer ถูกย้ายไปอย่างถูกต้อง. ในกรณีของ the read/write pointer ไม่กำลังชี้ expected offset, อย่างใดอย่างหนึ่งของต่อไปนี้ถูกทำให้เกิดขึ้นแล้ว.
   •  End of file. The specified ofs ถูกตัดให้สั้นแล้วที่ end of the file ใน read-only mode.
   •  Disk full. ไม่มี free space บน the volume เพื่อขยาย the file.

tha

The fast seek feature เปิดใช้งาน fast backward/long seek operations โดยไม่มี FAT access โดยการใช้ an on-memory CLMT (cluster link map table). มันถูกนำไปใช้กับ f_read and f_write function เช่นกัน, อย่างไรก็ตาม, the file size ไม่สามารถถูกขยายโดย f_write, f_lseek function ในขณะที่ the file อยู่ที่ fast seek mode.
The fast seek mode จะมีให้ใช้งานเมื่อ FF_USE_FASTSEEK = 1. The CLMT ต้องถูกสร้างลงใน the DWORD array ก่อนที่จะใช้ the fast seek mode. เพื่อสร้าง the CLMT, เซ็ต address of the DWORD array เป็น the member cltbl ใน the open file object, เซ็ต the size of array ใน unit of items ไปยัง the cltbl[0] และจากนั้นเรียก f_lseek function ด้วย ofs = CREATE_LINKMAP. หลังจาก the function สำเร็จ, ไม่มี FAT access ถูกเกิดขึ้นใน f_read, f_write, f_lseek function กับ the file ที่ตามมา. The number of items ที่ใช้หรือที่ต้องการถูกส่งคืนกลับลงใน the cltbl[0]. The number of items ที่ต้องการคือ (number of the file fragments + 1) * 2. ตัวอย่างเช่น, 12 items in the array จะถูกใช้สำหรับ the file fragmented ใน 5 portions. ถ้า the function ล้มเหลวด้วย FR_NOT_ENOUGH_CORE, the size of given array ไม่เพียงพอสำหรับ the file.

QuickInfo
มีให้ใช้งานเมื่อ FF_FS_MINIMIZE <= 2. เพื่อใช้ fast seek function, FF_USE_FASTSEEK จำเป็นต้องถูกเซ็ต 1 เพื่อเปิดใช้งานคุณสมลักษณะนี้.

Example
ตัวอย่างโค้ดดูในลิ้งค์เอานะครับ
http://elm-chan.org/fsw/ff/doc/lseek.html

See Also
f_open, f_truncate, f_expand, FIL

tha

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



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

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

Description
The f_truncate function ตัดยอด the file size เป็น the current file read/write pointer. ฟังชั่นนี้จะไม่มีผลอะไรถ้า the file read/write pointer กำลังชี้ end of the file แล้ว.

QuickInfo
มีให้ใช้งานเมื่อ FF_FS_READONLY == 0 and FF_FS_MINIMIZE == 0.

See Also
f_open, f_lseek, FIL


tha

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



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

Return Values
FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_INVALID_OBJECT, FR_TIMEOUT

Description
The f_sync function กระทำขั้นตอนเดียวกันกับ f_close function แต่ the file ถุกเปิดทิ้งไว้และสามารถต่อเนื่อง read/write/seek operations ถึง the file. นี้เหมาะสำหรับ the applications ที่เปิด open files เป็นเวลานานใน write mode, อย่างเช่น data logger. การดำเนินการ f_sync function ในระยะเวลาที่แน่นอนสามารถทำให้ต่ำสุด the risk of data loss เนื่องจาก a sudden blackout, wrong media removal หรือ unrecoverable disk error. สำหรับรายละเอียดเพิ่มเติม, ดูที่ application note.

อย่างไรก็ตาม ไม่มีความหมายใน f_sync function ทันทีก่อน f_close function เนื่องจากมันกระทำ f_sync function ในนั้น. กล่าวอีกนัยหนึ่ง, ความแตกต่างระหว่างฟังก์ชันเหล่านั้นคือว่า the file object ถูกทำให้ใช้งานไม่ได้หรือไม่.

QuickInfo
มีให้ใช้งานเมื่อ FF_FS_READONLY == 0.

See Also
f_close, Critical section

tha

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


The f_forward function อ่าน the file data และส่งต่อมันไปยัง the data streaming device.


Parameters
   fp
       ตัวชี้ไปยัง the open file object.
   func
       ตัวชี้ไปยัง the user-defined data streaming function. สำหรับรายละเอียด, ดูที่ the sample code.
   btf
       จำนวนของ bytes ที่จะส่งต่อในช่วงของ UINT.
   bf
       ตัวชี้ไปยัง the UINT variable เพื่อส่งคืนกลับ number of bytes ที่ถูกส่งต่อ.

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

Description
The f_forward function อ่าน the data จาก the file และส่งต่อมันไปยัง the outgoing stream. ฟังชั่นนี้เหมาะสำหรับ small memory system, เนื่องจากมันไม่ต้องการ any data buffer ใน the application module. The file pointer of the file object จะเลื่อนไปข้างหน้าตามจำนวนของ bytes ที่ถูกส่งต่อ. ในกรณีของ *bf น้อยกว่า btf โดยปราศจาก error, มันหมายความว่า the requested size of data ไม่สามารถถูกส่งถ่ายเนื่องจาก end of file หรือ stream ยุ่งอยู่ในระหว่าง data transfer.

QuickInfo
มีให้ใช้งานเมื่อ FF_USE_FORWARD == 1.

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

See Also
f_open, fgets, f_write, f_close, FIL

tha

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



Parameters
   fp
       ตัวชี้ไปยัง the open file object.
   fsz
       Number of bytes in size เพื่อจัดเตรียมหรือจัดสรรสำหรับ the file. The data type FSIZE_t เป็นนามแฝงของอย่างใดอย่างหนึ่ง
       DWORD(32-bit) or QWORD(64-bit) ขึ้นอยู่กับ the configuration option FF_FS_EXFAT.
   opt
       Allocation mode. Prepare to allocate (0) or Allocate now (1).

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

tha

Description
The f_expand function จัดเตรียมหรือจัดสรร a contiguous data area ให้กับ the file. เมื่อ opt เป็น 1, the data area ถูกจัดสรรให้กับ the file ในฟังชั่นนี้. ไม่เหมือน expansion of file size โดย f_lseek function, the file ต้องถูกตัดยอดก่อนจะใช้ฟังชั่นนี้และ read/write pointer of the file อยู่ที่ offset 0 หลังจาก the function call. The file content ที่จัดสรรด้วยฟังชั่นนี้ถูกไม่กำหนด, เนื่องจากไม่มี data ถูกเขียนไปยัง the file ในฟังชั่นนี้. The function อาจล้มเหลวด้วย FR_DENIED เนื่องจากบางเหตุผลข้างล่าง.

  •  ไม่มี free contiguous space ถูกพบ.
  •  Size of the file ไม่เป็นศูนย์.
  •  The file ถูกเปิดแล้วใน read-only mode.
  •  Not allowable file size. (>= 4 GB on FAT volume)

tha

เมื่อ opt เป็น 0, the function ค้นหา a contiguous data area และเซ็ตมันเป็นจุดที่แนะนำสำหรับ next allocation. The subsequent(ที่ตามมา) cluster allocation จะเริ่มที่ top of the contiguous area ที่พบโดยฟังชั่นนี้. ดังนั้น the file allocation ถูกรับประกันได้ว่าต่อเนื่องและไม่มี allocation delay จนกระทั่ง the file size ถึง size นี้ยกเว้นการเปลี่ยนแปลงอื่นใดๆกับ the volume ถูกกระทำ.
The contiguous file มีข้อได้เปรียบสำหรับ time-critical read/write operations. มันขจัด overheads บางอย่างใน the filesystem และ the storage device ที่เกิดจาก random access สำหรับ fragmented file.
นอกจากนี้ the contiguous file สามารถถูกเข้าถึงโดยตรงได้ง่ายโดยทาง low-level disk functions. อย่างไรก็ตาม, สิ่งนี้ไม่แนะนำโดยพิจารณาถึงความสะดวกในการพกพาและความเข้ากันได้ในอนาคต. ถ้า the file ไม่ได้รับยืนยันว่าอยู่ติดกัน, ให้ใช้ฟังก์ชันนี้เพื่อตรวจสอบว่าไฟล์อยู่ติดกันหรือไม่.

QuickInfo
มีให้ใช้งานเมื่อ FF_USE_EXPAND == 1 and FF_FS_READONLY == 0.

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

See Also
f_open, f_lseek, FIL