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

📄 ssfdc.c

📁 truefs for vxworks, make fs on flash or rom
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * $Log:   V:/ssfdc.c_v  $ * *    Rev 1.17   01 Mar 1998 12:59:30   amirban * Add parameter to mapSector * *    Rev 1.16   29 Sep 1997 14:17:28   danig * Call setBusy(OFF) from dismount function * *    Rev 1.15   18 Sep 1997 10:11:42   danig * Warnings * *    Rev 1.14   10 Sep 1997 16:21:16   danig * Got rid of generic names * *    Rev 1.13   10 Sep 1997 13:32:20   danig * Limit number of virtual units * *    Rev 1.12   04 Sep 1997 15:52:46   danig * Debug messages * *    Rev 1.11   04 Sep 1997 11:07:52   danig * Share buffer with MTD * *    Rev 1.10   28 Jul 1997 15:13:34   danig * volForCallback & moved standard typedefs to flbase.h * *    Rev 1.9   27 Jul 1997 14:04:18   danig * FAR -> FAR0 * *    Rev 1.8   24 Jul 1997 15:14:18   danig * Fixed ECC on read * *    Rev 1.7   20 Jul 1997 11:01:52   danig * Ver 2.0 * *    Rev 1.6   13 Jul 1997 10:51:58   danig * erasedSectors * *    Rev 1.5   01 Jul 1997 15:36:32   danig * Changes to isErasedSector & isErasedUnit * *    Rev 1.4   29 Jun 1997 16:13:02   danig * Comments * *    Rev 1.3   12 Jun 1997 17:41:54   danig * ECC on read, use second address area. * *    Rev 1.2   08 Jun 1997 19:05:24   danig * Delete sector bug & check for mount in setBusy() * *    Rev 1.1   01 Jun 1997 13:42:36   amirban * Use ftllite.h I/F * *    Rev 1.0   15 Apr 1997 17:56:26   danig * Initial revision. *//************************************************************************//*                                                                      *//*		FAT-FTL Lite Software Development Kit			*//*		Copyright (C) M-Systems Ltd. 1995-1997			*//*									*//************************************************************************/#include "fltl.h"#include "flflash.h"#include "flbuffer.h"/* VF: This macro is vital to supporting devices with 32 or more sectors per erase       unit.  Data types and code coming originally from M-Systems only provided       for up to 16 sectors per erase unit.  Some data types had bit fields that       depended on the number of sectors per erase unit not exceeding 16.       Several data type and code modifications have been made based on the value       of this macro to accomodate larger erase unit sized devices.*/#define TFFS_SECTORS_PER_UNIT  32typedef long int VirtualAddress;/* VF: Updated PhysUnit storage type.  As used below in the Unit type,       a PhysUnit only provided 8 bits of storage:  The upper 3 bits were       used to bookkeep sector status, and the low 5 bits represented a count       of sectors free in the unit.  5 bits only counts up to 31.  We need more       bits for the count, hence the increase in size of this data type.*/#if (TFFS_SECTORS_PER_UNIT < 32)typedef unsigned char PhysUnit;#elsetypedef unsigned short PhysUnit;#endiftypedef unsigned short UnitNo;#define FORMAT_PATTERN 1, 3, 0xd9, 1, 0xff, 0x18, 2, 0xdf, 1, 0x20#define CIS_DATA 0x1, 0x3, 0xd9, 0x1, 0xff, 0x18, 0x2, 0xdf, 0x1, \0x20, 0x4, 0x0, 0x0, 0x0, 0x0, 0x21, 0x2, \0x4, 0x1, 0x22, 0x2, 0x1, 0x1, 0x22, 0x3, \0x2, 0x4, 0x7, 0x1a, 0x5, 0x1, 0x3, 0x0, \0x2, 0xf, 0x1b, 0x8, 0xc0, 0xc0, 0xa1, 0x1, \0x55, 0x8, 0x0, 0x20, 0x1b, 0xa, 0xc1, 0x41, \0x99, 0x1, 0x55, 0x64, 0xf0, 0xff, 0xff, 0x20, \0x1b, 0xc, 0x82, 0x41, 0x18, 0xea, 0x61, 0xf0, \0x1, 0x7, 0xf6, 0x3, 0x1, 0xee, 0x1b, 0xc, \0x83, 0x41, 0x18, 0xea, 0x61, 0x70, 0x1, 0x7, \0x76, 0x3, 0x1, 0xee, 0x15, 0x14, 0x5, 0x0, \0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0, \0x20, 0x20, 0x20, 0x20, 0x0, 0x30, 0x2e, 0x30, \0x0, 0xff, 0x14, 0x0, 0xff, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0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1b, 0xc, \0x83, 0x41, 0x18, 0xea, 0x61, 0x70, 0x1, 0x7, \0x76, 0x3, 0x1, 0xee, 0x15, 0x14, 0x5, 0x0, \0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0, \0x20, 0x20, 0x20, 0x20, 0x0, 0x30, 0x2e, 0x30, \0x0, 0xff, 0x14, 0x0, 0xff, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, \0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0#define SECTOR_ERASED		1#define SECTOR_ALLOCATED        2#define SECTOR_REPLACED		3#define SECTOR_DELETED1		0x80#define SECTOR_DELETED2		0xf0#define SECTORS_PER_UNIT 16  /* default number of sectors per unit *//*#define ECC_ON_READ*/#define UNASSIGNED_ADDRESS 0xffffffffl/* VF: Due to the increase in size of PhysUnit above from 8 to 16 bits, these macros       must be adjusted accordingly to represent the upper 3 bits of a 16-bit quantity.*/#if (TFFS_SECTORS_PER_UNIT < 32)#define UNIT_FREE	0xe0   /* unassigned unit */#define	UNIT_AVAILABLE	0x80   /* assigned unit */#define UNIT_ERASED	0xc0   /* unit is erased */#define UNIT_BAD	0      /* unit is defective */#define STATUS_MASK	0xe0   /* the unit status is in the 3 MSBs */#else#define UNIT_FREE	0xe000   /* unassigned unit */#define	UNIT_AVAILABLE	0x8000   /* assigned unit */#define UNIT_ERASED	0xc000   /* unit is erased */#define UNIT_BAD	0x0000   /* unit is defective */#define STATUS_MASK	0xe000   /* the unit status is in the 3 MSBs */#endif/* extra area of odd pages is read before extra area of even pages   when page size is 256 */#define STATUS_AREA_OFFSET      ((vol.flash.flags & BIG_PAGE) ? 4 : 12)#define BLOCK_ADDRESS_OFFSET1   ((vol.flash.flags & BIG_PAGE) ? 6 : 14)#define BLOCK_ADDRESS_OFFSET2   ((vol.flash.flags & BIG_PAGE) ? 11 : 3)#define CIS_DATA_OFFSET		((vol.flash.flags & BIG_PAGE) ? 4 : 12)#define ECC1			((vol.flash.flags & BIG_PAGE) ? 13 : 5)#define ECC2			((vol.flash.flags & BIG_PAGE) ? 8 : 0)#define OFFSET1 1#define OFFSET2 2#define INCORRECT_DATA	0#define CORRECT_DATA	0xff#define NO_UNIT 0xfffftypedef struct {  PhysUnit unitStatus;             /* unit status in the 3 MSBs, unassigned */				   /* sectors counter in the rest of the bits. *//* VF: Updated next line.  This is a bit-field, so we need 32 bits to represent sectors: */#if (TFFS_SECTORS_PER_UNIT < 32)  unsigned short erasedSectors;    /* if bit i=1, sector i in the unit is erased. */#else  unsigned long erasedSectors;     /* if bit i=1, sector i in the unit is erased. */#endif} Unit;typedef struct  {  unsigned char sectorStatus;  unsigned char unitStatus;} StatusArea;typedef enum {BAD_FORMAT, SSFDC_FORMAT, ANAND_FORMAT} FormatType;#ifndef MALLOC_TFFS#define HEAP_SIZE	(0x100000l / ASSUMED_NFTL_UNIT_SIZE) *       \			(sizeof(UnitNo) + sizeof(Unit)) *  	\			MAX_VOLUME_MBYTES + SECTORS_PER_UNIT#endifstruct tTLrec {  FLBoolean	    badFormat;		/* true if TFFS format is bad */  UnitNo	    CISblock;           /* Unit no. of CIS block */  unsigned int	    erasableBlockSizeBits;  /* log2 of erasable block size */  UnitNo	    noOfVirtualUnits;  UnitNo	    freeUnits;              /* number of unassigned units */  unsigned long     unitOffsetMask;  unsigned int	    sectorsPerUnit;  UnitNo	    noOfUnits;  unsigned int	    unitSizeBits;  SectorNo	    virtualSectors;  UnitNo            roverUnit;          /* Starting point for allocation search */  UnitNo	    transferUnit;  UnitNo	    replacedUnit;  unsigned int	    sectorsDeleted;     /* number of sector deleted in the					   replaced unit */  Unit 		    *physicalUnits; 	/* unit table by physical no. */  UnitNo	    *virtualUnits; 	/* unit table by logical no. */  unsigned char	    *replacementSectors; /* a table of the sectors in the					    replaced unit */  SectorNo 	    mappedSectorNo;  void FAR0         *mappedSector;  CardAddress	    mappedSectorAddress;  FLFlash	    flash;  FLBuffer          *buffer;#ifndef MALLOC_TFFS  char		    heap[HEAP_SIZE];#endif};#define ssfdcBuffer  vol.buffer->datatypedef TLrec SSFDC;static SSFDC vols[DRIVES];/********************** ECC\EDC part ******************************//*----------------------------------------------------------------------*//*		         c h a r P a r i t y				*//*									*//* Get odd parity of one byte.						*//*                                                                      *//* Parameters:                                                          *//*	c		: One byte of data.				*//*                                                                      *//* Returns:                                                             *//*	Odd parity.							*//*----------------------------------------------------------------------*/static unsigned char charParity(unsigned char c){  unsigned char parityBit = 1;  for (; c; c >>= 1)    parityBit ^= c & 0x01;  return parityBit;}/*----------------------------------------------------------------------*//*		         c r e a t e E c c				*//*									*//* Calculate 22 bits Error correction \ detection code for 256 bytes    *//* of data. 16 bits line parity, 6 bits column parity. ECC scheme 	*//* according to SSFDC specification.					*//*                                                                      *//* Parameters:                                                          *//*	buf		: 256 bytes of data.				*//*	code		: 3 bytes of ECC.				*//*                                                                      *//*----------------------------------------------------------------------*/static void createEcc(unsigned char FAR0 *buf, unsigned char FAR0 *code){  unsigned char lineParity[16], columnParity[6], temp;  int i, k;  /* initialize to 1's, odd parity */  for (i = 0; i < 16; i++)    lineParity[i] = 0xff;  for (i = 0; i < 6; i++)    columnParity[i] = 1;  /* xor the lines */  for (i = 0; i < 256; i++)    for (k = 0; k < 8; k++)      if ((i / (1 << k)) % 2)	lineParity[2 * k + 1] ^= buf[i];      else	lineParity[2 * k] ^= buf[i];  temp = lineParity[0] ^ lineParity[1];  /* temp holds the xor of all the lines */  for(i = 0; i < 3; i++)    code[i] = 0;  /* get line parity */  for(i = 0; i < 16; i++)    if (charParity(lineParity[i]))      code[i / 8] |= (1 << (i % 8));  /* xor the columns */  for(i = 0; i < 8; i++)    for (k = 0; k < 3; k++)      if ((i / (1 << k)) % 2)	columnParity[2 * k + 1] ^= (temp & (0xff >> (7 -  i))) >> i;      else	columnParity[2 * k] ^= (temp & (0xff >> (7 -  i))) >> i;  code[2] |= 0x03;  /* bits 16 and 17 are always 1 */  /* get column parity */  for(i = 0; i < 6; i++)    if (columnParity[i])      code[2] |= 4 << i;}#ifdef ECC_ON_READ/*----------------------------------------------------------------------*//*		         i s F i x a b l e				*//*									*/

⌨️ 快捷键说明

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