Skip to contentSkip to conversation

Addition of btrfs to u-boot

PATCH New Adnan Ali 2 participants 6 messages Mar 11, 2013 – Mar 13, 2013

Subsystems (3)
lore
Share & tools
lore

Adnan Ali

author
#0 lore raw

PATCH v5 1/1 Addition of btrfs to u-boot

Adnan Ali (1):
Introduced btrfs file-system with btrload command

 Makefile                   |    1 +
 common/Makefile            |    1 +
 common/cmd_btr.c           |   65 +++
 fs/btrfs/Makefile          |   51 ++
 fs/btrfs/btrfs.c           | 1348 ++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/crc32_c.c         |   54 ++
 fs/fs.c                    |   10 +
 include/btrfs.h            |  416 ++++++++++++++
 include/config_fallbacks.h |    4 +
 include/fs.h               |    1 +
 10 files changed, 1951 insertions(+)
 create mode 100644 common/cmd_btr.c
 create mode 100644 fs/btrfs/Makefile
 create mode 100644 fs/btrfs/btrfs.c
 create mode 100644 fs/btrfs/crc32_c.c
 create mode 100644 include/btrfs.h
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v5 1/1 Introduced btrfs file-system with btrload command

Introduces btrfs file-system to read file from volume/sub-volumes with btrload command. This implementation has read-only support.
This btrfs implementation is based on syslinux btrfs code, commit 269ebc845ebc8b46ef4b0be7fa0005c7fdb95b8d.

v5:     merged with master.
v4:     btrls command added.
v3:     patch re-formated.
v2:     patch error removed.
---
 Makefile                   |    1 +
 common/Makefile            |    1 +
 common/cmd_btr.c           |   65 +++
 fs/btrfs/Makefile          |   51 ++
 fs/btrfs/btrfs.c           | 1348 ++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/crc32_c.c         |   54 ++
 fs/fs.c                    |   10 +
 include/btrfs.h            |  416 ++++++++++++++
 include/config_fallbacks.h |    4 +
 include/fs.h               |    1 +
 10 files changed, 1951 insertions(+)
 create mode 100644 common/cmd_btr.c
 create mode 100644 fs/btrfs/Makefile
 create mode 100644 fs/btrfs/btrfs.c
 create mode 100644 fs/btrfs/crc32_c.c
 create mode 100644 include/btrfs.h
Makefile +1 -0
index 55bd55c..b3da594 100644
@@ -257,6 +257,7 @@ endif
 LIBS-$(CONFIG_OF_EMBED) += dts/libdts.o
 LIBS-y += arch/$(ARCH)/lib/lib$(ARCH).o
 LIBS-y += fs/libfs.o \
+        fs/btrfs/libbtrfs.o \
 	fs/cbfs/libcbfs.o \
 	fs/cramfs/libcramfs.o \
 	fs/ext4/libext4fs.o \
common/Makefile +1 -0
index 719fc23..d1fae56 100644
@@ -73,6 +73,7 @@ COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o
 COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o
 COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o
 COBJS-$(CONFIG_CMD_BOOTSTAGE) += cmd_bootstage.o
+COBJS-$(CONFIG_CMD_BTR) += cmd_btr.o
 COBJS-$(CONFIG_CMD_CACHE) += cmd_cache.o
 COBJS-$(CONFIG_CMD_CBFS) += cmd_cbfs.o
 COBJS-$(CONFIG_CMD_CONSOLE) += cmd_console.o
common/cmd_btr.c new file +65 -0

65 lines not on this page · raw message

fs/btrfs/Makefile new file +51 -0

51 lines not on this page · raw message

fs/btrfs/btrfs.c new file +1348 -0

1,348 lines not on this page · raw message

fs/btrfs/crc32_c.c new file +54 -0

54 lines not on this page · raw message

fs/fs.c +10 -0
index 6f5063c..58b155c 100644
@@ -17,6 +17,7 @@
 #include <config.h>
 #include <common.h>
 #include <part.h>
+#include <btrfs.h>
 #include <ext4fs.h>
 #include <fat.h>
 #include <fs.h>
@@ -88,6 +89,15 @@ static struct fstype_info fstypes[] = {
 		.read = fs_read_sandbox,
 	},
 #endif
+#ifdef CONFIG_FS_BTR
+        {
+                .fstype = FS_TYPE_BTR,
+                .probe = btrfs_probe,
+                .close = btrfs_close,
+                .ls = btrfs_ls,
+                .read = btrfs_read_file,
+        },
+#endif
 	{
 		.fstype = FS_TYPE_ANY,
 		.probe = fs_probe_unsupported,
include/btrfs.h new file +416 -0

416 lines not on this page · raw message

include/config_fallbacks.h +4 -0
index bfb9680..28a0a66 100644
@@ -26,4 +26,8 @@
 #define CONFIG_EXT4_WRITE
 #endif
 
+#if defined(CONFIG_CMD_BTR) && !defined(CONFIG_FS_BTR)
+#define CONFIG_FS_BTR
+#endif
+
 #endif	/* __CONFIG_FALLBACKS_H */
include/fs.h +1 -0
index b6d69e5..a8b97ea 100644
@@ -22,6 +22,7 @@
 #define FS_TYPE_FAT	1
 #define FS_TYPE_EXT	2
 #define FS_TYPE_SANDBOX	3
+#define FS_TYPE_BTR	4
 
 /*
  * Tell the fs layer which block device an partition to use for future
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v5 1/1 Introduced btrfs file-system with btrload command

Hi Adnan,

Quoted 21 lines · Adnan Ali

Introduces btrfs file-system to read file from volume/sub-volumes with btrload command. This implementation has read-only support.
This btrfs implementation is based on syslinux btrfs code, commit 269ebc845ebc8b46ef4b0be7fa0005c7fdb95b8d.

v5:     merged with master.
v4:     btrls command added.
v3:     patch re-formated.
v2:     patch error removed.
---
 Makefile                   |    1 +
 common/Makefile            |    1 +
 common/cmd_btr.c           |   65 +++
 fs/btrfs/Makefile          |   51 ++
 fs/btrfs/btrfs.c           | 1348 ++++++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/crc32_c.c         |   54 ++
 fs/fs.c                    |   10 +
 include/btrfs.h            |  416 ++++++++++++++
Quoted 9 lines
 include/config_fallbacks.h |    4 +
 include/fs.h               |    1 +
 10 files changed, 1951 insertions(+)
 create mode 100644 common/cmd_btr.c
 create mode 100644 fs/btrfs/Makefile
 create mode 100644 fs/btrfs/btrfs.c
 create mode 100644 fs/btrfs/crc32_c.c
 create mode 100644 include/btrfs.h

I have ignored the code before this point in btrfs.c since it is imported and you want to keep the code style as is, but if you don't mind I will make a few comments after that point>

Quoted 4 lines
fs/btrfs/btrfs.c new file +4 -0
+struct btrfs_info fs;
+
+/*
+ *  mount btrfs file-system

fs/btrfs/btrfs.c line 1281

Quoted 10 lines
fs/btrfs/btrfs.c new file +10 -0
+ */
+int btrfs_probe(block_dev_desc_t *rbdd, disk_partition_t *info)
+{
+        btrfs_block_dev_desc = rbdd;
+        part_info = info;
+        btr_part_offset = info->start;
+       if (btrfs_fs_init(&fs) < 0 ) {
+          debug("btrfs probe failed\n");
+          return -1;
+       }

You should use tabs for intend (some of this bit uses spaces, some uses tabs).

Quoted 46 lines
fs/btrfs/btrfs.c new file +46 -0
+
+       return 0;
+}
+
+/*
+ *  Read file data
+ */
+int btrfs_read_file(const char *filename, void *buf, int offset, int len)
+{
+       int file_len=0;
+        int len_read;
+        struct com32_filedata filedata;
+        int handle;
+        if (offset != 0) {
+                debug("** Cannot support non-zero offset **\n");
+                return -1;
+        }
+
+        handle=btrfs_open_file(filename, &filedata);
+        if (handle < 0) {
+                debug("** File not found %s Invalid handle**\n", filename);
+                return -1;
+        }
+
+        /*file handle is valid get the size of the file*/
+        len = filedata.size;
+        if (len == 0)
+                len = file_len;
+
+        len_read = getfssec(&filedata, (char *)buf);
+        if (len_read != len) {
+                debug("** Unable to read file %s **\n", filename);
+                return -1;
+        }
+
+        return len_read;
+
+}
+
+/*
+ * Show directory entries
+ */
+char btrfs_ls(char *dirname)
+{
+  struct btrfs_dirent *de;
+  struct _DIR_ *dir;

fs/btrfs/btrfs.c line 1337

Quoted 10 lines
fs/btrfs/btrfs.c new file +10 -0
+
+  if(*dirname == '/' && *(dirname+1) == 0)
+     *dirname = '.';
+
+  dir = opendir(dirname);
+  if (dir == NULL)
+        return -1;
+
+  while ((de = readdir(dir)) != NULL)
+        ;

This doesn't seem to print anything.

fs/btrfs/btrfs.c line 1347

Quoted 10 lines
fs/btrfs/btrfs.c new file +10 -0
+
+  return 0;
+}
+
+/*
+ *  umount btrfs file-system
+ */
+void btrfs_close(void)
+{
+

Remove blank line

Quoted 17 lines
(quoted diff) +1 -0
+}
fs/btrfs/crc32_c.c new file +10 -0
new file mode 100644
index 0000000..78d0447
@@ -0,0 +1,54 @@
+/*
+ * Copied from Linux kernel crypto/crc32c.c
+ * Copyright (c) 2004 Cisco Systems, Inc.
+ * Copyright (c) 2008 Herbert Xu <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *

fs/btrfs/crc32_c.c line 20

Quoted 10 lines
fs/btrfs/crc32_c.c new file +10 -0
+ */
+
+/*
+ * This is the CRC-32C table
+ * Generated with:
+ * width = 32 bits
+ * poly = 0x1EDC6F41
+ * reflect input bytes = true
+ * reflect output bytes = true
+ */

Old comment?

Quoted 11 lines
fs/btrfs/crc32_c.c new file +11 -0
+
+/*
+ * Steps through buffer one byte at at time, calculates reflected
+ * crc using table.
+ */
+#include <linux/stat.h>
+#include <command.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+#include <common.h>
+#include <config.h>

fs/btrfs/crc32_c.c line 41

Quoted 10 lines
fs/btrfs/crc32_c.c new file +10 -0
+
+inline u32 crc32c_cal(u32 crc, const char *data, size_t length, u32 *crc32c_table)
+{
+       while (length--)
+               crc = crc32c_table[(u8)(crc ^ *data++)] ^ (crc >> 8);
+
+       return crc;
+}
+
+inline void crc32c_init(u32 *crc32c_table, u32 pol)

The 'inline' isn't needed.

fs/btrfs/crc32_c.c line 49

Quoted 8 lines
fs/btrfs/crc32_c.c new file +8 -0
+{
+       int i, j;
+       u32 v;
+       const u32 poly = pol; /* Bit-reflected CRC32C polynomial */
+
+       for (i = 0; i < 256; i++) {
+               v = i;
+               for (j = 0; j < 8; j++) {

Can remove this inner {} since you only have one line of code.

fs/btrfs/crc32_c.c line 54

Quoted 5 lines
fs/btrfs/crc32_c.c new file +5 -0
+                       v = (v >> 1) ^ ((v & 1) ? poly : 0);
+               }
+               crc32c_table[i] = v;
+       }
+}

I suggest you move your crc_32.c file to lib/ since it might be more generally useful. You should probably include the function prototypes in include/crc.h.

Also you seem to recalculate the crc table on every operation. Is is possible to only do this ones on startup?

Regards,
Simon

author
#3 lore raw

PATCH v5 1/1 Introduced btrfs file-system with btrload command

Hi

Quoted 33 lines · Simon Glass

Hi Adnan,

Quoted 24 lines · Adnan Ali

Introduces btrfs file-system to read file from volume/sub-volumes with btrload command. This implementation has read-only support.
This btrfs implementation is based on syslinux btrfs code, commit 269ebc845ebc8b46ef4b0be7fa0005c7fdb95b8d.

v5:     merged with master.
v4:     btrls command added.
v3:     patch re-formated.
v2:     patch error removed.
---
  Makefile                   |    1 +
  common/Makefile            |    1 +
  common/cmd_btr.c           |   65 +++
  fs/btrfs/Makefile          |   51 ++
  fs/btrfs/btrfs.c           | 1348 ++++++++++++++++++++++++++++++++++++++++++++
  fs/btrfs/crc32_c.c         |   54 ++
  fs/fs.c                    |   10 +
  include/btrfs.h            |  416 ++++++++++++++
  include/config_fallbacks.h |    4 +
  include/fs.h               |    1 +
  10 files changed, 1951 insertions(+)
Quoted 6 lines

create mode 100644 common/cmd_btr.c
create mode 100644 fs/btrfs/Makefile
create mode 100644 fs/btrfs/btrfs.c
create mode 100644 fs/btrfs/crc32_c.c
create mode 100644 include/btrfs.h

Quoted 3 lines

I have ignored the code before this point in btrfs.c since it is imported and you want to keep the code style as is, but if you don't mind I will make a few comments after that point>

Here are my comments

Quoted 16 lines
Quoted 5 lines
fs/btrfs/btrfs.c new file +4 -0
+struct btrfs_info fs;
+
+/*
+ *  mount btrfs file-system

fs/btrfs/btrfs.c line 1281

Quoted 10 lines
fs/btrfs/btrfs.c new file +10 -0
+ */
+int btrfs_probe(block_dev_desc_t *rbdd, disk_partition_t *info)
+{
+        btrfs_block_dev_desc = rbdd;
+        part_info = info;
+        btr_part_offset = info->start;
+       if (btrfs_fs_init(&fs) < 0 ) {
+          debug("btrfs probe failed\n");
+          return -1;
+       }

You should use tabs for intend (some of this bit uses spaces, some uses tabs).

Some how i missed will check it again. Ack

Quoted 50 lines
Quoted 50 lines
fs/btrfs/btrfs.c new file +49 -0
+
+       return 0;
+}
+
+/*
+ *  Read file data
+ */
+int btrfs_read_file(const char *filename, void *buf, int offset, int len)
+{
+       int file_len=0;
+        int len_read;
+        struct com32_filedata filedata;
+        int handle;
+        if (offset != 0) {
+                debug("** Cannot support non-zero offset **\n");
+                return -1;
+        }
+
+        handle=btrfs_open_file(filename, &filedata);
+        if (handle < 0) {
+                debug("** File not found %s Invalid handle**\n", filename);
+                return -1;
+        }
+
+        /*file handle is valid get the size of the file*/
+        len = filedata.size;
+        if (len == 0)
+                len = file_len;
+
+        len_read = getfssec(&filedata, (char *)buf);
+        if (len_read != len) {
+                debug("** Unable to read file %s **\n", filename);
+                return -1;
+        }
+
+        return len_read;
+
+}
+
+/*
+ * Show directory entries
+ */
+char btrfs_ls(char *dirname)
+{
+  struct btrfs_dirent *de;
+  struct _DIR_ *dir;
+
+  if(*dirname == '/' && *(dirname+1) == 0)
+     *dirname = '.';
Quoted 8 lines

fs/btrfs/btrfs.c line 1337

Quoted 7 lines
fs/btrfs/btrfs.c new file +7 -0
+
+  dir = opendir(dirname);
+  if (dir == NULL)
+        return -1;
+
+  while ((de = readdir(dir)) != NULL)
+        ;

This doesn't seem to print anything.

      readdir->btrfs_read, prints contents on media.
Quoted 12 lines

fs/btrfs/btrfs.c line 1347

Quoted 11 lines
fs/btrfs/btrfs.c new file +10 -0
+
+  return 0;
+}
+
+/*
+ *  umount btrfs file-system
+ */
+void btrfs_close(void)
+{
+

Remove blank line

Ack

Quoted 21 lines
Quoted 21 lines
(quoted diff) +1 -0
+}
fs/btrfs/crc32_c.c new file +13 -0
new file mode 100644
index 0000000..78d0447
@@ -0,0 +1,54 @@
+/*
+ * Copied from Linux kernel crypto/crc32c.c
+ * Copyright (c) 2004 Cisco Systems, Inc.
+ * Copyright (c) 2008 Herbert Xu <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+
+/*
Quoted 8 lines

fs/btrfs/crc32_c.c line 20

Quoted 7 lines
fs/btrfs/crc32_c.c new file +7 -0
+ * This is the CRC-32C table
+ * Generated with:
+ * width = 32 bits
+ * poly = 0x1EDC6F41
+ * reflect input bytes = true
+ * reflect output bytes = true
+ */

Old comment?

this crc was part of port

Quoted 15 lines
Quoted 15 lines
fs/btrfs/crc32_c.c new file +14 -0
+
+/*
+ * Steps through buffer one byte at at time, calculates reflected
+ * crc using table.
+ */
+#include <linux/stat.h>
+#include <command.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+#include <common.h>
+#include <config.h>
+
+inline u32 crc32c_cal(u32 crc, const char *data, size_t length, u32 *crc32c_table)
+{
Quoted 8 lines

fs/btrfs/crc32_c.c line 41

Quoted 7 lines
fs/btrfs/crc32_c.c new file +7 -0
+       while (length--)
+               crc = crc32c_table[(u8)(crc ^ *data++)] ^ (crc >> 8);
+
+       return crc;
+}
+
+inline void crc32c_init(u32 *crc32c_table, u32 pol)

The 'inline' isn't needed.

Ack

Quoted 10 lines

fs/btrfs/crc32_c.c line 49

Quoted 9 lines
fs/btrfs/crc32_c.c new file +8 -0
+{
+       int i, j;
+       u32 v;
+       const u32 poly = pol; /* Bit-reflected CRC32C polynomial */
+
+       for (i = 0; i < 256; i++) {
+               v = i;
+               for (j = 0; j < 8; j++) {

Can remove this inner {} since you only have one line of code.

Ack

Quoted 8 lines

fs/btrfs/crc32_c.c line 54

Quoted 5 lines
fs/btrfs/crc32_c.c new file +5 -0
+                       v = (v >> 1) ^ ((v & 1) ? poly : 0);
+               }
+               crc32c_table[i] = v;
+       }
+}

I suggest you move your crc_32.c file to lib/ since it might be more generally useful. You should probably include the function prototypes in include/crc.h.

The crc32_c.c was part of port as header file and you previously said
to move to btrfs folder and make it c file.

Quoted 2 lines

Also you seem to recalculate the crc table on every operation. Is is possible to only do this ones on startup?

Yes every time prob is called its calculated. It can be calculated at
boot time. Can you point me to file and function that it can be called. before that can we make decision on crc32_c.c.

Plus once i make all these changes will it be accepted than ;).

Quoted 3 lines

Regards,
Simon

Regards
Adnan

#4 lore raw

PATCH v5 1/1 Introduced btrfs file-system with btrload command

Hi Adnan,

Quoted 239 lines · Adnan Ali

Hi

Quoted 37 lines · Simon Glass

Hi Adnan,

Quoted 26 lines · Adnan Ali

Introduces btrfs file-system to read file from volume/sub-volumes with btrload command. This implementation has read-only support.
This btrfs implementation is based on syslinux btrfs code, commit 269ebc845ebc8b46ef4b0be7fa0005c7fdb95b8d.

v5:     merged with master.
v4:     btrls command added.
v3:     patch re-formated.
v2:     patch error removed.
---
  Makefile                   |    1 +
  common/Makefile            |    1 +
  common/cmd_btr.c           |   65 +++
  fs/btrfs/Makefile          |   51 ++
  fs/btrfs/btrfs.c           | 1348
++++++++++++++++++++++++++++++++++++++++++++
  fs/btrfs/crc32_c.c         |   54 ++
  fs/fs.c                    |   10 +
  include/btrfs.h            |  416 ++++++++++++++
  include/config_fallbacks.h |    4 +
  include/fs.h               |    1 +
  10 files changed, 1951 insertions(+)
Quoted 6 lines

create mode 100644 common/cmd_btr.c
create mode 100644 fs/btrfs/Makefile
create mode 100644 fs/btrfs/btrfs.c
create mode 100644 fs/btrfs/crc32_c.c
create mode 100644 include/btrfs.h

Quoted 3 lines

I have ignored the code before this point in btrfs.c since it is imported and you want to keep the code style as is, but if you don't mind I will make a few comments after that point>

Here are my comments

Quoted 10 lines
Quoted 10 lines
fs/btrfs/btrfs.c new file +9 -0
+struct btrfs_info fs;
+
+/*
+ *  mount btrfs file-system
+ */
+int btrfs_probe(block_dev_desc_t *rbdd, disk_partition_t *info)
+{
+        btrfs_block_dev_desc = rbdd;
+        part_info = info;
Quoted 8 lines

fs/btrfs/btrfs.c line 1281

Quoted 5 lines
fs/btrfs/btrfs.c new file +5 -0
+        btr_part_offset = info->start;
+       if (btrfs_fs_init(&fs) < 0 ) {
+          debug("btrfs probe failed\n");
+          return -1;
+       }

You should use tabs for intend (some of this bit uses spaces, some uses tabs).

Some how i missed will check it again. Ack

Quoted 53 lines
Quoted 53 lines
fs/btrfs/btrfs.c new file +8 -0
+
+       return 0;
+}
+
+/*
+ *  Read file data
+ */
+int btrfs_read_file(const char *filename, void *buf, int offset, int

len)

fs/btrfs/btrfs.c new file +13 -0
+{
+       int file_len=0;
+        int len_read;
+        struct com32_filedata filedata;
+        int handle;
+        if (offset != 0) {
+                debug("** Cannot support non-zero offset **\n");
+                return -1;
+        }
+
+        handle=btrfs_open_file(filename, &filedata);
+        if (handle < 0) {
+                debug("** File not found %s Invalid handle**\n",

filename);

fs/btrfs/btrfs.c new file +29 -0
+                return -1;
+        }
+
+        /*file handle is valid get the size of the file*/
+        len = filedata.size;
+        if (len == 0)
+                len = file_len;
+
+        len_read = getfssec(&filedata, (char *)buf);
+        if (len_read != len) {
+                debug("** Unable to read file %s **\n", filename);
+                return -1;
+        }
+
+        return len_read;
+
+}
+
+/*
+ * Show directory entries
+ */
+char btrfs_ls(char *dirname)
+{
+  struct btrfs_dirent *de;
+  struct _DIR_ *dir;
+
+  if(*dirname == '/' && *(dirname+1) == 0)
+     *dirname = '.';
+
Quoted 8 lines

fs/btrfs/btrfs.c line 1337

Quoted 6 lines
fs/btrfs/btrfs.c new file +6 -0
+  dir = opendir(dirname);
+  if (dir == NULL)
+        return -1;
+
+  while ((de = readdir(dir)) != NULL)
+        ;

This doesn't seem to print anything.

     readdir->btrfs_read, prints contents on media.
Quoted 13 lines

fs/btrfs/btrfs.c line 1347

Quoted 11 lines
fs/btrfs/btrfs.c new file +10 -0
+
+  return 0;
+}
+
+/*
+ *  umount btrfs file-system
+ */
+void btrfs_close(void)
+{
+

Remove blank line

Ack

Quoted 25 lines
Quoted 25 lines
(quoted diff) +1 -0
+}
fs/btrfs/crc32_c.c new file +6 -0
new file mode 100644
index 0000000..78d0447
@@ -0,0 +1,54 @@
+/*
+ * Copied from Linux kernel crypto/crc32c.c
+ * Copyright (c) 2004 Cisco Systems, Inc.
+ * Copyright (c) 2008 Herbert Xu <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify

it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */

fs/btrfs/crc32_c.c new file +3 -0
+
+/*
+ * This is the CRC-32C table
Quoted 8 lines
Quoted 6 lines

+ * Generated with:
+ * width = 32 bits
+ * poly = 0x1EDC6F41
+ * reflect input bytes = true
+ * reflect output bytes = true
+ */

Old comment?

this crc was part of port

Quoted 17 lines
Quoted 17 lines
fs/btrfs/crc32_c.c new file +13 -0
+
+/*
+ * Steps through buffer one byte at at time, calculates reflected
+ * crc using table.
+ */
+#include <linux/stat.h>
+#include <command.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+#include <common.h>
+#include <config.h>
+
+inline u32 crc32c_cal(u32 crc, const char *data, size_t length, u32

*crc32c_table)

fs/btrfs/crc32_c.c new file +2 -0
+{
+       while (length--)
Quoted 8 lines

fs/btrfs/crc32_c.c line 41

Quoted 6 lines
fs/btrfs/crc32_c.c new file +6 -0
+               crc = crc32c_table[(u8)(crc ^ *data++)] ^ (crc >> 8);
+
+       return crc;
+}
+
+inline void crc32c_init(u32 *crc32c_table, u32 pol)

The 'inline' isn't needed.

Ack

Quoted 11 lines

fs/btrfs/crc32_c.c line 49

Quoted 9 lines
fs/btrfs/crc32_c.c new file +8 -0
+{
+       int i, j;
+       u32 v;
+       const u32 poly = pol; /* Bit-reflected CRC32C polynomial */
+
+       for (i = 0; i < 256; i++) {
+               v = i;
+               for (j = 0; j < 8; j++) {

Can remove this inner {} since you only have one line of code.

Ack

Quoted 9 lines

fs/btrfs/crc32_c.c line 54

Quoted 5 lines
fs/btrfs/crc32_c.c new file +5 -0
+                       v = (v >> 1) ^ ((v & 1) ? poly : 0);
+               }
+               crc32c_table[i] = v;
+       }
+}

I suggest you move your crc_32.c file to lib/ since it might be more generally useful. You should probably include the function prototypes in include/crc.h.

The crc32_c.c was part of port as header file and you previously said
to move to btrfs folder and make it c file.

Quoted 6 lines
Quoted 2 lines

Also you seem to recalculate the crc table on every operation. Is is possible to only do this ones on startup?

Yes every time prob is called its calculated. It can be calculated at
boot time. Can you point me to file and function that it can be called. before that can we make decision on crc32_c.c.

Perhaps you could call it once in your btrfs_probe() function, and set a flag once you have done it once?

Quoted 3 lines

Plus once i make all these changes will it be accepted than ;).

I hope so. I think it fits in nicely. Did you have any comments as to why the btrload command doesn't have [bytes [pos] like fatload, for example?

Regards,
Simon

Quoted 8 lines
Quoted 4 lines

Regards,
Simon

Regards
Adnan

author
#5 lore raw

PATCH v5 1/1 Introduced btrfs file-system with btrload command

Quoted 224 lines · Simon Glass

Hi Adnan,

Quoted 213 lines · Adnan Ali

Hi

Quoted 35 lines · Simon Glass

Hi Adnan,

Quoted 25 lines · Adnan Ali

Introduces btrfs file-system to read file from volume/sub-volumes with btrload command. This implementation has read-only support.
This btrfs implementation is based on syslinux btrfs code, commit 269ebc845ebc8b46ef4b0be7fa0005c7fdb95b8d.

v5:     merged with master.
v4:     btrls command added.
v3:     patch re-formated.
v2:     patch error removed.
---
   Makefile                   |    1 +
   common/Makefile            |    1 +
   common/cmd_btr.c           |   65 +++
   fs/btrfs/Makefile          |   51 ++
   fs/btrfs/btrfs.c           | 1348
++++++++++++++++++++++++++++++++++++++++++++
   fs/btrfs/crc32_c.c         |   54 ++
   fs/fs.c                    |   10 +
   include/btrfs.h            |  416 ++++++++++++++
   include/config_fallbacks.h |    4 +
   include/fs.h               |    1 +
   10 files changed, 1951 insertions(+)
Quoted 6 lines

create mode 100644 common/cmd_btr.c create mode 100644 fs/btrfs/Makefile create mode 100644 fs/btrfs/btrfs.c create mode 100644 fs/btrfs/crc32_c.c create mode 100644 include/btrfs.h

Quoted 3 lines

I have ignored the code before this point in btrfs.c since it is imported and you want to keep the code style as is, but if you don't mind I will make a few comments after that point>

Here are my comments

Quoted 8 lines
Quoted 8 lines
fs/btrfs/btrfs.c new file +8 -0
+struct btrfs_info fs;
+
+/*
+ *  mount btrfs file-system
+ */
+int btrfs_probe(block_dev_desc_t *rbdd, disk_partition_t *info)
+{
+        btrfs_block_dev_desc = rbdd;
Quoted 8 lines

fs/btrfs/btrfs.c line 1281

Quoted 6 lines
fs/btrfs/btrfs.c new file +6 -0
+        part_info = info;
+        btr_part_offset = info->start;
+       if (btrfs_fs_init(&fs) < 0 ) {
+          debug("btrfs probe failed\n");
+          return -1;
+       }

You should use tabs for intend (some of this bit uses spaces, some uses tabs).

Some how i missed will check it again. Ack

Quoted 51 lines
Quoted 51 lines
fs/btrfs/btrfs.c new file +8 -0
+
+       return 0;
+}
+
+/*
+ *  Read file data
+ */
+int btrfs_read_file(const char *filename, void *buf, int offset, int

len)

fs/btrfs/btrfs.c new file +13 -0
+{
+       int file_len=0;
+        int len_read;
+        struct com32_filedata filedata;
+        int handle;
+        if (offset != 0) {
+                debug("** Cannot support non-zero offset **\n");
+                return -1;
+        }
+
+        handle=btrfs_open_file(filename, &filedata);
+        if (handle < 0) {
+                debug("** File not found %s Invalid handle**\n",

filename);

fs/btrfs/btrfs.c new file +28 -0
+                return -1;
+        }
+
+        /*file handle is valid get the size of the file*/
+        len = filedata.size;
+        if (len == 0)
+                len = file_len;
+
+        len_read = getfssec(&filedata, (char *)buf);
+        if (len_read != len) {
+                debug("** Unable to read file %s **\n", filename);
+                return -1;
+        }
+
+        return len_read;
+
+}
+
+/*
+ * Show directory entries
+ */
+char btrfs_ls(char *dirname)
+{
+  struct btrfs_dirent *de;
+  struct _DIR_ *dir;
+
+  if(*dirname == '/' && *(dirname+1) == 0)
+     *dirname = '.';
Quoted 8 lines

fs/btrfs/btrfs.c line 1337

Quoted 7 lines
fs/btrfs/btrfs.c new file +7 -0
+
+  dir = opendir(dirname);
+  if (dir == NULL)
+        return -1;
+
+  while ((de = readdir(dir)) != NULL)
+        ;

This doesn't seem to print anything.

      readdir->btrfs_read, prints contents on media.
Quoted 11 lines

fs/btrfs/btrfs.c line 1347

Quoted 10 lines
fs/btrfs/btrfs.c new file +10 -0
+
+  return 0;
+}
+
+/*
+ *  umount btrfs file-system
+ */
+void btrfs_close(void)
+{
+

Remove blank line

Ack

Quoted 23 lines
Quoted 23 lines
(quoted diff) +1 -0
+}
fs/btrfs/crc32_c.c new file +6 -0
new file mode 100644
index 0000000..78d0447
@@ -0,0 +1,54 @@
+/*
+ * Copied from Linux kernel crypto/crc32c.c
+ * Copyright (c) 2004 Cisco Systems, Inc.
+ * Copyright (c) 2008 Herbert Xu <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify

it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */

fs/btrfs/crc32_c.c new file +2 -0
+
+/*
Quoted 8 lines
Quoted 7 lines

+ * This is the CRC-32C table
+ * Generated with:
+ * width = 32 bits
+ * poly = 0x1EDC6F41
+ * reflect input bytes = true
+ * reflect output bytes = true
+ */

Old comment?

this crc was part of port

Quoted 15 lines
Quoted 15 lines
fs/btrfs/crc32_c.c new file +13 -0
+
+/*
+ * Steps through buffer one byte at at time, calculates reflected
+ * crc using table.
+ */
+#include <linux/stat.h>
+#include <command.h>
+#include <asm/byteorder.h>
+#include <linux/compiler.h>
+#include <common.h>
+#include <config.h>
+
+inline u32 crc32c_cal(u32 crc, const char *data, size_t length, u32

*crc32c_table)
+{

Quoted 8 lines

fs/btrfs/crc32_c.c line 41

Quoted 7 lines
fs/btrfs/crc32_c.c new file +7 -0
+       while (length--)
+               crc = crc32c_table[(u8)(crc ^ *data++)] ^ (crc >> 8);
+
+       return crc;
+}
+
+inline void crc32c_init(u32 *crc32c_table, u32 pol)

The 'inline' isn't needed.

Ack

Quoted 9 lines

fs/btrfs/crc32_c.c line 49

Quoted 8 lines
fs/btrfs/crc32_c.c new file +8 -0
+{
+       int i, j;
+       u32 v;
+       const u32 poly = pol; /* Bit-reflected CRC32C polynomial */
+
+       for (i = 0; i < 256; i++) {
+               v = i;
+               for (j = 0; j < 8; j++) {

Can remove this inner {} since you only have one line of code.

Ack

Quoted 8 lines

fs/btrfs/crc32_c.c line 54

Quoted 5 lines
fs/btrfs/crc32_c.c new file +5 -0
+                       v = (v >> 1) ^ ((v & 1) ? poly : 0);
+               }
+               crc32c_table[i] = v;
+       }
+}

I suggest you move your crc_32.c file to lib/ since it might be more generally useful. You should probably include the function prototypes in include/crc.h.

Quoted 8 lines

The crc32_c.c was part of port as header file and you previously said
to move to btrfs folder and make it c file.

Quoted 2 lines

Also you seem to recalculate the crc table on every operation. Is is possible to only do this ones on startup?

Yes every time prob is called its calculated. It can be calculated at
boot time. Can you point me to file and function that it can be called. before that can we make decision on crc32_c.c.

Quoted 8 lines

Perhaps you could call it once in your btrfs_probe() function, and set a flag once you have done it once?

Quoted 2 lines

Plus once i make all these changes will it be accepted than ;).

I hope so. I think it fits in nicely. Did you have any comments as to why the btrload command doesn't have [bytes [pos] like fatload, for example?

I will send patch v6 to cover all things you pointed out that isn't related to port.
I think [bytes [pos]] can be done in btrfs. I prefered adding
subvolume which
was unique to btrfs. I can add that later send patch for this, once
this goes
in main stream. If that is acceptable to you.

Quoted 10 lines

Regards,
Simon

Quoted 6 lines
Quoted 3 lines

Regards,
Simon

Regards
Adnan

Thanks
Adnan