]>
Commit | Line | Data |
---|---|---|
ca4d147e HP |
1 | /* |
2 | * linux/fs/ocfs2/ioctl.c | |
3 | * | |
4 | * Copyright (C) 2006 Herbert Poetzl | |
5 | * adapted from Remy Card's ext2/ioctl.c | |
6 | */ | |
7 | ||
8 | #include <linux/fs.h> | |
9 | #include <linux/mount.h> | |
34e6c59a | 10 | #include <linux/compat.h> |
ca4d147e | 11 | |
ca4d147e HP |
12 | #include <cluster/masklog.h> |
13 | ||
14 | #include "ocfs2.h" | |
15 | #include "alloc.h" | |
16 | #include "dlmglue.h" | |
b2580103 | 17 | #include "file.h" |
ca4d147e HP |
18 | #include "inode.h" |
19 | #include "journal.h" | |
20 | ||
21 | #include "ocfs2_fs.h" | |
2d562518 | 22 | #include "ioctl.h" |
d659072f | 23 | #include "resize.h" |
bd50873d | 24 | #include "refcounttree.h" |
3e5db17d TY |
25 | #include "sysfile.h" |
26 | #include "dir.h" | |
27 | #include "buffer_head_io.h" | |
2d562518 | 28 | |
ca4d147e HP |
29 | #include <linux/ext2_fs.h> |
30 | ||
ddee5cdb TY |
31 | #define o2info_from_user(a, b) \ |
32 | copy_from_user(&(a), (b), sizeof(a)) | |
33 | #define o2info_to_user(a, b) \ | |
34 | copy_to_user((typeof(a) __user *)b, &(a), sizeof(a)) | |
35 | ||
36 | /* | |
37 | * This call is void because we are already reporting an error that may | |
38 | * be -EFAULT. The error will be returned from the ioctl(2) call. It's | |
39 | * just a best-effort to tell userspace that this request caused the error. | |
40 | */ | |
8aa1fa36 | 41 | static inline void o2info_set_request_error(struct ocfs2_info_request *kreq, |
ddee5cdb TY |
42 | struct ocfs2_info_request __user *req) |
43 | { | |
44 | kreq->ir_flags |= OCFS2_INFO_FL_ERROR; | |
45 | (void)put_user(kreq->ir_flags, (__u32 __user *)&(req->ir_flags)); | |
46 | } | |
47 | ||
8aa1fa36 | 48 | static inline void o2info_set_request_filled(struct ocfs2_info_request *req) |
1936a267 TY |
49 | { |
50 | req->ir_flags |= OCFS2_INFO_FL_FILLED; | |
51 | } | |
52 | ||
8aa1fa36 | 53 | static inline void o2info_clear_request_filled(struct ocfs2_info_request *req) |
1936a267 TY |
54 | { |
55 | req->ir_flags &= ~OCFS2_INFO_FL_FILLED; | |
56 | } | |
57 | ||
3e5db17d TY |
58 | static inline int o2info_coherent(struct ocfs2_info_request *req) |
59 | { | |
60 | return (!(req->ir_flags & OCFS2_INFO_FL_NON_COHERENT)); | |
61 | } | |
62 | ||
ca4d147e HP |
63 | static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags) |
64 | { | |
65 | int status; | |
66 | ||
e63aecb6 | 67 | status = ocfs2_inode_lock(inode, NULL, 0); |
ca4d147e HP |
68 | if (status < 0) { |
69 | mlog_errno(status); | |
70 | return status; | |
71 | } | |
6e4b0d56 | 72 | ocfs2_get_inode_flags(OCFS2_I(inode)); |
ca4d147e | 73 | *flags = OCFS2_I(inode)->ip_attr; |
e63aecb6 | 74 | ocfs2_inode_unlock(inode, 0); |
ca4d147e | 75 | |
ca4d147e HP |
76 | return status; |
77 | } | |
78 | ||
79 | static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags, | |
80 | unsigned mask) | |
81 | { | |
82 | struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode); | |
83 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
1fabe148 | 84 | handle_t *handle = NULL; |
ca4d147e HP |
85 | struct buffer_head *bh = NULL; |
86 | unsigned oldflags; | |
87 | int status; | |
88 | ||
89 | mutex_lock(&inode->i_mutex); | |
90 | ||
e63aecb6 | 91 | status = ocfs2_inode_lock(inode, &bh, 1); |
ca4d147e HP |
92 | if (status < 0) { |
93 | mlog_errno(status); | |
94 | goto bail; | |
95 | } | |
96 | ||
ca4d147e | 97 | status = -EACCES; |
2e149670 | 98 | if (!inode_owner_or_capable(inode)) |
ca4d147e HP |
99 | goto bail_unlock; |
100 | ||
101 | if (!S_ISDIR(inode->i_mode)) | |
102 | flags &= ~OCFS2_DIRSYNC_FL; | |
103 | ||
65eff9cc | 104 | handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS); |
ca4d147e HP |
105 | if (IS_ERR(handle)) { |
106 | status = PTR_ERR(handle); | |
107 | mlog_errno(status); | |
108 | goto bail_unlock; | |
109 | } | |
110 | ||
111 | oldflags = ocfs2_inode->ip_attr; | |
112 | flags = flags & mask; | |
113 | flags |= oldflags & ~mask; | |
114 | ||
115 | /* | |
116 | * The IMMUTABLE and APPEND_ONLY flags can only be changed by | |
117 | * the relevant capability. | |
118 | */ | |
119 | status = -EPERM; | |
120 | if ((oldflags & OCFS2_IMMUTABLE_FL) || ((flags ^ oldflags) & | |
121 | (OCFS2_APPEND_FL | OCFS2_IMMUTABLE_FL))) { | |
122 | if (!capable(CAP_LINUX_IMMUTABLE)) | |
123 | goto bail_unlock; | |
124 | } | |
125 | ||
126 | ocfs2_inode->ip_attr = flags; | |
127 | ocfs2_set_inode_flags(inode); | |
128 | ||
129 | status = ocfs2_mark_inode_dirty(handle, inode, bh); | |
130 | if (status < 0) | |
131 | mlog_errno(status); | |
132 | ||
02dc1af4 | 133 | ocfs2_commit_trans(osb, handle); |
ca4d147e | 134 | bail_unlock: |
e63aecb6 | 135 | ocfs2_inode_unlock(inode, 1); |
ca4d147e HP |
136 | bail: |
137 | mutex_unlock(&inode->i_mutex); | |
138 | ||
a81cb88b | 139 | brelse(bh); |
ca4d147e | 140 | |
ca4d147e HP |
141 | return status; |
142 | } | |
143 | ||
ddee5cdb TY |
144 | int ocfs2_info_handle_blocksize(struct inode *inode, |
145 | struct ocfs2_info_request __user *req) | |
146 | { | |
147 | int status = -EFAULT; | |
148 | struct ocfs2_info_blocksize oib; | |
149 | ||
150 | if (o2info_from_user(oib, req)) | |
151 | goto bail; | |
152 | ||
153 | oib.ib_blocksize = inode->i_sb->s_blocksize; | |
1936a267 | 154 | |
8aa1fa36 | 155 | o2info_set_request_filled(&oib.ib_req); |
ddee5cdb TY |
156 | |
157 | if (o2info_to_user(oib, req)) | |
158 | goto bail; | |
159 | ||
160 | status = 0; | |
161 | bail: | |
162 | if (status) | |
8aa1fa36 | 163 | o2info_set_request_error(&oib.ib_req, req); |
ddee5cdb TY |
164 | |
165 | return status; | |
166 | } | |
167 | ||
168 | int ocfs2_info_handle_clustersize(struct inode *inode, | |
169 | struct ocfs2_info_request __user *req) | |
170 | { | |
171 | int status = -EFAULT; | |
172 | struct ocfs2_info_clustersize oic; | |
173 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
174 | ||
175 | if (o2info_from_user(oic, req)) | |
176 | goto bail; | |
177 | ||
178 | oic.ic_clustersize = osb->s_clustersize; | |
1936a267 | 179 | |
8aa1fa36 | 180 | o2info_set_request_filled(&oic.ic_req); |
ddee5cdb TY |
181 | |
182 | if (o2info_to_user(oic, req)) | |
183 | goto bail; | |
184 | ||
185 | status = 0; | |
186 | bail: | |
187 | if (status) | |
8aa1fa36 | 188 | o2info_set_request_error(&oic.ic_req, req); |
ddee5cdb TY |
189 | |
190 | return status; | |
191 | } | |
192 | ||
193 | int ocfs2_info_handle_maxslots(struct inode *inode, | |
194 | struct ocfs2_info_request __user *req) | |
195 | { | |
196 | int status = -EFAULT; | |
197 | struct ocfs2_info_maxslots oim; | |
198 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
199 | ||
200 | if (o2info_from_user(oim, req)) | |
201 | goto bail; | |
202 | ||
203 | oim.im_max_slots = osb->max_slots; | |
1936a267 | 204 | |
8aa1fa36 | 205 | o2info_set_request_filled(&oim.im_req); |
ddee5cdb TY |
206 | |
207 | if (o2info_to_user(oim, req)) | |
208 | goto bail; | |
209 | ||
210 | status = 0; | |
211 | bail: | |
212 | if (status) | |
8aa1fa36 | 213 | o2info_set_request_error(&oim.im_req, req); |
ddee5cdb TY |
214 | |
215 | return status; | |
216 | } | |
217 | ||
218 | int ocfs2_info_handle_label(struct inode *inode, | |
219 | struct ocfs2_info_request __user *req) | |
220 | { | |
221 | int status = -EFAULT; | |
222 | struct ocfs2_info_label oil; | |
223 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
224 | ||
225 | if (o2info_from_user(oil, req)) | |
226 | goto bail; | |
227 | ||
228 | memcpy(oil.il_label, osb->vol_label, OCFS2_MAX_VOL_LABEL_LEN); | |
1936a267 | 229 | |
8aa1fa36 | 230 | o2info_set_request_filled(&oil.il_req); |
ddee5cdb TY |
231 | |
232 | if (o2info_to_user(oil, req)) | |
233 | goto bail; | |
234 | ||
235 | status = 0; | |
236 | bail: | |
237 | if (status) | |
8aa1fa36 | 238 | o2info_set_request_error(&oil.il_req, req); |
ddee5cdb TY |
239 | |
240 | return status; | |
241 | } | |
242 | ||
243 | int ocfs2_info_handle_uuid(struct inode *inode, | |
244 | struct ocfs2_info_request __user *req) | |
245 | { | |
246 | int status = -EFAULT; | |
247 | struct ocfs2_info_uuid oiu; | |
248 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
249 | ||
250 | if (o2info_from_user(oiu, req)) | |
251 | goto bail; | |
252 | ||
253 | memcpy(oiu.iu_uuid_str, osb->uuid_str, OCFS2_TEXT_UUID_LEN + 1); | |
1936a267 | 254 | |
8aa1fa36 | 255 | o2info_set_request_filled(&oiu.iu_req); |
ddee5cdb TY |
256 | |
257 | if (o2info_to_user(oiu, req)) | |
258 | goto bail; | |
259 | ||
260 | status = 0; | |
261 | bail: | |
262 | if (status) | |
8aa1fa36 | 263 | o2info_set_request_error(&oiu.iu_req, req); |
ddee5cdb TY |
264 | |
265 | return status; | |
266 | } | |
267 | ||
268 | int ocfs2_info_handle_fs_features(struct inode *inode, | |
269 | struct ocfs2_info_request __user *req) | |
270 | { | |
271 | int status = -EFAULT; | |
272 | struct ocfs2_info_fs_features oif; | |
273 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
274 | ||
275 | if (o2info_from_user(oif, req)) | |
276 | goto bail; | |
277 | ||
278 | oif.if_compat_features = osb->s_feature_compat; | |
279 | oif.if_incompat_features = osb->s_feature_incompat; | |
280 | oif.if_ro_compat_features = osb->s_feature_ro_compat; | |
1936a267 | 281 | |
8aa1fa36 | 282 | o2info_set_request_filled(&oif.if_req); |
ddee5cdb TY |
283 | |
284 | if (o2info_to_user(oif, req)) | |
285 | goto bail; | |
286 | ||
287 | status = 0; | |
288 | bail: | |
289 | if (status) | |
8aa1fa36 | 290 | o2info_set_request_error(&oif.if_req, req); |
ddee5cdb TY |
291 | |
292 | return status; | |
293 | } | |
294 | ||
295 | int ocfs2_info_handle_journal_size(struct inode *inode, | |
296 | struct ocfs2_info_request __user *req) | |
297 | { | |
298 | int status = -EFAULT; | |
299 | struct ocfs2_info_journal_size oij; | |
300 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
301 | ||
302 | if (o2info_from_user(oij, req)) | |
303 | goto bail; | |
304 | ||
305 | oij.ij_journal_size = osb->journal->j_inode->i_size; | |
306 | ||
8aa1fa36 | 307 | o2info_set_request_filled(&oij.ij_req); |
ddee5cdb TY |
308 | |
309 | if (o2info_to_user(oij, req)) | |
310 | goto bail; | |
311 | ||
312 | status = 0; | |
313 | bail: | |
314 | if (status) | |
8aa1fa36 | 315 | o2info_set_request_error(&oij.ij_req, req); |
ddee5cdb TY |
316 | |
317 | return status; | |
318 | } | |
319 | ||
3e5db17d TY |
320 | int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb, |
321 | struct inode *inode_alloc, u64 blkno, | |
322 | struct ocfs2_info_freeinode *fi, u32 slot) | |
323 | { | |
324 | int status = 0, unlock = 0; | |
325 | ||
326 | struct buffer_head *bh = NULL; | |
327 | struct ocfs2_dinode *dinode_alloc = NULL; | |
328 | ||
329 | if (inode_alloc) | |
330 | mutex_lock(&inode_alloc->i_mutex); | |
331 | ||
332 | if (o2info_coherent(&fi->ifi_req)) { | |
333 | status = ocfs2_inode_lock(inode_alloc, &bh, 0); | |
334 | if (status < 0) { | |
335 | mlog_errno(status); | |
336 | goto bail; | |
337 | } | |
338 | unlock = 1; | |
339 | } else { | |
340 | status = ocfs2_read_blocks_sync(osb, blkno, 1, &bh); | |
341 | if (status < 0) { | |
342 | mlog_errno(status); | |
343 | goto bail; | |
344 | } | |
345 | } | |
346 | ||
347 | dinode_alloc = (struct ocfs2_dinode *)bh->b_data; | |
348 | ||
349 | fi->ifi_stat[slot].lfi_total = | |
350 | le32_to_cpu(dinode_alloc->id1.bitmap1.i_total); | |
351 | fi->ifi_stat[slot].lfi_free = | |
352 | le32_to_cpu(dinode_alloc->id1.bitmap1.i_total) - | |
353 | le32_to_cpu(dinode_alloc->id1.bitmap1.i_used); | |
354 | ||
355 | bail: | |
356 | if (unlock) | |
357 | ocfs2_inode_unlock(inode_alloc, 0); | |
358 | ||
359 | if (inode_alloc) | |
360 | mutex_unlock(&inode_alloc->i_mutex); | |
361 | ||
362 | brelse(bh); | |
363 | ||
364 | return status; | |
365 | } | |
366 | ||
367 | int ocfs2_info_handle_freeinode(struct inode *inode, | |
368 | struct ocfs2_info_request __user *req) | |
369 | { | |
370 | u32 i; | |
371 | u64 blkno = -1; | |
372 | char namebuf[40]; | |
373 | int status = -EFAULT, type = INODE_ALLOC_SYSTEM_INODE; | |
374 | struct ocfs2_info_freeinode *oifi = NULL; | |
375 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
376 | struct inode *inode_alloc = NULL; | |
377 | ||
378 | oifi = kzalloc(sizeof(struct ocfs2_info_freeinode), GFP_KERNEL); | |
379 | if (!oifi) { | |
380 | status = -ENOMEM; | |
381 | mlog_errno(status); | |
382 | goto bail; | |
383 | } | |
384 | ||
385 | if (o2info_from_user(*oifi, req)) | |
386 | goto bail; | |
387 | ||
388 | oifi->ifi_slotnum = osb->max_slots; | |
389 | ||
390 | for (i = 0; i < oifi->ifi_slotnum; i++) { | |
391 | if (o2info_coherent(&oifi->ifi_req)) { | |
392 | inode_alloc = ocfs2_get_system_file_inode(osb, type, i); | |
393 | if (!inode_alloc) { | |
394 | mlog(ML_ERROR, "unable to get alloc inode in " | |
395 | "slot %u\n", i); | |
396 | status = -EIO; | |
397 | goto bail; | |
398 | } | |
399 | } else { | |
400 | ocfs2_sprintf_system_inode_name(namebuf, | |
401 | sizeof(namebuf), | |
402 | type, i); | |
403 | status = ocfs2_lookup_ino_from_name(osb->sys_root_inode, | |
404 | namebuf, | |
405 | strlen(namebuf), | |
406 | &blkno); | |
407 | if (status < 0) { | |
408 | status = -ENOENT; | |
409 | goto bail; | |
410 | } | |
411 | } | |
412 | ||
413 | status = ocfs2_info_scan_inode_alloc(osb, inode_alloc, blkno, oifi, i); | |
414 | if (status < 0) | |
415 | goto bail; | |
416 | ||
417 | iput(inode_alloc); | |
418 | inode_alloc = NULL; | |
419 | } | |
420 | ||
421 | o2info_set_request_filled(&oifi->ifi_req); | |
422 | ||
423 | if (o2info_to_user(*oifi, req)) | |
424 | goto bail; | |
425 | ||
426 | status = 0; | |
427 | bail: | |
428 | if (status) | |
429 | o2info_set_request_error(&oifi->ifi_req, req); | |
430 | ||
431 | kfree(oifi); | |
432 | ||
433 | return status; | |
434 | } | |
435 | ||
ddee5cdb TY |
436 | int ocfs2_info_handle_unknown(struct inode *inode, |
437 | struct ocfs2_info_request __user *req) | |
438 | { | |
439 | int status = -EFAULT; | |
440 | struct ocfs2_info_request oir; | |
441 | ||
442 | if (o2info_from_user(oir, req)) | |
443 | goto bail; | |
444 | ||
8aa1fa36 | 445 | o2info_clear_request_filled(&oir); |
ddee5cdb TY |
446 | |
447 | if (o2info_to_user(oir, req)) | |
448 | goto bail; | |
449 | ||
450 | status = 0; | |
451 | bail: | |
452 | if (status) | |
8aa1fa36 | 453 | o2info_set_request_error(&oir, req); |
ddee5cdb TY |
454 | |
455 | return status; | |
456 | } | |
457 | ||
458 | /* | |
459 | * Validate and distinguish OCFS2_IOC_INFO requests. | |
460 | * | |
461 | * - validate the magic number. | |
462 | * - distinguish different requests. | |
463 | * - validate size of different requests. | |
464 | */ | |
465 | int ocfs2_info_handle_request(struct inode *inode, | |
466 | struct ocfs2_info_request __user *req) | |
467 | { | |
468 | int status = -EFAULT; | |
469 | struct ocfs2_info_request oir; | |
470 | ||
471 | if (o2info_from_user(oir, req)) | |
472 | goto bail; | |
473 | ||
474 | status = -EINVAL; | |
475 | if (oir.ir_magic != OCFS2_INFO_MAGIC) | |
476 | goto bail; | |
477 | ||
478 | switch (oir.ir_code) { | |
479 | case OCFS2_INFO_BLOCKSIZE: | |
480 | if (oir.ir_size == sizeof(struct ocfs2_info_blocksize)) | |
481 | status = ocfs2_info_handle_blocksize(inode, req); | |
482 | break; | |
483 | case OCFS2_INFO_CLUSTERSIZE: | |
484 | if (oir.ir_size == sizeof(struct ocfs2_info_clustersize)) | |
485 | status = ocfs2_info_handle_clustersize(inode, req); | |
486 | break; | |
487 | case OCFS2_INFO_MAXSLOTS: | |
488 | if (oir.ir_size == sizeof(struct ocfs2_info_maxslots)) | |
489 | status = ocfs2_info_handle_maxslots(inode, req); | |
490 | break; | |
491 | case OCFS2_INFO_LABEL: | |
492 | if (oir.ir_size == sizeof(struct ocfs2_info_label)) | |
493 | status = ocfs2_info_handle_label(inode, req); | |
494 | break; | |
495 | case OCFS2_INFO_UUID: | |
496 | if (oir.ir_size == sizeof(struct ocfs2_info_uuid)) | |
497 | status = ocfs2_info_handle_uuid(inode, req); | |
498 | break; | |
499 | case OCFS2_INFO_FS_FEATURES: | |
500 | if (oir.ir_size == sizeof(struct ocfs2_info_fs_features)) | |
501 | status = ocfs2_info_handle_fs_features(inode, req); | |
502 | break; | |
503 | case OCFS2_INFO_JOURNAL_SIZE: | |
504 | if (oir.ir_size == sizeof(struct ocfs2_info_journal_size)) | |
505 | status = ocfs2_info_handle_journal_size(inode, req); | |
506 | break; | |
3e5db17d TY |
507 | case OCFS2_INFO_FREEINODE: |
508 | if (oir.ir_size == sizeof(struct ocfs2_info_freeinode)) | |
509 | status = ocfs2_info_handle_freeinode(inode, req); | |
510 | break; | |
ddee5cdb TY |
511 | default: |
512 | status = ocfs2_info_handle_unknown(inode, req); | |
513 | break; | |
514 | } | |
515 | ||
516 | bail: | |
517 | return status; | |
518 | } | |
519 | ||
520 | int ocfs2_get_request_ptr(struct ocfs2_info *info, int idx, | |
521 | u64 *req_addr, int compat_flag) | |
522 | { | |
523 | int status = -EFAULT; | |
524 | u64 __user *bp = NULL; | |
525 | ||
526 | if (compat_flag) { | |
527 | #ifdef CONFIG_COMPAT | |
528 | /* | |
529 | * pointer bp stores the base address of a pointers array, | |
530 | * which collects all addresses of separate request. | |
531 | */ | |
532 | bp = (u64 __user *)(unsigned long)compat_ptr(info->oi_requests); | |
533 | #else | |
534 | BUG(); | |
535 | #endif | |
536 | } else | |
537 | bp = (u64 __user *)(unsigned long)(info->oi_requests); | |
538 | ||
539 | if (o2info_from_user(*req_addr, bp + idx)) | |
540 | goto bail; | |
541 | ||
542 | status = 0; | |
543 | bail: | |
544 | return status; | |
545 | } | |
546 | ||
547 | /* | |
548 | * OCFS2_IOC_INFO handles an array of requests passed from userspace. | |
549 | * | |
550 | * ocfs2_info_handle() recevies a large info aggregation, grab and | |
551 | * validate the request count from header, then break it into small | |
552 | * pieces, later specific handlers can handle them one by one. | |
553 | * | |
554 | * Idea here is to make each separate request small enough to ensure | |
555 | * a better backward&forward compatibility, since a small piece of | |
556 | * request will be less likely to be broken if disk layout get changed. | |
557 | */ | |
558 | int ocfs2_info_handle(struct inode *inode, struct ocfs2_info *info, | |
559 | int compat_flag) | |
560 | { | |
561 | int i, status = 0; | |
562 | u64 req_addr; | |
563 | struct ocfs2_info_request __user *reqp; | |
564 | ||
565 | if ((info->oi_count > OCFS2_INFO_MAX_REQUEST) || | |
566 | (!info->oi_requests)) { | |
567 | status = -EINVAL; | |
568 | goto bail; | |
569 | } | |
570 | ||
571 | for (i = 0; i < info->oi_count; i++) { | |
572 | ||
573 | status = ocfs2_get_request_ptr(info, i, &req_addr, compat_flag); | |
574 | if (status) | |
575 | break; | |
576 | ||
577 | reqp = (struct ocfs2_info_request *)(unsigned long)req_addr; | |
578 | if (!reqp) { | |
579 | status = -EINVAL; | |
580 | goto bail; | |
581 | } | |
582 | ||
583 | status = ocfs2_info_handle_request(inode, reqp); | |
584 | if (status) | |
585 | break; | |
586 | } | |
587 | ||
588 | bail: | |
589 | return status; | |
590 | } | |
591 | ||
c9ec1488 | 592 | long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
ca4d147e | 593 | { |
c9ec1488 | 594 | struct inode *inode = filp->f_path.dentry->d_inode; |
ca4d147e | 595 | unsigned int flags; |
d659072f | 596 | int new_clusters; |
ca4d147e | 597 | int status; |
b2580103 | 598 | struct ocfs2_space_resv sr; |
7909f2bf | 599 | struct ocfs2_new_group_input input; |
bd50873d TM |
600 | struct reflink_arguments args; |
601 | const char *old_path, *new_path; | |
602 | bool preserve; | |
ddee5cdb | 603 | struct ocfs2_info info; |
ca4d147e HP |
604 | |
605 | switch (cmd) { | |
606 | case OCFS2_IOC_GETFLAGS: | |
607 | status = ocfs2_get_inode_attr(inode, &flags); | |
608 | if (status < 0) | |
609 | return status; | |
610 | ||
611 | flags &= OCFS2_FL_VISIBLE; | |
612 | return put_user(flags, (int __user *) arg); | |
613 | case OCFS2_IOC_SETFLAGS: | |
614 | if (get_user(flags, (int __user *) arg)) | |
615 | return -EFAULT; | |
616 | ||
42a74f20 DH |
617 | status = mnt_want_write(filp->f_path.mnt); |
618 | if (status) | |
619 | return status; | |
620 | status = ocfs2_set_inode_attr(inode, flags, | |
ca4d147e | 621 | OCFS2_FL_MODIFIABLE); |
42a74f20 DH |
622 | mnt_drop_write(filp->f_path.mnt); |
623 | return status; | |
b2580103 MF |
624 | case OCFS2_IOC_RESVSP: |
625 | case OCFS2_IOC_RESVSP64: | |
626 | case OCFS2_IOC_UNRESVSP: | |
627 | case OCFS2_IOC_UNRESVSP64: | |
628 | if (copy_from_user(&sr, (int __user *) arg, sizeof(sr))) | |
629 | return -EFAULT; | |
630 | ||
631 | return ocfs2_change_file_space(filp, cmd, &sr); | |
d659072f | 632 | case OCFS2_IOC_GROUP_EXTEND: |
0957f007 MF |
633 | if (!capable(CAP_SYS_RESOURCE)) |
634 | return -EPERM; | |
635 | ||
d659072f TM |
636 | if (get_user(new_clusters, (int __user *)arg)) |
637 | return -EFAULT; | |
638 | ||
639 | return ocfs2_group_extend(inode, new_clusters); | |
7909f2bf TM |
640 | case OCFS2_IOC_GROUP_ADD: |
641 | case OCFS2_IOC_GROUP_ADD64: | |
0957f007 MF |
642 | if (!capable(CAP_SYS_RESOURCE)) |
643 | return -EPERM; | |
644 | ||
7909f2bf TM |
645 | if (copy_from_user(&input, (int __user *) arg, sizeof(input))) |
646 | return -EFAULT; | |
647 | ||
648 | return ocfs2_group_add(inode, &input); | |
bd50873d TM |
649 | case OCFS2_IOC_REFLINK: |
650 | if (copy_from_user(&args, (struct reflink_arguments *)arg, | |
651 | sizeof(args))) | |
652 | return -EFAULT; | |
653 | old_path = (const char *)(unsigned long)args.old_path; | |
654 | new_path = (const char *)(unsigned long)args.new_path; | |
655 | preserve = (args.preserve != 0); | |
656 | ||
657 | return ocfs2_reflink_ioctl(inode, old_path, new_path, preserve); | |
ddee5cdb TY |
658 | case OCFS2_IOC_INFO: |
659 | if (copy_from_user(&info, (struct ocfs2_info __user *)arg, | |
660 | sizeof(struct ocfs2_info))) | |
661 | return -EFAULT; | |
662 | ||
663 | return ocfs2_info_handle(inode, &info, 0); | |
ca4d147e HP |
664 | default: |
665 | return -ENOTTY; | |
666 | } | |
667 | } | |
668 | ||
586d232b MF |
669 | #ifdef CONFIG_COMPAT |
670 | long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg) | |
671 | { | |
34e6c59a TM |
672 | bool preserve; |
673 | struct reflink_arguments args; | |
674 | struct inode *inode = file->f_path.dentry->d_inode; | |
ddee5cdb | 675 | struct ocfs2_info info; |
34e6c59a | 676 | |
586d232b MF |
677 | switch (cmd) { |
678 | case OCFS2_IOC32_GETFLAGS: | |
679 | cmd = OCFS2_IOC_GETFLAGS; | |
680 | break; | |
681 | case OCFS2_IOC32_SETFLAGS: | |
682 | cmd = OCFS2_IOC_SETFLAGS; | |
683 | break; | |
b2580103 MF |
684 | case OCFS2_IOC_RESVSP: |
685 | case OCFS2_IOC_RESVSP64: | |
686 | case OCFS2_IOC_UNRESVSP: | |
687 | case OCFS2_IOC_UNRESVSP64: | |
d659072f | 688 | case OCFS2_IOC_GROUP_EXTEND: |
7909f2bf TM |
689 | case OCFS2_IOC_GROUP_ADD: |
690 | case OCFS2_IOC_GROUP_ADD64: | |
b2580103 | 691 | break; |
34e6c59a TM |
692 | case OCFS2_IOC_REFLINK: |
693 | if (copy_from_user(&args, (struct reflink_arguments *)arg, | |
694 | sizeof(args))) | |
695 | return -EFAULT; | |
696 | preserve = (args.preserve != 0); | |
697 | ||
698 | return ocfs2_reflink_ioctl(inode, compat_ptr(args.old_path), | |
699 | compat_ptr(args.new_path), preserve); | |
ddee5cdb TY |
700 | case OCFS2_IOC_INFO: |
701 | if (copy_from_user(&info, (struct ocfs2_info __user *)arg, | |
702 | sizeof(struct ocfs2_info))) | |
703 | return -EFAULT; | |
704 | ||
705 | return ocfs2_info_handle(inode, &info, 1); | |
586d232b MF |
706 | default: |
707 | return -ENOIOCTLCMD; | |
708 | } | |
709 | ||
c9ec1488 | 710 | return ocfs2_ioctl(file, cmd, arg); |
586d232b MF |
711 | } |
712 | #endif |