You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FreeRTOS-Kernel/Demo/Common/FileSystem/FatFs-0.7e/doc/ja/lseek.html

111 lines
3.5 KiB
HTML

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_j.html">
<link rel="stylesheet" href="../css_j.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_lseek</title>
</head>
<body>
<div class="para">
<h2>f_lseek</h2>
<p>ファイルのR/Wポインタを移動します。</p>
<pre>
FRESULT f_lseek (
FIL* <em>FileObject</em>, /* ファイル・オブジェクト構造体へのポインタ */
DWORD <em>Offset</em> /* 移動先オフセット */
);
</pre>
</div>
<div class="para">
<h4>引数</h4>
<dl class="par">
<dt>FileObject</dt>
<dd>対象となるファイル・オブジェクト構造体へのポインタを指定します。</dd>
<dt>Offset</dt>
<dd>移動先のオフセットR/Wポインタ値。ファイル先頭からのオフセットをバイト単位で指定します。</dd>
</dl>
</div>
<div class="para">
<h4>戻り値</h4>
<dl class="ret">
<dt>FR_OK (0)</dt>
<dd>正常終了。</dd>
<dt>FR_DISK_ERR</dt>
<dd>ディスク・エラーによる失敗。</dd>
<dt>FR_INT_ERR</dt>
<dd>不正なFAT構造または内部エラーによる失敗。</dd>
<dt>FR_NOT_READY</dt>
<dd>メディアがセットされていないなど、物理ドライブが動作不能状態。</dd>
<dt>FR_INVALID_OBJECT</dt>
<dd>無効なファイル・オブジェクト。</dd>
</dl>
</div>
<div class="para">
<h4>解説</h4>
<p>ファイルR/Wポインタ(ファイル・オブジェクト内のfptrメンバで、次に読み出し・書き込みされるバイトのオフセットを示す)を移動します。オフセットの原点はファイル先頭からです。書き込みモードでファイル・サイズより大きな値を指定すると、そこまでファイルが拡張され、拡張された部分のデータは未定義となります。データを遅延無く高速に書き込みたいときは、予めこの関数で必要なサイズまでファイル・サイズを拡張しておくと良いでしょう。f_lseek関数が正常終了したあとは、ファイルR/Wポインタが正しく移動したかfptrをチェックするべきです。ファイルR/Wポインタが指定より小さいときは、次の原因が考えられます。</p>
<ul>
<li>非書き込みモードのため、ファイル・サイズでクリップされた。</li>
<li>ファイル拡張中にディスクが満杯になった。</li>
</ul>
</div>
<div class="para">
<h4>対応情報</h4>
<p><tt>_FS_MINIMIZE &lt; 3</tt>のとき使用可能です。</p>
</div>
<div class="para">
<h4>使用例</h4>
<pre>
/* オフセット5000へ移動 */
res = f_lseek(&amp;file, 5000);
/* ファイル追記の準備 (ファイル終端へ移動) */
res = f_lseek(&amp;file, file.fsize);
/* 3000バイト進める */
res = f_lseek(&amp;file, file.fptr + 3000);
/* 2000バイト戻す (オーバーフローに注意) */
res = f_lseek(&amp;file, file.fptr - 2000);
</pre>
<pre>
/* クラスタ先行割り当て (ストリーミング・ライト時のバッファ・オーバーラン防止) */
res = f_open(&amp;file, "record.wav", FA_CREATE_NEW | FA_WRITE); /* ファイル作成 */
res = f_lseek(&amp;file, MAX_SIZE); /* 十分なクラスタの先行割り当て */
if (res || file.fptr != PRE_SIZE) .... /* 正しくファイルが拡張されたかチェック */
res = f_lseek(&amp;file, DATA_START); /* データ・ストリームの記録(アロケーションディレイ無し) */
...
res = f_truncate(&amp;file); /* 不要領域の切り捨て */
res = f_lseek(&amp;file, 0); /* ヘッダの記録 */
...
res = f_close(&amp;file);
</pre>
</div>
<div class="para">
<h4>参照</h4>
<p><tt><a href="open.html">f_open</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_j.html">戻る</a></p>
</body>
</html>