summaryrefslogtreecommitdiffstats
path: root/bcal.1
blob: b5f8fb14a7836a989425488cfef6cfa5ff20a8de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
.TH "BCAL" "1" "Jun 2017" "Version 1.6" "User Commands"
.SH NAME
bcal \- Perform storage conversions and calculations.
.SH SYNOPSIS
.B bcal [-c N] [-f FORMAT] [-s bytes] [-m] [-d] [-h]
.br
.B "    "[expression] [N [unit]]
.SH DESCRIPTION
.B bcal
(Byte CALculator) is a command-line utility to help with numerical calculations involving data storage units, addressing, base conversions etc.
.PP
.B Features
.PP
  * evaluate arithmetic expressions involving storage units
  * convert to IEC/SI standard data storage units
  * show the address in bytes
  * evaluate arithmetic expression of storage units
  * show address as LBA:OFFSET
  * convert CHS to LBA and vice versa
  * show binary, decimal and hex representation of a number
  * custom sector size, max heads/cylinder and max sectors/track
  * minimal dependencies
.PP
\fBbcal\fR follows Ubuntu's standard unit conversion and notation policy. Only 64-bit operating systems are supported.

Refer to:
.I https://wiki.ubuntu.com/UnitsPolicy
.SH OPERATIONAL NOTES
.PP
.IP 1. 4
\fBExpression\fR: An expression must be within double quotes. Inner spaces are ignored. A storage unit can only be multiplied or divided by positive integers. Only storage units can be used for addition and subtraction.
.PP
.IP 2. 4
\fBN [unit]\fR: \fIN\fR can be a decimal or '0x' prefixed hex value. \fIunit\fR can be B/KiB/MiB/GiB/TiB/kB/MB/GB/TB following Ubuntu policy. Default is byte. As all of these tokens are unique, \fIunit\fR is case-insensitive.
.PP
.IP 3. 4
Only decimal is recognized in expressions. Decimal and hex \fBnumeric representations\fR are recognized for unit conversions. Decimal, hex, binary and octal are recognized for all other operations.
.PP
.IP 4. 4
\fBSyntax\fR: Prefix hex inputs with '0x', binary inputs with '0b', octal inputs with '00'.
.PP
.IP 5. 4
\fBNo negative arguments\fR allowed. Input limits are \fIunsigned long long\fR and \fIdouble\fR.
.PP
.IP 6. 4
\fBFractional bytes do not exist\fR, because they can't be addressed. \fBbcal\fR shows the floor value of non-integer bytes.
.PP
.IP 7. 4
\fBCHS and LBA syntax\fR:
  - LBA: 'lLBA-MAX_HEAD-MAX_SECTOR'   [NOTE: LBA starts with 'l' (case ignored)]
  - CHS: 'cC-H-S-MAX_HEAD-MAX_SECTOR' [NOTE: CHS starts with 'c' (case ignored)]
  - Format conversion arguments must be hyphen separated.
  - Any unspecified value, including the one preceding the first '-' to the one following the last '-', is considered '0' (zero).
.PP
.IP 8. 4
\fBDefault values\fR:
  - sector size: 0x200 (512)
  - max heads per cylinder: 0x10 (16)
  - max sectors per track: 0x3f (63)
.SH OPTIONS
.TP
.BI "-c=" N
Show decimal, binary and hex representation of positive integer \fIN\fR.
.TP
.BI "-f=" FORMAT
Convert CHS to LBA or LBA to CHS. \fIFORMAT\fR is hyphen-separated representation of LBA or CHS.

LBA: lLBA-MAX_HEAD-MAX_SECTOR (starts with 'l')
.br
CHS: cC-H-S-MAX_HEAD-MAX_SECTOR (starts with 'c')

Omitted values, (other than MAX_HEAD and MAX_SECTOR) are considered 0. Default MAX_HEAD: 16, default MAX_SECTOR: 63.
.TP
.BI "-s=" bytes
Sector size in bytes. Default value is 512.
.TP
.BI "-m"
Show minimal output (e.g. decimal bytes).
.TP
.BI "-d"
Enable debug information and logs.
.TP
.BI "-h"
Show program help and exit.
.SH EXAMPLES
.PP
.IP 1. 4
Evaluate arithmetic expression of storage units
.PP
.EX
.IP
.B $ bcal """(5kb+2mb)/3"""
.B $ bcal """5 tb / 12"""
.B $ bcal """2.5mb*3"""
.EE
.PP
.IP 2. 4
Convert storage capacity to other units and get address, LBA.
.PP
.EX
.IP
.B $ bcal 20140115 b
.B $ bcal 0x1335053 B
.B $ bcal 0xaabbcc kb
.B $ bcal 0xdef Gib
Note that the units are case-insensitive.
.EE
.PP
.IP 3. 4
Convert storage capacity, set sector size to 4096 to calculate LBA.
.PP
.EX
.IP
.B $ bcal 0xaabbcc kb -s 4096
.EE
.PP
.IP 4. 4
Convert LBA to CHS.
.PP
.EX
.IP
.B $ bcal -f l500
.B $ bcal -f l0x600-18-0x7e
.B $ bcal -f l0x300-0x12-0x7e
.EE
.PP
.IP 5. 4
Convert CHS to LBA.
.PP
.EX
.IP
.B $ bcal -f c10-10-10
.B $ bcal -f c0x10-0x10-0x10
.B $ bcal -f c0x10-10-2-0x12
.B $ bcal -f c-10-2-0x12
.B $ bcal -f c0x10-10--0x12
.EE
.PP
.IP 6. 4
Show binary, decimal and hex representations of a number.
.PP
.EX
.IP
.B $ bcal -c 20140115
.B $ bcal -c 0b1001100110101000001010011
.B $ bcal -c 0x1335053
.SH AUTHORS
Arun Prakash Jana <engineerarun@gmail.com>
.SH HOME
.I https://github.com/jarun/bcal
.SH REPORTING BUGS
.I https://github.com/jarun/bcal/issues
.SH LICENSE
Copyright \(co 2016-2017 Arun Prakash Jana <engineerarun@gmail.com>
.PP
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
.br
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.