Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 #ifndef _UAPI_LINUX_MSDOS_FS_H
0003 #define _UAPI_LINUX_MSDOS_FS_H
0004 
0005 #include <linux/types.h>
0006 #include <linux/magic.h>
0007 #include <asm/byteorder.h>
0008 
0009 /*
0010  * The MS-DOS filesystem constants/structures
0011  */
0012 
0013 #ifndef SECTOR_SIZE
0014 #define SECTOR_SIZE 512     /* sector size (bytes) */
0015 #endif
0016 #define SECTOR_BITS 9       /* log2(SECTOR_SIZE) */
0017 #define MSDOS_DPB   (MSDOS_DPS) /* dir entries per block */
0018 #define MSDOS_DPB_BITS  4       /* log2(MSDOS_DPB) */
0019 #define MSDOS_DPS   (SECTOR_SIZE / sizeof(struct msdos_dir_entry))
0020 #define MSDOS_DPS_BITS  4       /* log2(MSDOS_DPS) */
0021 #define MSDOS_LONGNAME  256     /* maximum name length */
0022 #define CF_LE_W(v)  le16_to_cpu(v)
0023 #define CF_LE_L(v)  le32_to_cpu(v)
0024 #define CT_LE_W(v)  cpu_to_le16(v)
0025 #define CT_LE_L(v)  cpu_to_le32(v)
0026 
0027 #define MSDOS_ROOT_INO   1  /* The root inode number */
0028 #define MSDOS_FSINFO_INO 2  /* Used for managing the FSINFO block */
0029 
0030 #define MSDOS_DIR_BITS  5   /* log2(sizeof(struct msdos_dir_entry)) */
0031 
0032 /* directory limit */
0033 #define FAT_MAX_DIR_ENTRIES (65536)
0034 #define FAT_MAX_DIR_SIZE    (FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS)
0035 
0036 #define ATTR_NONE   0   /* no attribute bits */
0037 #define ATTR_RO     1   /* read-only */
0038 #define ATTR_HIDDEN 2   /* hidden */
0039 #define ATTR_SYS    4   /* system */
0040 #define ATTR_VOLUME 8   /* volume label */
0041 #define ATTR_DIR    16  /* directory */
0042 #define ATTR_ARCH   32  /* archived */
0043 
0044 /* attribute bits that are copied "as is" */
0045 #define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
0046 /* bits that are used by the Windows 95/Windows NT extended FAT */
0047 #define ATTR_EXT    (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
0048 
0049 #define CASE_LOWER_BASE 8   /* base is lower case */
0050 #define CASE_LOWER_EXT  16  /* extension is lower case */
0051 
0052 #define DELETED_FLAG    0xe5    /* marks file as deleted when in name[0] */
0053 #define IS_FREE(n)  (!*(n) || *(n) == DELETED_FLAG)
0054 
0055 #define FAT_LFN_LEN 255 /* maximum long name length */
0056 #define MSDOS_NAME  11  /* maximum name length */
0057 #define MSDOS_SLOTS 21  /* max # of slots for short and long names */
0058 #define MSDOS_DOT   ".          "   /* ".", padded to MSDOS_NAME chars */
0059 #define MSDOS_DOTDOT    "..         "   /* "..", padded to MSDOS_NAME chars */
0060 
0061 /* start of data cluster's entry (number of reserved clusters) */
0062 #define FAT_START_ENT   2
0063 
0064 /* maximum number of clusters */
0065 #define MAX_FAT12   0xFF4
0066 #define MAX_FAT16   0xFFF4
0067 #define MAX_FAT32   0x0FFFFFF6
0068 
0069 /* bad cluster mark */
0070 #define BAD_FAT12   0xFF7
0071 #define BAD_FAT16   0xFFF7
0072 #define BAD_FAT32   0x0FFFFFF7
0073 
0074 /* standard EOF */
0075 #define EOF_FAT12   0xFFF
0076 #define EOF_FAT16   0xFFFF
0077 #define EOF_FAT32   0x0FFFFFFF
0078 
0079 #define FAT_ENT_FREE    (0)
0080 #define FAT_ENT_BAD (BAD_FAT32)
0081 #define FAT_ENT_EOF (EOF_FAT32)
0082 
0083 #define FAT_FSINFO_SIG1 0x41615252
0084 #define FAT_FSINFO_SIG2 0x61417272
0085 #define IS_FSINFO(x)    (le32_to_cpu((x)->signature1) == FAT_FSINFO_SIG1 \
0086              && le32_to_cpu((x)->signature2) == FAT_FSINFO_SIG2)
0087 
0088 #define FAT_STATE_DIRTY 0x01
0089 
0090 struct __fat_dirent {
0091     long        d_ino;
0092     __kernel_off_t  d_off;
0093     unsigned short  d_reclen;
0094     char        d_name[256]; /* We must not include limits.h! */
0095 };
0096 
0097 /*
0098  * ioctl commands
0099  */
0100 #define VFAT_IOCTL_READDIR_BOTH     _IOR('r', 1, struct __fat_dirent[2])
0101 #define VFAT_IOCTL_READDIR_SHORT    _IOR('r', 2, struct __fat_dirent[2])
0102 /* <linux/videotext.h> has used 0x72 ('r') in collision, so skip a few */
0103 #define FAT_IOCTL_GET_ATTRIBUTES    _IOR('r', 0x10, __u32)
0104 #define FAT_IOCTL_SET_ATTRIBUTES    _IOW('r', 0x11, __u32)
0105 /*Android kernel has used 0x12, so we use 0x13*/
0106 #define FAT_IOCTL_GET_VOLUME_ID     _IOR('r', 0x13, __u32)
0107 
0108 struct fat_boot_sector {
0109     __u8    ignored[3]; /* Boot strap short or near jump */
0110     __u8    system_id[8];   /* Name - can be used to special case
0111                    partition manager volumes */
0112     __u8    sector_size[2]; /* bytes per logical sector */
0113     __u8    sec_per_clus;   /* sectors/cluster */
0114     __le16  reserved;   /* reserved sectors */
0115     __u8    fats;       /* number of FATs */
0116     __u8    dir_entries[2]; /* root directory entries */
0117     __u8    sectors[2]; /* number of sectors */
0118     __u8    media;      /* media code */
0119     __le16  fat_length; /* sectors/FAT */
0120     __le16  secs_track; /* sectors per track */
0121     __le16  heads;      /* number of heads */
0122     __le32  hidden;     /* hidden sectors (unused) */
0123     __le32  total_sect; /* number of sectors (if sectors == 0) */
0124 
0125     union {
0126         struct {
0127             /*  Extended BPB Fields for FAT16 */
0128             __u8    drive_number;   /* Physical drive number */
0129             __u8    state;      /* undocumented, but used
0130                            for mount state. */
0131             __u8    signature;  /* extended boot signature */
0132             __u8    vol_id[4];  /* volume ID */
0133             __u8    vol_label[MSDOS_NAME];  /* volume label */
0134             __u8    fs_type[8];     /* file system type */
0135             /* other fields are not added here */
0136         } fat16;
0137 
0138         struct {
0139             /* only used by FAT32 */
0140             __le32  length;     /* sectors/FAT */
0141             __le16  flags;      /* bit 8: fat mirroring,
0142                            low 4: active fat */
0143             __u8    version[2]; /* major, minor filesystem
0144                            version */
0145             __le32  root_cluster;   /* first cluster in
0146                            root directory */
0147             __le16  info_sector;    /* filesystem info sector */
0148             __le16  backup_boot;    /* backup boot sector */
0149             __le16  reserved2[6];   /* Unused */
0150             /* Extended BPB Fields for FAT32 */
0151             __u8    drive_number;   /* Physical drive number */
0152             __u8    state;          /* undocumented, but used
0153                            for mount state. */
0154             __u8    signature;  /* extended boot signature */
0155             __u8    vol_id[4];  /* volume ID */
0156             __u8    vol_label[MSDOS_NAME];  /* volume label */
0157             __u8    fs_type[8];     /* file system type */
0158             /* other fields are not added here */
0159         } fat32;
0160     };
0161 };
0162 
0163 struct fat_boot_fsinfo {
0164     __le32   signature1;    /* 0x41615252L */
0165     __le32   reserved1[120];    /* Nothing as far as I can tell */
0166     __le32   signature2;    /* 0x61417272L */
0167     __le32   free_clusters; /* Free cluster count.  -1 if unknown */
0168     __le32   next_cluster;  /* Most recently allocated cluster */
0169     __le32   reserved2[4];
0170 };
0171 
0172 struct msdos_dir_entry {
0173     __u8    name[MSDOS_NAME];/* name and extension */
0174     __u8    attr;       /* attribute bits */
0175     __u8    lcase;      /* Case for base and extension */
0176     __u8    ctime_cs;   /* Creation time, centiseconds (0-199) */
0177     __le16  ctime;      /* Creation time */
0178     __le16  cdate;      /* Creation date */
0179     __le16  adate;      /* Last access date */
0180     __le16  starthi;    /* High 16 bits of cluster in FAT32 */
0181     __le16  time,date,start;/* time, date and first cluster */
0182     __le32  size;       /* file size (in bytes) */
0183 };
0184 
0185 /* Up to 13 characters of the name */
0186 struct msdos_dir_slot {
0187     __u8    id;     /* sequence number for slot */
0188     __u8    name0_4[10];    /* first 5 characters in name */
0189     __u8    attr;       /* attribute byte */
0190     __u8    reserved;   /* always 0 */
0191     __u8    alias_checksum; /* checksum for 8.3 alias */
0192     __u8    name5_10[12];   /* 6 more characters in name */
0193     __le16   start;     /* starting cluster number, 0 in long slots */
0194     __u8    name11_12[4];   /* last 2 characters in name */
0195 };
0196 
0197 #endif /* _UAPI_LINUX_MSDOS_FS_H */