| 1 |
|
| 2 |
|
| 3 |
> |
| 4 |
|
| 5 |
|
| 6 |
#ifndef _APFS_H |
| 7 |
#define _APFS_H |
| 8 |
|
| 9 |
#include <linux/buffer_head.h> |
| 10 |
#include <linux/fs.h> |
| 11 |
#include <linux/list.h> |
| 12 |
#include <linux/types.h> |
| 13 |
#include <linux/version.h> |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifdef RHEL_RELEASE |
| 24 |
#define RHEL_VERSION_GE(a, b) (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(a, b)) |
| 25 |
#else |
| 26 |
#define RHEL_VERSION_GE(a, b) 0 |
| 27 |
#endif |
| 28 |
|
| 29 |
#include "apfs_raw.h" |
| 30 |
|
| 31 |
#define EFSBADCRC EBADMSG |
| 32 |
#define EFSCORRUPTED EUCLEAN |
| 33 |
|
| 34 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0) |
| 35 |
#define SB_RDONLY MS_RDONLY |
| 36 |
#define SB_SILENT MS_SILENT |
| 37 |
#define SB_NOSEC MS_NOSEC |
| 38 |
#define SB_ACTIVE MS_ACTIVE |
| 39 |
static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags & SB_RDONLY; } |
| 40 |
#endif |
| 41 |
|
| 42 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 3, 0) |
| 43 |
#define lockdep_assert_held_write(l) ((void)(l)) |
| 44 |
#endif |
| 45 |
|
| 46 |
|
| 47 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 2, 0) |
| 48 |
#define apfs_submit_bh(op, op_flags, bh) \ |
| 49 |
do { \ |
| 50 |
if (op == REQ_OP_READ) \ |
| 51 |
bh_submit(bh, op | op_flags, bh_end_read); \ |
| 52 |
else \ |
| 53 |
bh_submit(bh, op | op_flags, bh_end_write); \ |
| 54 |
} while (0) |
| 55 |
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0) || RHEL_VERSION_GE(9, 2) |
| 56 |
#define apfs_submit_bh(op, op_flags, bh) \ |
| 57 |
do { \ |
| 58 |
if (op == REQ_OP_READ) \ |
| 59 |
bh->b_end_io = end_buffer_read_sync; \ |
| 60 |
else \ |
| 61 |
bh->b_end_io = end_buffer_write_sync; \ |
| 62 |
submit_bh(op | op_flags, bh); \ |
| 63 |
} while (0) |
| 64 |
#else |
| 65 |
#define apfs_submit_bh(op, op_flags, bh) \ |
| 66 |
do { \ |
| 67 |
if (op == REQ_OP_READ) \ |
| 68 |
bh->b_end_io = end_buffer_read_sync; \ |
| 69 |
else \ |
| 70 |
bh->b_end_io = end_buffer_write_sync; \ |
| 71 |
submit_bh(op, op_flags, bh); \ |
| 72 |
} while (0) |
| 73 |
#endif |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
struct apfs_ioctl_snap_name { |
| 79 |
char name[APFS_SNAP_MAX_NAMELEN + 1]; |
| 80 |
}; |
| 81 |
|
| 82 |
#define APFS_IOC_SET_DFLT_PFK _IOW('@', 0x80, struct apfs_wrapped_crypto_state) |
| 83 |
#define APFS_IOC_SET_DIR_CLASS _IOW('@', 0x81, u32) |
| 84 |
#define APFS_IOC_SET_PFK _IOW('@', 0x82, struct apfs_wrapped_crypto_state) |
| 85 |
#define APFS_IOC_GET_CLASS _IOR('@', 0x83, u32) |
| 86 |
#define APFS_IOC_GET_PFK _IOR('@', 0x84, struct apfs_wrapped_crypto_state) |
| 87 |
#define APFS_IOC_TAKE_SNAPSHOT _IOW('@', 0x85, struct apfs_ioctl_snap_name) |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
struct apfs_object { |
| 93 |
struct super_block *sb; |
| 94 |
u64 block_nr; |
| 95 |
u64 oid; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
struct buffer_head *o_bh; |
| 103 |
char *data; |
| 104 |
bool ephemeral; |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
#define APFS_BTREE_TOC_ENTRY_INCREMENT 8 |
| 109 |
#define APFS_BTREE_TOC_ENTRY_MAX_UNUSED (2 * BTREE_TOC_ENTRY_INCREMENT) |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
struct apfs_node { |
| 115 |
u32 tree_type; |
| 116 |
u16 flags; |
| 117 |
u32 records; |
| 118 |
|
| 119 |
int key; |
| 120 |
int free; |
| 121 |
int val; |
| 122 |
|
| 123 |
int key_free_list_len; |
| 124 |
int val_free_list_len; |
| 125 |
|
| 126 |
struct apfs_object object; |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
static inline bool apfs_node_is_leaf(struct apfs_node *node) |
| 134 |
{ |
| 135 |
return (node->flags & APFS_BTNODE_LEAF) != 0; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
static inline bool apfs_node_is_root(struct apfs_node *node) |
| 143 |
{ |
| 144 |
return (node->flags & APFS_BTNODE_ROOT) != 0; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
static inline bool apfs_node_has_fixed_kv_size(struct apfs_node *node) |
| 153 |
{ |
| 154 |
return (node->flags & APFS_BTNODE_FIXED_KV_SIZE) != 0; |
| 155 |
} |
| 156 |
|
| 157 |
struct apfs_ip_bitmap_block_info { |
| 158 |
bool dirty; |
| 159 |
void *block; |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
struct apfs_spaceman { |
| 166 |
struct apfs_spaceman_phys *sm_raw; |
| 167 |
struct apfs_nxsb_info *sm_nxi; |
| 168 |
u32 sm_size; |
| 169 |
|
| 170 |
u32 sm_blocks_per_chunk; |
| 171 |
u32 sm_chunks_per_cib; |
| 172 |
u64 sm_block_count; |
| 173 |
u64 sm_chunk_count; |
| 174 |
u32 sm_cib_count; |
| 175 |
u64 sm_free_count; |
| 176 |
u32 sm_addr_offset; |
| 177 |
u64 sm_main_fq_nodes; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
u64 sm_free_cache_base; |
| 184 |
u64 sm_free_cache_blkcnt; |
| 185 |
|
| 186 |
|
| 187 |
int sm_ip_bmaps_shift; |
| 188 |
|
| 189 |
u32 sm_ip_bmaps_mask; |
| 190 |
|
| 191 |
u32 sm_ip_bmaps_count; |
| 192 |
|
| 193 |
struct apfs_ip_bitmap_block_info sm_ip_bmaps[]; |
| 194 |
}; |
| 195 |
|
| 196 |
#define APFS_TRANS_MAIN_QUEUE_MAX 10000 |
| 197 |
#define APFS_TRANS_BUFFERS_MAX 65536 |
| 198 |
#define APFS_TRANS_STARTS_MAX 65536 |
| 199 |
|
| 200 |
|
| 201 |
#define APFS_NX_TRANS_FORCE_COMMIT 1 |
| 202 |
#define APFS_NX_TRANS_DEFER_COMMIT 2 |
| 203 |
#define APFS_NX_TRANS_COMMITTING 4 |
| 204 |
#define APFS_NX_TRANS_INCOMPLETE_BLOCK 8 |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
enum apfs_trans_kind { |
| 210 |
APFS_TRANS_REG, |
| 211 |
APFS_TRANS_DEL, |
| 212 |
APFS_TRANS_SYNC, |
| 213 |
}; |
| 214 |
|
| 215 |
|
| 216 |
#define APFS_REG_ROOM 128 |
| 217 |
#define APFS_DEL_ROOM 20 |
| 218 |
#define APFS_SYNC_ROOM 6 |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
struct apfs_nx_transaction { |
| 224 |
unsigned int t_state; |
| 225 |
|
| 226 |
struct delayed_work t_work; |
| 227 |
struct super_block *t_work_sb; |
| 228 |
|
| 229 |
struct list_head t_inodes; |
| 230 |
struct list_head t_buffers; |
| 231 |
size_t t_buffers_count; |
| 232 |
int t_starts_count; |
| 233 |
}; |
| 234 |
|
| 235 |
|
| 236 |
#define BH_TRANS BH_PrivateStart |
| 237 |
#define BH_CSUM (BH_PrivateStart + 1) |
| 238 |
BUFFER_FNS(TRANS, trans); |
| 239 |
BUFFER_FNS(CSUM, csum); |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
struct apfs_bh_info { |
| 245 |
struct buffer_head *bh; |
| 246 |
struct list_head list; |
| 247 |
}; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
struct apfs_ephemeral_object_info { |
| 253 |
u64 oid; |
| 254 |
u32 size; |
| 255 |
void *object; |
| 256 |
}; |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
#define APFS_EPHEMERAL_LIST_SIZE 32768 |
| 264 |
#define APFS_EPHEMERAL_LIST_LIMIT (APFS_EPHEMERAL_LIST_SIZE / sizeof(struct apfs_ephemeral_object_info)) |
| 265 |
|
| 266 |
|
| 267 |
#define APFS_CHECK_NODES 1 |
| 268 |
#define APFS_READWRITE 2 |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
#define APFS_FLAGS_SET 4 |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
struct apfs_blkdev_info { |
| 279 |
struct block_device *blki_bdev; |
| 280 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 9, 0) || RHEL_VERSION_GE(9, 5) |
| 281 |
struct file *blki_bdev_file; |
| 282 |
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 8, 0) |
| 283 |
struct bdev_handle *blki_bdev_handle; |
| 284 |
#endif |
| 285 |
|
| 286 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 5, 0) && !RHEL_VERSION_GE(9, 4) |
| 287 |
fmode_t blki_mode; |
| 288 |
#endif |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
char *blki_path; |
| 296 |
}; |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
struct apfs_nxsb_info { |
| 302 |
|
| 303 |
struct apfs_blkdev_info *nx_blkdev_info; |
| 304 |
struct apfs_blkdev_info *nx_tier2_info; |
| 305 |
u64 nx_tier2_bno; |
| 306 |
|
| 307 |
struct apfs_nx_superblock *nx_raw; |
| 308 |
u64 nx_bno; |
| 309 |
u64 nx_xid; |
| 310 |
|
| 311 |
|
| 312 |
struct apfs_ephemeral_object_info *nx_eph_list; |
| 313 |
int nx_eph_count; |
| 314 |
|
| 315 |
struct list_head vol_list; |
| 316 |
|
| 317 |
unsigned int nx_flags; |
| 318 |
unsigned int nx_refcnt; |
| 319 |
|
| 320 |
|
| 321 |
unsigned long nx_blocksize; |
| 322 |
unsigned char nx_blocksize_bits; |
| 323 |
|
| 324 |
struct apfs_spaceman *nx_spaceman; |
| 325 |
struct apfs_nx_transaction nx_transaction; |
| 326 |
int nx_trans_buffers_max; |
| 327 |
|
| 328 |
|
| 329 |
struct rw_semaphore nx_big_sem; |
| 330 |
|
| 331 |
|
| 332 |
struct list_head nx_list; |
| 333 |
}; |
| 334 |
|
| 335 |
extern struct mutex nxs_mutex; |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
struct apfs_omap_map { |
| 342 |
u64 xid; |
| 343 |
u64 bno; |
| 344 |
u32 flags; |
| 345 |
}; |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
struct apfs_omap_rec { |
| 351 |
u64 oid; |
| 352 |
u64 bno; |
| 353 |
}; |
| 354 |
|
| 355 |
#define APFS_OMAP_CACHE_SLOTS 128 |
| 356 |
#define APFS_OMAP_CACHE_SLOT_MASK (APFS_OMAP_CACHE_SLOTS - 1) |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
struct apfs_omap_cache { |
| 362 |
struct apfs_omap_rec recs[APFS_OMAP_CACHE_SLOTS]; |
| 363 |
bool disabled; |
| 364 |
spinlock_t lock; |
| 365 |
}; |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
struct apfs_omap { |
| 371 |
struct apfs_node *omap_root; |
| 372 |
struct apfs_omap_cache omap_cache; |
| 373 |
|
| 374 |
|
| 375 |
u64 omap_latest_snap; |
| 376 |
|
| 377 |
|
| 378 |
unsigned int omap_refcnt; |
| 379 |
}; |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
struct apfs_sb_info { |
| 385 |
struct apfs_nxsb_info *s_nxi; |
| 386 |
struct list_head list; |
| 387 |
struct apfs_superblock *s_vsb_raw; |
| 388 |
|
| 389 |
dev_t s_anon_dev; |
| 390 |
|
| 391 |
char *s_tier2_path; |
| 392 |
|
| 393 |
char *s_snap_name; |
| 394 |
u64 s_snap_xid; |
| 395 |
|
| 396 |
struct apfs_node *s_cat_root; |
| 397 |
struct apfs_omap *s_omap; |
| 398 |
|
| 399 |
struct apfs_object s_vobject; |
| 400 |
|
| 401 |
|
| 402 |
unsigned int s_vol_nr; |
| 403 |
kuid_t s_uid; |
| 404 |
kgid_t s_gid; |
| 405 |
unsigned int s_mount_opt; |
| 406 |
|
| 407 |
struct apfs_crypto_state_val *s_dflt_pfk; |
| 408 |
|
| 409 |
struct inode *s_private_dir; |
| 410 |
struct work_struct s_orphan_cleanup_work; |
| 411 |
atomic_t s_orphan_cleanup_err; |
| 412 |
}; |
| 413 |
|
| 414 |
static inline struct apfs_sb_info *APFS_SB(struct super_block *sb) |
| 415 |
{ |
| 416 |
return sb->s_fs_info; |
| 417 |
} |
| 418 |
|
| 419 |
static inline bool apfs_is_sealed(struct super_block *sb) |
| 420 |
{ |
| 421 |
u64 flags = le64_to_cpu(APFS_SB(sb)->s_vsb_raw->apfs_incompatible_features); |
| 422 |
|
| 423 |
return flags & APFS_INCOMPAT_SEALED_VOLUME; |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
static inline bool apfs_vol_is_encrypted(struct super_block *sb) |
| 431 |
{ |
| 432 |
struct apfs_superblock *vsb_raw = APFS_SB(sb)->s_vsb_raw; |
| 433 |
|
| 434 |
return (vsb_raw->apfs_fs_flags & cpu_to_le64(APFS_FS_UNENCRYPTED)) == 0; |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
static inline struct apfs_nxsb_info *APFS_NXI(struct super_block *sb) |
| 442 |
{ |
| 443 |
return APFS_SB(sb)->s_nxi; |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
static inline struct apfs_spaceman *APFS_SM(struct super_block *sb) |
| 451 |
{ |
| 452 |
return APFS_NXI(sb)->nx_spaceman; |
| 453 |
} |
| 454 |
|
| 455 |
static inline bool apfs_is_case_insensitive(struct super_block *sb) |
| 456 |
{ |
| 457 |
return (APFS_SB(sb)->s_vsb_raw->apfs_incompatible_features & |
| 458 |
cpu_to_le64(APFS_INCOMPAT_CASE_INSENSITIVE)) != 0; |
| 459 |
} |
| 460 |
|
| 461 |
static inline bool apfs_is_normalization_insensitive(struct super_block *sb) |
| 462 |
{ |
| 463 |
struct apfs_sb_info *sbi = APFS_SB(sb); |
| 464 |
u64 flags = le64_to_cpu(sbi->s_vsb_raw->apfs_incompatible_features); |
| 465 |
|
| 466 |
if (apfs_is_case_insensitive(sb)) |
| 467 |
return true; |
| 468 |
if (flags & APFS_INCOMPAT_NORMALIZATION_INSENSITIVE) |
| 469 |
return true; |
| 470 |
return false; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
static inline int apfs_max_maps_per_block(struct super_block *sb) |
| 478 |
{ |
| 479 |
unsigned long maps_size; |
| 480 |
|
| 481 |
maps_size = (sb->s_blocksize - sizeof(struct apfs_checkpoint_map_phys)); |
| 482 |
return maps_size / sizeof(struct apfs_checkpoint_mapping); |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
struct apfs_key { |
| 489 |
u64 id; |
| 490 |
u64 number; |
| 491 |
const char *name; |
| 492 |
u8 type; |
| 493 |
}; |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
static inline void apfs_init_free_queue_key(u64 xid, u64 paddr, |
| 502 |
struct apfs_key *key) |
| 503 |
{ |
| 504 |
key->id = xid; |
| 505 |
key->type = 0; |
| 506 |
key->number = paddr; |
| 507 |
key->name = NULL; |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
static inline void apfs_init_omap_key(u64 oid, u64 xid, struct apfs_key *key) |
| 517 |
{ |
| 518 |
key->id = oid; |
| 519 |
key->type = 0; |
| 520 |
key->number = xid; |
| 521 |
key->name = NULL; |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
static inline void apfs_init_extent_key(u64 bno, struct apfs_key *key) |
| 530 |
{ |
| 531 |
key->id = bno; |
| 532 |
key->type = APFS_TYPE_EXTENT; |
| 533 |
key->number = 0; |
| 534 |
key->name = NULL; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
static inline void apfs_init_inode_key(u64 ino, struct apfs_key *key) |
| 543 |
{ |
| 544 |
key->id = ino; |
| 545 |
key->type = APFS_TYPE_INODE; |
| 546 |
key->number = 0; |
| 547 |
key->name = NULL; |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
static inline void apfs_init_file_extent_key(u64 id, u64 offset, |
| 557 |
struct apfs_key *key) |
| 558 |
{ |
| 559 |
key->id = id; |
| 560 |
key->type = APFS_TYPE_FILE_EXTENT; |
| 561 |
key->number = offset; |
| 562 |
key->name = NULL; |
| 563 |
} |
| 564 |
|
| 565 |
static inline void apfs_init_fext_key(u64 id, u64 offset, struct apfs_key *key) |
| 566 |
{ |
| 567 |
key->id = id; |
| 568 |
key->type = 0; |
| 569 |
key->number = offset; |
| 570 |
key->name = NULL; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
static inline void apfs_init_dstream_id_key(u64 id, struct apfs_key *key) |
| 579 |
{ |
| 580 |
key->id = id; |
| 581 |
key->type = APFS_TYPE_DSTREAM_ID; |
| 582 |
key->number = 0; |
| 583 |
key->name = NULL; |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
static inline void apfs_init_crypto_state_key(u64 id, struct apfs_key *key) |
| 592 |
{ |
| 593 |
key->id = id; |
| 594 |
key->type = APFS_TYPE_CRYPTO_STATE; |
| 595 |
key->number = 0; |
| 596 |
key->name = NULL; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
static inline void apfs_init_sibling_link_key(u64 ino, u64 id, |
| 606 |
struct apfs_key *key) |
| 607 |
{ |
| 608 |
key->id = ino; |
| 609 |
key->type = APFS_TYPE_SIBLING_LINK; |
| 610 |
key->number = id; |
| 611 |
key->name = NULL; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
static inline void apfs_init_sibling_map_key(u64 id, struct apfs_key *key) |
| 620 |
{ |
| 621 |
key->id = id; |
| 622 |
key->type = APFS_TYPE_SIBLING_MAP; |
| 623 |
key->number = 0; |
| 624 |
key->name = NULL; |
| 625 |
} |
| 626 |
|
| 627 |
extern void apfs_init_drec_key(struct super_block *sb, u64 ino, const char *name, |
| 628 |
unsigned int name_len, struct apfs_key *key); |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
static inline void apfs_init_xattr_key(u64 ino, const char *name, |
| 637 |
struct apfs_key *key) |
| 638 |
{ |
| 639 |
key->id = ino; |
| 640 |
key->type = APFS_TYPE_XATTR; |
| 641 |
key->number = 0; |
| 642 |
key->name = name; |
| 643 |
} |
| 644 |
|
| 645 |
static inline void apfs_init_snap_metadata_key(u64 xid, struct apfs_key *key) |
| 646 |
{ |
| 647 |
key->id = xid; |
| 648 |
key->type = APFS_TYPE_SNAP_METADATA; |
| 649 |
key->number = 0; |
| 650 |
key->name = NULL; |
| 651 |
} |
| 652 |
|
| 653 |
static inline void apfs_init_snap_name_key(const char *name, struct apfs_key *key) |
| 654 |
{ |
| 655 |
key->id = APFS_SNAP_NAME_OBJ_ID; |
| 656 |
key->type = APFS_TYPE_SNAP_NAME; |
| 657 |
key->number = 0; |
| 658 |
key->name = name; |
| 659 |
} |
| 660 |
|
| 661 |
static inline void apfs_init_omap_snap_key(u64 xid, struct apfs_key *key) |
| 662 |
{ |
| 663 |
key->id = xid; |
| 664 |
key->type = 0; |
| 665 |
key->number = 0; |
| 666 |
key->name = NULL; |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
static inline void apfs_key_set_hdr(u64 type, u64 id, void *key) |
| 676 |
{ |
| 677 |
struct apfs_key_header *hdr = key; |
| 678 |
|
| 679 |
hdr->obj_id_and_type = cpu_to_le64(id | type << APFS_OBJ_TYPE_SHIFT); |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
static inline int apfs_cat_type(struct apfs_key_header *key) |
| 687 |
{ |
| 688 |
return (le64_to_cpu(key->obj_id_and_type) & APFS_OBJ_TYPE_MASK) >> APFS_OBJ_TYPE_SHIFT; |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
static inline u64 apfs_cat_cnid(struct apfs_key_header *key) |
| 698 |
{ |
| 699 |
return le64_to_cpu(key->obj_id_and_type) & APFS_OBJ_ID_MASK; |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
#define APFS_QUERY_TREE_MASK 000177 |
| 704 |
#define APFS_QUERY_OMAP 000001 |
| 705 |
#define APFS_QUERY_CAT 000002 |
| 706 |
#define APFS_QUERY_FREE_QUEUE 000004 |
| 707 |
#define APFS_QUERY_EXTENTREF 000010 |
| 708 |
#define APFS_QUERY_FEXT 000020 |
| 709 |
#define APFS_QUERY_SNAP_META 000040 |
| 710 |
#define APFS_QUERY_OMAP_SNAP 000100 |
| 711 |
#define APFS_QUERY_NEXT 000200 |
| 712 |
#define APFS_QUERY_EXACT 000400 |
| 713 |
#define APFS_QUERY_DONE 001000 |
| 714 |
#define APFS_QUERY_ANY_NAME 002000 |
| 715 |
#define APFS_QUERY_ANY_NUMBER 004000 |
| 716 |
#define APFS_QUERY_MULTIPLE (APFS_QUERY_ANY_NAME | APFS_QUERY_ANY_NUMBER) |
| 717 |
#define APFS_QUERY_PREV 010000 |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
struct apfs_query { |
| 723 |
struct apfs_node *node; |
| 724 |
struct apfs_key key; |
| 725 |
|
| 726 |
struct apfs_query *parent; |
| 727 |
unsigned int flags; |
| 728 |
|
| 729 |
|
| 730 |
int index; |
| 731 |
int key_off; |
| 732 |
int key_len; |
| 733 |
int off; |
| 734 |
int len; |
| 735 |
|
| 736 |
int depth; |
| 737 |
}; |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
static inline u32 apfs_query_storage(struct apfs_query *query) |
| 744 |
{ |
| 745 |
if (query->flags & APFS_QUERY_OMAP) |
| 746 |
return APFS_OBJ_PHYSICAL; |
| 747 |
if (query->flags & APFS_QUERY_CAT) |
| 748 |
return APFS_OBJ_VIRTUAL; |
| 749 |
if (query->flags & APFS_QUERY_FEXT) |
| 750 |
return APFS_OBJ_PHYSICAL; |
| 751 |
if (query->flags & APFS_QUERY_FREE_QUEUE) |
| 752 |
return APFS_OBJ_EPHEMERAL; |
| 753 |
if (query->flags & APFS_QUERY_EXTENTREF) |
| 754 |
return APFS_OBJ_PHYSICAL; |
| 755 |
if (query->flags & APFS_QUERY_SNAP_META) |
| 756 |
return APFS_OBJ_PHYSICAL; |
| 757 |
if (query->flags & APFS_QUERY_OMAP_SNAP) |
| 758 |
return APFS_OBJ_PHYSICAL; |
| 759 |
|
| 760 |
|
| 761 |
return -1; |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
struct apfs_file_extent { |
| 768 |
u64 logical_addr; |
| 769 |
u64 phys_block_num; |
| 770 |
u64 len; |
| 771 |
u64 crypto_id; |
| 772 |
}; |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
struct apfs_phys_extent { |
| 778 |
u64 bno; |
| 779 |
u64 blkcount; |
| 780 |
u64 len; |
| 781 |
u32 refcnt; |
| 782 |
u8 kind; |
| 783 |
}; |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
struct apfs_dstream_info { |
| 789 |
struct super_block *ds_sb; |
| 790 |
struct inode *ds_inode; |
| 791 |
u64 ds_id; |
| 792 |
u64 ds_size; |
| 793 |
u64 ds_sparse_bytes; |
| 794 |
struct apfs_file_extent ds_cached_ext; |
| 795 |
bool ds_ext_dirty; |
| 796 |
spinlock_t ds_ext_lock; |
| 797 |
bool ds_shared; |
| 798 |
}; |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
static inline u64 apfs_alloced_size(struct apfs_dstream_info *dstream) |
| 807 |
{ |
| 808 |
struct super_block *sb = dstream->ds_sb; |
| 809 |
u64 blks = (dstream->ds_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits; |
| 810 |
|
| 811 |
return blks << sb->s_blocksize_bits; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
struct apfs_inode_info { |
| 818 |
u64 i_ino64; |
| 819 |
u64 i_parent_id; |
| 820 |
struct timespec64 i_crtime; |
| 821 |
u32 i_nchildren; |
| 822 |
uid_t i_saved_uid; |
| 823 |
gid_t i_saved_gid; |
| 824 |
u32 i_key_class; |
| 825 |
u64 i_int_flags; |
| 826 |
u32 i_bsd_flags; |
| 827 |
struct list_head i_list; |
| 828 |
|
| 829 |
bool i_has_dstream; |
| 830 |
struct apfs_dstream_info i_dstream; |
| 831 |
|
| 832 |
bool i_cleaned; |
| 833 |
|
| 834 |
struct inode vfs_inode; |
| 835 |
}; |
| 836 |
|
| 837 |
static inline struct apfs_inode_info *APFS_I(const struct inode *inode) |
| 838 |
{ |
| 839 |
return container_of(inode, struct apfs_inode_info, vfs_inode); |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
static inline u64 apfs_ino(const struct inode *inode) |
| 849 |
{ |
| 850 |
return APFS_I(inode)->i_ino64; |
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
static inline void apfs_set_ino(struct inode *inode, u64 id) |
| 861 |
{ |
| 862 |
inode->i_ino = id; |
| 863 |
APFS_I(inode)->i_ino64 = id; |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
#define i_ino DONT_USE_I_INO |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
struct apfs_drec { |
| 873 |
u8 *name; |
| 874 |
u64 ino; |
| 875 |
u64 sibling_id; |
| 876 |
int name_len; |
| 877 |
unsigned int type; |
| 878 |
}; |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
struct apfs_xattr { |
| 884 |
u8 *name; |
| 885 |
u8 *xdata; |
| 886 |
int name_len; |
| 887 |
int xdata_len; |
| 888 |
bool has_dstream; |
| 889 |
}; |
| 890 |
|
| 891 |
struct apfs_compressed_data { |
| 892 |
bool has_dstream; |
| 893 |
u64 size; |
| 894 |
union { |
| 895 |
struct apfs_dstream_info *dstream; |
| 896 |
void *data; |
| 897 |
}; |
| 898 |
}; |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
#define apfs_emerg(sb, fmt, ...) apfs_msg(sb, KERN_EMERG, __func__, __LINE__, fmt, ##__VA_ARGS__) |
| 906 |
#define apfs_alert(sb, fmt, ...) apfs_msg(sb, KERN_ALERT, __func__, __LINE__, fmt, ##__VA_ARGS__) |
| 907 |
#define apfs_crit(sb, fmt, ...) apfs_msg(sb, KERN_CRIT, __func__, __LINE__, fmt, ##__VA_ARGS__) |
| 908 |
#define apfs_err(sb, fmt, ...) apfs_msg(sb, KERN_ERR, __func__, __LINE__, fmt, ##__VA_ARGS__) |
| 909 |
#define apfs_warn(sb, fmt, ...) apfs_msg(sb, KERN_WARNING, NULL, 0, fmt, ##__VA_ARGS__) |
| 910 |
#define apfs_notice(sb, fmt, ...) apfs_msg(sb, KERN_NOTICE, NULL, 0, fmt, ##__VA_ARGS__) |
| 911 |
#define apfs_info(sb, fmt, ...) apfs_msg(sb, KERN_INFO, NULL, 0, fmt, ##__VA_ARGS__) |
| 912 |
|
| 913 |
#ifdef CONFIG_APFS_DEBUG |
| 914 |
#define ASSERT(expr) WARN_ON(!(expr)) |
| 915 |
#define apfs_debug(sb, fmt, ...) apfs_msg(sb, KERN_DEBUG, __func__, __LINE__, fmt, ##__VA_ARGS__) |
| 916 |
#else |
| 917 |
#define ASSERT(expr) ((void)0) |
| 918 |
#define apfs_debug(sb, fmt, ...) no_printk(fmt, ##__VA_ARGS__) |
| 919 |
#endif |
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
#define apfs_assert_in_transaction(sb, obj) \ |
| 927 |
do { \ |
| 928 |
(void)sb; \ |
| 929 |
(void)obj; \ |
| 930 |
ASSERT(le64_to_cpu((obj)->o_xid) == APFS_NXI(sb)->nx_xid); \ |
| 931 |
} while (0) |
| 932 |
|
| 933 |
|
| 934 |
extern struct apfs_node *apfs_query_root(const struct apfs_query *query); |
| 935 |
extern struct apfs_query *apfs_alloc_query(struct apfs_node *node, |
| 936 |
struct apfs_query *parent); |
| 937 |
extern void apfs_free_query(struct apfs_query *query); |
| 938 |
extern int apfs_btree_query(struct super_block *sb, struct apfs_query **query); |
| 939 |
extern int apfs_omap_lookup_block(struct super_block *sb, struct apfs_omap *omap, u64 id, u64 *block, bool write); |
| 940 |
extern int apfs_omap_lookup_newest_block(struct super_block *sb, struct apfs_omap *omap, u64 id, u64 *block, bool write); |
| 941 |
extern int apfs_create_omap_rec(struct super_block *sb, u64 oid, u64 bno); |
| 942 |
extern int apfs_delete_omap_rec(struct super_block *sb, u64 oid); |
| 943 |
extern int apfs_query_join_transaction(struct apfs_query *query); |
| 944 |
extern int __apfs_btree_insert(struct apfs_query *query, void *key, int key_len, void *val, int val_len); |
| 945 |
extern int apfs_btree_insert(struct apfs_query *query, void *key, int key_len, |
| 946 |
void *val, int val_len); |
| 947 |
extern int apfs_btree_remove(struct apfs_query *query); |
| 948 |
extern void apfs_btree_change_node_count(struct apfs_query *query, int change); |
| 949 |
extern int apfs_btree_replace(struct apfs_query *query, void *key, int key_len, |
| 950 |
void *val, int val_len); |
| 951 |
extern void apfs_query_direct_forward(struct apfs_query *query); |
| 952 |
|
| 953 |
|
| 954 |
extern int apfs_compress_get_size(struct inode *inode, loff_t *size); |
| 955 |
|
| 956 |
|
| 957 |
extern int apfs_inode_by_name(struct inode *dir, const struct qstr *child, |
| 958 |
u64 *ino); |
| 959 |
extern int apfs_mkany(struct inode *dir, struct dentry *dentry, |
| 960 |
umode_t mode, dev_t rdev, const char *symname); |
| 961 |
|
| 962 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0) |
| 963 |
extern int apfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
| 964 |
dev_t rdev); |
| 965 |
extern int apfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); |
| 966 |
extern int apfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 967 |
struct inode *new_dir, struct dentry *new_dentry, |
| 968 |
unsigned int flags); |
| 969 |
extern int apfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
| 970 |
bool excl); |
| 971 |
#elif LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) && !RHEL_VERSION_GE(9, 6) |
| 972 |
extern int apfs_mknod(struct user_namespace *mnt_userns, struct inode *dir, |
| 973 |
struct dentry *dentry, umode_t mode, dev_t rdev); |
| 974 |
extern int apfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, |
| 975 |
struct dentry *dentry, umode_t mode); |
| 976 |
extern int apfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir, |
| 977 |
struct dentry *old_dentry, struct inode *new_dir, |
| 978 |
struct dentry *new_dentry, unsigned int flags); |
| 979 |
extern int apfs_create(struct user_namespace *mnt_userns, struct inode *dir, |
| 980 |
struct dentry *dentry, umode_t mode, bool excl); |
| 981 |
#elif LINUX_VERSION_CODE < KERNEL_VERSION(6, 15, 0) |
| 982 |
extern int apfs_mknod(struct mnt_idmap *idmap, struct inode *dir, |
| 983 |
struct dentry *dentry, umode_t mode, dev_t rdev); |
| 984 |
extern int apfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, |
| 985 |
struct dentry *dentry, umode_t mode); |
| 986 |
extern int apfs_rename(struct mnt_idmap *idmap, struct inode *old_dir, |
| 987 |
struct dentry *old_dentry, struct inode *new_dir, |
| 988 |
struct dentry *new_dentry, unsigned int flags); |
| 989 |
extern int apfs_create(struct mnt_idmap *idmap, struct inode *dir, |
| 990 |
struct dentry *dentry, umode_t mode, bool excl); |
| 991 |
#else |
| 992 |
extern int apfs_mknod(struct mnt_idmap *idmap, struct inode *dir, |
| 993 |
struct dentry *dentry, umode_t mode, dev_t rdev); |
| 994 |
extern struct dentry *apfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode); |
| 995 |
extern int apfs_rename(struct mnt_idmap *idmap, struct inode *old_dir, |
| 996 |
struct dentry *old_dentry, struct inode *new_dir, |
| 997 |
struct dentry *new_dentry, unsigned int flags); |
| 998 |
extern int apfs_create(struct mnt_idmap *idmap, struct inode *dir, |
| 999 |
struct dentry *dentry, umode_t mode, bool excl); |
| 1000 |
#endif |
| 1001 |
|
| 1002 |
extern int apfs_link(struct dentry *old_dentry, struct inode *dir, |
| 1003 |
struct dentry *dentry); |
| 1004 |
extern int apfs_unlink(struct inode *dir, struct dentry *dentry); |
| 1005 |
extern int apfs_rmdir(struct inode *dir, struct dentry *dentry); |
| 1006 |
extern int apfs_delete_orphan_link(struct inode *inode); |
| 1007 |
extern u64 apfs_any_orphan_ino(struct super_block *sb, u64 *ino_p); |
| 1008 |
|
| 1009 |
|
| 1010 |
extern int apfs_extent_from_query(struct apfs_query *query, |
| 1011 |
struct apfs_file_extent *extent); |
| 1012 |
extern int apfs_logic_to_phys_bno(struct apfs_dstream_info *dstream, sector_t dsblock, u64 *bno); |
| 1013 |
extern int __apfs_get_block(struct apfs_dstream_info *dstream, sector_t iblock, |
| 1014 |
struct buffer_head *bh_result, int create); |
| 1015 |
extern int apfs_get_block(struct inode *inode, sector_t iblock, |
| 1016 |
struct buffer_head *bh_result, int create); |
| 1017 |
extern int apfs_flush_extent_cache(struct apfs_dstream_info *dstream); |
| 1018 |
extern int apfs_dstream_get_new_bno(struct apfs_dstream_info *dstream, u64 dsblock, u64 *bno); |
| 1019 |
extern int apfs_get_new_block(struct inode *inode, sector_t iblock, |
| 1020 |
struct buffer_head *bh_result, int create); |
| 1021 |
extern int apfs_truncate(struct apfs_dstream_info *dstream, loff_t new_size); |
| 1022 |
extern int apfs_inode_delete_front(struct inode *inode); |
| 1023 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0) |
| 1024 |
extern loff_t apfs_remap_file_range(struct file *src_file, loff_t off, struct file *dst_file, loff_t destoff, loff_t len, unsigned int remap_flags); |
| 1025 |
#else |
| 1026 |
extern int apfs_clone_file_range(struct file *src_file, loff_t off, struct file *dst_file, loff_t destoff, u64 len); |
| 1027 |
#endif |
| 1028 |
extern int apfs_clone_extents(struct apfs_dstream_info *dstream, u64 new_id); |
| 1029 |
extern int apfs_nonsparse_dstream_read(struct apfs_dstream_info *dstream, void *buf, size_t count, u64 offset); |
| 1030 |
extern void apfs_nonsparse_dstream_preread(struct apfs_dstream_info *dstream); |
| 1031 |
|
| 1032 |
|
| 1033 |
extern int apfs_file_mmap(struct file *file, struct vm_area_struct *vma); |
| 1034 |
extern int apfs_fsync(struct file *file, loff_t start, loff_t end, int datasync); |
| 1035 |
|
| 1036 |
|
| 1037 |
extern struct inode *apfs_iget(struct super_block *sb, u64 cnid); |
| 1038 |
extern int apfs_update_inode(struct inode *inode, char *new_name); |
| 1039 |
extern void apfs_schedule_orphan_cleanup(struct super_block *sb); |
| 1040 |
extern void apfs_orphan_cleanup_work(struct work_struct *work); |
| 1041 |
extern void apfs_evict_inode(struct inode *inode); |
| 1042 |
extern struct inode *apfs_new_inode(struct inode *dir, umode_t mode, |
| 1043 |
dev_t rdev); |
| 1044 |
extern int apfs_create_inode_rec(struct super_block *sb, struct inode *inode, |
| 1045 |
struct dentry *dentry); |
| 1046 |
extern int apfs_inode_create_exclusive_dstream(struct inode *inode); |
| 1047 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 17, 0) |
| 1048 |
extern int __apfs_write_begin(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned int len, unsigned int flags, struct page **pagep, void **fsdata); |
| 1049 |
extern int __apfs_write_end(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned int len, unsigned int copied, struct page *page, void *fsdata); |
| 1050 |
#else |
| 1051 |
extern int __apfs_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned int len, unsigned int flags, struct page **pagep, void **fsdata); |
| 1052 |
extern int __apfs_write_end(struct file *file, struct address_space *mapping, loff_t pos, unsigned int len, unsigned int copied, struct page *page, void *fsdata); |
| 1053 |
#endif |
| 1054 |
extern int apfs_dstream_adj_refcnt(struct apfs_dstream_info *dstream, u32 delta); |
| 1055 |
|
| 1056 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0) |
| 1057 |
extern int apfs_setattr(struct dentry *dentry, struct iattr *iattr); |
| 1058 |
#elif LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) && !RHEL_VERSION_GE(9, 6) |
| 1059 |
extern int apfs_setattr(struct user_namespace *mnt_userns, |
| 1060 |
struct dentry *dentry, struct iattr *iattr); |
| 1061 |
#else |
| 1062 |
extern int apfs_setattr(struct mnt_idmap *idmap, |
| 1063 |
struct dentry *dentry, struct iattr *iattr); |
| 1064 |
#endif |
| 1065 |
|
| 1066 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 0, 0) |
| 1067 |
extern int apfs_update_time(struct inode *inode, enum fs_update_time time, unsigned int flags); |
| 1068 |
#elif LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) |
| 1069 |
extern int apfs_update_time(struct inode *inode, struct timespec64 *time, int flags); |
| 1070 |
#else |
| 1071 |
extern int apfs_update_time(struct inode *inode, int flags); |
| 1072 |
#endif |
| 1073 |
long apfs_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
| 1074 |
long apfs_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
| 1075 |
|
| 1076 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) |
| 1077 |
extern int apfs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 1078 |
struct kstat *stat); |
| 1079 |
#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0) |
| 1080 |
extern int apfs_getattr(const struct path *path, struct kstat *stat, |
| 1081 |
u32 request_mask, unsigned int query_flags); |
| 1082 |
#elif LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) && !RHEL_VERSION_GE(9, 6) |
| 1083 |
extern int apfs_getattr(struct user_namespace *mnt_userns, |
| 1084 |
const struct path *path, struct kstat *stat, u32 request_mask, |
| 1085 |
unsigned int query_flags); |
| 1086 |
#else |
| 1087 |
extern int apfs_getattr(struct mnt_idmap *idmap, |
| 1088 |
const struct path *path, struct kstat *stat, u32 request_mask, |
| 1089 |
unsigned int query_flags); |
| 1090 |
#endif |
| 1091 |
|
| 1092 |
extern int apfs_crypto_adj_refcnt(struct super_block *sb, u64 crypto_id, int delta); |
| 1093 |
|
| 1094 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 17, 0) |
| 1095 |
#define fileattr file_kattr |
| 1096 |
#endif |
| 1097 |
|
| 1098 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) || RHEL_VERSION_GE(9, 6) |
| 1099 |
extern int apfs_fileattr_get(struct dentry *dentry, struct fileattr *fa); |
| 1100 |
extern int apfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry, struct fileattr *fa); |
| 1101 |
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 13, 0) |
| 1102 |
extern int apfs_fileattr_get(struct dentry *dentry, struct fileattr *fa); |
| 1103 |
extern int apfs_fileattr_set(struct user_namespace *mnt_userns, struct dentry *dentry, struct fileattr *fa); |
| 1104 |
#endif |
| 1105 |
|
| 1106 |
|
| 1107 |
extern int apfs_filename_cmp(struct super_block *sb, const char *name1, unsigned int len1, const char *name2, unsigned int len2); |
| 1108 |
extern int apfs_keycmp(struct apfs_key *k1, struct apfs_key *k2); |
| 1109 |
extern int apfs_read_cat_key(void *raw, int size, struct apfs_key *key, bool hashed); |
| 1110 |
extern int apfs_read_fext_key(void *raw, int size, struct apfs_key *key); |
| 1111 |
extern int apfs_read_free_queue_key(void *raw, int size, struct apfs_key *key); |
| 1112 |
extern int apfs_read_omap_key(void *raw, int size, struct apfs_key *key); |
| 1113 |
extern int apfs_read_extentref_key(void *raw, int size, struct apfs_key *key); |
| 1114 |
extern int apfs_read_snap_meta_key(void *raw, int size, struct apfs_key *key); |
| 1115 |
extern int apfs_read_omap_snap_key(void *raw, int size, struct apfs_key *key); |
| 1116 |
|
| 1117 |
|
| 1118 |
extern __printf(5, 6) void apfs_msg(struct super_block *sb, const char *prefix, const char *func, int line, const char *fmt, ...); |
| 1119 |
|
| 1120 |
|
| 1121 |
extern struct apfs_node *apfs_read_node(struct super_block *sb, u64 oid, |
| 1122 |
u32 storage, bool write); |
| 1123 |
extern void apfs_update_node(struct apfs_node *node); |
| 1124 |
extern int apfs_delete_node(struct apfs_node *node, int type); |
| 1125 |
extern int apfs_node_query(struct super_block *sb, struct apfs_query *query); |
| 1126 |
extern void apfs_node_query_first(struct apfs_query *query); |
| 1127 |
extern int apfs_omap_map_from_query(struct apfs_query *query, struct apfs_omap_map *map); |
| 1128 |
extern int apfs_node_split(struct apfs_query *query); |
| 1129 |
extern int apfs_node_locate_key(struct apfs_node *node, int index, int *off); |
| 1130 |
extern void apfs_node_free(struct apfs_node *node); |
| 1131 |
extern void apfs_node_free_range(struct apfs_node *node, u16 off, u16 len); |
| 1132 |
extern bool apfs_node_has_room(struct apfs_node *node, int length, bool replace); |
| 1133 |
extern int apfs_node_replace(struct apfs_query *query, void *key, int key_len, void *val, int val_len); |
| 1134 |
extern int apfs_node_insert(struct apfs_query *query, void *key, int key_len, void *val, int val_len); |
| 1135 |
extern int apfs_create_single_rec_node(struct apfs_query *query, void *key, int key_len, void *val, int val_len); |
| 1136 |
extern int apfs_make_empty_btree_root(struct super_block *sb, u32 subtype, u64 *oid); |
| 1137 |
|
| 1138 |
|
| 1139 |
extern int apfs_obj_verify_csum(struct super_block *sb, struct buffer_head *bh); |
| 1140 |
extern void apfs_obj_set_csum(struct super_block *sb, struct apfs_obj_phys *obj); |
| 1141 |
extern int apfs_multiblock_verify_csum(char *object, u32 size); |
| 1142 |
extern void apfs_multiblock_set_csum(char *object, u32 size); |
| 1143 |
extern int apfs_create_cpm_block(struct super_block *sb, u64 bno, struct buffer_head **bh_p); |
| 1144 |
extern int apfs_create_cpoint_map(struct super_block *sb, struct apfs_checkpoint_map_phys *cpm, struct apfs_obj_phys *obj, u64 bno, u32 size); |
| 1145 |
extern struct apfs_ephemeral_object_info *apfs_ephemeral_object_lookup(struct super_block *sb, u64 oid); |
| 1146 |
extern struct buffer_head *apfs_read_object_block(struct super_block *sb, u64 bno, bool write, bool preserve); |
| 1147 |
extern u32 apfs_index_in_data_area(struct super_block *sb, u64 bno); |
| 1148 |
extern u64 apfs_data_index_to_bno(struct super_block *sb, u32 index); |
| 1149 |
|
| 1150 |
|
| 1151 |
extern int apfs_ioc_take_snapshot(struct file *file, void __user *user_arg); |
| 1152 |
extern int apfs_switch_to_snapshot(struct super_block *sb); |
| 1153 |
|
| 1154 |
|
| 1155 |
extern int apfs_read_spaceman(struct super_block *sb); |
| 1156 |
extern int apfs_free_queue_insert_nocache(struct super_block *sb, u64 bno, u64 count); |
| 1157 |
extern int apfs_free_queue_insert(struct super_block *sb, u64 bno, u64 count); |
| 1158 |
extern int apfs_spaceman_allocate_block(struct super_block *sb, u64 *bno, bool backwards); |
| 1159 |
extern int apfs_write_ip_bitmaps(struct super_block *sb); |
| 1160 |
extern int apfs_spaceman_get_free_blkcnt(struct super_block *sb, u64 *blkcnt); |
| 1161 |
|
| 1162 |
|
| 1163 |
extern int apfs_map_volume_super_bno(struct super_block *sb, u64 bno, bool check); |
| 1164 |
extern int apfs_map_volume_super(struct super_block *sb, bool write); |
| 1165 |
extern void apfs_unmap_volume_super(struct super_block *sb); |
| 1166 |
extern int apfs_read_omap(struct super_block *sb, bool write); |
| 1167 |
extern int apfs_read_catalog(struct super_block *sb, bool write); |
| 1168 |
extern int apfs_sync_fs(struct super_block *sb, int wait); |
| 1169 |
|
| 1170 |
|
| 1171 |
extern int apfs_cpoint_data_free(struct super_block *sb, u64 bno); |
| 1172 |
extern void apfs_transaction_init(struct apfs_nx_transaction *trans); |
| 1173 |
extern int apfs_transaction_start(struct super_block *sb, enum apfs_trans_kind kind); |
| 1174 |
extern int apfs_transaction_commit(struct super_block *sb); |
| 1175 |
extern void apfs_inode_join_transaction(struct super_block *sb, struct inode *inode); |
| 1176 |
extern int apfs_transaction_join(struct super_block *sb, |
| 1177 |
struct buffer_head *bh); |
| 1178 |
void apfs_transaction_abort(struct super_block *sb); |
| 1179 |
extern int apfs_transaction_flush_all_inodes(struct super_block *sb); |
| 1180 |
extern int apfs_read_ephemeral_objects(struct super_block *sb); |
| 1181 |
|
| 1182 |
|
| 1183 |
extern int ____apfs_xattr_get(struct inode *inode, const char *name, void *buffer, |
| 1184 |
size_t size, bool only_whole); |
| 1185 |
extern int __apfs_xattr_get(struct inode *inode, const char *name, void *buffer, |
| 1186 |
size_t size); |
| 1187 |
extern int apfs_delete_all_xattrs(struct inode *inode); |
| 1188 |
extern int apfs_xattr_set(struct inode *inode, const char *name, const void *value, |
| 1189 |
size_t size, int flags); |
| 1190 |
extern ssize_t apfs_listxattr(struct dentry *dentry, char *buffer, size_t size); |
| 1191 |
extern int apfs_xattr_get_compressed_data(struct inode *inode, const char *name, struct apfs_compressed_data *cdata); |
| 1192 |
extern void apfs_release_compressed_data(struct apfs_compressed_data *cdata); |
| 1193 |
extern int apfs_compressed_data_read(struct apfs_compressed_data *cdata, void *buf, size_t count, u64 offset); |
| 1194 |
|
| 1195 |
|
| 1196 |
extern int apfs_find_xfield(u8 *xfields, int len, u8 xtype, char **xval); |
| 1197 |
extern int apfs_init_xfields(u8 *buffer, int buflen); |
| 1198 |
extern int apfs_insert_xfield(u8 *buffer, int buflen, |
| 1199 |
const struct apfs_x_field *xkey, |
| 1200 |
const void *xval); |
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
extern const struct address_space_operations apfs_compress_aops; |
| 1208 |
extern const struct file_operations apfs_compress_file_operations; |
| 1209 |
|
| 1210 |
|
| 1211 |
extern const struct file_operations apfs_dir_operations; |
| 1212 |
|
| 1213 |
|
| 1214 |
extern const struct file_operations apfs_file_operations; |
| 1215 |
extern const struct inode_operations apfs_file_inode_operations; |
| 1216 |
|
| 1217 |
|
| 1218 |
extern const struct inode_operations apfs_dir_inode_operations; |
| 1219 |
extern const struct inode_operations apfs_special_inode_operations; |
| 1220 |
extern const struct dentry_operations apfs_dentry_operations; |
| 1221 |
|
| 1222 |
|
| 1223 |
extern const struct inode_operations apfs_symlink_inode_operations; |
| 1224 |
|
| 1225 |
|
| 1226 |
extern const struct xattr_handler *apfs_xattr_handlers[]; |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
static inline void apfs_assert_query_is_valid(const struct apfs_query *query) |
| 1236 |
{ |
| 1237 |
ASSERT(apfs_node_is_root(apfs_query_root(query))); |
| 1238 |
} |
| 1239 |
|
| 1240 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 15, 0) |
| 1241 |
#define page_has_buffers(page) folio_buffers(page_folio(page)) |
| 1242 |
#endif |
| 1243 |
|
| 1244 |
static inline int apfs_inode_state_read_once(struct inode *inode) |
| 1245 |
{ |
| 1246 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 19, 0) |
| 1247 |
return inode_state_read_once(inode); |
| 1248 |
#else |
| 1249 |
return inode->i_state; |
| 1250 |
#endif |
| 1251 |
} |
| 1252 |
|
| 1253 |
static inline void apfs_inode_state_set_raw(struct inode *inode, int flags) |
| 1254 |
{ |
| 1255 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 19, 0) |
| 1256 |
inode_state_set_raw(inode, flags); |
| 1257 |
#else |
| 1258 |
inode->i_state |= flags; |
| 1259 |
#endif |
| 1260 |
} |
| 1261 |
|
| 1262 |
static inline void apfs_inode_state_clear_raw(struct inode *inode, int flags) |
| 1263 |
{ |
| 1264 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 19, 0) |
| 1265 |
inode_state_clear_raw(inode, flags); |
| 1266 |
#else |
| 1267 |
inode->i_state &= ~flags; |
| 1268 |
#endif |
| 1269 |
} |
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
static inline void |
| 1278 |
apfs_map_bh(struct buffer_head *bh, struct super_block *sb, sector_t block) |
| 1279 |
{ |
| 1280 |
struct apfs_nxsb_info *nxi = NULL; |
| 1281 |
struct apfs_blkdev_info *info = NULL; |
| 1282 |
|
| 1283 |
nxi = APFS_NXI(sb); |
| 1284 |
info = nxi->nx_blkdev_info; |
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
if (block >= nxi->nx_tier2_bno) { |
| 1293 |
if (nxi->nx_tier2_info) { |
| 1294 |
info = nxi->nx_tier2_info; |
| 1295 |
block -= nxi->nx_tier2_bno; |
| 1296 |
} else { |
| 1297 |
apfs_err(sb, "block number in tier 2 range (0x%llx)", (unsigned long long)block); |
| 1298 |
} |
| 1299 |
} |
| 1300 |
|
| 1301 |
set_buffer_mapped(bh); |
| 1302 |
bh->b_bdev = info->blki_bdev; |
| 1303 |
bh->b_blocknr = block; |
| 1304 |
bh->b_size = sb->s_blocksize; |
| 1305 |
} |
| 1306 |
|
| 1307 |
static inline struct buffer_head * |
| 1308 |
apfs_sb_bread(struct super_block *sb, sector_t block) |
| 1309 |
{ |
| 1310 |
struct apfs_nxsb_info *nxi = NULL; |
| 1311 |
struct apfs_blkdev_info *info = NULL; |
| 1312 |
|
| 1313 |
nxi = APFS_NXI(sb); |
| 1314 |
info = nxi->nx_blkdev_info; |
| 1315 |
|
| 1316 |
if (block >= nxi->nx_tier2_bno) { |
| 1317 |
if (!nxi->nx_tier2_info) { |
| 1318 |
|
| 1319 |
apfs_err(sb, "block number in tier 2 range (0x%llx)", (unsigned long long)block); |
| 1320 |
return NULL; |
| 1321 |
} |
| 1322 |
info = nxi->nx_tier2_info; |
| 1323 |
block -= nxi->nx_tier2_bno; |
| 1324 |
} |
| 1325 |
|
| 1326 |
return __bread_gfp(info->blki_bdev, block, sb->s_blocksize, __GFP_MOVABLE); |
| 1327 |
} |
| 1328 |
|
| 1329 |
|
| 1330 |
static inline struct buffer_head * |
| 1331 |
__apfs_getblk(struct super_block *sb, sector_t block) |
| 1332 |
{ |
| 1333 |
struct apfs_nxsb_info *nxi = NULL; |
| 1334 |
struct apfs_blkdev_info *info = NULL; |
| 1335 |
|
| 1336 |
nxi = APFS_NXI(sb); |
| 1337 |
info = nxi->nx_blkdev_info; |
| 1338 |
|
| 1339 |
if (block >= nxi->nx_tier2_bno) { |
| 1340 |
if (!nxi->nx_tier2_info) { |
| 1341 |
|
| 1342 |
apfs_err(sb, "block number in tier 2 range (0x%llx)", (unsigned long long)block); |
| 1343 |
return NULL; |
| 1344 |
} |
| 1345 |
info = nxi->nx_tier2_info; |
| 1346 |
block -= nxi->nx_tier2_bno; |
| 1347 |
} |
| 1348 |
|
| 1349 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0) |
| 1350 |
return __getblk_gfp(info->blki_bdev, block, sb->s_blocksize, __GFP_MOVABLE); |
| 1351 |
#else |
| 1352 |
return bdev_getblk(info->blki_bdev, block, sb->s_blocksize, __GFP_MOVABLE); |
| 1353 |
#endif |
| 1354 |
} |
| 1355 |
|
| 1356 |
|
| 1357 |
static inline struct buffer_head * |
| 1358 |
apfs_getblk(struct super_block *sb, sector_t block) |
| 1359 |
{ |
| 1360 |
struct buffer_head *bh = NULL; |
| 1361 |
|
| 1362 |
bh = __apfs_getblk(sb, block); |
| 1363 |
if (bh) |
| 1364 |
set_buffer_uptodate(bh); |
| 1365 |
return bh; |
| 1366 |
} |
| 1367 |
|
| 1368 |
#endif |