File Index
Files and directories
Sign in
FILE

hfs_fs.h

File preview with syntax highlighting.

linux-6.19.14/fs/hfs/hfs_fs.h C
  1/*
  2 *  linux/fs/hfs/hfs_fs.h
  3 *
  4 * Copyright (C) 1995-1997  Paul H. Hargrove
  5 * (C) 2003 Ardis Technologies <roman@ardistech.com>
  6 * This file may be distributed under the terms of the GNU General Public License.
  7 */
  8
  9#ifndef _LINUX_HFS_FS_H
 10#define _LINUX_HFS_FS_H
 11
 12#include <linux/slab.h>
 13#include <linux/types.h>
 14#include <linux/mutex.h>
 15#include <linux/buffer_head.h>
 16#include <linux/fs.h>
 17#include <linux/workqueue.h>
 18
 19#include <asm/byteorder.h>
 20#include <linux/uaccess.h>
 21
 22#include "hfs.h"
 23
 24/*
 25 * struct hfs_inode_info
 26 *
 27 * The HFS-specific part of a Linux (struct inode)
 28 */
 29struct hfs_inode_info {
 30	atomic_t opencnt;
 31
 32	unsigned int flags;
 33
 34	/* to deal with localtime ugliness */
 35	int tz_secondswest;
 36
 37	struct hfs_cat_key cat_key;
 38
 39	struct list_head open_dir_list;
 40	spinlock_t open_dir_lock;
 41	struct inode *rsrc_inode;
 42
 43	struct mutex extents_lock;
 44
 45	u16 alloc_blocks, clump_blocks;
 46	sector_t fs_blocks;
 47	/* Allocation extents from catlog record or volume header */
 48	hfs_extent_rec first_extents;
 49	u16 first_blocks;
 50	hfs_extent_rec cached_extents;
 51	u16 cached_start, cached_blocks;
 52
 53	loff_t phys_size;
 54	struct inode vfs_inode;
 55};
 56
 57#define HFS_FLG_RSRC		0x0001
 58#define HFS_FLG_EXT_DIRTY	0x0002
 59#define HFS_FLG_EXT_NEW		0x0004
 60
 61#define HFS_IS_RSRC(inode)	(HFS_I(inode)->flags & HFS_FLG_RSRC)
 62
 63/*
 64 * struct hfs_sb_info
 65 *
 66 * The HFS-specific part of a Linux (struct super_block)
 67 */
 68struct hfs_sb_info {
 69	struct buffer_head *mdb_bh;		/* The hfs_buffer
 70						   holding the real
 71						   superblock (aka VIB
 72						   or MDB) */
 73	struct hfs_mdb *mdb;
 74	struct buffer_head *alt_mdb_bh;		/* The hfs_buffer holding
 75						   the alternate superblock */
 76	struct hfs_mdb *alt_mdb;
 77	__be32 *bitmap;				/* The page holding the
 78						   allocation bitmap */
 79	struct hfs_btree *ext_tree;			/* Information about
 80						   the extents b-tree */
 81	struct hfs_btree *cat_tree;			/* Information about
 82						   the catalog b-tree */
 83	atomic64_t file_count;			/* The number of
 84						   regular files in
 85						   the filesystem */
 86	atomic64_t folder_count;		/* The number of
 87						   directories in the
 88						   filesystem */
 89	atomic64_t next_id;			/* The next available
 90						   file id number */
 91	u32 clumpablks;				/* The number of allocation
 92						   blocks to try to add when
 93						   extending a file */
 94	u32 fs_start;				/* The first 512-byte
 95						   block represented
 96						   in the bitmap */
 97	u32 part_start;
 98	u16 root_files;				/* The number of
 99						   regular
100						   (non-directory)
101						   files in the root
102						   directory */
103	u16 root_dirs;				/* The number of
104						   directories in the
105						   root directory */
106	u16 fs_ablocks;				/* The number of
107						   allocation blocks
108						   in the filesystem */
109	u16 free_ablocks;			/* the number of unused
110						   allocation blocks
111						   in the filesystem */
112	u32 alloc_blksz;			/* The size of an
113						   "allocation block" */
114	int s_quiet;				/* Silent failure when
115						   changing owner or mode? */
116	__be32 s_type;				/* Type for new files */
117	__be32 s_creator;			/* Creator for new files */
118	umode_t s_file_umask;			/* The umask applied to the
119						   permissions on all files */
120	umode_t s_dir_umask;			/* The umask applied to the
121						   permissions on all dirs */
122	kuid_t s_uid;				/* The uid of all files */
123	kgid_t s_gid;				/* The gid of all files */
124
125	int session, part;
126	struct nls_table *nls_io, *nls_disk;
127	struct mutex bitmap_lock;
128	unsigned long flags;
129	u16 blockoffset;
130	int fs_div;
131	struct super_block *sb;
132	int work_queued;		/* non-zero delayed work is queued */
133	struct delayed_work mdb_work;	/* MDB flush delayed work */
134	spinlock_t work_lock;		/* protects mdb_work and work_queued */
135};
136
137#define HFS_FLG_BITMAP_DIRTY	0
138#define HFS_FLG_MDB_DIRTY	1
139#define HFS_FLG_ALT_MDB_DIRTY	2
140
141/* bitmap.c */
142extern u32 hfs_vbm_search_free(struct super_block *sb, u32 goal, u32 *num_bits);
143extern int hfs_clear_vbm_bits(struct super_block *sb, u16 start, u16 count);
144
145/* catalog.c */
146extern int hfs_cat_keycmp(const btree_key *key1, const btree_key *key2);
147struct hfs_find_data;
148extern int hfs_cat_find_brec(struct super_block *sb, u32 cnid,
149			     struct hfs_find_data *fd);
150extern int hfs_cat_create(u32 cnid, struct inode *dir,
151			  const struct qstr *str, struct inode *inode);
152extern int hfs_cat_delete(u32 cnid, struct inode *dir, const struct qstr *str);
153extern int hfs_cat_move(u32 cnid, struct inode *src_dir,
154			const struct qstr *src_name,
155			struct inode *dst_dir,
156			const struct qstr *dst_name);
157extern void hfs_cat_build_key(struct super_block *sb, btree_key *key,
158			      u32 parent, const struct qstr *name);
159
160/* dir.c */
161extern const struct file_operations hfs_dir_operations;
162extern const struct inode_operations hfs_dir_inode_operations;
163
164/* extent.c */
165extern int hfs_ext_keycmp(const btree_key *key1, const btree_key *key2);
166extern u16 hfs_ext_find_block(struct hfs_extent *ext, u16 off);
167extern int hfs_free_fork(struct super_block *sb,
168			 struct hfs_cat_file *file, int type);
169extern int hfs_ext_write_extent(struct inode *inode);
170extern int hfs_extend_file(struct inode *inode);
171extern void hfs_file_truncate(struct inode *inode);
172
173extern int hfs_get_block(struct inode *inode, sector_t block,
174			 struct buffer_head *bh_result, int create);
175
176/* inode.c */
177extern const struct address_space_operations hfs_aops;
178extern const struct address_space_operations hfs_btree_aops;
179
180int hfs_write_begin(const struct kiocb *iocb, struct address_space *mapping,
181		    loff_t pos, unsigned int len, struct folio **foliop,
182		    void **fsdata);
183extern struct inode *hfs_new_inode(struct inode *dir, const struct qstr *name,
184				   umode_t mode);
185extern void hfs_inode_write_fork(struct inode *inode, struct hfs_extent *ext,
186				 __be32 *log_size, __be32 *phys_size);
187extern int hfs_write_inode(struct inode *inode, struct writeback_control *wbc);
188extern int hfs_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
189			     struct iattr *attr);
190extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
191				__be32 __log_size, __be32 phys_size,
192				u32 clump_size);
193extern struct inode *hfs_iget(struct super_block *sb, struct hfs_cat_key *key,
194				hfs_cat_rec *rec);
195extern void hfs_evict_inode(struct inode *inode);
196extern void hfs_delete_inode(struct inode *inode);
197
198/* attr.c */
199extern const struct xattr_handler * const hfs_xattr_handlers[];
200
201/* mdb.c */
202extern bool is_hfs_cnid_counts_valid(struct super_block *sb);
203extern int hfs_mdb_get(struct super_block *sb);
204extern void hfs_mdb_commit(struct super_block *sb);
205extern void hfs_mdb_close(struct super_block *sb);
206extern void hfs_mdb_put(struct super_block *sb);
207
208/* part_tbl.c */
209extern int hfs_part_find(struct super_block *sb,
210			 sector_t *part_start, sector_t *part_size);
211
212/* string.c */
213extern const struct dentry_operations hfs_dentry_operations;
214
215extern int hfs_hash_dentry(const struct dentry *dentry, struct qstr *this);
216extern int hfs_strcmp(const unsigned char *s1, unsigned int len1,
217		      const unsigned char *s2, unsigned int len2);
218extern int hfs_compare_dentry(const struct dentry *dentry,
219				unsigned int len, const char *str,
220				const struct qstr *name);
221
222/* trans.c */
223extern void hfs_asc2mac(struct super_block *sb,
224			struct hfs_name *out, const struct qstr *in);
225extern int hfs_mac2asc(struct super_block *sb,
226			char *out, const struct hfs_name *in);
227
228/* super.c */
229extern void hfs_mark_mdb_dirty(struct super_block *sb);
230
231/*
232 * There are two time systems.  Both are based on seconds since
233 * a particular time/date.
234 *	Unix:	signed little-endian since 00:00 GMT, Jan. 1, 1970
235 *	mac:	unsigned big-endian since 00:00 GMT, Jan. 1, 1904
236 *
237 * HFS implementations are highly inconsistent, this one matches the
238 * traditional behavior of 64-bit Linux, giving the most useful
239 * time range between 1970 and 2106, by treating any on-disk timestamp
240 * under HFS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
241 */
242#define HFS_UTC_OFFSET 2082844800U
243
244static inline time64_t __hfs_m_to_utime(__be32 mt)
245{
246	time64_t ut = (u32)(be32_to_cpu(mt) - HFS_UTC_OFFSET);
247
248	return ut + sys_tz.tz_minuteswest * 60;
249}
250
251static inline __be32 __hfs_u_to_mtime(time64_t ut)
252{
253	ut -= sys_tz.tz_minuteswest * 60;
254
255	return cpu_to_be32(lower_32_bits(ut) + HFS_UTC_OFFSET);
256}
257#define HFS_I(inode)	(container_of(inode, struct hfs_inode_info, vfs_inode))
258#define HFS_SB(sb)	((struct hfs_sb_info *)(sb)->s_fs_info)
259
260#define hfs_m_to_utime(time)   (struct timespec64){ .tv_sec = __hfs_m_to_utime(time) }
261#define hfs_u_to_mtime(time)   __hfs_u_to_mtime((time).tv_sec)
262#define hfs_mtime()		__hfs_u_to_mtime(ktime_get_real_seconds())
263
264static inline const char *hfs_mdb_name(struct super_block *sb)
265{
266	return sb->s_id;
267}
268
269static inline void hfs_bitmap_dirty(struct super_block *sb)
270{
271	set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags);
272	hfs_mark_mdb_dirty(sb);
273}
274
275#define sb_bread512(sb, sec, data) ({			\
276	struct buffer_head *__bh;			\
277	sector_t __block;				\
278	loff_t __start;					\
279	int __offset;					\
280							\
281	__start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\
282	__block = __start >> (sb)->s_blocksize_bits;	\
283	__offset = __start & ((sb)->s_blocksize - 1);	\
284	__bh = sb_bread((sb), __block);			\
285	if (likely(__bh != NULL))			\
286		data = (void *)(__bh->b_data + __offset);\
287	else						\
288		data = NULL;				\
289	__bh;						\
290})
291
292#endif
~/ Read-only file preview.