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; /* cluster * 2 */ 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 DOT_NAME_NUM_MAX 9999999 29 unsigned int dot_name_num; 30 }; 31 32 struct exfat_lookup_filter { 33 struct { 34 uint8_t type; 35 /* return 0 if matched, return 1 if not matched, 36 * otherwise return errno 37 */ 38 int (*filter)(struct exfat_de_iter *iter, 39 void *param, int *dentry_count); 40 void *param; 41 } in; 42 struct { 43 struct exfat_dentry *dentry_set; 44 int dentry_count; 45 off_t file_offset; 46 /* device offset where the dentry_set locates, or 47 * the empty slot locates or EOF if not found. 48 */ 49 off_t dev_offset; 50 } out; 51 }; 52 53 int exfat_de_iter_init(struct exfat_de_iter *iter, struct exfat *exfat, 54 struct exfat_inode *dir, struct buffer_desc *bd); 55 int exfat_de_iter_get(struct exfat_de_iter *iter, 56 int ith, struct exfat_dentry **dentry); 57 int exfat_de_iter_get_dirty(struct exfat_de_iter *iter, 58 int ith, struct exfat_dentry **dentry); 59 int exfat_de_iter_flush(struct exfat_de_iter *iter); 60 int exfat_de_iter_advance(struct exfat_de_iter *iter, int skip_dentries); 61 off_t exfat_de_iter_device_offset(struct exfat_de_iter *iter); 62 off_t exfat_de_iter_file_offset(struct exfat_de_iter *iter); 63 64 int exfat_lookup_dentry_set(struct exfat *exfat, struct exfat_inode *parent, 65 struct exfat_lookup_filter *filter); 66 int exfat_lookup_file(struct exfat *exfat, struct exfat_inode *parent, 67 const char *name, struct exfat_lookup_filter *filter_out); 68 69 int exfat_create_file(struct exfat *exfat, struct exfat_inode *parent, 70 const char *name, unsigned short attr); 71 int exfat_update_file_dentry_set(struct exfat *exfat, 72 struct exfat_dentry *dset, int dcount, 73 const char *name, 74 clus_t start_clu, clus_t ccount); 75 int exfat_build_file_dentry_set(struct exfat *exfat, const char *name, 76 unsigned short attr, struct exfat_dentry **dentry_set, 77 int *dentry_count); 78 int exfat_add_dentry_set(struct exfat *exfat, struct exfat_dentry_loc *loc, 79 struct exfat_dentry *dset, int dcount, 80 bool need_next_loc); 81 void exfat_calc_dentry_checksum(struct exfat_dentry *dentry, 82 uint16_t *checksum, bool primary); 83 uint16_t exfat_calc_name_hash(struct exfat *exfat, 84 __le16 *name, int len); 85 86 #endif 87