Merge branch '9p-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[sfrench/cifs-2.6.git] / include / uapi / linux / msdos_fs.h
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _UAPI_LINUX_MSDOS_FS_H
3 #define _UAPI_LINUX_MSDOS_FS_H
4
5 #include <linux/types.h>
6 #include <linux/magic.h>
7 #include <asm/byteorder.h>
8
9 /*
10  * The MS-DOS filesystem constants/structures
11  */
12
13 #define SECTOR_SIZE     512             /* sector size (bytes) */
14 #define SECTOR_BITS     9               /* log2(SECTOR_SIZE) */
15 #define MSDOS_DPB       (MSDOS_DPS)     /* dir entries per block */
16 #define MSDOS_DPB_BITS  4               /* log2(MSDOS_DPB) */
17 #define MSDOS_DPS       (SECTOR_SIZE / sizeof(struct msdos_dir_entry))
18 #define MSDOS_DPS_BITS  4               /* log2(MSDOS_DPS) */
19 #define MSDOS_LONGNAME  256             /* maximum name length */
20 #define CF_LE_W(v)      le16_to_cpu(v)
21 #define CF_LE_L(v)      le32_to_cpu(v)
22 #define CT_LE_W(v)      cpu_to_le16(v)
23 #define CT_LE_L(v)      cpu_to_le32(v)
24
25 #define MSDOS_ROOT_INO   1      /* The root inode number */
26 #define MSDOS_FSINFO_INO 2      /* Used for managing the FSINFO block */
27
28 #define MSDOS_DIR_BITS  5       /* log2(sizeof(struct msdos_dir_entry)) */
29
30 /* directory limit */
31 #define FAT_MAX_DIR_ENTRIES     (65536)
32 #define FAT_MAX_DIR_SIZE        (FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS)
33
34 #define ATTR_NONE       0       /* no attribute bits */
35 #define ATTR_RO         1       /* read-only */
36 #define ATTR_HIDDEN     2       /* hidden */
37 #define ATTR_SYS        4       /* system */
38 #define ATTR_VOLUME     8       /* volume label */
39 #define ATTR_DIR        16      /* directory */
40 #define ATTR_ARCH       32      /* archived */
41
42 /* attribute bits that are copied "as is" */
43 #define ATTR_UNUSED     (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
44 /* bits that are used by the Windows 95/Windows NT extended FAT */
45 #define ATTR_EXT        (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
46
47 #define CASE_LOWER_BASE 8       /* base is lower case */
48 #define CASE_LOWER_EXT  16      /* extension is lower case */
49
50 #define DELETED_FLAG    0xe5    /* marks file as deleted when in name[0] */
51 #define IS_FREE(n)      (!*(n) || *(n) == DELETED_FLAG)
52
53 #define FAT_LFN_LEN     255     /* maximum long name length */
54 #define MSDOS_NAME      11      /* maximum name length */
55 #define MSDOS_SLOTS     21      /* max # of slots for short and long names */
56 #define MSDOS_DOT       ".          "   /* ".", padded to MSDOS_NAME chars */
57 #define MSDOS_DOTDOT    "..         "   /* "..", padded to MSDOS_NAME chars */
58
59 #define FAT_FIRST_ENT(s, x)     ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \
60         MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x))
61
62 /* start of data cluster's entry (number of reserved clusters) */
63 #define FAT_START_ENT   2
64
65 /* maximum number of clusters */
66 #define MAX_FAT12       0xFF4
67 #define MAX_FAT16       0xFFF4
68 #define MAX_FAT32       0x0FFFFFF6
69 #define MAX_FAT(s)      (MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \
70         MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12)
71
72 /* bad cluster mark */
73 #define BAD_FAT12       0xFF7
74 #define BAD_FAT16       0xFFF7
75 #define BAD_FAT32       0x0FFFFFF7
76
77 /* standard EOF */
78 #define EOF_FAT12       0xFFF
79 #define EOF_FAT16       0xFFFF
80 #define EOF_FAT32       0x0FFFFFFF
81
82 #define FAT_ENT_FREE    (0)
83 #define FAT_ENT_BAD     (BAD_FAT32)
84 #define FAT_ENT_EOF     (EOF_FAT32)
85
86 #define FAT_FSINFO_SIG1 0x41615252
87 #define FAT_FSINFO_SIG2 0x61417272
88 #define IS_FSINFO(x)    (le32_to_cpu((x)->signature1) == FAT_FSINFO_SIG1 \
89                          && le32_to_cpu((x)->signature2) == FAT_FSINFO_SIG2)
90
91 #define FAT_STATE_DIRTY 0x01
92
93 struct __fat_dirent {
94         long            d_ino;
95         __kernel_off_t  d_off;
96         unsigned short  d_reclen;
97         char            d_name[256]; /* We must not include limits.h! */
98 };
99
100 /*
101  * ioctl commands
102  */
103 #define VFAT_IOCTL_READDIR_BOTH         _IOR('r', 1, struct __fat_dirent[2])
104 #define VFAT_IOCTL_READDIR_SHORT        _IOR('r', 2, struct __fat_dirent[2])
105 /* <linux/videotext.h> has used 0x72 ('r') in collision, so skip a few */
106 #define FAT_IOCTL_GET_ATTRIBUTES        _IOR('r', 0x10, __u32)
107 #define FAT_IOCTL_SET_ATTRIBUTES        _IOW('r', 0x11, __u32)
108 /*Android kernel has used 0x12, so we use 0x13*/
109 #define FAT_IOCTL_GET_VOLUME_ID         _IOR('r', 0x13, __u32)
110
111 struct fat_boot_sector {
112         __u8    ignored[3];     /* Boot strap short or near jump */
113         __u8    system_id[8];   /* Name - can be used to special case
114                                    partition manager volumes */
115         __u8    sector_size[2]; /* bytes per logical sector */
116         __u8    sec_per_clus;   /* sectors/cluster */
117         __le16  reserved;       /* reserved sectors */
118         __u8    fats;           /* number of FATs */
119         __u8    dir_entries[2]; /* root directory entries */
120         __u8    sectors[2];     /* number of sectors */
121         __u8    media;          /* media code */
122         __le16  fat_length;     /* sectors/FAT */
123         __le16  secs_track;     /* sectors per track */
124         __le16  heads;          /* number of heads */
125         __le32  hidden;         /* hidden sectors (unused) */
126         __le32  total_sect;     /* number of sectors (if sectors == 0) */
127
128         union {
129                 struct {
130                         /*  Extended BPB Fields for FAT16 */
131                         __u8    drive_number;   /* Physical drive number */
132                         __u8    state;          /* undocumented, but used
133                                                    for mount state. */
134                         __u8    signature;  /* extended boot signature */
135                         __u8    vol_id[4];      /* volume ID */
136                         __u8    vol_label[11];  /* volume label */
137                         __u8    fs_type[8];             /* file system type */
138                         /* other fields are not added here */
139                 } fat16;
140
141                 struct {
142                         /* only used by FAT32 */
143                         __le32  length;         /* sectors/FAT */
144                         __le16  flags;          /* bit 8: fat mirroring,
145                                                    low 4: active fat */
146                         __u8    version[2];     /* major, minor filesystem
147                                                    version */
148                         __le32  root_cluster;   /* first cluster in
149                                                    root directory */
150                         __le16  info_sector;    /* filesystem info sector */
151                         __le16  backup_boot;    /* backup boot sector */
152                         __le16  reserved2[6];   /* Unused */
153                         /* Extended BPB Fields for FAT32 */
154                         __u8    drive_number;   /* Physical drive number */
155                         __u8    state;          /* undocumented, but used
156                                                    for mount state. */
157                         __u8    signature;  /* extended boot signature */
158                         __u8    vol_id[4];      /* volume ID */
159                         __u8    vol_label[11];  /* volume label */
160                         __u8    fs_type[8];             /* file system type */
161                         /* other fields are not added here */
162                 } fat32;
163         };
164 };
165
166 struct fat_boot_fsinfo {
167         __le32   signature1;    /* 0x41615252L */
168         __le32   reserved1[120];        /* Nothing as far as I can tell */
169         __le32   signature2;    /* 0x61417272L */
170         __le32   free_clusters; /* Free cluster count.  -1 if unknown */
171         __le32   next_cluster;  /* Most recently allocated cluster */
172         __le32   reserved2[4];
173 };
174
175 struct msdos_dir_entry {
176         __u8    name[MSDOS_NAME];/* name and extension */
177         __u8    attr;           /* attribute bits */
178         __u8    lcase;          /* Case for base and extension */
179         __u8    ctime_cs;       /* Creation time, centiseconds (0-199) */
180         __le16  ctime;          /* Creation time */
181         __le16  cdate;          /* Creation date */
182         __le16  adate;          /* Last access date */
183         __le16  starthi;        /* High 16 bits of cluster in FAT32 */
184         __le16  time,date,start;/* time, date and first cluster */
185         __le32  size;           /* file size (in bytes) */
186 };
187
188 /* Up to 13 characters of the name */
189 struct msdos_dir_slot {
190         __u8    id;             /* sequence number for slot */
191         __u8    name0_4[10];    /* first 5 characters in name */
192         __u8    attr;           /* attribute byte */
193         __u8    reserved;       /* always 0 */
194         __u8    alias_checksum; /* checksum for 8.3 alias */
195         __u8    name5_10[12];   /* 6 more characters in name */
196         __le16   start;         /* starting cluster number, 0 in long slots */
197         __u8    name11_12[4];   /* last 2 characters in name */
198 };
199
200 #endif /* _UAPI_LINUX_MSDOS_FS_H */