X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=fs%2Ffs.c;h=7a4020607a3950e76ca46f53dbc4aa6296f2b55d;hb=5a1a8a63be8f7262a300eddafb18020926b12fb6;hp=adae98d021eef1b2c4640a12aef9b0affa43b9d1;hpb=27f622d56876f01e11a74b292e52a94451144cff;p=platform%2Fkernel%2Fu-boot.git diff --git a/fs/fs.c b/fs/fs.c index adae98d..7a40206 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -3,9 +3,15 @@ * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. */ +#define LOG_CATEGORY LOGC_CORE + +#include #include #include #include +#include +#include +#include #include #include #include @@ -17,18 +23,20 @@ #include #include #include +#include +#include DECLARE_GLOBAL_DATA_PTR; static struct blk_desc *fs_dev_desc; static int fs_dev_part; -static disk_partition_t fs_partition; +static struct disk_partition fs_partition; static int fs_type = FS_TYPE_ANY; static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc, - disk_partition_t *fs_partition) + struct disk_partition *fs_partition) { - printf("** Unrecognized filesystem type **\n"); + log_err("** Unrecognized filesystem type **\n"); return -1; } @@ -53,6 +61,9 @@ static int fs_ls_generic(const char *dirname) if (dent->type == FS_DT_DIR) { printf(" %s/\n", dent->name); ndirs++; + } else if (dent->type == FS_DT_LNK) { + printf(" %s\n", dent->name); + nfiles++; } else { printf(" %8lld %s\n", dent->size, dent->name); nfiles++; @@ -90,6 +101,11 @@ static inline int fs_write_unsupported(const char *filename, void *buf, return -1; } +static inline int fs_ln_unsupported(const char *filename, const char *target) +{ + return -1; +} + static inline void fs_close_unsupported(void) { } @@ -128,7 +144,7 @@ struct fstype_info { */ bool null_dev_desc_ok; int (*probe)(struct blk_desc *fs_dev_desc, - disk_partition_t *fs_partition); + struct disk_partition *fs_partition); int (*ls)(const char *dirname); int (*exists)(const char *filename); int (*size)(const char *filename, loff_t *size); @@ -154,6 +170,7 @@ struct fstype_info { void (*closedir)(struct fs_dir_stream *dirs); int (*unlink)(const char *filename); int (*mkdir)(const char *dirname); + int (*ln)(const char *filename, const char *target); }; static struct fstype_info fstypes[] = { @@ -168,7 +185,7 @@ static struct fstype_info fstypes[] = { .exists = fat_exists, .size = fat_size, .read = fat_read_file, -#ifdef CONFIG_FAT_WRITE +#if CONFIG_IS_ENABLED(FAT_WRITE) .write = file_fat_write, .unlink = fat_unlink, .mkdir = fat_mkdir, @@ -181,9 +198,11 @@ static struct fstype_info fstypes[] = { .opendir = fat_opendir, .readdir = fat_readdir, .closedir = fat_closedir, + .ln = fs_ln_unsupported, }, #endif -#ifdef CONFIG_FS_EXT4 + +#if CONFIG_IS_ENABLED(FS_EXT4) { .fstype = FS_TYPE_EXT, .name = "ext4", @@ -196,8 +215,10 @@ static struct fstype_info fstypes[] = { .read = ext4_read_file, #ifdef CONFIG_CMD_EXT4_WRITE .write = ext4_write_file, + .ln = ext4fs_create_link, #else .write = fs_write_unsupported, + .ln = fs_ln_unsupported, #endif .uuid = ext4fs_uuid, .opendir = fs_opendir_unsupported, @@ -221,6 +242,7 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .ln = fs_ln_unsupported, }, #endif #ifdef CONFIG_CMD_UBIFS @@ -239,6 +261,7 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .ln = fs_ln_unsupported, }, #endif #ifdef CONFIG_FS_BTRFS @@ -257,6 +280,28 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .ln = fs_ln_unsupported, + }, +#endif +#if IS_ENABLED(CONFIG_FS_SQUASHFS) + { + .fstype = FS_TYPE_SQUASHFS, + .name = "squashfs", + .null_dev_desc_ok = false, + .probe = sqfs_probe, + .opendir = sqfs_opendir, + .readdir = sqfs_readdir, + .ls = fs_ls_generic, + .read = sqfs_read, + .size = sqfs_size, + .close = sqfs_close, + .closedir = sqfs_closedir, + .exists = sqfs_exists, + .uuid = fs_uuid_unsupported, + .write = fs_write_unsupported, + .ln = fs_ln_unsupported, + .unlink = fs_unlink_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif { @@ -274,6 +319,7 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .ln = fs_ln_unsupported, }, }; @@ -292,6 +338,19 @@ static struct fstype_info *fs_get_info(int fstype) } /** + * fs_get_type() - Get type of current filesystem + * + * Return: filesystem type + * + * Returns filesystem type representing the current filesystem, or + * FS_TYPE_ANY for any unrecognised filesystem. + */ +int fs_get_type(void) +{ + return fs_type; +} + +/** * fs_get_type_name() - Get type of current filesystem * * Return: Pointer to filesystem name @@ -365,6 +424,7 @@ int fs_set_blk_dev_with_part(struct blk_desc *desc, int part) for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) { if (!info->probe(fs_dev_desc, &fs_partition)) { fs_type = info->fstype; + fs_dev_part = part; return 0; } } @@ -372,7 +432,7 @@ int fs_set_blk_dev_with_part(struct blk_desc *desc, int part) return -1; } -static void fs_close(void) +void fs_close(void) { struct fstype_info *info = fs_get_info(fs_type); @@ -396,7 +456,6 @@ int fs_ls(const char *dirname) ret = info->ls(dirname); - fs_type = FS_TYPE_ANY; fs_close(); return ret; @@ -428,13 +487,56 @@ int fs_size(const char *filename, loff_t *size) return ret; } -int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, - loff_t *actread) +#ifdef CONFIG_LMB +/* Check if a file may be read to the given address */ +static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset, + loff_t len, struct fstype_info *info) +{ + struct lmb lmb; + int ret; + loff_t size; + loff_t read_len; + + /* get the actual size of the file */ + ret = info->size(filename, &size); + if (ret) + return ret; + if (offset >= size) { + /* offset >= EOF, no bytes will be written */ + return 0; + } + read_len = size - offset; + + /* limit to 'len' if it is smaller */ + if (len && len < read_len) + read_len = len; + + lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); + lmb_dump_all(&lmb); + + if (lmb_alloc_addr(&lmb, addr, read_len) == addr) + return 0; + + log_err("** Reading file would overwrite reserved memory **\n"); + return -ENOSPC; +} +#endif + +static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, + int do_lmb_check, loff_t *actread) { struct fstype_info *info = fs_get_info(fs_type); void *buf; int ret; +#ifdef CONFIG_LMB + if (do_lmb_check) { + ret = fs_read_lmb_check(filename, addr, offset, len, info); + if (ret) + return ret; + } +#endif + /* * We don't actually know how many bytes are being read, since len==0 * means read the whole file. @@ -445,12 +547,18 @@ 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) - debug("** %s shorter than offset + len **\n", filename); + log_debug("** %s shorter than offset + len **\n", filename); fs_close(); return ret; } +int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, + loff_t *actread) +{ + return _fs_read(filename, addr, offset, len, 0, actread); +} + int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, loff_t *actwrite) { @@ -463,7 +571,7 @@ int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, unmap_sysmem(buf); if (ret < 0 && len != *actwrite) { - printf("** Unable to write file %s **\n", filename); + log_err("** Unable to write file %s **\n", filename); ret = -1; } fs_close(); @@ -531,7 +639,6 @@ int fs_unlink(const char *filename) ret = info->unlink(filename); - fs_type = FS_TYPE_ANY; fs_close(); return ret; @@ -545,14 +652,29 @@ int fs_mkdir(const char *dirname) ret = info->mkdir(dirname); - fs_type = FS_TYPE_ANY; fs_close(); return ret; } -int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], - int fstype) +int fs_ln(const char *fname, const char *target) +{ + struct fstype_info *info = fs_get_info(fs_type); + int ret; + + ret = info->ln(fname, target); + + if (ret < 0) { + log_err("** Unable to create link %s -> %s **\n", fname, target); + ret = -1; + } + fs_close(); + + return ret; +} + +int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], + int fstype) { loff_t size; @@ -570,8 +692,8 @@ int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], return 0; } -int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], - int fstype) +int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], + int fstype) { unsigned long addr; const char *addr_str; @@ -621,10 +743,16 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], pos = 0; time = get_timer(0); - ret = fs_read(filename, addr, pos, bytes, &len_read); + ret = _fs_read(filename, addr, pos, bytes, 1, &len_read); time = get_timer(time); - if (ret < 0) + if (ret < 0) { + log_err("Failed to load '%s'\n", filename); return 1; + } + + if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) + efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "", + (argc > 4) ? argv[4] : ""); printf("%llu bytes read in %lu ms", len_read, time); if (time > 0) { @@ -640,8 +768,8 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], return 0; } -int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], - int fstype) +int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], + int fstype) { if (argc < 2) return CMD_RET_USAGE; @@ -666,8 +794,8 @@ int file_exists(const char *dev_type, const char *dev_part, const char *file, return fs_exists(file); } -int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], - int fstype) +int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], + int fstype) { unsigned long addr; const char *filename; @@ -708,8 +836,8 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], return 0; } -int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], - int fstype) +int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], + int fstype) { int ret; char uuid[37]; @@ -733,7 +861,7 @@ int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], return CMD_RET_SUCCESS; } -int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct fstype_info *info; @@ -750,10 +878,12 @@ int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) else printf("%s\n", info->name); + fs_close(); + return CMD_RET_SUCCESS; } -int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], +int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], int fstype) { if (argc != 4) @@ -768,7 +898,7 @@ int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], return 0; } -int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], +int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], int fstype) { int ret; @@ -781,9 +911,44 @@ int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], ret = fs_mkdir(argv[3]); if (ret) { - printf("** Unable to create a directory \"%s\" **\n", argv[3]); + log_err("** Unable to create a directory \"%s\" **\n", argv[3]); return 1; } return 0; } + +int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], + int fstype) +{ + if (argc != 5) + return CMD_RET_USAGE; + + if (fs_set_blk_dev(argv[1], argv[2], fstype)) + return 1; + + if (fs_ln(argv[3], argv[4])) + return 1; + + return 0; +} + +int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) +{ + struct fstype_info *drv = fstypes; + const int n_ents = ARRAY_SIZE(fstypes); + struct fstype_info *entry; + int i = 0; + + puts("Supported filesystems"); + for (entry = drv; entry != drv + n_ents; entry++) { + if (entry->fstype != FS_TYPE_ANY) { + printf("%c %s", i ? ',' : ':', entry->name); + i++; + } + } + if (!i) + puts(": "); + puts("\n"); + return CMD_RET_SUCCESS; +}