Skip to contentSkip to conversation

fs: ext4: Change the Settings of file permissions

PATCH In review Jixiong Hu 2 participants 2 messages Mar 19, 2024 – Apr 10, 2024 ext4 file system

lore
Share & tools
lore

Jixiong Hu

author
#0 lore raw

PATCH 1/1 fs: ext4: Change the Settings of file permissions

When a file is created in the linux and corresponding file permission is set, if the file needs to be modified in uboot during the startup process, the modified file permission will be reset to 755. Therefore, when the ext4fs_write() function is called, if the file already exists, the file permission of the new file is equal to the file permission of the existing file.

---
 fs/ext4/ext4_write.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
fs/ext4/ext4_write.c +19 -2
index ea4c5d4157..c0b4803700 100644
@@ -847,6 +847,7 @@ int ext4fs_write(const char *fname, const char *buffer,
 {
 	int ret = 0;
 	struct ext2_inode *file_inode = NULL;
+	struct ext2_inode *existing_file_inode = NULL;
 	unsigned char *inode_buffer = NULL;
 	int parent_inodeno;
 	int inodeno;
@@ -900,6 +901,16 @@ int ext4fs_write(const char *fname, const char *buffer,
 	/* check if the filename is already present in root */
 	existing_file_inodeno = ext4fs_filename_unlink(filename);
 	if (existing_file_inodeno != -1) {
+		existing_file_inode = (struct ext2_inode *)zalloc(fs->inodesz);
+		if (!existing_file_inode)
+			goto fail;
+		ret = ext4fs_iget(existing_file_inodeno, existing_file_inode);
+		if (ret)
+		{
+			free(existing_file_inode);
+			goto fail;
+		}
+
 		ret = ext4fs_delete_file(existing_file_inodeno);
 		fs->first_pass_bbmap = 0;
 		fs->curr_blkno = 0;
@@ -948,9 +959,15 @@ int ext4fs_write(const char *fname, const char *buffer,
 			sizebytes = 0;
 		}
 	} else {
-		file_inode->mode = cpu_to_le16(S_IFREG | S_IRWXU | S_IRGRP |
-					       S_IROTH | S_IXGRP | S_IXOTH);
+		if(existing_file_inode) {
+			file_inode->mode = existing_file_inode->mode;
+		} else {
+			file_inode->mode = cpu_to_le16(S_IFREG | S_IRWXU | S_IRGRP |
+						       S_IROTH | S_IXGRP | S_IXOTH);
+		}
 	}
+	if(existing_file_inode)
+		free(existing_file_inode);
 	/* ToDo: Update correct time */
 	file_inode->mtime = cpu_to_le32(timestamp);
 	file_inode->atime = cpu_to_le32(timestamp);
Signature · 1 line
2.18.0
#1 lore raw
Quoted 8 lines · Jixiong Hu

When a file is created in the linux and corresponding file permission is set, if the file needs to be modified in uboot during the startup process, the modified file permission will be reset to 755. Therefore, when the ext4fs_write() function is called, if the file already exists, the file permission of the new file is equal to the file permission of the existing file.

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom