"""A parser for FAT file system images"""

import io
import posixpath
import shutil
from stat import *
import time

from . import *
from ..io import *
from ..util import *

FatHeader = Struct('FatHeader', [
 ('jump', Struct.STR % 3),
 ('oemName', Struct.STR % 8),
 ('bytesPerSector', Struct.INT16),
 ('sectorsPerCluster', Struct.INT8),
 ('reservedSectors', Struct.INT16),
 ('fatCopies', Struct.INT8),
 ('rootEntries', Struct.INT16),
 ('...', 2),
 ('mediaDescriptor', Struct.INT8),
 ('sectorsPerFat', Struct.INT16),
 ('...', 8),
 ('sectors', Struct.INT32),
 ('...', 2),
 ('extendedSignature', Struct.STR % 1),
 ('serialNumber', Struct.INT32),
 ('volumeLabel', Struct.STR % 11),
 ('fsType', Struct.STR % 8),
 ('...', 448),
 ('signature', Struct.STR % 2),
])
fatHeaderSignature = b'\x55\xaa'
fatHeaderExtendedSignature = b'\x29'

FatDirEntry = Struct('FatDirEntry', [
 ('name', Struct.STR % 8),
 ('ext', Struct.STR % 3),
 ('attr', Struct.INT8),
 ('...', 1),
 ('ctimeCs', Struct.INT8),
 ('...', 8),
 ('time', Struct.INT16),
 ('date', Struct.INT16),
 ('cluster', Struct.INT16),
 ('size', Struct.INT32),
])

VfatDirEntry = Struct('VfatDirEntry', [
 ('sequence', Struct.INT8),
 ('name1', Struct.STR % 10),
 ('attr', Struct.INT8),
 ('...', 1),
 ('checksum', Struct.INT8),
 ('name2', Struct.STR % 12),
 ('...', 2),
 ('name3', Struct.STR % 4),
])