// SPDX-License-Identifier: GPL-2.0-only /* * This file is part of UBIFS. * * Copyright (C) 2006-2008 Nokia Corporation. * * Authors: Artem Bityutskiy (Битюцкий Артём) * Adrian Hunter */ /* This file implements reading and writing the master node */ #include "ubifs.h" /** * ubifs_compare_master_node - compare two UBIFS master nodes * @c: UBIFS file-system description object * @m1: the first node * @m2: the second node * * This function compares two UBIFS master nodes. Returns 0 if they are equal * and nonzero if not. */ int ubifs_compare_master_node(struct ubifs_info *c, void *m1, void *m2) { … } /* mst_node_check_hash - Check hash of a master node * @c: UBIFS file-system description object * @mst: The master node * @expected: The expected hash of the master node * * This checks the hash of a master node against a given expected hash. * Note that we have two master nodes on a UBIFS image which have different * sequence numbers and consequently different CRCs. To be able to match * both master nodes we exclude the common node header containing the sequence * number and CRC from the hash. * * Returns 0 if the hashes are equal, a negative error code otherwise. */ static int mst_node_check_hash(const struct ubifs_info *c, const struct ubifs_mst_node *mst, const u8 *expected) { … } /** * scan_for_master - search the valid master node. * @c: UBIFS file-system description object * * This function scans the master node LEBs and search for the latest master * node. Returns zero in case of success, %-EUCLEAN if there master area is * corrupted and requires recovery, and a negative error code in case of * failure. */ static int scan_for_master(struct ubifs_info *c) { … } /** * validate_master - validate master node. * @c: UBIFS file-system description object * * This function validates data which was read from master node. Returns zero * if the data is all right and %-EINVAL if not. */ static int validate_master(const struct ubifs_info *c) { … } /** * ubifs_read_master - read master node. * @c: UBIFS file-system description object * * This function finds and reads the master node during file-system mount. If * the flash is empty, it creates default master node as well. Returns zero in * case of success and a negative error code in case of failure. */ int ubifs_read_master(struct ubifs_info *c) { … } /** * ubifs_write_master - write master node. * @c: UBIFS file-system description object * * This function writes the master node. Returns zero in case of success and a * negative error code in case of failure. The master node is written twice to * enable recovery. */ int ubifs_write_master(struct ubifs_info *c) { … }