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

📄 fdi_que.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
      FDI_FREE((BYTE_PTR) removed_ptr);
   }                                   /* ENDDO WHILE there are headers */

   /* deallocate memory for the descriptor structure */

#if (Q_ALIGN_CHECKING == TRUE)
   queue_ptr -= ((Q_DESC_PTR) queue_ptr)->alignment_shift;
#endif


   FDI_FREE((BYTE_PTR) queue_ptr);

   return Q_ERR_NONE;
}                                      /* END Q_Delete */


/*############################################################################
 *### Q_Remove
 *###
 *### DESCRIPTION:
 *### Removes the passed "data_ptr" object and associated item information
 *### structure.  If "data_ptr" is the last object in the queue, the
 *### associated priority header is also removed.
 *###
 *### PARAMETERS:
 *###    IN:
 *###       queue_id       -  remove the item in the queue with this handle
 *###       data_ptr       -  address of the item to remove
 *###       append_to_replace - flag; if true indicates the append is within
 *###                           an existing granularity, similar to replace
 *###    OUT:
 *###
 *### RETURNS:
 *###    Returns the following errors codes:
 *###       Q_ERR_NONE
 *###       Q_ERR_INVALID_HANDLE
 *###*/
Q_ERROR
Q_Remove(Q_ID queue_id, VOID_PTR data_ptr, BYTE append_to_replace)
{
   register Q_HDR_PTR removed_header_ptr = NULL;
   register Q_HDR_PTR header_ptr = NULL;
   register Q_DESC_PTR queue_ptr = (Q_DESC_PTR) queue_id;
   register Q_ITEM_PTR item_ptr = NULL;

#if (Q_VERIFICATION == TRUE)
   if (VALID_QUEUE_PTR(queue_ptr) == FALSE)  /* IF call ValidQueuePtr fails */
      return Q_ERR_INVALID_HANDLE;
#endif
   /*
    * assign the data item pointer to the beginning of the Q_ITEM_INFO
    * structure by subtracting the address of data_ptr by the sizeof the
    * Q_ITEM_INFO structure.
    */
   item_ptr = (Q_ITEM_PTR)((BYTE_PTR)data_ptr - sizeof(Q_ITEM_INFO));

   /* lock the sem_queue_cntrl_mutex field in queue_id */
   /*E.5.0.702.START*/
   SEM_MTX_WAIT(queue_ptr->sem_queue_cntrl_mutex);
   /*E.5.0.702.End*/
   /*
    * IF the first item in the first header is the item we what to remove.
    * THEN look from the Q_DESCRIPTOR structure into the first header
    */
   if (queue_ptr->first_header_ptr->first_item_ptr == item_ptr)
   {

      /*
       * decrement accum_dirty from for only WRITE_DELETE's
       */
      if (((COMMAND_PTR)(data_ptr))->sub_command == WRITE_DELETE)
      {
         queue_ptr->first_header_ptr->accum_dirty -= TOTALGRAN(
            ((COMMAND_PTR)(data_ptr))->gran_needed);

      }
      else if (((COMMAND_PTR)data_ptr)->sub_command == WRITE_TRUNCATE)
      {
          queue_ptr->first_header_ptr->accum_dirty -= TOTALGRAN(
             ((COMMAND_PTR)(data_ptr))->gran_needed);
/* E.5.5.993 Start */
          /* queue_ptr->first_header_ptr->accum_free -= 
               ((COMMAND_PTR)data_ptr)->gran_needed.grp_needed + 1; */
/* E.5.5.993 End */
      }
      else
      {
         /*
          * decrement from accum_free for all but WRITE_MODIFY
          */
         if (((COMMAND_PTR)(data_ptr))->sub_command != WRITE_MODIFY)
         {
            queue_ptr->first_header_ptr->accum_free -= TOTALGRAN(
               ((COMMAND_PTR)(data_ptr))->gran_needed);

         }
         /*
          * decrement from accum_dirty for WRITE_REPLACE or appends that do
          * not grow in size, but just replace within existing granularity
          */
         if ((((COMMAND_PTR)(data_ptr))->sub_command == WRITE_REPLACE) ||
             (append_to_replace == TRUE))
         {
            queue_ptr->first_header_ptr->accum_dirty -= TOTALGRAN(
               ((COMMAND_PTR)(data_ptr))->gran_needed);
         }
         /* added this condition for recording accum_dirty */
         /*
          * Test for appending to an existing single instance object and 
          * decrement the accum_dirty count by the existing object's 
          * data_offset
          */
          /* E.5.1.759 Begin */
         else if (( (((COMMAND_PTR)data_ptr)->sub_command == WRITE_APPEND) ||
                    (((COMMAND_PTR)data_ptr)->sub_command == WRITE_RESERVED) ) &&
            (((COMMAND_PTR)data_ptr)->data_offset != 0) &&
            (((COMMAND_PTR)data_ptr)->data_offset < 
            FDI_MAX_FRAG_SIZE))
          /* E.5.1.759 End */
         {

            queue_ptr->first_header_ptr->accum_dirty -=
               TO_GRAN(((COMMAND_PTR)data_ptr)->data_offset);
         }                             /* ENDIF appending to single inst */

       }

      /*
       * IF there are no more items in this priority THEN remove the priority
       * header
       */
      if (item_ptr->next_item_ptr == NULL)
      {
         removed_header_ptr = queue_ptr->first_header_ptr;

         /*
          * IF the subcommand is WRITE_RESERVE then we did not add the
          * data onto the bottom of the COMMAND structure, therefore we
          * only count the sizeof(COMMAND) and not the size pointed to by
          * the Q_ITEM_INFO structure.
          */
#if (PACKET_DATA == TRUE)
         if ((((COMMAND_PTR)data_ptr)->sub_command == WRITE_RESERVED) ||
                (((COMMAND_PTR)data_ptr)->sub_command == WRITE_RSRVPCKT) )
#else /* PACKET_DATA */
         if (((COMMAND_PTR)data_ptr)->sub_command == WRITE_RESERVED)
#endif /* PACKET_DATA */
         {
            /* increment the free count of the queue descriptor pointer. */
            queue_ptr->free_count += (sizeof(Q_ITEM_INFO) +
                                      sizeof(Q_PRIORITY_HEADER) +
                                      sizeof(COMMAND));
         }
        else if (((COMMAND_PTR)data_ptr)->sub_command == WRITE_TRUNCATE)
        {
           queue_ptr->free_count += (sizeof(Q_ITEM_INFO) +
                                     sizeof(Q_PRIORITY_HEADER) +
                                     sizeof(COMMAND));
        }
         else                          /* ELSE NOT WRITE_RESERVE */
         {
            /* increment the free count of the queue descriptor pointer. */
            queue_ptr->free_count += (sizeof(Q_ITEM_INFO) +
                                      sizeof(Q_PRIORITY_HEADER) +
               queue_ptr->first_header_ptr->first_item_ptr->item_size);
         }
         /* connect to the next header in line if available */
         queue_ptr->first_header_ptr =
          queue_ptr->first_header_ptr->next_header_ptr;

         /* delete the priority queue of this item */

         FDI_FREE((BYTE_PTR) removed_header_ptr);
      }
      else
      {
         /*
          * IF the subcommand is WRITE_RESERVE then we did not add the
          * data onto the bottom of the COMMAND structure, therefore we
          * only count the sizeof(COMMAND) and not the size pointed to by
          * the Q_ITEM_INFO structure.
          */
#if (PACKET_DATA == TRUE)
         if ((((COMMAND_PTR)data_ptr)->sub_command == WRITE_RESERVED) ||
             (((COMMAND_PTR)data_ptr)->sub_command == WRITE_RSRVPCKT) )
#else /* PACKET_DATA */
         if (((COMMAND_PTR)data_ptr)->sub_command == WRITE_RESERVED)
#endif /* PACKET_DATA */
         {
            /* increment the free count of the queue descriptor pointer. */
            queue_ptr->free_count += (sizeof(Q_ITEM_INFO) + sizeof(COMMAND));
         }
         else if (((COMMAND_PTR)data_ptr)->sub_command == WRITE_TRUNCATE)
         {
            queue_ptr->free_count += (sizeof(Q_ITEM_INFO) + sizeof(COMMAND));
         }
         else                          /* ELSE NOT WRITE_RESERVE */
         {
            /* increment the free count of the queue descriptor pointer. */
            queue_ptr->free_count += (sizeof(Q_ITEM_INFO) +
               queue_ptr->first_header_ptr->first_item_ptr->item_size);
         }
         /* connect to the next item in the priority */
         queue_ptr->first_header_ptr->first_item_ptr = item_ptr->next_item_ptr;
      }
   }
   else
   {
      /*
       * ELSE the first header is not the same priority look at the next and
       * succeeding headers always looking ahead incase we need to remove the
       * priority header of the item
       */

      /* assign header_ptr to first_header_ptr in queue_id */
      header_ptr = queue_ptr->first_header_ptr;

      /* DO WHILE header_ptr is not NULL */
      while (header_ptr != NULL)
      {

         /* IF the next priority item is the item we what to remove. THEN */
         if (header_ptr->next_header_ptr->first_item_ptr == item_ptr)
         {

            /*
             * decrement accum_dirty from for only WRITE_DELETE's
             */
            if (((COMMAND_PTR)(data_ptr))->sub_command == WRITE_DELETE)
            {
               header_ptr->next_header_ptr->accum_dirty -= TOTALGRAN(
                  ((COMMAND_PTR)(data_ptr))->gran_needed);

            }
            else if (((COMMAND_PTR)data_ptr)->sub_command == WRITE_TRUNCATE)
            {
                queue_ptr->first_header_ptr->accum_dirty -= TOTALGRAN(
                   ((COMMAND_PTR)(data_ptr))->gran_needed);
/* E.5.5.993 Start */
                /* queue_ptr->first_header_ptr->accum_free -= 
                     ((COMMAND_PTR)data_ptr)->gran_needed.grp_needed + 1; */
/* E.5.5.993 End */
            }
            else
            {
               /*
                * decrement from accum_free for all but WRITE_MODIFY
                */
               if (((COMMAND_PTR)(data_ptr))->sub_command != WRITE_MODIFY)
               {
                  header_ptr->next_header_ptr->accum_free -= TOTALGRAN(
                     ((COMMAND_PTR)(data_ptr))->gran_needed);
               }
               /*
                * decrement from accum_dirty for WRITE_REPLACE or appends that
                * do not grow in size, but just replace within existing
                * granularity.
                */
               if ((((COMMAND_PTR)(data_ptr))->sub_command ==
                  WRITE_REPLACE) || (append_to_replace == TRUE))
               {
                  header_ptr->next_header_ptr->accum_dirty -= TOTALGRAN(
                     ((COMMAND_PTR)(data_ptr))->gran_needed);
               }
               /* added this condition for recording accum_dirty */
               /*
                * Test for appending to an existing single instance object and 
                * decrement the accum_dirty count by the existing object's 
                * data_offset
                */
                /* E.5.1.759 Begin */
               else if (((((COMMAND_PTR)data_ptr)->sub_command == 
                  WRITE_APPEND) || (((COMMAND_PTR)data_ptr)->sub_command == 
                  WRITE_RESERVED)) &&
                  (((COMMAND_PTR)data_ptr)->data_offset != 0) &&
                  (((COMMAND_PTR)data_ptr)->data_offset < 
                  FDI_MAX_FRAG_SIZE))
                /* E.5.1.759 End */   
               {

                  header_ptr->next_header_ptr->accum_dirty -= 
                     TO_GRAN(((COMMAND_PTR)data_ptr)->data_offset);
               }                       /* ENDIF appending to single inst */

            }

            /*
             * IF there are no more items in this priority THEN remove the
             * priority header
             */
            if (item_ptr->next_item_ptr == NULL)
            {
               removed_header_ptr = header_ptr->next_header_ptr;

               /*
                * IF the subcommand is WRITE_RESERVE then we did not add the
                * data onto the bottom of the COMMAND structure, therefore we
                * only count the sizeof(COMMAND) and not the size pointed to by
                * the Q_ITEM_INFO structure.
                */
#if (PACKET_DATA == TRUE)
               if ((((COMMAND_PTR)data_ptr)->sub_command == WRITE_RESERVED) ||
                  (((COMMAND_PTR)data_ptr)->sub_command == WRITE_RSRVPCKT) )
#else /* PACKET_DATA */
               if (((COMMAND_PTR)data_ptr)->sub_command == WRITE_RESERVED)
#endif /* PACKET_DATA */
               {
                  /* increment the free count of the queue descriptor pointer.
                   */
                  queue_ptr->free_count += (sizeof(Q_ITEM_INFO) +
                                            sizeof(Q_PRIORITY_HEADER) +
                                            sizeof(COMMAND));
               }
               else if (((COMMAND_PTR)data_ptr)->sub_command == WRITE_TRUNCATE)
               {
                  queue_ptr->free_count += (sizeof(Q_ITEM_INFO) +
                                            sizeof(Q_PRIORITY_HEADER) +
                                            sizeof(COMMAND));
               }
               else                          /* ELSE NOT WRITE_RESERVE */
               {
                  /* increment the free count of the queue descriptor pointer.
                   */
                  queue_ptr->free_count += (sizeof(Q_ITEM_INFO) +
                                            sizeof(Q_PRIORITY_HEADER) +
                     header_ptr->next_header_ptr->first_item_ptr->item_size);
               }
               /* connect to the next header in line if available */
               header_ptr->next_header_ptr =
                  header_ptr->next_header_ptr->next_header_ptr;

               /* delete the priority queue of this item */

               FDI_FREE((BYTE_PTR) removed_header_ptr);
            }
            else
            {
               /*
                * IF the subcommand is WRITE_RESERVE then we did not add the
                * data onto the bottom of the COMMAND structure, therefore we
                * only count the sizeof(COMMAND) and not the size pointed to by
                * the Q_ITEM_INFO structure.
                */
#if (PACKET_DATA == TRUE)
               if ((((COMMAND_PTR)data_ptr)->sub_command == WRITE_RESERVED) ||
                  (((COMMAND_PTR)data_ptr)->sub_command == WRITE_RSRVPCKT) )
#else /* PACKET_DATA */
               if (((COMMAND_PTR)data_ptr)->sub_command == WRITE_RESERVED)
#endif /* PACKET_DATA */
               {
                  /* increment the free count of the queue descriptor pointer.
                   */
                  queue_ptr->free_count += (sizeof(Q_ITEM_INFO) +
                     sizeof(COMMAND));
               }

⌨️ 快捷键说明

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