• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef _EXFAT_FS_H_
8 #define _EXFAT_FS_H_
9 
10 #include "list.h"
11 
12 struct exfat_dentry;
13 
14 struct exfat_inode {
15 	struct exfat_inode	*parent;
16 	struct list_head	children;
17 	struct list_head	sibling;
18 	struct list_head	list;
19 	clus_t			first_clus;
20 	__u16			attr;
21 	uint64_t		size;
22 	bool			is_contiguous;
23 	struct exfat_dentry	*dentry_set;
24 	int			dentry_count;
25 	off_t			dev_offset;
26 	__le16			name[0];	/* only for directory */
27 };
28 
29 #define EXFAT_NAME_MAX			255
30 #define NAME_BUFFER_SIZE		((EXFAT_NAME_MAX + 1) * 2)
31 
32 struct exfat {
33 	struct exfat_blk_dev	*blk_dev;
34 	struct pbr		*bs;
35 	char			volume_label[VOLUME_LABEL_BUFFER_SIZE];
36 	struct exfat_inode	*root;
37 	struct list_head	dir_list;
38 	clus_t			clus_count;
39 	unsigned int		clus_size;
40 	unsigned int		sect_size;
41 	char			*disk_bitmap;
42 	char			*alloc_bitmap;
43 	char			*ohead_bitmap;
44 	clus_t			disk_bitmap_clus;
45 	unsigned int		disk_bitmap_size;
46 	__u16			*upcase_table;
47 	clus_t			start_clu;
48 	unsigned int		buffer_count;
49 	struct buffer_desc	*lookup_buffer; /* for dentry set lookup */
50 };
51 
52 struct exfat_dentry_loc {
53 	struct exfat_inode	*parent;
54 	off_t			file_offset;
55 	off_t			dev_offset;
56 };
57 
58 struct path_resolve_ctx {
59 	struct exfat_inode	*ancestors[255];
60 	__le16			utf16_path[PATH_MAX + 2];
61 	char			local_path[PATH_MAX * MB_LEN_MAX + 1];
62 };
63 
64 struct buffer_desc {
65 	__u32		p_clus;
66 	unsigned int	offset;
67 	char		*buffer;
68 	char		dirty[EXFAT_BITMAP_SIZE(4 * KB / 512)];
69 };
70 
71 struct exfat *exfat_alloc_exfat(struct exfat_blk_dev *blk_dev, struct pbr *bs);
72 void exfat_free_exfat(struct exfat *exfat);
73 
74 struct exfat_inode *exfat_alloc_inode(__u16 attr);
75 void exfat_free_inode(struct exfat_inode *node);
76 
77 void exfat_free_children(struct exfat_inode *dir, bool file_only);
78 void exfat_free_file_children(struct exfat_inode *dir);
79 void exfat_free_ancestors(struct exfat_inode *child);
80 void exfat_free_dir_list(struct exfat *exfat);
81 
82 int exfat_resolve_path(struct path_resolve_ctx *ctx, struct exfat_inode *child);
83 int exfat_resolve_path_parent(struct path_resolve_ctx *ctx,
84 			      struct exfat_inode *parent, struct exfat_inode *child);
85 
86 struct buffer_desc *exfat_alloc_buffer(struct exfat *exfat);
87 void exfat_free_buffer(const struct exfat *exfat, struct buffer_desc *bd);
88 
exfat_get_read_size(const struct exfat * exfat)89 static inline unsigned int exfat_get_read_size(const struct exfat *exfat)
90 {
91 	return MIN(exfat->clus_size, 4 * KB);
92 }
93 #endif
94