• 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 	char			*zero_cluster;
49 };
50 
51 struct exfat_dentry_loc {
52 	struct exfat_inode	*parent;
53 	off_t			file_offset;
54 	off_t			dev_offset;
55 };
56 
57 struct path_resolve_ctx {
58 	struct exfat_inode	*ancestors[255];
59 	__le16			utf16_path[PATH_MAX + 2];
60 	char			local_path[PATH_MAX * MB_LEN_MAX + 1];
61 };
62 
63 struct buffer_desc {
64 	__u32		p_clus;
65 	unsigned int	offset;
66 	char		*buffer;
67 	char		*dirty;
68 };
69 
70 struct exfat *exfat_alloc_exfat(struct exfat_blk_dev *blk_dev, struct pbr *bs);
71 void exfat_free_exfat(struct exfat *exfat);
72 
73 struct exfat_inode *exfat_alloc_inode(__u16 attr);
74 void exfat_free_inode(struct exfat_inode *node);
75 
76 void exfat_free_children(struct exfat_inode *dir, bool file_only);
77 void exfat_free_file_children(struct exfat_inode *dir);
78 void exfat_free_ancestors(struct exfat_inode *child);
79 void exfat_free_dir_list(struct exfat *exfat);
80 
81 int exfat_resolve_path(struct path_resolve_ctx *ctx, struct exfat_inode *child);
82 int exfat_resolve_path_parent(struct path_resolve_ctx *ctx,
83 			      struct exfat_inode *parent, struct exfat_inode *child);
84 
85 struct buffer_desc *exfat_alloc_buffer(int count,
86 				       unsigned int clu_size, unsigned int sect_size);
87 void exfat_free_buffer(struct buffer_desc *bd, int count);
88 #endif
89