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#ifndef __UBIFS_MISC_H__
28#define __UBIFS_MISC_H__
29
30
31
32
33
34
35
36static inline int ubifs_zn_dirty(const struct ubifs_znode *znode)
37{
38 return !!test_bit(DIRTY_ZNODE, &znode->flags);
39}
40
41
42
43
44
45static inline void ubifs_wake_up_bgt(struct ubifs_info *c)
46{
47 if (c->bgt && !c->need_bgt) {
48 c->need_bgt = 1;
49 wake_up_process(c->bgt);
50 }
51}
52
53
54
55
56
57
58
59
60
61static inline struct ubifs_znode *
62ubifs_tnc_find_child(struct ubifs_znode *znode, int start)
63{
64 while (start < znode->child_cnt) {
65 if (znode->zbranch[start].znode)
66 return znode->zbranch[start].znode;
67 start += 1;
68 }
69
70 return NULL;
71}
72
73
74
75
76
77static inline struct ubifs_inode *ubifs_inode(const struct inode *inode)
78{
79 return container_of(inode, struct ubifs_inode, vfs_inode);
80}
81
82
83
84
85
86
87
88
89static inline int ubifs_compr_present(int compr_type)
90{
91 ubifs_assert(compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
92 return !!ubifs_compressors[compr_type]->capi_name;
93}
94
95
96
97
98
99
100
101static inline const char *ubifs_compr_name(int compr_type)
102{
103 ubifs_assert(compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
104 return ubifs_compressors[compr_type]->name;
105}
106
107
108
109
110
111
112
113
114static inline int ubifs_wbuf_sync(struct ubifs_wbuf *wbuf)
115{
116 int err;
117
118 mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead);
119 err = ubifs_wbuf_sync_nolock(wbuf);
120 mutex_unlock(&wbuf->io_mutex);
121 return err;
122}
123
124
125
126
127
128
129
130
131static inline int ubifs_leb_unmap(const struct ubifs_info *c, int lnum)
132{
133 int err;
134
135 ubifs_assert(!c->ro_media && !c->ro_mount);
136 if (c->ro_error)
137 return -EROFS;
138 err = ubi_leb_unmap(c->ubi, lnum);
139 if (err) {
140 ubifs_err("unmap LEB %d failed, error %d", lnum, err);
141 return err;
142 }
143
144 return 0;
145}
146
147
148
149
150
151
152
153
154
155
156
157
158static inline int ubifs_leb_write(const struct ubifs_info *c, int lnum,
159 const void *buf, int offs, int len, int dtype)
160{
161 int err;
162
163 ubifs_assert(!c->ro_media && !c->ro_mount);
164 if (c->ro_error)
165 return -EROFS;
166 err = ubi_leb_write(c->ubi, lnum, buf, offs, len, dtype);
167 if (err) {
168 ubifs_err("writing %d bytes at %d:%d, error %d",
169 len, lnum, offs, err);
170 return err;
171 }
172
173 return 0;
174}
175
176
177
178
179
180
181
182
183
184
185
186static inline int ubifs_leb_change(const struct ubifs_info *c, int lnum,
187 const void *buf, int len, int dtype)
188{
189 int err;
190
191 ubifs_assert(!c->ro_media && !c->ro_mount);
192 if (c->ro_error)
193 return -EROFS;
194 err = ubi_leb_change(c->ubi, lnum, buf, len, dtype);
195 if (err) {
196 ubifs_err("changing %d bytes in LEB %d, error %d",
197 len, lnum, err);
198 return err;
199 }
200
201 return 0;
202}
203
204
205
206
207
208
209
210
211
212
213static inline int ubifs_encode_dev(union ubifs_dev_desc *dev, dev_t rdev)
214{
215 if (new_valid_dev(rdev)) {
216 dev->new = cpu_to_le32(new_encode_dev(rdev));
217 return sizeof(dev->new);
218 } else {
219 dev->huge = cpu_to_le64(huge_encode_dev(rdev));
220 return sizeof(dev->huge);
221 }
222}
223
224
225
226
227
228
229
230
231
232
233static inline int ubifs_add_dirt(struct ubifs_info *c, int lnum, int dirty)
234{
235 return ubifs_update_one_lp(c, lnum, LPROPS_NC, dirty, 0, 0);
236}
237
238
239
240
241
242
243
244
245
246
247static inline int ubifs_return_leb(struct ubifs_info *c, int lnum)
248{
249 return ubifs_change_one_lp(c, lnum, LPROPS_NC, LPROPS_NC, 0,
250 LPROPS_TAKEN, 0);
251}
252
253
254
255
256
257
258static inline int ubifs_idx_node_sz(const struct ubifs_info *c, int child_cnt)
259{
260 return UBIFS_IDX_NODE_SZ + (UBIFS_BRANCH_SZ + c->key_len) * child_cnt;
261}
262
263
264
265
266
267
268
269static inline
270struct ubifs_branch *ubifs_idx_branch(const struct ubifs_info *c,
271 const struct ubifs_idx_node *idx,
272 int bnum)
273{
274 return (struct ubifs_branch *)((void *)idx->branches +
275 (UBIFS_BRANCH_SZ + c->key_len) * bnum);
276}
277
278
279
280
281
282
283static inline void *ubifs_idx_key(const struct ubifs_info *c,
284 const struct ubifs_idx_node *idx)
285{
286 return (void *)((struct ubifs_branch *)idx->branches)->key;
287}
288
289
290
291
292
293static inline struct timespec ubifs_current_time(struct inode *inode)
294{
295 return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
296 current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
297}
298
299
300
301
302
303
304
305
306
307
308
309
310static inline int ubifs_tnc_lookup(struct ubifs_info *c,
311 const union ubifs_key *key, void *node)
312{
313 return ubifs_tnc_locate(c, key, node, NULL, NULL);
314}
315
316
317
318
319
320
321
322
323static inline void ubifs_get_lprops(struct ubifs_info *c)
324{
325 mutex_lock(&c->lp_mutex);
326}
327
328
329
330
331
332
333
334
335static inline void ubifs_release_lprops(struct ubifs_info *c)
336{
337 ubifs_assert(mutex_is_locked(&c->lp_mutex));
338 ubifs_assert(c->lst.empty_lebs >= 0 &&
339 c->lst.empty_lebs <= c->main_lebs);
340 mutex_unlock(&c->lp_mutex);
341}
342
343#endif
344