📄 tff_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Sample MSP430-4619LCD Project: tff.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.1 --><div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li id="current"><a href="files.html"><span>Files</span></a></li> </ul></div><div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul></div><h1>tff.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*--------------------------------------------------------------------------/</span><a name="l00002"></a>00002 <span class="comment">/ FatFs - Tiny FAT file system module R0.04b (C)ChaN, 2007</span><a name="l00003"></a>00003 <span class="comment">/---------------------------------------------------------------------------/</span><a name="l00004"></a>00004 <span class="comment">/ The FatFs module is an experimenal project to implement FAT file system to</span><a name="l00005"></a>00005 <span class="comment">/ cheap microcontrollers. This is a free software and is opened for education,</span><a name="l00006"></a>00006 <span class="comment">/ research and development under license policy of following trems.</span><a name="l00007"></a>00007 <span class="comment">/</span><a name="l00008"></a>00008 <span class="comment">/ Copyright (C) 2007, ChaN, all right reserved.</span><a name="l00009"></a>00009 <span class="comment">/</span><a name="l00010"></a>00010 <span class="comment">/ * The FatFs module is a free software and there is no warranty.</span><a name="l00011"></a>00011 <span class="comment">/ * You can use, modify and/or redistribute it for personal, non-profit or</span><a name="l00012"></a>00012 <span class="comment">/ profit use without any restriction under your responsibility.</span><a name="l00013"></a>00013 <span class="comment">/ * Redistributions of source code must retain the above copyright notice.</span><a name="l00014"></a>00014 <span class="comment">/</span><a name="l00015"></a>00015 <span class="comment">/---------------------------------------------------------------------------/</span><a name="l00016"></a>00016 <span class="comment">/ Feb 26, 2006 R0.00 Prototype.</span><a name="l00017"></a>00017 <span class="comment">/ Apr 29, 2006 R0.01 First stable version.</span><a name="l00018"></a>00018 <span class="comment">/ Jun 01, 2006 R0.02 Added FAT12 support.</span><a name="l00019"></a>00019 <span class="comment">/ Removed unbuffered mode.</span><a name="l00020"></a>00020 <span class="comment">/ Fixed a problem on small (<32M) patition.</span><a name="l00021"></a>00021 <span class="comment">/ Jun 10, 2006 R0.02a Added a configuration option (_FS_MINIMUM).</span><a name="l00022"></a>00022 <span class="comment">/ Sep 22, 2006 R0.03 Added f_rename().</span><a name="l00023"></a>00023 <span class="comment">/ Changed option _FS_MINIMUM to _FS_MINIMIZE.</span><a name="l00024"></a>00024 <span class="comment">/ Dec 09, 2006 R0.03a Improved cluster scan algolithm to write files fast.</span><a name="l00025"></a>00025 <span class="comment">/ Feb 04, 2007 R0.04 Added FAT32 supprt.</span><a name="l00026"></a>00026 <span class="comment">/ Changed some interfaces incidental to FatFs.</span><a name="l00027"></a>00027 <span class="comment">/ Changed f_mountdrv() to f_mount().</span><a name="l00028"></a>00028 <span class="comment">/ Apr 01, 2007 R0.04a Added a capability of extending file size to f_lseek().</span><a name="l00029"></a>00029 <span class="comment">/ Added minimization level 3.</span><a name="l00030"></a>00030 <span class="comment">/ Fixed a problem in FAT32 support.</span><a name="l00031"></a>00031 <span class="comment">/ May 05, 2007 R0.04b Added a configuration option _USE_NTFLAG.</span><a name="l00032"></a>00032 <span class="comment">/ Added FSInfo support.</span><a name="l00033"></a>00033 <span class="comment">/ Fixed some problems corresponds to FAT32 support.</span><a name="l00034"></a>00034 <span class="comment">/ Fixed DBCS name can result FR_INVALID_NAME.</span><a name="l00035"></a>00035 <span class="comment">/ Fixed short seek (<= csize) collapses the file object.</span><a name="l00036"></a>00036 <span class="comment">/---------------------------------------------------------------------------*/</span><a name="l00037"></a>00037 <a name="l00038"></a>00038 <span class="preprocessor">#include <string.h></span><a name="l00039"></a>00039 <span class="preprocessor">#include "tff.h"</span> <span class="comment">/* Tiny-FatFs declarations */</span><a name="l00040"></a>00040 <span class="preprocessor">#include "diskio.h"</span> <span class="comment">/* Include file for user provided disk functions */</span><a name="l00041"></a>00041 <a name="l00042"></a>00042 <a name="l00043"></a>00043 <span class="keyword">static</span><a name="l00044"></a>00044 <a class="code" href="struct__FATFS.html">FATFS</a> *FatFs; <span class="comment">/* Pointer to the file system objects (logical drive) */</span><a name="l00045"></a>00045 <span class="keyword">static</span><a name="l00046"></a>00046 WORD fsid; <span class="comment">/* File system mount ID */</span><a name="l00047"></a>00047 <a name="l00048"></a>00048 <a name="l00049"></a>00049 <span class="comment">/*-------------------------------------------------------------------------</span><a name="l00050"></a>00050 <span class="comment"></span><a name="l00051"></a>00051 <span class="comment"> Module Private Functions</span><a name="l00052"></a>00052 <span class="comment"></span><a name="l00053"></a>00053 <span class="comment">-------------------------------------------------------------------------*/</span><a name="l00054"></a>00054 <a name="l00055"></a>00055 <a name="l00056"></a>00056 <span class="comment">/*-----------------------------------------------------------------------*/</span><a name="l00057"></a>00057 <span class="comment">/* Change window offset */</span><a name="l00058"></a>00058 <span class="comment">/*-----------------------------------------------------------------------*/</span><a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="keyword">static</span><a name="l00061"></a>00061 BOOL move_window ( <span class="comment">/* TRUE: successful, FALSE: failed */</span><a name="l00062"></a>00062 DWORD sector <span class="comment">/* Sector number to make apperance in the FatFs->win */</span><a name="l00063"></a>00063 ) <span class="comment">/* Move to zero only writes back dirty window */</span><a name="l00064"></a>00064 {<a name="l00065"></a>00065 DWORD wsect;<a name="l00066"></a>00066 <a class="code" href="struct__FATFS.html">FATFS</a> *fs = FatFs;<a name="l00067"></a>00067 <a name="l00068"></a>00068 <a name="l00069"></a>00069 wsect = fs-><a class="code" href="struct__FATFS.html#4d7990897697ab6b380e1036672d40a2">winsect</a>;<a name="l00070"></a>00070 <span class="keywordflow">if</span> (wsect != sector) { <span class="comment">/* Changed current window */</span><a name="l00071"></a>00071 <span class="preprocessor">#if !_FS_READONLY</span><a name="l00072"></a>00072 <span class="preprocessor"></span> BYTE n;<a name="l00073"></a>00073 <span class="keywordflow">if</span> (fs-><a class="code" href="struct__FATFS.html#14c3cb7044924714bf3c7cc19b7da45e">winflag</a>) { <span class="comment">/* Write back dirty window if needed */</span><a name="l00074"></a>00074 <span class="keywordflow">if</span> (<a class="code" href="mmc_8c.html#0045ef2f87f7c45d77bcdef38eae7b67">disk_write</a>(0, fs-><a class="code" href="struct__FATFS.html#32c85fa1d26f37661c21f5a1afaa2c08">win</a>, wsect, 1) != RES_OK)<a name="l00075"></a>00075 <span class="keywordflow">return</span> <a class="code" href="common_8h.html#a93f0eb578d23995850d61f7d61c55c1">FALSE</a>;<a name="l00076"></a>00076 fs-><a class="code" href="struct__FATFS.html#14c3cb7044924714bf3c7cc19b7da45e">winflag</a> = 0;<a name="l00077"></a>00077 <span class="keywordflow">if</span> (wsect < (fs-><a class="code" href="struct__FATFS.html#08708ab393918e5bfdbf2be9492a6094">fatbase</a> + fs-><a class="code" href="struct__FATFS.html#118b4c13971f9e8964568a65d5e3f2ed">sects_fat</a>)) { <span class="comment">/* In FAT area */</span><a name="l00078"></a>00078 <span class="keywordflow">for</span> (n = fs-><a class="code" href="struct__FATFS.html#29d47bd0e83fe5eec8ed9b34cf814d53">n_fats</a>; n >= 2; n--) { <span class="comment">/* Refrect the change to all FAT copies */</span><a name="l00079"></a>00079 wsect += fs-><a class="code" href="struct__FATFS.html#118b4c13971f9e8964568a65d5e3f2ed">sects_fat</a>;<a name="l00080"></a>00080 <a class="code" href="mmc_8c.html#0045ef2f87f7c45d77bcdef38eae7b67">disk_write</a>(0, fs-><a class="code" href="struct__FATFS.html#32c85fa1d26f37661c21f5a1afaa2c08">win</a>, wsect, 1);<a name="l00081"></a>00081 }<a name="l00082"></a>00082 }<a name="l00083"></a>00083 }<a name="l00084"></a>00084 <span class="preprocessor">#endif</span><a name="l00085"></a>00085 <span class="preprocessor"></span> <span class="keywordflow">if</span> (sector) {<a name="l00086"></a>00086 <span class="keywordflow">if</span> (<a class="code" href="mmc_8c.html#42043c0f462756dbdf1f3bd1bdb5fa50">disk_read</a>(0, fs-><a class="code" href="struct__FATFS.html#32c85fa1d26f37661c21f5a1afaa2c08">win</a>, sector, 1) != RES_OK)<a name="l00087"></a>00087 <span class="keywordflow">return</span> <a class="code" href="common_8h.html#a93f0eb578d23995850d61f7d61c55c1">FALSE</a>;<a name="l00088"></a>00088 fs-><a class="code" href="struct__FATFS.html#4d7990897697ab6b380e1036672d40a2">winsect</a> = sector;<a name="l00089"></a>00089 }<a name="l00090"></a>00090 }<a name="l00091"></a>00091 <span class="keywordflow">return</span> <a class="code" href="common_8h.html#a8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;<a name="l00092"></a>00092 }<a name="l00093"></a>00093 <a name="l00094"></a>00094 <a name="l00095"></a>00095 <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="comment">/*-----------------------------------------------------------------------*/</span><a name="l00098"></a>00098 <span class="comment">/* Clean-up cached data */</span><a name="l00099"></a>00099 <span class="comment">/*-----------------------------------------------------------------------*/</span><a name="l00100"></a>00100 <a name="l00101"></a>00101 <span class="preprocessor">#if !_FS_READONLY</span><a name="l00102"></a>00102 <span class="preprocessor"></span><span class="keyword">static</span><a name="l00103"></a>00103 FRESULT sync (<span class="keywordtype">void</span>) <span class="comment">/* FR_OK: successful, FR_RW_ERROR: failed */</span><a name="l00104"></a>00104 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -