1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Copyright (C) 2021 LG Electronics. 4 * 5 * Author(s): Hyunchul Lee <hyc.lee@gmail.com> 6 */ 7 8 #ifndef _DIR_H_ 9 #define _DIR_H_ 10 11 struct exfat; 12 struct exfat_inode; 13 struct exfat_dentry_loc; 14 struct buffer_desc; 15 16 struct exfat_de_iter { 17 struct exfat *exfat; 18 struct exfat_inode *parent; 19 struct buffer_desc *buffer_desc; 20 __u32 ra_next_clus; 21 unsigned int ra_begin_offset; 22 unsigned int ra_partial_size; 23 unsigned int read_size; /* cluster size */ 24 unsigned int write_size; /* sector size */ 25 off_t de_file_offset; 26 off_t next_read_offset; 27 int max_skip_dentries; 28 #define INVALID_NAME_NUM_MAX 9999999 29 unsigned int invalid_name_num; 30 31 char *name_hash_bitmap; /* bitmap of children's name hashes */ 32 }; 33 34 struct exfat_lookup_filter { 35 struct { 36 uint8_t type; 37 int dentry_count; 38 /* return 0 if matched, return 1 if not matched, 39 * otherwise return errno 40 */ 41 int (*filter)(struct exfat_de_iter *iter, 42 void *param, int *dentry_count); 43 void *param; 44 } in; 45 struct { 46 struct exfat_dentry *dentry_set; 47 int dentry_count; 48 off_t file_offset; 49 /* 50 * If the dentry_set found: 51 * - device offset where the dentry_set locates. 52 * If the dentry_set not found: 53 * - device offset where the first empty dentry_set locates 54 * if in.dentry_count > 0 and there are enough empty dentry. 55 * - device offset where the last empty dentry_set locates 56 * if in.dentry_count = 0 or no enough empty dentry. 57 * - EOF if no empty dentry_set. 58 */ 59 off_t dev_offset; 60 } out; 61 }; 62 63 int exfat_de_iter_init(struct exfat_de_iter *iter, struct exfat *exfat, 64 struct exfat_inode *dir, struct buffer_desc *bd); 65 int exfat_de_iter_get(struct exfat_de_iter *iter, 66 int ith, struct exfat_dentry **dentry); 67 int exfat_de_iter_get_dirty(struct exfat_de_iter *iter, 68 int ith, struct exfat_dentry **dentry); 69 int exfat_de_iter_flush(struct exfat_de_iter *iter); 70 int exfat_de_iter_advance(struct exfat_de_iter *iter, int skip_dentries); 71 off_t exfat_de_iter_device_offset(struct exfat_de_iter *iter); 72 off_t exfat_de_iter_file_offset(struct exfat_de_iter *iter); 73 74 int exfat_lookup_dentry_set(struct exfat *exfat, struct exfat_inode *parent, 75 struct exfat_lookup_filter *filter); 76 int exfat_lookup_file(struct exfat *exfat, struct exfat_inode *parent, 77 const char *name, struct exfat_lookup_filter *filter_out); 78 int exfat_lookup_file_by_utf16name(struct exfat *exfat, 79 struct exfat_inode *parent, 80 __le16 *utf16_name, 81 struct exfat_lookup_filter *filter_out); 82 83 int exfat_create_file(struct exfat *exfat, struct exfat_inode *parent, 84 const char *name, unsigned short attr); 85 int exfat_update_file_dentry_set(struct exfat *exfat, 86 struct exfat_dentry *dset, int dcount, 87 const char *name, 88 clus_t start_clu, clus_t ccount); 89 int exfat_build_file_dentry_set(struct exfat *exfat, const char *name, 90 unsigned short attr, struct exfat_dentry **dentry_set, 91 int *dentry_count); 92 int exfat_add_dentry_set(struct exfat *exfat, struct exfat_dentry_loc *loc, 93 struct exfat_dentry *dset, int dcount, 94 bool need_next_loc); 95 void exfat_calc_dentry_checksum(struct exfat_dentry *dentry, 96 uint16_t *checksum, bool primary); 97 uint16_t exfat_calc_name_hash(struct exfat *exfat, 98 __le16 *name, int len); 99 100 #endif 101