2 * Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
6 #include <linux/reiserfs_fs.h>
7 #include <linux/sched.h>
8 #include <asm/uaccess.h>
9 #include <linux/smp_lock.h>
10 #include <linux/locks.h>
13 ** reiserfs_ioctl - handler for ioctl for inode
14 ** supported commands:
15 ** 1) REISERFS_IOC_UNPACK - try to unpack tail from direct item into indirect
16 ** and prevent packing file (argument arg has to be non-zero)
17 ** 2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION
18 ** 3) That's all for a while ...
20 int reiserfs_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
26 case REISERFS_IOC_UNPACK:
27 if( S_ISREG( inode -> i_mode ) ) {
29 return reiserfs_unpack (inode, filp);
35 * Following {G,S}ETFLAGS, and {G,S}ETVERSION are providing ext2
36 * binary compatible interface (used by lsattr(1), and chattr(1)) and
37 * are * thus conceptually similar to appropriate pieces of
40 case REISERFS_IOC_GETFLAGS:
41 flags = inode -> u.reiserfs_i.i_attrs;
42 i_attrs_to_sd_attrs( inode, ( __u16 * ) &flags );
43 return put_user(flags, (int *) arg);
44 case REISERFS_IOC_SETFLAGS: {
48 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
51 if (get_user(flags, (int *) arg))
54 if ( ( ( flags ^ inode->u.reiserfs_i.i_attrs) & ( REISERFS_IMMUTABLE_FL | REISERFS_APPEND_FL)) &&
55 !capable( CAP_LINUX_IMMUTABLE ) )
58 if( ( flags & REISERFS_NOTAIL_FL ) &&
59 S_ISREG( inode -> i_mode ) ) {
62 result = reiserfs_unpack( inode, filp );
66 sd_attrs_to_i_attrs( flags, inode );
67 inode -> u.reiserfs_i.i_attrs = flags;
68 inode->i_ctime = CURRENT_TIME;
69 mark_inode_dirty(inode);
72 case REISERFS_IOC_GETVERSION:
73 return put_user(inode->i_generation, (int *) arg);
74 case REISERFS_IOC_SETVERSION:
75 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
79 if (get_user(inode->i_generation, (int *) arg))
81 inode->i_ctime = CURRENT_TIME;
82 mark_inode_dirty(inode);
92 ** Function try to convert tail from direct item into indirect.
93 ** It set up nopack attribute in the inode.u.reiserfs_i.nopack
95 int reiserfs_unpack (struct inode * inode, struct file * filp)
100 unsigned long write_from ;
101 unsigned long blocksize = inode->i_sb->s_blocksize ;
103 if (inode->i_size == 0) {
104 inode->u.reiserfs_i.i_flags |= i_nopack_mask;
107 /* ioctl already done */
108 if (inode->u.reiserfs_i.i_flags & i_nopack_mask) {
113 /* we need to make sure nobody is changing the file size beneath
116 down(&inode->i_sem) ;
118 write_from = inode->i_size & (blocksize - 1) ;
119 /* if we are on a block boundary, we are already unpacked. */
120 if ( write_from == 0) {
121 inode->u.reiserfs_i.i_flags |= i_nopack_mask;
125 /* we unpack by finding the page with the tail, and calling
126 ** reiserfs_prepare_write on that page. This will force a
127 ** reiserfs_get_block to unpack the tail for us.
129 index = inode->i_size >> PAGE_CACHE_SHIFT ;
130 page = grab_cache_page(inode->i_mapping, index) ;
135 retval = reiserfs_prepare_write(NULL, page, write_from, blocksize) ;
139 /* conversion can change page contents, must flush */
140 flush_dcache_page(page) ;
141 inode->u.reiserfs_i.i_flags |= i_nopack_mask;
142 kunmap(page) ; /* mapped by prepare_write */
146 page_cache_release(page) ;