diff mbox

[4/5] fs/custom: add support for squashfs

Message ID f19557ea778ede9bf0de8be578a2fdd6cdd1785c.1388768519.git.yann.morin.1998@free.fr
State Changes Requested
Headers show

Commit Message

Yann E. MORIN Jan. 3, 2014, 5:19 p.m. UTC
From: "Yann E. MORIN" <yann.morin.1998@free.fr>

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Ryan Barnett <rjbarnet@rockwellcollins.com>
---
 docs/manual/partition-layout.txt | 11 ++++++++++-
 fs/custom/fs/squashfs            | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 fs/custom/fs/squashfs

Comments

Maxime Hadjinlian Jan. 4, 2014, 4:43 p.m. UTC | #1
Hi Yann,

On Fri, Jan 3, 2014 at 6:19 PM, Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> From: "Yann E. MORIN" <yann.morin.1998@free.fr>
>
> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> Cc: Ryan Barnett <rjbarnet@rockwellcollins.com>
> ---
>  docs/manual/partition-layout.txt | 11 ++++++++++-
>  fs/custom/fs/squashfs            | 19 +++++++++++++++++++
>  2 files changed, 29 insertions(+), 1 deletion(-)
>  create mode 100644 fs/custom/fs/squashfs
>
> diff --git a/docs/manual/partition-layout.txt b/docs/manual/partition-layout.txt
> index 092ae1b..e9027bf 100644
> --- a/docs/manual/partition-layout.txt
> +++ b/docs/manual/partition-layout.txt
> @@ -133,7 +133,8 @@ Properties for +type=fs+
>
>  * +fs_type+ (mandatory): the type of filesystem to generate
>  ** +ext+: generate an extended filesystem (ext2, ext3, ext4)
> -** +vfat+: generate a VFAT filesystem (FAT16, FAT32)
> +** +squashfs+: generate a squashfs (version 4) filesystem
> +** +vfat+: generate a VFAT filesystem (FAT12, FAT16 or FAT32)
>
>  * +fs_label+ (optional): the label to assign to this filesystem, if that
>    filesystem supports a label
> @@ -177,6 +178,14 @@ Properties for +fs_type=ext+
>  ** +1+ (mandatory for ext3 or ext4): generate a revision 1 extended
>     filesystem
>
> +Properties for +fs_type=squashfs+
> +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> +* +squashfs_comp+ (mandatory): the compression type to use
> +** +gzip+, +xz+, +lzo+: gzip, xz or lzo compression
> +
> +* +squashfs_block+ (optional): the size of blocks, in bytes
> +
>  Properties for +fs_type=vfat+
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> diff --git a/fs/custom/fs/squashfs b/fs/custom/fs/squashfs
> new file mode 100644
> index 0000000..132d3ef
> --- /dev/null
> +++ b/fs/custom/fs/squashfs
> @@ -0,0 +1,19 @@
> +# Create a squashfs filesystem
> +
> +#-----------------------------------------------------------------------------
> +DEPENDS+=( squashfs )
> +
> +#-----------------------------------------------------------------------------
> +do_image() {
> +    local root_dir="${1}"
> +    local img="${2}"
> +    local -a fs_opts
> +
> +    fs_opts+=( -no-progress -noappend )
> +    [ -z "${squashfs_comp}"  ] || fs_opts+=( -comp "${squashfs_comp}" )
It just a question of taste, but I really do prefer to read something like:
[ -n "${squashfs_comp}"  ] && fs_opts+=( -comp "${squashfs_comp}" )
But that's just a personal taste.
> +    [ -z "${squashfs_block}" ] || fs_opts+=( -b ${squahsfs_block} )
> +
> +    mksquashfs "${root_dir}" "${img}" "${fs_opts[@]}" >/dev/null
> +}
> +
> +# vim: ft=sh
> --
> 1.8.1.2
>
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

Thanks !
Yann E. MORIN Jan. 4, 2014, 5:01 p.m. UTC | #2
Maxime, All,

Thanks for the review! :-)

On 2014-01-04 17:43 +0100, Maxime Hadjinlian spake thusly:
> On Fri, Jan 3, 2014 at 6:19 PM, Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> > From: "Yann E. MORIN" <yann.morin.1998@free.fr>
> >
> > Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> > Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> > Cc: Ryan Barnett <rjbarnet@rockwellcollins.com>
> > ---
> >  docs/manual/partition-layout.txt | 11 ++++++++++-
> >  fs/custom/fs/squashfs            | 19 +++++++++++++++++++
> >  2 files changed, 29 insertions(+), 1 deletion(-)
> >  create mode 100644 fs/custom/fs/squashfs
> >
[--SNIP--]
> > diff --git a/fs/custom/fs/squashfs b/fs/custom/fs/squashfs
> > new file mode 100644
> > index 0000000..132d3ef
> > --- /dev/null
> > +++ b/fs/custom/fs/squashfs
> > @@ -0,0 +1,19 @@
> > +# Create a squashfs filesystem
> > +
> > +#-----------------------------------------------------------------------------
> > +DEPENDS+=( squashfs )
> > +
> > +#-----------------------------------------------------------------------------
> > +do_image() {
> > +    local root_dir="${1}"
> > +    local img="${2}"
> > +    local -a fs_opts
> > +
> > +    fs_opts+=( -no-progress -noappend )
> > +    [ -z "${squashfs_comp}"  ] || fs_opts+=( -comp "${squashfs_comp}" )
> It just a question of taste, but I really do prefer to read something like:
> [ -n "${squashfs_comp}"  ] && fs_opts+=( -comp "${squashfs_comp}" )
> But that's just a personal taste.

The genimages script runs with 'set -e -E', which means to exit as soon
as one command exits with a !0 exit code.

If we do as you suggested:
    [ -n "${squashfs_comp}"  ] && fs_opts+=( -comp "${squashfs_comp}" )

and "${squashfs_comp}" is empty, then the test is false, and the whole
list also is false, which amkes the shell error out.

If we do the way I did:
    [ -z "${squashfs_comp}"  ] || fs_opts+=( -comp "${squashfs_comp}" )

then it ensures that the list is never false, and thus there is no
error.

If this construct is not welcome, then we have to use if...fi blocks
instead:
    if [ -n "${squashfs_comp}" ]; then
        fs_opts+=( -comp "${squashfs_comp}" )
    fi

This is a bit more verbose, but maybe more explicit. I prefer concise,
since I know why it is written this way, but I don't really care.

Regards,
Yann E. MORIN.
diff mbox

Patch

diff --git a/docs/manual/partition-layout.txt b/docs/manual/partition-layout.txt
index 092ae1b..e9027bf 100644
--- a/docs/manual/partition-layout.txt
+++ b/docs/manual/partition-layout.txt
@@ -133,7 +133,8 @@  Properties for +type=fs+
 
 * +fs_type+ (mandatory): the type of filesystem to generate
 ** +ext+: generate an extended filesystem (ext2, ext3, ext4)
-** +vfat+: generate a VFAT filesystem (FAT16, FAT32)
+** +squashfs+: generate a squashfs (version 4) filesystem
+** +vfat+: generate a VFAT filesystem (FAT12, FAT16 or FAT32)
 
 * +fs_label+ (optional): the label to assign to this filesystem, if that
   filesystem supports a label
@@ -177,6 +178,14 @@  Properties for +fs_type=ext+
 ** +1+ (mandatory for ext3 or ext4): generate a revision 1 extended
    filesystem
 
+Properties for +fs_type=squashfs+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+* +squashfs_comp+ (mandatory): the compression type to use
+** +gzip+, +xz+, +lzo+: gzip, xz or lzo compression
+
+* +squashfs_block+ (optional): the size of blocks, in bytes
+
 Properties for +fs_type=vfat+
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
diff --git a/fs/custom/fs/squashfs b/fs/custom/fs/squashfs
new file mode 100644
index 0000000..132d3ef
--- /dev/null
+++ b/fs/custom/fs/squashfs
@@ -0,0 +1,19 @@ 
+# Create a squashfs filesystem
+
+#-----------------------------------------------------------------------------
+DEPENDS+=( squashfs )
+
+#-----------------------------------------------------------------------------
+do_image() {
+    local root_dir="${1}"
+    local img="${2}"
+    local -a fs_opts
+
+    fs_opts+=( -no-progress -noappend )
+    [ -z "${squashfs_comp}"  ] || fs_opts+=( -comp "${squashfs_comp}" )
+    [ -z "${squashfs_block}" ] || fs_opts+=( -b ${squahsfs_block} )
+
+    mksquashfs "${root_dir}" "${img}" "${fs_opts[@]}" >/dev/null
+}
+
+# vim: ft=sh