1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS File Systems Buffer Routines |
---|
5 | * @ingroup rtems_rfs |
---|
6 | * |
---|
7 | * RTEMS File Systems Buffer Routines for the RTEMS libblock BD buffer cache. |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org> |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #if HAVE_CONFIG_H |
---|
20 | #include "config.h" |
---|
21 | #endif |
---|
22 | |
---|
23 | #include <inttypes.h> |
---|
24 | #include <errno.h> |
---|
25 | |
---|
26 | #include <rtems/rfs/rtems-rfs-buffer.h> |
---|
27 | #include <rtems/rfs/rtems-rfs-file-system.h> |
---|
28 | |
---|
29 | #if RTEMS_RFS_USE_LIBBLOCK |
---|
30 | |
---|
31 | /** |
---|
32 | * Show errors. |
---|
33 | */ |
---|
34 | #define RTEMS_RFS_BUFFER_ERRORS 0 |
---|
35 | |
---|
36 | int |
---|
37 | rtems_rfs_buffer_bdbuf_request (rtems_rfs_file_system* fs, |
---|
38 | rtems_rfs_buffer_block block, |
---|
39 | bool read, |
---|
40 | rtems_rfs_buffer** buffer) |
---|
41 | { |
---|
42 | rtems_status_code sc; |
---|
43 | int rc = 0; |
---|
44 | |
---|
45 | if (read) |
---|
46 | sc = rtems_bdbuf_read (rtems_rfs_fs_device (fs), block, buffer); |
---|
47 | else |
---|
48 | sc = rtems_bdbuf_get (rtems_rfs_fs_device (fs), block, buffer); |
---|
49 | |
---|
50 | if (sc != RTEMS_SUCCESSFUL) |
---|
51 | { |
---|
52 | #if RTEMS_RFS_BUFFER_ERRORS |
---|
53 | printf ("rtems-rfs: buffer-bdbuf-request: block=%lu: bdbuf-%s: %d: %s\n", |
---|
54 | block, read ? "read" : "get", sc, rtems_status_text (sc)); |
---|
55 | #endif |
---|
56 | rc = EIO; |
---|
57 | } |
---|
58 | |
---|
59 | return rc; |
---|
60 | } |
---|
61 | |
---|
62 | int |
---|
63 | rtems_rfs_buffer_bdbuf_release (rtems_rfs_buffer* buffer, |
---|
64 | bool modified) |
---|
65 | { |
---|
66 | rtems_status_code sc; |
---|
67 | int rc = 0; |
---|
68 | |
---|
69 | if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_RELEASE)) |
---|
70 | printf ("rtems-rfs: bdbuf-release: block=%" PRIuPTR " bdbuf=%" PRIu32 " %s\n", |
---|
71 | ((intptr_t) buffer->user), |
---|
72 | buffer->block, modified ? "(modified)" : ""); |
---|
73 | |
---|
74 | if (modified) |
---|
75 | sc = rtems_bdbuf_release_modified (buffer); |
---|
76 | else |
---|
77 | sc = rtems_bdbuf_release (buffer); |
---|
78 | |
---|
79 | if (sc != RTEMS_SUCCESSFUL) |
---|
80 | { |
---|
81 | #if RTEMS_RFS_BUFFER_ERRORS |
---|
82 | printf ("rtems-rfs: buffer-release: bdbuf-%s: %s(%d)\n", |
---|
83 | modified ? "modified" : "not-modified", |
---|
84 | rtems_status_text (sc), sc); |
---|
85 | #endif |
---|
86 | rc = EIO; |
---|
87 | } |
---|
88 | |
---|
89 | return rc; |
---|
90 | } |
---|
91 | |
---|
92 | #endif |
---|