2022-11-28 06:36:47 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* mm/iob/iob_reserve.c
|
|
|
|
*
|
2024-09-12 16:44:55 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2022-11-28 06:36:47 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/mm/iob.h>
|
|
|
|
|
|
|
|
#include "iob.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: iob_reserve
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Adjust headroom offset of iobs by reducing the tail room.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void iob_reserve(FAR struct iob_s *iob, unsigned int reserved)
|
|
|
|
{
|
2023-08-17 09:55:32 +02:00
|
|
|
FAR struct iob_s *head = iob;
|
2022-11-28 06:36:47 +01:00
|
|
|
unsigned int offset;
|
2023-08-17 09:55:32 +02:00
|
|
|
int trimlen;
|
2022-11-28 06:36:47 +01:00
|
|
|
|
2023-08-17 09:55:32 +02:00
|
|
|
/* Update offset and adjust packet length. */
|
2022-11-28 06:36:47 +01:00
|
|
|
|
|
|
|
while (iob != NULL && reserved > 0)
|
|
|
|
{
|
2024-04-23 05:01:02 +02:00
|
|
|
if (reserved > IOB_BUFSIZE(iob))
|
2022-11-28 06:36:47 +01:00
|
|
|
{
|
2024-04-23 05:01:02 +02:00
|
|
|
offset = IOB_BUFSIZE(iob);
|
2022-11-28 06:36:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset = reserved;
|
|
|
|
}
|
|
|
|
|
2023-08-17 09:55:32 +02:00
|
|
|
trimlen = offset - iob->io_offset;
|
|
|
|
|
|
|
|
/* At most trim iob->io_len to 0. */
|
|
|
|
|
|
|
|
if ((int)(iob->io_len - trimlen) < 0)
|
2022-11-28 06:36:47 +01:00
|
|
|
{
|
2023-08-17 09:55:32 +02:00
|
|
|
trimlen = iob->io_len;
|
2022-11-28 06:36:47 +01:00
|
|
|
}
|
|
|
|
|
2023-08-17 09:55:32 +02:00
|
|
|
head->io_pktlen -= trimlen;
|
|
|
|
iob->io_len -= trimlen;
|
|
|
|
iob->io_offset = offset;
|
|
|
|
|
2022-11-28 06:36:47 +01:00
|
|
|
iob = iob->io_flink;
|
2022-12-07 11:05:44 +01:00
|
|
|
reserved -= offset;
|
2022-11-28 06:36:47 +01:00
|
|
|
}
|
|
|
|
}
|