The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/jfs/file.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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/fs.h>
   21 #include "jfs_incore.h"
   22 #include "jfs_dmap.h"
   23 #include "jfs_txnmgr.h"
   24 #include "jfs_xattr.h"
   25 #include "jfs_debug.h"
   26 
   27 
   28 extern int jfs_commit_inode(struct inode *, int);
   29 extern void jfs_truncate(struct inode *);
   30 
   31 int jfs_fsync(struct file *file, struct dentry *dentry, int datasync)
   32 {
   33         struct inode *inode = dentry->d_inode;
   34         int rc = 0;
   35 
   36         /* No need to resync the data at commit time, unless this flag gets
   37          * set again */
   38         clear_cflag(COMMIT_Syncdata, inode);
   39 
   40         rc = fsync_inode_data_buffers(inode);
   41 
   42         if (!(inode->i_state & I_DIRTY))
   43                 return rc;
   44         if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
   45                 return rc;
   46 
   47         rc |= jfs_commit_inode(inode, 1);
   48 
   49         return rc ? -EIO : 0;
   50 }
   51 
   52 static int jfs_open(struct inode *inode, struct file *file)
   53 {
   54         int rc;
   55 
   56         if ((rc = generic_file_open(inode, file)))
   57                 return rc;
   58 
   59         /*
   60          * We attempt to allow only one "active" file open per aggregate
   61          * group.  Otherwise, appending to files in parallel can cause
   62          * fragmentation within the files.
   63          *
   64          * If the file is empty, it was probably just created and going
   65          * to be written to.  If it has a size, we'll hold off until the
   66          * file is actually grown.
   67          */
   68         if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE &&
   69             (inode->i_size == 0)) {
   70                 struct jfs_inode_info *ji = JFS_IP(inode);
   71                 if (ji->active_ag == -1) {
   72                         ji->active_ag = ji->agno;
   73                         atomic_inc(
   74                             &JFS_SBI(inode->i_sb)->bmap->db_active[ji->agno]);
   75                 }
   76         }
   77 
   78         return 0;
   79 }
   80 static int jfs_release(struct inode *inode, struct file *file)
   81 {
   82         struct jfs_inode_info *ji = JFS_IP(inode);
   83 
   84         if (ji->active_ag != -1) {
   85                 struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
   86                 atomic_dec(&bmap->db_active[ji->active_ag]);
   87                 ji->active_ag = -1;
   88         }
   89 
   90         return 0;
   91 }
   92 
   93 struct inode_operations jfs_file_inode_operations = {
   94         .truncate       = jfs_truncate,
   95         .setxattr       = jfs_setxattr,
   96         .getxattr       = jfs_getxattr,
   97         .listxattr      = jfs_listxattr,
   98         .removexattr    = jfs_removexattr,
   99 };
  100 
  101 struct file_operations jfs_file_operations = {
  102         .open           = jfs_open,
  103         .llseek         = generic_file_llseek,
  104         .write          = generic_file_write,
  105         .read           = generic_file_read,
  106         .mmap           = generic_file_mmap,
  107         .fsync          = jfs_fsync,
  108         .release        = jfs_release,
  109 };

Cache object: c8030fcc6b5c14b5331de31e809a7802


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.