[U-Boot] [PATCH v5 4/7] fs: ext4: constify the buffer passed to write functions
Jean-Jacques Hiblot
jjhiblot at ti.com
Wed Feb 13 10:48:15 UTC 2019
There is no need to modify the buffer passed to ext4fs_write_file().
The memset() call is not required here and was likely copied from the
equivalent part of the ext4fs_read_file() function where we do need it.
Signed-off-by: Jean-Jacques Hiblot <jjhiblot at ti.com>
Reviewed-by: Tom Rini <trini at konsulko.com>
---
Changes in v5: None
Changes in v4:
- replaced u64 and u32 with uint64_t and uint32_t
Changes in v3:
- reworded commit log
Changes in v2: None
fs/ext4/ext4_common.c | 2 +-
fs/ext4/ext4_common.h | 2 +-
fs/ext4/ext4_write.c | 11 +++++------
include/ext4fs.h | 2 +-
4 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 67e2471bd3..1ff2cd28a6 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -190,7 +190,7 @@ uint32_t ext4fs_div_roundup(uint32_t size, uint32_t n)
return res;
}
-void put_ext4(uint64_t off, void *buf, uint32_t size)
+void put_ext4(uint64_t off, const void *buf, uint32_t size)
{
uint64_t startblock;
uint64_t remainder;
diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h
index 1ee81ab7ce..4dff1914d9 100644
--- a/fs/ext4/ext4_common.h
+++ b/fs/ext4/ext4_common.h
@@ -72,7 +72,7 @@ int ext4fs_iget(int inode_no, struct ext2_inode *inode);
void ext4fs_allocate_blocks(struct ext2_inode *file_inode,
unsigned int total_remaining_blocks,
unsigned int *total_no_of_block);
-void put_ext4(uint64_t off, void *buf, uint32_t size);
+void put_ext4(uint64_t off, const void *buf, uint32_t size);
struct ext2_block_group *ext4fs_get_group_descriptor
(const struct ext_filesystem *fs, uint32_t bg_idx);
uint64_t ext4fs_bg_get_block_id(const struct ext2_block_group *bg,
diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index 1de29236f0..51ca1c0916 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -752,7 +752,7 @@ void ext4fs_deinit(void)
* contigous sectors as ext4fs_read_file
*/
static int ext4fs_write_file(struct ext2_inode *file_inode,
- int pos, unsigned int len, char *buf)
+ int pos, unsigned int len, const char *buf)
{
int i;
int blockcnt;
@@ -764,7 +764,7 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
int delayed_start = 0;
int delayed_extent = 0;
int delayed_next = 0;
- char *delayed_buf = NULL;
+ const char *delayed_buf = NULL;
/* Adjust len so it we can't read past the end of the file. */
if (len > filesize)
@@ -816,7 +816,6 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
(uint32_t) delayed_extent);
previous_block_number = -1;
}
- memset(buf, 0, fs->blksz - skipfirst);
}
buf += fs->blksz - skipfirst;
}
@@ -830,8 +829,8 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,
return len;
}
-int ext4fs_write(const char *fname, unsigned char *buffer,
- unsigned long sizebytes)
+int ext4fs_write(const char *fname, const char *buffer,
+ unsigned long sizebytes)
{
int ret = 0;
struct ext2_inode *file_inode = NULL;
@@ -950,7 +949,7 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
if (ext4fs_put_metadata(temp_ptr, itable_blkno))
goto fail;
/* copy the file content into data blocks */
- if (ext4fs_write_file(file_inode, 0, sizebytes, (char *)buffer) == -1) {
+ if (ext4fs_write_file(file_inode, 0, sizebytes, buffer) == -1) {
printf("Error in copying content\n");
/* FIXME: Deallocate data blocks */
goto fail;
diff --git a/include/ext4fs.h b/include/ext4fs.h
index bcf440364e..d4dcefaa96 100644
--- a/include/ext4fs.h
+++ b/include/ext4fs.h
@@ -128,7 +128,7 @@ extern int gindex;
int ext4fs_init(void);
void ext4fs_deinit(void);
int ext4fs_filename_unlink(char *filename);
-int ext4fs_write(const char *fname, unsigned char *buffer,
+int ext4fs_write(const char *fname, const char *buffer,
unsigned long sizebytes);
int ext4_write_file(const char *filename, void *buf, loff_t offset, loff_t len,
loff_t *actwrite);
--
2.17.1
More information about the U-Boot
mailing list