[PATCH] olpc.fth - grow the root filesystem partition on boot

James Cameron quozl at laptop.org
Wed Mar 14 01:35:23 EDT 2012


Grows the second partition so that it takes up all remaining space on
the eMMC or microSD card.  Fix for #11690.  Part of #10040.

Costs 120ms.  (Use of a flag file costs 130ms).

Does not proceed if extra partitions are found.
---
Note: applies to XO-1.5, XO-1.75, and XO-3.

Note: resize2fs must be run by the operating system for the space to be
available to the user.
 olpc/olpc.fth |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/olpc/olpc.fth b/olpc/olpc.fth
index 368e3c5..cd3b723 100644
--- a/olpc/olpc.fth
+++ b/olpc/olpc.fth
@@ -72,6 +72,48 @@ false value enable-serial
 ;
 [then]
 
+warning @ warning off
+0 value mbr-ih
+warning !
+
+: get-size  ( -- size )  " size" mbr-ih $call-method d# 512 um/mod swap drop  ;
+
+h# 1be. 2value pt  \ device byte offset to start of partition table
+h# 10 value /pe    \ size of a partition entry
+/pe buffer: pe     \ partition entry buffer
+
+: pe-seek  ( d.pos -- )  " seek" mbr-ih $call-method drop  ;
+: pe-read  ( d.pos -- )  pe-seek  pe /pe " read" mbr-ih $call-method drop  ;
+: pe-write  ( d.pos -- )  pe-seek  pe /pe " write" mbr-ih $call-method drop  ;
+
+: pe-start@  ( pe -- start )  pe h# 08 + le-l@  ;
+: pe-length@  ( pe -- length )  pe h# 0c + le-l@  ;
+: pe-length!  ( length pe -- )  pe h# 0c + le-l!  ;
+
+: pe#>offset  ( n -- d.pos )  1- /pe * 0 pt d+  ;
+: pe-is-set?  ( pe# -- flag )  pe#>offset pe-read  pe-start@ pe-length@ or  ;
+
+\ expands the partition of the root filesystem to cover the remaining
+\ free space on the device.  costs 120ms on XO-1.75.
+: maximise  ( -- )
+   " last:0" open-dev  dup 0= abort" did not open device"
+   to mbr-ih                  ( )
+   4 pe-is-set?  abort" partition 4 is non-zero"
+   3 pe-is-set?  abort" partition 3 is non-zero"
+   get-size                   ( d-end )
+   2 pe#>offset pe-read       ( d-end )
+   pe-start@  dup >r          ( d-end p-start )  ( r: p-start )
+   pe-length@ + swap          ( p-end d-end )    ( r: p-start )
+   2dup > abort" partition ends beyond device size"
+   2dup < if                  ( p-end d-end )    ( r: p-start )
+      nip r> - pe-length!     ( )                ( r: )
+      2 pe#>offset pe-write   ( )                ( r: )
+   else                       ( p-end d-end )    ( r: p-start )
+      r> 3drop                ( )                ( r: )
+   then                       ( )                ( r: )
+   mbr-ih close-dev
+;
+
 : set-command-line  ( -- )
    button-check game-key?  enable-serial or  if
       " ttyS2 " " SP" $set-macro
@@ -107,4 +149,5 @@ false value enable-serial
    boot
 ;
 
+maximise
 olpc-fth-boot-me
-- 
1.7.5.4


-- 
James Cameron
http://quozl.linux.org.au/


More information about the Devel mailing list