[Prev][Next][Index][Thread]

Re: Unmount



On 1999-9-1 Facundo Arena <trax@abaconet.com.ar> wrote:
 > Leigh Stoller wrote:
 > 
 > > > From: Facundo Arena <trax@abaconet.com.ar>
 > > > Subject: Re: Unmount
 > > >
 > > > Ok, I create the directory with the following code:
 > > >
 > > >         oskit_filesystem_getroot(rootfs, &dir);
 > > >         HMM(err, oskit_dir_mkdir, (dir,"mydir",0777));
 > > >         printf("Created!");
 > > >         HMM(err,oskit_dir_sync,(dir,1));
 > > >
 > > > and when I unmount the partition with the following code:
 > > >
 > > >         printf(">>>Leaving root...\n");
 > > >         HMM(err, oskit_dir_release , (dir));
 > > >         printf(">>>Unmouting %s\n", partname);
 > > >         assert(oskit_filesystem_unmount(rootfs)==0);
 > > >
 > >
 > > So, you don't anything inbetween these two fragments, at all? Whats the
 > > error code?
 > >
 > > Lbs
 > 
 > Nothing, I don't do nothing. Here you got the error code:
 > 
 > 297: FAILED ASSERTION "oskit_filesystem_unmount(rootfs)==0"

Works for me.  Perhaps there is something wrong with the code
you didn't show us.  The unmount is probably failing with EBUSY, 
which is probably due to some other reference to rootfs.

Here is a stripped down linux_fs_com.c that works with the
--enable-unixexamples stuff on FreeBSD.  I highly doubt that
using a real partition would make a difference here.  (This is
with the current oskit, so might need some minor tweaking for
the last release.)

- - - - - - - - - - - - - - - - tear off - - - - - - - - - - - - - - - -

/*
 * Copyright (c) 1996, 1998, 1999 University of Utah and the Flux Group.
 * All rights reserved.
 *
 * This file is part of the Flux OSKit.  The OSKit is free software, also known
 * as "open source;" you can redistribute it and/or modify it under the terms
 * of the GNU General Public License (GPL), version 2, as published by the Free
 * Software Foundation (FSF).  To explore alternate licensing terms, contact
 * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
 * 
 * The OSKit 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 GPL for more details.  You should have
 * received a copy of the GPL along with the OSKit; see the file COPYING.  If
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
 */
/*
 * This demonstrates the oskit filesystem COM interfaces going to the
 * Linux filesytems.
 */

#if 0
#define DISK_NAME	"wd1"		/* pencil */
#define PARTITION_NAME	"e"
#else
#define DISK_NAME	"sd0"		/* shaky */
#define PARTITION_NAME	"g"
#endif

#include <oskit/dev/dev.h>
#include <oskit/dev/linux.h>
#include <oskit/io/blkio.h>
#include <oskit/fs/filesystem.h>
#include <oskit/fs/dir.h>
#include <oskit/fs/openfile.h>
#include <oskit/fs/linux.h>
#include <oskit/diskpart/diskpart.h>
#include <oskit/principal.h>
#include <oskit/clientos.h>
#include <oskit/startup.h>

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>

/* Partition array, filled in by the diskpart library. */
#define MAX_PARTS 30
static diskpart_t part_array[MAX_PARTS];

/* Identity of current client process. */
static oskit_principal_t *cur_principal;

#define CHECK(err, f, args) ({			\
	(err) = f args;			\
	if (err)				\
		panic(#f" failed 0x%lx", (err));\
})
#define HMM(err, f, args) ({			\
	(err) = f args;			\
	if (err)				\
		printf("** " #f " failed 0x%x\n", (err));\
})

oskit_error_t
oskit_get_call_context(const struct oskit_guid *iid, void **out_if)
{
    if (memcmp(iid, &oskit_iunknown_iid, sizeof(*iid)) == 0 ||
	memcmp(iid, &oskit_principal_iid, sizeof(*iid)) == 0) {
	*out_if = cur_principal;
	oskit_principal_addref(cur_principal);
	return 0;
    }

    *out_if = 0;
    return OSKIT_E_NOINTERFACE;
}

int
main(int argc, char **argv)
{
	oskit_blkio_t *disk;
	oskit_blkio_t *part;
	oskit_error_t err;
	oskit_identity_t id;
	oskit_filesystem_t *rootfs;
	oskit_dir_t *dir;
	int numparts;
	char *diskname = DISK_NAME;
	char *partname = PARTITION_NAME;

#ifdef OSKIT_UNIX
	if (argc < 2)
		panic("Usage: %s file\n", argv[0]);
	diskname = argv[1];
	partname = "<bogus>";
#endif

	oskit_clientos_init();
	start_clock();
	start_blk_devices();

	printf(">>>Initializing filesystem...\n");
	CHECK(err, fs_linux_init, ());

	printf(">>>Establishing client identity\n");
	id.uid = 0;
	id.gid = 0;
	id.ngroups = 0;
	id.groups = 0;
	CHECK(err, oskit_principal_create, (&id, &cur_principal));

	printf(">>>Opening the disk %s\n", diskname);
	err = oskit_linux_block_open(diskname,
				     OSKIT_DEV_OPEN_READ|OSKIT_DEV_OPEN_WRITE,
				     &disk);
	if (err)
		panic("error 0x%x opening disk%s", err,
		      err == OSKIT_E_DEV_NOSUCH_DEV ? ": no such device" : "");

	printf(">>>Reading partition table and looking for partition %s\n",
	       partname);
#ifdef OSKIT_UNIX
	part = disk;
	oskit_blkio_addref(disk);
#else /* not OSKIT_UNIX */
	numparts = diskpart_blkio_get_partition(disk, part_array, MAX_PARTS);
	if (numparts == 0)
		panic("No partitions found");
	if (diskpart_blkio_lookup_bsd_string(part_array, partname,
					     disk, &part) == 0)
		panic("Couldn't find partition %s", partname);
#endif /* OSKIT_UNIX */

	/* Don't need the disk anymore, the partition has a ref. */
	oskit_blkio_release(disk);

	printf(">>>Mounting partition %s\n", partname);
	CHECK(err, fs_linux_mount, (part, 0, &rootfs));

	/* Don't need the part anymore, the filesystem has a ref. */
	oskit_blkio_release(part);

/* ---------------------------------------------------------------------- */
        oskit_filesystem_getroot(rootfs, &dir);
        HMM(err, oskit_dir_mkdir, (dir,"mydir",0777));
        printf("Created!");
        HMM(err,oskit_dir_sync,(dir,1));

/* and when I unmount the partition with the following code: */

        printf(">>>Leaving root...\n");
        HMM(err, oskit_dir_release , (dir));
        printf(">>>Unmouting %s\n", partname);
        assert(oskit_filesystem_unmount(rootfs)==0);
/* ---------------------------------------------------------------------- */

	return 0;
}

References: