0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef __UBIFS_MISC_H__
0016 #define __UBIFS_MISC_H__
0017
0018
0019
0020
0021
0022
0023
0024 static inline int ubifs_zn_dirty(const struct ubifs_znode *znode)
0025 {
0026 return !!test_bit(DIRTY_ZNODE, &znode->flags);
0027 }
0028
0029
0030
0031
0032
0033
0034
0035 static inline int ubifs_zn_obsolete(const struct ubifs_znode *znode)
0036 {
0037 return !!test_bit(OBSOLETE_ZNODE, &znode->flags);
0038 }
0039
0040
0041
0042
0043
0044
0045
0046
0047 static inline int ubifs_zn_cow(const struct ubifs_znode *znode)
0048 {
0049 return !!test_bit(COW_ZNODE, &znode->flags);
0050 }
0051
0052
0053
0054
0055
0056 static inline void ubifs_wake_up_bgt(struct ubifs_info *c)
0057 {
0058 if (c->bgt && !c->need_bgt) {
0059 c->need_bgt = 1;
0060 wake_up_process(c->bgt);
0061 }
0062 }
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 static inline struct ubifs_znode *
0073 ubifs_tnc_find_child(struct ubifs_znode *znode, int start)
0074 {
0075 while (start < znode->child_cnt) {
0076 if (znode->zbranch[start].znode)
0077 return znode->zbranch[start].znode;
0078 start += 1;
0079 }
0080
0081 return NULL;
0082 }
0083
0084
0085
0086
0087
0088 static inline struct ubifs_inode *ubifs_inode(const struct inode *inode)
0089 {
0090 return container_of(inode, struct ubifs_inode, vfs_inode);
0091 }
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 static inline int ubifs_compr_present(struct ubifs_info *c, int compr_type)
0102 {
0103 ubifs_assert(c, compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
0104 return !!ubifs_compressors[compr_type]->capi_name;
0105 }
0106
0107
0108
0109
0110
0111
0112
0113
0114 static inline const char *ubifs_compr_name(struct ubifs_info *c, int compr_type)
0115 {
0116 ubifs_assert(c, compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
0117 return ubifs_compressors[compr_type]->name;
0118 }
0119
0120
0121
0122
0123
0124
0125
0126
0127 static inline int ubifs_wbuf_sync(struct ubifs_wbuf *wbuf)
0128 {
0129 int err;
0130
0131 mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead);
0132 err = ubifs_wbuf_sync_nolock(wbuf);
0133 mutex_unlock(&wbuf->io_mutex);
0134 return err;
0135 }
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 static inline int ubifs_encode_dev(union ubifs_dev_desc *dev, dev_t rdev)
0147 {
0148 dev->new = cpu_to_le32(new_encode_dev(rdev));
0149 return sizeof(dev->new);
0150 }
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161 static inline int ubifs_add_dirt(struct ubifs_info *c, int lnum, int dirty)
0162 {
0163 return ubifs_update_one_lp(c, lnum, LPROPS_NC, dirty, 0, 0);
0164 }
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 static inline int ubifs_return_leb(struct ubifs_info *c, int lnum)
0176 {
0177 return ubifs_change_one_lp(c, lnum, LPROPS_NC, LPROPS_NC, 0,
0178 LPROPS_TAKEN, 0);
0179 }
0180
0181
0182
0183
0184
0185
0186 static inline int ubifs_idx_node_sz(const struct ubifs_info *c, int child_cnt)
0187 {
0188 return UBIFS_IDX_NODE_SZ + (UBIFS_BRANCH_SZ + c->key_len + c->hash_len)
0189 * child_cnt;
0190 }
0191
0192
0193
0194
0195
0196
0197
0198 static inline
0199 struct ubifs_branch *ubifs_idx_branch(const struct ubifs_info *c,
0200 const struct ubifs_idx_node *idx,
0201 int bnum)
0202 {
0203 return (struct ubifs_branch *)((void *)idx->branches +
0204 (UBIFS_BRANCH_SZ + c->key_len + c->hash_len) * bnum);
0205 }
0206
0207
0208
0209
0210
0211
0212 static inline void *ubifs_idx_key(const struct ubifs_info *c,
0213 const struct ubifs_idx_node *idx)
0214 {
0215 return (void *)((struct ubifs_branch *)idx->branches)->key;
0216 }
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229 static inline int ubifs_tnc_lookup(struct ubifs_info *c,
0230 const union ubifs_key *key, void *node)
0231 {
0232 return ubifs_tnc_locate(c, key, node, NULL, NULL);
0233 }
0234
0235
0236
0237
0238
0239
0240
0241
0242 static inline void ubifs_get_lprops(struct ubifs_info *c)
0243 {
0244 mutex_lock(&c->lp_mutex);
0245 }
0246
0247
0248
0249
0250
0251
0252
0253
0254 static inline void ubifs_release_lprops(struct ubifs_info *c)
0255 {
0256 ubifs_assert(c, mutex_is_locked(&c->lp_mutex));
0257 ubifs_assert(c, c->lst.empty_lebs >= 0 &&
0258 c->lst.empty_lebs <= c->main_lebs);
0259 mutex_unlock(&c->lp_mutex);
0260 }
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270 static inline int ubifs_next_log_lnum(const struct ubifs_info *c, int lnum)
0271 {
0272 lnum += 1;
0273 if (lnum > c->log_last)
0274 lnum = UBIFS_LOG_LNUM;
0275
0276 return lnum;
0277 }
0278
0279 static inline int ubifs_xattr_max_cnt(struct ubifs_info *c)
0280 {
0281 int max_xattrs = (c->leb_size / 2) / UBIFS_INO_NODE_SZ;
0282
0283 ubifs_assert(c, max_xattrs < c->max_orphans);
0284 return max_xattrs;
0285 }
0286
0287 const char *ubifs_assert_action_name(struct ubifs_info *c);
0288
0289 #endif