xref: /aosp_15_r20/external/mtools/vfat.h (revision d5c9a868b113e0ec0db2f27bc2ce8a253e77c4b0)
1*d5c9a868SElliott Hughes #ifndef MTOOLS_VFAT_H
2*d5c9a868SElliott Hughes #define MTOOLS_VFAT_H
3*d5c9a868SElliott Hughes 
4*d5c9a868SElliott Hughes /*  Copyright 1995 David C. Niemi
5*d5c9a868SElliott Hughes  *  Copyright 1996-1998,2000-2003,2005,2007-2009 Alain Knaff.
6*d5c9a868SElliott Hughes  *  This file is part of mtools.
7*d5c9a868SElliott Hughes  *
8*d5c9a868SElliott Hughes  *  Mtools is free software: you can redistribute it and/or modify
9*d5c9a868SElliott Hughes  *  it under the terms of the GNU General Public License as published by
10*d5c9a868SElliott Hughes  *  the Free Software Foundation, either version 3 of the License, or
11*d5c9a868SElliott Hughes  *  (at your option) any later version.
12*d5c9a868SElliott Hughes  *
13*d5c9a868SElliott Hughes  *  Mtools is distributed in the hope that it will be useful,
14*d5c9a868SElliott Hughes  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15*d5c9a868SElliott Hughes  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*d5c9a868SElliott Hughes  *  GNU General Public License for more details.
17*d5c9a868SElliott Hughes  *
18*d5c9a868SElliott Hughes  *  You should have received a copy of the GNU General Public License
19*d5c9a868SElliott Hughes  *  along with Mtools.  If not, see <http://www.gnu.org/licenses/>.
20*d5c9a868SElliott Hughes  */
21*d5c9a868SElliott Hughes 
22*d5c9a868SElliott Hughes #include "msdos.h"
23*d5c9a868SElliott Hughes 
24*d5c9a868SElliott Hughes /*
25*d5c9a868SElliott Hughes  * VFAT-related common header file
26*d5c9a868SElliott Hughes  */
27*d5c9a868SElliott Hughes #define VFAT_SUPPORT
28*d5c9a868SElliott Hughes 
29*d5c9a868SElliott Hughes struct unicode_char {
30*d5c9a868SElliott Hughes 	unsigned char lchar;
31*d5c9a868SElliott Hughes 	unsigned char uchar;
32*d5c9a868SElliott Hughes };
33*d5c9a868SElliott Hughes 
34*d5c9a868SElliott Hughes 
35*d5c9a868SElliott Hughes /* #define MAX_VFAT_SUBENTRIES 32 */ /* Theoretical max # of VSEs */
36*d5c9a868SElliott Hughes #define MAX_VFAT_SUBENTRIES 20		/* Max useful # of VSEs */
37*d5c9a868SElliott Hughes #define VSE_NAMELEN 13
38*d5c9a868SElliott Hughes 
39*d5c9a868SElliott Hughes #define VSE1SIZE 5
40*d5c9a868SElliott Hughes #define VSE2SIZE 6
41*d5c9a868SElliott Hughes #define VSE3SIZE 2
42*d5c9a868SElliott Hughes 
43*d5c9a868SElliott Hughes #include "stream.h"
44*d5c9a868SElliott Hughes 
45*d5c9a868SElliott Hughes struct vfat_subentry {
46*d5c9a868SElliott Hughes 	unsigned char id;		/* 0x40 = last; & 0x1f = VSE ID */
47*d5c9a868SElliott Hughes 	struct unicode_char text1[VSE1SIZE];
48*d5c9a868SElliott Hughes 	unsigned char attribute;	/* 0x0f for VFAT */
49*d5c9a868SElliott Hughes 	unsigned char hash1;		/* Always 0? */
50*d5c9a868SElliott Hughes 	unsigned char sum;		/* Checksum of short name */
51*d5c9a868SElliott Hughes 	struct unicode_char text2[VSE2SIZE];
52*d5c9a868SElliott Hughes 	unsigned char sector_l;		/* 0 for VFAT */
53*d5c9a868SElliott Hughes 	unsigned char sector_u;		/* 0 for VFAT */
54*d5c9a868SElliott Hughes 	struct unicode_char text3[VSE3SIZE];
55*d5c9a868SElliott Hughes };
56*d5c9a868SElliott Hughes 
57*d5c9a868SElliott Hughes /* Enough size for a worst case number of full VSEs plus a null */
58*d5c9a868SElliott Hughes #define VBUFSIZE ((MAX_VFAT_SUBENTRIES*VSE_NAMELEN) + 1)
59*d5c9a868SElliott Hughes 
60*d5c9a868SElliott Hughes /* Max legal length of a VFAT long name */
61*d5c9a868SElliott Hughes #define MAX_VNAMELEN (255)
62*d5c9a868SElliott Hughes 
63*d5c9a868SElliott Hughes #define VSE_PRESENT 0x01
64*d5c9a868SElliott Hughes #define VSE_LAST 0x40
65*d5c9a868SElliott Hughes #define VSE_MASK 0x1f
66*d5c9a868SElliott Hughes 
67*d5c9a868SElliott Hughes struct vfat_state {
68*d5c9a868SElliott Hughes 	wchar_t name[VBUFSIZE];
69*d5c9a868SElliott Hughes 	int status; /* is now a bit map of 32 bits */
70*d5c9a868SElliott Hughes 	int subentries;
71*d5c9a868SElliott Hughes 	unsigned char sum; /* no need to remember the sum for each entry,
72*d5c9a868SElliott Hughes 			    * it is the same anyways */
73*d5c9a868SElliott Hughes 	int present;
74*d5c9a868SElliott Hughes };
75*d5c9a868SElliott Hughes 
76*d5c9a868SElliott Hughes 
77*d5c9a868SElliott Hughes struct scan_state {
78*d5c9a868SElliott Hughes 	int match_free;
79*d5c9a868SElliott Hughes 	int shortmatch;
80*d5c9a868SElliott Hughes 	int longmatch;
81*d5c9a868SElliott Hughes 	unsigned int free_start;
82*d5c9a868SElliott Hughes 	unsigned int free_end;
83*d5c9a868SElliott Hughes 	int slot;
84*d5c9a868SElliott Hughes 	int got_slots;
85*d5c9a868SElliott Hughes 	unsigned int size_needed;
86*d5c9a868SElliott Hughes 	int max_entry;
87*d5c9a868SElliott Hughes };
88*d5c9a868SElliott Hughes 
89*d5c9a868SElliott Hughes #include "mtoolsDirentry.h"
90*d5c9a868SElliott Hughes 
91*d5c9a868SElliott Hughes void clear_vfat(struct vfat_state  *);
92*d5c9a868SElliott Hughes int unicode_write(wchar_t *, struct unicode_char *, int num, int *end);
93*d5c9a868SElliott Hughes 
94*d5c9a868SElliott Hughes int clear_vses(Stream_t *, int, unsigned int);
95*d5c9a868SElliott Hughes void autorename_short(struct dos_name_t *, int);
96*d5c9a868SElliott Hughes void autorename_long(char *, int);
97*d5c9a868SElliott Hughes 
98*d5c9a868SElliott Hughes #define DO_OPEN 1 /* open all files that are found */
99*d5c9a868SElliott Hughes #define ACCEPT_LABEL 0x08
100*d5c9a868SElliott Hughes #define ACCEPT_DIR 0x10
101*d5c9a868SElliott Hughes #define ACCEPT_PLAIN 0x20
102*d5c9a868SElliott Hughes #define MATCH_ANY 0x40
103*d5c9a868SElliott Hughes #define NO_MSG 0x80
104*d5c9a868SElliott Hughes #define NO_DOTS 0x100 /* accept no dots if matched by wildcard */
105*d5c9a868SElliott Hughes #define DO_OPEN_DIRS 0x400 /* open all directories that are found */
106*d5c9a868SElliott Hughes #define OPEN_PARENT 0x1000  /* in target lookup, open parent
107*d5c9a868SElliott Hughes 			     * instead of file itself */
108*d5c9a868SElliott Hughes #define NO_UNIX 0x2000 /* in target lookup, consider all files to reside on
109*d5c9a868SElliott Hughes 			* the DOS fs */
110*d5c9a868SElliott Hughes #endif
111