Skip to content

Commit 88ee9d5

Browse files
janneketytso
authored andcommitted
ext4: support xattr gnu.* namespace for the Hurd
The Hurd gained[0] support for moving the translator and author fields out of the inode and into the "gnu.*" xattr namespace. In anticipation of that, an xattr INDEX was reserved[1]. The Hurd has now been brought into compliance[2] with that. This patch adds support for reading and writing such attributes from Linux; you can now do something like mkdir -p hurd-root/servers/socket touch hurd-root/servers/socket/1 setfattr --name=gnu.translator --value='"/hurd/pflocal\0"' \ hurd-root/servers/socket/1 getfattr --name=gnu.translator hurd-root/servers/socket/1 # file: 1 gnu.translator="/hurd/pflocal" to setup a pipe translator, which is being used to create[3] a vm-image for the Hurd from GNU Guix. [0] https://summerofcode.withgoogle.com/projects/#5869799859027968 [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3980bd3b406addb327d858aebd19e229ea340b9a [2] https://git.savannah.gnu.org/cgit/hurd/hurd.git/commit/?id=a04c7bf83172faa7cb080fbe3b6c04a8415ca645 [3] https://git.savannah.gnu.org/cgit/guix.git/log/?h=wip-hurd-vm Signed-off-by: Jan Nieuwenhuizen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 8119853 commit 88ee9d5

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

fs/ext4/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ ext4-y := balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \
99
extents_status.o file.o fsmap.o fsync.o hash.o ialloc.o \
1010
indirect.o inline.o inode.o ioctl.o mballoc.o migrate.o \
1111
mmp.o move_extent.o namei.o page-io.o readpage.o resize.o \
12-
super.o symlink.o sysfs.o xattr.o xattr_trusted.o xattr_user.o
12+
super.o symlink.o sysfs.o xattr.o xattr_hurd.o xattr_trusted.o \
13+
xattr_user.o
1314

1415
ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o
1516
ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o

fs/ext4/xattr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static const struct xattr_handler * const ext4_xattr_handler_map[] = {
9393
#ifdef CONFIG_EXT4_FS_SECURITY
9494
[EXT4_XATTR_INDEX_SECURITY] = &ext4_xattr_security_handler,
9595
#endif
96+
[EXT4_XATTR_INDEX_HURD] = &ext4_xattr_hurd_handler,
9697
};
9798

9899
const struct xattr_handler *ext4_xattr_handlers[] = {
@@ -105,6 +106,7 @@ const struct xattr_handler *ext4_xattr_handlers[] = {
105106
#ifdef CONFIG_EXT4_FS_SECURITY
106107
&ext4_xattr_security_handler,
107108
#endif
109+
&ext4_xattr_hurd_handler,
108110
NULL
109111
};
110112

fs/ext4/xattr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct ext4_xattr_inode_array {
124124
extern const struct xattr_handler ext4_xattr_user_handler;
125125
extern const struct xattr_handler ext4_xattr_trusted_handler;
126126
extern const struct xattr_handler ext4_xattr_security_handler;
127+
extern const struct xattr_handler ext4_xattr_hurd_handler;
127128

128129
#define EXT4_XATTR_NAME_ENCRYPTION_CONTEXT "c"
129130

fs/ext4/xattr_hurd.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* linux/fs/ext4/xattr_hurd.c
4+
* Handler for extended gnu attributes for the Hurd.
5+
*
6+
* Copyright (C) 2001 by Andreas Gruenbacher, <[email protected]>
7+
* Copyright (C) 2020 by Jan (janneke) Nieuwenhuizen, <[email protected]>
8+
*/
9+
10+
#include <linux/init.h>
11+
#include <linux/string.h>
12+
#include "ext4.h"
13+
#include "xattr.h"
14+
15+
static bool
16+
ext4_xattr_hurd_list(struct dentry *dentry)
17+
{
18+
return test_opt(dentry->d_sb, XATTR_USER);
19+
}
20+
21+
static int
22+
ext4_xattr_hurd_get(const struct xattr_handler *handler,
23+
struct dentry *unused, struct inode *inode,
24+
const char *name, void *buffer, size_t size)
25+
{
26+
if (!test_opt(inode->i_sb, XATTR_USER))
27+
return -EOPNOTSUPP;
28+
29+
return ext4_xattr_get(inode, EXT4_XATTR_INDEX_HURD,
30+
name, buffer, size);
31+
}
32+
33+
static int
34+
ext4_xattr_hurd_set(const struct xattr_handler *handler,
35+
struct dentry *unused, struct inode *inode,
36+
const char *name, const void *value,
37+
size_t size, int flags)
38+
{
39+
if (!test_opt(inode->i_sb, XATTR_USER))
40+
return -EOPNOTSUPP;
41+
42+
return ext4_xattr_set(inode, EXT4_XATTR_INDEX_HURD,
43+
name, value, size, flags);
44+
}
45+
46+
const struct xattr_handler ext4_xattr_hurd_handler = {
47+
.prefix = XATTR_HURD_PREFIX,
48+
.list = ext4_xattr_hurd_list,
49+
.get = ext4_xattr_hurd_get,
50+
.set = ext4_xattr_hurd_set,
51+
};

include/uapi/linux/xattr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Copyright (C) 2001 by Andreas Gruenbacher <[email protected]>
88
Copyright (c) 2001-2002 Silicon Graphics, Inc. All Rights Reserved.
99
Copyright (c) 2004 Red Hat, Inc., James Morris <[email protected]>
10+
Copyright (c) 2020 Jan (janneke) Nieuwenhuizen <[email protected]>
1011
*/
1112

1213
#include <linux/libc-compat.h>
@@ -31,6 +32,9 @@
3132
#define XATTR_BTRFS_PREFIX "btrfs."
3233
#define XATTR_BTRFS_PREFIX_LEN (sizeof(XATTR_BTRFS_PREFIX) - 1)
3334

35+
#define XATTR_HURD_PREFIX "gnu."
36+
#define XATTR_HURD_PREFIX_LEN (sizeof(XATTR_HURD_PREFIX) - 1)
37+
3438
#define XATTR_SECURITY_PREFIX "security."
3539
#define XATTR_SECURITY_PREFIX_LEN (sizeof(XATTR_SECURITY_PREFIX) - 1)
3640

0 commit comments

Comments
 (0)