199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1996, 1998 Robert Nordier
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the documentation and/or other materials provided with the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
199767f8919635c4928607450d9e0abb932109ceToomas Soome * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef DOSIO_H
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DOSIO_H
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DOS file attributes
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FA_RDONLY 001 /* read-only */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FA_HIDDEN 002 /* hidden file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FA_SYSTEM 004 /* system file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FA_LABEL 010 /* volume label */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FA_DIR 020 /* directory */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FA_ARCH 040 /* archive (file modified) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FA_XDE 017 /* extended directory entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FA_MASK 077 /* all attributes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Macros to convert DOS-format 16-bit and 32-bit quantities
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define cv2(p) ((u_int16_t)(p)[0] | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((u_int16_t)(p)[1] << 010))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define cv4(p) ((u_int32_t)(p)[0] | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((u_int32_t)(p)[1] << 010) | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((u_int32_t)(p)[2] << 020) | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((u_int32_t)(p)[3] << 030))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Directory, filesystem, and file structures.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char x_case; /* case */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char c_hsec; /* created: secs/100 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char c_time[2]; /* created: time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char c_date[2]; /* created: date */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char a_date[2]; /* accessed: date */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char h_clus[2]; /* clus[hi] */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} DOS_DEX;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char name[8]; /* name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char ext[3]; /* extension */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char attr; /* attributes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DOS_DEX dex; /* VFAT/FAT32 only */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char time[2]; /* modified: time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char date[2]; /* modified: date */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char clus[2]; /* starting cluster */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char size[4]; /* size */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} DOS_DE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char seq; /* flags */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char name1[5][2]; /* 1st name area */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char attr; /* (see fat_de) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char res; /* reserved */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char chk; /* checksum */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char name2[6][2]; /* 2nd name area */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char clus[2]; /* (see fat_de) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_char name3[2][2]; /* 3rd name area */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} DOS_XDE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef union {
199767f8919635c4928607450d9e0abb932109ceToomas Soome DOS_DE de; /* standard directory entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DOS_XDE xde; /* extended directory entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} DOS_DIR;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct open_file *fd; /* file descriptor */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int links; /* active links to structure */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int spc; /* sectors per cluster */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int bsize; /* cluster size in bytes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int bshift; /* cluster conversion shift */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int dirents; /* root directory entries */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int spf; /* sectors per fat */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int rdcl; /* root directory start cluster */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int lsnfat; /* start of fat */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int lsndir; /* start of root dir */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int lsndta; /* start of data area */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int fatsz; /* FAT entry size */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int xclus; /* maximum cluster number */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DOS_DE root;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} DOS_FS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome DOS_FS *fs; /* associated filesystem */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DOS_DE de; /* directory entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int offset; /* current offset */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_int c; /* last cluster read */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} DOS_FILE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !DOSIO_H */