Skip to content

Commit dab5ca8

Browse files
author
Miklos Szeredi
committed
ovl: add lsattr/chattr support
Implement FS_IOC_GETFLAGS and FS_IOC_SETFLAGS. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent aab8848 commit dab5ca8

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

‎fs/overlayfs/file.c‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/cred.h>
1010
#include <linux/file.h>
11+
#include <linux/mount.h>
1112
#include <linux/xattr.h>
1213
#include <linux/uio.h>
1314
#include "overlayfs.h"
@@ -309,6 +310,82 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
309310
return ret;
310311
}
311312

313+
static long ovl_real_ioctl(struct file *file, unsigned int cmd,
314+
unsigned long arg)
315+
{
316+
struct fd real;
317+
const struct cred *old_cred;
318+
long ret;
319+
320+
ret = ovl_real_fdget(file, &real);
321+
if (ret)
322+
return ret;
323+
324+
old_cred = ovl_override_creds(file_inode(file)->i_sb);
325+
ret = vfs_ioctl(real.file, cmd, arg);
326+
revert_creds(old_cred);
327+
328+
fdput(real);
329+
330+
return ret;
331+
}
332+
333+
static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
334+
{
335+
long ret;
336+
struct inode *inode = file_inode(file);
337+
338+
switch (cmd) {
339+
case FS_IOC_GETFLAGS:
340+
ret = ovl_real_ioctl(file, cmd, arg);
341+
break;
342+
343+
case FS_IOC_SETFLAGS:
344+
if (!inode_owner_or_capable(inode))
345+
return -EACCES;
346+
347+
ret = mnt_want_write_file(file);
348+
if (ret)
349+
return ret;
350+
351+
ret = ovl_copy_up(file_dentry(file));
352+
if (!ret) {
353+
ret = ovl_real_ioctl(file, cmd, arg);
354+
355+
inode_lock(inode);
356+
ovl_copyflags(ovl_inode_real(inode), inode);
357+
inode_unlock(inode);
358+
}
359+
360+
mnt_drop_write_file(file);
361+
break;
362+
363+
default:
364+
ret = -ENOTTY;
365+
}
366+
367+
return ret;
368+
}
369+
370+
static long ovl_compat_ioctl(struct file *file, unsigned int cmd,
371+
unsigned long arg)
372+
{
373+
switch (cmd) {
374+
case FS_IOC32_GETFLAGS:
375+
cmd = FS_IOC_GETFLAGS;
376+
break;
377+
378+
case FS_IOC32_SETFLAGS:
379+
cmd = FS_IOC_SETFLAGS;
380+
break;
381+
382+
default:
383+
return -ENOIOCTLCMD;
384+
}
385+
386+
return ovl_ioctl(file, cmd, arg);
387+
}
388+
312389
const struct file_operations ovl_file_operations = {
313390
.open = ovl_open,
314391
.release = ovl_release,
@@ -318,4 +395,6 @@ const struct file_operations ovl_file_operations = {
318395
.fsync = ovl_fsync,
319396
.mmap = ovl_mmap,
320397
.fallocate = ovl_fallocate,
398+
.unlocked_ioctl = ovl_ioctl,
399+
.compat_ioctl = ovl_compat_ioctl,
321400
};

0 commit comments

Comments
 (0)