126
132
#define OCFS2_CHB_WAITING 2
127
133
#define OCFS2_CHB_COMPLETE 3
135
/* Flags for global quotafile info */
136
#define OCFS2_QF_INFO_DIRTY 1
137
#define OCFS2_QF_INFO_LOADED 2
129
139
typedef void (*ocfs2_chb_notify)(int state, char *progress, void *data);
131
141
typedef struct _ocfs2_filesys ocfs2_filesys;
132
142
typedef struct _ocfs2_cached_inode ocfs2_cached_inode;
143
typedef struct _ocfs2_cached_dquot ocfs2_cached_dquot;
133
144
typedef struct _io_channel io_channel;
134
145
typedef struct _ocfs2_inode_scan ocfs2_inode_scan;
135
146
typedef struct _ocfs2_dir_scan ocfs2_dir_scan;
136
147
typedef struct _ocfs2_bitmap ocfs2_bitmap;
137
148
typedef struct _ocfs2_devices ocfs2_devices;
154
#define OCFS2_DEF_BLOCK_GRACE 604800 /* 1 week */
155
#define OCFS2_DEF_INODE_GRACE 604800 /* 1 week */
156
#define OCFS2_DEF_QUOTA_SYNC 10000 /* 10 seconds */
158
struct _ocfs2_quota_info {
159
ocfs2_cached_inode *qi_inode;
161
struct ocfs2_global_disk_dqinfo qi_info;
164
typedef struct _ocfs2_quota_info ocfs2_quota_info;
139
166
struct _ocfs2_filesys {
140
167
char *fs_devname;
141
168
uint32_t fs_flags;
207
245
uint32_t opt_ro_compat;
248
enum ocfs2_mkfs_types {
249
OCFS2_MKFSTYPE_DEFAULT,
250
OCFS2_MKFSTYPE_DATAFILES,
252
OCFS2_MKFSTYPE_VMSTORE,
255
struct _ocfs2_quota_hash {
258
ocfs2_cached_dquot **hash;
261
struct ocfs2_dx_hinfo {
266
struct ocfs2_dir_lookup_result {
267
struct ocfs2_dx_hinfo dl_hinfo; /* name hash results */
268
char * dl_leaf; /* unindexed block buffer */
269
uint64_t dl_leaf_blkno; /* blk number of dl_leaf */
270
struct ocfs2_dir_entry * dl_entry; /* dirent pointed into dl_leaf */
271
struct ocfs2_dx_leaf * dl_dx_leaf; /* indexed block buffer */
272
uint64_t dl_dx_leaf_blkno; /* blk number of dl_dx_leaf */
273
struct ocfs2_dx_entry * dl_dx_entry; /* indexed entry pointed to dl_dx_leaf */
274
int dl_dx_entry_idx; /* index of dl_dx_entry in entries list */
277
typedef struct _ocfs2_quota_hash ocfs2_quota_hash;
210
279
errcode_t ocfs2_malloc(unsigned long size, void *ptr);
211
280
errcode_t ocfs2_malloc0(unsigned long size, void *ptr);
212
281
errcode_t ocfs2_free(void *ptr);
282
352
errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
283
353
char *inode_buf);
284
354
errcode_t ocfs2_check_directory(ocfs2_filesys *fs, uint64_t dir);
355
int ocfs2_check_dir_entry(ocfs2_filesys *fs, struct ocfs2_dir_entry *de,
356
char *dir_buf, unsigned int offset);
286
357
errcode_t ocfs2_read_cached_inode(ocfs2_filesys *fs, uint64_t blkno,
287
358
ocfs2_cached_inode **ret_ci);
288
359
errcode_t ocfs2_write_cached_inode(ocfs2_filesys *fs,
289
360
ocfs2_cached_inode *cinode);
290
361
errcode_t ocfs2_free_cached_inode(ocfs2_filesys *fs,
291
362
ocfs2_cached_inode *cinode);
363
errcode_t ocfs2_refresh_cached_inode(ocfs2_filesys *fs,
364
ocfs2_cached_inode *cinode);
294
367
* obj is the object containing the extent list. eg, if you are swapping
342
423
errcode_t ocfs2_write_extent_block(ocfs2_filesys *fs, uint64_t blkno,
425
void ocfs2_swap_refcount_list_to_cpu(ocfs2_filesys *fs, void *obj,
426
struct ocfs2_refcount_list *rl);
427
void ocfs2_swap_refcount_list_from_cpu(ocfs2_filesys *fs, void *obj,
428
struct ocfs2_refcount_list *rl);
429
void ocfs2_swap_refcount_block_to_cpu(ocfs2_filesys *fs,
430
struct ocfs2_refcount_block *rb);
431
void ocfs2_swap_refcount_block_from_cpu(ocfs2_filesys *fs,
432
struct ocfs2_refcount_block *rb);
433
errcode_t ocfs2_read_refcount_block(ocfs2_filesys *fs, uint64_t blkno,
435
errcode_t ocfs2_read_refcount_block_nocheck(ocfs2_filesys *fs, uint64_t blkno,
437
errcode_t ocfs2_write_refcount_block(ocfs2_filesys *fs, uint64_t blkno,
439
errcode_t ocfs2_delete_refcount_block(ocfs2_filesys *fs, uint64_t blkno);
440
errcode_t ocfs2_new_refcount_block(ocfs2_filesys *fs, uint64_t *blkno,
441
uint64_t root_blkno, uint32_t rf_generation);
442
errcode_t ocfs2_increase_refcount(ocfs2_filesys *fs, uint64_t ino,
443
uint64_t cpos, uint32_t len);
444
errcode_t ocfs2_decrease_refcount(ocfs2_filesys *fs,
445
uint64_t ino, uint32_t cpos,
446
uint32_t len, int delete);
447
errcode_t ocfs2_refcount_cow(ocfs2_cached_inode *cinode,
448
uint32_t cpos, uint32_t write_len,
450
errcode_t ocfs2_refcount_cow_xattr(ocfs2_cached_inode *ci,
454
uint64_t value_blkno,
455
struct ocfs2_xattr_value_root *xv,
456
uint32_t cpos, uint32_t write_len);
457
errcode_t ocfs2_change_refcount_flag(ocfs2_filesys *fs, uint64_t i_blkno,
458
uint32_t v_cpos, uint32_t clusters,
460
int new_flags, int clear_flags);
461
errcode_t ocfs2_refcount_tree_get_rec(ocfs2_filesys *fs,
462
struct ocfs2_refcount_block *rb,
466
uint32_t *num_clusters);
467
errcode_t ocfs2_refcount_punch_hole(ocfs2_filesys *fs, uint64_t rf_blkno,
468
uint64_t p_start, uint32_t len);
469
errcode_t ocfs2_change_refcount(ocfs2_filesys *fs, uint64_t rf_blkno,
470
uint64_t p_start, uint32_t len,
472
int ocfs2_get_refcount_rec(ocfs2_filesys *fs,
474
uint64_t cpos, unsigned int len,
475
struct ocfs2_refcount_rec *ret_rec,
478
errcode_t ocfs2_create_refcount_tree(ocfs2_filesys *fs, uint64_t *refcount_loc);
479
errcode_t ocfs2_attach_refcount_tree(ocfs2_filesys *fs,
480
uint64_t ino, uint64_t refcount_loc);
344
481
errcode_t ocfs2_swap_dir_entries_from_cpu(void *buf, uint64_t bytes);
345
482
errcode_t ocfs2_swap_dir_entries_to_cpu(void *buf, uint64_t bytes);
346
483
void ocfs2_swap_dir_trailer(struct ocfs2_dir_block_trailer *trailer);
357
494
struct ocfs2_dir_entry *de, unsigned long offset);
358
495
void ocfs2_init_dir_trailer(ocfs2_filesys *fs, struct ocfs2_dinode *di,
359
496
uint64_t blkno, void *buf);
497
errcode_t ocfs2_read_dx_root(ocfs2_filesys *fs, uint64_t block,
499
errcode_t ocfs2_read_dx_leaf(ocfs2_filesys *fs, uint64_t block,
501
int ocfs2_dir_indexed(struct ocfs2_dinode *di);
502
errcode_t ocfs2_dx_dir_truncate(ocfs2_filesys *fs, uint64_t dir);
361
503
errcode_t ocfs2_dir_iterate2(ocfs2_filesys *fs,
377
520
int (*func)(struct ocfs2_dir_entry *dirent,
381
525
void *priv_data),
382
526
void *priv_data);
528
extern errcode_t ocfs2_dx_entries_iterate(ocfs2_filesys *fs,
529
struct ocfs2_dinode *dir,
531
int (*func)(ocfs2_filesys *fs,
532
struct ocfs2_dx_entry_list *entry_list,
533
struct ocfs2_dx_root_block *dx_root,
534
struct ocfs2_dx_leaf *dx_leaf,
538
extern errcode_t ocfs2_dx_frees_iterate(ocfs2_filesys *fs,
539
struct ocfs2_dinode *dir,
540
struct ocfs2_dx_root_block *dx_root,
542
int (*func)(ocfs2_filesys *fs,
544
struct ocfs2_dir_block_trailer *trailer,
384
549
errcode_t ocfs2_lookup(ocfs2_filesys *fs, uint64_t dir,
385
550
const char *name, int namelen, char *buf,
386
551
uint64_t *inode);
453
618
errcode_t ocfs2_get_ocfs1_label(char *device, uint8_t *label, uint16_t label_len,
454
619
uint8_t *uuid, uint16_t uuid_len);
456
void ocfs2_swap_group_desc(struct ocfs2_group_desc *gd);
621
void ocfs2_swap_group_desc_from_cpu(ocfs2_filesys *fs,
622
struct ocfs2_group_desc *gd);
623
void ocfs2_swap_group_desc_to_cpu(ocfs2_filesys *fs,
624
struct ocfs2_group_desc *gd);
457
625
errcode_t ocfs2_read_group_desc(ocfs2_filesys *fs, uint64_t blkno,
460
628
errcode_t ocfs2_write_group_desc(ocfs2_filesys *fs, uint64_t blkno,
630
uint64_t ocfs2_get_block_from_group(ocfs2_filesys *fs,
631
struct ocfs2_group_desc *grp,
632
int bpc, int bit_offset);
463
634
errcode_t ocfs2_chain_iterate(ocfs2_filesys *fs,
514
686
struct ocfs2_group_desc *gd,
515
687
uint64_t blkno, uint32_t generation,
516
688
uint64_t parent_inode, uint16_t bits,
689
uint16_t chain, int suballoc);
519
691
errcode_t ocfs2_new_dir_block(ocfs2_filesys *fs, uint64_t dir_ino,
520
692
uint64_t parent_ino, char **block);
522
errcode_t ocfs2_insert_extent(ocfs2_filesys *fs, uint64_t ino, uint32_t cpos,
523
uint64_t c_blkno, uint32_t clusters,
694
errcode_t ocfs2_inode_insert_extent(ocfs2_filesys *fs, uint64_t ino,
695
uint32_t cpos, uint64_t c_blkno,
696
uint32_t clusters, uint16_t flag);
525
697
errcode_t ocfs2_cached_inode_insert_extent(ocfs2_cached_inode *ci,
526
698
uint32_t cpos, uint64_t c_blkno,
527
699
uint32_t clusters, uint16_t flag);
533
705
errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino, int mode, int flags);
534
706
errcode_t ocfs2_delete_inode(ocfs2_filesys *fs, uint64_t ino);
535
707
errcode_t ocfs2_new_extent_block(ocfs2_filesys *fs, uint64_t *blkno);
708
errcode_t ocfs2_new_dx_root(ocfs2_filesys *fs, struct ocfs2_dinode *di, uint64_t *dr_blkno);
536
709
errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno);
710
errcode_t ocfs2_delete_dx_root(ocfs2_filesys *fs, uint64_t dr_blkno);
538
713
* Allocate the blocks and insert them to the file.
539
714
* only i_clusters of dinode will be updated accordingly, i_size not changed.
541
716
errcode_t ocfs2_extend_allocation(ocfs2_filesys *fs, uint64_t ino,
542
717
uint32_t new_clusters);
718
/* Ditto for cached inode */
719
errcode_t ocfs2_cached_inode_extend_allocation(ocfs2_cached_inode *ci,
720
uint32_t new_clusters);
543
721
/* Extend the file to the new size. No clusters will be allocated. */
544
722
errcode_t ocfs2_extend_file(ocfs2_filesys *fs, uint64_t ino, uint64_t new_size);
625
805
errcode_t ocfs2_meta_unlock(ocfs2_filesys *fs, ocfs2_cached_inode *ci);
807
/* Quota operations */
808
static inline int ocfs2_global_dqstr_in_blk(int blocksize)
810
return (blocksize - OCFS2_QBLK_RESERVED_SPACE -
811
sizeof(struct qt_disk_dqdbheader)) /
812
sizeof(struct ocfs2_global_disk_dqblk);
814
void ocfs2_swap_quota_header(struct ocfs2_disk_dqheader *header);
815
void ocfs2_swap_quota_local_info(struct ocfs2_local_disk_dqinfo *info);
816
void ocfs2_swap_quota_chunk_header(struct ocfs2_local_disk_chunk *chunk);
817
void ocfs2_swap_quota_global_info(struct ocfs2_global_disk_dqinfo *info);
818
void ocfs2_swap_quota_global_dqblk(struct ocfs2_global_disk_dqblk *dqblk);
819
void ocfs2_swap_quota_leaf_block_header(struct qt_disk_dqdbheader *bheader);
820
errcode_t ocfs2_init_local_quota_file(ocfs2_filesys *fs, int type,
822
errcode_t ocfs2_init_local_quota_files(ocfs2_filesys *fs, int type);
823
int ocfs2_qtree_depth(int blocksize);
824
int ocfs2_qtree_entry_unused(struct ocfs2_global_disk_dqblk *ddquot);
825
errcode_t ocfs2_init_global_quota_file(ocfs2_filesys *fs, int type);
826
errcode_t ocfs2_init_fs_quota_info(ocfs2_filesys *fs, int type);
827
errcode_t ocfs2_read_global_quota_info(ocfs2_filesys *fs, int type);
828
errcode_t ocfs2_load_fs_quota_info(ocfs2_filesys *fs);
829
errcode_t ocfs2_write_global_quota_info(ocfs2_filesys *fs, int type);
830
errcode_t ocfs2_write_dquot(ocfs2_filesys *fs, int type,
831
ocfs2_cached_dquot *dquot);
832
errcode_t ocfs2_delete_dquot(ocfs2_filesys *fs, int type,
833
ocfs2_cached_dquot *dquot);
834
errcode_t ocfs2_read_dquot(ocfs2_filesys *fs, int type, qid_t id,
835
ocfs2_cached_dquot **ret_dquot);
836
errcode_t ocfs2_new_quota_hash(ocfs2_quota_hash **hashp);
837
errcode_t ocfs2_free_quota_hash(ocfs2_quota_hash *hash);
838
errcode_t ocfs2_insert_quota_hash(ocfs2_quota_hash *hash,
839
ocfs2_cached_dquot *dquot);
840
errcode_t ocfs2_remove_quota_hash(ocfs2_quota_hash *hash,
841
ocfs2_cached_dquot *dquot);
842
errcode_t ocfs2_find_quota_hash(ocfs2_quota_hash *hash, qid_t id,
843
ocfs2_cached_dquot **dquotp);
844
errcode_t ocfs2_find_create_quota_hash(ocfs2_quota_hash *hash, qid_t id,
845
ocfs2_cached_dquot **dquotp);
846
errcode_t ocfs2_find_read_quota_hash(ocfs2_filesys *fs, ocfs2_quota_hash *hash,
848
ocfs2_cached_dquot **dquotp);
849
errcode_t ocfs2_compute_quota_usage(ocfs2_filesys *fs,
850
ocfs2_quota_hash *usr_hash,
851
ocfs2_quota_hash *grp_hash);
852
errcode_t ocfs2_init_quota_change(ocfs2_filesys *fs,
853
ocfs2_quota_hash **usrhash,
854
ocfs2_quota_hash **grphash);
855
errcode_t ocfs2_finish_quota_change(ocfs2_filesys *fs,
856
ocfs2_quota_hash *usrhash,
857
ocfs2_quota_hash *grphash);
858
errcode_t ocfs2_apply_quota_change(ocfs2_filesys *fs,
859
ocfs2_quota_hash *usrhash,
860
ocfs2_quota_hash *grphash,
861
uid_t uid, gid_t gid,
862
int64_t space_change,
863
int64_t inode_change);
864
errcode_t ocfs2_iterate_quota_hash(ocfs2_quota_hash *hash,
865
errcode_t (*f)(ocfs2_cached_dquot *, void *),
867
errcode_t ocfs2_write_release_dquots(ocfs2_filesys *fs, int type,
868
ocfs2_quota_hash *hash);
628
871
void ocfs2_swap_slot_map(struct ocfs2_slot_map *sm, int num_slots);
629
872
void ocfs2_swap_slot_map_extended(struct ocfs2_slot_map_extended *se,
720
963
errcode_t ocfs2_snprint_feature_flags(char *str, size_t size,
721
964
ocfs2_fs_options *flags);
722
965
errcode_t ocfs2_snprint_tunefs_flags(char *str, size_t size, uint16_t flags);
966
errcode_t ocfs2_snprint_extent_flags(char *str, size_t size, uint8_t flags);
967
errcode_t ocfs2_snprint_refcount_flags(char *str, size_t size, uint8_t flags);
723
968
errcode_t ocfs2_parse_feature(const char *opts,
724
969
ocfs2_fs_options *feature_flags,
725
970
ocfs2_fs_options *reverse_flags);
881
1127
return ret >> OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
1130
static inline uint64_t ocfs2_align_bytes_to_clusters(ocfs2_filesys *fs,
1135
clusters = ocfs2_clusters_in_bytes(fs, bytes);
1136
return (uint64_t)clusters <<
1137
OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
1140
static inline uint64_t ocfs2_align_bytes_to_blocks(ocfs2_filesys *fs,
1145
blocks = ocfs2_blocks_in_bytes(fs, bytes);
1146
return blocks << OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
885
1149
/* given a cluster offset, calculate which block group it belongs to
886
1150
* and return that block offset. */
1158
1462
void *priv_data),
1159
1463
void *priv_data);
1465
#define OCFS2_XATTR_ABORT 0x01
1466
#define OCFS2_XATTR_ERROR 0x02
1467
errcode_t ocfs2_xattr_iterate(ocfs2_cached_inode *ci,
1468
int (*func)(ocfs2_cached_inode *ci,
1471
struct ocfs2_xattr_entry *xe,
1473
uint64_t value_blkno,
1161
1479
uint32_t ocfs2_xattr_uuid_hash(unsigned char *uuid);
1162
1480
uint32_t ocfs2_xattr_name_hash(uint32_t uuid_hash, const char *name,
1164
int ocfs2_xattr_find_leaf(ocfs2_filesys *fs, struct ocfs2_xattr_block *xb,
1165
uint32_t cpos, char **leaf_buf);
1482
int ocfs2_tree_find_leaf(ocfs2_filesys *fs, struct ocfs2_extent_list *el,
1483
uint64_t el_blkno, char *el_blk,
1484
uint32_t cpos, char **leaf_buf);
1166
1485
uint16_t ocfs2_xattr_buckets_per_cluster(ocfs2_filesys *fs);
1167
1486
uint16_t ocfs2_blocks_per_xattr_bucket(ocfs2_filesys *fs);
1168
1487
/* See ocfs2_swap_extent_list() for a discussion of obj */
1213
1532
void *priv_data,
1215
1534
errcode_t ocfs2_delete_xattr_block(ocfs2_filesys *fs, uint64_t blkno);
1535
errcode_t ocfs2_dir_indexed_tree_truncate(ocfs2_filesys *fs,
1536
struct ocfs2_dx_root_block *dx_root);
1537
errcode_t ocfs2_write_dx_root(ocfs2_filesys *fs, uint64_t block, char *buf);
1538
errcode_t ocfs2_write_dx_leaf(ocfs2_filesys *fs, uint64_t block, void *buf);
1539
errcode_t ocfs2_dx_dir_build(ocfs2_filesys *fs, uint64_t dir);
1540
errcode_t ocfs2_dx_dir_insert_entry(ocfs2_filesys *fs, uint64_t dir, const char *name,
1541
uint64_t ino, uint64_t blkno);
1542
int ocfs2_search_dirblock(ocfs2_filesys *fs, char *dir_buf,
1543
const char *name, int namelen, unsigned int bytes,
1544
struct ocfs2_dir_entry **res_dir);
1545
void ocfs2_dx_dir_name_hash(ocfs2_filesys *fs, const char *name,
1546
int len, struct ocfs2_dx_hinfo *hinfo);
1547
errcode_t ocfs2_dx_dir_lookup(ocfs2_filesys *fs, struct ocfs2_dx_root_block *dx_root,
1548
struct ocfs2_extent_list *el, struct ocfs2_dx_hinfo *hinfo,
1549
uint32_t *ret_cpos, uint64_t *ret_phys_blkno);
1550
errcode_t ocfs2_dx_dir_search(ocfs2_filesys *fs, const char *name,
1551
int namelen, struct ocfs2_dx_root_block *dx_root,
1552
struct ocfs2_dir_lookup_result *res);
1553
void release_lookup_res(struct ocfs2_dir_lookup_result *res);
1554
int ocfs2_find_max_rec_len(ocfs2_filesys *fs, char *buf);
1555
void ocfs2_dx_list_remove_entry(struct ocfs2_dx_entry_list *entry_list, int index);
1556
int ocfs2_is_dir_trailer(ocfs2_filesys *fs, struct ocfs2_dinode *di, unsigned long de_off);
1557
/* routines for block check */
1558
uint32_t ocfs2_hamming_encode(uint32_t parity, void *data,
1559
unsigned int d, unsigned int nr);
1560
uint32_t ocfs2_hamming_encode_block(void *data, unsigned int d);
1561
void ocfs2_hamming_fix(void *data, unsigned int d,
1562
unsigned int nr, unsigned int fix);
1563
void ocfs2_hamming_fix_block(void *data, unsigned int d, unsigned int fix);
1564
uint32_t crc32_le(uint32_t crc, unsigned char const *p, size_t len);
1217
1569
#endif /* _FILESYS_H */