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

📄 flashfs.c

📁 flash驱动程序,Nor flash类型
💻 C
📖 第 1 页 / 共 5 页
字号:
**  optionLen**** Returns:**  ESUCCESS    Option (possibly) parsed and in option.**  EINVAL      Option too long.**  ENOENT      No more options.****----------------------------------------------------------------------*/static int  flashfs_ParseOption (char **pBuffer, char *option, int optionLen){    int     rc;    char *  buffer;    buffer = *pBuffer;    if (*buffer == '\0' )    {        /*        ** End of string.        */        *pBuffer = NULL;        rc = ENOENT;    }    else if (optionLen < 2)    {        /*        ** Option buffer not large enough.        */        rc = EINVAL;    }    else    {        int length = 0;        rc = ESUCCESS;        while (*buffer != '\0')        {            if (*buffer == OPEN_FILESEP)            {                buffer++;                if (*buffer != OPEN_FILESEP)                {                    break;                }            }            /*            ** Length check arguments            */            if (length < optionLen)            {                option [length++] = *buffer++;            }            else            {                rc = EINVAL;                break;            }        }        if (ESUCCESS == rc)        {            /*            ** Terminate option just parsed and pass back modified buffer pointer.            */            option [length] = '\0';            *pBuffer = buffer;        }    }    return rc;}/***----------------------------------------------------------------------**** flashfs_ParseFilename:**** Parse a filename, peeling off attributes**** Arguments:**  filename    String to be parsed**  namebuffer  Where to store filename (FLASHFS_NAME_LENGTH long).**  partition   Where to store partition number**** Returns:**  ESUCCESS    Name parsed successfully**  EINVAL      Invalid filename string****----------------------------------------------------------------------*/static int  flashfs_ParseFilename (char *filename, char *namebuffer, U32 *partition){    int         rc;    OPENFILE    f;    PTR		    values [MAX_FLASHFS_ATTRIBUTES];    assert (NULL != filename);    assert (NULL != namebuffer);    assert (NULL != partition);    /*    ** Skip past any queue name.    */    if (*filename == OPEN_FILESEP)    {        filename = skipqueuename (filename);    }        /*    ** Allow partition to be set by attribute selection.    */    f.partition = NO_PARTITION;    flashfs_InitialiseAttributes (&f, &values [0]);    *namebuffer = '\0';    /*    ** Look for attributes and the filename.    */    do    {        char    option [64];        rc  = flashfs_ParseOption (&filename, option, sizeof (option));        if (rc == ESUCCESS)        {            char *  value = strchr (option, OPEN_KEYSEP);            if (NULL == value)            {                strncpy (namebuffer, option, FLASHFS_NAME_LENGTH);                namebuffer [FLASHFS_NAME_LENGTH - 1] = '\0';            }            else            {                *value++ = '\0';                rc = set_attribute (flashfsKeys, values, option, value);            }        }        else if (ENOENT == rc)        {            /*            ** Convert 'end of file' to success.            */            rc = ESUCCESS;        }    } while ((rc == ESUCCESS) && (filename != NULL));    /*    ** If no partition was set set, then use the current default    */    if (f.partition == NO_PARTITION)    {        *partition = currentDefaultPartition;    }    else    {        *partition = f.partition;    }    return  rc;}/***----------------------------------------------------------------------**** flashfs_OpenslotFind:**** Look for an empty slot for storing file handles, etc.**** Arguments:**	<None>      Look for an empty file slot.**** Returns:**  NULL        No slots available.**  <>NULL      Free slot.****----------------------------------------------------------------------*/static OPENFILE * flashfs_OpenslotFind (void){    int         i;    OPENFILE *  slot = NULL;    i = 0;    while ((slot == NULL) && ( i < FLASHFS_OPENS))    {        if (openfile [i].inuse)        {            i++;        }        else        {            slot = &openfile [i];        }    }    return  slot;    }/***----------------------------------------------------------------------**** flashfs_HasFilesOpen:**** See if any files are open on the specified partition.**** Arguments:**	partition   Partiton to check**** Returns:**  FALSE       No files open**  TRUE        Has files open****----------------------------------------------------------------------*/static BOOL flashfs_HasFilesOpen (U32 partition){    int     i = 0;    BOOL    rc = FALSE;    /*    ** Check that this filing system isn't actively in use.    */    while (!rc && (i < FLASHFS_OPENS))    {        if ((openfile [i].inuse) && (openfile [i].partition == partition))        {            rc = TRUE;        }        else        {            i++;        }    }    return  rc;}/***----------------------------------------------------------------------**** flashfs_Search:**** Look for a file in the specified list**** Arguments:**	list        Pointer to flash memory**  slot        Name details**  prev        Where to store pointer to previous file (if any)**** Returns:**  FALSE       No file found**  TRUE        File found****----------------------------------------------------------------------*/static BOOL flashfs_Search(U32 list, OPENFILE *slot, U32 *prev){    U32             next;    FLASHFS_DIRENT  entry;    BOOL            found = FALSE;    assert (NULL != slot);    next = CHECK_ADDR (list);    if (prev)    {        *prev = 0;    }    /* scan down specified linked list searching for the filename we want.  */    while (!found && (0 != next))    {        flash_read_fs_data(next, (BYTE *)&entry, sizeof entry);        if (strncmp(entry.name, slot->name, sizeof entry.name) == 0)         {            /*            ** Fill in location details            */            slot->fpos   = 0;            slot->fmax   = entry.len;            slot->datptr = next + sizeof entry - sizeof entry.data;            found = TRUE;        }        else        {            if (prev)            {                *prev = next;            }            next = CHECK_ADDR (entry.next);        }    }    return  found;}/***----------------------------------------------------------------------**** flashfs_Find:**** Look for a file in the current FLASHFS**** Arguments:**  slot        Name details**  prev        Where to store pointer to previous file (if any)**  isDynamic   Where to list (fixed/dynamic)**** Returns:**  FALSE       No file found**  TRUE        File found****----------------------------------------------------------------------*/static BOOL flashfs_Find (OPENFILE *slot, U32 *prev, BOOL *isDynamic){    BOOL    found;    assert (NULL != slot);    assert (NULL != isDynamic);    if (flashfs_Search (flashfsRoot.first.dynamic, slot, prev))    {        *isDynamic = TRUE;        found = TRUE;    }    else if (flashfs_Search (flashfsRoot.first.fixed, slot, prev))    {        *isDynamic = FALSE;        found = TRUE;    }    else    {        found = FALSE;    }        return  found;}/***----------------------------------------------------------------------**** flashfs_Last:**** Find the address of the last element in a list.**** Arguments:**  dataptr     List start**  isFixed     Whether the list refers to the fixed or dynamic list.**** Returns:**  U32****----------------------------------------------------------------------*/static U32  flashfs_Last (U32 dataptr, BOOL isFixed){    U32     last = dataptr;    while ((dataptr != 0) && CHECK_ADDR (dataptr))    {        FLASHFS_DIRENT  entry;        last = dataptr;        flash_read_fs_data (dataptr, (BYTE *) &entry, sizeof (entry));        dataptr = entry.next;        if ((dataptr == 0) && isFixed)        {            last += ALIGN_UP (entry.len + sizeof (FLASHFS_DIRENT));        }    }    return  last;}/***----------------------------------------------------------------------**** flashfs_SysInfo:**** Return information about a flashfs partition**** Arguments:**  partition   Partition about which to read information.**  fsinfobuf   Where to store information about the partition.**** Returns:**  ESUCCESS    fsinfobuf updated**  <>ESUCCESS  Error when obtaining the information.****----------------------------------------------------------------------*/static int  flashfs_SysInfo (U32 partition, struct fsinfo *fsinfobuf){    U32     start;    memset (fsinfobuf, 0, sizeof(struct fsinfo));    fsinfobuf->blocks = flashfsSize;    fsinfobuf->used = 0;    if (ESUCCESS == flashfslib_PartitionValid (partition))    {        /*        ** Size each list (fixed and dynamic), allowing, for the alignment of file blocks.        ** Note that because one list grows up and the other down we have to use separate code        ** to size each list.        */        start = flashfsRoot.first.fixed;        if (0 == start)        {            fsinfobuf->used += ALIGN_UP (sizeof (FLASHFS_ROOT));        }        else        {            fsinfobuf->used += flashfs_Last (start, TRUE);        }        start = flashfsRoot.first.dynamic;        if (0 == start)        {            fsinfobuf->used += ALIGN_UP (sizeof (FLASH_HEADER));        }        else        {            fsinfobuf->used += flashfsSize - flashfs_Last (start, FALSE);        }        fsinfobuf->isValid = TRUE;    }    else    {        fsinfobuf->isValid = FALSE;    }    fsinfobuf->blocksize = 1;    fsinfobuf->dynamicAllocation = FALSE;    return  ESUCCESS;}/***----------------------------------------------------------------------**** flashfs_RemoveFile:**** Remove a file.**** Arguments:

⌨️ 快捷键说明

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