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

📄 fdi_ext.c

📁 Flash file system
💻 C
📖 第 1 页 / 共 5 页
字号:
       WRITE_APPEND)  ||
#if (PACKET_DATA == TRUE)
          (cmd_cntrl->sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
          (cmd_cntrl->sub_command == WRITE_RESERVED)))
   {
      /* Maximum size, in bytes, that a fragment can be before an overflow of
         the group table can occur.  */
      if( (cmd_cntrl->offset + cmd_cntrl->count)>
          (MAX_GRP_UNIT_ENTRIES*MAX_SEQ_ENTRY*
           UNIT_GRANULARITY*MAX_NUM_UNITS_PER_FRAG) )
      {
         /*
          * unlock the global_sem_cntrl_mutex to give others access to the
          * globals
          */
         /* Unlock the API_sem_cntrl_mutex. */
         /* E5.0.642 START */
         /* Do not post a semaphore that has not been taken */
         /* SEM_MTX_POST(SEM_APIMutexSemaphore); */
         /* E5.0.642 END */
         return ERR_MAXITEMSIZE;
      }
/* this data size check for reserve will result in early report of
 * ERR_MAXITEMSIZE. So it is removed from here. A more accurate check
 * has been added to BKGD_CheckForSpace
 */
/* move the data size check to BLKGD_CheckForSpace */
   }
#endif /* if INCLUDE_FRAGMENTED_DATA */

   /* Check to see if a data parameter or stream is not open. */
   /* lock the API_sem_cntrl_mutex. */
   SEM_MTX_WAIT(SEM_APIMutexSemaphore);

#if (PACKET_DATA == TRUE)
   if ( FDI_Pckt.ID != WORDMAX && FDI_Pckt.ID == cmd_cntrl->identifier &&
        FDI_Pckt.type == cmd_cntrl->type &&
        cmd_cntrl->sub_command != WRITE_RSRVPCKT )
   {
      SEM_MTX_POST(SEM_APIMutexSemaphore);
      return ERR_PCKTID_MUTEX;
   }
#endif /* PACKET_DATA */
   /*
    * Look into the FDI_DataLookupTable and assign the first free
    * identifier to the new data being created.
    */
   if (cmd_cntrl->identifier == NEW_DATA_STREAM_ID)
   {
      /* Check if the offset specified is zero for the first append. */
      if (cmd_cntrl->offset != 0)
      {
         /*
          * unlock the global_sem_cntrl_mutex to give others access to the
          * globals
          */
         /* Unlock the API_sem_cntrl_mutex. */
         SEM_MTX_POST(SEM_APIMutexSemaphore);
         return ERR_PARAM;
      }

      /* lock the global_sem_cntrl_mutex. */
      SEM_MTX_WAIT(SEM_LookupTable);

      /* Scan the data lookup table. */

   /* ERASE_COUNT_ID changed from type 14 ID 0 to type 14 ID NUM_TYPE14_PARMS */
      start = 0;

      for (index = start; index < NUM_PARMS[cmd_cntrl->type]; index++)
      {
         if (EMPTY_LOOKUP_TABLE(cmd_cntrl->type, index))
         {
            cmd_cntrl->identifier = index;
            break;
         }
      }


      /* unlock the global_sem_cntrl_mutex. */
      SEM_MTX_POST(SEM_LookupTable);

      if (index >= NUM_PARMS[cmd_cntrl->type])
      {
         /*
          * unlock the global_sem_cntrl_mutex to give others access to the
          * globals
          */
         /* Unlock the API_sem_cntrl_mutex. */
         SEM_MTX_POST(SEM_APIMutexSemaphore);

         return ERR_MAX_EXISTS;
      }
   }
   /*
    * Verify that the data exists and update the FDI_GetDataFound structure
    * with appropriate data information.
    */
   if (DataFind(cmd_cntrl->identifier, cmd_cntrl->type,
                GET_MATCHED) != ERR_NONE)
   {

      /* Tried to append to the data parameter that is not yet created. */
      if ((cmd_cntrl->sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
          (cmd_cntrl->sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
          (cmd_cntrl->sub_command == WRITE_RESERVED))
      {

         /* Check if the offset specified is zero for the first append. */
         if (cmd_cntrl->offset != 0)
         {
            /*
             * unlock the global_sem_cntrl_mutex to give others access to the
             * globals
             */
            /* Unlock the API_sem_cntrl_mutex. */
            SEM_MTX_POST(SEM_APIMutexSemaphore);

            return ERR_PARAM;
         }

      }

      /* Tried to replace or modify the data that does not exist. */
      else if ((cmd_cntrl->sub_command == WRITE_REPLACE) ||
               (cmd_cntrl->sub_command == WRITE_MODIFY))
      {
         /*
          * unlock the global_sem_cntrl_mutex to give others access to the
          * globals
          */
         /* Unlock the API_sem_cntrl_mutex. */
         SEM_MTX_POST(SEM_APIMutexSemaphore);
         return ERR_NOTEXISTS;
      }
   }
   else
   {
      data_found = 1;
   }


   if (data_found == 1)
   {
      /*
       * the data offset into the data stream(file) being accessed to begin
       * next access
       */

      status = GetDataSize(&size,
                           cmd_cntrl->identifier,
                           cmd_cntrl->type, cmd_cntrl->priority);
      if (status != ERR_NONE)
      {
         /*
          * unlock the global_sem_cntrl_mutex to give others access to the
          * globals
          */
         /* Unlock the API_sem_cntrl_mutex. */
         SEM_MTX_POST(SEM_APIMutexSemaphore);

         return status;
      }

      if ((cmd_cntrl->sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
          (cmd_cntrl->sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
          (cmd_cntrl->sub_command == WRITE_RESERVED))
      {

         if ((cmd_cntrl->offset > size) || ((cmd_cntrl->offset == 0) &&
                                            (size != 0)))
         {
            /*
             * unlock the global_sem_cntrl_mutex to give others access to the
             * globals
             */
            /* Unlock the API_sem_cntrl_mutex. */
            SEM_MTX_POST(SEM_APIMutexSemaphore);
            return ERR_PARAM;
         }
         if (size > UNIT_GRANULARITY)
         {

            if (cmd_cntrl->offset <
                ((size - UNIT_GRANULARITY) + ((((size / UNIT_GRANULARITY) +
                                  ((size % UNIT_GRANULARITY != 0) ? 1 : 0)) *
                                             UNIT_GRANULARITY) - size)))
            {
               /*
                * unlock the global_sem_cntrl_mutex to give others access to
                * the globals
                */
               /* Unlock the API_sem_cntrl_mutex. */
               SEM_MTX_POST(SEM_APIMutexSemaphore);

               return ERR_PARAM;
            }
         }
      }
      else
      {
         if ((cmd_cntrl->offset > size) ||
             ((cmd_cntrl->offset + cmd_cntrl->count) > size))
         {
            /*
             * unlock the global_sem_cntrl_mutex to give others access to the
             * globals
             */
            /* Unlock the API_sem_cntrl_mutex. */
            SEM_MTX_POST(SEM_APIMutexSemaphore);

            return ERR_PARAM;
         }
      }
   }


   /*
    * Fillup the local command and data structure buffers to be added in the
    * queue.
    */
   command_buffer.identifier = cmd_cntrl->identifier;
   command_buffer.data_offset = cmd_cntrl->offset;
   command_buffer.sub_command = cmd_cntrl->sub_command;
   command_buffer.priority = cmd_cntrl->priority;
   command_buffer.type = cmd_cntrl->type;


   /*
    * if this is not a new data parameter and we are doing an append, but the
    * size is not changing, we are effectively doing a replace which will
    * dirty as much  as it uses. This means we don't need to account for
    * threshold
    */

   if (((command_buffer.sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
        (command_buffer.sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
        (command_buffer.sub_command == WRITE_RESERVED)) &&
       (command_buffer.data_offset != 0))
   {
      initial_gran = TO_SIZE(command_buffer.data_offset, UNIT_GRANULARITY);
      new_gran = TO_SIZE((command_buffer.data_offset + cmd_cntrl->count), \
                         UNIT_GRANULARITY);
      if (new_gran <= initial_gran)
      {
         append_to_replace_flag = TRUE;
      }
   }

   /*
    * IF there is not enough space available to write this data THEN return
    * ERR_FLASH_FULL immediately
    */
#if (FREE_SPACE_FUNCTIONS == TRUE)
   hw_status = BKGD_CheckForSpace(&command_buffer, (WORD) cmd_cntrl->count,
                                  TRUE,NORMAL_CALCCHK);
#else   /* !FREE_SPACE_FUNCTIONS */
   hw_status = BKGD_CheckForSpace(&command_buffer, (WORD) cmd_cntrl->count,
                                  TRUE);
#endif   /* FREE_SPACE_FUNCTIONS */
   if ( hw_status != HW_ERR_NONE)
   {
      /*
       * unlock the global_sem_cntrl_mutex to give others access to the
       * globals
       */
      SEM_MTX_POST(SEM_APIMutexSemaphore); /* Unlock the API_sem_cntrl_mutex. */
      /* test for different error conditions from CheckForSpace */
      if (hw_status == HW_ERR_PARAM)
      {
         return ERR_PARAM;
      }
      else if (hw_status == HW_ERR_FLASH_FULL)
      {
         return ERR_FLASH_FULL;
      }
      else if (hw_status == HW_ERR_WRITE)
      {
         return ERR_MAXITEMSIZE;
      }
      else
         return ERR_SYSTEM;
   }

   SEM_MTX_WAIT(SEM_LookupTable);

   /*
    * Pass the pointer to command control structure, through the q_add routine
    * that adds the structure to the queue.
    */
   q_status = Q_Add((Q_ID) FDI_QueueIdentifier, (VOID_PTR) & command_buffer,
                    (VOID_PTR) cmd_cntrl->buffer_ptr, (WORD) sizeof(COMMAND),
                    (WORD) cmd_cntrl->count, cmd_cntrl->priority,
                    append_to_replace_flag);

   if (q_status != Q_ERR_NONE)
   {
      /*
       * unlock the global_sem_cntrl_mutex to give others access to the
       * globals
       */
      SEM_MTX_POST(SEM_LookupTable);
      /* Unlock the API_sem_cntrl_mutex. */
      SEM_MTX_POST(SEM_APIMutexSemaphore);
      if (q_status != Q_ERR_NO_MEMORY)
      {

         if (q_status == Q_ERR_PARAM)
         {

            return ERR_PARAM;
         }
         return ERR_Q_FULL;
      }
      else
      {

         return ERR_SYSTEM;
      }
   }

   if ((cmd_cntrl->sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
          (cmd_cntrl->sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
          (cmd_cntrl->sub_command == WRITE_RESERVED))
   {
      /*
       * IF we are using open
       * THEN set the FDI_OpenTotalSize global variable
       */
      SEM_MTX_WAIT(SEM_LookupTable);
      size =
         (DWORD)LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier);

      SEM_MTX_POST(SEM_LookupTable);
      if ((BYTE)size != BYTEMAX)
      {
         SEM_MTX_WAIT(SEM_TotalSize);
         FDI_OpenTotalSize[LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier)]
                                       = cmd_cntrl->offset + cmd_cntrl->count;
         if (((cmd_cntrl->offset + cmd_cntrl->count) % UNIT_GRANULARITY) != 0)
         {
            FDI_OpenTotalSize[LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier)] +=
                                                       GRAN_REMAINING(cmd_cntrl->offset +
                                                       cmd_cntrl->count);
         }
         SEM_MTX_POST(SEM_TotalSize);
      }
   }

   /*
    * are there any race conditions by incrementing q sizes after releasing
    * the queue semaphore
    */
   /* as above then changing to FType? */
   if (((cmd_cntrl->sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
     (cm

⌨️ 快捷键说明

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