<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.8.16">
  <compounddef id="fat__filelib_8c" kind="file" language="C++">
    <compoundname>fat_filelib.c</compoundname>
    <includes refid="string_8h" local="no">string.h</includes>
    <includes refid="fat__defs_8h" local="yes">fat_defs.h</includes>
    <includes refid="fat__access_8h" local="yes">fat_access.h</includes>
    <includes refid="fat__table_8h" local="yes">fat_table.h</includes>
    <includes refid="fat__write_8h" local="yes">fat_write.h</includes>
    <includes refid="fat__misc_8h" local="yes">fat_misc.h</includes>
    <includes refid="fat__string_8h" local="yes">fat_string.h</includes>
    <includes refid="fat__filelib_8h" local="yes">fat_filelib.h</includes>
    <includes refid="fat__cache_8h" local="yes">fat_cache.h</includes>
    <incdepgraph>
      <node id="10">
        <label>strings.h</label>
        <link refid="strings_8h"/>
        <childnode refid="3" relation="include">
        </childnode>
      </node>
      <node id="5">
        <label>sys/select.h</label>
        <link refid="select_8h"/>
        <childnode refid="6" relation="include">
        </childnode>
        <childnode refid="4" relation="include">
        </childnode>
        <childnode refid="7" relation="include">
        </childnode>
        <childnode refid="8" relation="include">
        </childnode>
        <childnode refid="9" relation="include">
        </childnode>
      </node>
      <node id="22">
        <label>fat_list.h</label>
        <link refid="fat__list_8h"/>
      </node>
      <node id="12">
        <label>fat/fat.h</label>
        <link refid="fat_8h"/>
      </node>
      <node id="9">
        <label>sys/_sigset.h</label>
        <link refid="__sigset_8h"/>
        <childnode refid="4" relation="include">
        </childnode>
      </node>
      <node id="17">
        <label>fat_table.h</label>
        <link refid="fat__table_8h"/>
        <childnode refid="13" relation="include">
        </childnode>
        <childnode refid="18" relation="include">
        </childnode>
      </node>
      <node id="15">
        <label>fat_types.h</label>
        <link refid="fat__types_8h"/>
      </node>
      <node id="2">
        <label>string.h</label>
        <link refid="string_8h"/>
        <childnode refid="3" relation="include">
        </childnode>
        <childnode refid="10" relation="include">
        </childnode>
      </node>
      <node id="11">
        <label>fat_defs.h</label>
        <link refid="fat__defs_8h"/>
        <childnode refid="12" relation="include">
        </childnode>
        <childnode refid="13" relation="include">
        </childnode>
        <childnode refid="15" relation="include">
        </childnode>
      </node>
      <node id="3">
        <label>sys/types.h</label>
        <link refid="include_2sys_2types_8h"/>
        <childnode refid="4" relation="include">
        </childnode>
        <childnode refid="5" relation="include">
        </childnode>
      </node>
      <node id="23">
        <label>fat_cache.h</label>
        <link refid="fat__cache_8h"/>
        <childnode refid="21" relation="include">
        </childnode>
      </node>
      <node id="6">
        <label>sys/cdefs.h</label>
        <link refid="cdefs_8h"/>
      </node>
      <node id="4">
        <label>sys/_types.h</label>
        <link refid="__types_8h"/>
      </node>
      <node id="20">
        <label>fat_string.h</label>
        <link refid="fat__string_8h"/>
      </node>
      <node id="7">
        <label>sys/_timespec.h</label>
        <link refid="__timespec_8h"/>
        <childnode refid="4" relation="include">
        </childnode>
      </node>
      <node id="14">
        <label>stdio.h</label>
      </node>
      <node id="8">
        <label>sys/_timeval.h</label>
        <link refid="__timeval_8h"/>
        <childnode refid="4" relation="include">
        </childnode>
      </node>
      <node id="16">
        <label>fat_access.h</label>
        <link refid="fat__access_8h"/>
        <childnode refid="11" relation="include">
        </childnode>
        <childnode refid="13" relation="include">
        </childnode>
      </node>
      <node id="19">
        <label>fat_write.h</label>
        <link refid="fat__write_8h"/>
        <childnode refid="11" relation="include">
        </childnode>
        <childnode refid="13" relation="include">
        </childnode>
      </node>
      <node id="18">
        <label>fat_misc.h</label>
        <link refid="fat__misc_8h"/>
        <childnode refid="11" relation="include">
        </childnode>
        <childnode refid="13" relation="include">
        </childnode>
      </node>
      <node id="1">
        <label>C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c</label>
        <link refid="fat__filelib_8c"/>
        <childnode refid="2" relation="include">
        </childnode>
        <childnode refid="11" relation="include">
        </childnode>
        <childnode refid="16" relation="include">
        </childnode>
        <childnode refid="17" relation="include">
        </childnode>
        <childnode refid="19" relation="include">
        </childnode>
        <childnode refid="18" relation="include">
        </childnode>
        <childnode refid="20" relation="include">
        </childnode>
        <childnode refid="21" relation="include">
        </childnode>
        <childnode refid="23" relation="include">
        </childnode>
      </node>
      <node id="13">
        <label>fat_opts.h</label>
        <link refid="fat__opts_8h"/>
        <childnode refid="14" relation="include">
        </childnode>
      </node>
      <node id="21">
        <label>fat_filelib.h</label>
        <link refid="fat__filelib_8h"/>
        <childnode refid="13" relation="include">
        </childnode>
        <childnode refid="16" relation="include">
        </childnode>
        <childnode refid="22" relation="include">
        </childnode>
      </node>
    </incdepgraph>
      <sectiondef kind="define">
      <memberdef kind="define" id="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" prot="public" static="no">
        <name>CHECK_FL_INIT</name>
        <param></param>
        <initializer>{ if (_filelib_init==0) <ref refid="fat__filelib_8h_1ac4154a1278a172ab8e6427eb64161179" kindref="member">fl_init</ref>(); }</initializer>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="58" column="9" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="58" bodyend="-1"/>
      </memberdef>
      <memberdef kind="define" id="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" prot="public" static="no">
        <name>FL_LOCK</name>
        <param><defname>a</defname></param>
        <initializer>do { if ((a)-&gt;fl_lock) (a)-&gt;fl_lock(); } while (0)</initializer>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="60" column="9" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="60" bodyend="-1"/>
      </memberdef>
      <memberdef kind="define" id="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" prot="public" static="no">
        <name>FL_UNLOCK</name>
        <param><defname>a</defname></param>
        <initializer>do { if ((a)-&gt;fl_unlock) (a)-&gt;fl_unlock(); } while (0)</initializer>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="61" column="9" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="61" bodyend="-1"/>
      </memberdef>
      </sectiondef>
      <sectiondef kind="var">
      <memberdef kind="variable" id="fat__filelib_8c_1a5a6dc23286e8eece085b55e46fa65948" prot="public" static="yes" mutable="no">
        <type>int</type>
        <definition>int _filelib_init</definition>
        <argsstring></argsstring>
        <name>_filelib_init</name>
        <initializer>= 0</initializer>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="47" column="12" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="47" bodyend="-1"/>
      </memberdef>
      <memberdef kind="variable" id="fat__filelib_8c_1a65aeeda5c4156646271ce68a2b4a6d61" prot="public" static="yes" mutable="no">
        <type>int</type>
        <definition>int _filelib_valid</definition>
        <argsstring></argsstring>
        <name>_filelib_valid</name>
        <initializer>= 0</initializer>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="48" column="12" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="48" bodyend="-1"/>
      </memberdef>
      <memberdef kind="variable" id="fat__filelib_8c_1a9f4c004f000c0c425a2e2b1b0439fc97" prot="public" static="yes" mutable="no">
        <type><ref refid="fat__filelib_8h_1ab1659dbb766794c2537f83372fc2705b" kindref="member">FL_FILE</ref></type>
        <definition>FL_FILE _files[64]</definition>
        <argsstring>[64]</argsstring>
        <name>_files</name>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="46" column="16" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="46" bodyend="-1"/>
      </memberdef>
      <memberdef kind="variable" id="fat__filelib_8c_1aa741fe296a13af2b4a750bae5f800879" prot="public" static="yes" mutable="no">
        <type>struct <ref refid="structfat__list" kindref="compound">fat_list</ref></type>
        <definition>struct fat_list _free_file_list</definition>
        <argsstring></argsstring>
        <name>_free_file_list</name>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="48" column="12" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="51" bodyend="-1"/>
      </memberdef>
      <memberdef kind="variable" id="fat__filelib_8c_1a5c16aac509fda9fd9310649de877d335" prot="public" static="yes" mutable="no">
        <type>struct <ref refid="structfatfs" kindref="compound">fatfs</ref></type>
        <definition>struct fatfs _fs</definition>
        <argsstring></argsstring>
        <name>_fs</name>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="48" column="12" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="49" bodyend="-1"/>
      </memberdef>
      <memberdef kind="variable" id="fat__filelib_8c_1a2a97b07890e264afb5e4154b7968924d" prot="public" static="yes" mutable="no">
        <type>struct <ref refid="structfat__list" kindref="compound">fat_list</ref></type>
        <definition>struct fat_list _open_file_list</definition>
        <argsstring></argsstring>
        <name>_open_file_list</name>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="48" column="12" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="50" bodyend="-1"/>
      </memberdef>
      </sectiondef>
      <sectiondef kind="func">
      <memberdef kind="function" id="fat__filelib_8c_1a3dd468537b94ad17915449842ac0f2be" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type><ref refid="fat__filelib_8h_1ab1659dbb766794c2537f83372fc2705b" kindref="member">FL_FILE</ref> *</type>
        <definition>static FL_FILE* _allocate_file</definition>
        <argsstring>(void)</argsstring>
        <name>_allocate_file</name>
        <param>
          <type>void</type>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="71" column="16" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="71" bodyend="79"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a02ef4fc8b6eb3785f93c8e74bcafddc3" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>static int _check_file_open</definition>
        <argsstring>(FL_FILE *file)</argsstring>
        <name>_check_file_open</name>
        <param>
          <type><ref refid="fat__filelib_8h_1ab1659dbb766794c2537f83372fc2705b" kindref="member">FL_FILE</ref> *</type>
          <declname>file</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="83" column="12" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="83" bodyend="100"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a48811ef369b134171629a7720e50ae0b" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>static int _create_directory</definition>
        <argsstring>(char *path)</argsstring>
        <name>_create_directory</name>
        <param>
          <type>char *</type>
          <declname>path</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="157" column="12" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="157" bodyend="298"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1ac9490069c2fbba3db4127c684dc4158a" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type><ref refid="fat__filelib_8h_1ab1659dbb766794c2537f83372fc2705b" kindref="member">FL_FILE</ref> *</type>
        <definition>static FL_FILE* _create_file</definition>
        <argsstring>(const char *filename)</argsstring>
        <name>_create_file</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>filename</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="368" column="16" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="368" bodyend="503"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a6234eb717862d124ebbbf9d7d8be74ad" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>void</type>
        <definition>static void _fl_init</definition>
        <argsstring>()</argsstring>
        <name>_fl_init</name>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="66" column="13" declfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" declline="66" declcolumn="13"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a14d8316724acbc77aebf6b8123c35984" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>void</type>
        <definition>static void _free_file</definition>
        <argsstring>(FL_FILE *file)</argsstring>
        <name>_free_file</name>
        <param>
          <type><ref refid="fat__filelib_8h_1ab1659dbb766794c2537f83372fc2705b" kindref="member">FL_FILE</ref> *</type>
          <declname>file</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="104" column="13" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="104" bodyend="110"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a28dd0d69e3a642b68f6664dea08c6c17" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>static int _open_directory</definition>
        <argsstring>(char *path, uint32 *pathCluster)</argsstring>
        <name>_open_directory</name>
        <param>
          <type>char *</type>
          <declname>path</declname>
        </param>
        <param>
          <type><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref> *</type>
          <declname>pathCluster</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="120" column="12" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="120" bodyend="152"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a54d386d40c8ac5b7cb09a051f82e2b9c" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type><ref refid="fat__filelib_8h_1ab1659dbb766794c2537f83372fc2705b" kindref="member">FL_FILE</ref> *</type>
        <definition>static FL_FILE* _open_file</definition>
        <argsstring>(const char *path)</argsstring>
        <name>_open_file</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>path</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="303" column="16" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="303" bodyend="363"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a1239349f2663de0d97e34ee0290b83c5" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref></type>
        <definition>static uint32 _read_sectors</definition>
        <argsstring>(FL_FILE *file, uint32 offset, uint8 *buffer, uint32 count)</argsstring>
        <name>_read_sectors</name>
        <param>
          <type><ref refid="fat__filelib_8h_1ab1659dbb766794c2537f83372fc2705b" kindref="member">FL_FILE</ref> *</type>
          <declname>file</declname>
        </param>
        <param>
          <type><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref></type>
          <declname>offset</declname>
        </param>
        <param>
          <type><ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref> *</type>
          <declname>buffer</declname>
        </param>
        <param>
          <type><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref></type>
          <declname>count</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="508" column="15" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="508" bodyend="575"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1aacb52fae2d79356abbc2570b05990295" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual">
        <type><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref></type>
        <definition>static uint32 _write_sectors</definition>
        <argsstring>(FL_FILE *file, uint32 offset, uint8 *buf, uint32 count)</argsstring>
        <name>_write_sectors</name>
        <param>
          <type><ref refid="fat__filelib_8h_1ab1659dbb766794c2537f83372fc2705b" kindref="member">FL_FILE</ref> *</type>
          <declname>file</declname>
        </param>
        <param>
          <type><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref></type>
          <declname>offset</declname>
        </param>
        <param>
          <type><ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref> *</type>
          <declname>buf</declname>
        </param>
        <param>
          <type><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref></type>
          <declname>count</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="750" column="15" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="750" bodyend="826"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a71ff2c6cb4d49c94ee51db25be152b1d" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>void</type>
        <definition>void fl_attach_locks</definition>
        <argsstring>(void(*lock)(void), void(*unlock)(void))</argsstring>
        <name>fl_attach_locks</name>
        <param>
          <type>void(*)(void)</type>
          <declname>lock</declname>
        </param>
        <param>
          <type>void(*)(void)</type>
          <declname>unlock</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="599" column="6" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="599" bodyend="602"/>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1af9d46bc71dd1953eb78c99d6615ade92" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_attach_media</definition>
        <argsstring>(fn_diskio_read rd, fn_diskio_write wr)</argsstring>
        <name>fl_attach_media</name>
        <param>
          <type><ref refid="fat__access_8h_1aaf031f5384342c34f5a446c5dd5b5ed3" kindref="member">fn_diskio_read</ref></type>
          <declname>rd</declname>
        </param>
        <param>
          <type><ref refid="fat__access_8h_1a8532f8239b515a20628a74e37d5a598e" kindref="member">fn_diskio_write</ref></type>
          <declname>wr</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="606" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="606" bodyend="623"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <referencedby refid="fat_8c_1a29aa9552ba9b567abcf938fe64d4ec95" compoundref="fat_8c" startline="56" endline="99">fat_initialize</referencedby>
        <referencedby refid="example_8c_1acdef7a1fd863a6d3770c1268cb06add3" compoundref="example_8c" startline="44" endline="87">main</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a236effde34fb2dd06c45f88035d0a670" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_closedir</definition>
        <argsstring>(FL_DIR *dir)</argsstring>
        <name>fl_closedir</name>
        <param>
          <type><ref refid="fat__filelib_8h_1a0e185ab27bc0e04a34c4fd884056192a" kindref="member">FL_DIR</ref> *</type>
          <declname>dir</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1451" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1451" bodyend="1454"/>
        <referencedby refid="fat__filelib_8h_1a02c9d78edd8026a5a633724a36849d16" compoundref="fat__filelib_8c" startline="1460" endline="1470">fl_is_dir</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1ab8d071e615bfb315cc0b6a3836e275e2" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_createdirectory</definition>
        <argsstring>(const char *path)</argsstring>
        <name>fl_createdirectory</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>path</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1345" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1345" bodyend="1356"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1aef5675bf1c0db1d3e073ea36d4cf2d3a" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>void</type>
        <definition>void fl_fclose</definition>
        <argsstring>(void *f)</argsstring>
        <name>fl_fclose</name>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="856" column="6" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="856" bodyend="891"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
        <referencedby refid="fat_8c_1a29aa9552ba9b567abcf938fe64d4ec95" compoundref="fat_8c" startline="56" endline="99">fat_initialize</referencedby>
        <referencedby refid="example_8c_1acdef7a1fd863a6d3770c1268cb06add3" compoundref="example_8c" startline="44" endline="87">main</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a870d92346325af5246948e81e33a51d5" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_feof</definition>
        <argsstring>(void *f)</argsstring>
        <name>fl_feof</name>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1125" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1125" bodyend="1142"/>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a6a857e4fbf7fa1ebd7d016e8bab36a94" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_fflush</definition>
        <argsstring>(void *f)</argsstring>
        <name>fl_fflush</name>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="831" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="831" bodyend="852"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1ade02f44157d32df37dc881d3e6702129" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_fgetc</definition>
        <argsstring>(void *f)</argsstring>
        <name>fl_fgetc</name>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="895" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="895" bodyend="904"/>
        <references refid="fat__filelib_8c_1acfc7937a8a1f6846f762a2af33507b66" compoundref="fat__filelib_8c" startline="938" endline="1030">fl_fread</references>
        <referencedby refid="fat__filelib_8h_1adfca2fc192150a8814b2b404c6b31cd7" compoundref="fat__filelib_8c" startline="908" endline="934">fl_fgets</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a3be6a942f1ebea135e5390e409681c00" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_fgetpos</definition>
        <argsstring>(void *f, uint32 *position)</argsstring>
        <name>fl_fgetpos</name>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <param>
          <type><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref> *</type>
          <declname>position</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1097" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1097" bodyend="1111"/>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
        <referencedby refid="fat__filelib_8h_1a1e80992d09dd901c83d9e1d924d642f4" compoundref="fat__filelib_8c" startline="1115" endline="1121">fl_ftell</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1adfca2fc192150a8814b2b404c6b31cd7" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>char *</type>
        <definition>char* fl_fgets</definition>
        <argsstring>(char *s, int n, void *f)</argsstring>
        <name>fl_fgets</name>
        <param>
          <type>char *</type>
          <declname>s</declname>
        </param>
        <param>
          <type>int</type>
          <declname>n</declname>
        </param>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="908" column="6" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="908" bodyend="934"/>
        <references refid="fat__filelib_8c_1ade02f44157d32df37dc881d3e6702129" compoundref="fat__filelib_8c" startline="895" endline="904">fl_fgetc</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a800a79c9fb283c5f5199e08b1f2ada38" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>void *</type>
        <definition>void* fl_fopen</definition>
        <argsstring>(const char *path, const char *mode)</argsstring>
        <name>fl_fopen</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>path</declname>
        </param>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>mode</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="638" column="6" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="638" bodyend="745"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" compoundref="tcpdump_8c" startline="45">file</references>
        <referencedby refid="fat_8c_1a29aa9552ba9b567abcf938fe64d4ec95" compoundref="fat_8c" startline="56" endline="99">fat_initialize</referencedby>
        <referencedby refid="example_8c_1acdef7a1fd863a6d3770c1268cb06add3" compoundref="example_8c" startline="44" endline="87">main</referencedby>
        <referencedby refid="fat_8c_1abcabf6d92d9d68a4dda0b0f8a8a803b5" compoundref="fat_8c" startline="131" endline="169">open_fat</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1af3d1cddac050fee30d1420e68b01e7c2" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_format</definition>
        <argsstring>(uint32 volume_sectors, const char *name)</argsstring>
        <name>fl_format</name>
        <param>
          <type><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref></type>
          <declname>volume_sectors</declname>
        </param>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>name</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1476" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1476" bodyend="1478"/>
        <references refid="fat__format_8c_1a8958cfd5dc4bfceb08f41e50e54da92d" compoundref="fat__format_8c" startline="524" endline="531">fatfs_format</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a4083be2162ea554186859138911f0db1" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_fputc</definition>
        <argsstring>(int c, void *f)</argsstring>
        <name>fl_fputc</name>
        <param>
          <type>int</type>
          <declname>c</declname>
        </param>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1147" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1147" bodyend="1156"/>
        <references refid="fat__filelib_8c_1a8349790c61beca1a9138fb28a2689607" compoundref="fat__filelib_8c" startline="1162" endline="1294">fl_fwrite</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a04f7ea53fa5650e4dca7767b0f9eb72e" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_fputs</definition>
        <argsstring>(const char *str, void *f)</argsstring>
        <name>fl_fputs</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>str</declname>
        </param>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1300" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1300" bodyend="1308"/>
        <references refid="fat__filelib_8c_1a8349790c61beca1a9138fb28a2689607" compoundref="fat__filelib_8c" startline="1162" endline="1294">fl_fwrite</references>
        <references refid="lib_8h_1ae6c8de953239811a34eeeab09458e55e" compoundref="strlen_8c" startline="55" endline="101">strlen</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1acfc7937a8a1f6846f762a2af33507b66" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_fread</definition>
        <argsstring>(void *buffer, int size, int length, void *f)</argsstring>
        <name>fl_fread</name>
        <param>
          <type>void *</type>
          <declname>buffer</declname>
        </param>
        <param>
          <type>int</type>
          <declname>size</declname>
        </param>
        <param>
          <type>int</type>
          <declname>length</declname>
        </param>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="938" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="938" bodyend="1030"/>
        <references refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" compoundref="shell_8c" startline="47">buffer</references>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" compoundref="fat__opts_8h" startline="70">FAT_SECTOR_SIZE</references>
        <references refid="fat__filelib_8h_1ad52d51659a75e25d96fb04d22ff718cb" compoundref="fat__filelib_8h" startline="64">FILE_READ</references>
        <references refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" compoundref="fat__string_8h" startline="17">NULL</references>
        <referencedby refid="fat__filelib_8h_1a3ac89cbc4edd114760c1dbd18e0d594d" compoundref="fat__filelib_8c" startline="895" endline="904">fl_fgetc</referencedby>
        <referencedby refid="fat_8c_1afe837a4cad1bab6f8b8f293cd76059a0" compoundref="fat_8c" startline="101" endline="114">read_fat</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1aca40d99888beddbc51b1a484b3b95757" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_fseek</definition>
        <argsstring>(void *f, long offset, int origin)</argsstring>
        <name>fl_fseek</name>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <param>
          <type>long</type>
          <declname>offset</declname>
        </param>
        <param>
          <type>int</type>
          <declname>origin</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1034" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1034" bodyend="1093"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
        <references refid="fat__filelib_8h_1ad2a2e6c114780c3071efd24f16c7f7d8" compoundref="fat__filelib_8h" startline="16">SEEK_END</references>
        <referencedby refid="fat_8c_1afe837a4cad1bab6f8b8f293cd76059a0" compoundref="fat_8c" startline="101" endline="114">read_fat</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a1e80992d09dd901c83d9e1d924d642f4" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>long</type>
        <definition>long fl_ftell</definition>
        <argsstring>(void *f)</argsstring>
        <name>fl_ftell</name>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1115" column="6" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1115" bodyend="1121"/>
        <references refid="fat__filelib_8c_1a3be6a942f1ebea135e5390e409681c00" compoundref="fat__filelib_8c" startline="1097" endline="1111">fl_fgetpos</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a8349790c61beca1a9138fb28a2689607" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_fwrite</definition>
        <argsstring>(const void *data, int size, int count, void *f)</argsstring>
        <name>fl_fwrite</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> void *</type>
          <declname>data</declname>
        </param>
        <param>
          <type>int</type>
          <declname>size</declname>
        </param>
        <param>
          <type>int</type>
          <declname>count</declname>
        </param>
        <param>
          <type>void *</type>
          <declname>f</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1162" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1162" bodyend="1294"/>
        <references refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" compoundref="shell_8c" startline="47">buffer</references>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
        <referencedby refid="fat_8c_1a29aa9552ba9b567abcf938fe64d4ec95" compoundref="fat_8c" startline="56" endline="99">fat_initialize</referencedby>
        <referencedby refid="fat__filelib_8h_1a8304df4fb0abe6a2d552fa39d8559a2d" compoundref="fat__filelib_8c" startline="1147" endline="1156">fl_fputc</referencedby>
        <referencedby refid="fat__filelib_8h_1a3e374b01d35084aa1eee63e50afdf097" compoundref="fat__filelib_8c" startline="1300" endline="1308">fl_fputs</referencedby>
        <referencedby refid="example_8c_1acdef7a1fd863a6d3770c1268cb06add3" compoundref="example_8c" startline="44" endline="87">main</referencedby>
        <referencedby refid="fat_8c_1a22a997ae15aa6d91cf887f388ce46520" compoundref="fat_8c" startline="116" endline="129">write_fat</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1ac4154a1278a172ab8e6427eb64161179" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>void</type>
        <definition>void fl_init</definition>
        <argsstring>(void)</argsstring>
        <name>fl_init</name>
        <param>
          <type>void</type>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="584" column="6" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="584" bodyend="595"/>
        <referencedby refid="fat_8h_1a8f1a7dc3b3ea2adcdea09c9dbd2ef762" compoundref="fat_8c" startline="179" endline="206">fat_init</referencedby>
        <referencedby refid="example_8c_1acdef7a1fd863a6d3770c1268cb06add3" compoundref="example_8c" startline="44" endline="87">main</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a02c9d78edd8026a5a633724a36849d16" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_is_dir</definition>
        <argsstring>(const char *path)</argsstring>
        <name>fl_is_dir</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>path</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1460" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1460" bodyend="1470"/>
        <references refid="fat__filelib_8c_1a236effde34fb2dd06c45f88035d0a670" compoundref="fat__filelib_8c" startline="1451" endline="1454">fl_closedir</references>
        <references refid="fat__filelib_8c_1a3aba2e202e0af1fb8711eec13e5e9b08" compoundref="fat__filelib_8c" startline="1401" endline="1426">fl_opendir</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a28ef1f43950ba4743e5ddd57db5b8b6e" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>void</type>
        <definition>void fl_listdirectory</definition>
        <argsstring>(const char *path)</argsstring>
        <name>fl_listdirectory</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>path</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1362" column="6" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1362" bodyend="1395"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
        <referencedby refid="example_8c_1acdef7a1fd863a6d3770c1268cb06add3" compoundref="example_8c" startline="44" endline="87">main</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a3aba2e202e0af1fb8711eec13e5e9b08" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type><ref refid="fat__filelib_8h_1a0e185ab27bc0e04a34c4fd884056192a" kindref="member">FL_DIR</ref> *</type>
        <definition>FL_DIR* fl_opendir</definition>
        <argsstring>(const char *path, FL_DIR *dir)</argsstring>
        <name>fl_opendir</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>path</declname>
        </param>
        <param>
          <type><ref refid="fat__filelib_8h_1a0e185ab27bc0e04a34c4fd884056192a" kindref="member">FL_DIR</ref> *</type>
          <declname>dir</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1401" column="8" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1401" bodyend="1426"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="structfs__dir__ent_1a6286cbb9d382cacf4e15b03ffd0c352c" compoundref="fat__access_8h" startline="101">fs_dir_ent::cluster</references>
        <references refid="fat__defs_8h_1a8dd000b545e9a127169fdbd82d418965" compoundref="fat__defs_8h" startline="109">FAT32_INVALID_CLUSTER</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
        <referencedby refid="fat__filelib_8h_1a02c9d78edd8026a5a633724a36849d16" compoundref="fat__filelib_8c" startline="1460" endline="1470">fl_is_dir</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1aa13527c9d4fc15a67a5608d9645b7ad8" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_readdir</definition>
        <argsstring>(FL_DIR *dirls, fl_dirent *entry)</argsstring>
        <name>fl_readdir</name>
        <param>
          <type><ref refid="fat__filelib_8h_1a0e185ab27bc0e04a34c4fd884056192a" kindref="member">FL_DIR</ref> *</type>
          <declname>dirls</declname>
        </param>
        <param>
          <type><ref refid="fat__filelib_8h_1ae511f1d179c3f530088b0f990760eea0" kindref="member">fl_dirent</ref> *</type>
          <declname>entry</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1432" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1432" bodyend="1445"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1ac3e517a9ac192e87329a62e5e8d53b2b" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>int</type>
        <definition>int fl_remove</definition>
        <argsstring>(const char *filename)</argsstring>
        <name>fl_remove</name>
        <param>
          <type><ref refid="cdefs_8h_1a2c212835823e3c54a8ab6d95c652660e" kindref="member">const</ref> char *</type>
          <declname>filename</declname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="1314" column="5" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="1314" bodyend="1339"/>
        <references refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" compoundref="tcpdump_8c" startline="45">file</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
        <referencedby refid="fat_8c_1a29aa9552ba9b567abcf938fe64d4ec95" compoundref="fat_8c" startline="56" endline="99">fat_initialize</referencedby>
        <referencedby refid="example_8c_1acdef7a1fd863a6d3770c1268cb06add3" compoundref="example_8c" startline="44" endline="87">main</referencedby>
      </memberdef>
      <memberdef kind="function" id="fat__filelib_8c_1a9e4ba72f7c41f41f4a31ca5d46de3f5d" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>void</type>
        <definition>void fl_shutdown</definition>
        <argsstring>(void)</argsstring>
        <name>fl_shutdown</name>
        <param>
          <type>void</type>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" line="627" column="6" bodyfile="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c" bodystart="627" bodyend="634"/>
        <references refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" compoundref="fat__filelib_8c" startline="58">CHECK_FL_INIT</references>
        <references refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" compoundref="fat__filelib_8c" startline="60">FL_LOCK</references>
        <referencedby refid="example_8c_1acdef7a1fd863a6d3770c1268cb06add3" compoundref="example_8c" startline="44" endline="87">main</referencedby>
      </memberdef>
      </sectiondef>
    <briefdescription>
    </briefdescription>
    <detaileddescription>
    </detaileddescription>
    <programlisting>
<codeline lineno="1"><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="2"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="3"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>FAT16/32<sp/>File<sp/>IO<sp/>Library</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="4"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>V2.6</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="5"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>Ultra-Embedded.com</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="6"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>Copyright<sp/>2003<sp/>-<sp/>2012</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="7"><highlight class="normal"></highlight><highlight class="comment">//</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="8"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>Email:<sp/>admin@ultra-embedded.com</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="9"><highlight class="normal"></highlight><highlight class="comment">//</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="10"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>License:<sp/>GPL</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="11"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/>If<sp/>you<sp/>would<sp/>like<sp/>a<sp/>version<sp/>with<sp/>a<sp/>more<sp/>permissive<sp/>license<sp/>for<sp/>use<sp/>in</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="12"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/>closed<sp/>source<sp/>commercial<sp/>applications<sp/>please<sp/>contact<sp/>me<sp/>for<sp/>details.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="13"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="14"><highlight class="normal"></highlight><highlight class="comment">//</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="15"><highlight class="normal"></highlight><highlight class="comment">//<sp/>This<sp/>file<sp/>is<sp/>part<sp/>of<sp/>FAT<sp/>File<sp/>IO<sp/>Library.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="16"><highlight class="normal"></highlight><highlight class="comment">//</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="17"><highlight class="normal"></highlight><highlight class="comment">//<sp/>FAT<sp/>File<sp/>IO<sp/>Library<sp/>is<sp/>free<sp/>software;<sp/>you<sp/>can<sp/>redistribute<sp/>it<sp/>and/or<sp/>modify</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="18"><highlight class="normal"></highlight><highlight class="comment">//<sp/>it<sp/>under<sp/>the<sp/>terms<sp/>of<sp/>the<sp/>GNU<sp/>General<sp/>Public<sp/>License<sp/>as<sp/>published<sp/>by</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="19"><highlight class="normal"></highlight><highlight class="comment">//<sp/>the<sp/>Free<sp/>Software<sp/>Foundation;<sp/>either<sp/>version<sp/>2<sp/>of<sp/>the<sp/>License,<sp/>or</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="20"><highlight class="normal"></highlight><highlight class="comment">//<sp/>(at<sp/>your<sp/>option)<sp/>any<sp/>later<sp/>version.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="21"><highlight class="normal"></highlight><highlight class="comment">//</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="22"><highlight class="normal"></highlight><highlight class="comment">//<sp/>FAT<sp/>File<sp/>IO<sp/>Library<sp/>is<sp/>distributed<sp/>in<sp/>the<sp/>hope<sp/>that<sp/>it<sp/>will<sp/>be<sp/>useful,</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="23"><highlight class="normal"></highlight><highlight class="comment">//<sp/>but<sp/>WITHOUT<sp/>ANY<sp/>WARRANTY;<sp/>without<sp/>even<sp/>the<sp/>implied<sp/>warranty<sp/>of</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="24"><highlight class="normal"></highlight><highlight class="comment">//<sp/>MERCHANTABILITY<sp/>or<sp/>FITNESS<sp/>FOR<sp/>A<sp/>PARTICULAR<sp/>PURPOSE.<sp/><sp/>See<sp/>the</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="25"><highlight class="normal"></highlight><highlight class="comment">//<sp/>GNU<sp/>General<sp/>Public<sp/>License<sp/>for<sp/>more<sp/>details.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="26"><highlight class="normal"></highlight><highlight class="comment">//</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="27"><highlight class="normal"></highlight><highlight class="comment">//<sp/>You<sp/>should<sp/>have<sp/>received<sp/>a<sp/>copy<sp/>of<sp/>the<sp/>GNU<sp/>General<sp/>Public<sp/>License</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="28"><highlight class="normal"></highlight><highlight class="comment">//<sp/>along<sp/>with<sp/>FAT<sp/>File<sp/>IO<sp/>Library;<sp/>if<sp/>not,<sp/>write<sp/>to<sp/>the<sp/>Free<sp/>Software</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="29"><highlight class="normal"></highlight><highlight class="comment">//<sp/>Foundation,<sp/>Inc.,<sp/>59<sp/>Temple<sp/>Place,<sp/>Suite<sp/>330,<sp/>Boston,<sp/>MA<sp/><sp/>02111-1307<sp/><sp/>USA</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="30"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="31"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="32"><highlight class="normal"></highlight><highlight class="comment">//#include<sp/>&lt;stdlib.h&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="33"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;<ref refid="string_8h" kindref="compound">string.h</ref>&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="34"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="fat__defs_8h" kindref="compound">fat_defs.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="35"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="fat__access_8h" kindref="compound">fat_access.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="36"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="fat__table_8h" kindref="compound">fat_table.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="37"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="fat__write_8h" kindref="compound">fat_write.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="38"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="fat__misc_8h" kindref="compound">fat_misc.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="39"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="fat__string_8h" kindref="compound">fat_string.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="40"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="fat__filelib_8h" kindref="compound">fat_filelib.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="41"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="fat__cache_8h" kindref="compound">fat_cache.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="42"><highlight class="normal"></highlight></codeline>
<codeline lineno="43"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="44"><highlight class="normal"></highlight><highlight class="comment">//<sp/>Locals</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="45"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="46"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>_files[<ref refid="fat__opts_8h_1afa06a8fa57091187d821deea2ffe93b9" kindref="member">FATFS_MAX_OPEN_FILES</ref>];</highlight></codeline>
<codeline lineno="47"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>_filelib_init<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="48"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>_filelib_valid<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="49"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfatfs" kindref="compound">fatfs</ref><sp/>_fs;</highlight></codeline>
<codeline lineno="50"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfat__list" kindref="compound">fat_list</ref><sp/>_open_file_list;</highlight></codeline>
<codeline lineno="51"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfat__list" kindref="compound">fat_list</ref><sp/>_free_file_list;</highlight></codeline>
<codeline lineno="52"><highlight class="normal"></highlight></codeline>
<codeline lineno="53"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="54"><highlight class="normal"></highlight><highlight class="comment">//<sp/>Macros</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="55"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="56"><highlight class="normal"></highlight></codeline>
<codeline lineno="57"><highlight class="normal"></highlight><highlight class="comment">//<sp/>Macro<sp/>for<sp/>checking<sp/>if<sp/>file<sp/>lib<sp/>is<sp/>initialised</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="58" refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" refkind="member"><highlight class="normal"></highlight><highlight class="preprocessor">#define<sp/>CHECK_FL_INIT()<sp/><sp/><sp/><sp/><sp/>{<sp/>if<sp/>(_filelib_init==0)<sp/>fl_init();<sp/>}</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="59"><highlight class="normal"></highlight></codeline>
<codeline lineno="60" refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" refkind="member"><highlight class="normal"></highlight><highlight class="preprocessor">#define<sp/>FL_LOCK(a)<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>do<sp/>{<sp/>if<sp/>((a)-&gt;fl_lock)<sp/>(a)-&gt;fl_lock();<sp/>}<sp/>while<sp/>(0)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="61" refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" refkind="member"><highlight class="normal"></highlight><highlight class="preprocessor">#define<sp/>FL_UNLOCK(a)<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>do<sp/>{<sp/>if<sp/>((a)-&gt;fl_unlock)<sp/>(a)-&gt;fl_unlock();<sp/>}<sp/>while<sp/>(0)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="62"><highlight class="normal"></highlight></codeline>
<codeline lineno="63"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="64"><highlight class="normal"></highlight><highlight class="comment">//<sp/>Local<sp/>Functions</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="65"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="66"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>_fl_init();</highlight></codeline>
<codeline lineno="67"><highlight class="normal"></highlight></codeline>
<codeline lineno="68"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="69"><highlight class="normal"></highlight><highlight class="comment">//<sp/>_allocate_file:<sp/>Find<sp/>a<sp/>slot<sp/>in<sp/>the<sp/>open<sp/>files<sp/>buffer<sp/>for<sp/>a<sp/>new<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="70"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="71"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*<sp/>_allocate_file(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="72"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Allocate<sp/>free<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="73"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfat__node" kindref="compound">fat_node</ref><sp/>*node<sp/>=<sp/>fat_list_pop_head(&amp;_free_file_list);</highlight></codeline>
<codeline lineno="74"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Add<sp/>to<sp/>open<sp/>list</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="75"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(node)</highlight></codeline>
<codeline lineno="76"><highlight class="normal"><sp/><sp/><sp/><sp/>fat_list_insert_last(&amp;_open_file_list,<sp/>node);</highlight></codeline>
<codeline lineno="77"><highlight class="normal"></highlight></codeline>
<codeline lineno="78"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__list_8h_1aab53a0527ed2fb648a6adc61e791fe62" kindref="member">fat_list_entry</ref>(node,<sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>,<sp/>list_node);</highlight></codeline>
<codeline lineno="79"><highlight class="normal">}</highlight></codeline>
<codeline lineno="80"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="81"><highlight class="normal"></highlight><highlight class="comment">//<sp/>_check_file_open:<sp/>Returns<sp/>true<sp/>if<sp/>the<sp/>file<sp/>is<sp/>already<sp/>open</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="82"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="83"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>_check_file_open(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref>)<sp/>{</highlight></codeline>
<codeline lineno="84"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfat__node" kindref="compound">fat_node</ref><sp/>*node;</highlight></codeline>
<codeline lineno="85"><highlight class="normal"></highlight></codeline>
<codeline lineno="86"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Compare<sp/>open<sp/>files</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="87"><highlight class="normal"><sp/><sp/><ref refid="fat__list_8h_1ae758b8b3afc33eb7dc35c7c0cf2e768b" kindref="member">fat_list_for_each</ref>(&amp;_open_file_list,<sp/>node)</highlight></codeline>
<codeline lineno="88"><highlight class="normal"><sp/><sp/>{</highlight></codeline>
<codeline lineno="89"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*openFile<sp/>=<sp/><ref refid="fat__list_8h_1aab53a0527ed2fb648a6adc61e791fe62" kindref="member">fat_list_entry</ref>(node,<sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>,<sp/>list_node);</highlight></codeline>
<codeline lineno="90"><highlight class="normal"></highlight></codeline>
<codeline lineno="91"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>not<sp/>the<sp/>current<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="92"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(openFile<sp/>!=<sp/><ref refid="structfile" kindref="compound">file</ref>)<sp/>{</highlight></codeline>
<codeline lineno="93"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Compare<sp/>path<sp/>and<sp/>name</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="94"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((<ref refid="fat__string_8c_1a88289160199a24ccb76d819a07c47921" kindref="member">fatfs_compare_names</ref>(openFile-&gt;<ref refid="structsFL__FILE_1ac711b022c3ad32744cf964bd27f6359c" kindref="member">path</ref>,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;path))<sp/>&amp;&amp;<sp/>(<ref refid="fat__string_8c_1a88289160199a24ccb76d819a07c47921" kindref="member">fatfs_compare_names</ref>(openFile-&gt;<ref refid="structsFL__FILE_1a555306a9493ae9b64a236bbeb43436cf" kindref="member">filename</ref>,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename)))</highlight></codeline>
<codeline lineno="95"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>1;</highlight></codeline>
<codeline lineno="96"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="97"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="98"><highlight class="normal"></highlight></codeline>
<codeline lineno="99"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="100"><highlight class="normal">}</highlight></codeline>
<codeline lineno="101"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="102"><highlight class="normal"></highlight><highlight class="comment">//<sp/>_free_file:<sp/>Free<sp/>open<sp/>file<sp/>handle</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="103"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="104"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>_free_file(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref>)<sp/>{</highlight></codeline>
<codeline lineno="105"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Remove<sp/>from<sp/>open<sp/>list</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="106"><highlight class="normal"><sp/><sp/>fat_list_remove(&amp;_open_file_list,<sp/>&amp;<ref refid="structfile" kindref="compound">file</ref>-&gt;list_node);</highlight></codeline>
<codeline lineno="107"><highlight class="normal"></highlight></codeline>
<codeline lineno="108"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Add<sp/>to<sp/>free<sp/>list</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="109"><highlight class="normal"><sp/><sp/>fat_list_insert_last(&amp;_free_file_list,<sp/>&amp;<ref refid="structfile" kindref="compound">file</ref>-&gt;list_node);</highlight></codeline>
<codeline lineno="110"><highlight class="normal">}</highlight></codeline>
<codeline lineno="111"><highlight class="normal"></highlight></codeline>
<codeline lineno="112"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="113"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>Low<sp/>Level</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="114"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="115"><highlight class="normal"></highlight></codeline>
<codeline lineno="116"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="117"><highlight class="normal"></highlight><highlight class="comment">//<sp/>_open_directory:<sp/>Cycle<sp/>through<sp/>path<sp/>string<sp/>to<sp/>find<sp/>the<sp/>start<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="118"><highlight class="normal"></highlight><highlight class="comment">//<sp/>address<sp/>of<sp/>the<sp/>highest<sp/>subdir.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="119"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="120"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>_open_directory(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*path,<sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>*pathCluster)<sp/>{</highlight></codeline>
<codeline lineno="121"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>levels;</highlight></codeline>
<codeline lineno="122"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>sublevel;</highlight></codeline>
<codeline lineno="123"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>currentfolder[<ref refid="fat__opts_8h_1a0512aa1c7fba93172e1ff275e5046dd4" kindref="member">FATFS_MAX_LONG_FILENAME</ref>];</highlight></codeline>
<codeline lineno="124"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfat__dir__entry" kindref="compound">fat_dir_entry</ref><sp/>sfEntry;</highlight></codeline>
<codeline lineno="125"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>startcluster;</highlight></codeline>
<codeline lineno="126"><highlight class="normal"></highlight></codeline>
<codeline lineno="127"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Set<sp/>starting<sp/>cluster<sp/>to<sp/>root<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="128"><highlight class="normal"><sp/><sp/>startcluster<sp/>=<sp/><ref refid="fat__access_8c_1a6d36c74c7a9ba228d327067786ecb0c2" kindref="member">fatfs_get_root_cluster</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="129"><highlight class="normal"></highlight></codeline>
<codeline lineno="130"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Find<sp/>number<sp/>of<sp/>levels</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="131"><highlight class="normal"><sp/><sp/>levels<sp/>=<sp/><ref refid="fat__string_8c_1aa3ef1d2590f2284ef1f983d6f7b2ad29" kindref="member">fatfs_total_path_levels</ref>(path);</highlight></codeline>
<codeline lineno="132"><highlight class="normal"></highlight></codeline>
<codeline lineno="133"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Cycle<sp/>through<sp/>each<sp/>level<sp/>and<sp/>get<sp/>the<sp/>start<sp/>sector</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="134"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(sublevel<sp/>=<sp/>0;<sp/>sublevel<sp/>&lt;<sp/>(levels<sp/>+<sp/>1);<sp/>sublevel++)<sp/>{</highlight></codeline>
<codeline lineno="135"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__string_8c_1af78d4ac644689020e4a75fc7fb2bc8fb" kindref="member">fatfs_get_substring</ref>(path,<sp/>sublevel,<sp/>currentfolder,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(currentfolder))<sp/>==<sp/>-1)</highlight></codeline>
<codeline lineno="136"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="137"><highlight class="normal"></highlight></codeline>
<codeline lineno="138"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Find<sp/>clusteraddress<sp/>for<sp/>folder<sp/>(currentfolder)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="139"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a0585d01a38409645830c9e7f57a4bf1b" kindref="member">fatfs_get_file_entry</ref>(&amp;_fs,<sp/>startcluster,<sp/>currentfolder,<sp/>&amp;sfEntry))<sp/>{</highlight></codeline>
<codeline lineno="140"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>entry<sp/>is<sp/>folder</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="141"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__misc_8c_1adca70c7e5b6a384a99baf9e1ecb9d1a8" kindref="member">fatfs_entry_is_dir</ref>(&amp;sfEntry))</highlight></codeline>
<codeline lineno="142"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>startcluster<sp/>=<sp/>((<ref refid="fat__types_8h_1abbb9c5db3bb96b1398c9b011870c335b" kindref="member">FAT_HTONS</ref>((<ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>)sfEntry.FstClusHI))<sp/>&lt;&lt;<sp/>16)<sp/>+<sp/><ref refid="fat__types_8h_1abbb9c5db3bb96b1398c9b011870c335b" kindref="member">FAT_HTONS</ref>(sfEntry.FstClusLO);</highlight></codeline>
<codeline lineno="143"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="144"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="145"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="146"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="147"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="148"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="149"><highlight class="normal"></highlight></codeline>
<codeline lineno="150"><highlight class="normal"><sp/><sp/>*pathCluster<sp/>=<sp/>startcluster;</highlight></codeline>
<codeline lineno="151"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>1;</highlight></codeline>
<codeline lineno="152"><highlight class="normal">}</highlight></codeline>
<codeline lineno="153"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="154"><highlight class="normal"></highlight><highlight class="comment">//<sp/>_create_directory:<sp/>Cycle<sp/>through<sp/>path<sp/>string<sp/>and<sp/>create<sp/>the<sp/>end<sp/>directory</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="155"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="156"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="157"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>_create_directory(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*path)<sp/>{</highlight></codeline>
<codeline lineno="158"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" kindref="member">file</ref>;</highlight></codeline>
<codeline lineno="159"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfat__dir__entry" kindref="compound">fat_dir_entry</ref><sp/>sfEntry;</highlight></codeline>
<codeline lineno="160"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>shortFilename[<ref refid="fat__defs_8h_1a0918d60f1f01721da31d3b2b0f79f7aa" kindref="member">FAT_SFN_SIZE_FULL</ref>];</highlight></codeline>
<codeline lineno="161"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>tailNum<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="162"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i;</highlight></codeline>
<codeline lineno="163"><highlight class="normal"></highlight></codeline>
<codeline lineno="164"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Allocate<sp/>a<sp/>new<sp/>file<sp/>handle</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="165"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>_allocate_file();</highlight></codeline>
<codeline lineno="166"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="structfile" kindref="compound">file</ref>)</highlight></codeline>
<codeline lineno="167"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="168"><highlight class="normal"></highlight></codeline>
<codeline lineno="169"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Clear<sp/>filename</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="170"><highlight class="normal"><sp/><sp/><ref refid="string_8h_1ace4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;path,<sp/></highlight><highlight class="charliteral">&apos;\0&apos;</highlight><highlight class="normal">,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;path));</highlight></codeline>
<codeline lineno="171"><highlight class="normal"><sp/><sp/><ref refid="string_8h_1ace4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/></highlight><highlight class="charliteral">&apos;\0&apos;</highlight><highlight class="normal">,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;filename));</highlight></codeline>
<codeline lineno="172"><highlight class="normal"></highlight></codeline>
<codeline lineno="173"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Split<sp/>full<sp/>path<sp/>into<sp/>filename<sp/>and<sp/>directory<sp/>path</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="174"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__string_8c_1a556702f8d10b5cadd5598170d41425b8" kindref="member">fatfs_split_path</ref>((</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/>path,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;path,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;path),<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;filename))<sp/>==<sp/>-1)<sp/>{</highlight></codeline>
<codeline lineno="175"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="176"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="177"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="178"><highlight class="normal"></highlight></codeline>
<codeline lineno="179"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>file<sp/>already<sp/>open</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="180"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(_check_file_open(<ref refid="structfile" kindref="compound">file</ref>))<sp/>{</highlight></codeline>
<codeline lineno="181"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="182"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="183"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="184"><highlight class="normal"></highlight></codeline>
<codeline lineno="185"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>file<sp/>is<sp/>in<sp/>the<sp/>root<sp/>dir</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="186"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;path[0]<sp/>==<sp/>0)</highlight></codeline>
<codeline lineno="187"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster<sp/>=<sp/><ref refid="fat__access_8c_1a6d36c74c7a9ba228d327067786ecb0c2" kindref="member">fatfs_get_root_cluster</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="188"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="189"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Find<sp/>parent<sp/>directory<sp/>start<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="190"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!_open_directory(<ref refid="structfile" kindref="compound">file</ref>-&gt;path,<sp/>&amp;<ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster))<sp/>{</highlight></codeline>
<codeline lineno="191"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="192"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="193"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="194"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="195"><highlight class="normal"></highlight></codeline>
<codeline lineno="196"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>same<sp/>filename<sp/>exists<sp/>in<sp/>directory</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="197"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a0585d01a38409645830c9e7f57a4bf1b" kindref="member">fatfs_get_file_entry</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/>&amp;sfEntry)<sp/>==<sp/>1)<sp/>{</highlight></codeline>
<codeline lineno="198"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="199"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="200"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="201"><highlight class="normal"></highlight></codeline>
<codeline lineno="202"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="203"><highlight class="normal"></highlight></codeline>
<codeline lineno="204"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Create<sp/>the<sp/>file<sp/>space<sp/>for<sp/>the<sp/>folder<sp/>(at<sp/>least<sp/>one<sp/>clusters<sp/>worth!)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="205"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__write_8c_1a68d609a89800a61f700b18500a56d30a" kindref="member">fatfs_allocate_free_space</ref>(&amp;_fs,<sp/>1,<sp/>&amp;<ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster,<sp/>1))<sp/>{</highlight></codeline>
<codeline lineno="206"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="207"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="208"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="209"><highlight class="normal"></highlight></codeline>
<codeline lineno="210"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Erase<sp/>new<sp/>directory<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="211"><highlight class="normal"><sp/><sp/><ref refid="string_8h_1ace4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_sector,<sp/>0x00,<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>);</highlight></codeline>
<codeline lineno="212"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref>;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="213"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__access_8c_1aba0dfdb700ff90e17883a8fea582f491" kindref="member">fatfs_write_sector</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster,<sp/>i,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_sector))<sp/>{</highlight></codeline>
<codeline lineno="214"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="215"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="216"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="217"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="218"><highlight class="normal"></highlight></codeline>
<codeline lineno="219"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_LFN_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="220"><highlight class="normal"></highlight></codeline>
<codeline lineno="221"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Generate<sp/>a<sp/>short<sp/>filename<sp/>&amp;<sp/>tail</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="222"><highlight class="normal"><sp/><sp/>tailNum<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="223"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">do</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="224"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Create<sp/>a<sp/>standard<sp/>short<sp/>filename<sp/>(without<sp/>tail)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="225"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__misc_8c_1a25a4d4a522ffdb06b4fab094d05b1763" kindref="member">fatfs_lfn_create_sfn</ref>(shortFilename,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename);</highlight></codeline>
<codeline lineno="226"><highlight class="normal"></highlight></codeline>
<codeline lineno="227"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>second<sp/>hit<sp/>or<sp/>more,<sp/>generate<sp/>a<sp/>~n<sp/>tail</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="228"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(tailNum<sp/>!=<sp/>0)</highlight></codeline>
<codeline lineno="229"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__misc_8c_1a140f2ac336bea9e8c945b6357fc65083" kindref="member">fatfs_lfn_generate_tail</ref>((</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/>shortFilename,<sp/>tailNum);</highlight></codeline>
<codeline lineno="230"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Try<sp/>with<sp/>no<sp/>tail<sp/>if<sp/>first<sp/>entry</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="231"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="232"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="string_8h_1ae33b18edb618c656b9b795b9fce2316c" kindref="member">memcpy</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/>shortFilename,<sp/><ref refid="fat__defs_8h_1a0918d60f1f01721da31d3b2b0f79f7aa" kindref="member">FAT_SFN_SIZE_FULL</ref>);</highlight></codeline>
<codeline lineno="233"><highlight class="normal"></highlight></codeline>
<codeline lineno="234"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>entry<sp/>exists<sp/>already<sp/>or<sp/>not</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="235"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a8bdad35bc1dd908eda5d02f47a8d73d4" kindref="member">fatfs_sfn_exists</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename)<sp/>==<sp/>0)</highlight></codeline>
<codeline lineno="236"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="237"><highlight class="normal"></highlight></codeline>
<codeline lineno="238"><highlight class="normal"><sp/><sp/><sp/><sp/>tailNum++;</highlight></codeline>
<codeline lineno="239"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(tailNum<sp/>&lt;<sp/>9999);</highlight></codeline>
<codeline lineno="240"><highlight class="normal"></highlight></codeline>
<codeline lineno="241"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>We<sp/>reached<sp/>the<sp/>max<sp/>number<sp/>of<sp/>duplicate<sp/>short<sp/>file<sp/>names<sp/>(unlikely!)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="242"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(tailNum<sp/>==<sp/>9999)<sp/>{</highlight></codeline>
<codeline lineno="243"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>allocated<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="244"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a7a329446088ccb4d6348f05fcd848ee4" kindref="member">fatfs_free_cluster_chain</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster);</highlight></codeline>
<codeline lineno="245"><highlight class="normal"></highlight></codeline>
<codeline lineno="246"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="247"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="248"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="249"><highlight class="normal"></highlight><highlight class="preprocessor">#else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="250"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Create<sp/>a<sp/>standard<sp/>short<sp/>filename<sp/>(without<sp/>tail)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="251"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__misc_8c_1a25a4d4a522ffdb06b4fab094d05b1763" kindref="member">fatfs_lfn_create_sfn</ref>(shortFilename,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename))</highlight></codeline>
<codeline lineno="252"><highlight class="normal"><sp/><sp/><sp/><sp/>{</highlight></codeline>
<codeline lineno="253"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>allocated<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="254"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a7a329446088ccb4d6348f05fcd848ee4" kindref="member">fatfs_free_cluster_chain</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster);</highlight></codeline>
<codeline lineno="255"><highlight class="normal"></highlight></codeline>
<codeline lineno="256"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="257"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="258"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="259"><highlight class="normal"></highlight></codeline>
<codeline lineno="260"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Copy<sp/>to<sp/>SFN<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="261"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="string_8h_1ae33b18edb618c656b9b795b9fce2316c" kindref="member">memcpy</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/>shortFilename,<sp/><ref refid="fat__defs_8h_1a0918d60f1f01721da31d3b2b0f79f7aa" kindref="member">FAT_SFN_SIZE_FULL</ref>);</highlight></codeline>
<codeline lineno="262"><highlight class="normal"></highlight></codeline>
<codeline lineno="263"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>entry<sp/>exists<sp/>already</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="264"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a8bdad35bc1dd908eda5d02f47a8d73d4" kindref="member">fatfs_sfn_exists</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename))</highlight></codeline>
<codeline lineno="265"><highlight class="normal"><sp/><sp/><sp/><sp/>{</highlight></codeline>
<codeline lineno="266"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>allocated<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="267"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a7a329446088ccb4d6348f05fcd848ee4" kindref="member">fatfs_free_cluster_chain</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster);</highlight></codeline>
<codeline lineno="268"><highlight class="normal"></highlight></codeline>
<codeline lineno="269"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="270"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="271"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="272"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="273"><highlight class="normal"></highlight></codeline>
<codeline lineno="274"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Add<sp/>file<sp/>to<sp/>disk</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="275"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__write_8c_1a1d762d2afde765d8848e7eaff4dd2fb1" kindref="member">fatfs_add_file_entry</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster,<sp/>0,<sp/>1))<sp/>{</highlight></codeline>
<codeline lineno="276"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>allocated<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="277"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a7a329446088ccb4d6348f05fcd848ee4" kindref="member">fatfs_free_cluster_chain</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster);</highlight></codeline>
<codeline lineno="278"><highlight class="normal"></highlight></codeline>
<codeline lineno="279"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="280"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="281"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="282"><highlight class="normal"></highlight></codeline>
<codeline lineno="283"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>General</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="284"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="285"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="286"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="287"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="288"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength_changed<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="289"><highlight class="normal"></highlight></codeline>
<codeline lineno="290"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Quick<sp/>lookup<sp/>for<sp/>next<sp/>link<sp/>in<sp/>the<sp/>chain</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="291"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="292"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.CurrentCluster<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="293"><highlight class="normal"></highlight></codeline>
<codeline lineno="294"><highlight class="normal"><sp/><sp/><ref refid="fat__table_8c_1a4122bbba15645ebdeea241ef7bcb663e" kindref="member">fatfs_fat_purge</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="295"><highlight class="normal"></highlight></codeline>
<codeline lineno="296"><highlight class="normal"><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="297"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>1;</highlight></codeline>
<codeline lineno="298"><highlight class="normal">}</highlight></codeline>
<codeline lineno="299"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="300"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="301"><highlight class="normal"></highlight><highlight class="comment">//<sp/>_open_file:<sp/>Open<sp/>a<sp/>file<sp/>for<sp/>reading</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="302"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="303"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*<sp/>_open_file(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*path)<sp/>{</highlight></codeline>
<codeline lineno="304"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" kindref="member">file</ref>;</highlight></codeline>
<codeline lineno="305"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfat__dir__entry" kindref="compound">fat_dir_entry</ref><sp/>sfEntry;</highlight></codeline>
<codeline lineno="306"><highlight class="normal"></highlight></codeline>
<codeline lineno="307"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Allocate<sp/>a<sp/>new<sp/>file<sp/>handle</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="308"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>_allocate_file();</highlight></codeline>
<codeline lineno="309"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="structfile" kindref="compound">file</ref>)</highlight></codeline>
<codeline lineno="310"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="311"><highlight class="normal"></highlight></codeline>
<codeline lineno="312"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Clear<sp/>filename</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="313"><highlight class="normal"><sp/><sp/><ref refid="string_8h_1ace4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;path,<sp/></highlight><highlight class="charliteral">&apos;\0&apos;</highlight><highlight class="normal">,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;path));</highlight></codeline>
<codeline lineno="314"><highlight class="normal"><sp/><sp/><ref refid="string_8h_1ace4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/></highlight><highlight class="charliteral">&apos;\0&apos;</highlight><highlight class="normal">,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;filename));</highlight></codeline>
<codeline lineno="315"><highlight class="normal"></highlight></codeline>
<codeline lineno="316"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Split<sp/>full<sp/>path<sp/>into<sp/>filename<sp/>and<sp/>directory<sp/>path</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="317"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__string_8c_1a556702f8d10b5cadd5598170d41425b8" kindref="member">fatfs_split_path</ref>((</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/>path,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;path,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;path),<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;filename))<sp/>==<sp/>-1)<sp/>{</highlight></codeline>
<codeline lineno="318"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="319"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="320"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="321"><highlight class="normal"></highlight></codeline>
<codeline lineno="322"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>file<sp/>already<sp/>open</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="323"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(_check_file_open(<ref refid="structfile" kindref="compound">file</ref>))<sp/>{</highlight></codeline>
<codeline lineno="324"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="325"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="326"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="327"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>file<sp/>is<sp/>in<sp/>the<sp/>root<sp/>dir</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="328"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;path[0]<sp/>==<sp/>0)</highlight></codeline>
<codeline lineno="329"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster<sp/>=<sp/><ref refid="fat__access_8c_1a6d36c74c7a9ba228d327067786ecb0c2" kindref="member">fatfs_get_root_cluster</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="330"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="331"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Find<sp/>parent<sp/>directory<sp/>start<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="332"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!_open_directory(<ref refid="structfile" kindref="compound">file</ref>-&gt;path,<sp/>&amp;<ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster))<sp/>{</highlight></codeline>
<codeline lineno="333"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="334"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="335"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="336"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="337"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Using<sp/>dir<sp/>cluster<sp/>address<sp/>search<sp/>for<sp/>filename</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="338"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a0585d01a38409645830c9e7f57a4bf1b" kindref="member">fatfs_get_file_entry</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/>&amp;sfEntry))<sp/>{</highlight></codeline>
<codeline lineno="339"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Make<sp/>sure<sp/>entry<sp/>is<sp/>file<sp/>not<sp/>dir!</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="340"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__misc_8c_1a11542caa285662d2b04f9d504f8f9e87" kindref="member">fatfs_entry_is_file</ref>(&amp;sfEntry))<sp/>{</highlight></codeline>
<codeline lineno="341"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Initialise<sp/>file<sp/>details</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="342"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="string_8h_1ae33b18edb618c656b9b795b9fce2316c" kindref="member">memcpy</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/>sfEntry.Name,<sp/><ref refid="fat__defs_8h_1a0918d60f1f01721da31d3b2b0f79f7aa" kindref="member">FAT_SFN_SIZE_FULL</ref>);</highlight></codeline>
<codeline lineno="343"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength<sp/>=<sp/><ref refid="fat__types_8h_1a79f47acd161cf6d4943a43745c179a6e" kindref="member">FAT_HTONL</ref>(sfEntry.FileSize);</highlight></codeline>
<codeline lineno="344"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="345"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster<sp/>=<sp/>((<ref refid="fat__types_8h_1abbb9c5db3bb96b1398c9b011870c335b" kindref="member">FAT_HTONS</ref>((<ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>)sfEntry.FstClusHI))<sp/>&lt;&lt;<sp/>16)<sp/>+<sp/><ref refid="fat__types_8h_1abbb9c5db3bb96b1398c9b011870c335b" kindref="member">FAT_HTONS</ref>(sfEntry.FstClusLO);</highlight></codeline>
<codeline lineno="346"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="347"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="348"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength_changed<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="349"><highlight class="normal"></highlight></codeline>
<codeline lineno="350"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Quick<sp/>lookup<sp/>for<sp/>next<sp/>link<sp/>in<sp/>the<sp/>chain</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="351"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="352"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.CurrentCluster<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="353"><highlight class="normal"></highlight></codeline>
<codeline lineno="354"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__cache_8c_1a205d74e989d0e076b031ea2990370c4d" kindref="member">fatfs_cache_init</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="355"><highlight class="normal"></highlight></codeline>
<codeline lineno="356"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a4122bbba15645ebdeea241ef7bcb663e" kindref="member">fatfs_fat_purge</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="357"><highlight class="normal"></highlight></codeline>
<codeline lineno="358"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" kindref="member">file</ref>;</highlight></codeline>
<codeline lineno="359"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="360"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="361"><highlight class="normal"><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="362"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="363"><highlight class="normal">}</highlight></codeline>
<codeline lineno="364"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="365"><highlight class="normal"></highlight><highlight class="comment">//<sp/>_create_file:<sp/>Create<sp/>a<sp/>new<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="366"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="367"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="368"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*<sp/>_create_file(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*filename)<sp/>{</highlight></codeline>
<codeline lineno="369"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" kindref="member">file</ref>;</highlight></codeline>
<codeline lineno="370"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfat__dir__entry" kindref="compound">fat_dir_entry</ref><sp/>sfEntry;</highlight></codeline>
<codeline lineno="371"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>shortFilename[<ref refid="fat__defs_8h_1a0918d60f1f01721da31d3b2b0f79f7aa" kindref="member">FAT_SFN_SIZE_FULL</ref>];</highlight></codeline>
<codeline lineno="372"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>tailNum<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="373"><highlight class="normal"></highlight></codeline>
<codeline lineno="374"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>No<sp/>write<sp/>access?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="375"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!_fs.<ref refid="structfatfs_1abe586c938c51e38d3d1c247e42a7bca9" kindref="member">disk_io</ref>.<ref refid="structdisk__if_1a94687066cd6e4df9e905358b73c67603" kindref="member">write_media</ref>)</highlight></codeline>
<codeline lineno="376"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="377"><highlight class="normal"></highlight></codeline>
<codeline lineno="378"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Allocate<sp/>a<sp/>new<sp/>file<sp/>handle</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="379"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>_allocate_file();</highlight></codeline>
<codeline lineno="380"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="structfile" kindref="compound">file</ref>)</highlight></codeline>
<codeline lineno="381"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="382"><highlight class="normal"></highlight></codeline>
<codeline lineno="383"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Clear<sp/>filename</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="384"><highlight class="normal"><sp/><sp/><ref refid="string_8h_1ace4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;path,<sp/></highlight><highlight class="charliteral">&apos;\0&apos;</highlight><highlight class="normal">,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;path));</highlight></codeline>
<codeline lineno="385"><highlight class="normal"><sp/><sp/><ref refid="string_8h_1ace4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/></highlight><highlight class="charliteral">&apos;\0&apos;</highlight><highlight class="normal">,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;filename));</highlight></codeline>
<codeline lineno="386"><highlight class="normal"></highlight></codeline>
<codeline lineno="387"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Split<sp/>full<sp/>path<sp/>into<sp/>filename<sp/>and<sp/>directory<sp/>path</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="388"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__string_8c_1a556702f8d10b5cadd5598170d41425b8" kindref="member">fatfs_split_path</ref>((</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/>filename,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;path,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;path),<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfile" kindref="compound">file</ref>-&gt;filename))<sp/>==<sp/>-1)<sp/>{</highlight></codeline>
<codeline lineno="389"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="390"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="391"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="392"><highlight class="normal"></highlight></codeline>
<codeline lineno="393"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>file<sp/>already<sp/>open</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="394"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(_check_file_open(<ref refid="structfile" kindref="compound">file</ref>))<sp/>{</highlight></codeline>
<codeline lineno="395"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="396"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="397"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="398"><highlight class="normal"></highlight></codeline>
<codeline lineno="399"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>file<sp/>is<sp/>in<sp/>the<sp/>root<sp/>dir</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="400"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;path[0]<sp/>==<sp/>0)</highlight></codeline>
<codeline lineno="401"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster<sp/>=<sp/><ref refid="fat__access_8c_1a6d36c74c7a9ba228d327067786ecb0c2" kindref="member">fatfs_get_root_cluster</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="402"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="403"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Find<sp/>parent<sp/>directory<sp/>start<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="404"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!_open_directory(<ref refid="structfile" kindref="compound">file</ref>-&gt;path,<sp/>&amp;<ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster))<sp/>{</highlight></codeline>
<codeline lineno="405"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="406"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="407"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="408"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="409"><highlight class="normal"></highlight></codeline>
<codeline lineno="410"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>same<sp/>filename<sp/>exists<sp/>in<sp/>directory</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="411"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a0585d01a38409645830c9e7f57a4bf1b" kindref="member">fatfs_get_file_entry</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/>&amp;sfEntry)<sp/>==<sp/>1)<sp/>{</highlight></codeline>
<codeline lineno="412"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="413"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="414"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="415"><highlight class="normal"></highlight></codeline>
<codeline lineno="416"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="417"><highlight class="normal"></highlight></codeline>
<codeline lineno="418"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Create<sp/>the<sp/>file<sp/>space<sp/>for<sp/>the<sp/>file<sp/>(at<sp/>least<sp/>one<sp/>clusters<sp/>worth!)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="419"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__write_8c_1a68d609a89800a61f700b18500a56d30a" kindref="member">fatfs_allocate_free_space</ref>(&amp;_fs,<sp/>1,<sp/>&amp;<ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster,<sp/>1))<sp/>{</highlight></codeline>
<codeline lineno="420"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="421"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="422"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="423"><highlight class="normal"></highlight></codeline>
<codeline lineno="424"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_LFN_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="425"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Generate<sp/>a<sp/>short<sp/>filename<sp/>&amp;<sp/>tail</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="426"><highlight class="normal"><sp/><sp/>tailNum<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="427"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">do</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="428"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Create<sp/>a<sp/>standard<sp/>short<sp/>filename<sp/>(without<sp/>tail)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="429"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__misc_8c_1a25a4d4a522ffdb06b4fab094d05b1763" kindref="member">fatfs_lfn_create_sfn</ref>(shortFilename,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename);</highlight></codeline>
<codeline lineno="430"><highlight class="normal"></highlight></codeline>
<codeline lineno="431"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>second<sp/>hit<sp/>or<sp/>more,<sp/>generate<sp/>a<sp/>~n<sp/>tail</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="432"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(tailNum<sp/>!=<sp/>0)</highlight></codeline>
<codeline lineno="433"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__misc_8c_1a140f2ac336bea9e8c945b6357fc65083" kindref="member">fatfs_lfn_generate_tail</ref>((</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/>shortFilename,<sp/>tailNum);</highlight></codeline>
<codeline lineno="434"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Try<sp/>with<sp/>no<sp/>tail<sp/>if<sp/>first<sp/>entry</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="435"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="436"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="string_8h_1ae33b18edb618c656b9b795b9fce2316c" kindref="member">memcpy</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/>shortFilename,<sp/><ref refid="fat__defs_8h_1a0918d60f1f01721da31d3b2b0f79f7aa" kindref="member">FAT_SFN_SIZE_FULL</ref>);</highlight></codeline>
<codeline lineno="437"><highlight class="normal"></highlight></codeline>
<codeline lineno="438"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>entry<sp/>exists<sp/>already<sp/>or<sp/>not</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="439"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a8bdad35bc1dd908eda5d02f47a8d73d4" kindref="member">fatfs_sfn_exists</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename)<sp/>==<sp/>0)</highlight></codeline>
<codeline lineno="440"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="441"><highlight class="normal"></highlight></codeline>
<codeline lineno="442"><highlight class="normal"><sp/><sp/><sp/><sp/>tailNum++;</highlight></codeline>
<codeline lineno="443"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(tailNum<sp/>&lt;<sp/>9999);</highlight></codeline>
<codeline lineno="444"><highlight class="normal"></highlight></codeline>
<codeline lineno="445"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>We<sp/>reached<sp/>the<sp/>max<sp/>number<sp/>of<sp/>duplicate<sp/>short<sp/>file<sp/>names<sp/>(unlikely!)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="446"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(tailNum<sp/>==<sp/>9999)<sp/>{</highlight></codeline>
<codeline lineno="447"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>allocated<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="448"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a7a329446088ccb4d6348f05fcd848ee4" kindref="member">fatfs_free_cluster_chain</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster);</highlight></codeline>
<codeline lineno="449"><highlight class="normal"></highlight></codeline>
<codeline lineno="450"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="451"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="452"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="453"><highlight class="normal"></highlight><highlight class="preprocessor">#else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="454"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Create<sp/>a<sp/>standard<sp/>short<sp/>filename<sp/>(without<sp/>tail)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="455"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__misc_8c_1a25a4d4a522ffdb06b4fab094d05b1763" kindref="member">fatfs_lfn_create_sfn</ref>(shortFilename,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename))</highlight></codeline>
<codeline lineno="456"><highlight class="normal"><sp/><sp/><sp/><sp/>{</highlight></codeline>
<codeline lineno="457"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>allocated<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="458"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a7a329446088ccb4d6348f05fcd848ee4" kindref="member">fatfs_free_cluster_chain</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster);</highlight></codeline>
<codeline lineno="459"><highlight class="normal"></highlight></codeline>
<codeline lineno="460"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="461"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="462"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="463"><highlight class="normal"></highlight></codeline>
<codeline lineno="464"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Copy<sp/>to<sp/>SFN<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="465"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="string_8h_1ae33b18edb618c656b9b795b9fce2316c" kindref="member">memcpy</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/>shortFilename,<sp/><ref refid="fat__defs_8h_1a0918d60f1f01721da31d3b2b0f79f7aa" kindref="member">FAT_SFN_SIZE_FULL</ref>);</highlight></codeline>
<codeline lineno="466"><highlight class="normal"></highlight></codeline>
<codeline lineno="467"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>entry<sp/>exists<sp/>already</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="468"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a8bdad35bc1dd908eda5d02f47a8d73d4" kindref="member">fatfs_sfn_exists</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename))</highlight></codeline>
<codeline lineno="469"><highlight class="normal"><sp/><sp/><sp/><sp/>{</highlight></codeline>
<codeline lineno="470"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>allocated<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="471"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a7a329446088ccb4d6348f05fcd848ee4" kindref="member">fatfs_free_cluster_chain</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster);</highlight></codeline>
<codeline lineno="472"><highlight class="normal"></highlight></codeline>
<codeline lineno="473"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="474"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="475"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="476"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="477"><highlight class="normal"></highlight></codeline>
<codeline lineno="478"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Add<sp/>file<sp/>to<sp/>disk</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="479"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__write_8c_1a1d762d2afde765d8848e7eaff4dd2fb1" kindref="member">fatfs_add_file_entry</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filename,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster,<sp/>0,<sp/>0))<sp/>{</highlight></codeline>
<codeline lineno="480"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>allocated<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="481"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a7a329446088ccb4d6348f05fcd848ee4" kindref="member">fatfs_free_cluster_chain</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster);</highlight></codeline>
<codeline lineno="482"><highlight class="normal"></highlight></codeline>
<codeline lineno="483"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="484"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="485"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="486"><highlight class="normal"></highlight></codeline>
<codeline lineno="487"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>General</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="488"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="489"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="490"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="491"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="492"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength_changed<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="493"><highlight class="normal"></highlight></codeline>
<codeline lineno="494"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Quick<sp/>lookup<sp/>for<sp/>next<sp/>link<sp/>in<sp/>the<sp/>chain</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="495"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="496"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.CurrentCluster<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="497"><highlight class="normal"></highlight></codeline>
<codeline lineno="498"><highlight class="normal"><sp/><sp/><ref refid="fat__cache_8c_1a205d74e989d0e076b031ea2990370c4d" kindref="member">fatfs_cache_init</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="499"><highlight class="normal"></highlight></codeline>
<codeline lineno="500"><highlight class="normal"><sp/><sp/><ref refid="fat__table_8c_1a4122bbba15645ebdeea241ef7bcb663e" kindref="member">fatfs_fat_purge</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="501"><highlight class="normal"></highlight></codeline>
<codeline lineno="502"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" kindref="member">file</ref>;</highlight></codeline>
<codeline lineno="503"><highlight class="normal">}</highlight></codeline>
<codeline lineno="504"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="505"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="506"><highlight class="normal"></highlight><highlight class="comment">//<sp/>_read_sectors:<sp/>Read<sp/>sector(s)<sp/>from<sp/>disk<sp/>to<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="507"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="508"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>_read_sectors(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref>,<sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>offset,<sp/><ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref><sp/>*<ref refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" kindref="member">buffer</ref>,<sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>count)<sp/>{</highlight></codeline>
<codeline lineno="509"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>Sector<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="510"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>ClusterIdx<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="511"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>Cluster<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="512"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>i;</highlight></codeline>
<codeline lineno="513"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>lba;</highlight></codeline>
<codeline lineno="514"><highlight class="normal"></highlight></codeline>
<codeline lineno="515"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Find<sp/>cluster<sp/>index<sp/>within<sp/>file<sp/>&amp;<sp/>sector<sp/>with<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="516"><highlight class="normal"><sp/><sp/>ClusterIdx<sp/>=<sp/>offset<sp/>/<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref>;</highlight></codeline>
<codeline lineno="517"><highlight class="normal"><sp/><sp/>Sector<sp/>=<sp/>offset<sp/>-<sp/>(ClusterIdx<sp/>*<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref>);</highlight></codeline>
<codeline lineno="518"><highlight class="normal"></highlight></codeline>
<codeline lineno="519"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Limit<sp/>number<sp/>of<sp/>sectors<sp/>read<sp/>to<sp/>the<sp/>number<sp/>remaining<sp/>in<sp/>this<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="520"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((Sector<sp/>+<sp/>count)<sp/>&gt;<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref>)</highlight></codeline>
<codeline lineno="521"><highlight class="normal"><sp/><sp/><sp/><sp/>count<sp/>=<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref><sp/>-<sp/>Sector;</highlight></codeline>
<codeline lineno="522"><highlight class="normal"></highlight></codeline>
<codeline lineno="523"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Quick<sp/>lookup<sp/>for<sp/>next<sp/>link<sp/>in<sp/>the<sp/>chain</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="524"><highlight class="normal"><sp/><sp/>if<sp/>(ClusterIdx<sp/>==<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx)</highlight></codeline>
<codeline lineno="525"><highlight class="normal"><sp/><sp/><sp/><sp/>Cluster<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.CurrentCluster;</highlight></codeline>
<codeline lineno="526"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Else<sp/>walk<sp/>the<sp/>chain</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="527"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="528"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Starting<sp/>from<sp/>last<sp/>recorded<sp/>cluster?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="529"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ClusterIdx<sp/>&amp;&amp;<sp/>ClusterIdx<sp/>==<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx<sp/>+<sp/>1)<sp/>{</highlight></codeline>
<codeline lineno="530"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>i<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx;</highlight></codeline>
<codeline lineno="531"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>Cluster<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.CurrentCluster;</highlight></codeline>
<codeline lineno="532"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="533"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Start<sp/>searching<sp/>from<sp/>the<sp/>beginning..</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="534"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="535"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Set<sp/>start<sp/>of<sp/>cluster<sp/>chain<sp/>to<sp/>initial<sp/>value</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="536"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>i<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="537"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>Cluster<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster;</highlight></codeline>
<codeline lineno="538"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="539"><highlight class="normal"></highlight></codeline>
<codeline lineno="540"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Follow<sp/>chain<sp/>to<sp/>find<sp/>cluster<sp/>to<sp/>read</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="541"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(;<sp/>i<sp/>&lt;<sp/>ClusterIdx;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="542"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>nextCluster;</highlight></codeline>
<codeline lineno="543"><highlight class="normal"></highlight></codeline>
<codeline lineno="544"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Does<sp/>the<sp/>entry<sp/>exist<sp/>in<sp/>the<sp/>cache?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="545"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__cache_8c_1afe54582a1aa9848bd2cb4724e1baf6bc" kindref="member">fatfs_cache_get_next_cluster</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>,<sp/>i,<sp/>&amp;nextCluster))<sp/>{</highlight></codeline>
<codeline lineno="546"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Scan<sp/>file<sp/>linked<sp/>list<sp/>to<sp/>find<sp/>next<sp/>entry</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="547"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>nextCluster<sp/>=<sp/><ref refid="fat__table_8c_1af6297d64179e09d929493451ab68d6e6" kindref="member">fatfs_find_next_cluster</ref>(&amp;_fs,<sp/>Cluster);</highlight></codeline>
<codeline lineno="548"><highlight class="normal"></highlight></codeline>
<codeline lineno="549"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Push<sp/>entry<sp/>into<sp/>cache</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="550"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__cache_8c_1ac21308cd551be1d3bafd1dc9e3690e5a" kindref="member">fatfs_cache_set_next_cluster</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>,<sp/>i,<sp/>nextCluster);</highlight></codeline>
<codeline lineno="551"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="552"><highlight class="normal"></highlight></codeline>
<codeline lineno="553"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>Cluster<sp/>=<sp/>nextCluster;</highlight></codeline>
<codeline lineno="554"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="555"><highlight class="normal"></highlight></codeline>
<codeline lineno="556"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Record<sp/>current<sp/>cluster<sp/>lookup<sp/>details<sp/>(if<sp/>valid)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="557"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(Cluster<sp/>!=<sp/><ref refid="fat__defs_8h_1a6542eeb37905e8f378fb8f3e5e94d083" kindref="member">FAT32_LAST_CLUSTER</ref>)<sp/>{</highlight></codeline>
<codeline lineno="558"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.CurrentCluster<sp/>=<sp/>Cluster;</highlight></codeline>
<codeline lineno="559"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx<sp/>=<sp/>ClusterIdx;</highlight></codeline>
<codeline lineno="560"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="561"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="562"><highlight class="normal"></highlight></codeline>
<codeline lineno="563"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>end<sp/>of<sp/>cluster<sp/>chain<sp/>then<sp/>return<sp/>false</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="564"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(Cluster<sp/>==<sp/><ref refid="fat__defs_8h_1a6542eeb37905e8f378fb8f3e5e94d083" kindref="member">FAT32_LAST_CLUSTER</ref>)</highlight></codeline>
<codeline lineno="565"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="566"><highlight class="normal"></highlight></codeline>
<codeline lineno="567"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Calculate<sp/>sector<sp/>address</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="568"><highlight class="normal"><sp/><sp/>lba<sp/>=<sp/><ref refid="fat__access_8c_1adda5a5dde3548cd09943efcbe5534c62" kindref="member">fatfs_lba_of_cluster</ref>(&amp;_fs,<sp/>Cluster)<sp/>+<sp/>Sector;</highlight></codeline>
<codeline lineno="569"><highlight class="normal"></highlight></codeline>
<codeline lineno="570"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Read<sp/>sector<sp/>of<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="571"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1ac227af7896c2e9ef03e27a73c52630e6" kindref="member">fatfs_sector_read</ref>(&amp;_fs,<sp/>lba,<sp/><ref refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" kindref="member">buffer</ref>,<sp/>count))</highlight></codeline>
<codeline lineno="572"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>count;</highlight></codeline>
<codeline lineno="573"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="574"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="575"><highlight class="normal">}</highlight></codeline>
<codeline lineno="576"><highlight class="normal"></highlight></codeline>
<codeline lineno="577"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="578"><highlight class="normal"></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>External<sp/>API</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="579"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="580"><highlight class="normal"></highlight></codeline>
<codeline lineno="581"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="582"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_init:<sp/>Initialise<sp/>library</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="583"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="584" refid="fat__filelib_8h_1ac4154a1278a172ab8e6427eb64161179" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1ac4154a1278a172ab8e6427eb64161179" kindref="member">fl_init</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="585"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i;</highlight></codeline>
<codeline lineno="586"><highlight class="normal"></highlight></codeline>
<codeline lineno="587"><highlight class="normal"><sp/><sp/>fat_list_init(&amp;_free_file_list);</highlight></codeline>
<codeline lineno="588"><highlight class="normal"><sp/><sp/>fat_list_init(&amp;_open_file_list);</highlight></codeline>
<codeline lineno="589"><highlight class="normal"></highlight></codeline>
<codeline lineno="590"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Add<sp/>all<sp/>file<sp/>objects<sp/>to<sp/>free<sp/>list</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="591"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/><ref refid="fat__opts_8h_1afa06a8fa57091187d821deea2ffe93b9" kindref="member">FATFS_MAX_OPEN_FILES</ref>;<sp/>i++)</highlight></codeline>
<codeline lineno="592"><highlight class="normal"><sp/><sp/><sp/><sp/>fat_list_insert_last(&amp;_free_file_list,<sp/>&amp;_files[i].list_node);</highlight></codeline>
<codeline lineno="593"><highlight class="normal"></highlight></codeline>
<codeline lineno="594"><highlight class="normal"><sp/><sp/>_filelib_init<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="595"><highlight class="normal">}</highlight></codeline>
<codeline lineno="596"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="597"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_attach_locks:</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="598"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="599" refid="fat__filelib_8h_1a71ff2c6cb4d49c94ee51db25be152b1d" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a71ff2c6cb4d49c94ee51db25be152b1d" kindref="member">fl_attach_locks</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>(*lock)(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">),<sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>(*unlock)(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">))<sp/>{</highlight></codeline>
<codeline lineno="600"><highlight class="normal"><sp/><sp/>_fs.<ref refid="structfatfs_1adec2afe1c9ec96ec4e595c98ea11eb6a" kindref="member">fl_lock</ref><sp/>=<sp/>lock;</highlight></codeline>
<codeline lineno="601"><highlight class="normal"><sp/><sp/>_fs.<ref refid="structfatfs_1a73121a64303db75481e1fbd5a58b17d0" kindref="member">fl_unlock</ref><sp/>=<sp/>unlock;</highlight></codeline>
<codeline lineno="602"><highlight class="normal">}</highlight></codeline>
<codeline lineno="603"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="604"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_attach_media:</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="605"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="606" refid="fat__filelib_8h_1af9d46bc71dd1953eb78c99d6615ade92" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1af9d46bc71dd1953eb78c99d6615ade92" kindref="member">fl_attach_media</ref>(<ref refid="fat__access_8h_1aaf031f5384342c34f5a446c5dd5b5ed3" kindref="member">fn_diskio_read</ref><sp/>rd,<sp/><ref refid="fat__access_8h_1a8532f8239b515a20628a74e37d5a598e" kindref="member">fn_diskio_write</ref><sp/>wr)<sp/>{</highlight></codeline>
<codeline lineno="607"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="608"><highlight class="normal"></highlight></codeline>
<codeline lineno="609"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="610"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="611"><highlight class="normal"></highlight></codeline>
<codeline lineno="612"><highlight class="normal"><sp/><sp/>_fs.<ref refid="structfatfs_1abe586c938c51e38d3d1c247e42a7bca9" kindref="member">disk_io</ref>.<ref refid="structdisk__if_1a70c0bb1beb23681d5dd78fb40f78454b" kindref="member">read_media</ref><sp/>=<sp/>rd;</highlight></codeline>
<codeline lineno="613"><highlight class="normal"><sp/><sp/>_fs.<ref refid="structfatfs_1abe586c938c51e38d3d1c247e42a7bca9" kindref="member">disk_io</ref>.<ref refid="structdisk__if_1a94687066cd6e4df9e905358b73c67603" kindref="member">write_media</ref><sp/>=<sp/>wr;</highlight></codeline>
<codeline lineno="614"><highlight class="normal"></highlight></codeline>
<codeline lineno="615"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Initialise<sp/>FAT<sp/>parameters</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="616"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((res<sp/>=<sp/><ref refid="fat__access_8c_1a79896ebc01463ec2121874995ea7d922" kindref="member">fatfs_init</ref>(&amp;_fs))<sp/>!=<sp/><ref refid="fat__access_8h_1ae6aa6129ce17d5e7286e043c850e23c2" kindref="member">FAT_INIT_OK</ref>)<sp/>{</highlight></codeline>
<codeline lineno="617"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__opts_8h_1a77e202c52dfa1ae6a4a060b21b70a80c" kindref="member">FAT_PRINTF</ref>((</highlight><highlight class="stringliteral">&quot;FAT_FS:<sp/>Error<sp/>could<sp/>not<sp/>load<sp/>FAT<sp/>details<sp/>(%d)!\r\n&quot;</highlight><highlight class="normal">,<sp/>res));</highlight></codeline>
<codeline lineno="618"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="619"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="620"><highlight class="normal"></highlight></codeline>
<codeline lineno="621"><highlight class="normal"><sp/><sp/>_filelib_valid<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="622"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__access_8h_1ae6aa6129ce17d5e7286e043c850e23c2" kindref="member">FAT_INIT_OK</ref>;</highlight></codeline>
<codeline lineno="623"><highlight class="normal">}</highlight></codeline>
<codeline lineno="624"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="625"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_shutdown:<sp/>Call<sp/>before<sp/>shutting<sp/>down<sp/>system</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="626"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="627" refid="fat__filelib_8h_1a9e4ba72f7c41f41f4a31ca5d46de3f5d" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a9e4ba72f7c41f41f4a31ca5d46de3f5d" kindref="member">fl_shutdown</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="628"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="629"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="630"><highlight class="normal"></highlight></codeline>
<codeline lineno="631"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="632"><highlight class="normal"><sp/><sp/><ref refid="fat__table_8c_1a4122bbba15645ebdeea241ef7bcb663e" kindref="member">fatfs_fat_purge</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="633"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="634"><highlight class="normal">}</highlight></codeline>
<codeline lineno="635"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="636"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fopen:<sp/>Open<sp/>or<sp/>Create<sp/>a<sp/>file<sp/>for<sp/>reading<sp/>or<sp/>writing</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="637"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="638" refid="fat__filelib_8h_1a475709f0a4f7ea3ab61799081ab4dd29" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal">*<sp/><ref refid="fat__filelib_8c_1a800a79c9fb283c5f5199e08b1f2ada38" kindref="member">fl_fopen</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*path,<sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*mode)<sp/>{</highlight></codeline>
<codeline lineno="639"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i;</highlight></codeline>
<codeline lineno="640"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" kindref="member">file</ref>;</highlight></codeline>
<codeline lineno="641"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref><sp/>flags<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="642"><highlight class="normal"></highlight></codeline>
<codeline lineno="643"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="644"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="645"><highlight class="normal"></highlight></codeline>
<codeline lineno="646"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!_filelib_valid)</highlight></codeline>
<codeline lineno="647"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="648"><highlight class="normal"></highlight></codeline>
<codeline lineno="649"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!path<sp/>||<sp/>!mode)</highlight></codeline>
<codeline lineno="650"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="651"><highlight class="normal"></highlight></codeline>
<codeline lineno="652"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Supported<sp/>Modes:</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="653"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>&quot;r&quot;<sp/>Open<sp/>a<sp/>file<sp/>for<sp/>reading.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="654"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>The<sp/>file<sp/>must<sp/>exist.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="655"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>&quot;w&quot;<sp/>Create<sp/>an<sp/>empty<sp/>file<sp/>for<sp/>writing.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="656"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>If<sp/>a<sp/>file<sp/>with<sp/>the<sp/>same<sp/>name<sp/>already<sp/>exists<sp/>its<sp/>content<sp/>is<sp/>erased<sp/>and<sp/>the<sp/>file<sp/>is<sp/>treated<sp/>as<sp/>a<sp/>new<sp/>empty<sp/>file.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="657"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>&quot;a&quot;<sp/>Append<sp/>to<sp/>a<sp/>file.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="658"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>Writing<sp/>operations<sp/>append<sp/>data<sp/>at<sp/>the<sp/>end<sp/>of<sp/>the<sp/>file.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="659"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>The<sp/>file<sp/>is<sp/>created<sp/>if<sp/>it<sp/>does<sp/>not<sp/>exist.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="660"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>&quot;r+&quot;<sp/>Open<sp/>a<sp/>file<sp/>for<sp/>update<sp/>both<sp/>reading<sp/>and<sp/>writing.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="661"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>The<sp/>file<sp/>must<sp/>exist.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="662"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>&quot;w+&quot;<sp/>Create<sp/>an<sp/>empty<sp/>file<sp/>for<sp/>both<sp/>reading<sp/>and<sp/>writing.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="663"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>If<sp/>a<sp/>file<sp/>with<sp/>the<sp/>same<sp/>name<sp/>already<sp/>exists<sp/>its<sp/>content<sp/>is<sp/>erased<sp/>and<sp/>the<sp/>file<sp/>is<sp/>treated<sp/>as<sp/>a<sp/>new<sp/>empty<sp/>file.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="664"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>&quot;a+&quot;<sp/>Open<sp/>a<sp/>file<sp/>for<sp/>reading<sp/>and<sp/>appending.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="665"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>All<sp/>writing<sp/>operations<sp/>are<sp/>performed<sp/>at<sp/>the<sp/>end<sp/>of<sp/>the<sp/>file,<sp/>protecting<sp/>the<sp/>previous<sp/>content<sp/>to<sp/>be<sp/>overwritten.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="666"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>You<sp/>can<sp/>reposition<sp/>(fseek,<sp/>rewind)<sp/>the<sp/>internal<sp/>pointer<sp/>to<sp/>anywhere<sp/>in<sp/>the<sp/>file<sp/>for<sp/>reading,<sp/>but<sp/>writing<sp/>operations</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="667"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>will<sp/>move<sp/>it<sp/>back<sp/>to<sp/>the<sp/>end<sp/>of<sp/>file.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="668"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>The<sp/>file<sp/>is<sp/>created<sp/>if<sp/>it<sp/>does<sp/>not<sp/>exist.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="669"><highlight class="normal"></highlight></codeline>
<codeline lineno="670"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>(int)<sp/><ref refid="lib_8h_1ae6c8de953239811a34eeeab09458e55e" kindref="member">strlen</ref>(mode);<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="671"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">switch</highlight><highlight class="normal"><sp/>(mode[i])<sp/>{</highlight></codeline>
<codeline lineno="672"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/></highlight><highlight class="charliteral">&apos;r&apos;</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="673"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/></highlight><highlight class="charliteral">&apos;R&apos;</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="674"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1ad52d51659a75e25d96fb04d22ff718cb" kindref="member">FILE_READ</ref>;</highlight></codeline>
<codeline lineno="675"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="676"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/></highlight><highlight class="charliteral">&apos;w&apos;</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="677"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/></highlight><highlight class="charliteral">&apos;W&apos;</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="678"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1ace34e503254fa9004599ddf122264c8f" kindref="member">FILE_WRITE</ref>;</highlight></codeline>
<codeline lineno="679"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1aea0d6d2bf8dc1ad57d506222cd4c1341" kindref="member">FILE_ERASE</ref>;</highlight></codeline>
<codeline lineno="680"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1a39eafd8be8b38d6867f8ea6f37555154" kindref="member">FILE_CREATE</ref>;</highlight></codeline>
<codeline lineno="681"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="682"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/></highlight><highlight class="charliteral">&apos;a&apos;</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="683"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/></highlight><highlight class="charliteral">&apos;A&apos;</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="684"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1ace34e503254fa9004599ddf122264c8f" kindref="member">FILE_WRITE</ref>;</highlight></codeline>
<codeline lineno="685"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1abb57841952be5b0be972b4bef8fd5021" kindref="member">FILE_APPEND</ref>;</highlight></codeline>
<codeline lineno="686"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1a39eafd8be8b38d6867f8ea6f37555154" kindref="member">FILE_CREATE</ref>;</highlight></codeline>
<codeline lineno="687"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="688"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/></highlight><highlight class="charliteral">&apos;+&apos;</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="689"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1ad52d51659a75e25d96fb04d22ff718cb" kindref="member">FILE_READ</ref>)</highlight></codeline>
<codeline lineno="690"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1ace34e503254fa9004599ddf122264c8f" kindref="member">FILE_WRITE</ref>;</highlight></codeline>
<codeline lineno="691"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1ace34e503254fa9004599ddf122264c8f" kindref="member">FILE_WRITE</ref>)<sp/>{</highlight></codeline>
<codeline lineno="692"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1ad52d51659a75e25d96fb04d22ff718cb" kindref="member">FILE_READ</ref>;</highlight></codeline>
<codeline lineno="693"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1aea0d6d2bf8dc1ad57d506222cd4c1341" kindref="member">FILE_ERASE</ref>;</highlight></codeline>
<codeline lineno="694"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1a39eafd8be8b38d6867f8ea6f37555154" kindref="member">FILE_CREATE</ref>;</highlight></codeline>
<codeline lineno="695"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="696"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1abb57841952be5b0be972b4bef8fd5021" kindref="member">FILE_APPEND</ref>)<sp/>{</highlight></codeline>
<codeline lineno="697"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1ad52d51659a75e25d96fb04d22ff718cb" kindref="member">FILE_READ</ref>;</highlight></codeline>
<codeline lineno="698"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1ace34e503254fa9004599ddf122264c8f" kindref="member">FILE_WRITE</ref>;</highlight></codeline>
<codeline lineno="699"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1abb57841952be5b0be972b4bef8fd5021" kindref="member">FILE_APPEND</ref>;</highlight></codeline>
<codeline lineno="700"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1a39eafd8be8b38d6867f8ea6f37555154" kindref="member">FILE_CREATE</ref>;</highlight></codeline>
<codeline lineno="701"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="702"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="703"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/></highlight><highlight class="charliteral">&apos;b&apos;</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="704"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/></highlight><highlight class="charliteral">&apos;B&apos;</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="705"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>flags<sp/>|=<sp/><ref refid="fat__filelib_8h_1a9d3d138c1de23ac8dcb6b1a80730d649" kindref="member">FILE_BINARY</ref>;</highlight></codeline>
<codeline lineno="706"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="707"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="708"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="709"><highlight class="normal"></highlight></codeline>
<codeline lineno="710"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="711"><highlight class="normal"></highlight></codeline>
<codeline lineno="712"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT<sp/>==<sp/>0</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="713"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>No<sp/>write<sp/>support!</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="714"><highlight class="normal"><sp/><sp/><sp/><sp/>flags<sp/>&amp;=<sp/>~(<ref refid="fat__filelib_8h_1a39eafd8be8b38d6867f8ea6f37555154" kindref="member">FILE_CREATE</ref><sp/>|<sp/><ref refid="fat__filelib_8h_1ace34e503254fa9004599ddf122264c8f" kindref="member">FILE_WRITE</ref><sp/>|<sp/><ref refid="fat__filelib_8h_1abb57841952be5b0be972b4bef8fd5021" kindref="member">FILE_APPEND</ref>);</highlight></codeline>
<codeline lineno="715"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="716"><highlight class="normal"></highlight></codeline>
<codeline lineno="717"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>No<sp/>write<sp/>access<sp/>-<sp/>remove<sp/>write/modify<sp/>flags</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="718"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!_fs.<ref refid="structfatfs_1abe586c938c51e38d3d1c247e42a7bca9" kindref="member">disk_io</ref>.<ref refid="structdisk__if_1a94687066cd6e4df9e905358b73c67603" kindref="member">write_media</ref>)</highlight></codeline>
<codeline lineno="719"><highlight class="normal"><sp/><sp/><sp/><sp/>flags<sp/>&amp;=<sp/>~(<ref refid="fat__filelib_8h_1a39eafd8be8b38d6867f8ea6f37555154" kindref="member">FILE_CREATE</ref><sp/>|<sp/><ref refid="fat__filelib_8h_1ace34e503254fa9004599ddf122264c8f" kindref="member">FILE_WRITE</ref><sp/>|<sp/><ref refid="fat__filelib_8h_1abb57841952be5b0be972b4bef8fd5021" kindref="member">FILE_APPEND</ref>);</highlight></codeline>
<codeline lineno="720"><highlight class="normal"></highlight></codeline>
<codeline lineno="721"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="722"><highlight class="normal"></highlight></codeline>
<codeline lineno="723"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Read</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="724"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1ad52d51659a75e25d96fb04d22ff718cb" kindref="member">FILE_READ</ref>)<sp/>{</highlight></codeline>
<codeline lineno="725"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>_open_file(path);</highlight></codeline>
<codeline lineno="726"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="727"><highlight class="normal"></highlight></codeline>
<codeline lineno="728"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Create<sp/>New</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="729"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="730"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="structfile" kindref="compound">file</ref><sp/>&amp;&amp;<sp/>(flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1a39eafd8be8b38d6867f8ea6f37555154" kindref="member">FILE_CREATE</ref>))</highlight></codeline>
<codeline lineno="731"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>_create_file(path);</highlight></codeline>
<codeline lineno="732"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="733"><highlight class="normal"></highlight></codeline>
<codeline lineno="734"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Write<sp/>Existing<sp/>(and<sp/>not<sp/>open<sp/>due<sp/>to<sp/>read<sp/>or<sp/>create)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="735"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!(flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1ad52d51659a75e25d96fb04d22ff718cb" kindref="member">FILE_READ</ref>))</highlight></codeline>
<codeline lineno="736"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1a39eafd8be8b38d6867f8ea6f37555154" kindref="member">FILE_CREATE</ref>)<sp/>&amp;&amp;<sp/>!<ref refid="structfile" kindref="compound">file</ref>)</highlight></codeline>
<codeline lineno="737"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(flags<sp/>&amp;<sp/>(<ref refid="fat__filelib_8h_1ace34e503254fa9004599ddf122264c8f" kindref="member">FILE_WRITE</ref><sp/>|<sp/><ref refid="fat__filelib_8h_1abb57841952be5b0be972b4bef8fd5021" kindref="member">FILE_APPEND</ref>))</highlight></codeline>
<codeline lineno="738"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>_open_file(path);</highlight></codeline>
<codeline lineno="739"><highlight class="normal"></highlight></codeline>
<codeline lineno="740"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>)</highlight></codeline>
<codeline lineno="741"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;flags<sp/>=<sp/>flags;</highlight></codeline>
<codeline lineno="742"><highlight class="normal"></highlight></codeline>
<codeline lineno="743"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="744"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" kindref="member">file</ref>;</highlight></codeline>
<codeline lineno="745"><highlight class="normal">}</highlight></codeline>
<codeline lineno="746"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="747"><highlight class="normal"></highlight><highlight class="comment">//<sp/>_write_sectors:<sp/>Write<sp/>sector(s)<sp/>to<sp/>disk</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="748"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="749"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="750"><highlight class="normal"></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>_write_sectors(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref>,<sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>offset,<sp/><ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref><sp/>*<ref refid="structbuf" kindref="compound">buf</ref>,<sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>count)<sp/>{</highlight></codeline>
<codeline lineno="751"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>SectorNumber<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="752"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>ClusterIdx<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="753"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>Cluster<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="754"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>LastCluster<sp/>=<sp/><ref refid="fat__defs_8h_1a6542eeb37905e8f378fb8f3e5e94d083" kindref="member">FAT32_LAST_CLUSTER</ref>;</highlight></codeline>
<codeline lineno="755"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>i;</highlight></codeline>
<codeline lineno="756"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>lba;</highlight></codeline>
<codeline lineno="757"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>TotalWriteCount<sp/>=<sp/>count;</highlight></codeline>
<codeline lineno="758"><highlight class="normal"></highlight></codeline>
<codeline lineno="759"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Find<sp/>values<sp/>for<sp/>Cluster<sp/>index<sp/>&amp;<sp/>sector<sp/>within<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="760"><highlight class="normal"><sp/><sp/>ClusterIdx<sp/>=<sp/>offset<sp/>/<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref>;</highlight></codeline>
<codeline lineno="761"><highlight class="normal"><sp/><sp/>SectorNumber<sp/>=<sp/>offset<sp/>-<sp/>(ClusterIdx<sp/>*<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref>);</highlight></codeline>
<codeline lineno="762"><highlight class="normal"></highlight></codeline>
<codeline lineno="763"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Limit<sp/>number<sp/>of<sp/>sectors<sp/>written<sp/>to<sp/>the<sp/>number<sp/>remaining<sp/>in<sp/>this<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="764"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((SectorNumber<sp/>+<sp/>count)<sp/>&gt;<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref>)</highlight></codeline>
<codeline lineno="765"><highlight class="normal"><sp/><sp/><sp/><sp/>count<sp/>=<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref><sp/>-<sp/>SectorNumber;</highlight></codeline>
<codeline lineno="766"><highlight class="normal"></highlight></codeline>
<codeline lineno="767"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Quick<sp/>lookup<sp/>for<sp/>next<sp/>link<sp/>in<sp/>the<sp/>chain</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="768"><highlight class="normal"><sp/><sp/>if<sp/>(ClusterIdx<sp/>==<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx)</highlight></codeline>
<codeline lineno="769"><highlight class="normal"><sp/><sp/><sp/><sp/>Cluster<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.CurrentCluster;</highlight></codeline>
<codeline lineno="770"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Else<sp/>walk<sp/>the<sp/>chain</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="771"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="772"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Starting<sp/>from<sp/>last<sp/>recorded<sp/>cluster?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="773"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ClusterIdx<sp/>&amp;&amp;<sp/>ClusterIdx<sp/>==<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx<sp/>+<sp/>1)<sp/>{</highlight></codeline>
<codeline lineno="774"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>i<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx;</highlight></codeline>
<codeline lineno="775"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>Cluster<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.CurrentCluster;</highlight></codeline>
<codeline lineno="776"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="777"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Start<sp/>searching<sp/>from<sp/>the<sp/>beginning..</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="778"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="779"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Set<sp/>start<sp/>of<sp/>cluster<sp/>chain<sp/>to<sp/>initial<sp/>value</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="780"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>i<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="781"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>Cluster<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster;</highlight></codeline>
<codeline lineno="782"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="783"><highlight class="normal"></highlight></codeline>
<codeline lineno="784"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Follow<sp/>chain<sp/>to<sp/>find<sp/>cluster<sp/>to<sp/>read</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="785"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(;<sp/>i<sp/>&lt;<sp/>ClusterIdx;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="786"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>nextCluster;</highlight></codeline>
<codeline lineno="787"><highlight class="normal"></highlight></codeline>
<codeline lineno="788"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Does<sp/>the<sp/>entry<sp/>exist<sp/>in<sp/>the<sp/>cache?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="789"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__cache_8c_1afe54582a1aa9848bd2cb4724e1baf6bc" kindref="member">fatfs_cache_get_next_cluster</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>,<sp/>i,<sp/>&amp;nextCluster))<sp/>{</highlight></codeline>
<codeline lineno="790"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Scan<sp/>file<sp/>linked<sp/>list<sp/>to<sp/>find<sp/>next<sp/>entry</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="791"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>nextCluster<sp/>=<sp/><ref refid="fat__table_8c_1af6297d64179e09d929493451ab68d6e6" kindref="member">fatfs_find_next_cluster</ref>(&amp;_fs,<sp/>Cluster);</highlight></codeline>
<codeline lineno="792"><highlight class="normal"></highlight></codeline>
<codeline lineno="793"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Push<sp/>entry<sp/>into<sp/>cache</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="794"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__cache_8c_1ac21308cd551be1d3bafd1dc9e3690e5a" kindref="member">fatfs_cache_set_next_cluster</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>,<sp/>i,<sp/>nextCluster);</highlight></codeline>
<codeline lineno="795"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="796"><highlight class="normal"></highlight></codeline>
<codeline lineno="797"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>LastCluster<sp/>=<sp/>Cluster;</highlight></codeline>
<codeline lineno="798"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>Cluster<sp/>=<sp/>nextCluster;</highlight></codeline>
<codeline lineno="799"><highlight class="normal"></highlight></codeline>
<codeline lineno="800"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Dont<sp/>keep<sp/>following<sp/>a<sp/>dead<sp/>end</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="801"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(Cluster<sp/>==<sp/><ref refid="fat__defs_8h_1a6542eeb37905e8f378fb8f3e5e94d083" kindref="member">FAT32_LAST_CLUSTER</ref>)</highlight></codeline>
<codeline lineno="802"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="803"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="804"><highlight class="normal"></highlight></codeline>
<codeline lineno="805"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>we<sp/>have<sp/>reached<sp/>the<sp/>end<sp/>of<sp/>the<sp/>chain,<sp/>allocate<sp/>more!</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="806"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(Cluster<sp/>==<sp/><ref refid="fat__defs_8h_1a6542eeb37905e8f378fb8f3e5e94d083" kindref="member">FAT32_LAST_CLUSTER</ref>)<sp/>{</highlight></codeline>
<codeline lineno="807"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Add<sp/>some<sp/>more<sp/>cluster(s)<sp/>to<sp/>the<sp/>last<sp/>good<sp/>cluster<sp/>chain</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="808"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="fat__write_8c_1ae8950d150955379c297d1ac53583f8e0" kindref="member">fatfs_add_free_space</ref>(&amp;_fs,<sp/>&amp;LastCluster,<sp/>(TotalWriteCount<sp/>+<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref><sp/>-<sp/>1)<sp/>/<sp/>_fs.<ref refid="structfatfs_1a56c20739c55aed4a87e22ebcdbc22d0e" kindref="member">sectors_per_cluster</ref>))</highlight></codeline>
<codeline lineno="809"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="810"><highlight class="normal"></highlight></codeline>
<codeline lineno="811"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>Cluster<sp/>=<sp/>LastCluster;</highlight></codeline>
<codeline lineno="812"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="813"><highlight class="normal"></highlight></codeline>
<codeline lineno="814"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Record<sp/>current<sp/>cluster<sp/>lookup<sp/>details</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="815"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.CurrentCluster<sp/>=<sp/>Cluster;</highlight></codeline>
<codeline lineno="816"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;last_fat_lookup.ClusterIdx<sp/>=<sp/>ClusterIdx;</highlight></codeline>
<codeline lineno="817"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="818"><highlight class="normal"></highlight></codeline>
<codeline lineno="819"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Calculate<sp/>write<sp/>address</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="820"><highlight class="normal"><sp/><sp/>lba<sp/>=<sp/><ref refid="fat__access_8c_1adda5a5dde3548cd09943efcbe5534c62" kindref="member">fatfs_lba_of_cluster</ref>(&amp;_fs,<sp/>Cluster)<sp/>+<sp/>SectorNumber;</highlight></codeline>
<codeline lineno="821"><highlight class="normal"></highlight></codeline>
<codeline lineno="822"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a04e80392b0318629a8f1b609b8204b69" kindref="member">fatfs_sector_write</ref>(&amp;_fs,<sp/>lba,<sp/><ref refid="structbuf" kindref="compound">buf</ref>,<sp/>count))</highlight></codeline>
<codeline lineno="823"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>count;</highlight></codeline>
<codeline lineno="824"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="825"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="826"><highlight class="normal">}</highlight></codeline>
<codeline lineno="827"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="828"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="829"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fflush:<sp/>Flush<sp/>un-written<sp/>data<sp/>to<sp/>the<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="830"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="831" refid="fat__filelib_8h_1ac3ce0b4a8ee1030821b73cf4a2718139" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a6a857e4fbf7fa1ebd7d016e8bab36a94" kindref="member">fl_fflush</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="832"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="833"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*)<sp/>f;</highlight></codeline>
<codeline lineno="834"><highlight class="normal"></highlight></codeline>
<codeline lineno="835"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="836"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="837"><highlight class="normal"></highlight></codeline>
<codeline lineno="838"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>)<sp/>{</highlight></codeline>
<codeline lineno="839"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="840"><highlight class="normal"></highlight></codeline>
<codeline lineno="841"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>some<sp/>write<sp/>data<sp/>still<sp/>in<sp/>buffer</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="842"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty)<sp/>{</highlight></codeline>
<codeline lineno="843"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Write<sp/>back<sp/>current<sp/>sector<sp/>before<sp/>loading<sp/>next</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="844"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(_write_sectors(<ref refid="structfile" kindref="compound">file</ref>,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_sector,<sp/>1))</highlight></codeline>
<codeline lineno="845"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="846"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="847"><highlight class="normal"></highlight></codeline>
<codeline lineno="848"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="849"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="850"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="851"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="852"><highlight class="normal">}</highlight></codeline>
<codeline lineno="853"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="854"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fclose:<sp/>Close<sp/>an<sp/>open<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="855"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="856" refid="fat__filelib_8h_1ad10e5f401505a6d2b006b1a24aee82d2" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1aef5675bf1c0db1d3e073ea36d4cf2d3a" kindref="member">fl_fclose</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="857"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*)<sp/>f;</highlight></codeline>
<codeline lineno="858"><highlight class="normal"></highlight></codeline>
<codeline lineno="859"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="860"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="861"><highlight class="normal"></highlight></codeline>
<codeline lineno="862"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>)<sp/>{</highlight></codeline>
<codeline lineno="863"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="864"><highlight class="normal"></highlight></codeline>
<codeline lineno="865"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Flush<sp/>un-written<sp/>data<sp/>to<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="866"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a6a857e4fbf7fa1ebd7d016e8bab36a94" kindref="member">fl_fflush</ref>(f);</highlight></codeline>
<codeline lineno="867"><highlight class="normal"></highlight></codeline>
<codeline lineno="868"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>File<sp/>size<sp/>changed?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="869"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;filelength_changed)<sp/>{</highlight></codeline>
<codeline lineno="870"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="871"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Update<sp/>filesize<sp/>in<sp/>directory</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="872"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__access_8c_1af94f715b4cdb59cf7854b564de855a65" kindref="member">fatfs_update_file_length</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength);</highlight></codeline>
<codeline lineno="873"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="874"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength_changed<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="875"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="876"><highlight class="normal"></highlight></codeline>
<codeline lineno="877"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="878"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="879"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="880"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="881"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="882"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength_changed<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="883"><highlight class="normal"></highlight></codeline>
<codeline lineno="884"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Free<sp/>file<sp/>handle</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="885"><highlight class="normal"><sp/><sp/><sp/><sp/>_free_file(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="886"><highlight class="normal"></highlight></codeline>
<codeline lineno="887"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__table_8c_1a4122bbba15645ebdeea241ef7bcb663e" kindref="member">fatfs_fat_purge</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="888"><highlight class="normal"></highlight></codeline>
<codeline lineno="889"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="890"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="891"><highlight class="normal">}</highlight></codeline>
<codeline lineno="892"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="893"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fgetc:<sp/>Get<sp/>a<sp/>character<sp/>in<sp/>the<sp/>stream</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="894"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="895" refid="fat__filelib_8h_1a3ac89cbc4edd114760c1dbd18e0d594d" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1ade02f44157d32df37dc881d3e6702129" kindref="member">fl_fgetc</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="896"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="897"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref><sp/>data<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="898"><highlight class="normal"></highlight></codeline>
<codeline lineno="899"><highlight class="normal"><sp/><sp/>res<sp/>=<sp/><ref refid="fat__filelib_8c_1acfc7937a8a1f6846f762a2af33507b66" kindref="member">fl_fread</ref>(&amp;data,<sp/>1,<sp/>1,<sp/>f);</highlight></codeline>
<codeline lineno="900"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(res<sp/>==<sp/>1)</highlight></codeline>
<codeline lineno="901"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal">)<sp/>data;</highlight></codeline>
<codeline lineno="902"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="903"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="904"><highlight class="normal">}</highlight></codeline>
<codeline lineno="905"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="906"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fgets:<sp/>Get<sp/>a<sp/>string<sp/>from<sp/>a<sp/>stream</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="907"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="908" refid="fat__filelib_8h_1adfca2fc192150a8814b2b404c6b31cd7" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*<sp/><ref refid="fat__filelib_8c_1adfca2fc192150a8814b2b404c6b31cd7" kindref="member">fl_fgets</ref>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*s,<sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>n,<sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="909"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>idx<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="910"><highlight class="normal"></highlight></codeline>
<codeline lineno="911"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Space<sp/>for<sp/>null<sp/>terminator?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="912"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(n<sp/>&gt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="913"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>While<sp/>space<sp/>(+space<sp/>for<sp/>null<sp/>terminator)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="914"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(idx<sp/>&lt;<sp/>(n<sp/>-<sp/>1))<sp/>{</highlight></codeline>
<codeline lineno="915"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>ch<sp/>=<sp/><ref refid="fat__filelib_8c_1ade02f44157d32df37dc881d3e6702129" kindref="member">fl_fgetc</ref>(f);</highlight></codeline>
<codeline lineno="916"><highlight class="normal"></highlight></codeline>
<codeline lineno="917"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>EOF<sp/>/<sp/>Error?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="918"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ch<sp/>&lt;<sp/>0)</highlight></codeline>
<codeline lineno="919"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="920"><highlight class="normal"></highlight></codeline>
<codeline lineno="921"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Store<sp/>character<sp/>read<sp/>from<sp/>stream</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="922"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>s[idx++]<sp/>=<sp/>(char)<sp/>ch;</highlight></codeline>
<codeline lineno="923"><highlight class="normal"></highlight></codeline>
<codeline lineno="924"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>End<sp/>of<sp/>line?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="925"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ch<sp/>==<sp/></highlight><highlight class="charliteral">&apos;\n&apos;</highlight><highlight class="normal">)</highlight></codeline>
<codeline lineno="926"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="927"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="928"><highlight class="normal"></highlight></codeline>
<codeline lineno="929"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(idx<sp/>&gt;<sp/>0)</highlight></codeline>
<codeline lineno="930"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>s[idx]<sp/>=<sp/></highlight><highlight class="charliteral">&apos;\0&apos;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="931"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="932"><highlight class="normal"></highlight></codeline>
<codeline lineno="933"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>(idx<sp/>&gt;<sp/>0)<sp/>?<sp/>s<sp/>:<sp/>0;</highlight></codeline>
<codeline lineno="934"><highlight class="normal">}</highlight></codeline>
<codeline lineno="935"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="936"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fread:<sp/>Read<sp/>a<sp/>block<sp/>of<sp/>data<sp/>from<sp/>the<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="937"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="938" refid="fat__filelib_8h_1ab8d83b67a235a4c7913086785f0b3002" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1acfc7937a8a1f6846f762a2af33507b66" kindref="member">fl_fread</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*<ref refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" kindref="member">buffer</ref>,<sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>size,<sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>length,<sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="939"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>sector;</highlight></codeline>
<codeline lineno="940"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>offset;</highlight></codeline>
<codeline lineno="941"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>copyCount;</highlight></codeline>
<codeline lineno="942"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>count<sp/>=<sp/>size<sp/>*<sp/>length;</highlight></codeline>
<codeline lineno="943"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>bytesRead<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="944"><highlight class="normal"></highlight></codeline>
<codeline lineno="945"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*)<sp/>f;</highlight></codeline>
<codeline lineno="946"><highlight class="normal"></highlight></codeline>
<codeline lineno="947"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="948"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="949"><highlight class="normal"></highlight></codeline>
<codeline lineno="950"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" kindref="member">buffer</ref><sp/>==<sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="structfile" kindref="compound">file</ref><sp/>==<sp/><ref refid="fat__string_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)</highlight></codeline>
<codeline lineno="951"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="952"><highlight class="normal"></highlight></codeline>
<codeline lineno="953"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>No<sp/>read<sp/>permissions</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="954"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!(<ref refid="structfile" kindref="compound">file</ref>-&gt;flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1ad52d51659a75e25d96fb04d22ff718cb" kindref="member">FILE_READ</ref>))</highlight></codeline>
<codeline lineno="955"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="956"><highlight class="normal"></highlight></codeline>
<codeline lineno="957"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Nothing<sp/>to<sp/>be<sp/>done</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="958"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!count)</highlight></codeline>
<codeline lineno="959"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="960"><highlight class="normal"></highlight></codeline>
<codeline lineno="961"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>if<sp/>read<sp/>starts<sp/>past<sp/>end<sp/>of<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="962"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>&gt;=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength)</highlight></codeline>
<codeline lineno="963"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="964"><highlight class="normal"></highlight></codeline>
<codeline lineno="965"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Limit<sp/>to<sp/>file<sp/>size</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="966"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((<ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>+<sp/>count)<sp/>&gt;<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength)</highlight></codeline>
<codeline lineno="967"><highlight class="normal"><sp/><sp/><sp/><sp/>count<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength<sp/>-<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum;</highlight></codeline>
<codeline lineno="968"><highlight class="normal"></highlight></codeline>
<codeline lineno="969"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Calculate<sp/>start<sp/>sector</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="970"><highlight class="normal"><sp/><sp/>sector<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>/<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>;</highlight></codeline>
<codeline lineno="971"><highlight class="normal"></highlight></codeline>
<codeline lineno="972"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Offset<sp/>to<sp/>start<sp/>copying<sp/>data<sp/>from<sp/>first<sp/>sector</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="973"><highlight class="normal"><sp/><sp/>offset<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>%<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>;</highlight></codeline>
<codeline lineno="974"><highlight class="normal"></highlight></codeline>
<codeline lineno="975"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(bytesRead<sp/>&lt;<sp/>count)<sp/>{</highlight></codeline>
<codeline lineno="976"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Read<sp/>whole<sp/>sector,<sp/>read<sp/>from<sp/>media<sp/>directly<sp/>into<sp/>target<sp/>buffer</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="977"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((offset<sp/>==<sp/>0)<sp/>&amp;&amp;<sp/>((count<sp/>-<sp/>bytesRead)<sp/>&gt;=<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>))<sp/>{</highlight></codeline>
<codeline lineno="978"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Read<sp/>as<sp/>many<sp/>sectors<sp/>as<sp/>possible<sp/>into<sp/>target<sp/>buffer</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="979"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>sectorsRead<sp/>=<sp/>_read_sectors(<ref refid="structfile" kindref="compound">file</ref>,<sp/>sector,<sp/>(<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>*)<sp/>((<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>*)<sp/><ref refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" kindref="member">buffer</ref><sp/>+<sp/>bytesRead),<sp/>(count<sp/>-<sp/>bytesRead)<sp/>/<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>);</highlight></codeline>
<codeline lineno="980"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(sectorsRead)<sp/>{</highlight></codeline>
<codeline lineno="981"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>We<sp/>have<sp/>upto<sp/>one<sp/>sector<sp/>to<sp/>copy</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="982"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>copyCount<sp/>=<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref><sp/>*<sp/>sectorsRead;</highlight></codeline>
<codeline lineno="983"><highlight class="normal"></highlight></codeline>
<codeline lineno="984"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Move<sp/>onto<sp/>next<sp/>sector<sp/>and<sp/>reset<sp/>copy<sp/>offset</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="985"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sector<sp/>+=<sp/>sectorsRead;</highlight></codeline>
<codeline lineno="986"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>offset<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="987"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="988"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="989"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="990"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="991"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="992"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Do<sp/>we<sp/>need<sp/>to<sp/>re-read<sp/>the<sp/>sector?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="993"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>!=<sp/>sector)<sp/>{</highlight></codeline>
<codeline lineno="994"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Flush<sp/>un-written<sp/>data<sp/>to<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="995"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty)</highlight></codeline>
<codeline lineno="996"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a6a857e4fbf7fa1ebd7d016e8bab36a94" kindref="member">fl_fflush</ref>(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="997"><highlight class="normal"></highlight></codeline>
<codeline lineno="998"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Get<sp/>LBA<sp/>of<sp/>sector<sp/>offset<sp/>within<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="999"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!_read_sectors(<ref refid="structfile" kindref="compound">file</ref>,<sp/>sector,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_sector,<sp/>1))</highlight></codeline>
<codeline lineno="1000"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Read<sp/>failed<sp/>-<sp/>out<sp/>of<sp/>range<sp/>(probably)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1001"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="1002"><highlight class="normal"></highlight></codeline>
<codeline lineno="1003"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>=<sp/>sector;</highlight></codeline>
<codeline lineno="1004"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1005"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1006"><highlight class="normal"></highlight></codeline>
<codeline lineno="1007"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>We<sp/>have<sp/>upto<sp/>one<sp/>sector<sp/>to<sp/>copy</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1008"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>copyCount<sp/>=<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref><sp/>-<sp/>offset;</highlight></codeline>
<codeline lineno="1009"><highlight class="normal"></highlight></codeline>
<codeline lineno="1010"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Only<sp/>require<sp/>some<sp/>of<sp/>this<sp/>sector?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1011"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(copyCount<sp/>&gt;<sp/>(count<sp/>-<sp/>bytesRead))</highlight></codeline>
<codeline lineno="1012"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>copyCount<sp/>=<sp/>(count<sp/>-<sp/>bytesRead);</highlight></codeline>
<codeline lineno="1013"><highlight class="normal"></highlight></codeline>
<codeline lineno="1014"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Copy<sp/>to<sp/>application<sp/>buffer</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1015"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="string_8h_1ae33b18edb618c656b9b795b9fce2316c" kindref="member">memcpy</ref>((<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>*)<sp/>((<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>*)<sp/><ref refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" kindref="member">buffer</ref><sp/>+<sp/>bytesRead),<sp/>(<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>*)<sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_sector<sp/>+<sp/>offset),<sp/>copyCount);</highlight></codeline>
<codeline lineno="1016"><highlight class="normal"></highlight></codeline>
<codeline lineno="1017"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Move<sp/>onto<sp/>next<sp/>sector<sp/>and<sp/>reset<sp/>copy<sp/>offset</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1018"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>sector++;</highlight></codeline>
<codeline lineno="1019"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>offset<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1020"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1021"><highlight class="normal"></highlight></codeline>
<codeline lineno="1022"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Increase<sp/>total<sp/>read<sp/>count</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1023"><highlight class="normal"><sp/><sp/><sp/><sp/>bytesRead<sp/>+=<sp/>copyCount;</highlight></codeline>
<codeline lineno="1024"><highlight class="normal"></highlight></codeline>
<codeline lineno="1025"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Increment<sp/>file<sp/>pointer</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1026"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>+=<sp/>copyCount;</highlight></codeline>
<codeline lineno="1027"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1028"><highlight class="normal"></highlight></codeline>
<codeline lineno="1029"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>bytesRead;</highlight></codeline>
<codeline lineno="1030"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1031"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1032"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fseek:<sp/>Seek<sp/>to<sp/>a<sp/>specific<sp/>place<sp/>in<sp/>the<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1033"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1034" refid="fat__filelib_8h_1aad8ebccf6a0e92762349c738bbe72b3a" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1aca40d99888beddbc51b1a484b3b95757" kindref="member">fl_fseek</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f,<sp/></highlight><highlight class="keywordtype">long</highlight><highlight class="normal"><sp/>offset,<sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>origin)<sp/>{</highlight></codeline>
<codeline lineno="1035"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*)<sp/>f;</highlight></codeline>
<codeline lineno="1036"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res<sp/>=<sp/>-1;</highlight></codeline>
<codeline lineno="1037"><highlight class="normal"></highlight></codeline>
<codeline lineno="1038"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1039"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="1040"><highlight class="normal"></highlight></codeline>
<codeline lineno="1041"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="structfile" kindref="compound">file</ref>)</highlight></codeline>
<codeline lineno="1042"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="1043"><highlight class="normal"></highlight></codeline>
<codeline lineno="1044"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(origin<sp/>==<sp/><ref refid="fat__filelib_8h_1ad2a2e6c114780c3071efd24f16c7f7d8" kindref="member">SEEK_END</ref><sp/>&amp;&amp;<sp/>offset<sp/>!=<sp/>0)</highlight></codeline>
<codeline lineno="1045"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="1046"><highlight class="normal"></highlight></codeline>
<codeline lineno="1047"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1048"><highlight class="normal"></highlight></codeline>
<codeline lineno="1049"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Invalidate<sp/>file<sp/>buffer</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1050"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="1051"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1052"><highlight class="normal"></highlight></codeline>
<codeline lineno="1053"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(origin<sp/>==<sp/><ref refid="fat__filelib_8h_1a0d112bae8fd35be772185b6ec6bcbe64" kindref="member">SEEK_SET</ref>)<sp/>{</highlight></codeline>
<codeline lineno="1054"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/>(<ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref>)<sp/>offset;</highlight></codeline>
<codeline lineno="1055"><highlight class="normal"></highlight></codeline>
<codeline lineno="1056"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>&gt;<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength)</highlight></codeline>
<codeline lineno="1057"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength;</highlight></codeline>
<codeline lineno="1058"><highlight class="normal"></highlight></codeline>
<codeline lineno="1059"><highlight class="normal"><sp/><sp/><sp/><sp/>res<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1060"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1061"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(origin<sp/>==<sp/><ref refid="fat__filelib_8h_1a4c8d0b76b470ba65a43ca46a88320f39" kindref="member">SEEK_CUR</ref>)<sp/>{</highlight></codeline>
<codeline lineno="1062"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Positive<sp/>shift</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1063"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(offset<sp/>&gt;=<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="1064"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>+=<sp/>offset;</highlight></codeline>
<codeline lineno="1065"><highlight class="normal"></highlight></codeline>
<codeline lineno="1066"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>&gt;<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength)</highlight></codeline>
<codeline lineno="1067"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength;</highlight></codeline>
<codeline lineno="1068"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1069"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Negative<sp/>shift</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1070"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="1071"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Make<sp/>shift<sp/>positive</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1072"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>offset<sp/>=<sp/>-offset;</highlight></codeline>
<codeline lineno="1073"><highlight class="normal"></highlight></codeline>
<codeline lineno="1074"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Limit<sp/>to<sp/>negative<sp/>shift<sp/>to<sp/>start<sp/>of<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1075"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((<ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref>)<sp/>offset<sp/>&gt;<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum)</highlight></codeline>
<codeline lineno="1076"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1077"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1078"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>-=<sp/>offset;</highlight></codeline>
<codeline lineno="1079"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1080"><highlight class="normal"></highlight></codeline>
<codeline lineno="1081"><highlight class="normal"><sp/><sp/><sp/><sp/>res<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1082"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1083"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(origin<sp/>==<sp/><ref refid="fat__filelib_8h_1ad2a2e6c114780c3071efd24f16c7f7d8" kindref="member">SEEK_END</ref>)<sp/>{</highlight></codeline>
<codeline lineno="1084"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength;</highlight></codeline>
<codeline lineno="1085"><highlight class="normal"><sp/><sp/><sp/><sp/>res<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1086"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1087"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1088"><highlight class="normal"><sp/><sp/><sp/><sp/>res<sp/>=<sp/>-1;</highlight></codeline>
<codeline lineno="1089"><highlight class="normal"></highlight></codeline>
<codeline lineno="1090"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1091"><highlight class="normal"></highlight></codeline>
<codeline lineno="1092"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1093"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1094"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1095"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fgetpos:<sp/>Get<sp/>the<sp/>current<sp/>file<sp/>position</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1096"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1097" refid="fat__filelib_8h_1afe3f5045d3c354c464f5ddd96271dc33" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a3be6a942f1ebea135e5390e409681c00" kindref="member">fl_fgetpos</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f,<sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>*position)<sp/>{</highlight></codeline>
<codeline lineno="1098"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*)<sp/>f;</highlight></codeline>
<codeline lineno="1099"><highlight class="normal"></highlight></codeline>
<codeline lineno="1100"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="structfile" kindref="compound">file</ref>)</highlight></codeline>
<codeline lineno="1101"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="1102"><highlight class="normal"></highlight></codeline>
<codeline lineno="1103"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1104"><highlight class="normal"></highlight></codeline>
<codeline lineno="1105"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Get<sp/>position</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1106"><highlight class="normal"><sp/><sp/>*position<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum;</highlight></codeline>
<codeline lineno="1107"><highlight class="normal"></highlight></codeline>
<codeline lineno="1108"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1109"><highlight class="normal"></highlight></codeline>
<codeline lineno="1110"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="1111"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1112"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1113"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_ftell:<sp/>Get<sp/>the<sp/>current<sp/>file<sp/>position</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1114"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1115" refid="fat__filelib_8h_1a1e80992d09dd901c83d9e1d924d642f4" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">long</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a1e80992d09dd901c83d9e1d924d642f4" kindref="member">fl_ftell</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="1116"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>pos<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1117"><highlight class="normal"></highlight></codeline>
<codeline lineno="1118"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a3be6a942f1ebea135e5390e409681c00" kindref="member">fl_fgetpos</ref>(f,<sp/>&amp;pos);</highlight></codeline>
<codeline lineno="1119"><highlight class="normal"></highlight></codeline>
<codeline lineno="1120"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">long</highlight><highlight class="normal">)<sp/>pos;</highlight></codeline>
<codeline lineno="1121"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1122"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1123"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_feof:<sp/>Is<sp/>the<sp/>file<sp/>pointer<sp/>at<sp/>the<sp/>end<sp/>of<sp/>the<sp/>stream?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1124"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1125" refid="fat__filelib_8h_1a870d92346325af5246948e81e33a51d5" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a870d92346325af5246948e81e33a51d5" kindref="member">fl_feof</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="1126"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*)<sp/>f;</highlight></codeline>
<codeline lineno="1127"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1128"><highlight class="normal"></highlight></codeline>
<codeline lineno="1129"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="structfile" kindref="compound">file</ref>)</highlight></codeline>
<codeline lineno="1130"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="1131"><highlight class="normal"></highlight></codeline>
<codeline lineno="1132"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1133"><highlight class="normal"></highlight></codeline>
<codeline lineno="1134"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>==<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength)</highlight></codeline>
<codeline lineno="1135"><highlight class="normal"><sp/><sp/><sp/><sp/>res<sp/>=<sp/><ref refid="fat__filelib_8h_1a59adc4c82490d23754cd39c2fb99b0da" kindref="member">EOF</ref>;</highlight></codeline>
<codeline lineno="1136"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1137"><highlight class="normal"><sp/><sp/><sp/><sp/>res<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1138"><highlight class="normal"></highlight></codeline>
<codeline lineno="1139"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1140"><highlight class="normal"></highlight></codeline>
<codeline lineno="1141"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1142"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1143"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1144"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fputc:<sp/>Write<sp/>a<sp/>character<sp/>to<sp/>the<sp/>stream</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1145"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1146"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1147" refid="fat__filelib_8h_1a8304df4fb0abe6a2d552fa39d8559a2d" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a4083be2162ea554186859138911f0db1" kindref="member">fl_fputc</ref>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>c,<sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="1148"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref><sp/>data<sp/>=<sp/>(<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>)<sp/>c;</highlight></codeline>
<codeline lineno="1149"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1150"><highlight class="normal"></highlight></codeline>
<codeline lineno="1151"><highlight class="normal"><sp/><sp/>res<sp/>=<sp/><ref refid="fat__filelib_8c_1a8349790c61beca1a9138fb28a2689607" kindref="member">fl_fwrite</ref>(&amp;data,<sp/>1,<sp/>1,<sp/>f);</highlight></codeline>
<codeline lineno="1152"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(res<sp/>==<sp/>1)</highlight></codeline>
<codeline lineno="1153"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>c;</highlight></codeline>
<codeline lineno="1154"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1155"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1156"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1157"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1158"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1159"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fwrite:<sp/>Write<sp/>a<sp/>block<sp/>of<sp/>data<sp/>to<sp/>the<sp/>stream</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1160"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1161"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1162" refid="fat__filelib_8h_1a72f5f8018ba62e365718d2e7eba374fa" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a8349790c61beca1a9138fb28a2689607" kindref="member">fl_fwrite</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*data,<sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>size,<sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>count,<sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="1163"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/>(<ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref>*)<sp/>f;</highlight></codeline>
<codeline lineno="1164"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>sector;</highlight></codeline>
<codeline lineno="1165"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>offset;</highlight></codeline>
<codeline lineno="1166"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>length<sp/>=<sp/>(size<sp/>*<sp/>count);</highlight></codeline>
<codeline lineno="1167"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref><sp/>*<ref refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" kindref="member">buffer</ref><sp/>=<sp/>(<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>*)<sp/>data;</highlight></codeline>
<codeline lineno="1168"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>bytesWritten<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1169"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>copyCount;</highlight></codeline>
<codeline lineno="1170"><highlight class="normal"></highlight></codeline>
<codeline lineno="1171"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1172"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="1173"><highlight class="normal"></highlight></codeline>
<codeline lineno="1174"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!<ref refid="structfile" kindref="compound">file</ref>)</highlight></codeline>
<codeline lineno="1175"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="1176"><highlight class="normal"></highlight></codeline>
<codeline lineno="1177"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1178"><highlight class="normal"></highlight></codeline>
<codeline lineno="1179"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>No<sp/>write<sp/>permissions</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1180"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!(<ref refid="structfile" kindref="compound">file</ref>-&gt;flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1ace34e503254fa9004599ddf122264c8f" kindref="member">FILE_WRITE</ref>))<sp/>{</highlight></codeline>
<codeline lineno="1181"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1182"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="1183"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1184"><highlight class="normal"></highlight></codeline>
<codeline lineno="1185"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Append<sp/>writes<sp/>to<sp/>end<sp/>of<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1186"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;flags<sp/>&amp;<sp/><ref refid="fat__filelib_8h_1abb57841952be5b0be972b4bef8fd5021" kindref="member">FILE_APPEND</ref>)</highlight></codeline>
<codeline lineno="1187"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength;</highlight></codeline>
<codeline lineno="1188"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Else<sp/>write<sp/>to<sp/>current<sp/>position</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1189"><highlight class="normal"></highlight></codeline>
<codeline lineno="1190"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Calculate<sp/>start<sp/>sector</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1191"><highlight class="normal"><sp/><sp/>sector<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>/<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>;</highlight></codeline>
<codeline lineno="1192"><highlight class="normal"></highlight></codeline>
<codeline lineno="1193"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Offset<sp/>to<sp/>start<sp/>copying<sp/>data<sp/>from<sp/>first<sp/>sector</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1194"><highlight class="normal"><sp/><sp/>offset<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>%<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>;</highlight></codeline>
<codeline lineno="1195"><highlight class="normal"></highlight></codeline>
<codeline lineno="1196"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(bytesWritten<sp/>&lt;<sp/>length)<sp/>{</highlight></codeline>
<codeline lineno="1197"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Whole<sp/>sector<sp/>or<sp/>more<sp/>to<sp/>be<sp/>written?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1198"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((offset<sp/>==<sp/>0)<sp/>&amp;&amp;<sp/>((length<sp/>-<sp/>bytesWritten)<sp/>&gt;=<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>))<sp/>{</highlight></codeline>
<codeline lineno="1199"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>sectorsWrote;</highlight></codeline>
<codeline lineno="1200"><highlight class="normal"></highlight></codeline>
<codeline lineno="1201"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Buffered<sp/>sector,<sp/>flush<sp/>back<sp/>to<sp/>disk</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1202"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>!=<sp/>0xFFFFFFFF)<sp/>{</highlight></codeline>
<codeline lineno="1203"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Flush<sp/>un-written<sp/>data<sp/>to<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1204"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty)</highlight></codeline>
<codeline lineno="1205"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a6a857e4fbf7fa1ebd7d016e8bab36a94" kindref="member">fl_fflush</ref>(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="1206"><highlight class="normal"></highlight></codeline>
<codeline lineno="1207"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>=<sp/>0xFFFFFFFF;</highlight></codeline>
<codeline lineno="1208"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1209"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1210"><highlight class="normal"></highlight></codeline>
<codeline lineno="1211"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Write<sp/>as<sp/>many<sp/>sectors<sp/>as<sp/>possible</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1212"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>sectorsWrote<sp/>=<sp/>_write_sectors(<ref refid="structfile" kindref="compound">file</ref>,<sp/>sector,<sp/>(<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>*)<sp/>(<ref refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" kindref="member">buffer</ref><sp/>+<sp/>bytesWritten),<sp/>(length<sp/>-<sp/>bytesWritten)<sp/>/<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>);</highlight></codeline>
<codeline lineno="1213"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>copyCount<sp/>=<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref><sp/>*<sp/>sectorsWrote;</highlight></codeline>
<codeline lineno="1214"><highlight class="normal"></highlight></codeline>
<codeline lineno="1215"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Increase<sp/>total<sp/>read<sp/>count</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1216"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>bytesWritten<sp/>+=<sp/>copyCount;</highlight></codeline>
<codeline lineno="1217"><highlight class="normal"></highlight></codeline>
<codeline lineno="1218"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Increment<sp/>file<sp/>pointer</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1219"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>+=<sp/>copyCount;</highlight></codeline>
<codeline lineno="1220"><highlight class="normal"></highlight></codeline>
<codeline lineno="1221"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Move<sp/>onto<sp/>next<sp/>sector<sp/>and<sp/>reset<sp/>copy<sp/>offset</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1222"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>sector<sp/>+=<sp/>sectorsWrote;</highlight></codeline>
<codeline lineno="1223"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>offset<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1224"><highlight class="normal"></highlight></codeline>
<codeline lineno="1225"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!sectorsWrote)</highlight></codeline>
<codeline lineno="1226"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="1227"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1228"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="1229"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>We<sp/>have<sp/>upto<sp/>one<sp/>sector<sp/>to<sp/>copy</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1230"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>copyCount<sp/>=<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref><sp/>-<sp/>offset;</highlight></codeline>
<codeline lineno="1231"><highlight class="normal"></highlight></codeline>
<codeline lineno="1232"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Only<sp/>require<sp/>some<sp/>of<sp/>this<sp/>sector?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1233"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(copyCount<sp/>&gt;<sp/>(length<sp/>-<sp/>bytesWritten))</highlight></codeline>
<codeline lineno="1234"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>copyCount<sp/>=<sp/>(length<sp/>-<sp/>bytesWritten);</highlight></codeline>
<codeline lineno="1235"><highlight class="normal"></highlight></codeline>
<codeline lineno="1236"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Do<sp/>we<sp/>need<sp/>to<sp/>read<sp/>a<sp/>new<sp/>sector?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1237"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>!=<sp/>sector)<sp/>{</highlight></codeline>
<codeline lineno="1238"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Flush<sp/>un-written<sp/>data<sp/>to<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1239"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty)</highlight></codeline>
<codeline lineno="1240"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a6a857e4fbf7fa1ebd7d016e8bab36a94" kindref="member">fl_fflush</ref>(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="1241"><highlight class="normal"></highlight></codeline>
<codeline lineno="1242"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>we<sp/>plan<sp/>to<sp/>overwrite<sp/>the<sp/>whole<sp/>sector,<sp/>we<sp/>don&apos;t<sp/>need<sp/>to<sp/>read<sp/>it<sp/>first!</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1243"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(copyCount<sp/>!=<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>)<sp/>{</highlight></codeline>
<codeline lineno="1244"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>NOTE:<sp/>This<sp/>does<sp/>not<sp/>have<sp/>succeed;<sp/>if<sp/>last<sp/>sector<sp/>of<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1245"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>reached,<sp/>no<sp/>valid<sp/>data<sp/>will<sp/>be<sp/>read<sp/>in,<sp/>but<sp/>write<sp/>will</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1246"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>allocate<sp/>some<sp/>more<sp/>space<sp/>for<sp/>new<sp/>data.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1247"><highlight class="normal"></highlight></codeline>
<codeline lineno="1248"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Get<sp/>LBA<sp/>of<sp/>sector<sp/>offset<sp/>within<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1249"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!_read_sectors(<ref refid="structfile" kindref="compound">file</ref>,<sp/>sector,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_sector,<sp/>1))</highlight></codeline>
<codeline lineno="1250"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="string_8h_1ace4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_sector,<sp/>0x00,<sp/><ref refid="fat__opts_8h_1a873b78b38ef34edf6291274eb0708634" kindref="member">FAT_SECTOR_SIZE</ref>);</highlight></codeline>
<codeline lineno="1251"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1252"><highlight class="normal"></highlight></codeline>
<codeline lineno="1253"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_address<sp/>=<sp/>sector;</highlight></codeline>
<codeline lineno="1254"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1255"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1256"><highlight class="normal"></highlight></codeline>
<codeline lineno="1257"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Copy<sp/>from<sp/>application<sp/>buffer<sp/>into<sp/>sector<sp/>buffer</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1258"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="string_8h_1ae33b18edb618c656b9b795b9fce2316c" kindref="member">memcpy</ref>((<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>*)<sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_sector<sp/>+<sp/>offset),<sp/>(<ref refid="fat__types_8h_1adde6aaee8457bee49c2a92621fe22b79" kindref="member">uint8</ref>*)<sp/>(<ref refid="shell_8c_1aff2566f4c366b48d73479bef43ee4d2e" kindref="member">buffer</ref><sp/>+<sp/>bytesWritten),<sp/>copyCount);</highlight></codeline>
<codeline lineno="1259"><highlight class="normal"></highlight></codeline>
<codeline lineno="1260"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Mark<sp/>buffer<sp/>as<sp/>dirty</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1261"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;file_data_dirty<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="1262"><highlight class="normal"></highlight></codeline>
<codeline lineno="1263"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Increase<sp/>total<sp/>read<sp/>count</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1264"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>bytesWritten<sp/>+=<sp/>copyCount;</highlight></codeline>
<codeline lineno="1265"><highlight class="normal"></highlight></codeline>
<codeline lineno="1266"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Increment<sp/>file<sp/>pointer</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1267"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>+=<sp/>copyCount;</highlight></codeline>
<codeline lineno="1268"><highlight class="normal"></highlight></codeline>
<codeline lineno="1269"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Move<sp/>onto<sp/>next<sp/>sector<sp/>and<sp/>reset<sp/>copy<sp/>offset</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1270"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>sector++;</highlight></codeline>
<codeline lineno="1271"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>offset<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1272"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1273"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1274"><highlight class="normal"></highlight></codeline>
<codeline lineno="1275"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Write<sp/>increased<sp/>extent<sp/>of<sp/>the<sp/>file?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1276"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum<sp/>&gt;<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength)<sp/>{</highlight></codeline>
<codeline lineno="1277"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Increase<sp/>file<sp/>size<sp/>to<sp/>new<sp/>point</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1278"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength<sp/>=<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;bytenum;</highlight></codeline>
<codeline lineno="1279"><highlight class="normal"></highlight></codeline>
<codeline lineno="1280"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>We<sp/>are<sp/>changing<sp/>the<sp/>file<sp/>length<sp/>and<sp/>this</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1281"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>will<sp/>need<sp/>to<sp/>be<sp/>writen<sp/>back<sp/>at<sp/>some<sp/>point</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1282"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength_changed<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="1283"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1284"><highlight class="normal"></highlight></codeline>
<codeline lineno="1285"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_TIME_DATE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1286"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>time<sp/>&amp;<sp/>date<sp/>support<sp/>is<sp/>enabled,<sp/>always<sp/>force<sp/>directory<sp/>entry<sp/>to<sp/>be</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1287"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>written<sp/>in-order<sp/>to<sp/>update<sp/>file<sp/>modify<sp/>/<sp/>access<sp/>time<sp/>&amp;<sp/>date.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1288"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;filelength_changed<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="1289"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1290"><highlight class="normal"></highlight></codeline>
<codeline lineno="1291"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1292"><highlight class="normal"></highlight></codeline>
<codeline lineno="1293"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>(size<sp/>*<sp/>count);</highlight></codeline>
<codeline lineno="1294"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1295"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1296"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1297"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_fputs:<sp/>Write<sp/>a<sp/>character<sp/>string<sp/>to<sp/>the<sp/>stream</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1298"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1299"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1300" refid="fat__filelib_8h_1a3e374b01d35084aa1eee63e50afdf097" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a04f7ea53fa5650e4dca7767b0f9eb72e" kindref="member">fl_fputs</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*str,<sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*f)<sp/>{</highlight></codeline>
<codeline lineno="1301"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>len<sp/>=<sp/>(int)<sp/><ref refid="lib_8h_1ae6c8de953239811a34eeeab09458e55e" kindref="member">strlen</ref>(str);</highlight></codeline>
<codeline lineno="1302"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res<sp/>=<sp/><ref refid="fat__filelib_8c_1a8349790c61beca1a9138fb28a2689607" kindref="member">fl_fwrite</ref>(str,<sp/>1,<sp/>len,<sp/>f);</highlight></codeline>
<codeline lineno="1303"><highlight class="normal"></highlight></codeline>
<codeline lineno="1304"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(res<sp/>==<sp/>len)</highlight></codeline>
<codeline lineno="1305"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>len;</highlight></codeline>
<codeline lineno="1306"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1307"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1308"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1309"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1310"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1311"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_remove:<sp/>Remove<sp/>a<sp/>file<sp/>from<sp/>the<sp/>filesystem</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1312"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1313"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1314" refid="fat__filelib_8h_1ac3e517a9ac192e87329a62e5e8d53b2b" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1ac3e517a9ac192e87329a62e5e8d53b2b" kindref="member">fl_remove</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*filename)<sp/>{</highlight></codeline>
<codeline lineno="1315"><highlight class="normal"><sp/><sp/><ref refid="structsFL__FILE" kindref="compound">FL_FILE</ref><sp/>*<ref refid="tcpdump_8c_1a03d2d7be521e9d357862075078d24f06" kindref="member">file</ref>;</highlight></codeline>
<codeline lineno="1316"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res<sp/>=<sp/>-1;</highlight></codeline>
<codeline lineno="1317"><highlight class="normal"></highlight></codeline>
<codeline lineno="1318"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1319"><highlight class="normal"></highlight></codeline>
<codeline lineno="1320"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Use<sp/>read_file<sp/>as<sp/>this<sp/>will<sp/>check<sp/>if<sp/>the<sp/>file<sp/>is<sp/>already<sp/>open!</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1321"><highlight class="normal"><sp/><sp/><ref refid="structfile" kindref="compound">file</ref><sp/>=<sp/><ref refid="fat__filelib_8c_1a800a79c9fb283c5f5199e08b1f2ada38" kindref="member">fl_fopen</ref>((</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/>filename,<sp/></highlight><highlight class="stringliteral">&quot;r&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline lineno="1322"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structfile" kindref="compound">file</ref>)<sp/>{</highlight></codeline>
<codeline lineno="1323"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>allocated<sp/>space</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1324"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__table_8c_1a7a329446088ccb4d6348f05fcd848ee4" kindref="member">fatfs_free_cluster_chain</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;startcluster))<sp/>{</highlight></codeline>
<codeline lineno="1325"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Remove<sp/>directory<sp/>entries</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1326"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__access_8c_1a7333a9802b496ce05ca6df36c2fc6009" kindref="member">fatfs_mark_file_deleted</ref>(&amp;_fs,<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;parentcluster,<sp/>(</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/><ref refid="structfile" kindref="compound">file</ref>-&gt;shortfilename))<sp/>{</highlight></codeline>
<codeline lineno="1327"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Close<sp/>the<sp/>file<sp/>handle<sp/>(this<sp/>should<sp/>not<sp/>write<sp/>anything<sp/>to<sp/>the<sp/>file</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1328"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>as<sp/>we<sp/>have<sp/>not<sp/>changed<sp/>the<sp/>file<sp/>since<sp/>opening<sp/>it!)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1329"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1aef5675bf1c0db1d3e073ea36d4cf2d3a" kindref="member">fl_fclose</ref>(<ref refid="structfile" kindref="compound">file</ref>);</highlight></codeline>
<codeline lineno="1330"><highlight class="normal"></highlight></codeline>
<codeline lineno="1331"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>res<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1332"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1333"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1334"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1335"><highlight class="normal"></highlight></codeline>
<codeline lineno="1336"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1337"><highlight class="normal"></highlight></codeline>
<codeline lineno="1338"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1339"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1340"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1341"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1342"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_createdirectory:<sp/>Create<sp/>a<sp/>directory<sp/>based<sp/>on<sp/>a<sp/>path</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1343"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1344"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_WRITE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1345" refid="fat__filelib_8h_1ab8d071e615bfb315cc0b6a3836e275e2" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1ab8d071e615bfb315cc0b6a3836e275e2" kindref="member">fl_createdirectory</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*path)<sp/>{</highlight></codeline>
<codeline lineno="1346"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1347"><highlight class="normal"></highlight></codeline>
<codeline lineno="1348"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1349"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="1350"><highlight class="normal"></highlight></codeline>
<codeline lineno="1351"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1352"><highlight class="normal"><sp/><sp/>res<sp/>=<sp/>_create_directory((</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/>path);</highlight></codeline>
<codeline lineno="1353"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1354"><highlight class="normal"></highlight></codeline>
<codeline lineno="1355"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1356"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1357"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1358"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1359"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_listdirectory:<sp/>List<sp/>a<sp/>directory<sp/>based<sp/>on<sp/>a<sp/>path</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1360"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1361"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_DIR_LIST_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1362" refid="fat__filelib_8h_1a28ef1f43950ba4743e5ddd57db5b8b6e" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a28ef1f43950ba4743e5ddd57db5b8b6e" kindref="member">fl_listdirectory</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*path)<sp/>{</highlight></codeline>
<codeline lineno="1363"><highlight class="normal"><sp/><sp/><ref refid="structfs__dir__list__status" kindref="compound">FL_DIR</ref><sp/>dirstat;</highlight></codeline>
<codeline lineno="1364"><highlight class="normal"></highlight></codeline>
<codeline lineno="1365"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1366"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="1367"><highlight class="normal"></highlight></codeline>
<codeline lineno="1368"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1369"><highlight class="normal"></highlight></codeline>
<codeline lineno="1370"><highlight class="normal"><sp/><sp/><ref refid="fat__opts_8h_1a77e202c52dfa1ae6a4a060b21b70a80c" kindref="member">FAT_PRINTF</ref>((</highlight><highlight class="stringliteral">&quot;\r\nDirectory<sp/>%s\r\n&quot;</highlight><highlight class="normal">,<sp/>path));</highlight></codeline>
<codeline lineno="1371"><highlight class="normal"></highlight></codeline>
<codeline lineno="1372"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__filelib_8c_1a3aba2e202e0af1fb8711eec13e5e9b08" kindref="member">fl_opendir</ref>(path,<sp/>&amp;dirstat))<sp/>{</highlight></codeline>
<codeline lineno="1373"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfs__dir__ent" kindref="compound">fs_dir_ent</ref><sp/><ref refid="structdirent" kindref="compound">dirent</ref>;</highlight></codeline>
<codeline lineno="1374"><highlight class="normal"></highlight></codeline>
<codeline lineno="1375"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(<ref refid="fat__filelib_8c_1aa13527c9d4fc15a67a5608d9645b7ad8" kindref="member">fl_readdir</ref>(&amp;dirstat,<sp/>&amp;<ref refid="structdirent" kindref="compound">dirent</ref>)<sp/>==<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="1376"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_TIME_DATE_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1377"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>d,m,y,h,mn,s;</highlight></codeline>
<codeline lineno="1378"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__misc_8h_1a8a0d22e7688e318ede6457eca6ba072d" kindref="member">fatfs_convert_from_fat_time</ref>(<ref refid="structdirent" kindref="compound">dirent</ref>.write_time,<sp/>&amp;h,&amp;m,&amp;s);</highlight></codeline>
<codeline lineno="1379"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__misc_8h_1ad9567e1afb538f55b9f5c8ec46871f44" kindref="member">fatfs_convert_from_fat_date</ref>(<ref refid="structdirent" kindref="compound">dirent</ref>.write_date,<sp/>&amp;d,&amp;mn,&amp;y);</highlight></codeline>
<codeline lineno="1380"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__opts_8h_1a77e202c52dfa1ae6a4a060b21b70a80c" kindref="member">FAT_PRINTF</ref>((</highlight><highlight class="stringliteral">&quot;%02d/%02d/%04d<sp/><sp/>%02d:%02d<sp/><sp/><sp/><sp/><sp/><sp/>&quot;</highlight><highlight class="normal">,<sp/>d,mn,y,h,m));</highlight></codeline>
<codeline lineno="1381"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1382"><highlight class="normal"></highlight></codeline>
<codeline lineno="1383"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structdirent" kindref="compound">dirent</ref>.is_dir)<sp/>{</highlight></codeline>
<codeline lineno="1384"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__opts_8h_1a77e202c52dfa1ae6a4a060b21b70a80c" kindref="member">FAT_PRINTF</ref>((</highlight><highlight class="stringliteral">&quot;%s<sp/>&lt;DIR&gt;\r\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="structdirent" kindref="compound">dirent</ref>.filename));</highlight></codeline>
<codeline lineno="1385"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1386"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="1387"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="fat__opts_8h_1a77e202c52dfa1ae6a4a060b21b70a80c" kindref="member">FAT_PRINTF</ref>((</highlight><highlight class="stringliteral">&quot;%s<sp/>[%d<sp/>bytes]\r\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="structdirent" kindref="compound">dirent</ref>.filename,<sp/><ref refid="structdirent" kindref="compound">dirent</ref>.size));</highlight></codeline>
<codeline lineno="1388"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1389"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="1390"><highlight class="normal"></highlight></codeline>
<codeline lineno="1391"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a236effde34fb2dd06c45f88035d0a670" kindref="member">fl_closedir</ref>(&amp;dirstat);</highlight></codeline>
<codeline lineno="1392"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1393"><highlight class="normal"></highlight></codeline>
<codeline lineno="1394"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1395"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1396"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1397"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1398"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_opendir:<sp/>Opens<sp/>a<sp/>directory<sp/>for<sp/>listing</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1399"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1400"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_DIR_LIST_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1401" refid="fat__filelib_8h_1a3aba2e202e0af1fb8711eec13e5e9b08" refkind="member"><highlight class="normal"><ref refid="structfs__dir__list__status" kindref="compound">FL_DIR</ref>*<sp/><ref refid="fat__filelib_8c_1a3aba2e202e0af1fb8711eec13e5e9b08" kindref="member">fl_opendir</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*path,<sp/><ref refid="structfs__dir__list__status" kindref="compound">FL_DIR</ref><sp/>*dir)<sp/>{</highlight></codeline>
<codeline lineno="1402"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>levels;</highlight></codeline>
<codeline lineno="1403"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="1404"><highlight class="normal"><sp/><sp/><ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/><ref refid="structfs__dir__ent_1a6286cbb9d382cacf4e15b03ffd0c352c" kindref="member">cluster</ref><sp/>=<sp/><ref refid="fat__defs_8h_1a8dd000b545e9a127169fdbd82d418965" kindref="member">FAT32_INVALID_CLUSTER</ref>;</highlight></codeline>
<codeline lineno="1405"><highlight class="normal"></highlight></codeline>
<codeline lineno="1406"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1407"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="1408"><highlight class="normal"></highlight></codeline>
<codeline lineno="1409"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1410"><highlight class="normal"></highlight></codeline>
<codeline lineno="1411"><highlight class="normal"><sp/><sp/>levels<sp/>=<sp/><ref refid="fat__string_8c_1aa3ef1d2590f2284ef1f983d6f7b2ad29" kindref="member">fatfs_total_path_levels</ref>((</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/>path)<sp/>+<sp/>1;</highlight></codeline>
<codeline lineno="1412"><highlight class="normal"></highlight></codeline>
<codeline lineno="1413"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>path<sp/>is<sp/>in<sp/>the<sp/>root<sp/>dir</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1414"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(levels<sp/>==<sp/>0)</highlight></codeline>
<codeline lineno="1415"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structfs__dir__ent_1a6286cbb9d382cacf4e15b03ffd0c352c" kindref="member">cluster</ref><sp/>=<sp/><ref refid="fat__access_8c_1a6d36c74c7a9ba228d327067786ecb0c2" kindref="member">fatfs_get_root_cluster</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1416"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Find<sp/>parent<sp/>directory<sp/>start<sp/>cluster</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1417"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1418"><highlight class="normal"><sp/><sp/><sp/><sp/>res<sp/>=<sp/>_open_directory((</highlight><highlight class="keywordtype">char</highlight><highlight class="normal">*)<sp/>path,<sp/>&amp;<ref refid="structfs__dir__ent_1a6286cbb9d382cacf4e15b03ffd0c352c" kindref="member">cluster</ref>);</highlight></codeline>
<codeline lineno="1419"><highlight class="normal"></highlight></codeline>
<codeline lineno="1420"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(res)</highlight></codeline>
<codeline lineno="1421"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__access_8c_1a4873df5d542fddb4a1d3b2884b56525e" kindref="member">fatfs_list_directory_start</ref>(&amp;_fs,<sp/>dir,<sp/><ref refid="structfs__dir__ent_1a6286cbb9d382cacf4e15b03ffd0c352c" kindref="member">cluster</ref>);</highlight></codeline>
<codeline lineno="1422"><highlight class="normal"></highlight></codeline>
<codeline lineno="1423"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1424"><highlight class="normal"></highlight></codeline>
<codeline lineno="1425"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="structfs__dir__ent_1a6286cbb9d382cacf4e15b03ffd0c352c" kindref="member">cluster</ref><sp/>!=<sp/><ref refid="fat__defs_8h_1a8dd000b545e9a127169fdbd82d418965" kindref="member">FAT32_INVALID_CLUSTER</ref><sp/>?<sp/>dir<sp/>:<sp/>0;</highlight></codeline>
<codeline lineno="1426"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1427"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1428"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1429"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_readdir:<sp/>Get<sp/>next<sp/>item<sp/>in<sp/>directory</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1430"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1431"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_DIR_LIST_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1432" refid="fat__filelib_8h_1aa13527c9d4fc15a67a5608d9645b7ad8" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1aa13527c9d4fc15a67a5608d9645b7ad8" kindref="member">fl_readdir</ref>(<ref refid="structfs__dir__list__status" kindref="compound">FL_DIR</ref><sp/>*dirls,<sp/><ref refid="structfs__dir__ent" kindref="compound">fl_dirent</ref><sp/>*entry)<sp/>{</highlight></codeline>
<codeline lineno="1433"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1434"><highlight class="normal"></highlight></codeline>
<codeline lineno="1435"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>If<sp/>first<sp/>call<sp/>to<sp/>library,<sp/>initialise</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1436"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1ac1d106623faa1621ee2244ac086c7252" kindref="member">CHECK_FL_INIT</ref>();</highlight></codeline>
<codeline lineno="1437"><highlight class="normal"></highlight></codeline>
<codeline lineno="1438"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a83cfcbafb27a4a899cc602da8a9ab29d" kindref="member">FL_LOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1439"><highlight class="normal"></highlight></codeline>
<codeline lineno="1440"><highlight class="normal"><sp/><sp/>res<sp/>=<sp/><ref refid="fat__access_8c_1a256495a47634d609602fc487830aba5c" kindref="member">fatfs_list_directory_next</ref>(&amp;_fs,<sp/>dirls,<sp/>entry);</highlight></codeline>
<codeline lineno="1441"><highlight class="normal"></highlight></codeline>
<codeline lineno="1442"><highlight class="normal"><sp/><sp/><ref refid="fat__filelib_8c_1a4e17542efa253bb6c0c0572d12ea263a" kindref="member">FL_UNLOCK</ref>(&amp;_fs);</highlight></codeline>
<codeline lineno="1443"><highlight class="normal"></highlight></codeline>
<codeline lineno="1444"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res<sp/>?<sp/>0<sp/>:<sp/>-1;</highlight></codeline>
<codeline lineno="1445"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1446"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1447"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1448"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_closedir:<sp/>Close<sp/>directory<sp/>after<sp/>listing</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1449"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1450"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_DIR_LIST_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1451" refid="fat__filelib_8h_1a236effde34fb2dd06c45f88035d0a670" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a236effde34fb2dd06c45f88035d0a670" kindref="member">fl_closedir</ref>(<ref refid="structfs__dir__list__status" kindref="compound">FL_DIR</ref><sp/>*dir)<sp/>{</highlight></codeline>
<codeline lineno="1452"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Not<sp/>used</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1453"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="1454"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1455"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1456"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1457"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_is_dir:<sp/>Is<sp/>this<sp/>a<sp/>directory?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1458"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1459"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_DIR_LIST_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1460" refid="fat__filelib_8h_1a02c9d78edd8026a5a633724a36849d16" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1a02c9d78edd8026a5a633724a36849d16" kindref="member">fl_is_dir</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*path)<sp/>{</highlight></codeline>
<codeline lineno="1461"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>res<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="1462"><highlight class="normal"><sp/><sp/><ref refid="structfs__dir__list__status" kindref="compound">FL_DIR</ref><sp/>dir;</highlight></codeline>
<codeline lineno="1463"><highlight class="normal"></highlight></codeline>
<codeline lineno="1464"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="fat__filelib_8c_1a3aba2e202e0af1fb8711eec13e5e9b08" kindref="member">fl_opendir</ref>(path,<sp/>&amp;dir))<sp/>{</highlight></codeline>
<codeline lineno="1465"><highlight class="normal"><sp/><sp/><sp/><sp/>res<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="1466"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="fat__filelib_8c_1a236effde34fb2dd06c45f88035d0a670" kindref="member">fl_closedir</ref>(&amp;dir);</highlight></codeline>
<codeline lineno="1467"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="1468"><highlight class="normal"></highlight></codeline>
<codeline lineno="1469"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>res;</highlight></codeline>
<codeline lineno="1470"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1471"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1472"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1473"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_format:<sp/>Format<sp/>a<sp/>partition<sp/>with<sp/>either<sp/>FAT16<sp/>or<sp/>FAT32<sp/>based<sp/>on<sp/>size</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1474"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1475"><highlight class="normal"></highlight><highlight class="preprocessor">#if<sp/>FATFS_INC_FORMAT_SUPPORT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1476" refid="fat__filelib_8h_1af3d1cddac050fee30d1420e68b01e7c2" refkind="member"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="fat__filelib_8c_1af3d1cddac050fee30d1420e68b01e7c2" kindref="member">fl_format</ref>(<ref refid="fat__types_8h_1a4b435a49c74bb91f284f075e63416cb6" kindref="member">uint32</ref><sp/>volume_sectors,<sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*<ref refid="pci_8c_1a8f8f80d37794cde9472343e4487ba3eb" kindref="member">name</ref>)<sp/>{</highlight></codeline>
<codeline lineno="1477"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="fat__format_8c_1a8958cfd5dc4bfceb08f41e50e54da92d" kindref="member">fatfs_format</ref>(&amp;_fs,<sp/>volume_sectors,<sp/><ref refid="pci_8c_1a8f8f80d37794cde9472343e4487ba3eb" kindref="member">name</ref>);</highlight></codeline>
<codeline lineno="1478"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1479"><highlight class="normal"></highlight><highlight class="preprocessor">#endif<sp/></highlight><highlight class="comment">/*FATFS_INC_FORMAT_SUPPORT*/</highlight><highlight class="preprocessor"></highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1480"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1481"><highlight class="normal"></highlight><highlight class="comment">//<sp/>fl_get_fs:</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1482"><highlight class="normal"></highlight><highlight class="comment">//-----------------------------------------------------------------------------</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1483"><highlight class="normal"></highlight><highlight class="preprocessor">#ifdef<sp/>FATFS_INC_TEST_HOOKS</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="1484"><highlight class="normal"></highlight><highlight class="keyword">struct<sp/></highlight><highlight class="normal"><ref refid="structfatfs" kindref="compound">fatfs</ref>*<sp/>fl_get_fs(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)</highlight></codeline>
<codeline lineno="1485"><highlight class="normal">{</highlight></codeline>
<codeline lineno="1486"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>&amp;_fs;</highlight></codeline>
<codeline lineno="1487"><highlight class="normal">}</highlight></codeline>
<codeline lineno="1488"><highlight class="normal"></highlight><highlight class="preprocessor">#endif</highlight></codeline>
    </programlisting>
    <location file="C:/Dev/git/UbixOS/sys/fs/fat/fat_filelib.c"/>
  </compounddef>
</doxygen>
