^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * This file is part of UBIFS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2006-2008 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Authors: Artem Bityutskiy (Битюцкий Артём)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Adrian Hunter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This file contains miscellaneous helper functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef __UBIFS_MISC_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define __UBIFS_MISC_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * ubifs_zn_dirty - check if znode is dirty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * @znode: znode to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * This helper function returns %1 if @znode is dirty and %0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static inline int ubifs_zn_dirty(const struct ubifs_znode *znode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return !!test_bit(DIRTY_ZNODE, &znode->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * ubifs_zn_obsolete - check if znode is obsolete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * @znode: znode to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * This helper function returns %1 if @znode is obsolete and %0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static inline int ubifs_zn_obsolete(const struct ubifs_znode *znode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return !!test_bit(OBSOLETE_ZNODE, &znode->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * ubifs_zn_cow - check if znode has to be copied on write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * @znode: znode to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * This helper function returns %1 if @znode is has COW flag set and %0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static inline int ubifs_zn_cow(const struct ubifs_znode *znode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return !!test_bit(COW_ZNODE, &znode->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * ubifs_wake_up_bgt - wake up background thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static inline void ubifs_wake_up_bgt(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (c->bgt && !c->need_bgt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) c->need_bgt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) wake_up_process(c->bgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * ubifs_tnc_find_child - find next child in znode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @znode: znode to search at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @start: the zbranch index to start at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * This helper function looks for znode child starting at index @start. Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * the child or %NULL if no children were found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static inline struct ubifs_znode *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ubifs_tnc_find_child(struct ubifs_znode *znode, int start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) while (start < znode->child_cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (znode->zbranch[start].znode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return znode->zbranch[start].znode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) start += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * ubifs_inode - get UBIFS inode information by VFS 'struct inode' object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * @inode: the VFS 'struct inode' pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static inline struct ubifs_inode *ubifs_inode(const struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return container_of(inode, struct ubifs_inode, vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * ubifs_compr_present - check if compressor was compiled in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * @compr_type: compressor type to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * @c: the UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * This function returns %1 of compressor of type @compr_type is present, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * %0 if not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static inline int ubifs_compr_present(struct ubifs_info *c, int compr_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ubifs_assert(c, compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return !!ubifs_compressors[compr_type]->capi_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * ubifs_compr_name - get compressor name string by its type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * @compr_type: compressor type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * @c: the UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * This function returns compressor type string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static inline const char *ubifs_compr_name(struct ubifs_info *c, int compr_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ubifs_assert(c, compr_type >= 0 && compr_type < UBIFS_COMPR_TYPES_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return ubifs_compressors[compr_type]->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * ubifs_wbuf_sync - synchronize write-buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * @wbuf: write-buffer to synchronize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * This is the same as 'ubifs_wbuf_sync_nolock()' but it does not assume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * that the write-buffer is already locked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static inline int ubifs_wbuf_sync(struct ubifs_wbuf *wbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) err = ubifs_wbuf_sync_nolock(wbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) mutex_unlock(&wbuf->io_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * ubifs_encode_dev - encode device node IDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * @dev: UBIFS device node information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * @rdev: device IDs to encode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * This is a helper function which encodes major/minor numbers of a device node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * into UBIFS device node description. We use standard Linux "new" and "huge"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * encodings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static inline int ubifs_encode_dev(union ubifs_dev_desc *dev, dev_t rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dev->new = cpu_to_le32(new_encode_dev(rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return sizeof(dev->new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * ubifs_add_dirt - add dirty space to LEB properties.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * @c: the UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * @lnum: LEB to add dirty space for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @dirty: dirty space to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * This is a helper function which increased amount of dirty LEB space. Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * zero in case of success and a negative error code in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static inline int ubifs_add_dirt(struct ubifs_info *c, int lnum, int dirty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return ubifs_update_one_lp(c, lnum, LPROPS_NC, dirty, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * ubifs_return_leb - return LEB to lprops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * @c: the UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * @lnum: LEB to return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * This helper function cleans the "taken" flag of a logical eraseblock in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * lprops. Returns zero in case of success and a negative error code in case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static inline int ubifs_return_leb(struct ubifs_info *c, int lnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return ubifs_change_one_lp(c, lnum, LPROPS_NC, LPROPS_NC, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) LPROPS_TAKEN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * ubifs_idx_node_sz - return index node size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * @c: the UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * @child_cnt: number of children of this index node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static inline int ubifs_idx_node_sz(const struct ubifs_info *c, int child_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return UBIFS_IDX_NODE_SZ + (UBIFS_BRANCH_SZ + c->key_len + c->hash_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * child_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * ubifs_idx_branch - return pointer to an index branch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * @c: the UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * @idx: index node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * @bnum: branch number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct ubifs_branch *ubifs_idx_branch(const struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) const struct ubifs_idx_node *idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int bnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return (struct ubifs_branch *)((void *)idx->branches +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) (UBIFS_BRANCH_SZ + c->key_len + c->hash_len) * bnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * ubifs_idx_key - return pointer to an index key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * @c: the UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * @idx: index node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static inline void *ubifs_idx_key(const struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) const struct ubifs_idx_node *idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return (void *)((struct ubifs_branch *)idx->branches)->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * ubifs_tnc_lookup - look up a file-system node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * @key: node key to lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * @node: the node is returned here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * This function look up and reads node with key @key. The caller has to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * sure the @node buffer is large enough to fit the node. Returns zero in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * of success, %-ENOENT if the node was not found, and a negative error code in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static inline int ubifs_tnc_lookup(struct ubifs_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) const union ubifs_key *key, void *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return ubifs_tnc_locate(c, key, node, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * ubifs_get_lprops - get reference to LEB properties.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * @c: the UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * This function locks lprops. Lprops have to be unlocked by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * 'ubifs_release_lprops()'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static inline void ubifs_get_lprops(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) mutex_lock(&c->lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * ubifs_release_lprops - release lprops lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * @c: the UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * This function has to be called after each 'ubifs_get_lprops()' call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * unlock lprops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static inline void ubifs_release_lprops(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) ubifs_assert(c, mutex_is_locked(&c->lp_mutex));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) ubifs_assert(c, c->lst.empty_lebs >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) c->lst.empty_lebs <= c->main_lebs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) mutex_unlock(&c->lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * ubifs_next_log_lnum - switch to the next log LEB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * @c: UBIFS file-system description object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * @lnum: current log LEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * This helper function returns the log LEB number which goes next after LEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * 'lnum'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static inline int ubifs_next_log_lnum(const struct ubifs_info *c, int lnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) lnum += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (lnum > c->log_last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) lnum = UBIFS_LOG_LNUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static inline int ubifs_xattr_max_cnt(struct ubifs_info *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int max_xattrs = (c->leb_size / 2) / UBIFS_INO_NODE_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ubifs_assert(c, max_xattrs < c->max_orphans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return max_xattrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) const char *ubifs_assert_action_name(struct ubifs_info *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #endif /* __UBIFS_MISC_H__ */