| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* |
| 3 |
* linux/include/linux/hfsplus_fs.h |
| 4 |
* |
| 5 |
* Copyright (C) 1999 |
| 6 |
* Brad Boyer ([email protected]) |
| 7 |
* (C) 2003 Ardis Technologies <[email protected]> |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef _LINUX_HFSPLUS_FS_H |
| 12 |
#define _LINUX_HFSPLUS_FS_H |
| 13 |
|
| 14 |
#include <linux/fs.h> |
| 15 |
#include <linux/mutex.h> |
| 16 |
#include <linux/buffer_head.h> |
| 17 |
#include <linux/blkdev.h> |
| 18 |
#include <linux/fs_context.h> |
| 19 |
#include "hfsplus_raw.h" |
| 20 |
|
| 21 |
/* Runtime config options */ |
| 22 |
#define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */ |
| 23 |
|
| 24 |
#define HFSPLUS_TYPE_DATA 0x00 |
| 25 |
#define HFSPLUS_TYPE_RSRC 0xFF |
| 26 |
|
| 27 |
typedef int (*btree_keycmp)(const hfsplus_btree_key *, |
| 28 |
const hfsplus_btree_key *); |
| 29 |
|
| 30 |
#define NODE_HASH_SIZE 256 |
| 31 |
|
| 32 |
/* B-tree mutex nested subclasses */ |
| 33 |
enum hfsplus_btree_mutex_classes { |
| 34 |
CATALOG_BTREE_MUTEX, |
| 35 |
EXTENTS_BTREE_MUTEX, |
| 36 |
ATTR_BTREE_MUTEX, |
| 37 |
}; |
| 38 |
|
| 39 |
/* An HFS+ BTree held in memory */ |
| 40 |
struct hfs_btree { |
| 41 |
struct super_block *sb; |
| 42 |
struct inode *inode; |
| 43 |
btree_keycmp keycmp; |
| 44 |
|
| 45 |
u32 cnid; |
| 46 |
u32 root; |
| 47 |
u32 leaf_count; |
| 48 |
u32 leaf_head; |
| 49 |
u32 leaf_tail; |
| 50 |
u32 node_count; |
| 51 |
u32 free_nodes; |
| 52 |
u32 attributes; |
| 53 |
|
| 54 |
unsigned int node_size; |
| 55 |
unsigned int node_size_shift; |
| 56 |
unsigned int max_key_len; |
| 57 |
unsigned int depth; |
| 58 |
|
| 59 |
struct mutex tree_lock; |
| 60 |
|
| 61 |
unsigned int pages_per_bnode; |
| 62 |
spinlock_t hash_lock; |
| 63 |
struct hfs_bnode *node_hash[NODE_HASH_SIZE]; |
| 64 |
int node_hash_cnt; |
| 65 |
}; |
| 66 |
|
| 67 |
struct page; |
| 68 |
|
| 69 |
/* An HFS+ BTree node in memory */ |
| 70 |
struct hfs_bnode { |
| 71 |
struct hfs_btree *tree; |
| 72 |
|
| 73 |
u32 prev; |
| 74 |
u32 this; |
| 75 |
u32 next; |
| 76 |
u32 parent; |
| 77 |
|
| 78 |
u16 num_recs; |
| 79 |
u8 type; |
| 80 |
u8 height; |
| 81 |
|
| 82 |
struct hfs_bnode *next_hash; |
| 83 |
unsigned long flags; |
| 84 |
wait_queue_head_t lock_wq; |
| 85 |
atomic_t refcnt; |
| 86 |
unsigned int page_offset; |
| 87 |
struct page *page[]; |
| 88 |
}; |
| 89 |
|
| 90 |
#define HFS_BNODE_LOCK 0 |
| 91 |
#define HFS_BNODE_ERROR 1 |
| 92 |
#define HFS_BNODE_NEW 2 |
| 93 |
#define HFS_BNODE_DIRTY 3 |
| 94 |
#define HFS_BNODE_DELETED 4 |
| 95 |
|
| 96 |
/* |
| 97 |
* Attributes file states |
| 98 |
*/ |
| 99 |
#define HFSPLUS_EMPTY_ATTR_TREE 0 |
| 100 |
#define HFSPLUS_CREATING_ATTR_TREE 1 |
| 101 |
#define HFSPLUS_VALID_ATTR_TREE 2 |
| 102 |
#define HFSPLUS_FAILED_ATTR_TREE 3 |
| 103 |
|
| 104 |
/* |
| 105 |
* HFS+ superblock info (built from Volume Header on disk) |
| 106 |
*/ |
| 107 |
|
| 108 |
struct hfsplus_vh; |
| 109 |
struct hfs_btree; |
| 110 |
|
| 111 |
struct hfsplus_sb_info { |
| 112 |
void *s_vhdr_buf; |
| 113 |
struct hfsplus_vh *s_vhdr; |
| 114 |
void *s_backup_vhdr_buf; |
| 115 |
struct hfsplus_vh *s_backup_vhdr; |
| 116 |
struct hfs_btree *ext_tree; |
| 117 |
struct hfs_btree *cat_tree; |
| 118 |
struct hfs_btree *attr_tree; |
| 119 |
atomic_t attr_tree_state; |
| 120 |
struct inode *alloc_file; |
| 121 |
struct inode *hidden_dir; |
| 122 |
struct nls_table *nls; |
| 123 |
|
| 124 |
/* Runtime variables */ |
| 125 |
u32 blockoffset; |
| 126 |
u32 min_io_size; |
| 127 |
sector_t part_start; |
| 128 |
sector_t sect_count; |
| 129 |
int fs_shift; |
| 130 |
|
| 131 |
/* immutable data from the volume header */ |
| 132 |
u32 alloc_blksz; |
| 133 |
int alloc_blksz_shift; |
| 134 |
u32 total_blocks; |
| 135 |
u32 data_clump_blocks, rsrc_clump_blocks; |
| 136 |
|
| 137 |
/* mutable data from the volume header, protected by alloc_mutex */ |
| 138 |
u32 free_blocks; |
| 139 |
struct mutex alloc_mutex; |
| 140 |
|
| 141 |
/* mutable data from the volume header, protected by vh_mutex */ |
| 142 |
u32 next_cnid; |
| 143 |
u32 file_count; |
| 144 |
u32 folder_count; |
| 145 |
struct mutex vh_mutex; |
| 146 |
|
| 147 |
/* Config options */ |
| 148 |
u32 creator; |
| 149 |
u32 type; |
| 150 |
|
| 151 |
umode_t umask; |
| 152 |
kuid_t uid; |
| 153 |
kgid_t gid; |
| 154 |
|
| 155 |
int part, session; |
| 156 |
unsigned long flags; |
| 157 |
|
| 158 |
int work_queued; /* non-zero delayed work is queued */ |
| 159 |
struct delayed_work sync_work; /* FS sync delayed work */ |
| 160 |
spinlock_t work_lock; /* protects sync_work and work_queued */ |
| 161 |
struct rcu_head rcu; |
| 162 |
}; |
| 163 |
|
| 164 |
#define HFSPLUS_SB_WRITEBACKUP 0 |
| 165 |
#define HFSPLUS_SB_NODECOMPOSE 1 |
| 166 |
#define HFSPLUS_SB_FORCE 2 |
| 167 |
#define HFSPLUS_SB_HFSX 3 |
| 168 |
#define HFSPLUS_SB_CASEFOLD 4 |
| 169 |
#define HFSPLUS_SB_NOBARRIER 5 |
| 170 |
#define HFSPLUS_SB_UID 6 |
| 171 |
#define HFSPLUS_SB_GID 7 |
| 172 |
|
| 173 |
static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb) |
| 174 |
{ |
| 175 |
return sb->s_fs_info; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
struct hfsplus_inode_info { |
| 180 |
atomic_t opencnt; |
| 181 |
|
| 182 |
/* |
| 183 |
* Extent allocation information, protected by extents_lock. |
| 184 |
*/ |
| 185 |
u32 first_blocks; |
| 186 |
u32 clump_blocks; |
| 187 |
u32 alloc_blocks; |
| 188 |
u32 cached_start; |
| 189 |
u32 cached_blocks; |
| 190 |
hfsplus_extent_rec first_extents; |
| 191 |
hfsplus_extent_rec cached_extents; |
| 192 |
unsigned int extent_state; |
| 193 |
struct mutex extents_lock; |
| 194 |
|
| 195 |
/* |
| 196 |
* Immutable data. |
| 197 |
*/ |
| 198 |
struct inode *rsrc_inode; |
| 199 |
__be32 create_date; |
| 200 |
|
| 201 |
/* |
| 202 |
* Protected by sbi->vh_mutex. |
| 203 |
*/ |
| 204 |
u32 linkid; |
| 205 |
|
| 206 |
/* |
| 207 |
* Accessed using atomic bitops. |
| 208 |
*/ |
| 209 |
unsigned long flags; |
| 210 |
|
| 211 |
/* |
| 212 |
* Protected by i_mutex. |
| 213 |
*/ |
| 214 |
sector_t fs_blocks; |
| 215 |
u8 userflags; /* BSD user file flags */ |
| 216 |
u32 subfolders; /* Subfolder count (HFSX only) */ |
| 217 |
struct list_head open_dir_list; |
| 218 |
spinlock_t open_dir_lock; |
| 219 |
loff_t phys_size; |
| 220 |
|
| 221 |
struct inode vfs_inode; |
| 222 |
}; |
| 223 |
|
| 224 |
#define HFSPLUS_EXT_DIRTY 0x0001 |
| 225 |
#define HFSPLUS_EXT_NEW 0x0002 |
| 226 |
|
| 227 |
#define HFSPLUS_I_RSRC 0 /* represents a resource fork */ |
| 228 |
#define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */ |
| 229 |
#define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */ |
| 230 |
#define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */ |
| 231 |
#define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */ |
| 232 |
|
| 233 |
#define HFSPLUS_IS_RSRC(inode) \ |
| 234 |
test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags) |
| 235 |
|
| 236 |
static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode) |
| 237 |
{ |
| 238 |
return container_of(inode, struct hfsplus_inode_info, vfs_inode); |
| 239 |
} |
| 240 |
|
| 241 |
/* |
| 242 |
* Mark an inode dirty, and also mark the btree in which the |
| 243 |
* specific type of metadata is stored. |
| 244 |
* For data or metadata that gets written back by into the catalog btree |
| 245 |
* by hfsplus_write_inode a plain mark_inode_dirty call is enough. |
| 246 |
*/ |
| 247 |
static inline void hfsplus_mark_inode_dirty(struct inode *inode, |
| 248 |
unsigned int flag) |
| 249 |
{ |
| 250 |
set_bit(flag, &HFSPLUS_I(inode)->flags); |
| 251 |
mark_inode_dirty(inode); |
| 252 |
} |
| 253 |
|
| 254 |
struct hfs_find_data { |
| 255 |
/* filled by caller */ |
| 256 |
hfsplus_btree_key *search_key; |
| 257 |
hfsplus_btree_key *key; |
| 258 |
/* filled by find */ |
| 259 |
struct hfs_btree *tree; |
| 260 |
struct hfs_bnode *bnode; |
| 261 |
/* filled by findrec */ |
| 262 |
int record; |
| 263 |
int keyoffset, keylength; |
| 264 |
int entryoffset, entrylength; |
| 265 |
}; |
| 266 |
|
| 267 |
struct hfsplus_readdir_data { |
| 268 |
struct list_head list; |
| 269 |
struct file *file; |
| 270 |
struct hfsplus_cat_key key; |
| 271 |
}; |
| 272 |
|
| 273 |
/* |
| 274 |
* Find minimum acceptible I/O size for an hfsplus sb. |
| 275 |
*/ |
| 276 |
static inline unsigned short hfsplus_min_io_size(struct super_block *sb) |
| 277 |
{ |
| 278 |
return max_t(unsigned short, HFSPLUS_SB(sb)->min_io_size, |
| 279 |
HFSPLUS_SECTOR_SIZE); |
| 280 |
} |
| 281 |
|
| 282 |
#define hfs_btree_open hfsplus_btree_open |
| 283 |
#define hfs_btree_close hfsplus_btree_close |
| 284 |
#define hfs_btree_write hfsplus_btree_write |
| 285 |
#define hfs_bmap_reserve hfsplus_bmap_reserve |
| 286 |
#define hfs_bmap_alloc hfsplus_bmap_alloc |
| 287 |
#define hfs_bmap_free hfsplus_bmap_free |
| 288 |
#define hfs_bnode_read hfsplus_bnode_read |
| 289 |
#define hfs_bnode_read_u16 hfsplus_bnode_read_u16 |
| 290 |
#define hfs_bnode_read_u8 hfsplus_bnode_read_u8 |
| 291 |
#define hfs_bnode_read_key hfsplus_bnode_read_key |
| 292 |
#define hfs_bnode_write hfsplus_bnode_write |
| 293 |
#define hfs_bnode_write_u16 hfsplus_bnode_write_u16 |
| 294 |
#define hfs_bnode_clear hfsplus_bnode_clear |
| 295 |
#define hfs_bnode_copy hfsplus_bnode_copy |
| 296 |
#define hfs_bnode_move hfsplus_bnode_move |
| 297 |
#define hfs_bnode_dump hfsplus_bnode_dump |
| 298 |
#define hfs_bnode_unlink hfsplus_bnode_unlink |
| 299 |
#define hfs_bnode_findhash hfsplus_bnode_findhash |
| 300 |
#define hfs_bnode_find hfsplus_bnode_find |
| 301 |
#define hfs_bnode_unhash hfsplus_bnode_unhash |
| 302 |
#define hfs_bnode_free hfsplus_bnode_free |
| 303 |
#define hfs_bnode_create hfsplus_bnode_create |
| 304 |
#define hfs_bnode_get hfsplus_bnode_get |
| 305 |
#define hfs_bnode_put hfsplus_bnode_put |
| 306 |
#define hfs_brec_lenoff hfsplus_brec_lenoff |
| 307 |
#define hfs_brec_keylen hfsplus_brec_keylen |
| 308 |
#define hfs_brec_insert hfsplus_brec_insert |
| 309 |
#define hfs_brec_remove hfsplus_brec_remove |
| 310 |
#define hfs_find_init hfsplus_find_init |
| 311 |
#define hfs_find_exit hfsplus_find_exit |
| 312 |
#define __hfs_brec_find __hfsplus_brec_find |
| 313 |
#define hfs_brec_find hfsplus_brec_find |
| 314 |
#define hfs_brec_read hfsplus_brec_read |
| 315 |
#define hfs_brec_goto hfsplus_brec_goto |
| 316 |
#define hfs_part_find hfsplus_part_find |
| 317 |
|
| 318 |
/* |
| 319 |
* hfs+-specific ioctl for making the filesystem bootable |
| 320 |
*/ |
| 321 |
#define HFSPLUS_IOC_BLESS _IO('h', 0x80) |
| 322 |
|
| 323 |
typedef int (*search_strategy_t)(struct hfs_bnode *, |
| 324 |
struct hfs_find_data *, |
| 325 |
int *, int *, int *); |
| 326 |
|
| 327 |
/* |
| 328 |
* Functions in any *.c used in other files |
| 329 |
*/ |
| 330 |
|
| 331 |
/* attributes.c */ |
| 332 |
int __init hfsplus_create_attr_tree_cache(void); |
| 333 |
void hfsplus_destroy_attr_tree_cache(void); |
| 334 |
int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1, |
| 335 |
const hfsplus_btree_key *k2); |
| 336 |
int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key, |
| 337 |
u32 cnid, const char *name); |
| 338 |
hfsplus_attr_entry *hfsplus_alloc_attr_entry(void); |
| 339 |
void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry); |
| 340 |
int hfsplus_find_attr(struct super_block *sb, u32 cnid, const char *name, |
| 341 |
struct hfs_find_data *fd); |
| 342 |
int hfsplus_attr_exists(struct inode *inode, const char *name); |
| 343 |
int hfsplus_create_attr(struct inode *inode, const char *name, |
| 344 |
const void *value, size_t size); |
| 345 |
int hfsplus_delete_attr(struct inode *inode, const char *name); |
| 346 |
int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid); |
| 347 |
int hfsplus_replace_attr(struct inode *inode, |
| 348 |
const char *name, |
| 349 |
const void *value, size_t size); |
| 350 |
|
| 351 |
/* bitmap.c */ |
| 352 |
int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, |
| 353 |
u32 *max); |
| 354 |
int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count); |
| 355 |
|
| 356 |
/* btree.c */ |
| 357 |
u32 hfsplus_calc_btree_clump_size(u32 block_size, u32 node_size, u64 sectors, |
| 358 |
int file_id); |
| 359 |
struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id); |
| 360 |
void hfs_btree_close(struct hfs_btree *tree); |
| 361 |
int hfs_btree_write(struct hfs_btree *tree); |
| 362 |
int hfs_bmap_reserve(struct hfs_btree *tree, u32 rsvd_nodes); |
| 363 |
struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree); |
| 364 |
void hfs_bmap_free(struct hfs_bnode *node); |
| 365 |
|
| 366 |
/* bnode.c */ |
| 367 |
void hfs_bnode_read(struct hfs_bnode *node, void *buf, u32 off, u32 len); |
| 368 |
u16 hfs_bnode_read_u16(struct hfs_bnode *node, u32 off); |
| 369 |
u8 hfs_bnode_read_u8(struct hfs_bnode *node, u32 off); |
| 370 |
void hfs_bnode_read_key(struct hfs_bnode *node, void *key, u32 off); |
| 371 |
void hfs_bnode_write(struct hfs_bnode *node, void *buf, u32 off, u32 len); |
| 372 |
void hfs_bnode_write_u16(struct hfs_bnode *node, u32 off, u16 data); |
| 373 |
void hfs_bnode_clear(struct hfs_bnode *node, u32 off, u32 len); |
| 374 |
void hfs_bnode_copy(struct hfs_bnode *dst_node, u32 dst, |
| 375 |
struct hfs_bnode *src_node, u32 src, u32 len); |
| 376 |
void hfs_bnode_move(struct hfs_bnode *node, u32 dst, u32 src, u32 len); |
| 377 |
void hfs_bnode_dump(struct hfs_bnode *node); |
| 378 |
void hfs_bnode_unlink(struct hfs_bnode *node); |
| 379 |
struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *tree, u32 cnid); |
| 380 |
void hfs_bnode_unhash(struct hfs_bnode *node); |
| 381 |
struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num); |
| 382 |
void hfs_bnode_free(struct hfs_bnode *node); |
| 383 |
struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num); |
| 384 |
void hfs_bnode_get(struct hfs_bnode *node); |
| 385 |
void hfs_bnode_put(struct hfs_bnode *node); |
| 386 |
bool hfs_bnode_need_zeroout(struct hfs_btree *tree); |
| 387 |
|
| 388 |
/* brec.c */ |
| 389 |
u16 hfs_brec_lenoff(struct hfs_bnode *node, u16 rec, u16 *off); |
| 390 |
u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec); |
| 391 |
int hfs_brec_insert(struct hfs_find_data *fd, void *entry, u32 entry_len); |
| 392 |
int hfs_brec_remove(struct hfs_find_data *fd); |
| 393 |
|
| 394 |
/* bfind.c */ |
| 395 |
int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd); |
| 396 |
void hfs_find_exit(struct hfs_find_data *fd); |
| 397 |
int hfs_find_1st_rec_by_cnid(struct hfs_bnode *bnode, struct hfs_find_data *fd, |
| 398 |
int *begin, int *end, int *cur_rec); |
| 399 |
int hfs_find_rec_by_key(struct hfs_bnode *bnode, struct hfs_find_data *fd, |
| 400 |
int *begin, int *end, int *cur_rec); |
| 401 |
int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd, |
| 402 |
search_strategy_t rec_found); |
| 403 |
int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare); |
| 404 |
int hfs_brec_read(struct hfs_find_data *fd, void *rec, u32 rec_len); |
| 405 |
int hfs_brec_goto(struct hfs_find_data *fd, int cnt); |
| 406 |
|
| 407 |
/* catalog.c */ |
| 408 |
int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *k1, |
| 409 |
const hfsplus_btree_key *k2); |
| 410 |
int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *k1, |
| 411 |
const hfsplus_btree_key *k2); |
| 412 |
int hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *key, |
| 413 |
u32 parent, const struct qstr *str); |
| 414 |
void hfsplus_cat_build_key_with_cnid(struct super_block *sb, |
| 415 |
hfsplus_btree_key *key, u32 parent); |
| 416 |
void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms); |
| 417 |
int hfsplus_find_cat(struct super_block *sb, u32 cnid, |
| 418 |
struct hfs_find_data *fd); |
| 419 |
int hfsplus_create_cat(u32 cnid, struct inode *dir, const struct qstr *str, |
| 420 |
struct inode *inode); |
| 421 |
int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str); |
| 422 |
int hfsplus_rename_cat(u32 cnid, struct inode *src_dir, const struct qstr *src_name, |
| 423 |
struct inode *dst_dir, const struct qstr *dst_name); |
| 424 |
|
| 425 |
/* dir.c */ |
| 426 |
extern const struct inode_operations hfsplus_dir_inode_operations; |
| 427 |
extern const struct file_operations hfsplus_dir_operations; |
| 428 |
|
| 429 |
/* extents.c */ |
| 430 |
int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1, |
| 431 |
const hfsplus_btree_key *k2); |
| 432 |
int hfsplus_ext_write_extent(struct inode *inode); |
| 433 |
int hfsplus_get_block(struct inode *inode, sector_t iblock, |
| 434 |
struct buffer_head *bh_result, int create); |
| 435 |
int hfsplus_free_fork(struct super_block *sb, u32 cnid, |
| 436 |
struct hfsplus_fork_raw *fork, int type); |
| 437 |
int hfsplus_file_extend(struct inode *inode, bool zeroout); |
| 438 |
void hfsplus_file_truncate(struct inode *inode); |
| 439 |
|
| 440 |
/* inode.c */ |
| 441 |
extern const struct address_space_operations hfsplus_aops; |
| 442 |
extern const struct address_space_operations hfsplus_btree_aops; |
| 443 |
extern const struct dentry_operations hfsplus_dentry_operations; |
| 444 |
|
| 445 |
int hfsplus_write_begin(const struct kiocb *iocb, |
| 446 |
struct address_space *mapping, |
| 447 |
loff_t pos, unsigned len, struct folio **foliop, |
| 448 |
void **fsdata); |
| 449 |
struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir, |
| 450 |
umode_t mode); |
| 451 |
void hfsplus_delete_inode(struct inode *inode); |
| 452 |
void hfsplus_inode_read_fork(struct inode *inode, |
| 453 |
struct hfsplus_fork_raw *fork); |
| 454 |
void hfsplus_inode_write_fork(struct inode *inode, |
| 455 |
struct hfsplus_fork_raw *fork); |
| 456 |
int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd); |
| 457 |
int hfsplus_cat_write_inode(struct inode *inode); |
| 458 |
int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path, |
| 459 |
struct kstat *stat, u32 request_mask, |
| 460 |
unsigned int query_flags); |
| 461 |
int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, |
| 462 |
int datasync); |
| 463 |
int hfsplus_fileattr_get(struct dentry *dentry, struct file_kattr *fa); |
| 464 |
int hfsplus_fileattr_set(struct mnt_idmap *idmap, |
| 465 |
struct dentry *dentry, struct file_kattr *fa); |
| 466 |
|
| 467 |
/* ioctl.c */ |
| 468 |
long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); |
| 469 |
|
| 470 |
/* options.c */ |
| 471 |
void hfsplus_fill_defaults(struct hfsplus_sb_info *opts); |
| 472 |
int hfsplus_parse_param(struct fs_context *fc, struct fs_parameter *param); |
| 473 |
int hfsplus_show_options(struct seq_file *seq, struct dentry *root); |
| 474 |
|
| 475 |
/* part_tbl.c */ |
| 476 |
int hfs_part_find(struct super_block *sb, sector_t *part_start, |
| 477 |
sector_t *part_size); |
| 478 |
|
| 479 |
/* super.c */ |
| 480 |
struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino); |
| 481 |
void hfsplus_mark_mdb_dirty(struct super_block *sb); |
| 482 |
void hfsplus_prepare_volume_header_for_commit(struct hfsplus_vh *vhdr); |
| 483 |
int hfsplus_commit_superblock(struct super_block *sb); |
| 484 |
|
| 485 |
/* tables.c */ |
| 486 |
extern u16 hfsplus_case_fold_table[]; |
| 487 |
extern u16 hfsplus_decompose_table[]; |
| 488 |
extern u16 hfsplus_compose_table[]; |
| 489 |
|
| 490 |
/* unicode.c */ |
| 491 |
int hfsplus_strcasecmp(const struct hfsplus_unistr *s1, |
| 492 |
const struct hfsplus_unistr *s2); |
| 493 |
int hfsplus_strcmp(const struct hfsplus_unistr *s1, |
| 494 |
const struct hfsplus_unistr *s2); |
| 495 |
int hfsplus_uni2asc_str(struct super_block *sb, |
| 496 |
const struct hfsplus_unistr *ustr, char *astr, |
| 497 |
int *len_p); |
| 498 |
int hfsplus_uni2asc_xattr_str(struct super_block *sb, |
| 499 |
const struct hfsplus_attr_unistr *ustr, |
| 500 |
char *astr, int *len_p); |
| 501 |
int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr, |
| 502 |
int max_unistr_len, const char *astr, int len); |
| 503 |
int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str); |
| 504 |
int hfsplus_compare_dentry(const struct dentry *dentry, unsigned int len, |
| 505 |
const char *str, const struct qstr *name); |
| 506 |
|
| 507 |
/* wrapper.c */ |
| 508 |
int hfsplus_submit_bio(struct super_block *sb, sector_t sector, void *buf, |
| 509 |
void **data, blk_opf_t opf); |
| 510 |
int hfsplus_read_wrapper(struct super_block *sb); |
| 511 |
|
| 512 |
static inline u32 hfsplus_cat_thread_size(const struct hfsplus_cat_thread *thread) |
| 513 |
{ |
| 514 |
return offsetof(struct hfsplus_cat_thread, nodeName) + |
| 515 |
offsetof(struct hfsplus_unistr, unicode) + |
| 516 |
be16_to_cpu(thread->nodeName.length) * sizeof(hfsplus_unichr); |
| 517 |
} |
| 518 |
|
| 519 |
int hfsplus_brec_read_cat(struct hfs_find_data *fd, hfsplus_cat_entry *entry); |
| 520 |
|
| 521 |
/* |
| 522 |
* time helpers: convert between 1904-base and 1970-base timestamps |
| 523 |
* |
| 524 |
* HFS+ implementations are highly inconsistent, this one matches the |
| 525 |
* traditional behavior of 64-bit Linux, giving the most useful |
| 526 |
* time range between 1970 and 2106, by treating any on-disk timestamp |
| 527 |
* under HFSPLUS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106. |
| 528 |
*/ |
| 529 |
#define HFSPLUS_UTC_OFFSET 2082844800U |
| 530 |
|
| 531 |
static inline time64_t __hfsp_mt2ut(__be32 mt) |
| 532 |
{ |
| 533 |
time64_t ut = (u32)(be32_to_cpu(mt) - HFSPLUS_UTC_OFFSET); |
| 534 |
|
| 535 |
return ut; |
| 536 |
} |
| 537 |
|
| 538 |
static inline __be32 __hfsp_ut2mt(time64_t ut) |
| 539 |
{ |
| 540 |
return cpu_to_be32(lower_32_bits(ut) + HFSPLUS_UTC_OFFSET); |
| 541 |
} |
| 542 |
|
| 543 |
static inline enum hfsplus_btree_mutex_classes |
| 544 |
hfsplus_btree_lock_class(struct hfs_btree *tree) |
| 545 |
{ |
| 546 |
enum hfsplus_btree_mutex_classes class; |
| 547 |
|
| 548 |
switch (tree->cnid) { |
| 549 |
case HFSPLUS_CAT_CNID: |
| 550 |
class = CATALOG_BTREE_MUTEX; |
| 551 |
break; |
| 552 |
case HFSPLUS_EXT_CNID: |
| 553 |
class = EXTENTS_BTREE_MUTEX; |
| 554 |
break; |
| 555 |
case HFSPLUS_ATTR_CNID: |
| 556 |
class = ATTR_BTREE_MUTEX; |
| 557 |
break; |
| 558 |
default: |
| 559 |
BUG(); |
| 560 |
} |
| 561 |
return class; |
| 562 |
} |
| 563 |
|
| 564 |
static inline |
| 565 |
bool is_bnode_offset_valid(struct hfs_bnode *node, u32 off) |
| 566 |
{ |
| 567 |
bool is_valid = off < node->tree->node_size; |
| 568 |
|
| 569 |
if (!is_valid) { |
| 570 |
pr_err("requested invalid offset: " |
| 571 |
"NODE: id %u, type %#x, height %u, " |
| 572 |
"node_size %u, offset %u\n", |
| 573 |
node->this, node->type, node->height, |
| 574 |
node->tree->node_size, off); |
| 575 |
} |
| 576 |
|
| 577 |
return is_valid; |
| 578 |
} |
| 579 |
|
| 580 |
static inline |
| 581 |
u32 check_and_correct_requested_length(struct hfs_bnode *node, u32 off, u32 len) |
| 582 |
{ |
| 583 |
unsigned int node_size; |
| 584 |
|
| 585 |
if (!is_bnode_offset_valid(node, off)) |
| 586 |
return 0; |
| 587 |
|
| 588 |
node_size = node->tree->node_size; |
| 589 |
|
| 590 |
if ((off + len) > node_size) { |
| 591 |
u32 new_len = node_size - off; |
| 592 |
|
| 593 |
pr_err("requested length has been corrected: " |
| 594 |
"NODE: id %u, type %#x, height %u, " |
| 595 |
"node_size %u, offset %u, " |
| 596 |
"requested_len %u, corrected_len %u\n", |
| 597 |
node->this, node->type, node->height, |
| 598 |
node->tree->node_size, off, len, new_len); |
| 599 |
|
| 600 |
return new_len; |
| 601 |
} |
| 602 |
|
| 603 |
return len; |
| 604 |
} |
| 605 |
|
| 606 |
/* compatibility */ |
| 607 |
#define hfsp_mt2ut(t) (struct timespec64){ .tv_sec = __hfsp_mt2ut(t) } |
| 608 |
#define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec) |
| 609 |
#define hfsp_now2mt() __hfsp_ut2mt(ktime_get_real_seconds()) |
| 610 |
|
| 611 |
#endif |