2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
5 #include <linux/capability.h>
7 #include <linux/mount.h>
9 #include <linux/time.h>
10 #include <linux/uaccess.h>
11 #include <linux/pagemap.h>
12 #include <linux/compat.h>
13 #include <linux/fileattr.h>
15 int reiserfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
17 struct inode *inode = d_inode(dentry);
19 if (!reiserfs_attrs(inode->i_sb))
22 fileattr_fill_flags(fa, REISERFS_I(inode)->i_attrs);
27 int reiserfs_fileattr_set(struct mnt_idmap *idmap,
28 struct dentry *dentry, struct fileattr *fa)
30 struct inode *inode = d_inode(dentry);
31 unsigned int flags = fa->flags;
34 reiserfs_write_lock(inode->i_sb);
37 if (!reiserfs_attrs(inode->i_sb))
41 if (fileattr_has_fsx(fa))
45 * Is it quota file? Do not allow user to mess with it
48 if (IS_NOQUOTA(inode))
51 if ((flags & REISERFS_NOTAIL_FL) && S_ISREG(inode->i_mode)) {
52 err = reiserfs_unpack(inode);
56 sd_attrs_to_i_attrs(flags, inode);
57 REISERFS_I(inode)->i_attrs = flags;
58 inode_set_ctime_current(inode);
59 mark_inode_dirty(inode);
62 reiserfs_write_unlock(inode->i_sb);
68 * reiserfs_ioctl - handler for ioctl for inode
70 * 1) REISERFS_IOC_UNPACK - try to unpack tail from direct item into indirect
71 * and prevent packing file (argument arg has t
73 * 2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION
74 * 3) That's all for a while ...
76 long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
78 struct inode *inode = file_inode(filp);
81 reiserfs_write_lock(inode->i_sb);
84 case REISERFS_IOC_UNPACK:
85 if (S_ISREG(inode->i_mode)) {
87 err = reiserfs_unpack(inode);
92 * following two cases are taken from fs/ext2/ioctl.c by Remy
93 * Card (card@masi.ibp.fr)
95 case REISERFS_IOC_GETVERSION:
96 err = put_user(inode->i_generation, (int __user *)arg);
98 case REISERFS_IOC_SETVERSION:
99 if (!inode_owner_or_capable(&nop_mnt_idmap, inode)) {
103 err = mnt_want_write_file(filp);
106 if (get_user(inode->i_generation, (int __user *)arg)) {
110 inode_set_ctime_current(inode);
111 mark_inode_dirty(inode);
113 mnt_drop_write_file(filp);
119 reiserfs_write_unlock(inode->i_sb);
125 long reiserfs_compat_ioctl(struct file *file, unsigned int cmd,
129 * These are just misnamed, they actually
130 * get/put from/to user an int
133 case REISERFS_IOC32_UNPACK:
134 cmd = REISERFS_IOC_UNPACK;
136 case REISERFS_IOC32_GETVERSION:
137 cmd = REISERFS_IOC_GETVERSION;
139 case REISERFS_IOC32_SETVERSION:
140 cmd = REISERFS_IOC_SETVERSION;
146 return reiserfs_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
150 int reiserfs_commit_write(struct file *f, struct page *page,
151 unsigned from, unsigned to);
154 * Function try to convert tail from direct item into indirect.
155 * It set up nopack attribute in the REISERFS_I(inode)->nopack
157 int reiserfs_unpack(struct inode *inode)
162 struct address_space *mapping;
163 unsigned long write_from;
164 unsigned long blocksize = inode->i_sb->s_blocksize;
166 if (inode->i_size == 0) {
167 REISERFS_I(inode)->i_flags |= i_nopack_mask;
170 /* ioctl already done */
171 if (REISERFS_I(inode)->i_flags & i_nopack_mask) {
175 /* we need to make sure nobody is changing the file size beneath us */
177 int depth = reiserfs_write_unlock_nested(inode->i_sb);
180 reiserfs_write_lock_nested(inode->i_sb, depth);
183 reiserfs_write_lock(inode->i_sb);
185 write_from = inode->i_size & (blocksize - 1);
186 /* if we are on a block boundary, we are already unpacked. */
187 if (write_from == 0) {
188 REISERFS_I(inode)->i_flags |= i_nopack_mask;
193 * we unpack by finding the page with the tail, and calling
194 * __reiserfs_write_begin on that page. This will force a
195 * reiserfs_get_block to unpack the tail for us.
197 index = inode->i_size >> PAGE_SHIFT;
198 mapping = inode->i_mapping;
199 page = grab_cache_page(mapping, index);
204 retval = __reiserfs_write_begin(page, write_from, 0);
208 /* conversion can change page contents, must flush */
209 flush_dcache_page(page);
210 retval = reiserfs_commit_write(NULL, page, write_from, write_from);
211 REISERFS_I(inode)->i_flags |= i_nopack_mask;
219 reiserfs_write_unlock(inode->i_sb);