Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *   Copyright (C) International Business Machines Corp., 2000-2002
  4 *   Portions Copyright (C) Christoph Hellwig, 2001-2002
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  5 */
  6
  7#include <linux/mm.h>
  8#include <linux/fs.h>
  9#include <linux/posix_acl.h>
 10#include <linux/quotaops.h>
 11#include "jfs_incore.h"
 12#include "jfs_inode.h"
 13#include "jfs_dmap.h"
 14#include "jfs_txnmgr.h"
 15#include "jfs_xattr.h"
 16#include "jfs_acl.h"
 17#include "jfs_debug.h"
 18
 19int jfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 20{
 21	struct inode *inode = file->f_mapping->host;
 22	int rc = 0;
 23
 24	rc = file_write_and_wait_range(file, start, end);
 25	if (rc)
 26		return rc;
 27
 28	inode_lock(inode);
 29	if (!(inode->i_state & I_DIRTY_ALL) ||
 30	    (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) {
 31		/* Make sure committed changes hit the disk */
 32		jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1);
 33		inode_unlock(inode);
 34		return rc;
 35	}
 36
 37	rc |= jfs_commit_inode(inode, 1);
 38	inode_unlock(inode);
 39
 40	return rc ? -EIO : 0;
 41}
 42
 43static int jfs_open(struct inode *inode, struct file *file)
 44{
 45	int rc;
 46
 47	if ((rc = dquot_file_open(inode, file)))
 48		return rc;
 49
 50	/*
 51	 * We attempt to allow only one "active" file open per aggregate
 52	 * group.  Otherwise, appending to files in parallel can cause
 53	 * fragmentation within the files.
 54	 *
 55	 * If the file is empty, it was probably just created and going
 56	 * to be written to.  If it has a size, we'll hold off until the
 57	 * file is actually grown.
 58	 */
 59	if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE &&
 60	    (inode->i_size == 0)) {
 61		struct jfs_inode_info *ji = JFS_IP(inode);
 62		spin_lock_irq(&ji->ag_lock);
 63		if (ji->active_ag == -1) {
 64			struct jfs_sb_info *jfs_sb = JFS_SBI(inode->i_sb);
 65			ji->active_ag = BLKTOAG(addressPXD(&ji->ixpxd), jfs_sb);
 66			atomic_inc(&jfs_sb->bmap->db_active[ji->active_ag]);
 67		}
 68		spin_unlock_irq(&ji->ag_lock);
 69	}
 70
 71	return 0;
 72}
 73static int jfs_release(struct inode *inode, struct file *file)
 74{
 75	struct jfs_inode_info *ji = JFS_IP(inode);
 76
 77	spin_lock_irq(&ji->ag_lock);
 78	if (ji->active_ag != -1) {
 79		struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
 80		atomic_dec(&bmap->db_active[ji->active_ag]);
 81		ji->active_ag = -1;
 82	}
 83	spin_unlock_irq(&ji->ag_lock);
 84
 85	return 0;
 86}
 87
 88int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
 89{
 90	struct inode *inode = d_inode(dentry);
 91	int rc;
 92
 93	rc = setattr_prepare(dentry, iattr);
 94	if (rc)
 95		return rc;
 96
 97	if (is_quota_modification(inode, iattr)) {
 98		rc = dquot_initialize(inode);
 99		if (rc)
100			return rc;
101	}
102	if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
103	    (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
104		rc = dquot_transfer(inode, iattr);
105		if (rc)
106			return rc;
107	}
108
109	if ((iattr->ia_valid & ATTR_SIZE) &&
110	    iattr->ia_size != i_size_read(inode)) {
111		inode_dio_wait(inode);
112
113		rc = inode_newsize_ok(inode, iattr->ia_size);
114		if (rc)
115			return rc;
116
117		truncate_setsize(inode, iattr->ia_size);
118		jfs_truncate(inode);
119	}
120
121	setattr_copy(inode, iattr);
122	mark_inode_dirty(inode);
123
124	if (iattr->ia_valid & ATTR_MODE)
125		rc = posix_acl_chmod(inode, inode->i_mode);
126	return rc;
127}
128
129const struct inode_operations jfs_file_inode_operations = {
 
 
 
130	.listxattr	= jfs_listxattr,
 
131	.setattr	= jfs_setattr,
132#ifdef CONFIG_JFS_POSIX_ACL
133	.get_acl	= jfs_get_acl,
134	.set_acl	= jfs_set_acl,
135#endif
136};
137
138const struct file_operations jfs_file_operations = {
139	.open		= jfs_open,
140	.llseek		= generic_file_llseek,
141	.read_iter	= generic_file_read_iter,
142	.write_iter	= generic_file_write_iter,
 
 
143	.mmap		= generic_file_mmap,
144	.splice_read	= generic_file_splice_read,
145	.splice_write	= iter_file_splice_write,
146	.fsync		= jfs_fsync,
147	.release	= jfs_release,
148	.unlocked_ioctl = jfs_ioctl,
149#ifdef CONFIG_COMPAT
150	.compat_ioctl	= jfs_compat_ioctl,
151#endif
152};
v3.1
 
  1/*
  2 *   Copyright (C) International Business Machines Corp., 2000-2002
  3 *   Portions Copyright (C) Christoph Hellwig, 2001-2002
  4 *
  5 *   This program is free software;  you can redistribute it and/or modify
  6 *   it under the terms of the GNU General Public License as published by
  7 *   the Free Software Foundation; either version 2 of the License, or
  8 *   (at your option) any later version.
  9 *
 10 *   This program is distributed in the hope that it will be useful,
 11 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 13 *   the GNU General Public License for more details.
 14 *
 15 *   You should have received a copy of the GNU General Public License
 16 *   along with this program;  if not, write to the Free Software
 17 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 18 */
 19
 20#include <linux/mm.h>
 21#include <linux/fs.h>
 
 22#include <linux/quotaops.h>
 23#include "jfs_incore.h"
 24#include "jfs_inode.h"
 25#include "jfs_dmap.h"
 26#include "jfs_txnmgr.h"
 27#include "jfs_xattr.h"
 28#include "jfs_acl.h"
 29#include "jfs_debug.h"
 30
 31int jfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 32{
 33	struct inode *inode = file->f_mapping->host;
 34	int rc = 0;
 35
 36	rc = filemap_write_and_wait_range(inode->i_mapping, start, end);
 37	if (rc)
 38		return rc;
 39
 40	mutex_lock(&inode->i_mutex);
 41	if (!(inode->i_state & I_DIRTY) ||
 42	    (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) {
 43		/* Make sure committed changes hit the disk */
 44		jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1);
 45		mutex_unlock(&inode->i_mutex);
 46		return rc;
 47	}
 48
 49	rc |= jfs_commit_inode(inode, 1);
 50	mutex_unlock(&inode->i_mutex);
 51
 52	return rc ? -EIO : 0;
 53}
 54
 55static int jfs_open(struct inode *inode, struct file *file)
 56{
 57	int rc;
 58
 59	if ((rc = dquot_file_open(inode, file)))
 60		return rc;
 61
 62	/*
 63	 * We attempt to allow only one "active" file open per aggregate
 64	 * group.  Otherwise, appending to files in parallel can cause
 65	 * fragmentation within the files.
 66	 *
 67	 * If the file is empty, it was probably just created and going
 68	 * to be written to.  If it has a size, we'll hold off until the
 69	 * file is actually grown.
 70	 */
 71	if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE &&
 72	    (inode->i_size == 0)) {
 73		struct jfs_inode_info *ji = JFS_IP(inode);
 74		spin_lock_irq(&ji->ag_lock);
 75		if (ji->active_ag == -1) {
 76			struct jfs_sb_info *jfs_sb = JFS_SBI(inode->i_sb);
 77			ji->active_ag = BLKTOAG(addressPXD(&ji->ixpxd), jfs_sb);
 78			atomic_inc( &jfs_sb->bmap->db_active[ji->active_ag]);
 79		}
 80		spin_unlock_irq(&ji->ag_lock);
 81	}
 82
 83	return 0;
 84}
 85static int jfs_release(struct inode *inode, struct file *file)
 86{
 87	struct jfs_inode_info *ji = JFS_IP(inode);
 88
 89	spin_lock_irq(&ji->ag_lock);
 90	if (ji->active_ag != -1) {
 91		struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
 92		atomic_dec(&bmap->db_active[ji->active_ag]);
 93		ji->active_ag = -1;
 94	}
 95	spin_unlock_irq(&ji->ag_lock);
 96
 97	return 0;
 98}
 99
100int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
101{
102	struct inode *inode = dentry->d_inode;
103	int rc;
104
105	rc = inode_change_ok(inode, iattr);
106	if (rc)
107		return rc;
108
109	if (is_quota_modification(inode, iattr))
110		dquot_initialize(inode);
111	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
112	    (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
 
 
 
113		rc = dquot_transfer(inode, iattr);
114		if (rc)
115			return rc;
116	}
117
118	if ((iattr->ia_valid & ATTR_SIZE) &&
119	    iattr->ia_size != i_size_read(inode)) {
120		inode_dio_wait(inode);
121
122		rc = vmtruncate(inode, iattr->ia_size);
123		if (rc)
124			return rc;
 
 
 
125	}
126
127	setattr_copy(inode, iattr);
128	mark_inode_dirty(inode);
129
130	if (iattr->ia_valid & ATTR_MODE)
131		rc = jfs_acl_chmod(inode);
132	return rc;
133}
134
135const struct inode_operations jfs_file_inode_operations = {
136	.truncate	= jfs_truncate,
137	.setxattr	= jfs_setxattr,
138	.getxattr	= jfs_getxattr,
139	.listxattr	= jfs_listxattr,
140	.removexattr	= jfs_removexattr,
141	.setattr	= jfs_setattr,
142#ifdef CONFIG_JFS_POSIX_ACL
143	.get_acl	= jfs_get_acl,
 
144#endif
145};
146
147const struct file_operations jfs_file_operations = {
148	.open		= jfs_open,
149	.llseek		= generic_file_llseek,
150	.write		= do_sync_write,
151	.read		= do_sync_read,
152	.aio_read	= generic_file_aio_read,
153	.aio_write	= generic_file_aio_write,
154	.mmap		= generic_file_mmap,
155	.splice_read	= generic_file_splice_read,
156	.splice_write	= generic_file_splice_write,
157	.fsync		= jfs_fsync,
158	.release	= jfs_release,
159	.unlocked_ioctl = jfs_ioctl,
160#ifdef CONFIG_COMPAT
161	.compat_ioctl	= jfs_compat_ioctl,
162#endif
163};