Blame source/uds/indexLayoutLinuxKernel.c

Packit Service 310c69
/*
Packit Service 310c69
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service 310c69
 *
Packit Service 310c69
 * This program is free software; you can redistribute it and/or
Packit Service 310c69
 * modify it under the terms of the GNU General Public License
Packit Service 310c69
 * as published by the Free Software Foundation; either version 2
Packit Service 310c69
 * of the License, or (at your option) any later version.
Packit Service 310c69
 * 
Packit Service 310c69
 * This program is distributed in the hope that it will be useful,
Packit Service 310c69
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 310c69
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 310c69
 * GNU General Public License for more details.
Packit Service 310c69
 * 
Packit Service 310c69
 * You should have received a copy of the GNU General Public License
Packit Service 310c69
 * along with this program; if not, write to the Free Software
Packit Service 310c69
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service 310c69
 * 02110-1301, USA. 
Packit Service 310c69
 *
Packit Service 310c69
 * $Id: //eng/uds-releases/jasper/kernelLinux/uds/indexLayoutLinuxKernel.c#5 $
Packit Service 310c69
 */
Packit Service 310c69
Packit Service 310c69
#include "indexLayout.h"
Packit Service 310c69
#include "indexLayoutParser.h"
Packit Service 310c69
#include "memoryAlloc.h"
Packit Service 310c69
Packit Service 310c69
/*****************************************************************************/
Packit Service 310c69
int makeIndexLayout(const char              *name,
Packit Service 310c69
                    bool                     newLayout,
Packit Service 310c69
                    const UdsConfiguration   config,
Packit Service 310c69
                    IndexLayout            **layoutPtr)
Packit Service 310c69
{
Packit Service 310c69
  char     *dev    = NULL;
Packit Service 310c69
  uint64_t  offset = 0;
Packit Service 310c69
  uint64_t  size   = 0;
Packit Service 310c69
Packit Service 310c69
  LayoutParameter parameterTable[] = {
Packit Service 310c69
    { "dev",    LP_STRING | LP_DEFAULT, { .str = &dev    } },
Packit Service 310c69
    { "offset", LP_UINT64,              { .num = &offset } },
Packit Service 310c69
    { "size",   LP_UINT64,              { .num = &size   } },
Packit Service 310c69
  };
Packit Service 310c69
  size_t numParameters = sizeof(parameterTable) / sizeof(*parameterTable);
Packit Service 310c69
Packit Service 310c69
  char *params = NULL;
Packit Service 310c69
  int result = duplicateString(name, "makeIndexLayout parameters", &params);
Packit Service 310c69
  if (result != UDS_SUCCESS) {
Packit Service 310c69
    return result;
Packit Service 310c69
  }
Packit Service 310c69
Packit Service 310c69
  // note dev will be set to memory owned by params
Packit Service 310c69
  result = parseLayoutString(params, parameterTable, numParameters);
Packit Service 310c69
  if (result != UDS_SUCCESS) {
Packit Service 310c69
    FREE(params);
Packit Service 310c69
    return result;
Packit Service 310c69
  }
Packit Service 310c69
Packit Service 310c69
  IOFactory *factory = NULL;
Packit Service 310c69
  result = makeIOFactory(dev, &factory);
Packit Service 310c69
  FREE(params);
Packit Service 310c69
  if (result != UDS_SUCCESS) {
Packit Service 310c69
    return result;
Packit Service 310c69
  }
Packit Service 310c69
  IndexLayout *layout;
Packit Service 310c69
  result = makeIndexLayoutFromFactory(factory, offset, size, newLayout, config,
Packit Service 310c69
                                      &layout);
Packit Service 310c69
  putIOFactory(factory);
Packit Service 310c69
  if (result != UDS_SUCCESS) {
Packit Service 310c69
    return result;
Packit Service 310c69
  }
Packit Service 310c69
  *layoutPtr = layout;
Packit Service 310c69
  return UDS_SUCCESS;
Packit Service 310c69
}