-
Notifications
You must be signed in to change notification settings - Fork 0
/
xattr0008-Translator-shouldn-t-work-on-non-hurd-created-filesy.patch
197 lines (180 loc) · 5.67 KB
/
xattr0008-Translator-shouldn-t-work-on-non-hurd-created-filesy.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
From 4fe6c413f41334f617efaea4c69cc50918e10c8e Mon Sep 17 00:00:00 2001
From: Shengyu Zhang <lastavengers@outlook.com>
Date: Wed, 10 Aug 2016 16:33:37 +0800
Subject: [PATCH] Translator shouldn't work on non-hurd-created filesystem
---
ext2fs/inode.c | 120 ++++++++++++++++++++++++++-------------------------------
1 file changed, 54 insertions(+), 66 deletions(-)
diff --git a/ext2fs/inode.c b/ext2fs/inode.c
index 6fe659c..6b582b8 100644
--- a/ext2fs/inode.c
+++ b/ext2fs/inode.c
@@ -557,6 +557,9 @@ diskfs_set_translator (struct node *np, const char *name, unsigned namelen,
assert (!diskfs_readonly);
+ if (sblock->s_creator_os != EXT2_OS_HURD)
+ return EOPNOTSUPP;
+
err = diskfs_catch_exception ();
if (err)
return err;
@@ -565,32 +568,29 @@ diskfs_set_translator (struct node *np, const char *name, unsigned namelen,
record, otherwise, use legacy translator record */
if (EXT2_HAS_COMPAT_FEATURE (sblock, EXT2_FEATURE_COMPAT_EXT_ATTR))
{
- /* If a legacy translator record found, clear it */
- if (sblock->s_creator_os == EXT2_OS_HURD)
- {
- daddr_t blkno;
- struct ext2_inode *di;
+ daddr_t blkno;
+ struct ext2_inode *di;
- di = dino_ref (np->cache_id);
- blkno = di->i_translator;
+ di = dino_ref (np->cache_id);
+ blkno = di->i_translator;
- if (blkno)
- {
- ext2_warning ("Old translator record found, clear it");
+ /* If a legacy translator record found, clear it */
+ if (blkno)
+ {
+ ext2_warning ("Old translator record found, clear it");
- /* Clear block for translator going away. */
- di->i_translator = 0;
- diskfs_node_disknode (np)->info_i_translator = 0;
- record_global_poke (di);
- ext2_free_blocks (blkno, 1);
+ /* Clear block for translator going away. */
+ di->i_translator = 0;
+ diskfs_node_disknode (np)->info_i_translator = 0;
+ record_global_poke (di);
+ ext2_free_blocks (blkno, 1);
- np->dn_stat.st_blocks -= 1 << log2_stat_blocks_per_fs_block;
- np->dn_stat.st_mode &= ~S_IPTRANS;
- np->dn_set_ctime = 1;
- }
- else
- dino_deref (di);
+ np->dn_stat.st_blocks -= 1 << log2_stat_blocks_per_fs_block;
+ np->dn_stat.st_mode &= ~S_IPTRANS;
+ np->dn_set_ctime = 1;
}
+ else
+ dino_deref (di);
/* Use xattr to store translator record, with key "gnu.translator" */
if (namelen)
@@ -599,9 +599,7 @@ diskfs_set_translator (struct node *np, const char *name, unsigned namelen,
if (!err)
{
- /* Do not use hurd extensions on non-hurd created filesystem */
- if (sblock->s_creator_os == EXT2_OS_HURD)
- np->dn_stat.st_mode |= S_IPTRANS;
+ np->dn_stat.st_mode |= S_IPTRANS;
np->dn_set_ctime = 1;
}
}
@@ -617,8 +615,7 @@ diskfs_set_translator (struct node *np, const char *name, unsigned namelen,
if (!err)
{
/* Do not use hurd extensions on non-hurd created filesystem */
- if (sblock->s_creator_os == EXT2_OS_HURD)
- np->dn_stat.st_mode &= ~S_IPTRANS;
+ np->dn_stat.st_mode &= ~S_IPTRANS;
np->dn_set_ctime = 1;
}
}
@@ -630,16 +627,9 @@ diskfs_set_translator (struct node *np, const char *name, unsigned namelen,
struct ext2_inode *di;
char buf[block_size];
- if (sblock->s_creator_os != EXT2_OS_HURD)
- return EOPNOTSUPP;
-
if (namelen + 2 > block_size)
return ENAMETOOLONG;
- err = diskfs_catch_exception ();
- if (err)
- return err;
-
di = dino_ref (np->cache_id);
blkno = di->i_translator;
@@ -708,50 +698,48 @@ error_t
diskfs_get_translator (struct node *np, char **namep, unsigned *namelen)
{
error_t err = 0;
+ daddr_t blkno;
int datalen;
+ void *transloc;
+ struct ext2_inode *di;
+
+ if (sblock->s_creator_os != EXT2_OS_HURD)
+ return EOPNOTSUPP;
err = diskfs_catch_exception ();
if (err)
return err;
+ di = dino_ref (np->cache_id);
+ blkno = di->i_translator;
+ dino_deref (di);
+
/* If an old translator record found, read it firstly */
- if (sblock->s_creator_os == EXT2_OS_HURD)
+ if (blkno)
{
- daddr_t blkno;
- void *transloc;
- struct ext2_inode *di;
-
- di = dino_ref (np->cache_id);
- blkno = di->i_translator;
- dino_deref (di);
-
- if (blkno)
+ /* If xattr is no supported by this filesystem, don't report a warning */
+ if (EXT2_HAS_COMPAT_FEATURE (sblock, EXT2_FEATURE_COMPAT_EXT_ATTR))
+ ext2_warning ("This is a old translotor record, please update it");
+
+ transloc = disk_cache_block_ref (blkno);
+ datalen =
+ ((unsigned char *)transloc)[0] + (((unsigned char *)transloc)[1] << 8);
+ if (datalen > block_size - 2)
+ err = EFTYPE; /* ? */
+ else
{
- /* If xattr is no supported by this filesystem,
- don't report a warning */
- if (EXT2_HAS_COMPAT_FEATURE (sblock, EXT2_FEATURE_COMPAT_EXT_ATTR))
- ext2_warning ("This is a old translotor record, please update it");
-
- transloc = disk_cache_block_ref (blkno);
- datalen = ((unsigned char *)transloc)[0] +
- (((unsigned char *)transloc)[1] << 8);
- if (datalen > block_size - 2)
- err = EFTYPE; /* ? */
+ *namep = malloc (datalen);
+ if (!*namep)
+ err = ENOMEM;
else
- {
- *namep = malloc (datalen);
- if (!*namep)
- err = ENOMEM;
- else
- memcpy (*namep, transloc + 2, datalen);
- }
-
- disk_cache_block_deref (transloc);
- diskfs_end_catch_exception ();
-
- *namelen = datalen;
- return err;
+ memcpy (*namep, transloc + 2, datalen);
}
+
+ disk_cache_block_deref (transloc);
+ diskfs_end_catch_exception ();
+
+ *namelen = datalen;
+ return err;
}
err = ext2_get_xattr (np, "gnu.translator", NULL, &datalen);
--
2.9.2