summaryrefslogtreecommitdiff
blob: ef2175b41de7636dc8a232f27bcbe07765785869 (plain)
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
Index: linux-2.6.16/fs/ocfs2/Makefile
===================================================================
--- linux-2.6.16.orig/fs/ocfs2/Makefile
+++ linux-2.6.16/fs/ocfs2/Makefile
@@ -16,6 +16,7 @@ ocfs2-objs := \
 	file.o 			\
 	heartbeat.o 		\
 	inode.o 		\
+	ioctl.o 		\
 	journal.o 		\
 	localalloc.o 		\
 	mmap.o 			\
Index: linux-2.6.16/fs/ocfs2/file.c
===================================================================
--- linux-2.6.16.orig/fs/ocfs2/file.c
+++ linux-2.6.16/fs/ocfs2/file.c
@@ -1162,9 +1162,12 @@ bail:
 	return ret;
 }
 
+extern int ocfs2_sync_flags(struct inode *);
+
 struct inode_operations ocfs2_file_iops = {
 	.setattr	= ocfs2_setattr,
 	.getattr	= ocfs2_getattr,
+	.sync_flags     = ocfs2_sync_flags,
 };
 
 struct inode_operations ocfs2_special_file_iops = {
@@ -1172,6 +1175,9 @@ struct inode_operations ocfs2_special_fi
 	.getattr	= ocfs2_getattr,
 };
 
+extern int ocfs2_ioctl(struct inode *, struct file *,
+	unsigned int, unsigned long);
+
 struct file_operations ocfs2_fops = {
 	.read		= do_sync_read,
 	.write		= do_sync_write,
@@ -1182,10 +1188,12 @@ struct file_operations ocfs2_fops = {
 	.open		= ocfs2_file_open,
 	.aio_read	= ocfs2_file_aio_read,
 	.aio_write	= ocfs2_file_aio_write,
+	.ioctl		= ocfs2_ioctl,
 };
 
 struct file_operations ocfs2_dops = {
 	.read		= generic_read_dir,
 	.readdir	= ocfs2_readdir,
 	.fsync		= ocfs2_sync_file,
+	.ioctl		= ocfs2_ioctl,
 };
Index: linux-2.6.16/fs/ocfs2/inode.c
===================================================================
--- linux-2.6.16.orig/fs/ocfs2/inode.c
+++ linux-2.6.16/fs/ocfs2/inode.c
@@ -71,6 +71,81 @@ static int ocfs2_truncate_for_delete(str
 				    struct inode *inode,
 				    struct buffer_head *fe_bh);
 
+void ocfs2_set_inode_flags(struct inode *inode)
+{
+	unsigned int flags = OCFS2_I(inode)->ip_flags;
+
+	inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
+		S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
+
+	if (flags & OCFS2_IMMUTABLE_FL)
+		inode->i_flags |= S_IMMUTABLE;
+	if (flags & OCFS2_IUNLINK_FL)
+		inode->i_flags |= S_IUNLINK;
+	if (flags & OCFS2_BARRIER_FL)
+		inode->i_flags |= S_BARRIER;
+
+	if (flags & OCFS2_SYNC_FL)
+		inode->i_flags |= S_SYNC;
+	if (flags & OCFS2_APPEND_FL)
+		inode->i_flags |= S_APPEND;
+	if (flags & OCFS2_NOATIME_FL)
+		inode->i_flags |= S_NOATIME;
+	if (flags & OCFS2_DIRSYNC_FL)
+		inode->i_flags |= S_DIRSYNC;
+}
+
+int ocfs2_sync_flags(struct inode *inode)
+{
+	unsigned int oldflags, newflags;
+
+	oldflags = OCFS2_I(inode)->ip_flags;
+	newflags = oldflags & ~(OCFS2_APPEND_FL |
+		OCFS2_IMMUTABLE_FL | OCFS2_IUNLINK_FL |
+		OCFS2_BARRIER_FL | OCFS2_NOATIME_FL |
+		OCFS2_SYNC_FL | OCFS2_DIRSYNC_FL);
+
+	if (IS_APPEND(inode))
+		newflags |= OCFS2_APPEND_FL;
+	if (IS_IMMUTABLE(inode))
+		newflags |= OCFS2_IMMUTABLE_FL;
+	if (IS_IUNLINK(inode))
+		newflags |= OCFS2_IUNLINK_FL;
+	if (IS_BARRIER(inode))
+		newflags |= OCFS2_BARRIER_FL;
+
+	/* we do not want to copy superblock flags */
+	if (inode->i_flags & S_NOATIME)
+		newflags |= OCFS2_NOATIME_FL;
+	if (inode->i_flags & S_SYNC)
+		newflags |= OCFS2_SYNC_FL;
+	if (inode->i_flags & S_DIRSYNC)
+		newflags |= OCFS2_DIRSYNC_FL;
+
+	if (oldflags ^ newflags) {
+		OCFS2_I(inode)->ip_flags = newflags;
+		inode->i_ctime = CURRENT_TIME;
+		mark_inode_dirty(inode);
+	}
+	return 0;
+}
+
+static inline void ocfs2_map_dinode(struct inode *inode, struct ocfs2_dinode *fe, int from)
+{
+	unsigned flags;
+
+	if (from) {
+		flags = le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK;
+		OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
+		OCFS2_I(inode)->ip_flags |= flags;
+	} else {
+		flags = OCFS2_I(inode)->ip_flags & OCFS2_FL_MASK;
+		flags |= le32_to_cpu(fe->i_flags) & ~OCFS2_FL_MASK;
+		fe->i_flags = cpu_to_le32(flags);
+	}
+}
+
+
 struct inode *ocfs2_ilookup_for_vote(struct ocfs2_super *osb,
 				     u64 blkno,
 				     int delete_vote)
@@ -265,6 +340,7 @@ int ocfs2_populate_inode(struct inode *i
 	inode->i_mtime.tv_nsec = le32_to_cpu(fe->i_mtime_nsec);
 	inode->i_ctime.tv_sec = le64_to_cpu(fe->i_ctime);
 	inode->i_ctime.tv_nsec = le32_to_cpu(fe->i_ctime_nsec);
+	ocfs2_map_dinode(inode, fe, 1);
 
 	if (OCFS2_I(inode)->ip_blkno != le64_to_cpu(fe->i_blkno))
 		mlog(ML_ERROR,
@@ -327,6 +403,7 @@ int ocfs2_populate_inode(struct inode *i
 	ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_data_lockres,
 				  OCFS2_LOCK_TYPE_DATA, inode);
 
+	ocfs2_set_inode_flags(inode);
 	status = 0;
 bail:
 	mlog_exit(status);
@@ -1138,6 +1215,7 @@ int ocfs2_mark_inode_dirty(struct ocfs2_
 	fe->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
 	fe->i_mtime = cpu_to_le64(inode->i_mtime.tv_sec);
 	fe->i_mtime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
+	ocfs2_map_dinode(inode, fe, 0);
 
 	status = ocfs2_journal_dirty(handle, bh);
 	if (status < 0)
@@ -1179,6 +1257,7 @@ void ocfs2_refresh_inode(struct inode *i
 	inode->i_mtime.tv_nsec = le32_to_cpu(fe->i_mtime_nsec);
 	inode->i_ctime.tv_sec = le64_to_cpu(fe->i_ctime);
 	inode->i_ctime.tv_nsec = le32_to_cpu(fe->i_ctime_nsec);
+	ocfs2_map_dinode(inode, fe, 1);
 
 	spin_unlock(&OCFS2_I(inode)->ip_lock);
 }
Index: linux-2.6.16/fs/ocfs2/ioctl.c
===================================================================
--- /dev/null
+++ linux-2.6.16/fs/ocfs2/ioctl.c
@@ -0,0 +1,140 @@
+/*
+ * linux/fs/ocfs2/ioctl.c
+ *
+ * Copyright (C) 2006 Herbert Poetzl
+ * adapted from Remy Card's ext2/ioctl.c
+ */
+
+#include <linux/fs.h>
+#include <linux/mount.h>
+
+#define MLOG_MASK_PREFIX ML_INODE
+#include <cluster/masklog.h>
+
+#include "ocfs2.h"
+#include "alloc.h"
+#include "dlmglue.h"
+#include "inode.h"
+#include "journal.h"
+
+#include "ocfs2_fs.h"
+#include <linux/ext2_fs.h>
+
+static struct {
+	long ocfs2_flag;
+	long ext2_flag;
+} ocfs2_map[] = {
+	{OCFS2_NOATIME_FL, EXT2_NOATIME_FL},
+	{OCFS2_DIRSYNC_FL, EXT2_DIRSYNC_FL},
+	{OCFS2_SYNC_FL, EXT2_SYNC_FL},
+	{OCFS2_SECRM_FL, EXT2_SECRM_FL},
+	{OCFS2_UNRM_FL, EXT2_UNRM_FL},
+	{OCFS2_APPEND_FL, EXT2_APPEND_FL},
+	{OCFS2_IMMUTABLE_FL, EXT2_IMMUTABLE_FL},
+	{0, 0},
+};
+
+static long ocfs2_map_ext2(unsigned long flags, int from)
+{
+	int index=0;
+	long mapped=0;
+
+	while (ocfs2_map[index].ocfs2_flag) {
+		if (from) {
+			if (ocfs2_map[index].ext2_flag & flags)
+				mapped |= ocfs2_map[index].ocfs2_flag;
+		} else {
+			if (ocfs2_map[index].ocfs2_flag & flags)
+				mapped |= ocfs2_map[index].ext2_flag;
+		}
+		index++;
+	}
+	return mapped;
+}
+
+extern void ocfs2_set_inode_flags(struct inode *);
+
+
+int ocfs2_ioctl(struct inode * inode, struct file * filp, unsigned int cmd,
+		unsigned long arg)
+{
+	struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
+	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+	struct ocfs2_journal_handle *handle = NULL;
+	struct buffer_head *bh = NULL;
+	unsigned int flags;
+	int status;
+
+	switch (cmd) {
+	case OCFS2_IOC_GETFLAGS:
+		flags = ocfs2_inode->ip_flags & OCFS2_FL_VISIBLE;
+		flags = ocfs2_map_ext2(flags, 0);
+		return put_user(flags, (int __user *) arg);
+	case OCFS2_IOC_SETFLAGS: {
+		unsigned int oldflags;
+
+		if (IS_RDONLY(inode) ||
+			(filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
+			return -EROFS;
+
+		if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
+			return -EACCES;
+
+		if (get_user(flags, (int __user *) arg))
+			return -EFAULT;
+
+		flags = ocfs2_map_ext2(flags, 1);
+		if (!S_ISDIR(inode->i_mode))
+			flags &= ~OCFS2_DIRSYNC_FL;
+
+		status = ocfs2_meta_lock(inode, NULL, &bh, 1);
+		if (status < 0) {
+			mlog_errno(status);
+			goto bail;
+		}
+
+		handle = ocfs2_start_trans(osb, NULL, OCFS2_INODE_UPDATE_CREDITS);
+		if (IS_ERR(handle)) {
+			status = PTR_ERR(handle);
+			mlog_errno(status);
+			goto bail_unlock;
+		}
+
+		oldflags = ocfs2_inode->ip_flags;
+
+		/*
+		 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
+		 * the relevant capability.
+		 */
+		if ((oldflags & OCFS2_IMMUTABLE_FL) ||
+			((flags ^ oldflags) & (OCFS2_APPEND_FL |
+			OCFS2_IMMUTABLE_FL | OCFS2_IUNLINK_FL))) {
+			if (!capable(CAP_LINUX_IMMUTABLE))
+				return -EPERM;
+		}
+
+		flags = flags & OCFS2_FL_MODIFIABLE;
+		flags |= oldflags & ~OCFS2_FL_MODIFIABLE;
+		ocfs2_inode->ip_flags = flags;
+
+		ocfs2_set_inode_flags(inode);
+
+		status = ocfs2_mark_inode_dirty(handle, inode, bh);
+		if (status < 0)
+			mlog_errno(status);
+
+		ocfs2_commit_trans(handle);
+	bail_unlock:
+		ocfs2_meta_unlock(inode, 1);
+	bail:
+		if (bh)
+			brelse(bh);
+
+		mlog_exit(status);
+		return 0;
+	}
+	default:
+		return -ENOTTY;
+	}
+}
+
Index: linux-2.6.16/fs/ocfs2/ocfs2_fs.h
===================================================================
--- linux-2.6.16.orig/fs/ocfs2/ocfs2_fs.h
+++ linux-2.6.16/fs/ocfs2/ocfs2_fs.h
@@ -114,6 +114,26 @@
 #define OCFS2_CHAIN_FL		(0x00000400)	/* Chain allocator */
 #define OCFS2_DEALLOC_FL	(0x00000800)	/* Truncate log */
 
+#define OCFS2_DIRSYNC_FL	(0x00010000)	/* dirsync behaviour (directories only) */
+#define OCFS2_SYNC_FL		(0x00020000)	/* Synchronous updates */
+#define OCFS2_SECRM_FL		(0x00040000)	/* Secure deletion */
+#define OCFS2_UNRM_FL		(0x00080000)	/* Undelete */
+
+#define OCFS2_IMMUTABLE_FL	(0x00100000)	/* Immutable file */
+#define OCFS2_APPEND_FL		(0x00200000)	/* writes to file may only append */
+#define OCFS2_NOATIME_FL	(0x00400000)	/* do not update atime */
+
+#define OCFS2_BARRIER_FL	(0x04000000)	/* Barrier for chroot() */
+#define OCFS2_IUNLINK_FL	(0x08000000)	/* Immutable unlink */
+
+#define OCFS2_FL_MASK		(0x0FFF0000)
+#define OCFS2_FL_VISIBLE	(0x00FF0000)
+#define OCFS2_FL_MODIFIABLE	(0x007F0000)
+#define OCFS2_FL_INHERIT	(0x007C0000)
+
+#define OCFS2_IOC_GETFLAGS	_IOR('f', 1, long)
+#define OCFS2_IOC_SETFLAGS	_IOW('f', 2, long)
+
 /*
  * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
  */