2018-09-05 01:46:30 +03:00
/* SPDX-License-Identifier: GPL-2.0+ */
2009-04-07 06:01:23 +04:00
/*
2021-11-09 05:35:01 +03:00
* NILFS local header file .
2009-04-07 06:01:23 +04:00
*
* Copyright ( C ) 2005 - 2008 Nippon Telegraph and Telephone Corporation .
*
2016-05-24 02:23:09 +03:00
* Written by Koji Sato and Ryusuke Konishi .
2009-04-07 06:01:23 +04:00
*/
# ifndef _NILFS_H
# define _NILFS_H
# include <linux/kernel.h>
# include <linux/buffer_head.h>
# include <linux/spinlock.h>
# include <linux/blkdev.h>
2016-08-03 00:05:30 +03:00
# include <linux/nilfs2_api.h>
# include <linux/nilfs2_ondisk.h>
2009-04-07 06:01:23 +04:00
# include "the_nilfs.h"
# include "bmap.h"
2012-07-31 01:42:10 +04:00
/**
* struct nilfs_inode_info - nilfs inode data in memory
* @ i_flags : inode flags
* @ i_state : dynamic state flags
* @ i_bmap : pointer on i_bmap_data
* @ i_bmap_data : raw block mapping
* @ i_xattr : < TODO >
* @ i_dir_start_lookup : page index of last successful search
* @ i_cno : checkpoint number for GC inode
2022-04-01 21:28:18 +03:00
* @ i_assoc_inode : associated inode ( B - tree node cache holder or back pointer )
2012-07-31 01:42:10 +04:00
* @ i_dirty : list for connecting dirty files
* @ xattr_sem : semaphore for extended attributes processing
* @ i_bh : buffer contains disk inode
* @ i_root : root object of the current filesystem tree
* @ vfs_inode : VFS inode object
2009-04-07 06:01:23 +04:00
*/
struct nilfs_inode_info {
__u32 i_flags ;
unsigned long i_state ; /* Dynamic state flags */
struct nilfs_bmap * i_bmap ;
2010-07-10 15:52:09 +04:00
struct nilfs_bmap i_bmap_data ;
2009-04-07 06:01:23 +04:00
__u64 i_xattr ; /* sector_t ??? */
__u32 i_dir_start_lookup ;
__u64 i_cno ; /* check point number for GC inode */
2022-04-01 21:28:18 +03:00
struct inode * i_assoc_inode ;
2009-04-07 06:01:23 +04:00
struct list_head i_dirty ; /* List for connecting dirty files */
# ifdef CONFIG_NILFS_XATTR
/*
* Extended attributes can be read independently of the main file
* data . Taking i_sem even when reading would cause contention
* between readers of EAs and writers of regular file data , so
* instead we synchronize on xattr_sem when reading or changing
* EAs .
*/
struct rw_semaphore xattr_sem ;
# endif
2016-05-24 02:23:48 +03:00
struct buffer_head * i_bh ; /*
* i_bh contains a new or dirty
* disk inode .
*/
2010-08-25 12:45:44 +04:00
struct nilfs_root * i_root ;
2009-04-07 06:01:23 +04:00
struct inode vfs_inode ;
} ;
static inline struct nilfs_inode_info * NILFS_I ( const struct inode * inode )
{
return container_of ( inode , struct nilfs_inode_info , vfs_inode ) ;
}
static inline struct nilfs_inode_info *
NILFS_BMAP_I ( const struct nilfs_bmap * bmap )
{
2010-07-10 15:52:09 +04:00
return container_of ( bmap , struct nilfs_inode_info , i_bmap_data ) ;
2009-04-07 06:01:23 +04:00
}
/*
* Dynamic state flags of NILFS on - memory inode ( i_state )
*/
enum {
NILFS_I_NEW = 0 , /* Inode is newly created */
NILFS_I_DIRTY , /* The file is dirty */
NILFS_I_QUEUED , /* inode is in dirty_files list */
2016-05-24 02:23:48 +03:00
NILFS_I_BUSY , /*
* Inode is grabbed by a segment
* constructor
*/
2009-04-07 06:01:23 +04:00
NILFS_I_COLLECTED , /* All dirty blocks are collected */
NILFS_I_UPDATED , /* The file has been written back */
2014-10-14 02:53:22 +04:00
NILFS_I_INODE_SYNC , /* dsync is not allowed for inode */
2009-04-07 06:01:23 +04:00
NILFS_I_BMAP , /* has bmap and btnode_cache */
NILFS_I_GCINODE , /* inode for GC, on memory only */
2022-04-01 21:28:18 +03:00
NILFS_I_BTNC , /* inode for btree node cache */
2022-04-01 21:28:21 +03:00
NILFS_I_SHADOW , /* inode for shadowed page cache */
2009-04-07 06:01:23 +04:00
} ;
2010-06-28 12:49:33 +04:00
/*
* commit flags for nilfs_commit_super and nilfs_sync_super
*/
enum {
NILFS_SB_COMMIT = 0 , /* Commit a super block alternately */
NILFS_SB_COMMIT_ALL /* Commit both super blocks */
} ;
2009-04-07 06:01:23 +04:00
/*
* Macros to check inode numbers
*/
2016-08-03 00:05:28 +03:00
# define NILFS_MDT_INO_BITS \
( BIT ( NILFS_DAT_INO ) | BIT ( NILFS_CPFILE_INO ) | \
BIT ( NILFS_SUFILE_INO ) | BIT ( NILFS_IFILE_INO ) | \
BIT ( NILFS_ATIME_INO ) | BIT ( NILFS_SKETCH_INO ) )
2009-04-07 06:01:23 +04:00
2016-08-03 00:05:28 +03:00
# define NILFS_SYS_INO_BITS (BIT(NILFS_ROOT_INO) | NILFS_MDT_INO_BITS)
2009-04-07 06:01:23 +04:00
2011-03-09 05:05:08 +03:00
# define NILFS_FIRST_INO(sb) (((struct the_nilfs *)sb->s_fs_info)->ns_first_ino)
2009-04-07 06:01:23 +04:00
# define NILFS_MDT_INODE(sb, ino) \
2016-08-03 00:05:28 +03:00
( ( ino ) < NILFS_FIRST_INO ( sb ) & & ( NILFS_MDT_INO_BITS & BIT ( ino ) ) )
2009-04-07 06:01:23 +04:00
# define NILFS_VALID_INODE(sb, ino) \
2016-08-03 00:05:28 +03:00
( ( ino ) > = NILFS_FIRST_INO ( sb ) | | ( NILFS_SYS_INO_BITS & BIT ( ino ) ) )
2009-04-07 06:01:23 +04:00
/**
* struct nilfs_transaction_info : context information for synchronization
* @ ti_magic : Magic number
* @ ti_save : Backup of journal_info field of task_struct
* @ ti_flags : Flags
* @ ti_count : Nest level
*/
struct nilfs_transaction_info {
u32 ti_magic ;
void * ti_save ;
2016-05-24 02:23:48 +03:00
/*
* This should never be used . If it happens ,
* one of other filesystems has a bug .
*/
2009-04-07 06:01:23 +04:00
unsigned short ti_flags ;
unsigned short ti_count ;
} ;
/* ti_magic */
# define NILFS_TI_MAGIC 0xd9e392fb
/* ti_flags */
# define NILFS_TI_DYNAMIC_ALLOC 0x0001 /* Allocated from slab */
2016-05-24 02:23:48 +03:00
# define NILFS_TI_SYNC 0x0002 / *
* Force to construct segment at the
* end of transaction .
*/
2009-04-07 06:01:23 +04:00
# define NILFS_TI_GC 0x0004 /* GC context */
# define NILFS_TI_COMMIT 0x0008 /* Change happened or not */
# define NILFS_TI_WRITER 0x0010 /* Constructor context */
int nilfs_transaction_begin ( struct super_block * ,
struct nilfs_transaction_info * , int ) ;
2009-04-07 06:01:45 +04:00
int nilfs_transaction_commit ( struct super_block * ) ;
void nilfs_transaction_abort ( struct super_block * ) ;
2009-04-07 06:01:23 +04:00
static inline void nilfs_set_transaction_flag ( unsigned int flag )
{
struct nilfs_transaction_info * ti = current - > journal_info ;
ti - > ti_flags | = flag ;
}
static inline int nilfs_test_transaction_flag ( unsigned int flag )
{
struct nilfs_transaction_info * ti = current - > journal_info ;
if ( ti = = NULL | | ti - > ti_magic ! = NILFS_TI_MAGIC )
return 0 ;
return ! ! ( ti - > ti_flags & flag ) ;
}
static inline int nilfs_doing_gc ( void )
{
return nilfs_test_transaction_flag ( NILFS_TI_GC ) ;
}
static inline int nilfs_doing_construction ( void )
{
return nilfs_test_transaction_flag ( NILFS_TI_WRITER ) ;
}
/*
* function prototype
*/
# ifdef CONFIG_NILFS_POSIX_ACL
# error "NILFS: not yet supported POSIX ACL"
extern int nilfs_acl_chmod ( struct inode * ) ;
extern int nilfs_init_acl ( struct inode * , struct inode * ) ;
# else
static inline int nilfs_acl_chmod ( struct inode * inode )
{
return 0 ;
}
static inline int nilfs_init_acl ( struct inode * inode , struct inode * dir )
{
2022-06-23 11:54:01 +03:00
if ( S_ISLNK ( inode - > i_mode ) )
return 0 ;
2009-04-07 06:01:23 +04:00
inode - > i_mode & = ~ current_umask ( ) ;
return 0 ;
}
# endif
# define NILFS_ATIME_DISABLE
2011-01-19 20:09:53 +03:00
/* Flags that should be inherited by new inodes from their parent. */
# define NILFS_FL_INHERITED \
( FS_SECRM_FL | FS_UNRM_FL | FS_COMPR_FL | FS_SYNC_FL | \
FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL | \
FS_COMPRBLK_FL | FS_NOCOMP_FL | FS_NOTAIL_FL | FS_DIRSYNC_FL )
/* Mask out flags that are inappropriate for the given type of inode. */
static inline __u32 nilfs_mask_flags ( umode_t mode , __u32 flags )
{
if ( S_ISDIR ( mode ) )
return flags ;
else if ( S_ISREG ( mode ) )
return flags & ~ ( FS_DIRSYNC_FL | FS_TOPDIR_FL ) ;
else
return flags & ( FS_NODUMP_FL | FS_NOATIME_FL ) ;
}
2009-04-07 06:01:23 +04:00
/* dir.c */
extern int nilfs_add_link ( struct dentry * , struct inode * ) ;
2010-02-01 05:02:09 +03:00
extern ino_t nilfs_inode_by_name ( struct inode * , const struct qstr * ) ;
2009-04-07 06:01:23 +04:00
extern int nilfs_make_empty ( struct inode * , struct inode * ) ;
extern struct nilfs_dir_entry *
2010-02-01 05:02:09 +03:00
nilfs_find_entry ( struct inode * , const struct qstr * , struct page * * ) ;
2009-04-07 06:01:23 +04:00
extern int nilfs_delete_entry ( struct nilfs_dir_entry * , struct page * ) ;
extern int nilfs_empty_dir ( struct inode * ) ;
extern struct nilfs_dir_entry * nilfs_dotdot ( struct inode * , struct page * * ) ;
extern void nilfs_set_link ( struct inode * , struct nilfs_dir_entry * ,
struct page * , struct inode * ) ;
/* file.c */
2011-07-17 04:44:56 +04:00
extern int nilfs_sync_file ( struct file * , loff_t , loff_t , int ) ;
2009-04-07 06:01:23 +04:00
/* ioctl.c */
2021-04-07 15:36:44 +03:00
int nilfs_fileattr_get ( struct dentry * dentry , struct fileattr * m ) ;
2023-01-13 14:49:21 +03:00
int nilfs_fileattr_set ( struct mnt_idmap * idmap ,
2021-04-07 15:36:44 +03:00
struct dentry * dentry , struct fileattr * fa ) ;
2009-04-07 06:01:53 +04:00
long nilfs_ioctl ( struct file * , unsigned int , unsigned long ) ;
2011-02-03 15:26:17 +03:00
long nilfs_compat_ioctl ( struct file * file , unsigned int cmd , unsigned long arg ) ;
2009-05-10 17:41:43 +04:00
int nilfs_ioctl_prepare_clean_segments ( struct the_nilfs * , struct nilfs_argv * ,
void * * ) ;
2009-04-07 06:01:23 +04:00
/* inode.c */
2011-03-04 18:19:32 +03:00
void nilfs_inode_add_blocks ( struct inode * inode , int n ) ;
void nilfs_inode_sub_blocks ( struct inode * inode , int n ) ;
2011-07-26 11:07:14 +04:00
extern struct inode * nilfs_new_inode ( struct inode * , umode_t ) ;
2009-04-07 06:01:23 +04:00
extern int nilfs_get_block ( struct inode * , sector_t , struct buffer_head * , int ) ;
extern void nilfs_set_inode_flags ( struct inode * ) ;
extern int nilfs_read_inode_common ( struct inode * , struct nilfs_inode * ) ;
extern void nilfs_write_inode_common ( struct inode * , struct nilfs_inode * , int ) ;
2010-09-13 06:16:34 +04:00
struct inode * nilfs_ilookup ( struct super_block * sb , struct nilfs_root * root ,
unsigned long ino ) ;
2010-09-05 07:20:59 +04:00
struct inode * nilfs_iget_locked ( struct super_block * sb , struct nilfs_root * root ,
unsigned long ino ) ;
2010-08-25 12:45:44 +04:00
struct inode * nilfs_iget ( struct super_block * sb , struct nilfs_root * root ,
unsigned long ino ) ;
2010-08-20 14:06:11 +04:00
extern struct inode * nilfs_iget_for_gc ( struct super_block * sb ,
unsigned long ino , __u64 cno ) ;
2022-04-01 21:28:18 +03:00
int nilfs_attach_btree_node_cache ( struct inode * inode ) ;
void nilfs_detach_btree_node_cache ( struct inode * inode ) ;
2022-04-01 21:28:21 +03:00
struct inode * nilfs_iget_for_shadow ( struct inode * inode ) ;
2014-10-14 02:53:22 +04:00
extern void nilfs_update_inode ( struct inode * , struct buffer_head * , int ) ;
2009-04-07 06:01:23 +04:00
extern void nilfs_truncate ( struct inode * ) ;
2010-06-07 19:55:00 +04:00
extern void nilfs_evict_inode ( struct inode * ) ;
2023-01-13 14:49:11 +03:00
extern int nilfs_setattr ( struct mnt_idmap * , struct dentry * ,
2021-01-21 16:19:43 +03:00
struct iattr * ) ;
2012-12-15 14:57:37 +04:00
extern void nilfs_write_failed ( struct address_space * mapping , loff_t to ) ;
2023-01-13 14:49:22 +03:00
int nilfs_permission ( struct mnt_idmap * idmap , struct inode * inode ,
2021-01-21 16:19:43 +03:00
int mask ) ;
2010-12-26 18:05:49 +03:00
int nilfs_load_inode_block ( struct inode * inode , struct buffer_head * * pbh ) ;
2009-04-07 06:01:23 +04:00
extern int nilfs_inode_dirty ( struct inode * ) ;
2016-05-24 02:23:39 +03:00
int nilfs_set_file_dirty ( struct inode * inode , unsigned int nr_dirty ) ;
2014-10-14 02:53:22 +04:00
extern int __nilfs_mark_inode_dirty ( struct inode * , int ) ;
2011-05-27 14:53:02 +04:00
extern void nilfs_dirty_inode ( struct inode * , int flags ) ;
2010-12-26 10:38:43 +03:00
int nilfs_fiemap ( struct inode * inode , struct fiemap_extent_info * fieinfo ,
__u64 start , __u64 len ) ;
2014-10-14 02:53:22 +04:00
static inline int nilfs_mark_inode_dirty ( struct inode * inode )
{
return __nilfs_mark_inode_dirty ( inode , I_DIRTY ) ;
}
static inline int nilfs_mark_inode_dirty_sync ( struct inode * inode )
{
return __nilfs_mark_inode_dirty ( inode , I_DIRTY_SYNC ) ;
}
2009-04-07 06:01:23 +04:00
/* super.c */
extern struct inode * nilfs_alloc_inode ( struct super_block * ) ;
2016-08-03 00:05:00 +03:00
2020-08-12 04:35:46 +03:00
__printf ( 2 , 3 )
void __nilfs_msg ( struct super_block * sb , const char * fmt , . . . ) ;
2011-11-01 04:11:33 +04:00
extern __printf ( 3 , 4 )
2016-08-03 00:05:00 +03:00
void __nilfs_error ( struct super_block * sb , const char * function ,
const char * fmt , . . . ) ;
# ifdef CONFIG_PRINTK
2016-08-03 00:05:02 +03:00
# define nilfs_msg(sb, level, fmt, ...) \
2020-08-12 04:35:46 +03:00
__nilfs_msg ( sb , level fmt , # # __VA_ARGS__ )
2016-08-03 00:05:00 +03:00
# define nilfs_error(sb, fmt, ...) \
__nilfs_error ( sb , __func__ , fmt , # # __VA_ARGS__ )
# else
2016-08-03 00:05:02 +03:00
# define nilfs_msg(sb, level, fmt, ...) \
2016-08-03 00:05:14 +03:00
do { \
2020-08-12 04:35:46 +03:00
no_printk ( level fmt , # # __VA_ARGS__ ) ; \
2016-08-03 00:05:14 +03:00
( void ) ( sb ) ; \
} while ( 0 )
2016-08-03 00:05:00 +03:00
# define nilfs_error(sb, fmt, ...) \
do { \
no_printk ( fmt , # # __VA_ARGS__ ) ; \
__nilfs_error ( sb , " " , " " ) ; \
} while ( 0 )
# endif /* CONFIG_PRINTK */
2020-08-12 04:35:49 +03:00
# define nilfs_crit(sb, fmt, ...) \
nilfs_msg ( sb , KERN_CRIT , fmt , # # __VA_ARGS__ )
# define nilfs_err(sb, fmt, ...) \
nilfs_msg ( sb , KERN_ERR , fmt , # # __VA_ARGS__ )
# define nilfs_warn(sb, fmt, ...) \
nilfs_msg ( sb , KERN_WARNING , fmt , # # __VA_ARGS__ )
# define nilfs_info(sb, fmt, ...) \
nilfs_msg ( sb , KERN_INFO , fmt , # # __VA_ARGS__ )
2009-04-07 06:01:23 +04:00
extern struct nilfs_super_block *
2009-04-07 06:01:59 +04:00
nilfs_read_super_block ( struct super_block * , u64 , int , struct buffer_head * * ) ;
2009-04-07 06:01:23 +04:00
extern int nilfs_store_magic_and_option ( struct super_block * ,
struct nilfs_super_block * , char * ) ;
2010-07-21 22:22:20 +04:00
extern int nilfs_check_feature_compatibility ( struct super_block * ,
struct nilfs_super_block * ) ;
2010-06-28 12:49:31 +04:00
extern void nilfs_set_log_cursor ( struct nilfs_super_block * ,
struct the_nilfs * ) ;
2011-03-09 05:05:08 +03:00
struct nilfs_super_block * * nilfs_prepare_super ( struct super_block * sb ,
int flip ) ;
int nilfs_commit_super ( struct super_block * sb , int flag ) ;
int nilfs_cleanup_super ( struct super_block * sb ) ;
2011-05-04 20:23:58 +04:00
int nilfs_resize_fs ( struct super_block * sb , __u64 newsize ) ;
2011-03-09 05:05:08 +03:00
int nilfs_attach_checkpoint ( struct super_block * sb , __u64 cno , int curr_mnt ,
2010-08-25 12:45:44 +04:00
struct nilfs_root * * root ) ;
2010-09-13 06:16:34 +04:00
int nilfs_checkpoint_is_mounted ( struct super_block * sb , __u64 cno ) ;
2009-04-07 06:01:23 +04:00
/* gcinode.c */
int nilfs_gccache_submit_read_data ( struct inode * , sector_t , sector_t , __u64 ,
struct buffer_head * * ) ;
int nilfs_gccache_submit_read_node ( struct inode * , sector_t , __u64 ,
struct buffer_head * * ) ;
int nilfs_gccache_wait_and_mark_dirty ( struct buffer_head * ) ;
2010-08-20 14:06:11 +04:00
int nilfs_init_gcinode ( struct inode * inode ) ;
void nilfs_remove_all_gcinodes ( struct the_nilfs * nilfs ) ;
2009-04-07 06:01:23 +04:00
2014-08-09 01:20:55 +04:00
/* sysfs.c */
int __init nilfs_sysfs_init ( void ) ;
void nilfs_sysfs_exit ( void ) ;
int nilfs_sysfs_create_device_group ( struct super_block * ) ;
void nilfs_sysfs_delete_device_group ( struct the_nilfs * ) ;
int nilfs_sysfs_create_snapshot_group ( struct nilfs_root * ) ;
void nilfs_sysfs_delete_snapshot_group ( struct nilfs_root * ) ;
2009-04-07 06:01:23 +04:00
/*
* Inodes and files operations
*/
2009-10-02 02:43:56 +04:00
extern const struct file_operations nilfs_dir_operations ;
2009-09-22 04:01:11 +04:00
extern const struct inode_operations nilfs_file_inode_operations ;
2009-10-02 02:43:56 +04:00
extern const struct file_operations nilfs_file_operations ;
2009-09-22 04:01:10 +04:00
extern const struct address_space_operations nilfs_aops ;
2009-09-22 04:01:11 +04:00
extern const struct inode_operations nilfs_dir_inode_operations ;
extern const struct inode_operations nilfs_special_inode_operations ;
extern const struct inode_operations nilfs_symlink_inode_operations ;
2009-04-07 06:01:23 +04:00
/*
* filesystem type
*/
extern struct file_system_type nilfs_fs_type ;
# endif /* _NILFS_H */