diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-06-03 06:45:09 -0400 |
---|---|---|
committer | Artem Bityutskiy <dedekind1@gmail.com> | 2011-07-04 03:54:33 -0400 |
commit | 83cef708c606f46a2b527af025acb3d24555f0c4 (patch) | |
tree | f5f91da8f13a7f013304ae596e56e7d52a5dcd76 /fs/ubifs/io.c | |
parent | d033c98b17ecf30d64d83d96938ce7bfb47f7520 (diff) |
UBIFS: introduce more I/O helpers
Introduce the following I/O helper functions: 'ubifs_leb_read()',
'ubifs_leb_write()', 'ubifs_leb_change()', 'ubifs_leb_unmap()',
'ubifs_leb_map()', 'ubifs_is_mapped().
The idea is to wrap all UBI I/O functions in order to encapsulate various
assertions and error path handling (error message, stack dump, switching to R/O
mode). And there are some other benefits of this which will be used in the
following patches.
This patch does not switch whole UBIFS to use these functions yet.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs/ubifs/io.c')
-rw-r--r-- | fs/ubifs/io.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c index 48e16804ca57..239899d7bf3f 100644 --- a/fs/ubifs/io.c +++ b/fs/ubifs/io.c | |||
@@ -90,6 +90,123 @@ void ubifs_ro_mode(struct ubifs_info *c, int err) | |||
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | /* | ||
94 | * Below are simple wrappers over UBI I/O functions which include some | ||
95 | * additional checks and UBIFS debugging stuff. See corresponding UBI function | ||
96 | * for more information. | ||
97 | */ | ||
98 | |||
99 | int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs, | ||
100 | int len, int even_ebadmsg) | ||
101 | { | ||
102 | int err; | ||
103 | |||
104 | err = ubi_read(c->ubi, lnum, buf, offs, len); | ||
105 | /* | ||
106 | * In case of %-EBADMSG print the error message only if the | ||
107 | * @even_ebadmsg is true. | ||
108 | */ | ||
109 | if (err && (err != -EBADMSG || even_ebadmsg)) { | ||
110 | ubifs_err("reading %d bytes from LEB %d:%d failed, error %d", | ||
111 | len, lnum, offs, err); | ||
112 | dbg_dump_stack(); | ||
113 | } | ||
114 | return err; | ||
115 | } | ||
116 | |||
117 | int ubifs_leb_write(struct ubifs_info *c, int lnum, const void *buf, int offs, | ||
118 | int len, int dtype) | ||
119 | { | ||
120 | int err; | ||
121 | |||
122 | ubifs_assert(!c->ro_media && !c->ro_mount); | ||
123 | if (c->ro_error) | ||
124 | return -EROFS; | ||
125 | if (!dbg_is_tst_rcvry(c)) | ||
126 | err = ubi_leb_write(c->ubi, lnum, buf, offs, len, dtype); | ||
127 | else | ||
128 | err = dbg_leb_write(c->ubi, lnum, buf, offs, len, dtype); | ||
129 | if (err) { | ||
130 | ubifs_err("writing %d bytes to LEB %d:%d failed, error %d", | ||
131 | len, lnum, offs, err); | ||
132 | ubifs_ro_mode(c, err); | ||
133 | dbg_dump_stack(); | ||
134 | } | ||
135 | return err; | ||
136 | } | ||
137 | |||
138 | int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len, | ||
139 | int dtype) | ||
140 | { | ||
141 | int err; | ||
142 | |||
143 | ubifs_assert(!c->ro_media && !c->ro_mount); | ||
144 | if (c->ro_error) | ||
145 | return -EROFS; | ||
146 | if (!dbg_is_tst_rcvry(c)) | ||
147 | err = ubi_leb_change(c->ubi, lnum, buf, len, dtype); | ||
148 | else | ||
149 | err = dbg_leb_change(c->ubi, lnum, buf, len, dtype); | ||
150 | if (err) { | ||
151 | ubifs_err("changing %d bytes in LEB %d failed, error %d", | ||
152 | len, lnum, err); | ||
153 | ubifs_ro_mode(c, err); | ||
154 | dbg_dump_stack(); | ||
155 | } | ||
156 | return err; | ||
157 | } | ||
158 | |||
159 | int ubifs_leb_unmap(struct ubifs_info *c, int lnum) | ||
160 | { | ||
161 | int err; | ||
162 | |||
163 | ubifs_assert(!c->ro_media && !c->ro_mount); | ||
164 | if (c->ro_error) | ||
165 | return -EROFS; | ||
166 | if (!dbg_is_tst_rcvry(c)) | ||
167 | err = ubi_leb_unmap(c->ubi, lnum); | ||
168 | else | ||
169 | err = dbg_leb_unmap(c->ubi, lnum); | ||
170 | if (err) { | ||
171 | ubifs_err("unmap LEB %d failed, error %d", lnum, err); | ||
172 | ubifs_ro_mode(c, err); | ||
173 | dbg_dump_stack(); | ||
174 | } | ||
175 | return err; | ||
176 | } | ||
177 | |||
178 | int ubifs_leb_map(struct ubifs_info *c, int lnum, int dtype) | ||
179 | { | ||
180 | int err; | ||
181 | |||
182 | ubifs_assert(!c->ro_media && !c->ro_mount); | ||
183 | if (c->ro_error) | ||
184 | return -EROFS; | ||
185 | if (!dbg_is_tst_rcvry(c)) | ||
186 | err = ubi_leb_map(c->ubi, lnum, dtype); | ||
187 | else | ||
188 | err = dbg_leb_map(c->ubi, lnum, dtype); | ||
189 | if (err) { | ||
190 | ubifs_err("mapping LEB %d failed, error %d", lnum, err); | ||
191 | ubifs_ro_mode(c, err); | ||
192 | dbg_dump_stack(); | ||
193 | } | ||
194 | return err; | ||
195 | } | ||
196 | |||
197 | int ubifs_is_mapped(const struct ubifs_info *c, int lnum) | ||
198 | { | ||
199 | int err; | ||
200 | |||
201 | err = ubi_is_mapped(c->ubi, lnum); | ||
202 | if (err < 0) { | ||
203 | ubifs_err("ubi_is_mapped failed for LEB %d, error %d", | ||
204 | lnum, err); | ||
205 | dbg_dump_stack(); | ||
206 | } | ||
207 | return err; | ||
208 | } | ||
209 | |||
93 | /** | 210 | /** |
94 | * ubifs_check_node - check node. | 211 | * ubifs_check_node - check node. |
95 | * @c: UBIFS file-system description object | 212 | * @c: UBIFS file-system description object |