On Mon, Nov 3, 2014 at 6:25 AM, Chris Ruehl <[email protected]> wrote:
> Hi,
>
> I was in need to have f2fs support in busybox.
> This patchset based on f2fs-tools commit
> 056e4b04fc44a006d5529bafbf87b1d73296c665
>
> [Patch v1.1][f2fs] add build support
> [Patch v1.2][f2fs] add libs header
> [Patch v1.3][f2fs] add libs c-files
>
> Please feel free to use it.

It needs a lot of work to get into a good shape.
Here are the things which need changing:

+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+#include <time.h>
+#include "libbb.h"

libbb.h includes most of the typical standard headers.
Do not include them again.

+extern struct f2fs_configuration config;
+struct f2fs_super_block super_block;

Global data enlarges bbox's data and bss.
Rework code to not use them unless there is a very good reason
for having them.

+const char *media_ext_lists[] = {
+       "jpg",
+       "gif",
+       "png",
...
};
+       while (*extlist) {
+               name_len = strlen(*extlist);
+               memcpy(super_block.extension_list[i++], *extlist, name_len);
+               extlist++;
+       }

This code is very inefficient.

+       err = f2fs_init_sit_area();
+       if (err < 0) {
+               MSG(0, "\tError: Failed to Initialise the SIT AREA!!!\n");
+               goto exit;
+       }

With fatal errors (most mkfs errors are), don't bother propagating
them to callers. Just bb_error_msg_and_die("concise error msg").

+static void mkfs_usage(void)
+{
+       MSG(0, "\nUsage: mkfs.f2fs [options] device [sectors]\n");
+       MSG(0, "[options]:\n");
+       MSG(0, "  -a heap-based allocation [default:1]\n");
+       MSG(0, "  -d debug level [default:0]\n");
+       MSG(0, "  -e [extension list] e.g. \"mp3,gif,mov\"\n");
+       MSG(0, "  -l label\n");
+       MSG(0, "  -o overprovision ratio [default:5]\n");
+       MSG(0, "  -s # of segments per section [default:1]\n");
+       MSG(0, "  -z # of sections per zone [default:1]\n");
+       MSG(0, "  -t 0: nodiscard, 1: discard [default:1]\n");
+       MSG(0, "sectors: number of sectors. [default: determined by
device size]\n");
+       exit(1);
+}

Code duplication. Use bb_show_usage() instead.

+       while ((option = getopt(argc,argv,option_string)) != EOF) {
+               switch (option) {
+               case 'a':

Try to port this to getopt32() - see examples in other applets.

+       if (fstat(config.fd, &stat_buf) < 0 ) {
+               MSG(1, "\tError: Failed to get the device stat!!!\n");
+               return -1;
+       }

Use xfstat()

+static const int bits_in_byte[256] = {
+       0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
+       1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
+       1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
+       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+       1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
+       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+       3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
+       1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
+       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+       3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
+       2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
+       3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
+       3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
+       4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
+};
+
+int get_bits_in_byte(unsigned char n)
+{
+       return bits_in_byte[n];
+}

This results in more than a kilobyte of .text segment.
Please try to do better.
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to