Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
misc.h
Go to the documentation of this file.
1 /*
2  * This file is part of UBIFS.
3  *
4  * Copyright (C) 2006-2008 Nokia Corporation
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by
8  * the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 51
17  * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Authors: Artem Bityutskiy (Битюцкий Артём)
20  * Adrian Hunter
21  */
22 
23 /*
24  * This file contains miscellaneous helper functions.
25  */
26 
27 #ifndef __UBIFS_MISC_H__
28 #define __UBIFS_MISC_H__
29 
36 static inline int ubifs_zn_dirty(const struct ubifs_znode *znode)
37 {
38  return !!test_bit(DIRTY_ZNODE, &znode->flags);
39 }
40 
47 static inline int ubifs_zn_obsolete(const struct ubifs_znode *znode)
48 {
49  return !!test_bit(OBSOLETE_ZNODE, &znode->flags);
50 }
51 
59 static inline int ubifs_zn_cow(const struct ubifs_znode *znode)
60 {
61  return !!test_bit(COW_ZNODE, &znode->flags);
62 }
63 
68 static inline void ubifs_wake_up_bgt(struct ubifs_info *c)
69 {
70  if (c->bgt && !c->need_bgt) {
71  c->need_bgt = 1;
72  wake_up_process(c->bgt);
73  }
74 }
75 
84 static inline struct ubifs_znode *
85 ubifs_tnc_find_child(struct ubifs_znode *znode, int start)
86 {
87  while (start < znode->child_cnt) {
88  if (znode->zbranch[start].znode)
89  return znode->zbranch[start].znode;
90  start += 1;
91  }
92 
93  return NULL;
94 }
95 
100 static inline struct ubifs_inode *ubifs_inode(const struct inode *inode)
101 {
102  return container_of(inode, struct ubifs_inode, vfs_inode);
103 }
104 
112 static inline int ubifs_compr_present(int compr_type)
113 {
114  ubifs_assert(compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
115  return !!ubifs_compressors[compr_type]->capi_name;
116 }
117 
124 static inline const char *ubifs_compr_name(int compr_type)
125 {
126  ubifs_assert(compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
127  return ubifs_compressors[compr_type]->name;
128 }
129 
137 static inline int ubifs_wbuf_sync(struct ubifs_wbuf *wbuf)
138 {
139  int err;
140 
141  mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead);
142  err = ubifs_wbuf_sync_nolock(wbuf);
143  mutex_unlock(&wbuf->io_mutex);
144  return err;
145 }
146 
156 static inline int ubifs_encode_dev(union ubifs_dev_desc *dev, dev_t rdev)
157 {
158  if (new_valid_dev(rdev)) {
159  dev->new = cpu_to_le32(new_encode_dev(rdev));
160  return sizeof(dev->new);
161  } else {
162  dev->huge = cpu_to_le64(huge_encode_dev(rdev));
163  return sizeof(dev->huge);
164  }
165 }
166 
176 static inline int ubifs_add_dirt(struct ubifs_info *c, int lnum, int dirty)
177 {
178  return ubifs_update_one_lp(c, lnum, LPROPS_NC, dirty, 0, 0);
179 }
180 
190 static inline int ubifs_return_leb(struct ubifs_info *c, int lnum)
191 {
192  return ubifs_change_one_lp(c, lnum, LPROPS_NC, LPROPS_NC, 0,
193  LPROPS_TAKEN, 0);
194 }
195 
201 static inline int ubifs_idx_node_sz(const struct ubifs_info *c, int child_cnt)
202 {
203  return UBIFS_IDX_NODE_SZ + (UBIFS_BRANCH_SZ + c->key_len) * child_cnt;
204 }
205 
212 static inline
213 struct ubifs_branch *ubifs_idx_branch(const struct ubifs_info *c,
214  const struct ubifs_idx_node *idx,
215  int bnum)
216 {
217  return (struct ubifs_branch *)((void *)idx->branches +
218  (UBIFS_BRANCH_SZ + c->key_len) * bnum);
219 }
220 
226 static inline void *ubifs_idx_key(const struct ubifs_info *c,
227  const struct ubifs_idx_node *idx)
228 {
229  return (void *)((struct ubifs_branch *)idx->branches)->key;
230 }
231 
236 static inline struct timespec ubifs_current_time(struct inode *inode)
237 {
238  return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
240 }
241 
253 static inline int ubifs_tnc_lookup(struct ubifs_info *c,
254  const union ubifs_key *key, void *node)
255 {
256  return ubifs_tnc_locate(c, key, node, NULL, NULL);
257 }
258 
266 static inline void ubifs_get_lprops(struct ubifs_info *c)
267 {
268  mutex_lock(&c->lp_mutex);
269 }
270 
278 static inline void ubifs_release_lprops(struct ubifs_info *c)
279 {
280  ubifs_assert(mutex_is_locked(&c->lp_mutex));
281  ubifs_assert(c->lst.empty_lebs >= 0 &&
282  c->lst.empty_lebs <= c->main_lebs);
283  mutex_unlock(&c->lp_mutex);
284 }
285 
294 static inline int ubifs_next_log_lnum(const struct ubifs_info *c, int lnum)
295 {
296  lnum += 1;
297  if (lnum > c->log_last)
298  lnum = UBIFS_LOG_LNUM;
299 
300  return lnum;
301 }
302 
303 #endif /* __UBIFS_MISC_H__ */