⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fatlite.c

📁 cpc-1631的BSP包for VxWorks操作系统
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 * $Log:   P:/user/amir/lite/vcs/fatlite.c_v  $
 *
 *    Rev 1.46   06 Oct 1997 19:44:58   danig
 * COPY2
 *
 *    Rev 1.45   06 Oct 1997 10:28:54   danig
 * Check that drive handle < noOfDrives
 *
 *    Rev 1.44   29 Sep 1997 16:00:50   danig
 * Take the no. of hidden sectors from partition table in getBPB
 *
 *    Rev 1.43   29 Sep 1997 14:20:16   danig
 * flExitSocket & check findSector() return value
 *
 *    Rev 1.43   28 Sep 1997 19:08:02   danig
 * flExitSocket & check findSector return value
 *
 *    Rev 1.42   10 Sep 1997 17:51:40   danig
 * Got rid of generic names  &
 * big-endian + unaligned in replaceFATsector
 *
 *    Rev 1.41   04 Sep 1997 18:29:08   danig
 * Debug messages
 *
 *    Rev 1.40   02 Sep 1997 15:29:30   danig
 * Fixed flushBuffer for SINGLE_BUFFER
 *
 *    Rev 1.39   21 Aug 1997 14:06:20   unknown
 * Unaligned4
 *
 *    Rev 1.38   19 Aug 1997 20:05:38   danig
 * Andray's changes
 *
 *    Rev 1.37   17 Aug 1997 17:32:32   danig
 * Mutual exclusive mounting
 *
 *    Rev 1.37   17 Aug 1997 16:51:08   danig
 * Mutual exclusive mounting
 *
 *    Rev 1.36   14 Aug 1997 15:49:46   danig
 * Change in low level routines
 *
 *    Rev 1.35   04 Aug 1997 13:26:30   danig
 * Low level API & no irHandle in formatVolume
 *
 *    Rev 1.34   27 Jul 1997 14:35:58   danig
 * FAR -> FAR0 in split\joinFile
 *
 *    Rev 1.33   27 Jul 1997 11:59:24   amirban
 * Socket.volNo initialization
 *
 *    Rev 1.32   27 Jul 1997 10:12:32   amirban
 * replaceFATSector and name changes
 *
 *    Rev 1.30   21 Jul 1997 20:01:50   danig
 * Compilation issues
 *
 *    Rev 1.29   20 Jul 1997 18:44:10   danig
 *
 *    Rev 1.28   20 Jul 1997 18:34:50   danig
 * Fixed findFile with SET_ATTRIBUTES bug
 *
 *    Rev 1.27   20 Jul 1997 17:16:46   amirban
 * No watchDogTimer
 *
 *    Rev 1.26   07 Jul 1997 15:21:02   amirban
 * Ver 2.0
 *
 *    Rev 1.24   29 May 1997 14:59:00   amirban
 * Dismount closes files on one drive only
 *
 *    Rev 1.23   28 May 1997 18:51:28   amirban
 * setBusy(OFF) always
 *
 *    Rev 1.22   20 Apr 1997 10:48:50   danig
 * Fixed bug: fsFindFirstFile when subdirectories are undefined.
 *
 *    Rev 1.21   09 Apr 1997 17:35:42   amirban
 * Partition table redefined
 *
 *    Rev 1.20   31 Mar 1997 18:02:38   amirban
 * BPB redefined
 *
 v    Rev 1.19   03 Nov 1996 17:40:14   amirban
 * Correction for single-buffer
 *
 *    Rev 1.17   21 Oct 1996 18:10:20   amirban
 * Defragment I/F change
 *
 *    Rev 1.16   17 Oct 1996 18:56:36   danig
 * added big-endian to splitFile and joinFile
 *
 *    Rev 1.15   17 Oct 1996 16:21:46   danig
 * Audio features: splitFile, joinFile
 *
 *    Rev 1.14   17 Oct 1996 12:39:08   amirban
 * Buffer FAT sectors
 *
 *    Rev 1.13   03 Oct 1996 11:56:24   amirban
 * New Big-Endian
 *
 *    Rev 1.12   09 Sep 1996 11:38:52   amirban
 * Introduce sectorNotFound errors
 *
 *    Rev 1.11   29 Aug 1996 14:16:48   amirban
 * Warnings
 *
 *    Rev 1.10   20 Aug 1996 13:22:52   amirban
 * fsGetBPB
 *
 *    Rev 1.9   12 Aug 1996 15:46:26   amirban
 * Use setBusy instead of socketSetBusy
 *
 *    Rev 1.8   31 Jul 1996 14:29:58   amirban
 * Background stuff, and current file size in fsFindFile
 *
 *    Rev 1.7   14 Jul 1996 16:48:12   amirban
 * Format params
 *
 *    Rev 1.6   01 Jul 1996 15:41:26   amirban
 * new fsInit and modified fsGetDiskInfo
 *
 *    Rev 1.5   16 Jun 1996 14:04:06   amirban
 * Format does not need mounting
 *
 *    Rev 1.4   09 Jun 1996 18:15:42   amirban
 * Added fsExit, and VFAT rename mode
 *
 *    Rev 1.3   03 Jun 1996 16:26:24   amirban
 * Separated fsParsePath, and rename-file change
 *
 *    Rev 1.2   19 May 1996 19:31:46   amirban
 * Got rid of aliases in IOreq, and better fsParsePath
 *
 *    Rev 1.1   12 May 1996 20:05:26   amirban
 * Changes to findFile
 *
 *    Rev 1.0   20 Mar 1996 13:33:06   amirban
 * Initial revision.
 */

/************************************************************************/
/*                                                                      */
/*		FAT-FTL Lite Software Development Kit			*/
/*		Copyright (C) M-Systems Ltd. 1995-1996			*/
/*									*/
/************************************************************************/


#include "fltl.h"
#include "flsocket.h"
#include "dosformt.h"
#include "backgrnd.h"
#include "flbuffer.h"
#include "stdcomp.h"
#include "fatlite.h"

volatile unsigned long flMsecCounter = 0;

/* Volume flag definitions */

#define VOLUME_LOW_LVL_MOUNTED  1       /* volume is mounted for low level operations */
#define	VOLUME_MOUNTED		2	/* Volume is mounted */
#define VOLUME_12BIT_FAT	4	/* Volume uses 12-bit FAT */
#define	VOLUME_ABS_MOUNTED	8	/* Volume is mounted for abs calls */

typedef struct {
  char		flags;			/* See description above */

  unsigned	sectorsPerCluster;	/* Cluster size in sectors */
  unsigned	maxCluster;		/* highest cluster no. */
  unsigned	bytesPerCluster;	/* Bytes per cluster */
  unsigned	bootSectorNo;		/* Sector no. of DOS boot sector */
  unsigned	firstFATSectorNo;	/* Sector no. of 1st FAT */
  unsigned	secondFATSectorNo;	/* Sector no. of 2nd FAT */
  unsigned	numberOfFATS;		/* number of FAT copies */
  unsigned	sectorsPerFAT;		/* Sectors per FAT copy */
  unsigned	rootDirectorySectorNo;	/* Sector no. of root directory */
  unsigned	sectorsInRootDirectory;	/* No. of sectors in root directory */
  unsigned	firstDataSectorNo;	/* 1st cluster sector no. */
  unsigned	allocationRover;	/* rover pointer for allocation */

#ifndef SINGLE_BUFFER
  #if FILES > 0
  FLBuffer	volBuffer;		/* Define a sector buffer */
  #endif
  FLMutex	volExecInProgress;
#endif

/* #ifdef LOW_LEVEL */
  FLFlash 	flash;			/* flash structure for low level operations */
/* #endif */

  TL		tl;			/* Translation layer methods */
  FLSocket	*socket;		/* Pointer to socket */
} Volume;


static FLBoolean initDone = FALSE;	/* Initialization already done */

static Volume 	vols[DRIVES];


typedef struct {
  long		currentPosition;	/* current byte offset in file */
#define		ownerDirCluster currentPosition	/* 1st cluster of owner directory */
  long 		fileSize;		/* file size in bytes */
  SectorNo	directorySector;	/* sector of directory containing file */
  unsigned      currentCluster;		/* cluster of current position */
  unsigned char	directoryIndex;		/* entry no. in directory sector */
  unsigned char	flags;			/* See description below */
  Volume *	fileVol;		/* Drive of file */
} File;

/* File flag definitions */

#define	FILE_MODIFIED		4	/* File was modified */
#define FILE_IS_OPEN		8	/* File entry is used */
#define	FILE_IS_DIRECTORY    0x10	/* File is a directory */
#define	FILE_IS_ROOT_DIR     0x20	/* File is root directory */
#define	FILE_READ_ONLY	     0x40	/* Writes not allowed */
#define	FILE_MUST_OPEN       0x80	/* Create file if not found */


#if FILES > 0
static File 	fileTable[FILES];	/* the file table */

#endif	/* FILES > 0 */

#ifdef SINGLE_BUFFER

FLBuffer buffer;
FLMutex execInProgress;

#else

#define buffer (vol.volBuffer)
#define execInProgress (vol.volExecInProgress)

#endif

#define directory ((DirectoryEntry *) buffer.data)



/*----------------------------------------------------------------------*/
/*      	           s e t B u s y				*/
/*									*/
/* Notifies the start and end of a file-system operation.		*/
/*									*/
/* Parameters:                                                          */
/*	vol		: Pointer identifying drive			*/
/*      state		: TFFS_ON (1) = operation entry			*/
/*			  TFFS_OFF(0) = operation exit			*/
/*                                                                      */
/*----------------------------------------------------------------------*/

static FLStatus setBusy(Volume vol, FLBoolean state)
{
  if (state == TFFS_ON) {
    if (!flTakeMutex(&execInProgress,1))
      return flDriveNotAvailable;
    flSocketSetBusy(vol.socket,TFFS_ON);
    flNeedVcc(vol.socket);
    if (vol.flags & VOLUME_ABS_MOUNTED)
      vol.tl.tlSetBusy(vol.tl.rec,TFFS_ON);
  }
  else {
    if (vol.flags & VOLUME_ABS_MOUNTED)
      vol.tl.tlSetBusy(vol.tl.rec,TFFS_OFF);
    flDontNeedVcc(vol.socket);
    flSocketSetBusy(vol.socket,TFFS_OFF);
    flFreeMutex(&execInProgress);
  }

  return flOK;
}



/*----------------------------------------------------------------------*/
/*		          f i n d S e c t o r				*/
/*									*/
/* Locates a sector in the buffer or maps it				*/
/*                                                                      */
/* Parameters:                                                          */
/*	vol		: Pointer identifying drive			*/
/*	sectorNo	: Sector no. to locate				*/
/*                                                                      */
/*----------------------------------------------------------------------*/


static const void FAR0 *findSector(Volume vol, SectorNo sectorNo)
{
CardAddress *physAddress =0;
  return
#if FILES > 0
	 (sectorNo == buffer.sectorNo && &vol == buffer.owner) ?
	 buffer.data :
#endif
	 vol.tl.mapSector(vol.tl.rec,sectorNo, physAddress);
}


#if FILES > 0
static FLStatus closeFile(File *file);	/* forward */
static FLStatus flushBuffer(Volume vol);	/* forward */
#endif

/*----------------------------------------------------------------------*/
/*		      d i s m o u n t V o l u m e			*/
/*									*/
/* Dismounts the volume, closing all files.				*/
/* This call is not normally necessary, unless it is known the volume   */
/* will soon be removed.						*/
/*									*/
/* Parameters:                                                          */
/*	vol		: Pointer identifying drive			*/
/*                                                                      */
/* Returns:                                                             */
/*	FLStatus	: 0 on success, otherwise failed                */
/*----------------------------------------------------------------------*/

static FLStatus dismountVolume(Volume vol)
{
#if FILES > 0
  int i;
#endif

  if (vol.flags & VOLUME_ABS_MOUNTED) {
    FLStatus status = flOK;
#ifndef FIXED_MEDIA
    status = flMediaCheck(vol.socket);
#endif
    if (status != flOK)
      vol.flags = 0;
#if FILES > 0
    else {
      checkStatus(flushBuffer(&vol));
    }

    /* Close or discard all files and make them available */
    for (i = 0; i < FILES; i++)
      if (fileTable[i].fileVol == &vol)
	if (vol.flags & VOLUME_MOUNTED)
	  closeFile(&fileTable[i]);
	else
	  fileTable[i].flags = 0;

    vol.tl.dismount(vol.tl.rec);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -