···1111 * David S. Miller (davem@caip.rutgers.edu), 19951212 */13131414-#include <linux/time.h>1515-#include <linux/capability.h>1616-#include <linux/fs.h>1717-#include <linux/slab.h>1818-#include <linux/jbd.h>1919-#include <linux/ext3_fs.h>2020-#include <linux/ext3_jbd.h>2114#include <linux/quotaops.h>2222-#include <linux/buffer_head.h>2315#include <linux/blkdev.h>2424-#include <trace/events/ext3.h>1616+#include "ext3.h"25172618/*2719 * balloc.c contains the blocks allocation and deallocation routines
+1-3
fs/ext3/bitmap.c
···77 * Universite Pierre et Marie Curie (Paris VI)88 */991010-#include <linux/buffer_head.h>1111-#include <linux/jbd.h>1212-#include <linux/ext3_fs.h>1010+#include "ext3.h"13111412#ifdef EXT3FS_DEBUG1513
···2222 * we can depend on generic_block_fdatasync() to sync the data blocks.2323 */24242525-#include <linux/time.h>2625#include <linux/blkdev.h>2727-#include <linux/fs.h>2828-#include <linux/sched.h>2926#include <linux/writeback.h>3030-#include <linux/jbd.h>3131-#include <linux/ext3_fs.h>3232-#include <linux/ext3_jbd.h>3333-#include <trace/events/ext3.h>2727+#include "ext3.h"34283529/*3630 * akpm: A new design for ext3_sync_file().
···5050 * by the buffer lock.5151 */52525353-#include <linux/init.h>5454-#include <linux/fs.h>5555-#include <linux/slab.h>5656-#include <linux/ext3_jbd.h>5757-#include <linux/ext3_fs.h>5353+#include "ext3.h"5854#include <linux/mbcache.h>5955#include <linux/quotaops.h>6060-#include <linux/rwsem.h>6156#include "xattr.h"6257#include "acl.h"6358
+1-5
fs/ext3/xattr_security.c
···33 * Handler for storing security labels as extended attributes.44 */5566-#include <linux/slab.h>77-#include <linux/string.h>88-#include <linux/fs.h>99-#include <linux/ext3_jbd.h>1010-#include <linux/ext3_fs.h>116#include <linux/security.h>77+#include "ext3.h"128#include "xattr.h"1391410static size_t
+1-5
fs/ext3/xattr_trusted.c
···55 * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>66 */7788-#include <linux/string.h>99-#include <linux/capability.h>1010-#include <linux/fs.h>1111-#include <linux/ext3_jbd.h>1212-#include <linux/ext3_fs.h>88+#include "ext3.h"139#include "xattr.h"14101511static size_t
+1-4
fs/ext3/xattr_user.c
···55 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>66 */7788-#include <linux/string.h>99-#include <linux/fs.h>1010-#include <linux/ext3_jbd.h>1111-#include <linux/ext3_fs.h>88+#include "ext3.h"129#include "xattr.h"13101411static size_t
+415-73
include/linux/ext3_fs.h
fs/ext3/ext3.h
···11/*22- * linux/include/linux/ext3_fs.h22+ * Written by Stephen C. Tweedie <sct@redhat.com>, 199933+ *44+ * Copyright 1998--1999 Red Hat corp --- All Rights Reserved55+ *66+ * This file is part of the Linux kernel and is made available under77+ * the terms of the GNU General Public License, version 2, or at your88+ * option, any later version, incorporated herein by reference.39 *410 * Copyright (C) 1992, 1993, 1994, 1995511 * Remy Card (card@masi.ibp.fr)···1913 * Copyright (C) 1991, 1992 Linus Torvalds2014 */21152222-#ifndef _LINUX_EXT3_FS_H2323-#define _LINUX_EXT3_FS_H2424-2525-#include <linux/types.h>1616+#include <linux/fs.h>1717+#include <linux/jbd.h>2618#include <linux/magic.h>2719#include <linux/bug.h>2020+#include <linux/blockgroup_lock.h>28212922/*3023 * The second extended filesystem constants/structures···8075#define EXT3_MIN_BLOCK_SIZE 10248176#define EXT3_MAX_BLOCK_SIZE 655368277#define EXT3_MIN_BLOCK_LOG_SIZE 108383-#ifdef __KERNEL__8484-# define EXT3_BLOCK_SIZE(s) ((s)->s_blocksize)8585-#else8686-# define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)8787-#endif7878+#define EXT3_BLOCK_SIZE(s) ((s)->s_blocksize)8879#define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))8989-#ifdef __KERNEL__9090-# define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)9191-#else9292-# define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)9393-#endif9494-#ifdef __KERNEL__8080+#define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)9581#define EXT3_ADDR_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_addr_per_block_bits)9682#define EXT3_INODE_SIZE(s) (EXT3_SB(s)->s_inode_size)9783#define EXT3_FIRST_INO(s) (EXT3_SB(s)->s_first_ino)9898-#else9999-#define EXT3_INODE_SIZE(s) (((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \100100- EXT3_GOOD_OLD_INODE_SIZE : \101101- (s)->s_inode_size)102102-#define EXT3_FIRST_INO(s) (((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \103103- EXT3_GOOD_OLD_FIRST_INO : \104104- (s)->s_first_ino)105105-#endif1068410785/*10886 * Macro-instructions used to manage fragments···93105#define EXT3_MIN_FRAG_SIZE 102494106#define EXT3_MAX_FRAG_SIZE 409695107#define EXT3_MIN_FRAG_LOG_SIZE 109696-#ifdef __KERNEL__9797-# define EXT3_FRAG_SIZE(s) (EXT3_SB(s)->s_frag_size)9898-# define EXT3_FRAGS_PER_BLOCK(s) (EXT3_SB(s)->s_frags_per_block)9999-#else100100-# define EXT3_FRAG_SIZE(s) (EXT3_MIN_FRAG_SIZE << (s)->s_log_frag_size)101101-# define EXT3_FRAGS_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / EXT3_FRAG_SIZE(s))102102-#endif108108+#define EXT3_FRAG_SIZE(s) (EXT3_SB(s)->s_frag_size)109109+#define EXT3_FRAGS_PER_BLOCK(s) (EXT3_SB(s)->s_frags_per_block)103110104111/*105112 * Structure of a blocks group descriptor···114131/*115132 * Macro-instructions used to manage group descriptors116133 */117117-#ifdef __KERNEL__118118-# define EXT3_BLOCKS_PER_GROUP(s) (EXT3_SB(s)->s_blocks_per_group)119119-# define EXT3_DESC_PER_BLOCK(s) (EXT3_SB(s)->s_desc_per_block)120120-# define EXT3_INODES_PER_GROUP(s) (EXT3_SB(s)->s_inodes_per_group)121121-# define EXT3_DESC_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_desc_per_block_bits)122122-#else123123-# define EXT3_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)124124-# define EXT3_DESC_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_group_desc))125125-# define EXT3_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)126126-#endif134134+#define EXT3_BLOCKS_PER_GROUP(s) (EXT3_SB(s)->s_blocks_per_group)135135+#define EXT3_DESC_PER_BLOCK(s) (EXT3_SB(s)->s_desc_per_block)136136+#define EXT3_INODES_PER_GROUP(s) (EXT3_SB(s)->s_inodes_per_group)137137+#define EXT3_DESC_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_desc_per_block_bits)127138128139/*129140 * Constants relative to the data blocks···313336314337#define i_size_high i_dir_acl315338316316-#if defined(__KERNEL__) || defined(__linux__)317339#define i_reserved1 osd1.linux1.l_i_reserved1318340#define i_frag osd2.linux2.l_i_frag319341#define i_fsize osd2.linux2.l_i_fsize···321345#define i_uid_high osd2.linux2.l_i_uid_high322346#define i_gid_high osd2.linux2.l_i_gid_high323347#define i_reserved2 osd2.linux2.l_i_reserved2324324-325325-#elif defined(__GNU__)326326-327327-#define i_translator osd1.hurd1.h_i_translator328328-#define i_frag osd2.hurd2.h_i_frag;329329-#define i_fsize osd2.hurd2.h_i_fsize;330330-#define i_uid_high osd2.hurd2.h_i_uid_high331331-#define i_gid_high osd2.hurd2.h_i_gid_high332332-#define i_author osd2.hurd2.h_i_author333333-334334-#elif defined(__masix__)335335-336336-#define i_reserved1 osd1.masix1.m_i_reserved1337337-#define i_frag osd2.masix2.m_i_frag338338-#define i_fsize osd2.masix2.m_i_fsize339339-#define i_reserved2 osd2.masix2.m_i_reserved2340340-341341-#endif /* defined(__KERNEL__) || defined(__linux__) */342348343349/*344350 * File system states···489531 __u32 s_reserved[162]; /* Padding to the end of the block */490532};491533492492-#ifdef __KERNEL__493493-#include <linux/ext3_fs_i.h>494494-#include <linux/ext3_fs_sb.h>534534+/* data type for block offset of block group */535535+typedef int ext3_grpblk_t;536536+537537+/* data type for filesystem-wide blocks number */538538+typedef unsigned long ext3_fsblk_t;539539+540540+#define E3FSBLK "%lu"541541+542542+struct ext3_reserve_window {543543+ ext3_fsblk_t _rsv_start; /* First byte reserved */544544+ ext3_fsblk_t _rsv_end; /* Last byte reserved or 0 */545545+};546546+547547+struct ext3_reserve_window_node {548548+ struct rb_node rsv_node;549549+ __u32 rsv_goal_size;550550+ __u32 rsv_alloc_hit;551551+ struct ext3_reserve_window rsv_window;552552+};553553+554554+struct ext3_block_alloc_info {555555+ /* information about reservation window */556556+ struct ext3_reserve_window_node rsv_window_node;557557+ /*558558+ * was i_next_alloc_block in ext3_inode_info559559+ * is the logical (file-relative) number of the560560+ * most-recently-allocated block in this file.561561+ * We use this for detecting linearly ascending allocation requests.562562+ */563563+ __u32 last_alloc_logical_block;564564+ /*565565+ * Was i_next_alloc_goal in ext3_inode_info566566+ * is the *physical* companion to i_next_alloc_block.567567+ * it the physical block number of the block which was most-recentl568568+ * allocated to this file. This give us the goal (target) for the next569569+ * allocation when we detect linearly ascending requests.570570+ */571571+ ext3_fsblk_t last_alloc_physical_block;572572+};573573+574574+#define rsv_start rsv_window._rsv_start575575+#define rsv_end rsv_window._rsv_end576576+577577+/*578578+ * third extended file system inode data in memory579579+ */580580+struct ext3_inode_info {581581+ __le32 i_data[15]; /* unconverted */582582+ __u32 i_flags;583583+#ifdef EXT3_FRAGMENTS584584+ __u32 i_faddr;585585+ __u8 i_frag_no;586586+ __u8 i_frag_size;587587+#endif588588+ ext3_fsblk_t i_file_acl;589589+ __u32 i_dir_acl;590590+ __u32 i_dtime;591591+592592+ /*593593+ * i_block_group is the number of the block group which contains594594+ * this file's inode. Constant across the lifetime of the inode,595595+ * it is ued for making block allocation decisions - we try to596596+ * place a file's data blocks near its inode block, and new inodes597597+ * near to their parent directory's inode.598598+ */599599+ __u32 i_block_group;600600+ unsigned long i_state_flags; /* Dynamic state flags for ext3 */601601+602602+ /* block reservation info */603603+ struct ext3_block_alloc_info *i_block_alloc_info;604604+605605+ __u32 i_dir_start_lookup;606606+#ifdef CONFIG_EXT3_FS_XATTR607607+ /*608608+ * Extended attributes can be read independently of the main file609609+ * data. Taking i_mutex even when reading would cause contention610610+ * between readers of EAs and writers of regular file data, so611611+ * instead we synchronize on xattr_sem when reading or changing612612+ * EAs.613613+ */614614+ struct rw_semaphore xattr_sem;615615+#endif616616+617617+ struct list_head i_orphan; /* unlinked but open inodes */618618+619619+ /*620620+ * i_disksize keeps track of what the inode size is ON DISK, not621621+ * in memory. During truncate, i_size is set to the new size by622622+ * the VFS prior to calling ext3_truncate(), but the filesystem won't623623+ * set i_disksize to 0 until the truncate is actually under way.624624+ *625625+ * The intent is that i_disksize always represents the blocks which626626+ * are used by this file. This allows recovery to restart truncate627627+ * on orphans if we crash during truncate. We actually write i_disksize628628+ * into the on-disk inode when writing inodes out, instead of i_size.629629+ *630630+ * The only time when i_disksize and i_size may be different is when631631+ * a truncate is in progress. The only things which change i_disksize632632+ * are ext3_get_block (growth) and ext3_truncate (shrinkth).633633+ */634634+ loff_t i_disksize;635635+636636+ /* on-disk additional length */637637+ __u16 i_extra_isize;638638+639639+ /*640640+ * truncate_mutex is for serialising ext3_truncate() against641641+ * ext3_getblock(). In the 2.4 ext2 design, great chunks of inode's642642+ * data tree are chopped off during truncate. We can't do that in643643+ * ext3 because whenever we perform intermediate commits during644644+ * truncate, the inode and all the metadata blocks *must* be in a645645+ * consistent state which allows truncation of the orphans to restart646646+ * during recovery. Hence we must fix the get_block-vs-truncate race647647+ * by other means, so we have truncate_mutex.648648+ */649649+ struct mutex truncate_mutex;650650+651651+ /*652652+ * Transactions that contain inode's metadata needed to complete653653+ * fsync and fdatasync, respectively.654654+ */655655+ atomic_t i_sync_tid;656656+ atomic_t i_datasync_tid;657657+658658+ struct inode vfs_inode;659659+};660660+661661+/*662662+ * third extended-fs super-block data in memory663663+ */664664+struct ext3_sb_info {665665+ unsigned long s_frag_size; /* Size of a fragment in bytes */666666+ unsigned long s_frags_per_block;/* Number of fragments per block */667667+ unsigned long s_inodes_per_block;/* Number of inodes per block */668668+ unsigned long s_frags_per_group;/* Number of fragments in a group */669669+ unsigned long s_blocks_per_group;/* Number of blocks in a group */670670+ unsigned long s_inodes_per_group;/* Number of inodes in a group */671671+ unsigned long s_itb_per_group; /* Number of inode table blocks per group */672672+ unsigned long s_gdb_count; /* Number of group descriptor blocks */673673+ unsigned long s_desc_per_block; /* Number of group descriptors per block */674674+ unsigned long s_groups_count; /* Number of groups in the fs */675675+ unsigned long s_overhead_last; /* Last calculated overhead */676676+ unsigned long s_blocks_last; /* Last seen block count */677677+ struct buffer_head * s_sbh; /* Buffer containing the super block */678678+ struct ext3_super_block * s_es; /* Pointer to the super block in the buffer */679679+ struct buffer_head ** s_group_desc;680680+ unsigned long s_mount_opt;681681+ ext3_fsblk_t s_sb_block;682682+ uid_t s_resuid;683683+ gid_t s_resgid;684684+ unsigned short s_mount_state;685685+ unsigned short s_pad;686686+ int s_addr_per_block_bits;687687+ int s_desc_per_block_bits;688688+ int s_inode_size;689689+ int s_first_ino;690690+ spinlock_t s_next_gen_lock;691691+ u32 s_next_generation;692692+ u32 s_hash_seed[4];693693+ int s_def_hash_version;694694+ int s_hash_unsigned; /* 3 if hash should be signed, 0 if not */695695+ struct percpu_counter s_freeblocks_counter;696696+ struct percpu_counter s_freeinodes_counter;697697+ struct percpu_counter s_dirs_counter;698698+ struct blockgroup_lock *s_blockgroup_lock;699699+700700+ /* root of the per fs reservation window tree */701701+ spinlock_t s_rsv_window_lock;702702+ struct rb_root s_rsv_window_root;703703+ struct ext3_reserve_window_node s_rsv_window_head;704704+705705+ /* Journaling */706706+ struct inode * s_journal_inode;707707+ struct journal_s * s_journal;708708+ struct list_head s_orphan;709709+ struct mutex s_orphan_lock;710710+ struct mutex s_resize_lock;711711+ unsigned long s_commit_interval;712712+ struct block_device *journal_bdev;713713+#ifdef CONFIG_QUOTA714714+ char *s_qf_names[MAXQUOTAS]; /* Names of quota files with journalled quota */715715+ int s_jquota_fmt; /* Format of quota to use */716716+#endif717717+};718718+719719+static inline spinlock_t *720720+sb_bgl_lock(struct ext3_sb_info *sbi, unsigned int block_group)721721+{722722+ return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);723723+}724724+495725static inline struct ext3_sb_info * EXT3_SB(struct super_block *sb)496726{497727 return sb->s_fs_info;···722576{723577 clear_bit(bit, &EXT3_I(inode)->i_state_flags);724578}725725-#else726726-/* Assume that user mode programs are passing in an ext3fs superblock, not727727- * a kernel struct super_block. This will allow us to call the feature-test728728- * macros from user land. */729729-#define EXT3_SB(sb) (sb)730730-#endif731579732580#define NEXT_ORPHAN(inode) EXT3_I(inode)->i_dtime733581···910770#define DX_HASH_LEGACY_UNSIGNED 3911771#define DX_HASH_HALF_MD4_UNSIGNED 4912772#define DX_HASH_TEA_UNSIGNED 5913913-914914-#ifdef __KERNEL__915773916774/* hash info structure used by the directory hash */917775struct dx_hash_info···1112974extern const struct inode_operations ext3_symlink_inode_operations;1113975extern const struct inode_operations ext3_fast_symlink_inode_operations;1114976977977+#define EXT3_JOURNAL(inode) (EXT3_SB((inode)->i_sb)->s_journal)111597811161116-#endif /* __KERNEL__ */979979+/* Define the number of blocks we need to account to a transaction to980980+ * modify one block of data.981981+ *982982+ * We may have to touch one inode, one bitmap buffer, up to three983983+ * indirection blocks, the group and superblock summaries, and the data984984+ * block to complete the transaction. */111798511181118-#endif /* _LINUX_EXT3_FS_H */986986+#define EXT3_SINGLEDATA_TRANS_BLOCKS 8U987987+988988+/* Extended attribute operations touch at most two data buffers,989989+ * two bitmap buffers, and two group summaries, in addition to the inode990990+ * and the superblock, which are already accounted for. */991991+992992+#define EXT3_XATTR_TRANS_BLOCKS 6U993993+994994+/* Define the minimum size for a transaction which modifies data. This995995+ * needs to take into account the fact that we may end up modifying two996996+ * quota files too (one for the group, one for the user quota). The997997+ * superblock only gets updated once, of course, so don't bother998998+ * counting that again for the quota updates. */999999+10001000+#define EXT3_DATA_TRANS_BLOCKS(sb) (EXT3_SINGLEDATA_TRANS_BLOCKS + \10011001+ EXT3_XATTR_TRANS_BLOCKS - 2 + \10021002+ EXT3_MAXQUOTAS_TRANS_BLOCKS(sb))10031003+10041004+/* Delete operations potentially hit one directory's namespace plus an10051005+ * entire inode, plus arbitrary amounts of bitmap/indirection data. Be10061006+ * generous. We can grow the delete transaction later if necessary. */10071007+10081008+#define EXT3_DELETE_TRANS_BLOCKS(sb) (EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) + 64)10091009+10101010+/* Define an arbitrary limit for the amount of data we will anticipate10111011+ * writing to any given transaction. For unbounded transactions such as10121012+ * write(2) and truncate(2) we can write more than this, but we always10131013+ * start off at the maximum transaction size and grow the transaction10141014+ * optimistically as we go. */10151015+10161016+#define EXT3_MAX_TRANS_DATA 64U10171017+10181018+/* We break up a large truncate or write transaction once the handle's10191019+ * buffer credits gets this low, we need either to extend the10201020+ * transaction or to start a new one. Reserve enough space here for10211021+ * inode, bitmap, superblock, group and indirection updates for at least10221022+ * one block, plus two quota updates. Quota allocations are not10231023+ * needed. */10241024+10251025+#define EXT3_RESERVE_TRANS_BLOCKS 12U10261026+10271027+#define EXT3_INDEX_EXTRA_TRANS_BLOCKS 810281028+10291029+#ifdef CONFIG_QUOTA10301030+/* Amount of blocks needed for quota update - we know that the structure was10311031+ * allocated so we need to update only inode+data */10321032+#define EXT3_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0)10331033+/* Amount of blocks needed for quota insert/delete - we do some block writes10341034+ * but inode, sb and group updates are done only once */10351035+#define EXT3_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\10361036+ (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0)10371037+#define EXT3_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\10381038+ (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0)10391039+#else10401040+#define EXT3_QUOTA_TRANS_BLOCKS(sb) 010411041+#define EXT3_QUOTA_INIT_BLOCKS(sb) 010421042+#define EXT3_QUOTA_DEL_BLOCKS(sb) 010431043+#endif10441044+#define EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_TRANS_BLOCKS(sb))10451045+#define EXT3_MAXQUOTAS_INIT_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_INIT_BLOCKS(sb))10461046+#define EXT3_MAXQUOTAS_DEL_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_DEL_BLOCKS(sb))10471047+10481048+int10491049+ext3_mark_iloc_dirty(handle_t *handle,10501050+ struct inode *inode,10511051+ struct ext3_iloc *iloc);10521052+10531053+/*10541054+ * On success, We end up with an outstanding reference count against10551055+ * iloc->bh. This _must_ be cleaned up later.10561056+ */10571057+10581058+int ext3_reserve_inode_write(handle_t *handle, struct inode *inode,10591059+ struct ext3_iloc *iloc);10601060+10611061+int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode);10621062+10631063+/*10641064+ * Wrapper functions with which ext3 calls into JBD. The intent here is10651065+ * to allow these to be turned into appropriate stubs so ext3 can control10661066+ * ext2 filesystems, so ext2+ext3 systems only nee one fs. This work hasn't10671067+ * been done yet.10681068+ */10691069+10701070+static inline void ext3_journal_release_buffer(handle_t *handle,10711071+ struct buffer_head *bh)10721072+{10731073+ journal_release_buffer(handle, bh);10741074+}10751075+10761076+void ext3_journal_abort_handle(const char *caller, const char *err_fn,10771077+ struct buffer_head *bh, handle_t *handle, int err);10781078+10791079+int __ext3_journal_get_undo_access(const char *where, handle_t *handle,10801080+ struct buffer_head *bh);10811081+10821082+int __ext3_journal_get_write_access(const char *where, handle_t *handle,10831083+ struct buffer_head *bh);10841084+10851085+int __ext3_journal_forget(const char *where, handle_t *handle,10861086+ struct buffer_head *bh);10871087+10881088+int __ext3_journal_revoke(const char *where, handle_t *handle,10891089+ unsigned long blocknr, struct buffer_head *bh);10901090+10911091+int __ext3_journal_get_create_access(const char *where,10921092+ handle_t *handle, struct buffer_head *bh);10931093+10941094+int __ext3_journal_dirty_metadata(const char *where,10951095+ handle_t *handle, struct buffer_head *bh);10961096+10971097+#define ext3_journal_get_undo_access(handle, bh) \10981098+ __ext3_journal_get_undo_access(__func__, (handle), (bh))10991099+#define ext3_journal_get_write_access(handle, bh) \11001100+ __ext3_journal_get_write_access(__func__, (handle), (bh))11011101+#define ext3_journal_revoke(handle, blocknr, bh) \11021102+ __ext3_journal_revoke(__func__, (handle), (blocknr), (bh))11031103+#define ext3_journal_get_create_access(handle, bh) \11041104+ __ext3_journal_get_create_access(__func__, (handle), (bh))11051105+#define ext3_journal_dirty_metadata(handle, bh) \11061106+ __ext3_journal_dirty_metadata(__func__, (handle), (bh))11071107+#define ext3_journal_forget(handle, bh) \11081108+ __ext3_journal_forget(__func__, (handle), (bh))11091109+11101110+int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh);11111111+11121112+handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks);11131113+int __ext3_journal_stop(const char *where, handle_t *handle);11141114+11151115+static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)11161116+{11171117+ return ext3_journal_start_sb(inode->i_sb, nblocks);11181118+}11191119+11201120+#define ext3_journal_stop(handle) \11211121+ __ext3_journal_stop(__func__, (handle))11221122+11231123+static inline handle_t *ext3_journal_current_handle(void)11241124+{11251125+ return journal_current_handle();11261126+}11271127+11281128+static inline int ext3_journal_extend(handle_t *handle, int nblocks)11291129+{11301130+ return journal_extend(handle, nblocks);11311131+}11321132+11331133+static inline int ext3_journal_restart(handle_t *handle, int nblocks)11341134+{11351135+ return journal_restart(handle, nblocks);11361136+}11371137+11381138+static inline int ext3_journal_blocks_per_page(struct inode *inode)11391139+{11401140+ return journal_blocks_per_page(inode);11411141+}11421142+11431143+static inline int ext3_journal_force_commit(journal_t *journal)11441144+{11451145+ return journal_force_commit(journal);11461146+}11471147+11481148+/* super.c */11491149+int ext3_force_commit(struct super_block *sb);11501150+11511151+static inline int ext3_should_journal_data(struct inode *inode)11521152+{11531153+ if (!S_ISREG(inode->i_mode))11541154+ return 1;11551155+ if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)11561156+ return 1;11571157+ if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)11581158+ return 1;11591159+ return 0;11601160+}11611161+11621162+static inline int ext3_should_order_data(struct inode *inode)11631163+{11641164+ if (!S_ISREG(inode->i_mode))11651165+ return 0;11661166+ if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)11671167+ return 0;11681168+ if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA)11691169+ return 1;11701170+ return 0;11711171+}11721172+11731173+static inline int ext3_should_writeback_data(struct inode *inode)11741174+{11751175+ if (!S_ISREG(inode->i_mode))11761176+ return 0;11771177+ if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)11781178+ return 0;11791179+ if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)11801180+ return 1;11811181+ return 0;11821182+}11831183+11841184+#include <trace/events/ext3.h>
-151
include/linux/ext3_fs_i.h
···11-/*22- * linux/include/linux/ext3_fs_i.h33- *44- * Copyright (C) 1992, 1993, 1994, 199555- * Remy Card (card@masi.ibp.fr)66- * Laboratoire MASI - Institut Blaise Pascal77- * Universite Pierre et Marie Curie (Paris VI)88- *99- * from1010- *1111- * linux/include/linux/minix_fs_i.h1212- *1313- * Copyright (C) 1991, 1992 Linus Torvalds1414- */1515-1616-#ifndef _LINUX_EXT3_FS_I1717-#define _LINUX_EXT3_FS_I1818-1919-#include <linux/rwsem.h>2020-#include <linux/rbtree.h>2121-#include <linux/seqlock.h>2222-#include <linux/mutex.h>2323-2424-/* data type for block offset of block group */2525-typedef int ext3_grpblk_t;2626-2727-/* data type for filesystem-wide blocks number */2828-typedef unsigned long ext3_fsblk_t;2929-3030-#define E3FSBLK "%lu"3131-3232-struct ext3_reserve_window {3333- ext3_fsblk_t _rsv_start; /* First byte reserved */3434- ext3_fsblk_t _rsv_end; /* Last byte reserved or 0 */3535-};3636-3737-struct ext3_reserve_window_node {3838- struct rb_node rsv_node;3939- __u32 rsv_goal_size;4040- __u32 rsv_alloc_hit;4141- struct ext3_reserve_window rsv_window;4242-};4343-4444-struct ext3_block_alloc_info {4545- /* information about reservation window */4646- struct ext3_reserve_window_node rsv_window_node;4747- /*4848- * was i_next_alloc_block in ext3_inode_info4949- * is the logical (file-relative) number of the5050- * most-recently-allocated block in this file.5151- * We use this for detecting linearly ascending allocation requests.5252- */5353- __u32 last_alloc_logical_block;5454- /*5555- * Was i_next_alloc_goal in ext3_inode_info5656- * is the *physical* companion to i_next_alloc_block.5757- * it the physical block number of the block which was most-recentl5858- * allocated to this file. This give us the goal (target) for the next5959- * allocation when we detect linearly ascending requests.6060- */6161- ext3_fsblk_t last_alloc_physical_block;6262-};6363-6464-#define rsv_start rsv_window._rsv_start6565-#define rsv_end rsv_window._rsv_end6666-6767-/*6868- * third extended file system inode data in memory6969- */7070-struct ext3_inode_info {7171- __le32 i_data[15]; /* unconverted */7272- __u32 i_flags;7373-#ifdef EXT3_FRAGMENTS7474- __u32 i_faddr;7575- __u8 i_frag_no;7676- __u8 i_frag_size;7777-#endif7878- ext3_fsblk_t i_file_acl;7979- __u32 i_dir_acl;8080- __u32 i_dtime;8181-8282- /*8383- * i_block_group is the number of the block group which contains8484- * this file's inode. Constant across the lifetime of the inode,8585- * it is ued for making block allocation decisions - we try to8686- * place a file's data blocks near its inode block, and new inodes8787- * near to their parent directory's inode.8888- */8989- __u32 i_block_group;9090- unsigned long i_state_flags; /* Dynamic state flags for ext3 */9191-9292- /* block reservation info */9393- struct ext3_block_alloc_info *i_block_alloc_info;9494-9595- __u32 i_dir_start_lookup;9696-#ifdef CONFIG_EXT3_FS_XATTR9797- /*9898- * Extended attributes can be read independently of the main file9999- * data. Taking i_mutex even when reading would cause contention100100- * between readers of EAs and writers of regular file data, so101101- * instead we synchronize on xattr_sem when reading or changing102102- * EAs.103103- */104104- struct rw_semaphore xattr_sem;105105-#endif106106-107107- struct list_head i_orphan; /* unlinked but open inodes */108108-109109- /*110110- * i_disksize keeps track of what the inode size is ON DISK, not111111- * in memory. During truncate, i_size is set to the new size by112112- * the VFS prior to calling ext3_truncate(), but the filesystem won't113113- * set i_disksize to 0 until the truncate is actually under way.114114- *115115- * The intent is that i_disksize always represents the blocks which116116- * are used by this file. This allows recovery to restart truncate117117- * on orphans if we crash during truncate. We actually write i_disksize118118- * into the on-disk inode when writing inodes out, instead of i_size.119119- *120120- * The only time when i_disksize and i_size may be different is when121121- * a truncate is in progress. The only things which change i_disksize122122- * are ext3_get_block (growth) and ext3_truncate (shrinkth).123123- */124124- loff_t i_disksize;125125-126126- /* on-disk additional length */127127- __u16 i_extra_isize;128128-129129- /*130130- * truncate_mutex is for serialising ext3_truncate() against131131- * ext3_getblock(). In the 2.4 ext2 design, great chunks of inode's132132- * data tree are chopped off during truncate. We can't do that in133133- * ext3 because whenever we perform intermediate commits during134134- * truncate, the inode and all the metadata blocks *must* be in a135135- * consistent state which allows truncation of the orphans to restart136136- * during recovery. Hence we must fix the get_block-vs-truncate race137137- * by other means, so we have truncate_mutex.138138- */139139- struct mutex truncate_mutex;140140-141141- /*142142- * Transactions that contain inode's metadata needed to complete143143- * fsync and fdatasync, respectively.144144- */145145- atomic_t i_sync_tid;146146- atomic_t i_datasync_tid;147147-148148- struct inode vfs_inode;149149-};150150-151151-#endif /* _LINUX_EXT3_FS_I */
-91
include/linux/ext3_fs_sb.h
···11-/*22- * linux/include/linux/ext3_fs_sb.h33- *44- * Copyright (C) 1992, 1993, 1994, 199555- * Remy Card (card@masi.ibp.fr)66- * Laboratoire MASI - Institut Blaise Pascal77- * Universite Pierre et Marie Curie (Paris VI)88- *99- * from1010- *1111- * linux/include/linux/minix_fs_sb.h1212- *1313- * Copyright (C) 1991, 1992 Linus Torvalds1414- */1515-1616-#ifndef _LINUX_EXT3_FS_SB1717-#define _LINUX_EXT3_FS_SB1818-1919-#ifdef __KERNEL__2020-#include <linux/timer.h>2121-#include <linux/wait.h>2222-#include <linux/blockgroup_lock.h>2323-#include <linux/percpu_counter.h>2424-#endif2525-#include <linux/rbtree.h>2626-2727-/*2828- * third extended-fs super-block data in memory2929- */3030-struct ext3_sb_info {3131- unsigned long s_frag_size; /* Size of a fragment in bytes */3232- unsigned long s_frags_per_block;/* Number of fragments per block */3333- unsigned long s_inodes_per_block;/* Number of inodes per block */3434- unsigned long s_frags_per_group;/* Number of fragments in a group */3535- unsigned long s_blocks_per_group;/* Number of blocks in a group */3636- unsigned long s_inodes_per_group;/* Number of inodes in a group */3737- unsigned long s_itb_per_group; /* Number of inode table blocks per group */3838- unsigned long s_gdb_count; /* Number of group descriptor blocks */3939- unsigned long s_desc_per_block; /* Number of group descriptors per block */4040- unsigned long s_groups_count; /* Number of groups in the fs */4141- unsigned long s_overhead_last; /* Last calculated overhead */4242- unsigned long s_blocks_last; /* Last seen block count */4343- struct buffer_head * s_sbh; /* Buffer containing the super block */4444- struct ext3_super_block * s_es; /* Pointer to the super block in the buffer */4545- struct buffer_head ** s_group_desc;4646- unsigned long s_mount_opt;4747- ext3_fsblk_t s_sb_block;4848- uid_t s_resuid;4949- gid_t s_resgid;5050- unsigned short s_mount_state;5151- unsigned short s_pad;5252- int s_addr_per_block_bits;5353- int s_desc_per_block_bits;5454- int s_inode_size;5555- int s_first_ino;5656- spinlock_t s_next_gen_lock;5757- u32 s_next_generation;5858- u32 s_hash_seed[4];5959- int s_def_hash_version;6060- int s_hash_unsigned; /* 3 if hash should be signed, 0 if not */6161- struct percpu_counter s_freeblocks_counter;6262- struct percpu_counter s_freeinodes_counter;6363- struct percpu_counter s_dirs_counter;6464- struct blockgroup_lock *s_blockgroup_lock;6565-6666- /* root of the per fs reservation window tree */6767- spinlock_t s_rsv_window_lock;6868- struct rb_root s_rsv_window_root;6969- struct ext3_reserve_window_node s_rsv_window_head;7070-7171- /* Journaling */7272- struct inode * s_journal_inode;7373- struct journal_s * s_journal;7474- struct list_head s_orphan;7575- struct mutex s_orphan_lock;7676- struct mutex s_resize_lock;7777- unsigned long s_commit_interval;7878- struct block_device *journal_bdev;7979-#ifdef CONFIG_QUOTA8080- char *s_qf_names[MAXQUOTAS]; /* Names of quota files with journalled quota */8181- int s_jquota_fmt; /* Format of quota to use */8282-#endif8383-};8484-8585-static inline spinlock_t *8686-sb_bgl_lock(struct ext3_sb_info *sbi, unsigned int block_group)8787-{8888- return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);8989-}9090-9191-#endif /* _LINUX_EXT3_FS_SB */
-229
include/linux/ext3_jbd.h
···11-/*22- * linux/include/linux/ext3_jbd.h33- *44- * Written by Stephen C. Tweedie <sct@redhat.com>, 199955- *66- * Copyright 1998--1999 Red Hat corp --- All Rights Reserved77- *88- * This file is part of the Linux kernel and is made available under99- * the terms of the GNU General Public License, version 2, or at your1010- * option, any later version, incorporated herein by reference.1111- *1212- * Ext3-specific journaling extensions.1313- */1414-1515-#ifndef _LINUX_EXT3_JBD_H1616-#define _LINUX_EXT3_JBD_H1717-1818-#include <linux/fs.h>1919-#include <linux/jbd.h>2020-#include <linux/ext3_fs.h>2121-2222-#define EXT3_JOURNAL(inode) (EXT3_SB((inode)->i_sb)->s_journal)2323-2424-/* Define the number of blocks we need to account to a transaction to2525- * modify one block of data.2626- *2727- * We may have to touch one inode, one bitmap buffer, up to three2828- * indirection blocks, the group and superblock summaries, and the data2929- * block to complete the transaction. */3030-3131-#define EXT3_SINGLEDATA_TRANS_BLOCKS 8U3232-3333-/* Extended attribute operations touch at most two data buffers,3434- * two bitmap buffers, and two group summaries, in addition to the inode3535- * and the superblock, which are already accounted for. */3636-3737-#define EXT3_XATTR_TRANS_BLOCKS 6U3838-3939-/* Define the minimum size for a transaction which modifies data. This4040- * needs to take into account the fact that we may end up modifying two4141- * quota files too (one for the group, one for the user quota). The4242- * superblock only gets updated once, of course, so don't bother4343- * counting that again for the quota updates. */4444-4545-#define EXT3_DATA_TRANS_BLOCKS(sb) (EXT3_SINGLEDATA_TRANS_BLOCKS + \4646- EXT3_XATTR_TRANS_BLOCKS - 2 + \4747- EXT3_MAXQUOTAS_TRANS_BLOCKS(sb))4848-4949-/* Delete operations potentially hit one directory's namespace plus an5050- * entire inode, plus arbitrary amounts of bitmap/indirection data. Be5151- * generous. We can grow the delete transaction later if necessary. */5252-5353-#define EXT3_DELETE_TRANS_BLOCKS(sb) (EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) + 64)5454-5555-/* Define an arbitrary limit for the amount of data we will anticipate5656- * writing to any given transaction. For unbounded transactions such as5757- * write(2) and truncate(2) we can write more than this, but we always5858- * start off at the maximum transaction size and grow the transaction5959- * optimistically as we go. */6060-6161-#define EXT3_MAX_TRANS_DATA 64U6262-6363-/* We break up a large truncate or write transaction once the handle's6464- * buffer credits gets this low, we need either to extend the6565- * transaction or to start a new one. Reserve enough space here for6666- * inode, bitmap, superblock, group and indirection updates for at least6767- * one block, plus two quota updates. Quota allocations are not6868- * needed. */6969-7070-#define EXT3_RESERVE_TRANS_BLOCKS 12U7171-7272-#define EXT3_INDEX_EXTRA_TRANS_BLOCKS 87373-7474-#ifdef CONFIG_QUOTA7575-/* Amount of blocks needed for quota update - we know that the structure was7676- * allocated so we need to update only inode+data */7777-#define EXT3_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0)7878-/* Amount of blocks needed for quota insert/delete - we do some block writes7979- * but inode, sb and group updates are done only once */8080-#define EXT3_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\8181- (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0)8282-#define EXT3_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\8383- (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0)8484-#else8585-#define EXT3_QUOTA_TRANS_BLOCKS(sb) 08686-#define EXT3_QUOTA_INIT_BLOCKS(sb) 08787-#define EXT3_QUOTA_DEL_BLOCKS(sb) 08888-#endif8989-#define EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_TRANS_BLOCKS(sb))9090-#define EXT3_MAXQUOTAS_INIT_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_INIT_BLOCKS(sb))9191-#define EXT3_MAXQUOTAS_DEL_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_DEL_BLOCKS(sb))9292-9393-int9494-ext3_mark_iloc_dirty(handle_t *handle,9595- struct inode *inode,9696- struct ext3_iloc *iloc);9797-9898-/*9999- * On success, We end up with an outstanding reference count against100100- * iloc->bh. This _must_ be cleaned up later.101101- */102102-103103-int ext3_reserve_inode_write(handle_t *handle, struct inode *inode,104104- struct ext3_iloc *iloc);105105-106106-int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode);107107-108108-/*109109- * Wrapper functions with which ext3 calls into JBD. The intent here is110110- * to allow these to be turned into appropriate stubs so ext3 can control111111- * ext2 filesystems, so ext2+ext3 systems only nee one fs. This work hasn't112112- * been done yet.113113- */114114-115115-static inline void ext3_journal_release_buffer(handle_t *handle,116116- struct buffer_head *bh)117117-{118118- journal_release_buffer(handle, bh);119119-}120120-121121-void ext3_journal_abort_handle(const char *caller, const char *err_fn,122122- struct buffer_head *bh, handle_t *handle, int err);123123-124124-int __ext3_journal_get_undo_access(const char *where, handle_t *handle,125125- struct buffer_head *bh);126126-127127-int __ext3_journal_get_write_access(const char *where, handle_t *handle,128128- struct buffer_head *bh);129129-130130-int __ext3_journal_forget(const char *where, handle_t *handle,131131- struct buffer_head *bh);132132-133133-int __ext3_journal_revoke(const char *where, handle_t *handle,134134- unsigned long blocknr, struct buffer_head *bh);135135-136136-int __ext3_journal_get_create_access(const char *where,137137- handle_t *handle, struct buffer_head *bh);138138-139139-int __ext3_journal_dirty_metadata(const char *where,140140- handle_t *handle, struct buffer_head *bh);141141-142142-#define ext3_journal_get_undo_access(handle, bh) \143143- __ext3_journal_get_undo_access(__func__, (handle), (bh))144144-#define ext3_journal_get_write_access(handle, bh) \145145- __ext3_journal_get_write_access(__func__, (handle), (bh))146146-#define ext3_journal_revoke(handle, blocknr, bh) \147147- __ext3_journal_revoke(__func__, (handle), (blocknr), (bh))148148-#define ext3_journal_get_create_access(handle, bh) \149149- __ext3_journal_get_create_access(__func__, (handle), (bh))150150-#define ext3_journal_dirty_metadata(handle, bh) \151151- __ext3_journal_dirty_metadata(__func__, (handle), (bh))152152-#define ext3_journal_forget(handle, bh) \153153- __ext3_journal_forget(__func__, (handle), (bh))154154-155155-int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh);156156-157157-handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks);158158-int __ext3_journal_stop(const char *where, handle_t *handle);159159-160160-static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)161161-{162162- return ext3_journal_start_sb(inode->i_sb, nblocks);163163-}164164-165165-#define ext3_journal_stop(handle) \166166- __ext3_journal_stop(__func__, (handle))167167-168168-static inline handle_t *ext3_journal_current_handle(void)169169-{170170- return journal_current_handle();171171-}172172-173173-static inline int ext3_journal_extend(handle_t *handle, int nblocks)174174-{175175- return journal_extend(handle, nblocks);176176-}177177-178178-static inline int ext3_journal_restart(handle_t *handle, int nblocks)179179-{180180- return journal_restart(handle, nblocks);181181-}182182-183183-static inline int ext3_journal_blocks_per_page(struct inode *inode)184184-{185185- return journal_blocks_per_page(inode);186186-}187187-188188-static inline int ext3_journal_force_commit(journal_t *journal)189189-{190190- return journal_force_commit(journal);191191-}192192-193193-/* super.c */194194-int ext3_force_commit(struct super_block *sb);195195-196196-static inline int ext3_should_journal_data(struct inode *inode)197197-{198198- if (!S_ISREG(inode->i_mode))199199- return 1;200200- if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)201201- return 1;202202- if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)203203- return 1;204204- return 0;205205-}206206-207207-static inline int ext3_should_order_data(struct inode *inode)208208-{209209- if (!S_ISREG(inode->i_mode))210210- return 0;211211- if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)212212- return 0;213213- if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA)214214- return 1;215215- return 0;216216-}217217-218218-static inline int ext3_should_writeback_data(struct inode *inode)219219-{220220- if (!S_ISREG(inode->i_mode))221221- return 0;222222- if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)223223- return 0;224224- if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)225225- return 1;226226- return 0;227227-}228228-229229-#endif /* _LINUX_EXT3_JBD_H */