2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
5 #include <linux/capability.h>
7 #include <linux/mount.h>
8 #include <linux/reiserfs_fs.h>
9 #include <linux/time.h>
10 #include <asm/uaccess.h>
11 #include <linux/pagemap.h>
12 #include <linux/compat.h>
15 * reiserfs_ioctl - handler for ioctl for inode
17 * 1) REISERFS_IOC_UNPACK - try to unpack tail from direct item into indirect
18 * and prevent packing file (argument arg has to be non-zero)
19 * 2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION
20 * 3) That's all for a while ...
22 long reiserfs_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
24 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
28 reiserfs_write_lock(inode
->i_sb
);
31 case REISERFS_IOC_UNPACK
:
32 if (S_ISREG(inode
->i_mode
)) {
34 err
= reiserfs_unpack(inode
, filp
);
39 * following two cases are taken from fs/ext2/ioctl.c by Remy
40 * Card (card@masi.ibp.fr)
42 case REISERFS_IOC_GETFLAGS
:
43 if (!reiserfs_attrs(inode
->i_sb
)) {
48 flags
= REISERFS_I(inode
)->i_attrs
;
49 i_attrs_to_sd_attrs(inode
, (__u16
*) & flags
);
50 err
= put_user(flags
, (int __user
*)arg
);
52 case REISERFS_IOC_SETFLAGS
:{
53 if (!reiserfs_attrs(inode
->i_sb
)) {
58 err
= mnt_want_write(filp
->f_path
.mnt
);
62 if (!is_owner_or_cap(inode
)) {
66 if (get_user(flags
, (int __user
*)arg
)) {
71 * Is it quota file? Do not allow user to mess with it
73 if (IS_NOQUOTA(inode
)) {
77 if (((flags
^ REISERFS_I(inode
)->
78 i_attrs
) & (REISERFS_IMMUTABLE_FL
|
80 && !capable(CAP_LINUX_IMMUTABLE
)) {
84 if ((flags
& REISERFS_NOTAIL_FL
) &&
85 S_ISREG(inode
->i_mode
)) {
88 result
= reiserfs_unpack(inode
, filp
);
94 sd_attrs_to_i_attrs(flags
, inode
);
95 REISERFS_I(inode
)->i_attrs
= flags
;
96 inode
->i_ctime
= CURRENT_TIME_SEC
;
97 mark_inode_dirty(inode
);
99 mnt_drop_write(filp
->f_path
.mnt
);
102 case REISERFS_IOC_GETVERSION
:
103 err
= put_user(inode
->i_generation
, (int __user
*)arg
);
105 case REISERFS_IOC_SETVERSION
:
106 if (!is_owner_or_cap(inode
)) {
110 err
= mnt_want_write(filp
->f_path
.mnt
);
113 if (get_user(inode
->i_generation
, (int __user
*)arg
)) {
117 inode
->i_ctime
= CURRENT_TIME_SEC
;
118 mark_inode_dirty(inode
);
120 mnt_drop_write(filp
->f_path
.mnt
);
126 reiserfs_write_unlock(inode
->i_sb
);
132 long reiserfs_compat_ioctl(struct file
*file
, unsigned int cmd
,
135 /* These are just misnamed, they actually get/put from/to user an int */
137 case REISERFS_IOC32_UNPACK
:
138 cmd
= REISERFS_IOC_UNPACK
;
140 case REISERFS_IOC32_GETFLAGS
:
141 cmd
= REISERFS_IOC_GETFLAGS
;
143 case REISERFS_IOC32_SETFLAGS
:
144 cmd
= REISERFS_IOC_SETFLAGS
;
146 case REISERFS_IOC32_GETVERSION
:
147 cmd
= REISERFS_IOC_GETVERSION
;
149 case REISERFS_IOC32_SETVERSION
:
150 cmd
= REISERFS_IOC_SETVERSION
;
156 return reiserfs_ioctl(file
, cmd
, (unsigned long) compat_ptr(arg
));
160 int reiserfs_commit_write(struct file
*f
, struct page
*page
,
161 unsigned from
, unsigned to
);
164 ** Function try to convert tail from direct item into indirect.
165 ** It set up nopack attribute in the REISERFS_I(inode)->nopack
167 int reiserfs_unpack(struct inode
*inode
, struct file
*filp
)
173 struct address_space
*mapping
;
174 unsigned long write_from
;
175 unsigned long blocksize
= inode
->i_sb
->s_blocksize
;
177 if (inode
->i_size
== 0) {
178 REISERFS_I(inode
)->i_flags
|= i_nopack_mask
;
181 /* ioctl already done */
182 if (REISERFS_I(inode
)->i_flags
& i_nopack_mask
) {
186 depth
= reiserfs_write_lock_once(inode
->i_sb
);
188 /* we need to make sure nobody is changing the file size beneath us */
189 reiserfs_mutex_lock_safe(&inode
->i_mutex
, inode
->i_sb
);
191 write_from
= inode
->i_size
& (blocksize
- 1);
192 /* if we are on a block boundary, we are already unpacked. */
193 if (write_from
== 0) {
194 REISERFS_I(inode
)->i_flags
|= i_nopack_mask
;
198 /* we unpack by finding the page with the tail, and calling
199 ** __reiserfs_write_begin on that page. This will force a
200 ** reiserfs_get_block to unpack the tail for us.
202 index
= inode
->i_size
>> PAGE_CACHE_SHIFT
;
203 mapping
= inode
->i_mapping
;
204 page
= grab_cache_page(mapping
, index
);
209 retval
= __reiserfs_write_begin(page
, write_from
, 0);
213 /* conversion can change page contents, must flush */
214 flush_dcache_page(page
);
215 retval
= reiserfs_commit_write(NULL
, page
, write_from
, write_from
);
216 REISERFS_I(inode
)->i_flags
|= i_nopack_mask
;
220 page_cache_release(page
);
223 mutex_unlock(&inode
->i_mutex
);
224 reiserfs_write_unlock_once(inode
->i_sb
, depth
);