···32323333#include "ubifs.h"3434#include <linux/writeback.h>3535-#include <asm/div64.h>3535+#include <linux/math64.h>36363737/*3838 * When pessimistic budget calculations say that there is no enough space,···258258 */259259int ubifs_calc_min_idx_lebs(struct ubifs_info *c)260260{261261- int ret;262262- uint64_t idx_size;261261+ int idx_lebs, eff_leb_size = c->leb_size - c->max_idx_node_sz;262262+ long long idx_size;263263264264 idx_size = c->old_idx_sz + c->budg_idx_growth + c->budg_uncommitted_idx;265265···271271 * pair, nor similarly the two variables for the new index size, so we272272 * have to do this costly 64-bit division on fast-path.273273 */274274- if (do_div(idx_size, c->leb_size - c->max_idx_node_sz))275275- ret = idx_size + 1;276276- else277277- ret = idx_size;274274+ idx_size += eff_leb_size - 1;275275+ idx_lebs = div_u64(idx_size, eff_leb_size);278276 /*279277 * The index head is not available for the in-the-gaps method, so add an280278 * extra LEB to compensate.281279 */282282- ret += 1;283283- if (ret < MIN_INDEX_LEBS)284284- ret = MIN_INDEX_LEBS;285285- return ret;280280+ idx_lebs += 1;281281+ if (idx_lebs < MIN_INDEX_LEBS)282282+ idx_lebs = MIN_INDEX_LEBS;283283+ return idx_lebs;286284}287285288286/**···716718 * Note, the calculation is pessimistic, which means that most of the time717719 * UBIFS reports less space than it actually has.718720 */719719-long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free)721721+long long ubifs_reported_space(const struct ubifs_info *c, long long free)720722{721723 int divisor, factor, f;722724···738740 divisor = UBIFS_MAX_DATA_NODE_SZ;739741 divisor += (c->max_idx_node_sz * 3) / (f - 1);740742 free *= factor;741741- do_div(free, divisor);742742- return free;743743+ return div_u64(free, divisor);743744}744745745746/**
···4343 * mounted.4444 */45454646-#include <linux/crc16.h>4746#include "ubifs.h"4747+#include <linux/crc16.h>4848+#include <linux/math64.h>48494950/**5051 * do_calc_lpt_geom - calculate sizes for the LPT area.···136135int ubifs_calc_lpt_geom(struct ubifs_info *c)137136{138137 int lebs_needed;139139- uint64_t sz;138138+ long long sz;140139141140 do_calc_lpt_geom(c);142141143142 /* Verify that lpt_lebs is big enough */144143 sz = c->lpt_sz * 2; /* Must have at least 2 times the size */145145- sz += c->leb_size - 1;146146- do_div(sz, c->leb_size);147147- lebs_needed = sz;144144+ lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size);148145 if (lebs_needed > c->lpt_lebs) {149146 ubifs_err("too few LPT LEBs");150147 return -EINVAL;···174175 int *big_lpt)175176{176177 int i, lebs_needed;177177- uint64_t sz;178178+ long long sz;178179179180 /* Start by assuming the minimum number of LPT LEBs */180181 c->lpt_lebs = UBIFS_MIN_LPT_LEBS;···201202 /* Now check there are enough LPT LEBs */202203 for (i = 0; i < 64 ; i++) {203204 sz = c->lpt_sz * 4; /* Allow 4 times the size */204204- sz += c->leb_size - 1;205205- do_div(sz, c->leb_size);206206- lebs_needed = sz;205205+ lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size);207206 if (lebs_needed > c->lpt_lebs) {208207 /* Not enough LPT LEBs so try again with more */209208 c->lpt_lebs = lebs_needed;
+5-5
fs/ubifs/sb.c
···28282929#include "ubifs.h"3030#include <linux/random.h>3131+#include <linux/math64.h>31323233/*3334 * Default journal size in logical eraseblocks as a percent of total···8180 int err, tmp, jnl_lebs, log_lebs, max_buds, main_lebs, main_first;8281 int lpt_lebs, lpt_first, orph_lebs, big_lpt, ino_waste, sup_flags = 0;8382 int min_leb_cnt = UBIFS_MIN_LEB_CNT;8484- uint64_t tmp64, main_bytes;8383+ long long tmp64, main_bytes;8584 __le64 tmp_le64;86858786 /* Some functions called from here depend on the @c->key_len filed */···161160 if (!sup)162161 return -ENOMEM;163162164164- tmp64 = (uint64_t)max_buds * c->leb_size;163163+ tmp64 = (long long)max_buds * c->leb_size;165164 if (big_lpt)166165 sup_flags |= UBIFS_FLG_BIGLPT;167166···188187189188 generate_random_uuid(sup->uuid);190189191191- main_bytes = (uint64_t)main_lebs * c->leb_size;192192- tmp64 = main_bytes * DEFAULT_RP_PERCENT;193193- do_div(tmp64, 100);190190+ main_bytes = (long long)main_lebs * c->leb_size;191191+ tmp64 = div_u64(main_bytes * DEFAULT_RP_PERCENT, 100);194192 if (tmp64 > DEFAULT_MAX_RP_SIZE)195193 tmp64 = DEFAULT_MAX_RP_SIZE;196194 sup->rp_size = cpu_to_le64(tmp64);
+6-6
fs/ubifs/super.c
···3434#include <linux/parser.h>3535#include <linux/seq_file.h>3636#include <linux/mount.h>3737+#include <linux/math64.h>3738#include "ubifs.h"38393940/*···613612static int init_constants_late(struct ubifs_info *c)614613{615614 int tmp, err;616616- uint64_t tmp64;615615+ long long tmp64;617616618617 c->main_bytes = (long long)c->main_lebs * c->leb_size;619618 c->max_znode_sz = sizeof(struct ubifs_znode) +···640639 * Make sure that the log is large enough to fit reference nodes for641640 * all buds plus one reserved LEB.642641 */643643- tmp64 = c->max_bud_bytes;644644- tmp = do_div(tmp64, c->leb_size);645645- c->max_bud_cnt = tmp64 + !!tmp;642642+ tmp64 = c->max_bud_bytes + c->leb_size - 1;643643+ c->max_bud_cnt = div_u64(tmp64, c->leb_size);646644 tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1);647645 tmp /= c->leb_size;648646 tmp += 1;···677677 * Consequently, if the journal is too small, UBIFS will treat it as678678 * always full.679679 */680680- tmp64 = (uint64_t)(c->jhead_cnt + 1) * c->leb_size + 1;680680+ tmp64 = (long long)(c->jhead_cnt + 1) * c->leb_size + 1;681681 if (c->bg_bud_bytes < tmp64)682682 c->bg_bud_bytes = tmp64;683683 if (c->max_bud_bytes < tmp64 + c->leb_size)···699699 * head is available.700700 */701701 tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt + 1;702702- tmp64 *= (uint64_t)c->leb_size - c->leb_overhead;702702+ tmp64 *= (long long)c->leb_size - c->leb_overhead;703703 tmp64 = ubifs_reported_space(c, tmp64);704704 c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT;705705
+1-1
fs/ubifs/ubifs.h
···14981498long long ubifs_get_free_space(struct ubifs_info *c);14991499int ubifs_calc_min_idx_lebs(struct ubifs_info *c);15001500void ubifs_convert_page_budget(struct ubifs_info *c);15011501-long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free);15011501+long long ubifs_reported_space(const struct ubifs_info *c, long long free);15021502long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);1503150315041504/* find.c */