mkfs: reserve x2 sections

This is due to GC on data sections.
When a data section is cleaned, it produces maximum same number of dirty node
blocks additionally.
So, we should reserve x2 sections to flush dirty node blocks safely.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
build: add description of prerequisite to build

Let's check two more packages before building f2fs-tools.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
build: move f2fs_format.h to ../include/f2fs_fs.h

This is to use f2fs.h globally, which will be used by other tools such as
fsck.f2fs.

Siged-mff-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
build: sync f2fs_fs.h with current f2fs sources

Rearrange positions of all the data structures for easy synchronization between
f2fs-tools and f2fs kernel sources.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
build: make several base functions as a library

Let's make a library and relocate functions for other tools like fsck.f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
build: clean up the base functions

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
build: compile static by default

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
build: change f2fs_fs.h

Let's sync f2fs_fs.h in the kernel source tree.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
build: revert "Compile static by default"

By default, we should use dynamic linking.
If anyone need to build 100% statically, add -all-static.

This reverts commit 2eb19102d4c5bec57c04c944ee697584a493ef9c.
mkfs: fix to avoid format of device when already mounted

In case of embedded devices, where /etc/ is mounted as 'read-only'.
We donot have the /etc/mtab file. So, checking if the device is already
mounted from this file is not sufficient.
Try to read /proc/mounts in case of failure from /etc/mtab.

Issue logs:
/dev/sdb4 /mnt vfat rw,relatime,fmask=0022,dmask=0022,codepage=cp437,
iocharset=ascii,errors=remount-ro 0 0

Here device - sb4 is already mounted.
But, when trying to format using mkfs.f2fs

F2FS-tools: Ver: 1.1.0 (2013-01-14)
Info: sector size = 512
Info: total sectors = 13108784 (in 512bytes)
WARN: Align start sector number in a unit of pages
        i.e., start sector: 2542124, ofs:4 (sectors per page: 8)
Info: zone aligned segment0 blkaddr: 186
Info: This device doesn't support TRIM
Info: format successful

After Change:

F2FS-tools: Ver: 1.1.0 (2013-01-14)
Error: /dev/sdb4 is already mounted

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
mkfs: default to blank label

Signed-off-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
mkfs: handle labels longer than 16 characters

Mkfs copies labels up to 512 characters into a the 16 character buffer
config.vol_label corrupting memory afterwards and causing a core dump.

    # mkfs.f2fs -l aaaaaaaaaabbbbbbbbbbcccccccccc /dev/sda12

            F2FS-tools: mkfs.f2fs Ver: 1.1.0 (2013-03-08)

    Info: Label = aaaaaaaaaabbbbbbbbbbcccccccccc
    Info: sector size = 512
    Info: total sectors = 2097152 (in 512bytes)
    Info: zone aligned segment0 blkaddr: 256
    Segmentation fault (core dumped)

Make config.vol_label a pointer to the label in argv, rather than
copying it into a too small buffer.

Signed-off-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
mkfs: add option to disable trim at format

This patch adds an option to disable trim command at format.
Default operation sends trim command to device.

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>