/*  layout.c  */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "kernel.h"
#include "newfs.h"
#include "swis.h"

/***************************************************************************/

_kernel_oserror *layout_image(int fswh, char *image_name, int block_size)

  /* creates the image header and writes it to the file */

{
  image_hdr hdr;
  _kernel_oserror *err;

 /* initialise image header fields */
  hdr.size = sizeof(image_hdr);
  hdr.version = NEWFS_VERSION;
  hdr.block_size = block_size;
  hdr.image_size = sizeof(image_hdr);
  hdr.boot_option = 0;
  hdr.stamp_value = 0;
  hdr.id = NEWFS_ID;
  strncpy(hdr.image_name, image_name, 10);
   /* only space for 10 chars in an ADFS disc record */

 /* write header out to image file */
  err = _swix(OS_GBPB, I0|I1|I2|I3|I4,
              1,
              fswh,
              &hdr,
              sizeof(image_hdr),
              0
             );
 
  return err;
}

/***************************************************************************/

_kernel_oserror *NewFS_LayoutStructure
(
  _kernel_swi_regs *r,
   void *private
)

  /* called as a result of a call of the SWI NewFS_LayoutStructure:

       r0  -  structure specifier (currently ignored)
       r1  -  bad block list (currently ignored)
       r2  -  pointer to null-terminated disc name
       r3  -  file handle of image file
  */

{
  int fswh = r->r[3];
  char *image_name = (char*)(r->r[2]);

  debug("NewFS_LayoutStructure (SWI): image-name = '%s', file handle = %d\n",
        image_name, fswh);

  return layout_image(fswh, image_name, 64);   /* default block_size is 64 */
}

/***************************************************************************/
