xref: /openbmc/linux/fs/efs/efs.h (revision 02d89917)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 1999 Al Smith, <Al.Smith@aeschi.ch.eu.org>
4  *
5  * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
6  * Portions derived from IRIX header files (c) 1988 Silicon Graphics
7  */
8 #ifndef _EFS_EFS_H_
9 #define _EFS_EFS_H_
10 
11 #ifdef pr_fmt
12 #undef pr_fmt
13 #endif
14 
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 
17 #include <linux/fs.h>
18 #include <linux/uaccess.h>
19 
20 #define EFS_VERSION "1.0a"
21 
22 /* 1 block is 512 bytes */
23 #define	EFS_BLOCKSIZE_BITS	9
24 #define	EFS_BLOCKSIZE		(1 << EFS_BLOCKSIZE_BITS)
25 
26 typedef	int32_t		efs_block_t;
27 typedef uint32_t	efs_ino_t;
28 
29 #define	EFS_DIRECTEXTENTS	12
30 
31 /*
32  * layout of an extent, in memory and on disk. 8 bytes exactly.
33  */
34 typedef union extent_u {
35 	unsigned char raw[8];
36 	struct extent_s {
37 		unsigned int	ex_magic:8;	/* magic # (zero) */
38 		unsigned int	ex_bn:24;	/* basic block */
39 		unsigned int	ex_length:8;	/* numblocks in this extent */
40 		unsigned int	ex_offset:24;	/* logical offset into file */
41 	} cooked;
42 } efs_extent;
43 
44 typedef struct edevs {
45 	__be16		odev;
46 	__be32		ndev;
47 } efs_devs;
48 
49 /*
50  * extent based filesystem inode as it appears on disk.  The efs inode
51  * is exactly 128 bytes long.
52  */
53 struct	efs_dinode {
54 	__be16		di_mode;	/* mode and type of file */
55 	__be16		di_nlink;	/* number of links to file */
56 	__be16		di_uid;		/* owner's user id */
57 	__be16		di_gid;		/* owner's group id */
58 	__be32		di_size;	/* number of bytes in file */
59 	__be32		di_atime;	/* time last accessed */
60 	__be32		di_mtime;	/* time last modified */
61 	__be32		di_ctime;	/* time created */
62 	__be32		di_gen;		/* generation number */
63 	__be16		di_numextents;	/* # of extents */
64 	u_char		di_version;	/* version of inode */
65 	u_char		di_spare;	/* spare - used by AFS */
66 	union di_addr {
67 		efs_extent	di_extents[EFS_DIRECTEXTENTS];
68 		efs_devs	di_dev;	/* device for IFCHR/IFBLK */
69 	} di_u;
70 };
71 
72 /* efs inode storage in memory */
73 struct efs_inode_info {
74 	int		numextents;
75 	int		lastextent;
76 
77 	efs_extent	extents[EFS_DIRECTEXTENTS];
78 	struct inode	vfs_inode;
79 };
80 
81 #include <linux/efs_fs_sb.h>
82 
83 #define EFS_DIRBSIZE_BITS	EFS_BLOCKSIZE_BITS
84 #define EFS_DIRBSIZE		(1 << EFS_DIRBSIZE_BITS)
85 
86 struct efs_dentry {
87 	__be32		inode;
88 	unsigned char	namelen;
89 	char		name[3];
90 };
91 
92 #define EFS_DENTSIZE	(sizeof(struct efs_dentry) - 3 + 1)
93 #define EFS_MAXNAMELEN  ((1 << (sizeof(char) * 8)) - 1)
94 
95 #define EFS_DIRBLK_HEADERSIZE	4
96 #define EFS_DIRBLK_MAGIC	0xbeef	/* moo */
97 
98 struct efs_dir {
99 	__be16	magic;
100 	unsigned char	firstused;
101 	unsigned char	slots;
102 
103 	unsigned char	space[EFS_DIRBSIZE - EFS_DIRBLK_HEADERSIZE];
104 };
105 
106 #define EFS_MAXENTS \
107 	((EFS_DIRBSIZE - EFS_DIRBLK_HEADERSIZE) / \
108 	 (EFS_DENTSIZE + sizeof(char)))
109 
110 #define EFS_SLOTAT(dir, slot) EFS_REALOFF((dir)->space[slot])
111 
112 #define EFS_REALOFF(offset) ((offset << 1))
113 
114 
115 static inline struct efs_inode_info *INODE_INFO(struct inode *inode)
116 {
117 	return container_of(inode, struct efs_inode_info, vfs_inode);
118 }
119 
120 static inline struct efs_sb_info *SUPER_INFO(struct super_block *sb)
121 {
122 	return sb->s_fs_info;
123 }
124 
125 struct statfs;
126 struct fid;
127 
128 extern const struct inode_operations efs_dir_inode_operations;
129 extern const struct file_operations efs_dir_operations;
130 extern const struct address_space_operations efs_symlink_aops;
131 
132 extern struct inode *efs_iget(struct super_block *, unsigned long);
133 extern efs_block_t efs_map_block(struct inode *, efs_block_t);
134 extern int efs_get_block(struct inode *, sector_t, struct buffer_head *, int);
135 
136 extern struct dentry *efs_lookup(struct inode *, struct dentry *, unsigned int);
137 extern struct dentry *efs_fh_to_dentry(struct super_block *sb, struct fid *fid,
138 		int fh_len, int fh_type);
139 extern struct dentry *efs_fh_to_parent(struct super_block *sb, struct fid *fid,
140 		int fh_len, int fh_type);
141 extern struct dentry *efs_get_parent(struct dentry *);
142 extern int efs_bmap(struct inode *, int);
143 
144 #endif /* _EFS_EFS_H_ */
145