/* This is buggy code and only used for debugging purposes!  */

/* $ gcc -D_GNU_SOURCE -Wall -g -D_FILE_OFFSET_BITS=64 -o memfile memfile.c -ltrivfs -lfshelp
 * $ settrans -ca node ./memfile
 * $ echo something > node
 * $ # Watch the translator and your shell (!) being killed, maybe the screen
 * $ # session as well and maybe your sshd instance as well.
 */

/* This once was...
   memfs-1.c - A trivial single-memory-based-file translator, multithreaded.
   Copyright (C) 1998, 1999, 2007 Free Software Foundation, Inc.
   Copyright (C) 2000 Farid Hajji <farid.hajji@ob.kamp.net>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#include <assert.h>
#include <fcntl.h>
#include <hurd/trivfs.h>

int trivfs_fstype = FSTYPE_MISC;
int trivfs_fsid = 0;

int trivfs_allow_open = O_WRITE;

int trivfs_support_read = 0;
int trivfs_support_write = 1;
int trivfs_support_exec = 0;

void
trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st)
{
}

error_t
trivfs_goaway (struct trivfs_control *cntl, int flags)
{
  exit (0);
}

kern_return_t
trivfs_S_file_set_size (struct trivfs_protid *cred, mach_port_t reply, 
                        mach_msg_type_name_t reply_type, off_t size)
{
  return 0;
}

error_t
trivfs_S_io_write (struct trivfs_protid * cred,
		   mach_port_t reply, mach_msg_type_name_t reply_type,
		   data_t data, mach_msg_type_number_t data_len,
		   off_t offs, mach_msg_type_number_t * amount)
{
  *(int *) 0 = 0;

  return 0;
}

int
main (int argc, char **argv)
{
  error_t err;
  mach_port_t bootstrap;
  struct trivfs_control *fsys;

  task_get_bootstrap_port (mach_task_self (), &bootstrap);
  assert (bootstrap != MACH_PORT_NULL);

  err = trivfs_startup (bootstrap, 0, 0, 0, 0, 0, &fsys);
  assert (err == 0);

  mach_port_deallocate (mach_task_self (), bootstrap);

  ports_manage_port_operations_multithread (fsys->pi.bucket, 
                                            trivfs_demuxer, 
                                            10 * 1000,	
					    10 * 60 * 1000,
					    0);

  return 0;
}
