Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am following a tutorial on few kernel dev. I encountered an operation where I have to use dd like

dd ... if=PBL.bin of=... count=block_number

The block_number variable is defined to be as

The HEX of ($filesize - 1)/512 + 1

where $filesize is the filesize of the input file PBL.bin as given in the dd command above.

How do I calculate this value? Thanks in advance

share|improve this question
1  
Note that dd also accepts decimal for count= as well. Also please include a link to the tutorial so we can see were this occurs. –  Dan D. Feb 5 at 9:11
1  
Make sure that you use signed integer arithmetic with that formula. (-: –  JdeBP Feb 5 at 11:31

1 Answer 1

up vote 2 down vote accepted

What about:

printf "%x" `stat -c "%b" PBL.bin`

printf will print in hex format (%x) the output from stat which requests just the number of blocks allocated (%b) of the file.

If you don't trust the number of blocks allocated as reported by stat then by hand:

printf "%x" $(( (`stat -c "%s" PBL.bin ` - 1) / 512 + 1))

So you get the filesize and then do the maths by hand

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.