xref: /openbmc/linux/fs/xfs/libxfs/xfs_inode_buf.h (revision 0bf49ffb)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef	__XFS_INODE_BUF_H__
7 #define	__XFS_INODE_BUF_H__
8 
9 struct xfs_inode;
10 struct xfs_dinode;
11 
12 /*
13  * In memory representation of the XFS inode. This is held in the in-core struct
14  * xfs_inode and represents the current on disk values but the structure is not
15  * in on-disk format.  That is, this structure is always translated to on-disk
16  * format specific structures at the appropriate time.
17  */
18 struct xfs_icdinode {
19 	uint16_t	di_flushiter;	/* incremented on flush */
20 	prid_t		di_projid;	/* owner's project id */
21 	xfs_fsize_t	di_size;	/* number of bytes in file */
22 	xfs_rfsblock_t	di_nblocks;	/* # of direct & btree blocks used */
23 	xfs_extlen_t	di_extsize;	/* basic/minimum extent size for file */
24 	uint8_t		di_forkoff;	/* attr fork offs, <<3 for 64b align */
25 	uint32_t	di_dmevmask;	/* DMIG event mask */
26 	uint16_t	di_dmstate;	/* DMIG state info */
27 	uint16_t	di_flags;	/* random flags, XFS_DIFLAG_... */
28 
29 	uint64_t	di_flags2;	/* more random flags */
30 	uint32_t	di_cowextsize;	/* basic cow extent size for file */
31 
32 	struct timespec64 di_crtime;	/* time created */
33 };
34 
35 static inline bool xfs_icdinode_has_bigtime(const struct xfs_icdinode *icd)
36 {
37 	return icd->di_flags2 & XFS_DIFLAG2_BIGTIME;
38 }
39 
40 /*
41  * Inode location information.  Stored in the inode and passed to
42  * xfs_imap_to_bp() to get a buffer and dinode for a given inode.
43  */
44 struct xfs_imap {
45 	xfs_daddr_t	im_blkno;	/* starting BB of inode chunk */
46 	unsigned short	im_len;		/* length in BBs of inode chunk */
47 	unsigned short	im_boffset;	/* inode offset in block in bytes */
48 };
49 
50 int	xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *,
51 		       struct xfs_imap *, struct xfs_dinode **,
52 		       struct xfs_buf **, uint);
53 void	xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);
54 void	xfs_inode_to_disk(struct xfs_inode *ip, struct xfs_dinode *to,
55 			  xfs_lsn_t lsn);
56 int	xfs_inode_from_disk(struct xfs_inode *ip, struct xfs_dinode *from);
57 
58 xfs_failaddr_t xfs_dinode_verify(struct xfs_mount *mp, xfs_ino_t ino,
59 			   struct xfs_dinode *dip);
60 xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp,
61 		uint32_t extsize, uint16_t mode, uint16_t flags);
62 xfs_failaddr_t xfs_inode_validate_cowextsize(struct xfs_mount *mp,
63 		uint32_t cowextsize, uint16_t mode, uint16_t flags,
64 		uint64_t flags2);
65 
66 static inline uint64_t xfs_inode_encode_bigtime(struct timespec64 tv)
67 {
68 	return xfs_unix_to_bigtime(tv.tv_sec) * NSEC_PER_SEC + tv.tv_nsec;
69 }
70 
71 struct timespec64 xfs_inode_from_disk_ts(struct xfs_dinode *dip,
72 		const xfs_timestamp_t ts);
73 
74 #endif	/* __XFS_INODE_BUF_H__ */
75