本文主要是介绍mkfs.ubifs -c 计算工具,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
mkfs.ubifs -c 输入的logical erase block count,是指除掉ubi文件系统自身管理和坏块处理后的逻辑可擦除最大块数。
参考信息如下:
logical erase block count 计算工具,实现代码如下:
#!/usr/bin/python
# -*- coding: UTF-8 -*-import os
import xml.sax
import sys
import time
import getopt
import mathclass ANSI:RED = '\033[31m'RESET = '\033[m'def print_red(text):print(ANSI.RED + text + ANSI.RESET)
def contains_chars(s,chars):for c in chars:if c in s:return Truereturn Falsedef trams_str_digital(text):tramsNumber = 0tramstr = textif contains_chars(tramstr,'M'):valueStr = tramstr.replace('M','')tramsNumber = int(valueStr) * 1024 * 1024elif contains_chars(tramstr,'m'):valueStr = tramstr.replace('m','')tramsNumber = int(valueStr) * 1024 * 1024elif contains_chars(tramstr,'K'):valueStr = tramstr.replace('K','')tramsNumber = int(valueStr) * 1024elif contains_chars(tramstr,'k'):valueStr = tramstr.replace('k','')tramsNumber = int(valueStr) * 1024else:tramsNumber = int(tramstr)return tramsNumberdef show_help():print("ubi_lebc.py -e <logical erase block size> -s <mtd volume total size>")print("eg:ubi_lebc.py -e 124K -s 30M")'''
input:mtd volume total size
input:logical erase block size
input:Physical Erase Block size
out:maximum logical erase block count
'''
if __name__ == "__main__":peb_size = 128 * 1024leb_size = 124 * 1024lebc_max = 0mtd_total_size=0try:opts, args = getopt.getopt(sys.argv[1:],"hb:e:s:",['help',"block_size=","erase_size=","size="])for opt, arg in opts:if opt in ('-b',"--block_size="):peb_size = trams_str_digital(arg)elif opt in ('-e',"--erase_size="):leb_size = trams_str_digital(arg)elif opt in ('-s',"--size="):mtd_total_size = trams_str_digital(arg)elif opt in ("-h","--help"):show_help()sys.exit(0)else:show_help()sys.exit(0)except getopt.GetoptError as e:print(sys.argv)print(e.msg)print(e.opt)show_help()sys.exit(0)if mtd_total_size == 0:show_help()sys.exit(0)block_total_number = mtd_total_size//peb_sizebad_block_max = math.ceil(block_total_number * 0.02)if(bad_block_max < 2):bad_block_max = 2over_head = peb_size - leb_sizeover_head_total_size = over_head * (block_total_number - bad_block_max - 4)loss_total_size = (bad_block_max + 4) * peb_sizeoverhead_manager_size = over_head_total_size + loss_total_sizeuser_data_size = mtd_total_size - overhead_manager_sizelebc_max = int(user_data_size // leb_size)#print("hysical Erase Block size:"+ "%dK" % (peb_size/1024) + " logical erase block size:" + "%dK" % (leb_size/1024) + " out logical erase block count:" + "%d" % lebc_max)print(lebc_max)sys.exit(0)
python ubi_lebc.py -b 128K -e 124K -s 40M
运行结果为:309
这篇关于mkfs.ubifs -c 计算工具的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!