xref: /linux/fs/gfs2/inode.h (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
17336d0e6SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2b3b94faaSDavid Teigland /*
3b3b94faaSDavid Teigland  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
43a8a9a10SSteven Whitehouse  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
5b3b94faaSDavid Teigland  */
6b3b94faaSDavid Teigland 
7b3b94faaSDavid Teigland #ifndef __INODE_DOT_H__
8b3b94faaSDavid Teigland #define __INODE_DOT_H__
9b3b94faaSDavid Teigland 
10b2760583SSteven Whitehouse #include <linux/fs.h>
11b1e71b06SSteven Whitehouse #include <linux/buffer_head.h>
12b1e71b06SSteven Whitehouse #include <linux/mm.h>
1377658aadSSteven Whitehouse #include "util.h"
1477658aadSSteven Whitehouse 
15e45c20d1SMatthew Wilcox (Oracle) bool gfs2_release_folio(struct folio *folio, gfp_t gfp_mask);
16*0b2355feSAndreas Gruenbacher ssize_t gfs2_internal_read(struct gfs2_inode *ip,
17be7f6a6bSAndreas Gruenbacher 			   char *buf, loff_t *pos, size_t size);
18*0b2355feSAndreas Gruenbacher void gfs2_set_aops(struct inode *inode);
19b1e71b06SSteven Whitehouse 
gfs2_is_stuffed(const struct gfs2_inode * ip)20dbb7cae2SSteven Whitehouse static inline int gfs2_is_stuffed(const struct gfs2_inode *ip)
21b3b94faaSDavid Teigland {
22ecc30c79SSteven Whitehouse 	return !ip->i_height;
23b3b94faaSDavid Teigland }
24b3b94faaSDavid Teigland 
gfs2_is_jdata(const struct gfs2_inode * ip)25dbb7cae2SSteven Whitehouse static inline int gfs2_is_jdata(const struct gfs2_inode *ip)
26b3b94faaSDavid Teigland {
27383f01fbSSteven Whitehouse 	return ip->i_diskflags & GFS2_DIF_JDATA;
28b3b94faaSDavid Teigland }
29b3b94faaSDavid Teigland 
gfs2_is_ordered(const struct gfs2_sbd * sdp)30977767a7SAndreas Gruenbacher static inline bool gfs2_is_ordered(const struct gfs2_sbd *sdp)
31bf36a713SSteven Whitehouse {
32977767a7SAndreas Gruenbacher 	return sdp->sd_args.ar_data == GFS2_DATA_ORDERED;
33bf36a713SSteven Whitehouse }
34bf36a713SSteven Whitehouse 
gfs2_is_writeback(const struct gfs2_sbd * sdp)35977767a7SAndreas Gruenbacher static inline bool gfs2_is_writeback(const struct gfs2_sbd *sdp)
365561093eSSteven Whitehouse {
37977767a7SAndreas Gruenbacher 	return sdp->sd_args.ar_data == GFS2_DATA_WRITEBACK;
385561093eSSteven Whitehouse }
395561093eSSteven Whitehouse 
gfs2_is_dir(const struct gfs2_inode * ip)40dbb7cae2SSteven Whitehouse static inline int gfs2_is_dir(const struct gfs2_inode *ip)
4118ec7d5cSSteven Whitehouse {
42b60623c2SSteven Whitehouse 	return S_ISDIR(ip->i_inode.i_mode);
4318ec7d5cSSteven Whitehouse }
4418ec7d5cSSteven Whitehouse 
gfs2_set_inode_blocks(struct inode * inode,u64 blocks)4577658aadSSteven Whitehouse static inline void gfs2_set_inode_blocks(struct inode *inode, u64 blocks)
469e2dbdacSSteven Whitehouse {
4713587069SAndreas Gruenbacher 	inode->i_blocks = blocks << (inode->i_blkbits - 9);
489e2dbdacSSteven Whitehouse }
499e2dbdacSSteven Whitehouse 
gfs2_get_inode_blocks(const struct inode * inode)5077658aadSSteven Whitehouse static inline u64 gfs2_get_inode_blocks(const struct inode *inode)
5177658aadSSteven Whitehouse {
5213587069SAndreas Gruenbacher 	return inode->i_blocks >> (inode->i_blkbits - 9);
5377658aadSSteven Whitehouse }
5477658aadSSteven Whitehouse 
gfs2_add_inode_blocks(struct inode * inode,s64 change)5577658aadSSteven Whitehouse static inline void gfs2_add_inode_blocks(struct inode *inode, s64 change)
5677658aadSSteven Whitehouse {
5713587069SAndreas Gruenbacher 	change <<= inode->i_blkbits - 9;
587c03e756STim Smith 	gfs2_assert(GFS2_SB(inode), (change >= 0 || inode->i_blocks >= -change));
5977658aadSSteven Whitehouse 	inode->i_blocks += change;
6077658aadSSteven Whitehouse }
6177658aadSSteven Whitehouse 
gfs2_check_inum(const struct gfs2_inode * ip,u64 no_addr,u64 no_formal_ino)62dbb7cae2SSteven Whitehouse static inline int gfs2_check_inum(const struct gfs2_inode *ip, u64 no_addr,
63dbb7cae2SSteven Whitehouse 				  u64 no_formal_ino)
64dbb7cae2SSteven Whitehouse {
65dbb7cae2SSteven Whitehouse 	return ip->i_no_addr == no_addr && ip->i_no_formal_ino == no_formal_ino;
66dbb7cae2SSteven Whitehouse }
67dbb7cae2SSteven Whitehouse 
gfs2_inum_out(const struct gfs2_inode * ip,struct gfs2_dirent * dent)68bb8d8a6fSSteven Whitehouse static inline void gfs2_inum_out(const struct gfs2_inode *ip,
69bb8d8a6fSSteven Whitehouse 				 struct gfs2_dirent *dent)
70bb8d8a6fSSteven Whitehouse {
71bb8d8a6fSSteven Whitehouse 	dent->de_inum.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino);
72bb8d8a6fSSteven Whitehouse 	dent->de_inum.no_addr = cpu_to_be64(ip->i_no_addr);
73bb8d8a6fSSteven Whitehouse }
74bb8d8a6fSSteven Whitehouse 
gfs2_check_internal_file_size(struct inode * inode,u64 minsize,u64 maxsize)75a2e0f799SSteven Whitehouse static inline int gfs2_check_internal_file_size(struct inode *inode,
76a2e0f799SSteven Whitehouse 						u64 minsize, u64 maxsize)
77a2e0f799SSteven Whitehouse {
78a2e0f799SSteven Whitehouse 	u64 size = i_size_read(inode);
79a2e0f799SSteven Whitehouse 	if (size < minsize || size > maxsize)
80a2e0f799SSteven Whitehouse 		goto err;
8147a9a527SFabian Frederick 	if (size & (BIT(inode->i_blkbits) - 1))
82a2e0f799SSteven Whitehouse 		goto err;
83a2e0f799SSteven Whitehouse 	return 0;
84a2e0f799SSteven Whitehouse err:
85a2e0f799SSteven Whitehouse 	gfs2_consist_inode(GFS2_I(inode));
86a2e0f799SSteven Whitehouse 	return -EIO;
87a2e0f799SSteven Whitehouse }
88bb8d8a6fSSteven Whitehouse 
89*0b2355feSAndreas Gruenbacher struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type,
903ce37b2cSAndreas Gruenbacher 			        u64 no_addr, u64 no_formal_ino,
913ce37b2cSAndreas Gruenbacher 			        unsigned int blktype);
92*0b2355feSAndreas Gruenbacher struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
936bdcadeaSAndreas Gruenbacher 				  u64 no_formal_ino,
94044b9414SSteven Whitehouse 				  unsigned int blktype);
95b3b94faaSDavid Teigland 
96*0b2355feSAndreas Gruenbacher int gfs2_inode_refresh(struct gfs2_inode *ip);
97b3b94faaSDavid Teigland 
98*0b2355feSAndreas Gruenbacher struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
99a569c711SAl Viro 			   int is_root);
100*0b2355feSAndreas Gruenbacher int gfs2_permission(struct mnt_idmap *idmap,
101549c7297SChristian Brauner 		    struct inode *inode, int mask);
102*0b2355feSAndreas Gruenbacher struct inode *gfs2_lookup_meta(struct inode *dip, const char *name);
103*0b2355feSAndreas Gruenbacher void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf);
104*0b2355feSAndreas Gruenbacher int gfs2_open_common(struct inode *inode, struct file *file);
105*0b2355feSAndreas Gruenbacher loff_t gfs2_seek_data(struct file *file, loff_t offset);
106*0b2355feSAndreas Gruenbacher loff_t gfs2_seek_hole(struct file *file, loff_t offset);
107b3b94faaSDavid Teigland 
10810d21988SChristoph Hellwig extern const struct file_operations gfs2_file_fops_nolock;
10910d21988SChristoph Hellwig extern const struct file_operations gfs2_dir_fops_nolock;
110b2760583SSteven Whitehouse 
111*0b2355feSAndreas Gruenbacher int gfs2_fileattr_get(struct dentry *dentry, struct fileattr *fa);
112*0b2355feSAndreas Gruenbacher int gfs2_fileattr_set(struct mnt_idmap *idmap,
11388b631cbSMiklos Szeredi 		      struct dentry *dentry, struct fileattr *fa);
114*0b2355feSAndreas Gruenbacher void gfs2_set_inode_flags(struct inode *inode);
115b2760583SSteven Whitehouse 
116f057f6cdSSteven Whitehouse #ifdef CONFIG_GFS2_FS_LOCKING_DLM
11710d21988SChristoph Hellwig extern const struct file_operations gfs2_file_fops;
11810d21988SChristoph Hellwig extern const struct file_operations gfs2_dir_fops;
11910d21988SChristoph Hellwig 
gfs2_localflocks(const struct gfs2_sbd * sdp)120f057f6cdSSteven Whitehouse static inline int gfs2_localflocks(const struct gfs2_sbd *sdp)
121f057f6cdSSteven Whitehouse {
122f057f6cdSSteven Whitehouse 	return sdp->sd_args.ar_localflocks;
123f057f6cdSSteven Whitehouse }
124f057f6cdSSteven Whitehouse #else /* Single node only */
12510d21988SChristoph Hellwig #define gfs2_file_fops gfs2_file_fops_nolock
12610d21988SChristoph Hellwig #define gfs2_dir_fops gfs2_dir_fops_nolock
12710d21988SChristoph Hellwig 
gfs2_localflocks(const struct gfs2_sbd * sdp)128f057f6cdSSteven Whitehouse static inline int gfs2_localflocks(const struct gfs2_sbd *sdp)
129f057f6cdSSteven Whitehouse {
130f057f6cdSSteven Whitehouse 	return 1;
131f057f6cdSSteven Whitehouse }
132f057f6cdSSteven Whitehouse #endif /* CONFIG_GFS2_FS_LOCKING_DLM */
133f057f6cdSSteven Whitehouse 
134b3b94faaSDavid Teigland #endif /* __INODE_DOT_H__ */
135b3b94faaSDavid Teigland 
136