/* * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README */ #include <linux/time.h> #include <linux/fs.h> #include "reiserfs.h" #include "acl.h" #include "xattr.h" #include <linux/exportfs.h> #include <linux/pagemap.h> #include <linux/highmem.h> #include <linux/slab.h> #include <linux/uaccess.h> #include <asm/unaligned.h> #include <linux/buffer_head.h> #include <linux/mpage.h> #include <linux/writeback.h> #include <linux/quotaops.h> #include <linux/swap.h> #include <linux/uio.h> #include <linux/bio.h> int reiserfs_commit_write(struct file *f, struct page *page, unsigned from, unsigned to); void reiserfs_evict_inode(struct inode *inode) { … } static void _make_cpu_key(struct cpu_key *key, int version, __u32 dirid, __u32 objectid, loff_t offset, int type, int length) { … } /* * take base of inode_key (it comes from inode always) (dirid, objectid) * and version from an inode, set offset and type of key */ void make_cpu_key(struct cpu_key *key, struct inode *inode, loff_t offset, int type, int length) { … } /* when key is 0, do not set version and short key */ inline void make_le_item_head(struct item_head *ih, const struct cpu_key *key, int version, loff_t offset, int type, int length, int entry_count /*or ih_free_space */ ) { … } /* * FIXME: we might cache recently accessed indirect item * Ugh. Not too eager for that.... * I cut the code until such time as I see a convincing argument (benchmark). * I don't want a bloated inode struct..., and I don't like code complexity.... */ /* * cutting the code is fine, since it really isn't in use yet and is easy * to add back in. But, Vladimir has a really good idea here. Think * about what happens for reading a file. For each page, * The VFS layer calls reiserfs_read_folio, who searches the tree to find * an indirect item. This indirect item has X number of pointers, where * X is a big number if we've done the block allocation right. But, * we only use one or two of these pointers during each call to read_folio, * needlessly researching again later on. * * The size of the cache could be dynamic based on the size of the file. * * I'd also like to see us cache the location the stat data item, since * we are needlessly researching for that frequently. * * --chris */ /* * If this page has a file tail in it, and * it was read in by get_block_create_0, the page data is valid, * but tail is still sitting in a direct item, and we can't write to * it. So, look through this page, and check all the mapped buffers * to make sure they have valid block numbers. Any that don't need * to be unmapped, so that __block_write_begin will correctly call * reiserfs_get_block to convert the tail into an unformatted node */ static inline void fix_tail_page_for_writing(struct page *page) { … } /* * reiserfs_get_block does not need to allocate a block only if it has been * done already or non-hole position has been found in the indirect item */ static inline int allocation_needed(int retval, b_blocknr_t allocated, struct item_head *ih, __le32 * item, int pos_in_item) { … } static inline int indirect_item_found(int retval, struct item_head *ih) { … } static inline void set_block_dev_mapped(struct buffer_head *bh, b_blocknr_t block, struct inode *inode) { … } /* * files which were created in the earlier version can not be longer, * than 2 gb */ static int file_capable(struct inode *inode, sector_t block) { … } static int restart_transaction(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *path) { … } /* * it is called by get_block when create == 0. Returns block number * for 'block'-th logical block of file. When it hits direct item it * returns 0 (being called from bmap) or read direct item into piece * of page (bh_result) * Please improve the english/clarity in the comment above, as it is * hard to understand. */ static int _get_block_create_0(struct inode *inode, sector_t block, struct buffer_head *bh_result, int args) { … } /* * this is called to create file map. So, _get_block_create_0 will not * read direct item */ static int reiserfs_bmap(struct inode *inode, sector_t block, struct buffer_head *bh_result, int create) { … } /* * special version of get_block that is only used by grab_tail_page right * now. It is sent to __block_write_begin, and when you try to get a * block past the end of the file (or a block from a hole) it returns * -ENOENT instead of a valid buffer. __block_write_begin expects to * be able to do i/o on the buffers returned, unless an error value * is also returned. * * So, this allows __block_write_begin to be used for reading a single block * in a page. Where it does not produce a valid page for holes, or past the * end of the file. This turns out to be exactly what we need for reading * tails for conversion. * * The point of the wrapper is forcing a certain value for create, even * though the VFS layer is calling this function with create==1. If you * don't want to send create == GET_BLOCK_NO_HOLE to reiserfs_get_block, * don't use this function. */ static int reiserfs_get_block_create_0(struct inode *inode, sector_t block, struct buffer_head *bh_result, int create) { … } /* * This is special helper for reiserfs_get_block in case we are executing * direct_IO request. */ static int reiserfs_get_blocks_direct_io(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create) { … } /* * helper function for when reiserfs_get_block is called for a hole * but the file tail is still in a direct item * bh_result is the buffer head for the hole * tail_offset is the offset of the start of the tail in the file * * This calls prepare_write, which will start a new transaction * you should not be in a transaction, or have any paths held when you * call this. */ static int convert_tail_for_hole(struct inode *inode, struct buffer_head *bh_result, loff_t tail_offset) { … } static inline int _allocate_block(struct reiserfs_transaction_handle *th, sector_t block, struct inode *inode, b_blocknr_t * allocated_block_nr, struct treepath *path, int flags) { … } int reiserfs_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_result, int create) { … } static void reiserfs_readahead(struct readahead_control *rac) { … } /* * Compute real number of used bytes by file * Following three functions can go away when we'll have enough space in * stat item */ static int real_space_diff(struct inode *inode, int sd_size) { … } static inline loff_t to_real_used_space(struct inode *inode, ulong blocks, int sd_size) { … } /* Compute number of blocks used by file in ReiserFS counting */ static inline ulong to_fake_used_blocks(struct inode *inode, int sd_size) { … } /* * BAD: new directories have stat data of new type and all other items * of old type. Version stored in the inode says about body items, so * in update_stat_data we can not rely on inode, but have to check * item version directly */ /* called by read_locked_inode */ static void init_inode(struct inode *inode, struct treepath *path) { … } /* update new stat data with inode fields */ static void inode2sd(void *sd, struct inode *inode, loff_t size) { … } /* used to copy inode's fields to old stat data */ static void inode2sd_v1(void *sd, struct inode *inode, loff_t size) { … } /* * NOTE, you must prepare the buffer head before sending it here, * and then log it after the call */ static void update_stat_data(struct treepath *path, struct inode *inode, loff_t size) { … } void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th, struct inode *inode, loff_t size) { … } /* * reiserfs_read_locked_inode is called to read the inode off disk, and it * does a make_bad_inode when things go wrong. But, we need to make sure * and clear the key in the private portion of the inode, otherwise a * corresponding iput might try to delete whatever object the inode last * represented. */ static void reiserfs_make_bad_inode(struct inode *inode) { … } /* * initially this function was derived from minix or ext2's analog and * evolved as the prototype did */ int reiserfs_init_locked_inode(struct inode *inode, void *p) { … } /* * looks for stat data in the tree, and fills up the fields of in-core * inode stat data fields */ void reiserfs_read_locked_inode(struct inode *inode, struct reiserfs_iget_args *args) { … } /* * reiserfs_find_actor() - "find actor" reiserfs supplies to iget5_locked(). * * @inode: inode from hash table to check * @opaque: "cookie" passed to iget5_locked(). This is &reiserfs_iget_args. * * This function is called by iget5_locked() to distinguish reiserfs inodes * having the same inode numbers. Such inodes can only exist due to some * error condition. One of them should be bad. Inodes with identical * inode numbers (objectids) are distinguished by parent directory ids. * */ int reiserfs_find_actor(struct inode *inode, void *opaque) { … } struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key) { … } static struct dentry *reiserfs_get_dentry(struct super_block *sb, u32 objectid, u32 dir_id, u32 generation) { … } struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { … } struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { … } int reiserfs_encode_fh(struct inode *inode, __u32 * data, int *lenp, struct inode *parent) { … } /* * looks for stat data, then copies fields to it, marks the buffer * containing stat data as dirty */ /* * reiserfs inodes are never really dirty, since the dirty inode call * always logs them. This call allows the VFS inode marking routines * to properly mark inodes for datasync and such, but only actually * does something when called for a synchronous update. */ int reiserfs_write_inode(struct inode *inode, struct writeback_control *wbc) { … } /* * stat data of new object is inserted already, this inserts the item * containing "." and ".." entries */ static int reiserfs_new_directory(struct reiserfs_transaction_handle *th, struct inode *inode, struct item_head *ih, struct treepath *path, struct inode *dir) { … } /* * stat data of object has been inserted, this inserts the item * containing the body of symlink */ static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct inode *inode, struct item_head *ih, struct treepath *path, const char *symname, int item_len) { … } /* * inserts the stat data into the tree, and then calls * reiserfs_new_directory (to insert ".", ".." item if new object is * directory) or reiserfs_new_symlink (to insert symlink body if new * object is symlink) or nothing (if new object is regular file) * NOTE! uid and gid must already be set in the inode. If we return * non-zero due to an error, we have to drop the quota previously allocated * for the fresh inode. This can only be done outside a transaction, so * if we return non-zero, we also end the transaction. * * @th: active transaction handle * @dir: parent directory for new inode * @mode: mode of new inode * @symname: symlink contents if inode is symlink * @isize: 0 for regular file, EMPTY_DIR_SIZE for dirs, strlen(symname) for * symlinks * @inode: inode to be filled * @security: optional security context to associate with this inode */ int reiserfs_new_inode(struct reiserfs_transaction_handle *th, struct inode *dir, umode_t mode, const char *symname, /* 0 for regular, EMTRY_DIR_SIZE for dirs, strlen (symname) for symlinks) */ loff_t i_size, struct dentry *dentry, struct inode *inode, struct reiserfs_security_handle *security) { … } /* * finds the tail page in the page cache, * reads the last block in. * * On success, page_result is set to a locked, pinned page, and bh_result * is set to an up to date buffer for the last block in the file. returns 0. * * tail conversion is not done, so bh_result might not be valid for writing * check buffer_mapped(bh_result) and bh_result->b_blocknr != 0 before * trying to write the block. * * on failure, nonzero is returned, page_result and bh_result are untouched. */ static int grab_tail_page(struct inode *inode, struct page **page_result, struct buffer_head **bh_result) { … } /* * vfs version of truncate file. Must NOT be called with * a transaction already started. * * some code taken from block_truncate_page */ int reiserfs_truncate_file(struct inode *inode, int update_timestamps) { … } static int map_block_for_writepage(struct inode *inode, struct buffer_head *bh_result, unsigned long block) { … } /* * [email protected]: updated in 2.5.54 to follow the same general io * start/recovery path as __block_write_full_folio, along with special * code to handle reiserfs tails. */ static int reiserfs_write_folio(struct folio *folio, struct writeback_control *wbc, void *data) { … } static int reiserfs_read_folio(struct file *f, struct folio *folio) { … } static int reiserfs_writepages(struct address_space *mapping, struct writeback_control *wbc) { … } static void reiserfs_truncate_failed_write(struct inode *inode) { … } static int reiserfs_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, struct page **pagep, void **fsdata) { … } int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len) { … } static sector_t reiserfs_aop_bmap(struct address_space *as, sector_t block) { … } static int reiserfs_write_end(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) { … } int reiserfs_commit_write(struct file *f, struct page *page, unsigned from, unsigned to) { … } void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode) { … } /* * decide if this buffer needs to stay around for data logging or ordered * write purposes */ static int invalidate_folio_can_drop(struct inode *inode, struct buffer_head *bh) { … } /* clm -- taken from fs/buffer.c:block_invalidate_folio */ static void reiserfs_invalidate_folio(struct folio *folio, size_t offset, size_t length) { … } static bool reiserfs_dirty_folio(struct address_space *mapping, struct folio *folio) { … } /* * Returns true if the folio's buffers were dropped. The folio is locked. * * Takes j_dirty_buffers_lock to protect the b_assoc_buffers list_heads * in the buffers at folio_buffers(folio). * * even in -o notail mode, we can't be sure an old mount without -o notail * didn't create files with tails. */ static bool reiserfs_release_folio(struct folio *folio, gfp_t unused_gfp_flags) { … } /* * We thank Mingming Cao for helping us understand in great detail what * to do in this section of the code. */ static ssize_t reiserfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) { … } int reiserfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr) { … } const struct address_space_operations reiserfs_address_space_operations = …;