• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *  Copyright (C) 2020 Hyunchul Lee <hyc.lee@gmail.com>
4  */
5 #ifndef _FSCK_H
6 #define _FSCK_H
7 
8 #include "list.h"
9 
10 typedef __u32 clus_t;
11 
12 struct exfat_inode {
13 	struct exfat_inode	*parent;
14 	struct list_head	children;
15 	struct list_head	sibling;
16 	struct list_head	list;
17 	clus_t			first_clus;
18 	clus_t			last_lclus;
19 	clus_t			last_pclus;
20 	__u16			attr;
21 	uint64_t		size;
22 	bool			is_contiguous;
23 	__le16			name[0];	/* only for directory */
24 };
25 
26 #define EXFAT_NAME_MAX			255
27 #define NAME_BUFFER_SIZE		((EXFAT_NAME_MAX+1)*2)
28 
29 struct buffer_desc {
30 	clus_t		p_clus;
31 	unsigned int	offset;
32 	char		*buffer;
33 	char		*dirty;
34 };
35 
36 struct exfat_de_iter {
37 	struct exfat		*exfat;
38 	struct exfat_inode	*parent;
39 	struct buffer_desc	*buffer_desc;		/* cluster * 2 */
40 	clus_t			ra_next_clus;
41 	unsigned int		ra_begin_offset;
42 	unsigned int		ra_partial_size;
43 	unsigned int		read_size;		/* cluster size */
44 	unsigned int		write_size;		/* sector size */
45 	off_t			de_file_offset;
46 	off_t			next_read_offset;
47 	int			max_skip_dentries;
48 };
49 
50 enum fsck_ui_options {
51 	FSCK_OPTS_REPAIR_ASK	= 0x01,
52 	FSCK_OPTS_REPAIR_YES	= 0x02,
53 	FSCK_OPTS_REPAIR_NO	= 0x04,
54 	FSCK_OPTS_REPAIR_AUTO	= 0x08,
55 	FSCK_OPTS_REPAIR_WRITE	= 0x0b,
56 	FSCK_OPTS_REPAIR_ALL	= 0x0f,
57 };
58 
59 struct exfat {
60 	enum fsck_ui_options	options;
61 	bool			dirty:1;
62 	bool			dirty_fat:1;
63 	struct exfat_blk_dev	*blk_dev;
64 	struct pbr		*bs;
65 	char			volume_label[VOLUME_LABEL_BUFFER_SIZE];
66 	struct exfat_inode	*root;
67 	struct list_head	dir_list;
68 	clus_t			clus_count;
69 	unsigned int		clus_size;
70 	unsigned int		sect_size;
71 	struct exfat_de_iter	de_iter;
72 	struct buffer_desc	buffer_desc[2];	/* cluster * 2 */
73 	char			*alloc_bitmap;
74 	char			*disk_bitmap;
75 	clus_t			disk_bitmap_clus;
76 	unsigned int		disk_bitmap_size;
77 };
78 
79 #define EXFAT_CLUSTER_SIZE(pbr) (1 << ((pbr)->bsx.sect_size_bits +	\
80 					(pbr)->bsx.sect_per_clus_bits))
81 #define EXFAT_SECTOR_SIZE(pbr) (1 << (pbr)->bsx.sect_size_bits)
82 
83 /* fsck.c */
84 off_t exfat_c2o(struct exfat *exfat, unsigned int clus);
85 int get_next_clus(struct exfat *exfat, struct exfat_inode *node,
86 				clus_t clus, clus_t *next);
87 
88 /* de_iter.c */
89 int exfat_de_iter_init(struct exfat_de_iter *iter, struct exfat *exfat,
90 				struct exfat_inode *dir);
91 int exfat_de_iter_get(struct exfat_de_iter *iter,
92 			int ith, struct exfat_dentry **dentry);
93 int exfat_de_iter_get_dirty(struct exfat_de_iter *iter,
94 			int ith, struct exfat_dentry **dentry);
95 int exfat_de_iter_flush(struct exfat_de_iter *iter);
96 int exfat_de_iter_advance(struct exfat_de_iter *iter, int skip_dentries);
97 off_t exfat_de_iter_file_offset(struct exfat_de_iter *iter);
98 
99 #endif
100