* [Buildroot] [git commit master 1/1] genext2fs.sh: improve number of blocks calculation
@ 2010-12-30 22:10 Peter Korsgaard
2010-12-30 22:31 ` Yann E. MORIN
0 siblings, 1 reply; 3+ messages in thread
From: Peter Korsgaard @ 2010-12-30 22:10 UTC (permalink / raw)
To: buildroot
commit: http://git.buildroot.net/buildroot/commit/?id=eeea3ea6a88a8f1c7511abf0b429297a562e7d30
branch: http://git.buildroot.net/buildroot/commit/?id=refs/heads/master
Closes #2929
Instead of just adding a fixed amount to the blocks used, try to
estimate the real space needed according to the filesystem structure
(bitmaps, inodes, blocks).
The side effect of this is that we no longer significantly overestimate
the size needed for small file systems.
Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
---
CHANGES | 1 +
fs/ext2/genext2fs.sh | 25 +++++++++++--------------
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/CHANGES b/CHANGES
index 4fef0eb..a67d1d1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,7 @@
#1735: [PATCH] mplayer: convert to autotools infrastructure
#2371: QT MYSQL Module does not build when MySQL installed on the host
#2905: Qt: Speed up compilation, if gui-module isn't selected
+ #2929: genext2fs: couldn't allocate a block (no free space)
#2965: Broken linkage to xkbcomp (blocking X server startup)
#2983: xlib_libX11 build failed
diff --git a/fs/ext2/genext2fs.sh b/fs/ext2/genext2fs.sh
index b315ec3..7a518ae 100755
--- a/fs/ext2/genext2fs.sh
+++ b/fs/ext2/genext2fs.sh
@@ -10,24 +10,11 @@ while getopts x:d:D:b:i:N:m:g:e:zfqUPhVv f
do
case $f in
b) CALC_BLOCKS=0 ;;
- N) CALC_INODES=0 ;;
+ N) CALC_INODES=0; INODES=$OPTARG ;;
d) TARGET_DIR=$OPTARG ;;
esac
done
-# calculate needed blocks
-if [ $CALC_BLOCKS -eq 1 ];
-then
- BLOCKS=$(du -s -c -k $TARGET_DIR | grep total | sed -e "s/total//")
- if [ $BLOCKS -ge 20000 ];
- then
- BLOCKS=$(expr $BLOCKS + 16384)
- else
- BLOCKS=$(expr $BLOCKS + 2400)
- fi
- set -- $@ -b $BLOCKS
-fi
-
# calculate needed inodes
if [ $CALC_INODES -eq 1 ];
then
@@ -36,4 +23,14 @@ then
set -- $@ -N $INODES
fi
+# calculate needed blocks
+if [ $CALC_BLOCKS -eq 1 ];
+then
+ # size ~= superblock, block+inode bitmaps, inodes (8 per block), blocks
+ # we scale inodes / blocks with 10% to compensate for bitmaps size + slack
+ BLOCKS=$(du -s -c -k $TARGET_DIR | grep total | sed -e "s/total//")
+ BLOCKS=$(expr 500 + \( $BLOCKS + $INODES / 8 \) \* 11 / 10)
+ set -- $@ -b $BLOCKS
+fi
+
exec genext2fs $@
--
1.7.2.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* [Buildroot] [git commit master 1/1] genext2fs.sh: improve number of blocks calculation
2010-12-30 22:10 [Buildroot] [git commit master 1/1] genext2fs.sh: improve number of blocks calculation Peter Korsgaard
@ 2010-12-30 22:31 ` Yann E. MORIN
2010-12-30 22:40 ` Peter Korsgaard
0 siblings, 1 reply; 3+ messages in thread
From: Yann E. MORIN @ 2010-12-30 22:31 UTC (permalink / raw)
To: buildroot
Peter, All,
On Thursday 30 December 2010 23:10:21 Peter Korsgaard wrote:
> + BLOCKS=$(expr 500 + \( $BLOCKS + $INODES / 8 \) \* 11 / 10)
POSIX specifies that you can do arithmetics in the shell:
2.6.4 Arithmetic Expansion
Arithmetic expansion provides a mechanism for evaluating an arithmetic
expression and substituting its value. The format for arithmetic expansion
shall be as follows:
$((expression))
You do even need to do variable expansion, it's implicit when doing
arithmetics expansion:
If the shell variable x contains a value that forms a valid integer
constant, then the arithmetic expansions "$((x))" and "$(($x))" shall
return the same value.
So I'd write that as:
BLOCKS=$(( 500 + (BLOCKS+INODES/8) * 11 / 10 ))
Much more readable, IMHO.
Regards,
Yann E. MORIN.
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Buildroot] [git commit master 1/1] genext2fs.sh: improve number of blocks calculation
2010-12-30 22:31 ` Yann E. MORIN
@ 2010-12-30 22:40 ` Peter Korsgaard
0 siblings, 0 replies; 3+ messages in thread
From: Peter Korsgaard @ 2010-12-30 22:40 UTC (permalink / raw)
To: buildroot
>>>>> "Yann" == Yann E MORIN <yann.morin.1998@anciens.enib.fr> writes:
Yann> Peter, All,
Yann> On Thursday 30 December 2010 23:10:21 Peter Korsgaard wrote:
>> + BLOCKS=$(expr 500 + \( $BLOCKS + $INODES / 8 \) \* 11 / 10)
Yann> POSIX specifies that you can do arithmetics in the shell:
Yann> So I'd write that as:
Yann> BLOCKS=$(( 500 + (BLOCKS+INODES/8) * 11 / 10 ))
True. I kept it with expr as that's what the rest of the file was doing,
and I didn't find it too bad regarding readability.
--
Bye, Peter Korsgaard
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-12-30 22:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-30 22:10 [Buildroot] [git commit master 1/1] genext2fs.sh: improve number of blocks calculation Peter Korsgaard
2010-12-30 22:31 ` Yann E. MORIN
2010-12-30 22:40 ` Peter Korsgaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox