2.4.22pre10+aa: XFS has it right, setxattr() takes "const void *"
Subsystems (3)
PATCH 1/1 2.4.22pre10+aa: XFS has it right, setxattr() takes "const void *"
It seems that the XFS developers have the right idea about setxattr(), namely that it should take a "const void *" parameter for the attributes it will set, rather than "void *".
This patch Makes It So. It is in some sense only cosmetic, since the generated code is the same, but the usage of const is a Good Thing for this kind of interface.
PS: I created the patch against 2.4.20pre10 plus many of the patches in the 'aa' tree, so perhaps it should be taken as more of a suggested idea rather than a literal patch.
Index: linux/fs/befs/linuxvfs.c
fs/befs/linuxvfs.c renamed from fs/befs/linuxvfs.c.old +2 -2
@@ -59,5 +59,5 @@static ssize_t befs_getxattr (struct dentry *dentry,const char *name,void *buffer,size_t size); -static int befs_setxattr (struct dentry *dentry,const char *name,void *value, +static int befs_setxattr (struct dentry *dentry,const char *name,const void *value,size_t size,int flags);static int befs_removexattr (struct dentry *dentry,const char *name);
@@ -694,5 +694,5 @@static int befs_setxattr (struct dentry *dentry,const char *name, -void *value,size_t size,int flags) +const void *value,size_t size,int flags) {return 0 ;
Index: linux/fs/jfs/jfs_xattr.h
fs/jfs/jfs_xattr.h renamed from fs/jfs/jfs_xattr.h.old +2 -2
@@ -53,6 +53,6 @@ ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist))) -extern int __jfs_setxattr (struct inode *,const char *,void *,size_t ,int ); -extern int jfs_setxattr (struct dentry *,const char *,void *,size_t ,int ); +extern int __jfs_setxattr (struct inode *,const char *,const void *,size_t ,int ); +extern int jfs_setxattr (struct dentry *,const char *,const void *,size_t ,int );extern ssize_t __jfs_getxattr (struct inode *,const char *,void *,size_t );extern ssize_t jfs_getxattr (struct dentry *,const char *,void *,size_t );
Index: linux/fs/jfs/xattr.c
fs/jfs/xattr.c renamed from fs/jfs/xattr.c.old +2 -2
@@ -661,5 +661,5 @@ } -int __jfs_setxattr (struct inode *inode,const char *name,void *value, +int __jfs_setxattr (struct inode *inode,const char *name,const void *value,size_t value_len,int flags) {
@@ -800,5 +800,5 @@ } -int jfs_setxattr (struct dentry *dentry,const char *name,void *value, +int jfs_setxattr (struct dentry *dentry,const char *name,const void *value,size_t value_len,int flags) {
Index: linux/fs/xattr.c
fs/xattr.c renamed from fs/xattr.c.old +4 -4
@@ -59,5 +59,5 @@*/ static long -setxattr (struct dentry *d,char *name,void *value,size_t size,int flags) +setxattr (struct dentry *d,char *name,const void *value,size_t size,int flags) {int error;
@@ -97,5 +97,5 @@asmlinkage long -sys_setxattr (char *path,char *name,void *value,size_t size,int flags) +sys_setxattr (char *path,char *name,const void *value,size_t size,int flags) {struct nameidata nd;
@@ -111,5 +111,5 @@asmlinkage long -sys_lsetxattr (char *path,char *name,void *value,size_t size,int flags) +sys_lsetxattr (char *path,char *name,const void *value,size_t size,int flags) {struct nameidata nd;
@@ -125,5 +125,5 @@asmlinkage long -sys_fsetxattr (int fd,char *name,void *value,size_t size,int flags) +sys_fsetxattr (int fd,char *name,const void *value,size_t size,int flags) {struct file *f;
Index: linux/include/linux/fs.h
include/linux/fs.h renamed from include/linux/fs.h.old +1 -1
@@ -990,5 +990,5 @@int (*setattr) (struct dentry *,struct iattr *);int (*getattr) (struct dentry *,struct iattr *); -int (*setxattr) (struct dentry *,const char *,void *,size_t ,int ); +int (*setxattr) (struct dentry *,const char *,const void *,size_t ,int );ssize_t (*getxattr) (struct dentry *,const char *,void *,size_t );ssize_t (*listxattr) (struct dentry *,char *,size_t );
Signature · 3 lines
Chip Salzenberg - a.k.a. - <[email protected]> "I wanted to play hopscotch with the impenetrable mystery of existence, but he stepped in a wormhole and had to go in early." // MST3K
Quoted 7 lines · Chip Salzenberg
It seems that the XFS developers have the right idea about
setxattr(), namely that it should take a "const void *" parameter for the attributes it will set, rather than "void *".This patch Makes It So. It is in some sense only cosmetic, since the generated code is the same, but the usage of const is a Good Thing for this kind of interface.
Well, the const is how it works on 2.5, 2.4 should not change module APIs. Please submit a patch for XFS instead to remove the const for 2.4.