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