2021-12-03 17:18:03 -05:00
/* SPDX-License-Identifier: GPL-2.0 */
# ifndef BTRFS_INODE_ITEM_H
# define BTRFS_INODE_ITEM_H
# include <linux/types.h>
2023-08-25 16:19:21 -04:00
# include <linux/crc32c.h>
2021-12-03 17:18:03 -05:00
2024-01-27 03:19:56 +01:00
struct fscrypt_str ;
struct extent_buffer ;
2021-12-03 17:18:03 -05:00
struct btrfs_trans_handle ;
struct btrfs_root ;
struct btrfs_path ;
struct btrfs_key ;
struct btrfs_inode_extref ;
2021-12-03 17:18:04 -05:00
struct btrfs_inode ;
2024-01-27 03:19:56 +01:00
struct btrfs_truncate_control ;
2021-12-03 17:18:03 -05:00
2021-12-03 17:18:04 -05:00
/*
* Return this if we need to call truncate_block for the last bit of the
* truncate .
*/
# define BTRFS_NEED_TRUNCATE_BLOCK 1
2021-12-03 17:18:09 -05:00
struct btrfs_truncate_control {
2021-12-03 17:18:15 -05:00
/*
* IN : the inode we ' re operating on , this can be NULL if
* - > clear_extent_range is false .
*/
struct btrfs_inode * inode ;
2021-12-03 17:18:09 -05:00
/* IN: the size we're truncating to. */
u64 new_size ;
/* OUT: the number of extents truncated. */
u64 extents_found ;
2021-12-03 17:18:10 -05:00
/* OUT: the last size we truncated this inode to. */
u64 last_size ;
2021-12-03 17:18:11 -05:00
/* OUT: the number of bytes to sub from this inode. */
u64 sub_bytes ;
2021-12-03 17:18:14 -05:00
/* IN: the ino we are truncating. */
u64 ino ;
2021-12-03 17:18:09 -05:00
/*
* IN : minimum key type to remove . All key types with this type are
* removed only if their offset > = new_size .
*/
u32 min_type ;
2021-12-03 17:18:12 -05:00
/*
* IN : true if we don ' t want to do extent reference updates for any file
* extents we drop .
*/
bool skip_ref_updates ;
2021-12-03 17:18:13 -05:00
/*
* IN : true if we need to clear the file extent range for the inode as
* we drop the file extent items .
*/
bool clear_extent_range ;
2021-12-03 17:18:09 -05:00
} ;
2023-04-29 16:07:18 -04:00
/*
* btrfs_inode_item stores flags in a u64 , btrfs_inode stores them in two
* separate u32s . These two functions convert between the two representations .
*/
static inline u64 btrfs_inode_combine_flags ( u32 flags , u32 ro_flags )
{
return ( flags | ( ( u64 ) ro_flags < < 32 ) ) ;
}
static inline void btrfs_inode_split_flags ( u64 inode_item_flags ,
u32 * flags , u32 * ro_flags )
{
* flags = ( u32 ) inode_item_flags ;
* ro_flags = ( u32 ) ( inode_item_flags > > 32 ) ;
}
2023-08-25 16:19:21 -04:00
/* Figure the key offset of an extended inode ref. */
static inline u64 btrfs_extref_hash ( u64 parent_objectid , const char * name , int len )
{
return ( u64 ) crc32c ( parent_objectid , name , len ) ;
}
2021-12-03 17:18:04 -05:00
int btrfs_truncate_inode_items ( struct btrfs_trans_handle * trans ,
struct btrfs_root * root ,
2021-12-03 17:18:09 -05:00
struct btrfs_truncate_control * control ) ;
2021-12-03 17:18:03 -05:00
int btrfs_insert_inode_ref ( struct btrfs_trans_handle * trans ,
2022-10-20 12:58:27 -04:00
struct btrfs_root * root , const struct fscrypt_str * name ,
2021-12-03 17:18:03 -05:00
u64 inode_objectid , u64 ref_objectid , u64 index ) ;
int btrfs_del_inode_ref ( struct btrfs_trans_handle * trans ,
2022-10-20 12:58:27 -04:00
struct btrfs_root * root , const struct fscrypt_str * name ,
2022-10-20 12:58:25 -04:00
u64 inode_objectid , u64 ref_objectid , u64 * index ) ;
2021-12-03 17:18:03 -05:00
int btrfs_insert_empty_inode ( struct btrfs_trans_handle * trans ,
struct btrfs_root * root ,
struct btrfs_path * path , u64 objectid ) ;
2022-10-20 12:58:25 -04:00
int btrfs_lookup_inode ( struct btrfs_trans_handle * trans ,
struct btrfs_root * root , struct btrfs_path * path ,
2021-12-03 17:18:03 -05:00
struct btrfs_key * location , int mod ) ;
struct btrfs_inode_extref * btrfs_lookup_inode_extref (
struct btrfs_trans_handle * trans ,
struct btrfs_root * root ,
struct btrfs_path * path ,
2022-10-20 12:58:27 -04:00
const struct fscrypt_str * name ,
2021-12-03 17:18:03 -05:00
u64 inode_objectid , u64 ref_objectid , int ins_len ,
int cow ) ;
struct btrfs_inode_ref * btrfs_find_name_in_backref ( struct extent_buffer * leaf ,
2022-10-20 12:58:25 -04:00
int slot ,
2022-10-20 12:58:27 -04:00
const struct fscrypt_str * name ) ;
2021-12-03 17:18:03 -05:00
struct btrfs_inode_extref * btrfs_find_name_in_ext_backref (
struct extent_buffer * leaf , int slot , u64 ref_objectid ,
2022-10-20 12:58:27 -04:00
const struct fscrypt_str * name ) ;
2021-12-03 17:18:03 -05:00
# endif