package com.github.mjdev.libaums.fs.fat32;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/* JADX INFO: loaded from: classes.dex */
class Fat32BootSector {
    private static final int BYTES_PER_SECTOR_OFF = 11;
    private static final int FAT_COUNT_OFF = 16;
    private static final int FLAGS_OFF = 40;
    private static final int FS_INFO_SECTOR_OFF = 48;
    private static final int RESERVED_COUNT_OFF = 14;
    private static final int ROOT_DIR_CLUSTER_OFF = 44;
    private static final int SECTORS_PER_CLUSTER_OFF = 13;
    private static final int SECTORS_PER_FAT_OFF = 36;
    private static final int TOTAL_SECTORS_OFF = 32;
    private static final int VOLUME_LABEL_OFF = 48;
    private short bytesPerSector;
    private byte fatCount;
    private boolean fatMirrored;
    private short fsInfoStartSector;
    private short reservedSectors;
    private long rootDirStartCluster;
    private short sectorsPerCluster;
    private long sectorsPerFat;
    private long totalNumberOfSectors;
    private byte validFat;
    private String volumeLabel;

    private Fat32BootSector() {
    }

    static Fat32BootSector read(ByteBuffer byteBuffer) {
        Fat32BootSector fat32BootSector = new Fat32BootSector();
        byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
        fat32BootSector.bytesPerSector = byteBuffer.getShort(11);
        fat32BootSector.sectorsPerCluster = (short) (byteBuffer.get(13) & 255);
        fat32BootSector.reservedSectors = byteBuffer.getShort(14);
        fat32BootSector.fatCount = byteBuffer.get(16);
        fat32BootSector.totalNumberOfSectors = ((long) byteBuffer.getInt(32)) & 4294967295L;
        fat32BootSector.sectorsPerFat = ((long) byteBuffer.getInt(36)) & 4294967295L;
        fat32BootSector.rootDirStartCluster = ((long) byteBuffer.getInt(44)) & 4294967295L;
        fat32BootSector.fsInfoStartSector = byteBuffer.getShort(48);
        byte b = (byte) byteBuffer.getShort(40);
        fat32BootSector.fatMirrored = (b & 128) == 0;
        fat32BootSector.validFat = (byte) (b & 7);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 11; i++) {
            byte b2 = byteBuffer.get(i + 48);
            if (b2 == 0) {
                break;
            }
            sb.append((char) b2);
        }
        fat32BootSector.volumeLabel = sb.toString();
        return fat32BootSector;
    }

    short getBytesPerSector() {
        return this.bytesPerSector;
    }

    short getSectorsPerCluster() {
        return this.sectorsPerCluster;
    }

    short getReservedSectors() {
        return this.reservedSectors;
    }

    byte getFatCount() {
        return this.fatCount;
    }

    long getTotalNumberOfSectors() {
        return this.totalNumberOfSectors;
    }

    long getSectorsPerFat() {
        return this.sectorsPerFat;
    }

    long getRootDirStartCluster() {
        return this.rootDirStartCluster;
    }

    short getFsInfoStartSector() {
        return this.fsInfoStartSector;
    }

    boolean isFatMirrored() {
        return this.fatMirrored;
    }

    byte getValidFat() {
        return this.validFat;
    }

    int getBytesPerCluster() {
        return this.sectorsPerCluster * this.bytesPerSector;
    }

    long getFatOffset(int i) {
        return ((long) getBytesPerSector()) * (((long) getReservedSectors()) + (((long) i) * getSectorsPerFat()));
    }

    long getDataAreaOffset() {
        return getFatOffset(0) + (((long) getFatCount()) * getSectorsPerFat() * ((long) getBytesPerSector()));
    }

    String getVolumeLabel() {
        return this.volumeLabel;
    }

    public String toString() {
        return "Fat32BootSector{bytesPerSector=" + ((int) this.bytesPerSector) + ", sectorsPerCluster=" + ((int) this.sectorsPerCluster) + ", reservedSectors=" + ((int) this.reservedSectors) + ", fatCount=" + ((int) this.fatCount) + ", totalNumberOfSectors=" + this.totalNumberOfSectors + ", sectorsPerFat=" + this.sectorsPerFat + ", rootDirStartCluster=" + this.rootDirStartCluster + ", fsInfoStartSector=" + ((int) this.fsInfoStartSector) + ", fatMirrored=" + this.fatMirrored + ", validFat=" + ((int) this.validFat) + ", volumeLabel='" + this.volumeLabel + "'}";
    }
}
