Skip to contentSkip to conversation

sandbox: Add filesystem support

PATCH New Simon Glass 3 participants 32 messages Dec 26, 2012 – Mar 4, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover sandbox: Add filesystem support

This series adds support for filesystems to sandbox. While we don't yet have access to host machine block devices, we can access files on the host through a new 'host' filesystem type and the new sandbox command 'sb'.

For example:

sb load host 0 1000 foo.bar

will load foo.bar from the host into memory at address 1000. The '0' parameter is the device number, currently unused.

While doing this work, I noticed that fs.c had code that probably belongs more in the filesystems themselves. So this series moves fat/ext4 code into those files. This removes most of the #ifdefs from this file, as well as the #defines of functions to 'unsupported'. Now there is a list of filesystems that we support, and if we don't find the one we need, we automatically fall back to the 'unsupported' one.

Finally, the ext4 write support is moved into a separate file since ext4fs.c was over 3500 lines and the write support seems entirely separate from the main function in that file.

Simon Glass (11):
ext4: Split write support into its own file
fs: Fully populate the filesystem method struct
fs: Use filesystem methods instead of switch()
fs: Tell probe functions where to put their results
fs: Use map_sysmem() on read
fs: Move ls and read methods into ext4, fat
sandbox: Add a way of obtaining directory listings
sandbox: Add host filesystem
sandbox: Add 'sb' command to access filesystem features
sandbox: Enable ext4 and fat filesystems
sandbox: config: Enable sandbox command

 Makefile                  |    1 +
 README                    |    1 +
 arch/sandbox/cpu/os.c     |  101 +++++
 common/Makefile           |    1 +
 common/cmd_sandbox.c      |   63 +++
 disk/part.c               |   17 +
 fs/ext4/Makefile          |    2 +-
 fs/ext4/ext4_write.c      |  996 +++++++++++++++++++++++++++++++++++++++++++++
 fs/ext4/ext4fs.c          |  962 +------------------------------------------
 fs/fat/fat.c              |   17 +
 fs/fs.c                   |  237 +++++-------
 fs/sandbox/Makefile       |   47 +++
 fs/sandbox/sandboxfs.c    |   83 ++++
 include/config_cmd_all.h  |    1 +
 include/configs/sandbox.h |    9 +
 include/ext4fs.h          |    3 +
 include/fat.h             |    2 +
 include/fs.h              |    1 +
 include/os.h              |   48 +++
 include/sandboxfs.h       |   30 ++
 20 files changed, 1533 insertions(+), 1089 deletions(-)
 create mode 100644 common/cmd_sandbox.c
 create mode 100644 fs/ext4/ext4_write.c
 create mode 100644 fs/sandbox/Makefile
 create mode 100644 fs/sandbox/sandboxfs.c
 create mode 100644 include/sandboxfs.h
Signature · 1 line
1.7.7.3
#1 lore raw

PATCH 1/11 ext4: Split write support into its own file

This code seems to be entirely othogonal, so remove the #ifdef and put the condition in the Makefile instead.

---
 fs/ext4/Makefile     |    2 +-
 fs/ext4/ext4_write.c |  996 ++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ext4/ext4fs.c     |  963 ------------------------------------------------
 3 files changed, 997 insertions(+), 964 deletions(-)
 create mode 100644 fs/ext4/ext4_write.c
fs/ext4/Makefile +1 -1
index bb801f9..3bde824 100644
@@ -31,7 +31,7 @@ LIB	= $(obj)libext4fs.o
 
 AOBJS	=
 COBJS-$(CONFIG_FS_EXT4) := ext4fs.o ext4_common.o dev.o
-COBJS-$(CONFIG_EXT4_WRITE) += ext4_journal.o crc16.o
+COBJS-$(CONFIG_EXT4_WRITE) += ext4_write.o ext4_journal.o crc16.o
 
 SRCS	:= $(AOBJS:.o=.S) $(COBJS-y:.o=.c)
 OBJS	:= $(addprefix $(obj),$(AOBJS) $(COBJS-y))
fs/ext4/ext4_write.c new file +996 -0

996 lines not on this page · raw message

fs/ext4/ext4fs.c +0 -963

974 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#2 lore raw

PATCH 1/11 ext4: Split write support into its own file

Hi Simon,

Quoted 2 lines

This code seems to be entirely othogonal, so remove the #ifdef and put the condition in the Makefile instead.

I'm fully with you in respect of cleaning/refactoring the ext4 u-boot code.

I will test this change when I only find some time ...

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung Poland R&D Center | Linux Platform Group
#3 lore raw

PATCH 1/11 ext4: Split write support into its own file

Hi Simon,

Quoted 9 lines
Quoted 3 lines

This code seems to be entirely othogonal, so remove the #ifdef and put the condition in the Makefile instead.

I'm fully with you in respect of cleaning/refactoring the ext4 u-boot code.

I will test this change when I only find some time ...

Are you doing any work on ext4 code refactoring/rewritting at u-boot?

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Poland (SRPOL) | Linux Platform Group
#4 lore raw

PATCH 1/11 ext4: Split write support into its own file

Hi Lukasz,

Quoted 6 lines · Lukasz Majewski

Hi Simon,

Quoted 4 lines
Quoted 3 lines

This code seems to be entirely othogonal, so remove the #ifdef and put the condition in the Makefile instead.

Quoted 7 lines
Quoted 5 lines

I'm fully with you in respect of cleaning/refactoring the ext4 u-boot code.

I will test this change when I only find some time ...

Are you doing any work on ext4 code refactoring/rewritting at u-boot?

No, just the fs layer, so that I could get sandbox to work. Plus I split up the file a bit. But I have no other plans.

Regards,
Simon

Quoted 7 lines

--
Best regards,

Lukasz Majewski

Samsung R&D Poland (SRPOL) | Linux Platform Group

#5 lore raw

PATCH 1/11 ext4: Split write support into its own file

Hi Simon,

Quoted 13 lines

Hi Lukasz,

Quoted 9 lines · Lukasz Majewski

Hi Simon,

Quoted 7 lines
Quoted 3 lines

This code seems to be entirely othogonal, so remove the #ifdef and put the condition in the Makefile instead.

I'm fully with you in respect of cleaning/refactoring the ext4 u-boot code.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

I will test this change when I only find some time ...

Are you doing any work on ext4 code refactoring/rewritting at u-boot?

No, just the fs layer, so that I could get sandbox to work. Plus I split up the file a bit. But I have no other plans.

Ok, thanks for info.

Quoted 10 lines

Regards,
Simon

Quoted 7 lines

--
Best regards,

Lukasz Majewski

Samsung R&D Poland (SRPOL) | Linux Platform Group

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Poland (SRPOL) | Linux Platform Group
#6 lore raw

PATCH 1/11 ext4: Split write support into its own file

In reply to Simon Glass
Quoted 4 lines · Simon Glass

This code seems to be entirely othogonal, so remove the #ifdef and put the condition in the Makefile instead.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/9c464179/attachment.pgp>
#7 lore raw

PATCH 2/11 fs: Fully populate the filesystem method struct

In reply to Simon Glass

There is a structure in fs.c with just a probe method. By adding methods for other operations, we can avoid lots of #ifdefs and switch()s. As a first step, create the structure ready for use.

---
 fs/fs.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 9 deletions(-)
fs/fs.c +47 -9
index 2c9f2c5..66835e2 100644
@@ -27,6 +27,12 @@ static block_dev_desc_t *fs_dev_desc;
 static disk_partition_t fs_partition;
 static int fs_type = FS_TYPE_ANY;
 
+static inline int fs_probe_unsupported(void)
+{
+	printf("** Unrecognized filesystem type **\n");
+	return -1;
+}
+
 static inline int fs_ls_unsupported(const char *dirname)
 {
 	printf("** Unrecognized filesystem type **\n");
@@ -40,6 +46,10 @@ static inline int fs_read_unsupported(const char *filename, ulong addr,
 	return -1;
 }
 
+static inline void fs_close_unsupported(void)
+{
+}
+
 #ifdef CONFIG_FS_FAT
 static int fs_probe_fat(void)
 {
@@ -143,29 +153,57 @@ static inline void fs_close_ext(void)
 #define fs_read_ext fs_read_unsupported
 #endif
 
-static struct {
+struct fstype_info {
 	int fstype;
 	int (*probe)(void);
-} fstypes[] = {
+	int (*ls)(const char *dirname);
+	int (*read)(const char *filename, ulong addr, int offset, int len);
+	void (*close)(void);
+};
+
+static struct fstype_info fstypes[] = {
+#ifdef CONFIG_FS_FAT
 	{
 		.fstype = FS_TYPE_FAT,
 		.probe = fs_probe_fat,
+		.close = fs_close_fat,
+		.ls = file_fat_ls,
+		.read = fs_read_fat,
 	},
+#endif
+#ifdef CONFIG_FS_EXT4
 	{
 		.fstype = FS_TYPE_EXT,
 		.probe = fs_probe_ext,
+		.close = fs_close_ext,
+		.ls = ext4fs_ls,
+		.read = fs_read_ext,
+	},
+#endif
+	{
+		.fstype = FS_TYPE_ANY,
+		.probe = fs_probe_unsupported,
+		.close = fs_close_unsupported,
+		.ls = fs_ls_unsupported,
+		.read = fs_read_unsupported,
 	},
 };
 
 int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
 {
+	struct fstype_info *info;
 	int part, i;
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
 	static int relocated;
 
 	if (!relocated) {
-		for (i = 0; i < ARRAY_SIZE(fstypes); i++)
-			fstypes[i].probe += gd->reloc_off;
+		for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);
+				i++, info++) {
+			info->probe += gd->reloc_off;
+			info->close += gd->reloc_off;
+			info->ls += gd->reloc_off;
+			info->read += gd->reloc_off;
+		}
 		relocated = 1;
 	}
 #endif
@@ -175,17 +213,17 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
 	if (part < 0)
 		return -1;
 
-	for (i = 0; i < ARRAY_SIZE(fstypes); i++) {
-		if ((fstype != FS_TYPE_ANY) && (fstype != fstypes[i].fstype))
+	for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
+		if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY &&
+				fstype != info->fstype)
 			continue;
 
-		if (!fstypes[i].probe()) {
-			fs_type = fstypes[i].fstype;
+		if (!info->probe()) {
+			fs_type = info->fstype;
 			return 0;
 		}
 	}
 
-	printf("** Unrecognized filesystem type **\n");
 	return -1;
 }
 
Signature · 1 line
1.7.7.3
#8 lore raw

PATCH 2/11 fs: Fully populate the filesystem method struct

Quoted 5 lines · Simon Glass

There is a structure in fs.c with just a probe method. By adding methods for other operations, we can avoid lots of #ifdefs and switch()s. As a first step, create the structure ready for use.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/51ddfdcb/attachment.pgp>
#9 lore raw

PATCH 3/11 fs: Use filesystem methods instead of switch()

In reply to Simon Glass

We can use the available methods and avoid using switch(). When the filesystem is not supported, we fall through to the 'unsupported'
methods: fs_probe_unsupported() prints an error, so the others do not need to.

---
 fs/fs.c |   60 ++++++++++++++++++++++++++----------------------------------
 1 files changed, 26 insertions(+), 34 deletions(-)
fs/fs.c +26 -34
index 66835e2..856d8ba 100644
@@ -35,14 +35,12 @@ static inline int fs_probe_unsupported(void)
 
 static inline int fs_ls_unsupported(const char *dirname)
 {
-	printf("** Unrecognized filesystem type **\n");
 	return -1;
 }
 
 static inline int fs_read_unsupported(const char *filename, ulong addr,
 				      int offset, int len)
 {
-	printf("** Unrecognized filesystem type **\n");
 	return -1;
 }
 
@@ -189,6 +187,20 @@ static struct fstype_info fstypes[] = {
 	},
 };
 
+static struct fstype_info *fs_get_info(int fstype)
+{
+	struct fstype_info *info;
+	int i;
+
+	for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
+		if (fstype == info->fstype)
+			return info;
+	}
+
+	/* Return the 'unsupported' sentinel */
+	return info;
+}
+
 int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
 {
 	struct fstype_info *info;
@@ -229,17 +241,9 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
 
 static void fs_close(void)
 {
-	switch (fs_type) {
-	case FS_TYPE_FAT:
-		fs_close_fat();
-		break;
-	case FS_TYPE_EXT:
-		fs_close_ext();
-		break;
-	default:
-		break;
-	}
+	struct fstype_info *info = fs_get_info(fs_type);
 
+	info->close();
 	fs_type = FS_TYPE_ANY;
 }
 
@@ -247,17 +251,9 @@ int fs_ls(const char *dirname)
 {
 	int ret;
 
-	switch (fs_type) {
-	case FS_TYPE_FAT:
-		ret = fs_ls_fat(dirname);
-		break;
-	case FS_TYPE_EXT:
-		ret = fs_ls_ext(dirname);
-		break;
-	default:
-		ret = fs_ls_unsupported(dirname);
-		break;
-	}
+	struct fstype_info *info = fs_get_info(fs_type);
+
+	ret = info->ls(dirname);
 
 	fs_close();
 
@@ -266,20 +262,16 @@ int fs_ls(const char *dirname)
 
 int fs_read(const char *filename, ulong addr, int offset, int len)
 {
+	struct fstype_info *info = fs_get_info(fs_type);
 	int ret;
 
-	switch (fs_type) {
-	case FS_TYPE_FAT:
-		ret = fs_read_fat(filename, addr, offset, len);
-		break;
-	case FS_TYPE_EXT:
-		ret = fs_read_ext(filename, addr, offset, len);
-		break;
-	default:
-		ret = fs_read_unsupported(filename, addr, offset, len);
-		break;
-	}
+	ret = info->read(filename, addr, offset, len);
 
+	/* If we requested a specific number of bytes, check we got it */
+	if (ret >= 0 && len && ret != len) {
+		printf("** Unable to read file %s **\n", filename);
+		ret = -1;
+	}
 	fs_close();
 
 	return ret;
Signature · 1 line
1.7.7.3
#10 lore raw

PATCH 3/11 fs: Use filesystem methods instead of switch()

Quoted 6 lines · Simon Glass

We can use the available methods and avoid using switch(). When the filesystem is not supported, we fall through to the 'unsupported'
methods: fs_probe_unsupported() prints an error, so the others do not need to.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/80f0ec1e/attachment.pgp>
#11 lore raw

PATCH 4/11 fs: Tell probe functions where to put their results

In reply to Simon Glass

Rather than rely on global variables for the probe functions, pass in the information that we need filled in. This allows us to potentially keep the variables private to fs.c in the future, and the meaning of the probe function is clearer.

---
 fs/fs.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
fs/fs.c +12 -8
index 856d8ba..3561727 100644
@@ -27,7 +27,8 @@ static block_dev_desc_t *fs_dev_desc;
 static disk_partition_t fs_partition;
 static int fs_type = FS_TYPE_ANY;
 
-static inline int fs_probe_unsupported(void)
+static inline int fs_probe_unsupported(block_dev_desc_t *fs_dev_desc,
+				      disk_partition_t *fs_partition)
 {
 	printf("** Unrecognized filesystem type **\n");
 	return -1;
@@ -49,9 +50,10 @@ static inline void fs_close_unsupported(void)
 }
 
 #ifdef CONFIG_FS_FAT
-static int fs_probe_fat(void)
+static int fs_probe_fat(block_dev_desc_t *fs_dev_desc,
+			disk_partition_t *fs_partition)
 {
-	return fat_set_blk_dev(fs_dev_desc, &fs_partition);
+	return fat_set_blk_dev(fs_dev_desc, fs_partition);
 }
 
 static void fs_close_fat(void)
@@ -88,11 +90,12 @@ static inline void fs_close_fat(void)
 #endif
 
 #ifdef CONFIG_FS_EXT4
-static int fs_probe_ext(void)
+static int fs_probe_ext(block_dev_desc_t *fs_dev_desc,
+			disk_partition_t *fs_partition)
 {
-	ext4fs_set_blk_dev(fs_dev_desc, &fs_partition);
+	ext4fs_set_blk_dev(fs_dev_desc, fs_partition);
 
-	if (!ext4fs_mount(fs_partition.size)) {
+	if (!ext4fs_mount(fs_partition->size)) {
 		ext4fs_close();
 		return -1;
 	}
@@ -153,7 +156,8 @@ static inline void fs_close_ext(void)
 
 struct fstype_info {
 	int fstype;
-	int (*probe)(void);
+	int (*probe)(block_dev_desc_t *fs_dev_desc,
+		     disk_partition_t *fs_partition);
 	int (*ls)(const char *dirname);
 	int (*read)(const char *filename, ulong addr, int offset, int len);
 	void (*close)(void);
@@ -230,7 +234,7 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
 				fstype != info->fstype)
 			continue;
 
-		if (!info->probe()) {
+		if (!info->probe(fs_dev_desc, &fs_partition)) {
 			fs_type = info->fstype;
 			return 0;
 		}
Signature · 1 line
1.7.7.3
#12 lore raw

PATCH 4/11 fs: Tell probe functions where to put their results

Quoted 6 lines · Simon Glass

Rather than rely on global variables for the probe functions, pass in the information that we need filled in. This allows us to potentially keep the variables private to fs.c in the future, and the meaning of the probe function is clearer.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/f20b1301/attachment.pgp>
#13 lore raw

PATCH 5/11 fs: Use map_sysmem() on read

In reply to Simon Glass

This allows us to use filesystems on sandbox. It has no effect on other architectures.

---
 fs/fs.c |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)
fs/fs.c +15 -8
index 3561727..0cbec99 100644
@@ -20,6 +20,7 @@
 #include <ext4fs.h>
 #include <fat.h>
 #include <fs.h>
+#include <asm/io.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -39,7 +40,7 @@ static inline int fs_ls_unsupported(const char *dirname)
 	return -1;
 }
 
-static inline int fs_read_unsupported(const char *filename, ulong addr,
+static inline int fs_read_unsupported(const char *filename, void *buf,
 				      int offset, int len)
 {
 	return -1;
@@ -62,12 +63,11 @@ static void fs_close_fat(void)
 
 #define fs_ls_fat file_fat_ls
 
-static int fs_read_fat(const char *filename, ulong addr, int offset, int len)
+static int fs_read_fat(const char *filename, void *buf, int offset, int len)
 {
 	int len_read;
 
-	len_read = file_fat_read_at(filename, offset,
-				    (unsigned char *)addr, len);
+	len_read = file_fat_read_at(filename, offset, buf, len);
 	if (len_read == -1) {
 		printf("** Unable to read file %s **\n", filename);
 		return -1;
@@ -110,7 +110,7 @@ static void fs_close_ext(void)
 
 #define fs_ls_ext ext4fs_ls
 
-static int fs_read_ext(const char *filename, ulong addr, int offset, int len)
+static int fs_read_ext(const char *filename, void *buf, int offset, int len)
 {
 	int file_len;
 	int len_read;
@@ -130,7 +130,7 @@ static int fs_read_ext(const char *filename, ulong addr, int offset, int len)
 	if (len == 0)
 		len = file_len;
 
-	len_read = ext4fs_read((char *)addr, len);
+	len_read = ext4fs_read(buf, len);
 	ext4fs_close();
 
 	if (len_read != len) {
@@ -159,7 +159,7 @@ struct fstype_info {
 	int (*probe)(block_dev_desc_t *fs_dev_desc,
 		     disk_partition_t *fs_partition);
 	int (*ls)(const char *dirname);
-	int (*read)(const char *filename, ulong addr, int offset, int len);
+	int (*read)(const char *filename, void *buf, int offset, int len);
 	void (*close)(void);
 };
 
@@ -267,9 +267,16 @@ int fs_ls(const char *dirname)
 int fs_read(const char *filename, ulong addr, int offset, int len)
 {
 	struct fstype_info *info = fs_get_info(fs_type);
+	void *buf;
 	int ret;
 
-	ret = info->read(filename, addr, offset, len);
+	/*
+	 * We don't actually know how many bytes are being read, since len==0
+	 * means read the whole file.
+	 */
+	buf = map_sysmem(addr, len);
+	ret = info->read(filename, buf, offset, len);
+	unmap_sysmem(buf);
 
 	/* If we requested a specific number of bytes, check we got it */
 	if (ret >= 0 && len && ret != len) {
Signature · 1 line
1.7.7.3
#14 lore raw

PATCH 5/11 fs: Use map_sysmem() on read

Quoted 4 lines · Simon Glass

This allows us to use filesystems on sandbox. It has no effect on other architectures.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/3f56b295/attachment.pgp>
#15 lore raw

PATCH 6/11 fs: Move ls and read methods into ext4, fat

In reply to Simon Glass

It doesn't make a lot of sense to have these methods in fs.c. They are filesystem-specific, not generic code. Add each to the relevant filesystem and remove the associated #ifdefs in fs.c.

---
 fs/ext4/ext4fs.c |   37 +++++++++++++++++
 fs/fat/fat.c     |   17 ++++++++
 fs/fs.c          |  118 ++++--------------------------------------------------
 include/ext4fs.h |    3 +
 include/fat.h    |    2 +
 5 files changed, 67 insertions(+), 110 deletions(-)
fs/ext4/ext4fs.c +37 -0
index 7fdb463..4dddde2 100644
@@ -191,3 +191,40 @@ int ext4fs_read(char *buf, unsigned len)
 
 	return ext4fs_read_file(ext4fs_file, 0, len, buf);
 }
+
+int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
+		 disk_partition_t *fs_partition)
+{
+	ext4fs_set_blk_dev(fs_dev_desc, fs_partition);
+
+	if (!ext4fs_mount(fs_partition->size)) {
+		ext4fs_close();
+		return -1;
+	}
+
+	return 0;
+}
+
+int ext4_read_file(const char *filename, void *buf, int offset, int len)
+{
+	int file_len;
+	int len_read;
+
+	if (offset != 0) {
+		printf("** Cannot support non-zero offset **\n");
+		return -1;
+	}
+
+	file_len = ext4fs_open(filename);
+	if (file_len < 0) {
+		printf("** File not found %s **\n", filename);
+		return -1;
+	}
+
+	if (len == 0)
+		len = file_len;
+
+	len_read = ext4fs_read(buf, len);
+
+	return len_read;
+}
fs/fat/fat.c +17 -0
index 393c378..82135b5 100644
@@ -1256,3 +1256,20 @@ long file_fat_read(const char *filename, void *buffer, unsigned long maxsize)
 {
 	return file_fat_read_at(filename, 0, buffer, maxsize);
 }
+
+int fat_read_file(const char *filename, void *buf, int offset, int len)
+{
+	int len_read;
+
+	len_read = file_fat_read_at(filename, offset, buf, len);
+	if (len_read == -1) {
+		printf("** Unable to read file %s **\n", filename);
+		return -1;
+	}
+
+	return len_read;
+}
+
+void fat_close(void)
+{
+}
fs/fs.c +8 -110

149 lines not on this page · raw message

include/ext4fs.h +3 -0
index 3b59d15..025a2e8 100644
@@ -138,4 +138,7 @@ void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
 int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf);
 void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
 long int read_allocated_block(struct ext2_inode *inode, int fileblock);
+int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
+		 disk_partition_t *fs_partition);
+int ext4_read_file(const char *filename, void *buf, int offset, int len);
 #endif
include/fat.h +2 -0
index 706cd7a..0b9017e 100644
@@ -216,4 +216,6 @@ int fat_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
 int fat_register_device(block_dev_desc_t *dev_desc, int part_no);
 
 int file_fat_write(const char *filename, void *buffer, unsigned long maxsize);
+int fat_read_file(const char *filename, void *buf, int offset, int len);
+void fat_close(void);
 #endif /* _FAT_H_ */
Signature · 1 line
1.7.7.3
#16 lore raw

PATCH 6/11 fs: Move ls and read methods into ext4, fat

Quoted 5 lines · Simon Glass

It doesn't make a lot of sense to have these methods in fs.c. They are filesystem-specific, not generic code. Add each to the relevant filesystem and remove the associated #ifdefs in fs.c.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/80fd00bb/attachment.pgp>
#17 lore raw

PATCH 7/11 sandbox: Add a way of obtaining directory listings

In reply to Simon Glass

This implementation uses opendir()/readdir() to access the directory information and then puts it in a linked list for the caller's use.

---
 arch/sandbox/cpu/os.c |  101 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/os.h          |   48 +++++++++++++++++++++++
 2 files changed, 149 insertions(+), 0 deletions(-)
arch/sandbox/cpu/os.c +101 -0
index 3e37c93..d075407 100644
@@ -19,10 +19,13 @@
  * MA 02111-1307 USA
  */
 
+#include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <termios.h>
 #include <time.h>
 #include <unistd.h>
@@ -261,3 +264,101 @@ int os_parse_args(struct sandbox_state *state, int argc, char *argv[])
 
 	return 0;
 }
+
+void os_dirent_free(struct os_dirent_node *node)
+{
+	struct os_dirent_node *next;
+
+	while (node) {
+		next = node->next;
+		free(node);
+		node = next;
+	}
+}
+
+int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
+{
+	struct dirent entry, *result;
+	struct os_dirent_node *head, *node, *next;
+	struct stat buf;
+	DIR *dir;
+	int ret;
+	char *fname;
+	int len;
+
+	*headp = NULL;
+	dir = opendir(dirname);
+	if (!dir)
+		return -1;
+
+	/* Create a buffer for the maximum filename length */
+	len = sizeof(entry.d_name) + strlen(dirname) + 2;
+	fname = malloc(len);
+	if (!fname) {
+		ret = -ENOMEM;
+		goto done;
+	}
+
+	for (node = head = NULL;; node = next) {
+		ret = readdir_r(dir, &entry, &result);
+		if (ret || !result)
+			break;
+		next = malloc(sizeof(*node) + strlen(entry.d_name) + 1);
+		if (!next) {
+			os_dirent_free(head);
+			ret = -ENOMEM;
+			goto done;
+		}
+		strcpy(next->name, entry.d_name);
+		switch (entry.d_type) {
+		case DT_REG:
+			next->type = OS_FILET_REG;
+			break;
+		case DT_DIR:
+			next->type = OS_FILET_DIR;
+			break;
+		case DT_LNK:
+			next->type = OS_FILET_LNK;
+			break;
+		}
+		next->size = 0;
+		snprintf(fname, len, "%s/%s", dirname, next->name);
+		if (!stat(fname, &buf))
+			next->size = buf.st_size;
+		if (node)
+			node->next = next;
+		if (!head)
+			head = node;
+	}
+	*headp = head;
+
+done:
+	closedir(dir);
+	return ret;
+}
+
+const char *os_dirent_typename[OS_FILET_COUNT] = {
+	"   ",
+	"SYM",
+	"DIR",
+	"???",
+};
+
+const char *os_dirent_get_typename(enum os_dirent_t type)
+{
+	if (type >= 0 && type < OS_FILET_COUNT)
+		return os_dirent_typename[type];
+
+	return os_dirent_typename[OS_FILET_UNKNOWN];
+}
+
+ssize_t os_get_filesize(const char *fname)
+{
+	struct stat buf;
+	int ret;
+
+	ret = stat(fname, &buf);
+	if (ret)
+		return ret;
+	return buf.st_size;
+}
include/os.h +48 -0

52 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#18 lore raw

PATCH 7/11 sandbox: Add a way of obtaining directory listings

Quoted 8 lines · Simon Glass

This implementation uses opendir()/readdir() to access the directory information and then puts it in a linked list for the caller's use.

---
 arch/sandbox/cpu/os.c |  101 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/os.h          |   48 +++++++++++++++++++++++
 2 files changed, 149 insertions(+), 0 deletions(-)

Since the code looks fine,

But a question. Do you really want this in cpu/os.c rather than some new file for filesystem stuff (since this is the arch side of sandboxfs) ? I can see you saying it should stay here since it's all OS interaction related stuff.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/6e7c44e9/attachment.pgp>
#19 lore raw

PATCH 7/11 sandbox: Add a way of obtaining directory listings

Hi Tom,

Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass

This implementation uses opendir()/readdir() to access the directory information and then puts it in a linked list for the caller's use.

---
 arch/sandbox/cpu/os.c |  101 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/os.h          |   48 +++++++++++++++++++++++
 2 files changed, 149 insertions(+), 0 deletions(-)
Quoted 8 lines

Since the code looks fine,

But a question. Do you really want this in cpu/os.c rather than some new file for filesystem stuff (since this is the arch side of sandboxfs) ? I can see you saying it should stay here since it's all OS interaction related stuff.

Thanks for reviewing. The practical reason why everything is in os.c is that this file is the interface between files which include common.h and files which include system headers. But logically speaking, I have tended to make os.c hold anything that interfaces with or calls a Linux API function.

We could certainly create something like os_filedir,c or similar if os.c is getting a bit large. But it would still need to include system headers. I don't think we want anything like this in in drivers/ at present.

Regards,
Simon

Quoted 3 lines

--
Tom

#20 lore raw

PATCH 7/11 sandbox: Add a way of obtaining directory listings

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 29 lines · Simon Glass

Hi Tom,

Quoted 11 lines · Tom Rini
Quoted 9 lines · Simon Glass

This implementation uses opendir()/readdir() to access the directory information and then puts it in a linked list for the caller's use.

arch/sandbox/cpu/os.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ include/os.h
| 48 +++++++++++++++++++++++ 2 files changed, 149
insertions(+), 0 deletions(-)

Quoted 8 lines

Since the code looks fine,

But a question. Do you really want this in cpu/os.c rather than some new file for filesystem stuff (since this is the arch side of sandboxfs) ? I can see you saying it should stay here since it's all OS interaction related stuff.

Thanks for reviewing. The practical reason why everything is in os.c is that this file is the interface between files which include common.h and files which include system headers. But logically speaking, I have tended to make os.c hold anything that interfaces with or calls a Linux API function.

Quoted 4 lines

We could certainly create something like os_filedir,c or similar if os.c is getting a bit large. But it would still need to include system headers. I don't think we want anything like this in in drivers/ at present.

I agree with not putting this into drivers/ as it's sandbox-side stuff. If os.c isn't yet unwieldy to you, OK, we can go as-is. But I'll ask next time you add another big hunk to os.c I'll ask if it's unwieldy yet.

- --
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRMPLmAAoJENk4IS6UOR1W+1YP/Rveu5b/OoEPqTqo6akhTiZa chVnl0td2tFYW6SQmLfCn8qPLBjsprsxlUzAywkvBzn8HJ33wPtKx00vCj04m9Fw ELbFuGpEkLEkHL6UEF2j9PGtZKudqybl7m0RRWIZfVA3ku4rPvav0w59WFzhNKF7 5EqzMyfvVX9XlnkVJ6H75H/JkNFxF3DaJ9jYs7zeOxmlyhgPby4df8GQEENpOvRs co2DvlbcuT3pHXAW7jqUYMb3wGphvCKlb2NE8fOjPszCm9F5En/M3i01lKFVRPZ1 MSLszZaUmMm6K4UjLVdnAAl8lPmP7SdwpsH0EhmehsVlh7jshbjhbEgAcN4tr2+V nUP/yW8gJl3oJ0JL04HV0ggYY7U71WnTRC+AMJcFdfen/4btfqGkJbERp5fiO6La qO8kx+mhl4hycMB+2pAhux6b4wK+vPXuyK7QbnliKA715S9FK3huf/u/QiPntKMA 6kE23ROuZMzvpnRu39brPCSAXLjDgyxWR+ofT/BuKPyrcXvOFjTa+IyI3EcFPKFX 0CdaGU6b/cxBVOHkBBeRLq0a5I2NNjV3dEXW78B9HmRNSpeDpCiZrNKDOe5ov1XH MVqthVBxQWgvoSZrQ+t4ff8dnP2fjNJfaUn15+EzmM8YZDPownNlaLaiSMuKL3dR XmF60m4s5kHSYpLOWa9l
=jsTJ
-----END PGP SIGNATURE-----

#21 lore raw

PATCH 7/11 sandbox: Add a way of obtaining directory listings

Hi Tom,

Quoted 38 lines · Tom Rini

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 29 lines · Simon Glass

Hi Tom,

Quoted 11 lines · Tom Rini
Quoted 9 lines · Simon Glass

This implementation uses opendir()/readdir() to access the directory information and then puts it in a linked list for the caller's use.

arch/sandbox/cpu/os.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ include/os.h
| 48 +++++++++++++++++++++++ 2 files changed, 149
insertions(+), 0 deletions(-)

Quoted 8 lines

Since the code looks fine,

But a question. Do you really want this in cpu/os.c rather than some new file for filesystem stuff (since this is the arch side of sandboxfs) ? I can see you saying it should stay here since it's all OS interaction related stuff.

Thanks for reviewing. The practical reason why everything is in os.c is that this file is the interface between files which include common.h and files which include system headers. But logically speaking, I have tended to make os.c hold anything that interfaces with or calls a Linux API function.

Quoted 4 lines

We could certainly create something like os_filedir,c or similar if os.c is getting a bit large. But it would still need to include system headers. I don't think we want anything like this in in drivers/ at present.

Quoted 4 lines

I agree with not putting this into drivers/ as it's sandbox-side stuff. If os.c isn't yet unwieldy to you, OK, we can go as-is. But I'll ask next time you add another big hunk to os.c I'll ask if it's unwieldy yet.

Understood, thanks.

Regards,
Simon

#22 lore raw

PATCH 8/11 sandbox: Add host filesystem

In reply to Simon Glass

This allows reading of files from the host filesystem in sandbox.

---
 Makefile               |    1 +
 disk/part.c            |   17 ++++++++++
 fs/fs.c                |   10 ++++++
 fs/sandbox/Makefile    |   47 +++++++++++++++++++++++++++
 fs/sandbox/sandboxfs.c |   83 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/fs.h           |    1 +
 include/sandboxfs.h    |   30 +++++++++++++++++
 7 files changed, 189 insertions(+), 0 deletions(-)
 create mode 100644 fs/sandbox/Makefile
 create mode 100644 fs/sandbox/sandboxfs.c
 create mode 100644 include/sandboxfs.h
Makefile +1 -0
index a7b6cd1..ee21b24 100644
@@ -268,6 +268,7 @@ LIBS-y += fs/libfs.o \
 	fs/fdos/libfdos.o \
 	fs/jffs2/libjffs2.o \
 	fs/reiserfs/libreiserfs.o \
+	fs/sandbox/libsandboxfs.o \
 	fs/ubifs/libubifs.o \
 	fs/yaffs2/libyaffs2.o \
 	fs/zfs/libzfs.o
disk/part.c +17 -0
index 7bdc90e..58a4563 100644
@@ -472,6 +472,23 @@ int get_device_and_partition(const char *ifname, const char *dev_part_str,
 	int part;
 	disk_partition_t tmpinfo;
 
+	/*
+	 * For now, we have a special case for sandbox, since there is no
+	 * real block device support.
+	 */
+	if (0 == strcmp(ifname, "host")) {
+		*dev_desc = NULL;
+		info->start = info->size =  info->blksz = 0;
+		info->bootable = 0;
+		strcpy((char *)info->type, BOOT_PART_TYPE);
+		strcpy((char *)info->name, "Sandbox host");
+#ifdef CONFIG_PARTITION_UUIDS
+		info->uuid[0] = 0;
+#endif
+
+		return 0;
+	}
+
 	/* If no dev_part_str, use bootdevice environment variable */
 	if (!dev_part_str || !strlen(dev_part_str) ||
 	    !strcmp(dev_part_str, "-"))
fs/fs.c +10 -0
index 95c882e..6f5063c 100644
@@ -20,6 +20,7 @@
 #include <ext4fs.h>
 #include <fat.h>
 #include <fs.h>
+#include <sandboxfs.h>
 #include <asm/io.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -78,6 +79,15 @@ static struct fstype_info fstypes[] = {
 		.read = ext4_read_file,
 	},
 #endif
+#ifdef CONFIG_SANDBOX
+	{
+		.fstype = FS_TYPE_SANDBOX,
+		.probe = sandbox_fs_set_blk_dev,
+		.close = sandbox_fs_close,
+		.ls = sandbox_fs_ls,
+		.read = fs_read_sandbox,
+	},
+#endif
 	{
 		.fstype = FS_TYPE_ANY,
 		.probe = fs_probe_unsupported,
fs/sandbox/Makefile new file +47 -0

47 lines not on this page · raw message

fs/sandbox/sandboxfs.c new file +83 -0

83 lines not on this page · raw message

include/fs.h +1 -0
index 4f30a38..b6d69e5 100644
@@ -21,6 +21,7 @@
 #define FS_TYPE_ANY	0
 #define FS_TYPE_FAT	1
 #define FS_TYPE_EXT	2
+#define FS_TYPE_SANDBOX	3
 
 /*
  * Tell the fs layer which block device an partition to use for future
include/sandboxfs.h new file +30 -0
new file mode 100644
index 0000000..f5213ac
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2012, Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __SANDBOX_FS__
+#define __SANDBOX_FS__
+
+int sandbox_fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
+
+long sandbox_fs_read_at(const char *filename, unsigned long pos,
+			     void *buffer, unsigned long maxsize);
+
+void sandbox_fs_close(void);
+int sandbox_fs_ls(const char *dirname);
+int fs_read_sandbox(const char *filename, void *buf, int offset, int len);
+
+#endif
Signature · 1 line
1.7.7.3
#23 lore raw

PATCH 8/11 sandbox: Add host filesystem

Quoted 3 lines · Simon Glass

This allows reading of files from the host filesystem in sandbox.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/599aa6be/attachment.pgp>
#24 lore raw

PATCH 9/11 sandbox: Add 'sb' command to access filesystem features

In reply to Simon Glass

The new 'sb' command is intended to deal with sandbox-specific features that have no parallel in other archs. This commit adds two sub-commands to list a directory and read a file from the host filesystem.

---
 README                   |    1 +
 common/Makefile          |    1 +
 common/cmd_sandbox.c     |   63 ++++++++++++++++++++++++++++++++++++++++++++++
 include/config_cmd_all.h |    1 +
 4 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_sandbox.c
README +1 -0
index 8dd3867..e54279e 100644
@@ -867,6 +867,7 @@ The following options need to be configured:
 		CONFIG_CMD_READ		* Read raw data from partition
 		CONFIG_CMD_REGINFO	* Register dump
 		CONFIG_CMD_RUN		  run command in env variable
+		CONFIG_CMD_SANDBOX	* sb command to access sandbox features
 		CONFIG_CMD_SAVES	* save S record dump
 		CONFIG_CMD_SCSI		* SCSI Support
 		CONFIG_CMD_SDRAM	* print SDRAM configuration information
common/Makefile +1 -0
index 54fcc81..719fc23 100644
@@ -152,6 +152,7 @@ COBJS-$(CONFIG_CMD_PXE) += cmd_pxe.o
 COBJS-$(CONFIG_CMD_READ) += cmd_read.o
 COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o
 COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o
+COBJS-$(CONFIG_SANDBOX) += cmd_sandbox.o
 COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o
 COBJS-$(CONFIG_CMD_SF) += cmd_sf.o
 COBJS-$(CONFIG_CMD_SCSI) += cmd_scsi.o
common/cmd_sandbox.c new file +63 -0

63 lines not on this page · raw message

include/config_cmd_all.h +1 -0
index e82f642..61c302e 100644
@@ -75,6 +75,7 @@
 #define CONFIG_CMD_RARP		/* rarpboot support		*/
 #define CONFIG_CMD_READ		/* Read data from partition	*/
 #define CONFIG_CMD_RUN		/* run command in env variable	*/
+#define CONFIG_CMD_SANDBOX	/* sb command to access sandbox features */
 #define CONFIG_CMD_SAVEENV	/* saveenv			*/
 #define CONFIG_CMD_SAVES	/* save S record dump		*/
 #define CONFIG_CMD_SCSI		/* SCSI Support			*/
Signature · 1 line
1.7.7.3
#25 lore raw

PATCH 9/11 sandbox: Add 'sb' command to access filesystem features

Quoted 5 lines · Simon Glass

The new 'sb' command is intended to deal with sandbox-specific features that have no parallel in other archs. This commit adds two sub-commands to list a directory and read a file from the host filesystem.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/e4b7b528/attachment.pgp>
#26 lore raw

PATCH 10/11 sandbox: Enable ext4 and fat filesystems

In reply to Simon Glass

These are useful for build-testing code, at least.

---
 include/configs/sandbox.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
include/configs/sandbox.h +7 -0
index 9f51a0b..2a45c7b 100644
@@ -32,6 +32,13 @@
 #define CONFIG_OF_LIBFDT
 #define CONFIG_LMB
 
+#define CONFIG_FS_FAT
+#define CONFIG_FS_EXT4
+#define CONFIG_EXT4_WRITE
+#define CONFIG_CMD_FAT
+#define CONFIG_CMD_EXT4
+#define CONFIG_CMD_EXT4_WRITE
+
 #define CONFIG_SYS_VSNPRINTF
 
 #define CONFIG_CMD_GPIO
Signature · 1 line
1.7.7.3
#27 lore raw

PATCH 10/11 sandbox: Enable ext4 and fat filesystems

Quoted 3 lines · Simon Glass

These are useful for build-testing code, at least.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/5104ec41/attachment.pgp>
#28 lore raw

PATCH 11/11 sandbox: config: Enable sandbox command

In reply to Simon Glass

The 'sb' command allows loading files from the host, and listing directories.

---
 include/configs/sandbox.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
include/configs/sandbox.h +2 -0
index 2a45c7b..406da43 100644
@@ -97,6 +97,8 @@
 #define CONFIG_SHA1
 #define CONFIG_SHA256
 
+#define CONFIG_CMD_SANDBOX
+
 #define CONFIG_BOOTARGS ""
 
 #define CONFIG_EXTRA_ENV_SETTINGS	"stdin=serial\0" \
Signature · 1 line
1.7.7.3
#29 lore raw

PATCH 11/11 sandbox: config: Enable sandbox command

Quoted 4 lines · Simon Glass

The 'sb' command allows loading files from the host, and listing directories.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130301/38c58502/attachment.pgp>
#30 lore raw

cover sandbox: Add filesystem support

In reply to Simon Glass

Hi,

Quoted 18 lines · Simon Glass

This series adds support for filesystems to sandbox. While we don't yet have access to host machine block devices, we can access files on the host through a new 'host' filesystem type and the new sandbox command 'sb'.

For example:

sb load host 0 1000 foo.bar

will load foo.bar from the host into memory at address 1000. The '0' parameter is the device number, currently unused.

While doing this work, I noticed that fs.c had code that probably belongs more in the filesystems themselves. So this series moves fat/ext4 code into those files. This removes most of the #ifdefs from this file, as well as the #defines of functions to 'unsupported'. Now there is a list of filesystems that we support, and if we don't find the one we need, we automatically fall back to the 'unsupported' one.

Quoted 3 lines

Finally, the ext4 write support is moved into a separate file since ext4fs.c was over 3500 lines and the write support seems entirely separate from the main function in that file.

Are there any comments on this series please? It adds new methods to the filesystem interface, and a new 'host' filesystem type for sandbox.

Regards,
Simon

Quoted 45 lines

Simon Glass (11):
ext4: Split write support into its own file
fs: Fully populate the filesystem method struct
fs: Use filesystem methods instead of switch()
fs: Tell probe functions where to put their results
fs: Use map_sysmem() on read
fs: Move ls and read methods into ext4, fat
sandbox: Add a way of obtaining directory listings
sandbox: Add host filesystem
sandbox: Add 'sb' command to access filesystem features
sandbox: Enable ext4 and fat filesystems
sandbox: config: Enable sandbox command

 Makefile                  |    1 +
 README                    |    1 +
 arch/sandbox/cpu/os.c     |  101 +++++
 common/Makefile           |    1 +
 common/cmd_sandbox.c      |   63 +++
 disk/part.c               |   17 +
 fs/ext4/Makefile          |    2 +-
 fs/ext4/ext4_write.c      |  996 +++++++++++++++++++++++++++++++++++++++++++++
 fs/ext4/ext4fs.c          |  962 +------------------------------------------
 fs/fat/fat.c              |   17 +
 fs/fs.c                   |  237 +++++-------
 fs/sandbox/Makefile       |   47 +++
 fs/sandbox/sandboxfs.c    |   83 ++++
 include/config_cmd_all.h  |    1 +
 include/configs/sandbox.h |    9 +
 include/ext4fs.h          |    3 +
 include/fat.h             |    2 +
 include/fs.h              |    1 +
 include/os.h              |   48 +++
 include/sandboxfs.h       |   30 ++
 20 files changed, 1533 insertions(+), 1089 deletions(-)
 create mode 100644 common/cmd_sandbox.c
 create mode 100644 fs/ext4/ext4_write.c
 create mode 100644 fs/sandbox/Makefile
 create mode 100644 fs/sandbox/sandboxfs.c
 create mode 100644 include/sandboxfs.h

--
1.7.7.3

#31 lore raw

cover sandbox: Add filesystem support

Quoted 21 lines · Simon Glass

Hi,

Quoted 18 lines · Simon Glass

This series adds support for filesystems to sandbox. While we don't yet have access to host machine block devices, we can access files on the host through a new 'host' filesystem type and the new sandbox command 'sb'.

For example:

sb load host 0 1000 foo.bar

will load foo.bar from the host into memory at address 1000. The '0' parameter is the device number, currently unused.

While doing this work, I noticed that fs.c had code that probably belongs more in the filesystems themselves. So this series moves fat/ext4 code into those files. This removes most of the #ifdefs from this file, as well as the #defines of functions to 'unsupported'. Now there is a list of filesystems that we support, and if we don't find the one we need, we automatically fall back to the 'unsupported' one.

Quoted 7 lines
Quoted 3 lines

Finally, the ext4 write support is moved into a separate file since ext4fs.c was over 3500 lines and the write support seems entirely separate from the main function in that file.

Are there any comments on this series please? It adds new methods to the filesystem interface, and a new 'host' filesystem type for sandbox.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130304/18c22334/attachment.pgp>