shithub: lwext4

Download patch

ref: a1a24db03c42c2f6af2aa97dc9a145dbb03559e2
parent: 5ddffb5961175beb6f5946b13cbc977662955115
author: gkostka <[email protected]>
date: Fri Oct 9 13:28:40 EDT 2015

Fix const correctness

--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -1925,18 +1925,14 @@
 	return r;
 }
 
-int ext4_setxattr(char *path,
-		   char *name,
-		   size_t name_len,
-		   void *data,
-		   size_t data_size,
-		   bool replace)
+int ext4_setxattr(const char *path, const char *name, size_t name_len,
+		  const void *data, size_t data_size, bool replace)
 {
 	int r = EOK;
 	ext4_file f;
 	uint32_t inode;
 	uint8_t name_index;
-	char *dissected_name = NULL;
+	const char *dissected_name = NULL;
 	size_t dissected_len = 0;
 	struct ext4_xattr_ref xattr_ref;
 	struct ext4_inode_ref inode_ref;
@@ -1968,10 +1964,8 @@
 		goto Finish;
 	}
 
-	r = ext4_fs_set_xattr(&xattr_ref, name_index,
-				dissected_name, dissected_len,
-				data, data_size,
-				replace);
+	r = ext4_fs_set_xattr(&xattr_ref, name_index, dissected_name,
+			dissected_len, data, data_size, replace);
 
 	ext4_fs_put_xattr_ref(&xattr_ref);
 	ext4_fs_put_inode_ref(&inode_ref);
@@ -1980,18 +1974,14 @@
 	return r;
 }
 
-int ext4_getxattr(char *path,
-		   char *name,
-		   size_t name_len,
-		   void  *buf,
-		   size_t buf_size,
-		   size_t *data_size)
+int ext4_getxattr(const char *path, const char *name, size_t name_len,
+		  void *buf, size_t buf_size, size_t *data_size)
 {
 	int r = EOK;
 	ext4_file f;
 	uint32_t inode;
 	uint8_t name_index;
-	char *dissected_name = NULL;
+	const char *dissected_name = NULL;
 	size_t dissected_len = 0;
 	struct ext4_xattr_ref xattr_ref;
 	struct ext4_inode_ref inode_ref;
@@ -2072,8 +2062,7 @@
 	return EXT4_XATTR_ITERATE_CONT;
 }
 
-int ext4_listxattr(const char *path, char *list, size_t size,
-		   size_t *ret_size)
+int ext4_listxattr(const char *path, char *list, size_t size, size_t *ret_size)
 {
 	int r = EOK;
 	ext4_file f;
@@ -2126,15 +2115,13 @@
 
 }
 
-int ext4_removexattr(char *path,
-		   char *name,
-		   size_t name_len)
+int ext4_removexattr(const char *path, const char *name, size_t name_len)
 {
 	int r = EOK;
 	ext4_file f;
 	uint32_t inode;
 	uint8_t name_index;
-	char *dissected_name = NULL;
+	const char *dissected_name = NULL;
 	size_t dissected_len = 0;
 	struct ext4_xattr_ref xattr_ref;
 	struct ext4_inode_ref inode_ref;
@@ -2166,8 +2153,7 @@
 		goto Finish;
 	}
 
-	r = ext4_fs_remove_xattr(&xattr_ref,
-				name_index, dissected_name,
+	r = ext4_fs_remove_xattr(&xattr_ref, name_index, dissected_name,
 				dissected_len);
 
 	ext4_fs_put_xattr_ref(&xattr_ref);
--- a/lwext4/ext4.h
+++ b/lwext4/ext4.h
@@ -363,16 +363,12 @@
 
 int ext4_readlink(const char *path, char *buf, size_t bufsize, size_t *rcnt);
 
-int ext4_setxattr(char *path, char *name, size_t name_len,
-		  void *data, size_t data_size,
-		  bool replace);
-int ext4_getxattr(char *path, char *name, size_t name_len,
+int ext4_setxattr(const char *path, const char *name, size_t name_len,
+		  const void *data, size_t data_size, bool replace);
+int ext4_getxattr(const char *path, const char *name, size_t name_len,
 		  void *buf, size_t buf_size, size_t *data_size);
-int ext4_listxattr(const char *path, char *list, size_t size,
-		   size_t *ret_size);
-int ext4_removexattr(char *path,
-		   char *name,
-		   size_t name_len);
+int ext4_listxattr(const char *path, char *list, size_t size, size_t *ret_size);
+int ext4_removexattr(const char *path, const char *name, size_t name_len);
 
 
 /*********************************DIRECTORY OPERATION***********************/
--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -131,7 +131,7 @@
 		     ext4_xattr_item_cmp, static inline)
 
 static struct ext4_xattr_item *
-ext4_xattr_item_alloc(uint8_t name_index, char *name, size_t name_len)
+ext4_xattr_item_alloc(uint8_t name_index, const char *name, size_t name_len)
 {
 	struct ext4_xattr_item *item;
 	item = malloc(sizeof(struct ext4_xattr_item) + name_len);
@@ -151,7 +151,7 @@
 }
 
 static int ext4_xattr_item_alloc_data(struct ext4_xattr_item *item,
-				      void *orig_data, size_t data_size)
+				      const void *orig_data, size_t data_size)
 {
 	void *data = NULL;
 	ext4_assert(!item->data);
@@ -350,11 +350,11 @@
 
 static struct ext4_xattr_item *
 ext4_xattr_lookup_item(struct ext4_xattr_ref *xattr_ref, uint8_t name_index,
-		       char *name, size_t name_len)
+		       const char *name, size_t name_len)
 {
 	struct ext4_xattr_item tmp = {
 		.name_index = name_index,
-		.name = name,
+		.name = (char *)name, /*RB_FIND - won't touch this string*/
 		.name_len = name_len,
 	};
 
@@ -363,7 +363,7 @@
 
 static struct ext4_xattr_item *
 ext4_xattr_insert_item(struct ext4_xattr_ref *xattr_ref, uint8_t name_index,
-		       char *name, size_t name_len, void *data,
+		       const char *name, size_t name_len, const void *data,
 		       size_t data_size)
 {
 	struct ext4_xattr_item *item;
@@ -390,7 +390,7 @@
 }
 
 static int ext4_xattr_remove_item(struct ext4_xattr_ref *xattr_ref,
-				  uint8_t name_index, char *name,
+				  uint8_t name_index, const char *name,
 				  size_t name_len)
 {
 	int ret = ENOENT;
@@ -683,8 +683,8 @@
 }
 
 int ext4_fs_set_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
-		      char *name, size_t name_len, void *data, size_t data_size,
-		      bool replace)
+		      const char *name, size_t name_len, const void *data,
+		      size_t data_size, bool replace)
 {
 	int ret = EOK;
 	struct ext4_xattr_item *item =
@@ -716,13 +716,13 @@
 }
 
 int ext4_fs_remove_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
-			 char *name, size_t name_len)
+			 const char *name, size_t name_len)
 {
 	return ext4_xattr_remove_item(ref, name_index, name, name_len);
 }
 
 int ext4_fs_get_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
-		      char *name, size_t name_len, void *buf, size_t buf_size,
+		      const char *name, size_t name_len, void *buf, size_t buf_size,
 		      size_t *data_size)
 {
 	int ret = EOK;
@@ -811,7 +811,7 @@
     {NULL, 0},
 };
 
-char *ext4_extract_xattr_name(char *full_name, size_t full_name_len,
+const char *ext4_extract_xattr_name(const char *full_name, size_t full_name_len,
 			      uint8_t *name_index, size_t *name_len)
 {
 	int i;
--- a/lwext4/ext4_xattr.h
+++ b/lwext4/ext4_xattr.h
@@ -46,15 +46,15 @@
 void ext4_fs_put_xattr_ref(struct ext4_xattr_ref *ref);
 
 int ext4_fs_set_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
-		      char *name, size_t name_len, void *data, size_t data_size,
-		      bool replace);
+		      const char *name, size_t name_len, const void *data,
+		      size_t data_size, bool replace);
 
 int ext4_fs_remove_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
-			 char *name, size_t name_len);
+			 const char *name, size_t name_len);
 
 int ext4_fs_get_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
-		      char *name, size_t name_len, void *buf, size_t buf_size,
-		      size_t *data_size);
+		      const char *name, size_t name_len, void *buf,
+		      size_t buf_size, size_t *data_size);
 
 void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref,
 			   int (*iter)(struct ext4_xattr_ref *ref,
@@ -62,7 +62,7 @@
 
 void ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref);
 
-char *ext4_extract_xattr_name(char *full_name, size_t full_name_len,
+const char *ext4_extract_xattr_name(const char *full_name, size_t full_name_len,
 			      uint8_t *name_index, size_t *name_len);
 
 const char *ext4_get_xattr_name_prefix(uint8_t name_index,