Explorar o código

fs: Move ls and read methods into ext4, fat

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.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@ti.com>
Simon Glass %!s(int64=12) %!d(string=hai) anos
pai
achega
e6d5241534
Modificáronse 5 ficheiros con 67 adicións e 110 borrados
  1. 37 0
      fs/ext4/ext4fs.c
  2. 17 0
      fs/fat/fat.c
  3. 8 110
      fs/fs.c
  4. 3 0
      include/ext4fs.h
  5. 2 0
      include/fat.h

+ 37 - 0
fs/ext4/ext4fs.c

@@ -191,3 +191,40 @@ int ext4fs_read(char *buf, unsigned len)
 
 
 	return ext4fs_read_file(ext4fs_file, 0, len, buf);
 	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;
+}

+ 17 - 0
fs/fat/fat.c

@@ -1260,3 +1260,20 @@ long file_fat_read(const char *filename, void *buffer, unsigned long maxsize)
 {
 {
 	return file_fat_read_at(filename, 0, buffer, 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)
+{
+}

+ 8 - 110
fs/fs.c

@@ -50,110 +50,6 @@ static inline void fs_close_unsupported(void)
 {
 {
 }
 }
 
 
-#ifdef CONFIG_FS_FAT
-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);
-}
-
-static void fs_close_fat(void)
-{
-}
-
-#define fs_ls_fat file_fat_ls
-
-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, buf, len);
-	if (len_read == -1) {
-		printf("** Unable to read file %s **\n", filename);
-		return -1;
-	}
-
-	return len_read;
-}
-#else
-static inline int fs_probe_fat(void)
-{
-	return -1;
-}
-
-static inline void fs_close_fat(void)
-{
-}
-
-#define fs_ls_fat fs_ls_unsupported
-#define fs_read_fat fs_read_unsupported
-#endif
-
-#ifdef CONFIG_FS_EXT4
-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);
-
-	if (!ext4fs_mount(fs_partition->size)) {
-		ext4fs_close();
-		return -1;
-	}
-
-	return 0;
-}
-
-static void fs_close_ext(void)
-{
-	ext4fs_close();
-}
-
-#define fs_ls_ext ext4fs_ls
-
-static int fs_read_ext(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);
-		ext4fs_close();
-		return -1;
-	}
-
-	if (len == 0)
-		len = file_len;
-
-	len_read = ext4fs_read(buf, len);
-	ext4fs_close();
-
-	if (len_read != len) {
-		printf("** Unable to read file %s **\n", filename);
-		return -1;
-	}
-
-	return len_read;
-}
-#else
-static inline int fs_probe_ext(void)
-{
-	return -1;
-}
-
-static inline void fs_close_ext(void)
-{
-}
-
-#define fs_ls_ext fs_ls_unsupported
-#define fs_read_ext fs_read_unsupported
-#endif
-
 struct fstype_info {
 struct fstype_info {
 	int fstype;
 	int fstype;
 	int (*probe)(block_dev_desc_t *fs_dev_desc,
 	int (*probe)(block_dev_desc_t *fs_dev_desc,
@@ -167,19 +63,19 @@ static struct fstype_info fstypes[] = {
 #ifdef CONFIG_FS_FAT
 #ifdef CONFIG_FS_FAT
 	{
 	{
 		.fstype = FS_TYPE_FAT,
 		.fstype = FS_TYPE_FAT,
-		.probe = fs_probe_fat,
-		.close = fs_close_fat,
+		.probe = fat_set_blk_dev,
+		.close = fat_close,
 		.ls = file_fat_ls,
 		.ls = file_fat_ls,
-		.read = fs_read_fat,
+		.read = fat_read_file,
 	},
 	},
 #endif
 #endif
 #ifdef CONFIG_FS_EXT4
 #ifdef CONFIG_FS_EXT4
 	{
 	{
 		.fstype = FS_TYPE_EXT,
 		.fstype = FS_TYPE_EXT,
-		.probe = fs_probe_ext,
-		.close = fs_close_ext,
+		.probe = ext4fs_probe,
+		.close = ext4fs_close,
 		.ls = ext4fs_ls,
 		.ls = ext4fs_ls,
-		.read = fs_read_ext,
+		.read = ext4_read_file,
 	},
 	},
 #endif
 #endif
 	{
 	{
@@ -248,6 +144,7 @@ static void fs_close(void)
 	struct fstype_info *info = fs_get_info(fs_type);
 	struct fstype_info *info = fs_get_info(fs_type);
 
 
 	info->close();
 	info->close();
+
 	fs_type = FS_TYPE_ANY;
 	fs_type = FS_TYPE_ANY;
 }
 }
 
 
@@ -259,6 +156,7 @@ int fs_ls(const char *dirname)
 
 
 	ret = info->ls(dirname);
 	ret = info->ls(dirname);
 
 
+	fs_type = FS_TYPE_ANY;
 	fs_close();
 	fs_close();
 
 
 	return ret;
 	return ret;

+ 3 - 0
include/ext4fs.h

@@ -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);
 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);
 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);
 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
 #endif

+ 2 - 0
include/fat.h

@@ -213,4 +213,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 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 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_ */
 #endif /* _FAT_H_ */