1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef __UBIFS_MISC_H__
16#define __UBIFS_MISC_H__
17
18
19
20
21
22
23
24static inline int ubifs_zn_dirty(const struct ubifs_znode *znode)
25{
26 return !!test_bit(DIRTY_ZNODE, &znode->flags);
27}
28
29
30
31
32
33
34
35static inline int ubifs_zn_obsolete(const struct ubifs_znode *znode)
36{
37 return !!test_bit(OBSOLETE_ZNODE, &znode->flags);
38}
39
40
41
42
43
44
45
46
47static inline int ubifs_zn_cow(const struct ubifs_znode *znode)
48{
49 return !!test_bit(COW_ZNODE, &znode->flags);
50}
51
52
53
54
55
56static inline void ubifs_wake_up_bgt(struct ubifs_info *c)
57{
58 if (c->bgt && !c->need_bgt) {
59 c->need_bgt = 1;
60 wake_up_process(c->bgt);
61 }
62}
63
64
65
66
67
68
69
70
71
72static inline struct ubifs_znode *
73ubifs_tnc_find_child(struct ubifs_znode *znode, int start)
74{
75 while (start < znode->child_cnt) {
76 if (znode->zbranch[start].znode)
77 return znode->zbranch[start].znode;
78 start += 1;
79 }
80
81 return NULL;
82}
83
84
85
86
87
88static inline struct ubifs_inode *ubifs_inode(const struct inode *inode)
89{
90 return container_of(inode, struct ubifs_inode, vfs_inode);
91}
92
93
94
95
96
97
98
99
100
101static inline int ubifs_compr_present(struct ubifs_info *c, int compr_type)
102{
103 ubifs_assert(c, compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
104 return !!ubifs_compressors[compr_type]->capi_name;
105}
106
107
108
109
110
111
112
113
114static inline const char *ubifs_compr_name(struct ubifs_info *c, int compr_type)
115{
116 ubifs_assert(c, compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
117 return ubifs_compressors[compr_type]->name;
118}
119
120
121
122
123
124
125
126
127static inline int ubifs_wbuf_sync(struct ubifs_wbuf *wbuf)
128{
129 int err;
130
131 mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead);
132 err = ubifs_wbuf_sync_nolock(wbuf);
133 mutex_unlock(&wbuf->io_mutex);
134 return err;
135}
136
137
138
139
140
141
142
143
144
145
146static inline int ubifs_encode_dev(union ubifs_dev_desc *dev, dev_t rdev)
147{
148 dev->new = cpu_to_le32(new_encode_dev(rdev));
149 return sizeof(dev->new);
150}
151
152
153
154
155
156
157
158
159
160
161static inline int ubifs_add_dirt(struct ubifs_info *c, int lnum, int dirty)
162{
163 return ubifs_update_one_lp(c, lnum, LPROPS_NC, dirty, 0, 0);
164}
165
166
167
168
169
170
171
172
173
174
175static inline int ubifs_return_leb(struct ubifs_info *c, int lnum)
176{
177 return ubifs_change_one_lp(c, lnum, LPROPS_NC, LPROPS_NC, 0,
178 LPROPS_TAKEN, 0);
179}
180
181
182
183
184
185
186static inline int ubifs_idx_node_sz(const struct ubifs_info *c, int child_cnt)
187{
188 return UBIFS_IDX_NODE_SZ + (UBIFS_BRANCH_SZ + c->key_len + c->hash_len)
189 * child_cnt;
190}
191
192
193
194
195
196
197
198static inline
199struct ubifs_branch *ubifs_idx_branch(const struct ubifs_info *c,
200 const struct ubifs_idx_node *idx,
201 int bnum)
202{
203 return (struct ubifs_branch *)((void *)idx->branches +
204 (UBIFS_BRANCH_SZ + c->key_len + c->hash_len) * bnum);
205}
206
207
208
209
210
211
212static inline void *ubifs_idx_key(const struct ubifs_info *c,
213 const struct ubifs_idx_node *idx)
214{
215 return (void *)((struct ubifs_branch *)idx->branches)->key;
216}
217
218
219
220
221
222
223
224
225
226
227
228
229static inline int ubifs_tnc_lookup(struct ubifs_info *c,
230 const union ubifs_key *key, void *node)
231{
232 return ubifs_tnc_locate(c, key, node, NULL, NULL);
233}
234
235
236
237
238
239
240
241
242static inline void ubifs_get_lprops(struct ubifs_info *c)
243{
244 mutex_lock(&c->lp_mutex);
245}
246
247
248
249
250
251
252
253
254static inline void ubifs_release_lprops(struct ubifs_info *c)
255{
256 ubifs_assert(c, mutex_is_locked(&c->lp_mutex));
257 ubifs_assert(c, c->lst.empty_lebs >= 0 &&
258 c->lst.empty_lebs <= c->main_lebs);
259 mutex_unlock(&c->lp_mutex);
260}
261
262
263
264
265
266
267
268
269
270static inline int ubifs_next_log_lnum(const struct ubifs_info *c, int lnum)
271{
272 lnum += 1;
273 if (lnum > c->log_last)
274 lnum = UBIFS_LOG_LNUM;
275
276 return lnum;
277}
278
279static inline int ubifs_xattr_max_cnt(struct ubifs_info *c)
280{
281 int max_xattrs = (c->leb_size / 2) / UBIFS_INO_NODE_SZ;
282
283 ubifs_assert(c, max_xattrs < c->max_orphans);
284 return max_xattrs;
285}
286
287const char *ubifs_assert_action_name(struct ubifs_info *c);
288
289#endif
290