pc_fs.h revision 0e42dee69ed771bf604dd1789fca9d77b5bbe302
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_FS_PC_FS_H
#define _SYS_FS_PC_FS_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
typedef uint16_t pc_cluster16_t;
typedef uint32_t pc_cluster32_t;
/*
* PC (MSDOS) compatible virtual file system.
*
* A main goal of the implementation was to maintain statelessness
* except while files are open. Thus mounting and unmounting merely
* declared the file system name. The user may change disks at almost
* any time without concern (just like the PC). It is assumed that when
* files are open for writing the disk access light will be on, as a
* warning not to change disks. The implementation must, however, detect
* disk change and recover gracefully. It does this by comparing the
* in core entry for a directory to the on disk entry whenever a directory
* is searched. If a discrepancy is found active directories become root and
* active files are marked invalid.
*
* There are only two type of nodes on the PC file system; files and
* directories. These are represented by two separate vnode op vectors,
* and they are kept in two separate tables. Files are known by the
* disk block number and block (cluster) offset of the files directory
* entry. Directories are known by the starting cluster number.
*
* The file system is locked for during each user operation. This is
* done to simplify disk verification error conditions.
*
* Notes on FAT32 support
* ----------------------
* The basic difference between FAT32 and FAT16 is that cluster numbers are now
* 32-bit instead of 16-bit. The FAT is thus an array of 32-bit cluster numbers,
* and because of this the cluster size can be much smaller on a large disk
* (4k, say, on a 1 Gig drive instead of 16k). Unfortunately, the FAT is not
* the only place cluster numbers are stored - the starting cluster is stored
* in the directory entry for a file, and of course it's only 16-bit. Luckily,
* there's a 16-bit OS/2 Extended Attribute field that is now used to store the
* upper 16-bits of the starting cluster number.
*
* Most of the FAT32 changes to pcfs are under 'if it's FAT32' to minimize the
* effect on non-FAT32 filesystems (and still share the code), except for the
* starting cluster changes. It seemed easier to make common functions to
* handle that.
*
* Other changes:
*
* 1. FAT32 partitions are indicated by partition types 0xB and 0xC.
* 2. The boot sector is now 2 sectors, to make room for FAT32 extensions.
* 3. The root directory is no longer stored in a fixed location. Its'
* starting cluster is stored in the extended boot sector.
* 4. "Summary information" is now stored and we need to (at least) maintain
* the number of free clusters or scandisk will be upset. Though the
* sector this info is in is pointed to by the extensions in the boot
* sector, the magic offset of this information is just that so
* far - magic. 0x1e0.
* 5. FAT32 can use the alternate FAT. But we don't.
*
* FAT32 also exposed a latent bug: we bread() each copy of the FAT in one
* big chunk. This is not good on a large FAT32 drive, such as a 1 Gig
* Jaz drive that has 4k clusters, since the FAT becomes 1 Meg in size and
* bread blocks forever. So now we read the FAT in chunks.
*/
/*
* pre-FAT32 boot sector.
*/
struct bootsec {
};
/*
* FAT32 volumes have a bigger boot sector. They include the normal
* boot sector.
*/
struct fat32_bootsec {
};
#define FAT32_FS_SIGN 0x61417272
#define FAT32_BOOT_FSINFO_OFF 0x1e0
/*
* summary information for fat32 volumes. We need to maintain fs_free_clusters
* or Microsoft Scandisk will be upset.
*/
struct fat32_boot_fsinfo {
};
#define FSINFO_UNKNOWN (-1)
struct pcfs {
int pcfs_flags; /* flags */
int pcfs_ldrv; /* logical DOS drive number */
int pcfs_secsize; /* sector size in bytes */
int pcfs_spcl; /* sectors per cluster */
int pcfs_spt; /* sectors per track */
int pcfs_sdshift; /* shift to convert sector into */
/* DEV_BSIZE "sectors"; assume */
/* pcfs_secsize is 2**n times of */
/* DEV_BSIZE */
int pcfs_fatsec; /* number of sec per FAT */
int pcfs_numfat; /* number of FAT copies */
int pcfs_rdirsec; /* number of sec in root dir */
int pcfs_clsize; /* cluster size in bytes */
int pcfs_ncluster; /* number of clusters in fs */
int pcfs_entps; /* number of dir entry per sector */
int pcfs_nrefs; /* number of active pcnodes */
int pcfs_frefs; /* number of active file pcnodes */
int pcfs_nxfrecls; /* next free cluster */
int pcfs_fatsize; /* size of FAT data */
int pcfs_fat_changemapsize; /* size of FAT changemap */
int pcfs_count; /* # of pcfs locks for pcfs_owner */
int pcfs_fatjustread; /* Used to flag a freshly found FAT */
};
/*
* flags
*/
/* lowercase */
/* for compatibility */
struct old_pcfs_args {
int secondswest; /* seconds west of Greenwich */
int dsttime; /* type of dst correction */
};
struct pcfs_args {
int secondswest; /* seconds west of Greenwich */
int dsttime; /* type of dst correction */
int flags;
};
/*
* flags for the pcfs_args 'flags' field.
*
* Note that these two macros are obsolete - do not use them.
*/
/* lowercase */
/*
* pcfs mount options.
*/
#define MNTOPT_PCFS_HIDDEN "hidden"
#define MNTOPT_PCFS_NOHIDDEN "nohidden"
#define MNTOPT_PCFS_FOLDCASE "foldcase"
#define MNTOPT_PCFS_NOFOLDCASE "nofoldcase"
/*
* Disk timeout value in sec.
* This is used to time out the in core FAT and to re-verify the disk.
* This should be less than the time it takes to change floppys
*/
#define PCFS_DISKTIMEOUT 2
/*
* special cluster numbers in FAT
*/
/*
* file system constants
*/
/*
* file system parameter macros
*/
#define pc_clear_fatchanges(PCFS) \
((OFF) >= \
((PCFS)->pcfs_rdirsec & \
((PCFS)->pcfs_rdirsec & \
(PCFS)->pcfs_clsize): \
(PCFS)->pcfs_clsize)
(PCFS)->pcfs_sdshift)
((int)(CL) >= PCF_FIRSTCLUSTER && \
/*
* external routines.
*/
/*
* debugging
*/
extern int pcfsdebuglevel;
#define PC_DPRINTF0(level, A) \
if (pcfsdebuglevel >= level) \
#define PC_DPRINTF1(level, A, B) \
if (pcfsdebuglevel >= level) \
#define PC_DPRINTF2(level, A, B, C) \
if (pcfsdebuglevel >= level) \
#define PC_DPRINTF3(level, A, B, C, D) \
if (pcfsdebuglevel >= level) \
#define PC_DPRINTF4(level, A, B, C, D, E) \
if (pcfsdebuglevel >= level) \
#ifdef __cplusplus
}
#endif
#endif /* _SYS_FS_PC_FS_H */