<commit_before>/*
 * Copyright 2000 by <NAME>, licensing governed by reiserfs/README
 */

#include <linux/fs.h>
#include <linux/reiserfs_fs.h>
#include <linux/time.h>
#include <asm/uaccess.h>
#include <linux/pagemap.h>
#include <linux/smp_lock.h>

static int reiserfs_unpack (struct inode * inode, struct file * filp);

/*
** reiserfs_ioctl - handler for ioctl for inode
** supported commands:
**  1) REISERFS_IOC_UNPACK - try to unpack tail from direct item into indirect
**                           and prevent packing file (argument arg has to be non-zero)
**  2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION
**  3) That's all for a while ...
*/
int reiserfs_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
		unsigned long arg)
{
	unsigned int flags;

	switch (cmd) {
	    case REISERFS_IOC_UNPACK:
		if( S_ISREG( inode -> i_mode ) ) {
		if (arg)
		    return reiserfs_unpack (inode, filp);
			else
				return 0;
		} else
			return -ENOTTY;
	/* following two cases are taken from fs/ext2/ioctl.c by Remy
	   Card (<EMAIL>) */
	case REISERFS_IOC_GETFLAGS:
		flags = REISERFS_I(inode) -> i_attrs;
		i_attrs_to_sd_attrs( inode, ( __u16 * ) &flags );
		return put_user(flags, (int __user *) arg);
	case REISERFS_IOC_SETFLAGS: {
		if (IS_RDONLY(inode))
			return -EROFS;

		if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
			return -EPERM;

		if (get_user(flags, (int __user *) arg))
			return -EFAULT;

		if ( ( ( flags ^ REISERFS_I(inode) -> i_attrs) & ( REISERFS_IMMUTABLE_FL | REISERFS_APPEND_FL)) &&
		     !capable( CAP_LINUX_IMMUTABLE ) )
			return -EPERM;
			
		if( ( flags & REISERFS_NOTAIL_FL ) &&
		    S_ISREG( inode -> i_mode ) ) {
				int result;

				result = reiserfs_unpack( inode, filp );
				if( result )
					return result;<commit_msg>[PATCH] reiserfs: Check if attrs are enabled for attr ioctls<commit_after>/*
 * Copyright 2000 by <NAME>, licensing governed by reiserfs/README
 */

#include <linux/fs.h>
#include <linux/reiserfs_fs.h>
#include <linux/time.h>
#include <asm/uaccess.h>
#include <linux/pagemap.h>
#include <linux/smp_lock.h>

static int reiserfs_unpack (struct inode * inode, struct file * filp);

/*
** reiserfs_ioctl - handler for ioctl for inode
** supported commands:
**  1) REISERFS_IOC_UNPACK - try to unpack tail from direct item into indirect
**                           and prevent packing file (argument arg has to be non-zero)
**  2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION
**  3) That's all for a while ...
*/
int reiserfs_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
		unsigned long arg)
{
	unsigned int flags;

	switch (cmd) {
	    case REISERFS_IOC_UNPACK:
		if( S_ISREG( inode -> i_mode ) ) {
		if (arg)
		    return reiserfs_unpack (inode, filp);
			else
				return 0;
		} else
			return -ENOTTY;
	/* following two cases are taken from fs/ext2/ioctl.c by <NAME> (<EMAIL>) */
	case REISERFS_IOC_GETFLAGS:
		if (!reiserfs_attrs (inode->i_sb))
			return -ENOTTY;

		flags = REISERFS_I(inode) -> i_attrs;
		i_attrs_to_sd_attrs( inode, ( __u16 * ) &flags );
		return put_user(flags, (int __user *) arg);
	case REISERFS_IOC_SETFLAGS: {
		if (!reiserfs_attrs (inode->i_sb))
			return -ENOTTY;

		if (IS_RDONLY(inode))
			return -EROFS;

		if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
			return -EPERM;

		if (get_user(flags, (int __user *) arg))
			return -EFAULT;

		if ( ( ( flags ^ REISERFS_I(inode) -> i_attrs) & ( REISERFS_IMMUTABLE_FL | REISERFS_APPEND_FL)) &&
		     !capable( CAP_LINUX_IMMUTABLE ) )
			return -EPERM;
			
		if( ( flags & REISERFS_NOTAIL_FL ) &&
		    S_ISREG( inode -> i_mode ) ) {
				int result;

				result = reiserfs_unpack( inode, filp );
				if( result )
					return result;
{'fraction_non_alphanumeric': 0.12526709401709402, 'fraction_numerical': 0.005876068376068376, 'mean_word_length': 3.3903868698710435, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7444105', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1418, 'n_words': 367}