summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/ext4fs.c8
-rw-r--r--fs/fat/fat.c18
-rw-r--r--fs/fs.c57
-rw-r--r--fs/sandbox/sandboxfs.c8
-rw-r--r--fs/ubifs/Makefile2
-rw-r--r--fs/yaffs2/Makefile9
6 files changed, 85 insertions, 17 deletions
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 735b256417..417ce7b63b 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -174,6 +174,14 @@ int ext4fs_ls(const char *dirname)
return 0;
}
+int ext4fs_exists(const char *filename)
+{
+ int file_len;
+
+ file_len = ext4fs_open(filename);
+ return file_len >= 0;
+}
+
int ext4fs_read(char *buf, unsigned len)
{
if (ext4fs_root == NULL || ext4fs_file == NULL)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index b41d62e3c3..54f42eae0d 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -808,7 +808,7 @@ __u8 do_fat_read_at_block[MAX_CLUSTSIZE]
long
do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
- unsigned long maxsize, int dols)
+ unsigned long maxsize, int dols, int dogetsize)
{
char fnamecopy[2048];
boot_sector bs;
@@ -1152,7 +1152,10 @@ rootdir_done:
subname = nextname;
}
- ret = get_contents(mydata, dentptr, pos, buffer, maxsize);
+ if (dogetsize)
+ ret = FAT2CPU32(dentptr->size);
+ else
+ ret = get_contents(mydata, dentptr, pos, buffer, maxsize);
debug("Size: %d, got: %ld\n", FAT2CPU32(dentptr->size), ret);
exit:
@@ -1163,7 +1166,7 @@ exit:
long
do_fat_read(const char *filename, void *buffer, unsigned long maxsize, int dols)
{
- return do_fat_read_at(filename, 0, buffer, maxsize, dols);
+ return do_fat_read_at(filename, 0, buffer, maxsize, dols, 0);
}
int file_fat_detectfs(void)
@@ -1233,11 +1236,18 @@ int file_fat_ls(const char *dir)
return do_fat_read(dir, NULL, 0, LS_YES);
}
+int fat_exists(const char *filename)
+{
+ int sz;
+ sz = do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1);
+ return sz >= 0;
+}
+
long file_fat_read_at(const char *filename, unsigned long pos, void *buffer,
unsigned long maxsize)
{
printf("reading %s\n", filename);
- return do_fat_read_at(filename, pos, buffer, maxsize, LS_NO);
+ return do_fat_read_at(filename, pos, buffer, maxsize, LS_NO, 0);
}
long file_fat_read(const char *filename, void *buffer, unsigned long maxsize)
diff --git a/fs/fs.c b/fs/fs.c
index be1855d129..79d432d58f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -41,6 +41,11 @@ static inline int fs_ls_unsupported(const char *dirname)
return -1;
}
+static inline int fs_exists_unsupported(const char *filename)
+{
+ return 0;
+}
+
static inline int fs_read_unsupported(const char *filename, void *buf,
int offset, int len)
{
@@ -59,9 +64,19 @@ static inline void fs_close_unsupported(void)
struct fstype_info {
int fstype;
+ /*
+ * Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This
+ * should be false in most cases. For "virtual" filesystems which
+ * aren't based on a U-Boot block device (e.g. sandbox), this can be
+ * set to true. This should also be true for the dumm entry at the end
+ * of fstypes[], since that is essentially a "virtual" (non-existent)
+ * filesystem.
+ */
+ bool null_dev_desc_ok;
int (*probe)(block_dev_desc_t *fs_dev_desc,
disk_partition_t *fs_partition);
int (*ls)(const char *dirname);
+ int (*exists)(const char *filename);
int (*read)(const char *filename, void *buf, int offset, int len);
int (*write)(const char *filename, void *buf, int offset, int len);
void (*close)(void);
@@ -71,36 +86,46 @@ static struct fstype_info fstypes[] = {
#ifdef CONFIG_FS_FAT
{
.fstype = FS_TYPE_FAT,
+ .null_dev_desc_ok = false,
.probe = fat_set_blk_dev,
.close = fat_close,
.ls = file_fat_ls,
+ .exists = fat_exists,
.read = fat_read_file,
+ .write = fs_write_unsupported,
},
#endif
#ifdef CONFIG_FS_EXT4
{
.fstype = FS_TYPE_EXT,
+ .null_dev_desc_ok = false,
.probe = ext4fs_probe,
.close = ext4fs_close,
.ls = ext4fs_ls,
+ .exists = ext4fs_exists,
.read = ext4_read_file,
+ .write = fs_write_unsupported,
},
#endif
#ifdef CONFIG_SANDBOX
{
.fstype = FS_TYPE_SANDBOX,
+ .null_dev_desc_ok = true,
.probe = sandbox_fs_set_blk_dev,
.close = sandbox_fs_close,
.ls = sandbox_fs_ls,
+ .exists = sandbox_fs_exists,
.read = fs_read_sandbox,
.write = fs_write_sandbox,
},
#endif
{
.fstype = FS_TYPE_ANY,
+ .null_dev_desc_ok = true,
.probe = fs_probe_unsupported,
.close = fs_close_unsupported,
.ls = fs_ls_unsupported,
+ .exists = fs_exists_unsupported,
.read = fs_read_unsupported,
.write = fs_write_unsupported,
},
@@ -150,6 +175,9 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
fstype != info->fstype)
continue;
+ if (!fs_dev_desc && !info->null_dev_desc_ok)
+ continue;
+
if (!info->probe(fs_dev_desc, &fs_partition)) {
fs_type = info->fstype;
return 0;
@@ -182,6 +210,19 @@ int fs_ls(const char *dirname)
return ret;
}
+int fs_exists(const char *filename)
+{
+ int ret;
+
+ struct fstype_info *info = fs_get_info(fs_type);
+
+ ret = info->exists(filename);
+
+ fs_close();
+
+ return ret;
+}
+
int fs_read(const char *filename, ulong addr, int offset, int len)
{
struct fstype_info *info = fs_get_info(fs_type);
@@ -212,16 +253,11 @@ int fs_write(const char *filename, ulong addr, int offset, int len)
void *buf;
int ret;
- /*
- * 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->write(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) {
+ if (ret >= 0 && ret != len) {
printf("** Unable to write file %s **\n", filename);
ret = -1;
}
@@ -312,6 +348,15 @@ int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
return 0;
}
+int file_exists(const char *dev_type, const char *dev_part, const char *file,
+ int fstype)
+{
+ if (fs_set_blk_dev(dev_type, dev_part, fstype))
+ return 0;
+
+ return fs_exists(file);
+}
+
int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
int fstype)
{
diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c
index dd028da8e3..85079788c9 100644
--- a/fs/sandbox/sandboxfs.c
+++ b/fs/sandbox/sandboxfs.c
@@ -72,6 +72,14 @@ int sandbox_fs_ls(const char *dirname)
return 0;
}
+int sandbox_fs_exists(const char *filename)
+{
+ ssize_t sz;
+
+ sz = os_get_filesize(filename);
+ return sz >= 0;
+}
+
void sandbox_fs_close(void)
{
}
diff --git a/fs/ubifs/Makefile b/fs/ubifs/Makefile
index 389b0e37e7..6b1a9a5b00 100644
--- a/fs/ubifs/Makefile
+++ b/fs/ubifs/Makefile
@@ -15,4 +15,4 @@ obj-y += tnc.o tnc_misc.o debug.o crc16.o budget.o
obj-y += log.o orphan.o recovery.o replay.o
# SEE README.arm-unaligned-accesses
-$(obj)super.o: CFLAGS += $(PLATFORM_NO_UNALIGNED)
+CFLAGS_super.o := $(PLATFORM_NO_UNALIGNED)
diff --git a/fs/yaffs2/Makefile b/fs/yaffs2/Makefile
index d811287ddb..45ff7458c6 100644
--- a/fs/yaffs2/Makefile
+++ b/fs/yaffs2/Makefile
@@ -24,9 +24,6 @@ obj-y := \
yaffs_summary.o yaffs_tagscompat.o yaffs_verify.o yaffs_yaffs1.o \
yaffs_yaffs2.o yaffs_mtdif.o yaffs_mtdif2.o
-YCFLAGS = -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM
-YCFLAGS += -DCONFIG_YAFFS_YAFFS2 -DNO_Y_INLINE
-YCFLAGS += -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES
-
-CFLAGS += $(YCFLAGS)
-CPPFLAGS += $(YCFLAGS)
+ccflags-y = -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM \
+ -DCONFIG_YAFFS_YAFFS2 -DNO_Y_INLINE \
+ -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES