[BACK]Return to fsconsole.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / rump / fs / bin / fsconsole

File: [cvs.NetBSD.org] / src / sys / rump / fs / bin / fsconsole / Attic / fsconsole.c (download)

Revision 1.6, Sun Sep 2 13:55:27 2007 UTC (15 years, 1 month ago) by pooka
Branch: MAIN
CVS Tags: yamt-x86pmap-base4, yamt-x86pmap-base3, yamt-x86pmap-base2, yamt-x86pmap-base, yamt-x86pmap, yamt-kmem-base3, yamt-kmem-base2, yamt-kmem-base, yamt-kmem, vmlocking2-base3, vmlocking2-base2, vmlocking2-base1, vmlocking2, vmlocking-nbase, vmlocking-base, reinoud-bufcleanup-nbase, reinoud-bufcleanup-base, nick-net80211-sync-base, nick-net80211-sync, nick-csl-alignment-base5, nick-csl-alignment-base4, mjf-devfs-base, mjf-devfs, matt-armv6-base, jmcneill-pm-base, jmcneill-base, hpcarm-cleanup-base, cube-autoconf-base, cube-autoconf, bouyer-xeni386-nbase, bouyer-xeni386-merge1, bouyer-xeni386-base, bouyer-xeni386, bouyer-xenamd64-base2, bouyer-xenamd64-base, bouyer-xenamd64
Branch point for: yamt-lazymbuf, nick-csl-alignment, mjf-devfs2, keiichi-mipv6, jmcneill-pm
Changes since 1.5: +5 -1 lines

"proper" return value handling

/*	$NetBSD: fsconsole.c,v 1.6 2007/09/02 13:55:27 pooka Exp $	*/

/*
 * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
 *
 * Development of this software was supported by the
 * Finnish Cultural Foundation.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * If you can keep a secret: THIS IS NOT FINISHED AT ALL
 */

#include <sys/types.h>
#include <dirent.h>

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

#include "ukfs.h"

struct fscons_args {
	char *fspec;
};

int
main(int argc, char *argv[])
{
	uint8_t buf[8192];
	struct ukfs *fs;
	struct fscons_args args;
#ifdef __NetBSD__
	struct dirent *dent;
#endif
	char *p;
	int rv;

	ukfs_init();

	if (argc != 3) {
		fprintf(stderr, "usage: fsconsole fstype fsdevice\n");
		exit(1);
	}

	/* XXXXXXXXXXX: this needs fs-specific handling */
	memset(&args, 0, sizeof(args));
	args.fspec = strdup(argv[2]);
	fs = ukfs_mount(argv[1], argv[2], "/", 0, &args, sizeof(args));

	printf("got fs at %p\n", fs);

	rv = ukfs_getdents(fs, "/", 0, buf, sizeof(buf));
	printf("rv %d\n", rv);
	if (rv == -1)
		rv = 0;

#ifdef __NetBSD__
	dent = (void *)buf;
	while (rv) {
		printf("%s\n", dent->d_name);
		rv -= _DIRENT_SIZE(dent);
		dent = _DIRENT_NEXT(dent);
	}
#endif

	rv = ukfs_read(fs, "/etc/passwd", 0, buf, sizeof(buf));
	printf("rv %d\n%s\n", rv, buf);

	rv = ukfs_remove(fs, "/lopinaa");
	if (rv == -1)
		warn("rv %d", rv);

#if 0
	rv = ukfs_remove(fs, "/etc/LUSIKKAPUOLI");
	if (rv == -1)
		warn("rv %d", rv);
#endif

	rv = ukfs_create(fs, "/lopinaa", 0555);
	if (rv == -1)
		warn("rv %d", rv);

	rv = ukfs_link(fs, "/lopinaa", "/etc/LUSIKKAPUOLI");
	if (rv == -1)
		warn("link rv %d", rv);

	/* XXX */
	p = strdup("jonnekin/aivan/muualle");
	rv = ukfs_symlink(fs, "/mihis_haluat_menna_tanaan", p);
	free(p);
	if (rv == -1)
		warn("symlink %d", rv);

	rv = ukfs_readlink(fs, "/mihis_haluat_menna_tanaan",
	    (char *)buf, sizeof(buf));
	if (rv > 0)
		buf[rv] = '\0';
	printf("readlink rv %d result \"%s\"\n", rv, buf);

	rv = ukfs_getdents(fs, "/etc", 0, buf, sizeof(buf));
	printf("rv %d\n", rv);
	if (rv == -1)
		rv = 0;

#ifdef __NetBSD__
	dent = (void *)buf;
	while (rv) {
		printf("%s\n", dent->d_name);
		rv -= _DIRENT_SIZE(dent);
		dent = _DIRENT_NEXT(dent);
	}
#endif

	ukfs_release(fs, 1);
}