journal_ext2.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  2.  * vim:expandtab:shiftwidth=8:tabstop=8:
  3.  *
  4.  *  Copyright (C) 1998 Peter J. Braam <braam@clusterfs.com>
  5.  *
  6.  *   This file is part of InterMezzo, http://www.inter-mezzo.org.
  7.  *
  8.  *   InterMezzo is free software; you can redistribute it and/or
  9.  *   modify it under the terms of version 2 of the GNU General Public
  10.  *   License as published by the Free Software Foundation.
  11.  *
  12.  *   InterMezzo is distributed in the hope that it will be useful,
  13.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *   GNU General Public License for more details.
  16.  *
  17.  *   You should have received a copy of the GNU General Public License
  18.  *   along with InterMezzo; if not, write to the Free Software
  19.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21. #include <linux/types.h>
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include <linux/fs.h>
  25. #include <linux/slab.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/stat.h>
  28. #include <linux/errno.h>
  29. #include <linux/locks.h>
  30. #include <asm/segment.h>
  31. #include <asm/uaccess.h>
  32. #include <linux/string.h>
  33. #include <linux/ext2_fs.h> 
  34. #include <linux/intermezzo_fs.h>
  35. #include <linux/intermezzo_psdev.h>
  36. #if defined(CONFIG_EXT2_FS)
  37. /* EXT2 has no journalling, so these functions do nothing */
  38. static loff_t presto_e2_freespace(struct presto_cache *cache,
  39.                                          struct super_block *sb)
  40. {
  41.         unsigned long freebl = le32_to_cpu(sb->u.ext2_sb.s_es->s_free_blocks_count);
  42.         unsigned long avail =   freebl - le32_to_cpu(sb->u.ext2_sb.s_es->s_r_blocks_count);
  43. return (avail <<  EXT2_BLOCK_SIZE_BITS(sb));
  44. }
  45. /* start the filesystem journal operations */
  46. static void *presto_e2_trans_start(struct presto_file_set *fset, struct inode *inode, int op)
  47. {
  48.         __u32 avail_kmlblocks;
  49.         if ( presto_no_journal(fset) ||
  50.              strcmp(fset->fset_cache->cache_type, "ext2"))
  51.                 return NULL;
  52.         avail_kmlblocks = inode->i_sb->u.ext2_sb.s_es->s_free_blocks_count;
  53.         
  54.         if ( avail_kmlblocks < 3 ) {
  55.                 return ERR_PTR(-ENOSPC);
  56.         }
  57.         
  58.         if (  (op != KML_OPCODE_UNLINK && op != KML_OPCODE_RMDIR)
  59.               && avail_kmlblocks < 6 ) {
  60.                 return ERR_PTR(-ENOSPC);
  61.         }            
  62. return (void *) 1;
  63. }
  64. static void presto_e2_trans_commit(struct presto_file_set *fset, void *handle)
  65. {
  66.         do {} while (0);
  67. }
  68. static int presto_e2_has_all_data(struct inode *inode)
  69. {
  70.         BUG();
  71.         return 0;
  72. }
  73. struct journal_ops presto_ext2_journal_ops = {
  74.         tr_all_data: presto_e2_has_all_data,
  75.         tr_avail: presto_e2_freespace,
  76.         tr_start: presto_e2_trans_start,
  77.         tr_commit: presto_e2_trans_commit,
  78.         tr_journal_data: NULL
  79. };
  80. #endif /* CONFIG_EXT2_FS */