]> git.sur5r.net Git - u-boot/blobdiff - fs/fs.c
Prepare v2018.03-rc3
[u-boot] / fs / fs.c
diff --git a/fs/fs.c b/fs/fs.c
index fc0c953fcbd13a6089a6dbdaade234c104710261..6155cb1daf34352c95f3d5270e5cf7b8d7b0e32f 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -14,6 +14,7 @@
 #include <fs.h>
 #include <sandboxfs.h>
 #include <ubifs_uboot.h>
+#include <btrfs.h>
 #include <asm/io.h>
 #include <div64.h>
 #include <linux/math64.h>
@@ -37,6 +38,35 @@ static inline int fs_ls_unsupported(const char *dirname)
        return -1;
 }
 
+/* generic implementation of ls in terms of opendir/readdir/closedir */
+__maybe_unused
+static int fs_ls_generic(const char *dirname)
+{
+       struct fs_dir_stream *dirs;
+       struct fs_dirent *dent;
+       int nfiles = 0, ndirs = 0;
+
+       dirs = fs_opendir(dirname);
+       if (!dirs)
+               return -errno;
+
+       while ((dent = fs_readdir(dirs))) {
+               if (dent->type == FS_DT_DIR) {
+                       printf("            %s/\n", dent->name);
+                       ndirs++;
+               } else {
+                       printf(" %8lld   %s\n", dent->size, dent->name);
+                       nfiles++;
+               }
+       }
+
+       fs_closedir(dirs);
+
+       printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs);
+
+       return 0;
+}
+
 static inline int fs_exists_unsupported(const char *filename)
 {
        return 0;
@@ -123,7 +153,7 @@ static struct fstype_info fstypes[] = {
                .null_dev_desc_ok = false,
                .probe = fat_set_blk_dev,
                .close = fat_close,
-               .ls = file_fat_ls,
+               .ls = fs_ls_generic,
                .exists = fat_exists,
                .size = fat_size,
                .read = fat_read_file,
@@ -133,7 +163,9 @@ static struct fstype_info fstypes[] = {
                .write = fs_write_unsupported,
 #endif
                .uuid = fs_uuid_unsupported,
-               .opendir = fs_opendir_unsupported,
+               .opendir = fat_opendir,
+               .readdir = fat_readdir,
+               .closedir = fat_closedir,
        },
 #endif
 #ifdef CONFIG_FS_EXT4
@@ -187,6 +219,22 @@ static struct fstype_info fstypes[] = {
                .uuid = fs_uuid_unsupported,
                .opendir = fs_opendir_unsupported,
        },
+#endif
+#ifdef CONFIG_FS_BTRFS
+       {
+               .fstype = FS_TYPE_BTRFS,
+               .name = "btrfs",
+               .null_dev_desc_ok = false,
+               .probe = btrfs_probe,
+               .close = btrfs_close,
+               .ls = btrfs_ls,
+               .exists = btrfs_exists,
+               .size = btrfs_size,
+               .read = btrfs_read,
+               .write = fs_write_unsupported,
+               .uuid = btrfs_uuid,
+               .opendir = fs_opendir_unsupported,
+       },
 #endif
        {
                .fstype = FS_TYPE_ANY,
@@ -359,7 +407,7 @@ int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
 
        /* If we requested a specific number of bytes, check we got it */
        if (ret == 0 && len && *actread != len)
-               printf("** %s shorter than offset + len **\n", filename);
+               debug("** %s shorter than offset + len **\n", filename);
        fs_close();
 
        return ret;