File: ex_file_system_8c-example.html

package info (click to toggle)
wiredtiger 3.2.1-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 25,456 kB
  • sloc: ansic: 102,922; python: 52,573; sh: 6,915; java: 6,130; cpp: 2,311; makefile: 1,018; xml: 176
file content (81 lines) | stat: -rw-r--r-- 86,284 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>WiredTiger: ex_file_system.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="wiredtiger.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://wiredtiger.com/"><img alt="Logo" src="LogoFinal-header.png" alt="WiredTiger" /></a></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">
   &#160;<span id="projectnumber">Version 3.2.1</span>
   </div>
   <div id="projectbrief"><!-- 3.2.1 --></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<div class="banner">
  <a href="https://github.com/wiredtiger/wiredtiger">Fork me on GitHub</a>
  <a class="last" href="http://groups.google.com/group/wiredtiger-users">Join my user group</a>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',false,false,'search.php','Search');
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('ex_file_system_8c-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">ex_file_system.c</div>  </div>
</div><!--header-->
<div class="contents">
<p>Shows how to extend WiredTiger with a custom file-system implementation.</p>
<div class="fragment"><div class="line"><span class="comment">/*-</span></div><div class="line"><span class="comment"> * Public Domain 2014-2019 MongoDB, Inc.</span></div><div class="line"><span class="comment"> * Public Domain 2008-2014 WiredTiger, Inc.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This is free and unencumbered software released into the public domain.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Anyone is free to copy, modify, publish, use, compile, sell, or</span></div><div class="line"><span class="comment"> * distribute this software, either in source code form or as a compiled</span></div><div class="line"><span class="comment"> * binary, for any purpose, commercial or non-commercial, and by any</span></div><div class="line"><span class="comment"> * means.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * In jurisdictions that recognize copyright laws, the author or authors</span></div><div class="line"><span class="comment"> * of this software dedicate any and all copyright interest in the</span></div><div class="line"><span class="comment"> * software to the public domain. We make this dedication for the benefit</span></div><div class="line"><span class="comment"> * of the public at large and to the detriment of our heirs and</span></div><div class="line"><span class="comment"> * successors. We intend this dedication to be an overt act of</span></div><div class="line"><span class="comment"> * relinquishment in perpetuity of all present and future rights to this</span></div><div class="line"><span class="comment"> * software under copyright law.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,</span></div><div class="line"><span class="comment"> * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span></div><div class="line"><span class="comment"> * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.</span></div><div class="line"><span class="comment"> * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR</span></div><div class="line"><span class="comment"> * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,</span></div><div class="line"><span class="comment"> * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR</span></div><div class="line"><span class="comment"> * OTHER DEALINGS IN THE SOFTWARE.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * ex_file_system.c</span></div><div class="line"><span class="comment"> *      demonstrates how to use the custom file system interface</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="preprocessor">#include &lt;test_util.h&gt;</span></div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * This example code uses pthread functions for portable locking, we ignore errors for simplicity.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">allocate_file_system_lock(pthread_rwlock_t *lockp)</div><div class="line">{</div><div class="line">    error_check(pthread_rwlock_init(lockp, NULL));</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">destroy_file_system_lock(pthread_rwlock_t *lockp)</div><div class="line">{</div><div class="line">    error_check(pthread_rwlock_destroy(lockp));</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">lock_file_system(pthread_rwlock_t *lockp)</div><div class="line">{</div><div class="line">    error_check(pthread_rwlock_wrlock(lockp));</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">unlock_file_system(pthread_rwlock_t *lockp)</div><div class="line">{</div><div class="line">    error_check(pthread_rwlock_unlock(lockp));</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Example file system implementation, using memory buffers to represent files.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div><div class="line">    <a name="_a0"></a><a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> iface;</div><div class="line"></div><div class="line">    <span class="comment">/*</span></div><div class="line"><span class="comment">     * WiredTiger performs schema and I/O operations in parallel, all file system and file handle</span></div><div class="line"><span class="comment">     * access must be thread-safe. This example uses a single, global file system lock for</span></div><div class="line"><span class="comment">     * simplicity; real applications might require finer granularity, for example, a single lock for</span></div><div class="line"><span class="comment">     * the file system handle list and per-handle locks serializing I/O.</span></div><div class="line"><span class="comment">     */</span></div><div class="line">    pthread_rwlock_t lock; <span class="comment">/* Lock */</span></div><div class="line"></div><div class="line">    <span class="keywordtype">int</span> opened_file_count;</div><div class="line">    <span class="keywordtype">int</span> opened_unique_file_count;</div><div class="line">    <span class="keywordtype">int</span> closed_file_count;</div><div class="line">    <span class="keywordtype">int</span> read_ops;</div><div class="line">    <span class="keywordtype">int</span> write_ops;</div><div class="line"></div><div class="line">    <span class="comment">/* Queue of file handles */</span></div><div class="line">    TAILQ_HEAD(demo_file_handle_qh, demo_file_handle) fileq;</div><div class="line"></div><div class="line">    <a name="_a1"></a><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *wtext; <span class="comment">/* Extension functions */</span></div><div class="line"></div><div class="line">} DEMO_FILE_SYSTEM;</div><div class="line"></div><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>demo_file_handle {</div><div class="line">    <a name="_a2"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> iface;</div><div class="line"></div><div class="line">    <span class="comment">/*</span></div><div class="line"><span class="comment">     * Add custom file handle fields after the interface.</span></div><div class="line"><span class="comment">     */</span></div><div class="line">    DEMO_FILE_SYSTEM *demo_fs; <span class="comment">/* Enclosing file system */</span></div><div class="line"></div><div class="line">    TAILQ_ENTRY(demo_file_handle) q; <span class="comment">/* Queue of handles */</span></div><div class="line">    uint32_t ref;                    <span class="comment">/* Reference count */</span></div><div class="line"></div><div class="line">    <span class="keywordtype">char</span> *buf;      <span class="comment">/* In-memory contents */</span></div><div class="line">    <span class="keywordtype">size_t</span> bufsize; <span class="comment">/* In-memory buffer size */</span></div><div class="line"></div><div class="line">    <span class="keywordtype">size_t</span> size; <span class="comment">/* Read/write data size */</span></div><div class="line">} DEMO_FILE_HANDLE;</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Extension initialization function.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="preprocessor">#ifdef _WIN32</span></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Explicitly export this function so it is visible when loading extensions.</span></div><div class="line"><span class="comment"> */</span></div><div class="line">__declspec(dllexport)</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line">  <span class="keywordtype">int</span> demo_file_system_create(<a name="_a3"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html">WT_CONNECTION</a> *, <a class="code" href="group__wt__ext.html#ga6fa5797cf581d18dc843e07333a497e4">WT_CONFIG_ARG</a> *);</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Forward function declarations for file system API implementation</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_fs_open(</div><div class="line">  <a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *, <a name="_a4"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <a class="code" href="group__wt__ext.html#gae93ff9285c3e44f34ffd98ed54ff69c8">WT_FS_OPEN_FILE_TYPE</a>, uint32_t, <a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> **);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_fs_directory_list(</div><div class="line">  <a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">char</span> ***, uint32_t *);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_fs_directory_list_free(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, <span class="keywordtype">char</span> **, uint32_t);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_fs_exist(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keywordtype">bool</span> *);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_fs_remove(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, uint32_t);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_fs_rename(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, uint32_t);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_fs_size(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *, wt_off_t *);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_fs_terminate(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *);</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Forward function declarations for file handle API implementation</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_file_close(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_file_lock(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, <span class="keywordtype">bool</span>);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_file_read(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, wt_off_t, <span class="keywordtype">size_t</span>, <span class="keywordtype">void</span> *);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_file_size(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, wt_off_t *);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_file_sync(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_file_truncate(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, wt_off_t);</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_file_write(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, wt_off_t, <span class="keywordtype">size_t</span>, <span class="keyword">const</span> <span class="keywordtype">void</span> *);</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Forward function declarations for internal functions</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> demo_handle_remove(<a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *, DEMO_FILE_HANDLE *);</div><div class="line"><span class="keyword">static</span> DEMO_FILE_HANDLE *demo_handle_search(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *, <span class="keyword">const</span> <span class="keywordtype">char</span> *);</div><div class="line"></div><div class="line"><span class="preprocessor">#define DEMO_FILE_SIZE_INCREMENT 32768</span></div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * string_match --</span></div><div class="line"><span class="comment"> *     Return if a string matches a byte string of len bytes.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">bool</span></div><div class="line">byte_string_match(<span class="keyword">const</span> <span class="keywordtype">char</span> *str, <span class="keyword">const</span> <span class="keywordtype">char</span> *bytes, <span class="keywordtype">size_t</span> len)</div><div class="line">{</div><div class="line">    <span class="keywordflow">return</span> (strncmp(str, bytes, len) == 0 &amp;&amp; (str)[(len)] == <span class="charliteral">&#39;\0&#39;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_file_system_create --</span></div><div class="line"><span class="comment"> *     Initialization point for demo file system</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keywordtype">int</span></div><div class="line">demo_file_system_create(<a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html">WT_CONNECTION</a> *conn, <a class="code" href="group__wt__ext.html#ga6fa5797cf581d18dc843e07333a497e4">WT_CONFIG_ARG</a> *config)</div><div class="line">{</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <a name="_a5"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html">WT_CONFIG_ITEM</a> k, v;</div><div class="line">    <a name="_a6"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___p_a_r_s_e_r.html">WT_CONFIG_PARSER</a> *config_parser;</div><div class="line">    <a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *wtext;</div><div class="line">    <a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line"></div><div class="line">    wtext = conn-&gt;<a name="a7"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#a99df5b3a17564eb5b3e4ec076590133d">get_extension_api</a>(conn);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> ((demo_fs = calloc(1, <span class="keyword">sizeof</span>(DEMO_FILE_SYSTEM))) == NULL) {</div><div class="line">        (void)wtext-&gt;<a name="a8"></a><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(</div><div class="line">          wtext, NULL, <span class="stringliteral">&quot;demo_file_system_create: %s&quot;</span>, wtext-&gt;<a name="a9"></a><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, ENOMEM));</div><div class="line">        <span class="keywordflow">return</span> (ENOMEM);</div><div class="line">    }</div><div class="line">    demo_fs-&gt;wtext = wtext;</div><div class="line">    file_system = (<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *)demo_fs;</div><div class="line"></div><div class="line">    <span class="comment">/*</span></div><div class="line"><span class="comment">     * Applications may have their own configuration information to pass to the underlying</span></div><div class="line"><span class="comment">     * filesystem implementation. See the main function for the setup of those configuration</span></div><div class="line"><span class="comment">     * strings; here we parse configuration information as passed in by main, through WiredTiger.</span></div><div class="line"><span class="comment">     */</span></div><div class="line">    <span class="keywordflow">if</span> ((ret = wtext-&gt;<a name="a10"></a><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#ae498b02cf83cdb644c2665c37917e785">config_parser_open_arg</a>(wtext, NULL, config, &amp;config_parser)) != 0) {</div><div class="line">        (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(wtext, NULL, <span class="stringliteral">&quot;WT_EXTENSION_API.config_parser_open: config: %s&quot;</span>,</div><div class="line">          wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, ret));</div><div class="line">        <span class="keywordflow">goto</span> err;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">/* Step through our configuration values. */</span></div><div class="line">    printf(<span class="stringliteral">&quot;Custom file system configuration\n&quot;</span>);</div><div class="line">    <span class="keywordflow">while</span> ((ret = config_parser-&gt;<a name="a11"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___p_a_r_s_e_r.html#a2033bdd009b0a75ade51305f00a7dc8f">next</a>(config_parser, &amp;k, &amp;v)) == 0) {</div><div class="line">        <span class="keywordflow">if</span> (byte_string_match(<span class="stringliteral">&quot;config_string&quot;</span>, k.<a name="a12"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#aa0ce7d30a32600e16824966c638ee45f">str</a>, k.<a name="a13"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a>)) {</div><div class="line">            printf(</div><div class="line">              <span class="stringliteral">&quot;\t&quot;</span></div><div class="line">              <span class="stringliteral">&quot;key %.*s=\&quot;%.*s\&quot;\n&quot;</span>,</div><div class="line">              (<span class="keywordtype">int</span>)k.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a>, k.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#aa0ce7d30a32600e16824966c638ee45f">str</a>, (<span class="keywordtype">int</span>)v.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a>, v.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#aa0ce7d30a32600e16824966c638ee45f">str</a>);</div><div class="line">            <span class="keywordflow">continue</span>;</div><div class="line">        }</div><div class="line">        <span class="keywordflow">if</span> (byte_string_match(<span class="stringliteral">&quot;config_value&quot;</span>, k.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#aa0ce7d30a32600e16824966c638ee45f">str</a>, k.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a>)) {</div><div class="line">            printf(</div><div class="line">              <span class="stringliteral">&quot;\t&quot;</span></div><div class="line">              <span class="stringliteral">&quot;key %.*s=%&quot;</span> PRId64 <span class="stringliteral">&quot;\n&quot;</span>,</div><div class="line">              (<span class="keywordtype">int</span>)k.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a>, k.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#aa0ce7d30a32600e16824966c638ee45f">str</a>, v.<a name="a14"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#a4aefab7843f434e5a5cc18203e9fec5f">val</a>);</div><div class="line">            <span class="keywordflow">continue</span>;</div><div class="line">        }</div><div class="line">        ret = EINVAL;</div><div class="line">        (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(wtext, NULL,</div><div class="line">          <span class="stringliteral">&quot;WT_CONFIG_PARSER.next: unexpected configuration &quot;</span></div><div class="line">          <span class="stringliteral">&quot;information: %.*s=%.*s: %s&quot;</span>,</div><div class="line">          (<span class="keywordtype">int</span>)k.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a>, k.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#aa0ce7d30a32600e16824966c638ee45f">str</a>, (<span class="keywordtype">int</span>)v.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#adff0f6e5a3f781f0228015e8336f1a14">len</a>, v.<a class="code" href="struct_w_t___c_o_n_f_i_g___i_t_e_m.html#aa0ce7d30a32600e16824966c638ee45f">str</a>, wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, ret));</div><div class="line">        <span class="keywordflow">goto</span> err;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">/* Check for expected parser termination and close the parser. */</span></div><div class="line">    <span class="keywordflow">if</span> (ret != <a name="a15"></a><a class="code" href="group__wt.html#ga3c9e1b494d95cf34404ab7a974af6bf8">WT_NOTFOUND</a>) {</div><div class="line">        (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(</div><div class="line">          wtext, NULL, <span class="stringliteral">&quot;WT_CONFIG_PARSER.next: config: %s&quot;</span>, wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, ret));</div><div class="line">        <span class="keywordflow">goto</span> err;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> ((ret = config_parser-&gt;<a name="a16"></a><a class="code" href="struct_w_t___c_o_n_f_i_g___p_a_r_s_e_r.html#a44eea5e27a4da10006ab444ee7cf00f3">close</a>(config_parser)) != 0) {</div><div class="line">        (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(</div><div class="line">          wtext, NULL, <span class="stringliteral">&quot;WT_CONFIG_PARSER.close: config: %s&quot;</span>, wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, ret));</div><div class="line">        <span class="keywordflow">goto</span> err;</div><div class="line">    }</div><div class="line"></div><div class="line">    allocate_file_system_lock(&amp;demo_fs-&gt;lock);</div><div class="line"></div><div class="line">    <span class="comment">/* Initialize the in-memory jump table. */</span></div><div class="line">    file_system-&gt;<a name="a17"></a><a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html#a461137686ca8dc659b314b29f7c98299">fs_directory_list</a> = demo_fs_directory_list;</div><div class="line">    file_system-&gt;<a name="a18"></a><a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html#a96913fda6ff35e7543fabb02b76d71eb">fs_directory_list_free</a> = demo_fs_directory_list_free;</div><div class="line">    file_system-&gt;<a name="a19"></a><a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html#a04768a78e64d45bb61b170e6c2dcb3a2">fs_exist</a> = demo_fs_exist;</div><div class="line">    file_system-&gt;<a name="a20"></a><a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html#a86d9e245b3e20bb3faae46767c11df99">fs_open_file</a> = demo_fs_open;</div><div class="line">    file_system-&gt;<a name="a21"></a><a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html#a1c57a707ff18f2766c3132ddcb405b26">fs_remove</a> = demo_fs_remove;</div><div class="line">    file_system-&gt;<a name="a22"></a><a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html#a39b082e5c6649954d3ebc2b158fe9ab8">fs_rename</a> = demo_fs_rename;</div><div class="line">    file_system-&gt;<a name="a23"></a><a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html#a2e97ea38029d156f3ead1cea90652c47">fs_size</a> = demo_fs_size;</div><div class="line">    file_system-&gt;<a name="a24"></a><a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html#aff641cfd86a92a170d1bb17eb33c6cf3">terminate</a> = demo_fs_terminate;</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> ((ret = conn-&gt;<a name="a25"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#a7c9d5b40133a6ba1cbc4a6b1d8e1e86b">set_file_system</a>(conn, file_system, NULL)) != 0) {</div><div class="line">        (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(</div><div class="line">          wtext, NULL, <span class="stringliteral">&quot;WT_CONNECTION.set_file_system: %s&quot;</span>, wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, ret));</div><div class="line">        <span class="keywordflow">goto</span> err;</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> (0);</div><div class="line"></div><div class="line">err:</div><div class="line">    free(demo_fs);</div><div class="line">    <span class="comment">/* An error installing the file system is fatal. */</span></div><div class="line">    exit(1);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_fs_open --</span></div><div class="line"><span class="comment"> *     fopen for our demo file system</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_fs_open(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keyword">const</span> <span class="keywordtype">char</span> *name,</div><div class="line">  <a class="code" href="group__wt__ext.html#gae93ff9285c3e44f34ffd98ed54ff69c8">WT_FS_OPEN_FILE_TYPE</a> file_type, uint32_t flags, <a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> **file_handlep)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *wtext;</div><div class="line">    <a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *file_handle;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line"></div><div class="line">    (void)file_type; <span class="comment">/* Unused */</span></div><div class="line">    (void)flags;     <span class="comment">/* Unused */</span></div><div class="line"></div><div class="line">    *file_handlep = NULL;</div><div class="line"></div><div class="line">    demo_fs = (DEMO_FILE_SYSTEM *)file_system;</div><div class="line">    demo_fh = NULL;</div><div class="line">    wtext = demo_fs-&gt;wtext;</div><div class="line"></div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    ++demo_fs-&gt;opened_file_count;</div><div class="line"></div><div class="line">    <span class="comment">/*</span></div><div class="line"><span class="comment">     * First search the file queue, if we find it, assert there&#39;s only a single reference, we only</span></div><div class="line"><span class="comment">     * support a single handle on any file.</span></div><div class="line"><span class="comment">     */</span></div><div class="line">    demo_fh = demo_handle_search(file_system, name);</div><div class="line">    <span class="keywordflow">if</span> (demo_fh != NULL) {</div><div class="line">        <span class="keywordflow">if</span> (demo_fh-&gt;ref != 0) {</div><div class="line">            (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(wtext, session, <span class="stringliteral">&quot;demo_fs_open: %s: file already open&quot;</span>, name);</div><div class="line">            ret = EBUSY;</div><div class="line">            <span class="keywordflow">goto</span> err;</div><div class="line">        }</div><div class="line"></div><div class="line">        demo_fh-&gt;ref = 1;</div><div class="line"></div><div class="line">        *file_handlep = (<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *)demo_fh;</div><div class="line"></div><div class="line">        unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">        <span class="keywordflow">return</span> (0);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">/* The file hasn&#39;t been opened before, create a new one. */</span></div><div class="line">    <span class="keywordflow">if</span> ((demo_fh = calloc(1, <span class="keyword">sizeof</span>(DEMO_FILE_HANDLE))) == NULL) {</div><div class="line">        ret = ENOMEM;</div><div class="line">        <span class="keywordflow">goto</span> err;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">/* Initialize private information. */</span></div><div class="line">    demo_fh-&gt;demo_fs = demo_fs;</div><div class="line">    demo_fh-&gt;ref = 1;</div><div class="line">    <span class="keywordflow">if</span> ((demo_fh-&gt;buf = calloc(1, DEMO_FILE_SIZE_INCREMENT)) == NULL) {</div><div class="line">        ret = ENOMEM;</div><div class="line">        <span class="keywordflow">goto</span> err;</div><div class="line">    }</div><div class="line">    demo_fh-&gt;bufsize = DEMO_FILE_SIZE_INCREMENT;</div><div class="line">    demo_fh-&gt;size = 0;</div><div class="line"></div><div class="line">    <span class="comment">/* Initialize public information. */</span></div><div class="line">    file_handle = (<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *)demo_fh;</div><div class="line">    <span class="keywordflow">if</span> ((file_handle-&gt;<a name="a26"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#ad2a2c8838d62efa219404eeb006bddd5">name</a> = strdup(name)) == NULL) {</div><div class="line">        ret = ENOMEM;</div><div class="line">        <span class="keywordflow">goto</span> err;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">/*</span></div><div class="line"><span class="comment">     * Setup the function call table for our custom file system. Set the function pointer to NULL</span></div><div class="line"><span class="comment">     * where our implementation doesn&#39;t support the functionality.</span></div><div class="line"><span class="comment">     */</span></div><div class="line">    file_handle-&gt;<a name="a27"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#aa4376c70336f8a0bbd8bf1c91749aeed">close</a> = demo_file_close;</div><div class="line">    file_handle-&gt;<a name="a28"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#a5b68b388279c64add7b0ef893b1d2e00">fh_advise</a> = NULL;</div><div class="line">    file_handle-&gt;<a name="a29"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#ab4b685446f0ce09b7270dd32bb771ce7">fh_extend</a> = NULL;</div><div class="line">    file_handle-&gt;<a name="a30"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#a2479acb713a211b2d7cc84aaada4b29b">fh_extend_nolock</a> = NULL;</div><div class="line">    file_handle-&gt;<a name="a31"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#a5db2aa421c5297d9119b9517e1117afb">fh_lock</a> = demo_file_lock;</div><div class="line">    file_handle-&gt;<a name="a32"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#afaf6ca726275db6772700eaca399c89f">fh_map</a> = NULL;</div><div class="line">    file_handle-&gt;<a name="a33"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#a02b0e75636d323ce5bd42fdf7e83615e">fh_map_discard</a> = NULL;</div><div class="line">    file_handle-&gt;<a name="a34"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#a350e1db2cd51c8c2479b03beae9af90f">fh_map_preload</a> = NULL;</div><div class="line">    file_handle-&gt;<a name="a35"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#a9e8786a0eedb67d92a9e8e5239faef6b">fh_unmap</a> = NULL;</div><div class="line">    file_handle-&gt;<a name="a36"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#ad41718cb1f7a59cfb21a68785aa09897">fh_read</a> = demo_file_read;</div><div class="line">    file_handle-&gt;<a name="a37"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#a1e0b90f0a4fcf943e81b22b94069738b">fh_size</a> = demo_file_size;</div><div class="line">    file_handle-&gt;<a name="a38"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#ad4f3371981540000e182ed0cb75eefad">fh_sync</a> = demo_file_sync;</div><div class="line">    file_handle-&gt;<a name="a39"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#ad4203cea23fd8f62765564ba9a24fe6c">fh_sync_nowait</a> = NULL;</div><div class="line">    file_handle-&gt;<a name="a40"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#aadcd969865c263c9e9b00d39308e296c">fh_truncate</a> = demo_file_truncate;</div><div class="line">    file_handle-&gt;<a name="a41"></a><a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html#ab69c295b076627307a6528793d7a9b43">fh_write</a> = demo_file_write;</div><div class="line"></div><div class="line">    TAILQ_INSERT_HEAD(&amp;demo_fs-&gt;fileq, demo_fh, q);</div><div class="line">    ++demo_fs-&gt;opened_unique_file_count;</div><div class="line"></div><div class="line">    *file_handlep = file_handle;</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (0) {</div><div class="line">err:</div><div class="line">        free(demo_fh-&gt;buf);</div><div class="line">        free(demo_fh);</div><div class="line">    }</div><div class="line"></div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_fs_directory_list --</span></div><div class="line"><span class="comment"> *     Return a list of files in a given sub-directory.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_fs_directory_list(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keyword">const</span> <span class="keywordtype">char</span> *directory,</div><div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span> *prefix, <span class="keywordtype">char</span> ***dirlistp, uint32_t *countp)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <span class="keywordtype">size_t</span> len, prefix_len;</div><div class="line">    uint32_t allocated, count;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line">    <span class="keywordtype">char</span> *name, **entries;</div><div class="line">    <span class="keywordtype">void</span> *p;</div><div class="line"></div><div class="line">    (void)session; <span class="comment">/* Unused */</span></div><div class="line"></div><div class="line">    demo_fs = (DEMO_FILE_SYSTEM *)file_system;</div><div class="line"></div><div class="line">    *dirlistp = NULL;</div><div class="line">    *countp = 0;</div><div class="line"></div><div class="line">    entries = NULL;</div><div class="line">    allocated = count = 0;</div><div class="line">    len = strlen(directory);</div><div class="line">    prefix_len = prefix == NULL ? 0 : strlen(prefix);</div><div class="line"></div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    TAILQ_FOREACH (demo_fh, &amp;demo_fs-&gt;fileq, q) {</div><div class="line">        name = demo_fh-&gt;iface.name;</div><div class="line">        <span class="keywordflow">if</span> (strncmp(name, directory, len) != 0 ||</div><div class="line">          (prefix != NULL &amp;&amp; strncmp(name, prefix, prefix_len) != 0))</div><div class="line">            <span class="keywordflow">continue</span>;</div><div class="line"></div><div class="line">        <span class="comment">/*</span></div><div class="line"><span class="comment">         * Increase the list size in groups of 10, it doesn&#39;t matter if the list is a bit longer</span></div><div class="line"><span class="comment">         * than necessary.</span></div><div class="line"><span class="comment">         */</span></div><div class="line">        <span class="keywordflow">if</span> (count &gt;= allocated) {</div><div class="line">            p = realloc(entries, (allocated + 10) * <span class="keyword">sizeof</span>(*entries));</div><div class="line">            <span class="keywordflow">if</span> (p == NULL) {</div><div class="line">                ret = ENOMEM;</div><div class="line">                <span class="keywordflow">goto</span> err;</div><div class="line">            }</div><div class="line"></div><div class="line">            entries = p;</div><div class="line">            memset(entries + allocated * <span class="keyword">sizeof</span>(*entries), 0, 10 * <span class="keyword">sizeof</span>(*entries));</div><div class="line">            allocated += 10;</div><div class="line">        }</div><div class="line">        entries[count++] = strdup(name);</div><div class="line">    }</div><div class="line"></div><div class="line">    *dirlistp = entries;</div><div class="line">    *countp = count;</div><div class="line"></div><div class="line">err:</div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">if</span> (ret == 0)</div><div class="line">        <span class="keywordflow">return</span> (0);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (entries != NULL) {</div><div class="line">        <span class="keywordflow">while</span> (count &gt; 0)</div><div class="line">            free(entries[--count]);</div><div class="line">        free(entries);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_fs_directory_list_free --</span></div><div class="line"><span class="comment"> *     Free memory allocated by demo_fs_directory_list.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_fs_directory_list_free(</div><div class="line">  <a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keywordtype">char</span> **dirlist, uint32_t count)</div><div class="line">{</div><div class="line">    (void)file_system;</div><div class="line">    (void)session;</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (dirlist != NULL) {</div><div class="line">        <span class="keywordflow">while</span> (count &gt; 0)</div><div class="line">            free(dirlist[--count]);</div><div class="line">        free(dirlist);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_fs_exist --</span></div><div class="line"><span class="comment"> *     Return if the file exists.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_fs_exist(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">bool</span> *existp)</div><div class="line">{</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line"></div><div class="line">    (void)session; <span class="comment">/* Unused */</span></div><div class="line"></div><div class="line">    demo_fs = (DEMO_FILE_SYSTEM *)file_system;</div><div class="line"></div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    *existp = demo_handle_search(file_system, name) != NULL;</div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_fs_remove --</span></div><div class="line"><span class="comment"> *     POSIX remove.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_fs_remove(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, uint32_t flags)</div><div class="line">{</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line"></div><div class="line">    (void)session; <span class="comment">/* Unused */</span></div><div class="line">    (void)flags;   <span class="comment">/* Unused */</span></div><div class="line"></div><div class="line">    demo_fs = (DEMO_FILE_SYSTEM *)file_system;</div><div class="line"></div><div class="line">    ret = ENOENT;</div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">if</span> ((demo_fh = demo_handle_search(file_system, name)) != NULL)</div><div class="line">        ret = demo_handle_remove(session, demo_fh);</div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_fs_rename --</span></div><div class="line"><span class="comment"> *     POSIX rename.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_fs_rename(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keyword">const</span> <span class="keywordtype">char</span> *from, <span class="keyword">const</span> <span class="keywordtype">char</span> *to,</div><div class="line">  uint32_t flags)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <span class="keywordtype">char</span> *copy;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line"></div><div class="line">    (void)session; <span class="comment">/* Unused */</span></div><div class="line">    (void)flags;   <span class="comment">/* Unused */</span></div><div class="line"></div><div class="line">    demo_fs = (DEMO_FILE_SYSTEM *)file_system;</div><div class="line"></div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">if</span> ((demo_fh = demo_handle_search(file_system, from)) == NULL)</div><div class="line">        ret = ENOENT;</div><div class="line">    <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((copy = strdup(to)) == NULL)</div><div class="line">        ret = ENOMEM;</div><div class="line">    <span class="keywordflow">else</span> {</div><div class="line">        free(demo_fh-&gt;iface.name);</div><div class="line">        demo_fh-&gt;iface.name = copy;</div><div class="line">    }</div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_fs_size --</span></div><div class="line"><span class="comment"> *     Get the size of a file in bytes, by file name.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_fs_size(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keyword">const</span> <span class="keywordtype">char</span> *name, wt_off_t *sizep)</div><div class="line">{</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line"></div><div class="line">    demo_fs = (DEMO_FILE_SYSTEM *)file_system;</div><div class="line"></div><div class="line">    ret = ENOENT;</div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">if</span> ((demo_fh = demo_handle_search(file_system, name)) != NULL)</div><div class="line">        ret = demo_file_size((<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *)demo_fh, session, sizep);</div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_fs_terminate --</span></div><div class="line"><span class="comment"> *     Discard any resources on termination</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_fs_terminate(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh, *demo_fh_tmp;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <span class="keywordtype">int</span> ret = 0, tret;</div><div class="line"></div><div class="line">    demo_fs = (DEMO_FILE_SYSTEM *)file_system;</div><div class="line"></div><div class="line">    TAILQ_FOREACH_SAFE(demo_fh, &amp;demo_fs-&gt;fileq, q, demo_fh_tmp)</div><div class="line">    <span class="keywordflow">if</span> ((tret = demo_handle_remove(session, demo_fh)) != 0 &amp;&amp; ret == 0)</div><div class="line">        ret = tret;</div><div class="line"></div><div class="line">    printf(<span class="stringliteral">&quot;Custom file system\n&quot;</span>);</div><div class="line">    printf(<span class="stringliteral">&quot;\t%d unique file opens\n&quot;</span>, demo_fs-&gt;opened_unique_file_count);</div><div class="line">    printf(<span class="stringliteral">&quot;\t%d files opened\n&quot;</span>, demo_fs-&gt;opened_file_count);</div><div class="line">    printf(<span class="stringliteral">&quot;\t%d files closed\n&quot;</span>, demo_fs-&gt;closed_file_count);</div><div class="line">    printf(<span class="stringliteral">&quot;\t%d reads, %d writes\n&quot;</span>, demo_fs-&gt;read_ops, demo_fs-&gt;write_ops);</div><div class="line"></div><div class="line">    destroy_file_system_lock(&amp;demo_fs-&gt;lock);</div><div class="line">    free(demo_fs);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_file_close --</span></div><div class="line"><span class="comment"> *     ANSI C close.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_file_close(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *file_handle, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line"></div><div class="line">    (void)session; <span class="comment">/* Unused */</span></div><div class="line"></div><div class="line">    demo_fh = (DEMO_FILE_HANDLE *)file_handle;</div><div class="line">    demo_fs = demo_fh-&gt;demo_fs;</div><div class="line"></div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">if</span> (--demo_fh-&gt;ref == 0)</div><div class="line">        ++demo_fs-&gt;closed_file_count;</div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_file_lock --</span></div><div class="line"><span class="comment"> *     Lock/unlock a file.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_file_lock(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *file_handle, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keywordtype">bool</span> lock)</div><div class="line">{</div><div class="line">    <span class="comment">/* Locks are always granted. */</span></div><div class="line">    (void)file_handle; <span class="comment">/* Unused */</span></div><div class="line">    (void)session;     <span class="comment">/* Unused */</span></div><div class="line">    (void)lock;        <span class="comment">/* Unused */</span></div><div class="line">    <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_file_read --</span></div><div class="line"><span class="comment"> *     POSIX pread.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_file_read(</div><div class="line">  <a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *file_handle, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, wt_off_t offset, <span class="keywordtype">size_t</span> len, <span class="keywordtype">void</span> *buf)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *wtext;</div><div class="line">    <span class="keywordtype">size_t</span> off;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line"></div><div class="line">    demo_fh = (DEMO_FILE_HANDLE *)file_handle;</div><div class="line">    demo_fs = demo_fh-&gt;demo_fs;</div><div class="line">    wtext = demo_fs-&gt;wtext;</div><div class="line">    off = (size_t)offset;</div><div class="line"></div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    ++demo_fs-&gt;read_ops;</div><div class="line">    <span class="keywordflow">if</span> (off &lt; demo_fh-&gt;size) {</div><div class="line">        <span class="keywordflow">if</span> (len &gt; demo_fh-&gt;size - off)</div><div class="line">            len = demo_fh-&gt;size - off;</div><div class="line">        memcpy(buf, (uint8_t *)demo_fh-&gt;buf + off, len);</div><div class="line">    } <span class="keywordflow">else</span></div><div class="line">        ret = EIO; <span class="comment">/* EOF */</span></div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">if</span> (ret == 0)</div><div class="line">        <span class="keywordflow">return</span> (0);</div><div class="line"></div><div class="line">    (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(wtext, session,</div><div class="line">      <span class="stringliteral">&quot;%s: handle-read: failed to read %zu bytes at offset %zu: %s&quot;</span>, demo_fh-&gt;iface.name, len, off,</div><div class="line">      wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, ret));</div><div class="line">    <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_file_size --</span></div><div class="line"><span class="comment"> *     Get the size of a file in bytes, by file handle.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_file_size(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *file_handle, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, wt_off_t *sizep)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line"></div><div class="line">    (void)session; <span class="comment">/* Unused */</span></div><div class="line"></div><div class="line">    demo_fh = (DEMO_FILE_HANDLE *)file_handle;</div><div class="line">    demo_fs = demo_fh-&gt;demo_fs;</div><div class="line"></div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    *sizep = (wt_off_t)demo_fh-&gt;size;</div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_file_sync --</span></div><div class="line"><span class="comment"> *     Ensure the content of the file is stable. This is a no-op in our memory backed file system.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_file_sync(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *file_handle, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session)</div><div class="line">{</div><div class="line">    (void)file_handle; <span class="comment">/* Unused */</span></div><div class="line">    (void)session;     <span class="comment">/* Unused */</span></div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_buffer_resize --</span></div><div class="line"><span class="comment"> *     Resize the write buffer.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_buffer_resize(<a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, DEMO_FILE_HANDLE *demo_fh, wt_off_t offset)</div><div class="line">{</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *wtext;</div><div class="line">    <span class="keywordtype">size_t</span> off;</div><div class="line">    <span class="keywordtype">void</span> *p;</div><div class="line"></div><div class="line">    demo_fs = demo_fh-&gt;demo_fs;</div><div class="line">    wtext = demo_fs-&gt;wtext;</div><div class="line">    off = (size_t)offset;</div><div class="line"></div><div class="line">    <span class="comment">/* Grow the buffer as necessary and clear any new space in the file. */</span></div><div class="line">    <span class="keywordflow">if</span> (demo_fh-&gt;bufsize &gt;= off)</div><div class="line">        <span class="keywordflow">return</span> (0);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> ((p = realloc(demo_fh-&gt;buf, off)) == NULL) {</div><div class="line">        (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(wtext, session, <span class="stringliteral">&quot;%s: failed to resize buffer&quot;</span>, demo_fh-&gt;iface.name,</div><div class="line">          wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, ENOMEM));</div><div class="line">        <span class="keywordflow">return</span> (ENOMEM);</div><div class="line">    }</div><div class="line">    memset((uint8_t *)p + demo_fh-&gt;bufsize, 0, off - demo_fh-&gt;bufsize);</div><div class="line">    demo_fh-&gt;buf = p;</div><div class="line">    demo_fh-&gt;bufsize = off;</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_file_truncate --</span></div><div class="line"><span class="comment"> *     POSIX ftruncate.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_file_truncate(<a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *file_handle, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, wt_off_t offset)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line"></div><div class="line">    demo_fh = (DEMO_FILE_HANDLE *)file_handle;</div><div class="line">    demo_fs = demo_fh-&gt;demo_fs;</div><div class="line"></div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">if</span> ((ret = demo_buffer_resize(session, demo_fh, offset)) == 0)</div><div class="line">        demo_fh-&gt;size = (size_t)offset;</div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_file_write --</span></div><div class="line"><span class="comment"> *     POSIX pwrite.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_file_write(</div><div class="line">  <a class="code" href="struct_w_t___f_i_l_e___h_a_n_d_l_e.html">WT_FILE_HANDLE</a> *file_handle, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, wt_off_t offset, <span class="keywordtype">size_t</span> len, <span class="keyword">const</span> <span class="keywordtype">void</span> *buf)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *wtext;</div><div class="line">    <span class="keywordtype">size_t</span> off;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line"></div><div class="line">    demo_fh = (DEMO_FILE_HANDLE *)file_handle;</div><div class="line">    demo_fs = demo_fh-&gt;demo_fs;</div><div class="line">    wtext = demo_fs-&gt;wtext;</div><div class="line">    off = (size_t)offset;</div><div class="line"></div><div class="line">    lock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    ++demo_fs-&gt;write_ops;</div><div class="line">    <span class="keywordflow">if</span> ((ret = demo_buffer_resize(</div><div class="line">           session, demo_fh, offset + (wt_off_t)(len + DEMO_FILE_SIZE_INCREMENT))) == 0) {</div><div class="line">        memcpy((uint8_t *)demo_fh-&gt;buf + off, buf, len);</div><div class="line">        <span class="keywordflow">if</span> (off + len &gt; demo_fh-&gt;size)</div><div class="line">            demo_fh-&gt;size = off + len;</div><div class="line">    }</div><div class="line">    unlock_file_system(&amp;demo_fs-&gt;lock);</div><div class="line">    <span class="keywordflow">if</span> (ret == 0)</div><div class="line">        <span class="keywordflow">return</span> (0);</div><div class="line"></div><div class="line">    (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(wtext, session,</div><div class="line">      <span class="stringliteral">&quot;%s: handle-write: failed to write %zu bytes at offset %zu: %s&quot;</span>, demo_fh-&gt;iface.name, len,</div><div class="line">      off, wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, ret));</div><div class="line">    <span class="keywordflow">return</span> (ret);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_handle_remove --</span></div><div class="line"><span class="comment"> *     Destroy an in-memory file handle. Should only happen on remove or shutdown.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">demo_handle_remove(<a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, DEMO_FILE_HANDLE *demo_fh)</div><div class="line">{</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line">    <a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *wtext;</div><div class="line"></div><div class="line">    demo_fs = demo_fh-&gt;demo_fs;</div><div class="line">    wtext = demo_fs-&gt;wtext;</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (demo_fh-&gt;ref != 0) {</div><div class="line">        (void)wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(wtext, session, <span class="stringliteral">&quot;demo_handle_remove: %s: file is currently open&quot;</span>,</div><div class="line">          demo_fh-&gt;iface.name, wtext-&gt;<a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wtext, NULL, EBUSY));</div><div class="line">        <span class="keywordflow">return</span> (EBUSY);</div><div class="line">    }</div><div class="line"></div><div class="line">    TAILQ_REMOVE(&amp;demo_fs-&gt;fileq, demo_fh, q);</div><div class="line"></div><div class="line">    <span class="comment">/* Clean up private information. */</span></div><div class="line">    free(demo_fh-&gt;buf);</div><div class="line"></div><div class="line">    <span class="comment">/* Clean up public information. */</span></div><div class="line">    free(demo_fh-&gt;iface.name);</div><div class="line"></div><div class="line">    free(demo_fh);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * demo_handle_search --</span></div><div class="line"><span class="comment"> *     Return a matching handle, if one exists.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> DEMO_FILE_HANDLE *</div><div class="line">demo_handle_search(<a class="code" href="struct_w_t___f_i_l_e___s_y_s_t_e_m.html">WT_FILE_SYSTEM</a> *file_system, <span class="keyword">const</span> <span class="keywordtype">char</span> *name)</div><div class="line">{</div><div class="line">    DEMO_FILE_HANDLE *demo_fh;</div><div class="line">    DEMO_FILE_SYSTEM *demo_fs;</div><div class="line"></div><div class="line">    demo_fs = (DEMO_FILE_SYSTEM *)file_system;</div><div class="line"></div><div class="line">    TAILQ_FOREACH (demo_fh, &amp;demo_fs-&gt;fileq, q)</div><div class="line">        <span class="keywordflow">if</span> (strcmp(demo_fh-&gt;iface.name, name) == 0)</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">    <span class="keywordflow">return</span> (demo_fh);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *home;</div><div class="line"></div><div class="line"><span class="keywordtype">int</span></div><div class="line">main(<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">    <a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html">WT_CONNECTION</a> *conn;</div><div class="line">    <a name="_a42"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html">WT_CURSOR</a> *cursor;</div><div class="line">    <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session;</div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">char</span> *key, *open_config, *uri;</div><div class="line">    <span class="keywordtype">int</span> i;</div><div class="line">    <span class="keywordtype">int</span> ret = 0;</div><div class="line">    <span class="keywordtype">char</span> kbuf[64];</div><div class="line"></div><div class="line">    <span class="comment">/*</span></div><div class="line"><span class="comment">     * Create a clean test directory for this run of the test program if the environment variable</span></div><div class="line"><span class="comment">     * isn&#39;t already set (as is done by make check).</span></div><div class="line"><span class="comment">     */</span></div><div class="line">    <span class="keywordflow">if</span> (getenv(<span class="stringliteral">&quot;WIREDTIGER_HOME&quot;</span>) == NULL) {</div><div class="line">        home = <span class="stringliteral">&quot;WT_HOME&quot;</span>;</div><div class="line">        ret = system(<span class="stringliteral">&quot;rm -rf WT_HOME &amp;&amp; mkdir WT_HOME&quot;</span>);</div><div class="line">    } <span class="keywordflow">else</span></div><div class="line">        home = NULL;</div><div class="line"></div><div class="line">    <span class="comment">/*</span></div><div class="line"><span class="comment">     * Setup a configuration string that will load our custom file system. Use the special local</span></div><div class="line"><span class="comment">     * extension to indicate that the entry point is in the same executable. Also enable early load</span></div><div class="line"><span class="comment">     * for this extension, since WiredTiger needs to be able to find it before doing any file</span></div><div class="line"><span class="comment">     * operations. Finally, pass in two pieces of configuration information to our initialization</span></div><div class="line"><span class="comment">     * function as the &quot;config&quot; value.</span></div><div class="line"><span class="comment">     */</span></div><div class="line">    open_config =</div><div class="line">      <span class="stringliteral">&quot;create,log=(enabled=true),extensions=(local={&quot;</span></div><div class="line">      <span class="stringliteral">&quot;entry=demo_file_system_create,early_load=true,&quot;</span></div><div class="line">      <span class="stringliteral">&quot;config={config_string=\&quot;demo-file-system\&quot;,config_value=37}&quot;</span></div><div class="line">      <span class="stringliteral">&quot;})&quot;</span>;</div><div class="line">    <span class="comment">/* Open a connection to the database, creating it if necessary. */</span></div><div class="line">    <span class="keywordflow">if</span> ((ret = <a name="a43"></a><a class="code" href="group__wt.html#gacbe8d118f978f5bfc8ccb4c77c9e8813">wiredtiger_open</a>(home, NULL, open_config, &amp;conn)) != 0) {</div><div class="line">        fprintf(stderr, <span class="stringliteral">&quot;Error connecting to %s: %s\n&quot;</span>, home == NULL ? <span class="stringliteral">&quot;.&quot;</span> : home,</div><div class="line">          <a name="a44"></a><a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">        <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> ((ret = conn-&gt;<a name="a45"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#adad5965cd4a60f65b5ac01f7ca6d1fc0">open_session</a>(conn, NULL, NULL, &amp;session)) != 0) {</div><div class="line">        fprintf(stderr, <span class="stringliteral">&quot;WT_CONNECTION.open_session: %s\n&quot;</span>, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">        <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">    }</div><div class="line">    uri = <span class="stringliteral">&quot;table:fs&quot;</span>;</div><div class="line">    <span class="keywordflow">if</span> ((ret = session-&gt;<a name="a46"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb">create</a>(session, uri, <span class="stringliteral">&quot;key_format=S,value_format=S&quot;</span>)) != 0) {</div><div class="line">        fprintf(stderr, <span class="stringliteral">&quot;WT_SESSION.create: %s: %s\n&quot;</span>, uri, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">        <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> ((ret = session-&gt;<a name="a47"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session, uri, NULL, NULL, &amp;cursor)) != 0) {</div><div class="line">        fprintf(stderr, <span class="stringliteral">&quot;WT_SESSION.open_cursor: %s: %s\n&quot;</span>, uri, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">        <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">for</span> (i = 0; i &lt; 1000; ++i) {</div><div class="line">        (void)snprintf(kbuf, <span class="keyword">sizeof</span>(kbuf), <span class="stringliteral">&quot;%010d KEY -----&quot;</span>, i);</div><div class="line">        cursor-&gt;<a name="a48"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#ad1088d719df40babc1f57d086691ebdc">set_key</a>(cursor, kbuf);</div><div class="line">        cursor-&gt;<a name="a49"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a27f7cbd0cd3e561f6a145704813ad64c">set_value</a>(cursor, <span class="stringliteral">&quot;--- VALUE ---&quot;</span>);</div><div class="line">        <span class="keywordflow">if</span> ((ret = cursor-&gt;<a name="a50"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#aac90d9fbcc031570f924db55f8a1cee3">insert</a>(cursor)) != 0) {</div><div class="line">            fprintf(stderr, <span class="stringliteral">&quot;WT_CURSOR.insert: %s: %s\n&quot;</span>, kbuf, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">            <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">        }</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> ((ret = cursor-&gt;<a name="a51"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#aeea071f192cab12245a50fbe71c3460b">close</a>(cursor)) != 0) {</div><div class="line">        fprintf(stderr, <span class="stringliteral">&quot;WT_CURSOR.close: %s\n&quot;</span>, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">        <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> ((ret = session-&gt;<a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session, uri, NULL, NULL, &amp;cursor)) != 0) {</div><div class="line">        fprintf(stderr, <span class="stringliteral">&quot;WT_SESSION.open_cursor: %s: %s\n&quot;</span>, uri, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">        <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">for</span> (i = 0; i &lt; 1000; ++i) {</div><div class="line">        <span class="keywordflow">if</span> ((ret = cursor-&gt;<a name="a52"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a0503f16bd8f3d05aa3552f229b3a8e1b">next</a>(cursor)) != 0) {</div><div class="line">            fprintf(stderr, <span class="stringliteral">&quot;WT_CURSOR.insert: %s: %s\n&quot;</span>, kbuf, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">            <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">        }</div><div class="line">        (void)snprintf(kbuf, <span class="keyword">sizeof</span>(kbuf), <span class="stringliteral">&quot;%010d KEY -----&quot;</span>, i);</div><div class="line">        <span class="keywordflow">if</span> ((ret = cursor-&gt;<a name="a53"></a><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af19f6f9d9c7fc248ab38879032620b2f">get_key</a>(cursor, &amp;key)) != 0) {</div><div class="line">            fprintf(stderr, <span class="stringliteral">&quot;WT_CURSOR.get_key: %s\n&quot;</span>, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">            <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">        }</div><div class="line">        <span class="keywordflow">if</span> (strcmp(kbuf, key) != 0) {</div><div class="line">            fprintf(stderr, <span class="stringliteral">&quot;Key mismatch: %s, %s\n&quot;</span>, kbuf, key);</div><div class="line">            <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">        }</div><div class="line">    }</div><div class="line">    <span class="keywordflow">if</span> ((ret = cursor-&gt;<a class="code" href="struct_w_t___c_u_r_s_o_r.html#a0503f16bd8f3d05aa3552f229b3a8e1b">next</a>(cursor)) != <a class="code" href="group__wt.html#ga3c9e1b494d95cf34404ab7a974af6bf8">WT_NOTFOUND</a>) {</div><div class="line">        fprintf(</div><div class="line">          stderr, <span class="stringliteral">&quot;WT_CURSOR.insert: expected WT_NOTFOUND, got %s\n&quot;</span>, <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">        <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> ((ret = conn-&gt;<a name="a54"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#af535c517df851eeac8ebf3594d40b545">close</a>(conn, NULL)) != 0) {</div><div class="line">        fprintf(stderr, <span class="stringliteral">&quot;Error closing connection to %s: %s\n&quot;</span>, home == NULL ? <span class="stringliteral">&quot;.&quot;</span> : home,</div><div class="line">          <a class="code" href="group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd">wiredtiger_strerror</a>(ret));</div><div class="line">        <span class="keywordflow">return</span> (EXIT_FAILURE);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> (EXIT_SUCCESS);</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Copyright (c) 2008-2019 MongoDB, Inc.  All rights reserved.  Contact <a href="mailto:info@wiredtiger.com">info@wiredtiger.com</a> for more information.</li>
  </ul>
</div>
</body>
</html>