2009-10-08 Chris Johns <chrisj@rtems.org>

* Makefile.am, preinstall.am: Added statvfs.h.
        * libcsupport/Makefile.am: Add statvfs.c.
        * libcsupport/include/sys/statvfs.h, libcsupport/src/statvfs.c:
        New.
        * libcsupport/include/rtems/libio.h: Add a file system handler for
        the statvfs call.
        * libfs/src/devfs/devfs_init.c, libfs/src/dosfs/msdos_init.c,
        libfs/src/imfs/imfs_init.c, libfs/src/nfsclient/src/nfs.c: Set the
        statvfs handler to NULL.
        * include/rtems/fs.h: Add a second node access field for the RFS
        file system to hold a directory offset while the existing field
        holds the inode number. This save a rescan of the directory when
        working with directories.
        * libblock/include/rtems/bdbuf.h: Added references and user fields
        to the buffer descriptor.
        * libblock/src/bdbuf.c: Added dynamic buffer support for different
        block sizes. Fixed a number of bugs.
        * libblock/src/blkdev.c: Release the disk device on an error.
        * libblock/src/diskdevs.c: Set the block size to the media block
        size during initialisation of the disk device.
        * libblock/src/flashdisk.c, libblock/src/nvdisk.c,
        libblock/src/ramdisk.c: Updated the drivers to handle variable
        block sizes.
        * libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h: Release any
        buffers when an error occurs. The FAT buffer layer hangs onto a
        single buffer while mounted. This should be fixed.
        * sapi/inline/rtems/chain.inl: Added rtems_chain_set_off_chain,
        rtems_chain_is_node_off_chain, and rtems_chain_previous.
        * score/inline/rtems/score/chain.inl: Added _Chain_Set_off_chain,
        and _Chain_Is_node_off_chain.
        * libmisc/shell/main_ln.c, libmisc/shell/main_mknod.c,
        libmisc/shell/mknod-pack_dev.c, libmisc/shell/mknod-pack_dev.h:
        New shell commands.
        * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Added ln and
        mknod commands.
        * libmisc/shell/hexdump-display.c: Fixed the reopen bug which
        showed up as a free with a bad pointer.
        * libmisc/shell/main_mount.c: List the user adding file system
        when listing the available file systems to mount.
        * libmisc/shell/utils-cp.c: Remove the fixed static copy buffer
        and use a large dynamic buffer.
        * score/inline/rtems/score/address.inl, score/src/coremsgsubmit.c,
        score/src/objectallocate.c, score/src/objectfree.c: Remove
        warnings.
This commit is contained in:
Chris Johns
2009-10-08 07:07:36 +00:00
parent cdf0be65ed
commit eb649786c8
36 changed files with 1874 additions and 298 deletions

View File

@@ -365,8 +365,9 @@ next(rtems_shell_hexdump_globals* globals, char **argv)
errno = ENOMEM;
err(exit_jump, 1, "file name allocation");
}
memset (hdstdin, 0, sizeof(FILE));
}
if (!(hdstdin = fopen(*_argv, "r"))) {
if (!(hdstdin = freopen(*_argv, "r", hdstdin))) {
warn("%s", *_argv);
exitval = 1;
++_argv;
@@ -399,22 +400,23 @@ doskip(rtems_shell_hexdump_globals* globals, const char *fname, int statok)
if (statok) {
if (fstat(fileno(hdstdin), &sb))
err(exit_jump, 1, "%s", fname);
if (S_ISREG(sb.st_mode) && skip >= sb.st_size) {
/* can seek block devices on RTEMS */
if (0 && S_ISREG(sb.st_mode) && skip >= sb.st_size) {
address += sb.st_size;
skip -= sb.st_size;
return;
}
}
if (S_ISREG(sb.st_mode)) {
if (fseeko(hdstdin, skip, SEEK_SET))
err(exit_jump, 1, "%s", fname);
address += skip;
skip = 0;
} else {
for (cnt = 0; cnt < skip; ++cnt)
if (getchar() == EOF)
break;
address += cnt;
skip -= cnt;
if (1 || S_ISREG(sb.st_mode)) {
if (fseeko(hdstdin, skip, SEEK_SET))
err(exit_jump, 1, "%s", fname);
address += skip;
skip = 0;
} else {
for (cnt = 0; cnt < skip; ++cnt)
if (getchar() == EOF)
break;
address += cnt;
skip -= cnt;
}
}
}

View File

@@ -0,0 +1,305 @@
/* $NetBSD: ln.c,v 1.34 2008/07/20 00:52:40 lukem Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS 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 0
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)ln.c 8.2 (Berkeley) 3/31/94";
#else
__RCSID("$NetBSD: ln.c,v 1.34 2008/07/20 00:52:40 lukem Exp $");
#endif
#endif /* not lint */
#endif
#include <rtems.h>
#include <rtems/shell.h>
#include <rtems/shellconfig.h>
#define __need_getopt_newlib
#include <getopt.h>
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <setjmp.h>
typedef struct {
int fflag; /* Unlink existing files. */
int hflag; /* Check new name for symlink first. */
int iflag; /* Interactive mode. */
int sflag; /* Symbolic, not hard, link. */
int vflag; /* Verbose output */
char linkch;
int exit_code;
jmp_buf exit_jmp;
} rtems_shell_ln_globals;
#define fflag globals->fflag
#define hflag globals->hflag
#define iflag globals->iflag
#define sflag globals->sflag
#define vflag globals->vflag
#define linkch globals->linkch
#define exit_jump &(globals->exit_jmp)
#define exit(ec) rtems_shell_ln_exit(globals, ec)
static int main_ln(rtems_shell_ln_globals* , int, char *[]);
static void
rtems_shell_ln_exit (rtems_shell_ln_globals* globals, int code)
{
globals->exit_code = code;
longjmp (globals->exit_jmp, 1);
}
static int main_ln(rtems_shell_ln_globals* globals, int argc, char *argv[]);
int
rtems_shell_main_ln(int argc, char *argv[])
{
rtems_shell_ln_globals ln_globals;
rtems_shell_ln_globals* globals = &ln_globals;
memset (globals, 0, sizeof (ln_globals));
ln_globals.exit_code = 1;
if (setjmp (ln_globals.exit_jmp) == 0)
return main_ln (globals, argc, argv);
return ln_globals.exit_code;
}
#if RTEMS_REMOVED
int fflag; /* Unlink existing files. */
int hflag; /* Check new name for symlink first. */
int iflag; /* Interactive mode. */
int sflag; /* Symbolic, not hard, link. */
int vflag; /* Verbose output */
/* System link call. */
int (*linkf)(const char *, const char *);
char linkch;
#endif
int (*linkf)(const char *, const char *);
static int linkit(rtems_shell_ln_globals* , const char *, const char *, int);
static void usage(rtems_shell_ln_globals* );
static int
main_ln(rtems_shell_ln_globals* globals, int argc, char *argv[])
{
struct stat sb;
int ch, exitval;
char *sourcedir;
struct getopt_data getopt_reent;
memset(&getopt_reent, 0, sizeof(getopt_data));
#if RTEMS_REMOVED
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
#endif
while ((ch = getopt_r(argc, argv, "fhinsv", &getopt_reent)) != -1)
switch (ch) {
case 'f':
fflag = 1;
iflag = 0;
break;
case 'h':
case 'n':
hflag = 1;
break;
case 'i':
iflag = 1;
fflag = 0;
break;
case 's':
sflag = 1;
break;
case 'v':
vflag = 1;
break;
case '?':
default:
usage(globals);
/* NOTREACHED */
}
argv += getopt_reent.optind;
argc -= getopt_reent.optind;
if (sflag) {
linkf = symlink;
linkch = '-';
} else {
linkf = link;
linkch = '=';
}
switch(argc) {
case 0:
usage(globals);
/* NOTREACHED */
case 1: /* ln target */
exit(linkit(globals, argv[0], ".", 1));
/* NOTREACHED */
case 2: /* ln target source */
exit(linkit(globals, argv[0], argv[1], 0));
/* NOTREACHED */
}
/* ln target1 target2 directory */
sourcedir = argv[argc - 1];
if (hflag && lstat(sourcedir, &sb) == 0 && S_ISLNK(sb.st_mode)) {
/* we were asked not to follow symlinks, but found one at
the target--simulate "not a directory" error */
errno = ENOTDIR;
err(exit_jump, EXIT_FAILURE, "%s", sourcedir);
/* NOTREACHED */
}
if (stat(sourcedir, &sb)) {
err(exit_jump, EXIT_FAILURE, "%s", sourcedir);
/* NOTREACHED */
}
if (!S_ISDIR(sb.st_mode)) {
usage(globals);
/* NOTREACHED */
}
for (exitval = 0; *argv != sourcedir; ++argv)
exitval |= linkit(globals, *argv, sourcedir, 1);
exit(exitval);
/* NOTREACHED */
return 0;
}
int
linkit(rtems_shell_ln_globals* globals, const char *source, const char *target, int isdir)
{
struct stat sb;
const char *p;
char path[MAXPATHLEN];
int ch, exists, first;
if (!sflag) {
/* If target doesn't exist, quit now. */
if (stat(target, &sb)) {
warn("%s", target);
return (1);
}
}
/* If the source is a directory (and not a symlink if hflag),
append the target's name. */
if (isdir ||
(!lstat(source, &sb) && S_ISDIR(sb.st_mode)) ||
(!hflag && !stat(source, &sb) && S_ISDIR(sb.st_mode))) {
if ((p = strrchr(target, '/')) == NULL)
p = target;
else
++p;
(void)snprintf(path, sizeof(path), "%s/%s", source, p);
source = path;
}
exists = !lstat(source, &sb);
/*
* If the file exists, then unlink it forcibly if -f was specified
* and interactively if -i was specified.
*/
if (fflag && exists) {
if (unlink(source)) {
warn("%s", source);
return (1);
}
} else if (iflag && exists) {
fflush(stdout);
(void)fprintf(stderr, "replace %s? ", source);
first = ch = getchar();
while (ch != '\n' && ch != EOF)
ch = getchar();
if (first != 'y' && first != 'Y') {
(void)fprintf(stderr, "not replaced\n");
return (1);
}
if (unlink(source)) {
warn("%s", source);
return (1);
}
}
/* Attempt the link. */
if ((*linkf)(target, source)) {
warn("%s", source);
return (1);
}
if (vflag)
(void)printf("%s %c> %s\n", source, linkch, target);
return (0);
}
void
usage(rtems_shell_ln_globals* globals)
{
#define getprogname() "ln"
(void)fprintf(stderr,
"usage:\t%s [-fhinsv] file1 file2\n\t%s [-fhinsv] file ... directory\n",
getprogname(), getprogname());
exit(1);
/* NOTREACHED */
}
rtems_shell_cmd_t rtems_shell_LN_Command = {
"ln", /* name */
"ln ln [-fhinsv] source_file [target_file]", /* usage */
"files", /* topic */
rtems_shell_main_ln, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,459 @@
/* $NetBSD: mknod.c,v 1.39 2009/02/13 01:37:23 lukem Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION 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 HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#if 0
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1998\
The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: mknod.c,v 1.39 2009/02/13 01:37:23 lukem Exp $");
#endif /* not lint */
#endif
#include <rtems.h>
#include <rtems/shell.h>
#include <rtems/shellconfig.h>
#define __need_getopt_newlib
#include <getopt.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#if !HAVE_NBTOOL_CONFIG_H
#include <sys/sysctl.h>
#endif
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
#include <string.h>
#include <ctype.h>
#include "mknod-pack_dev.h"
#include <setjmp.h>
typedef struct {
int exit_code;
jmp_buf exit_jmp;
} rtems_shell_mknod_globals;
#define exit_jump &(globals->exit_jmp)
#define exit(ec) rtems_shell_mknod_exit(globals, ec)
static int gid_name(const char *, gid_t *);
static portdev_t callPack(rtems_shell_mknod_globals* globals,
pack_t *, int, u_long *);
static int main_mknod(rtems_shell_mknod_globals*, int, char *[]);
static void usage(rtems_shell_mknod_globals* );
static void
rtems_shell_mknod_exit (rtems_shell_mknod_globals* globals, int code)
{
globals->exit_code = code;
longjmp (globals->exit_jmp, 1);
}
#include "mknod-pack_dev.c"
int
rtems_shell_main_mknod(int argc, char *argv[])
{
rtems_shell_mknod_globals mknod_globals;
rtems_shell_mknod_globals* globals = &mknod_globals;
memset (globals, 0, sizeof (mknod_globals));
mknod_globals.exit_code = 1;
if (setjmp (mknod_globals.exit_jmp) == 0)
return main_mknod (globals, argc, argv);
return mknod_globals.exit_code;
}
#define getprogname() "mknod"
#ifdef KERN_DRIVERS
#error invalid for RTEMS
static struct kinfo_drivers *kern_drivers;
static int num_drivers;
static void get_device_info(void);
static void print_device_info(char **);
static int major_from_name(const char *, mode_t);
#endif
#define MAXARGS 3 /* 3 for bsdos, 2 for rest */
int
main_mknod(rtems_shell_mknod_globals* globals, int argc, char **argv)
{
char *name, *p;
mode_t mode;
portdev_t dev;
pack_t *pack;
u_long numbers[MAXARGS];
int n, ch, fifo, hasformat;
int r_flag = 0; /* force: delete existing entry */
#ifdef KERN_DRIVERS
int l_flag = 0; /* list device names and numbers */
int major;
#endif
#if RTEMS_REMOVED
void *modes = 0;
#endif
uid_t uid = -1;
gid_t gid = -1;
int rval;
struct getopt_data getopt_reent;
memset(&getopt_reent, 0, sizeof(getopt_data));
dev = 0;
fifo = hasformat = 0;
pack = pack_native;
#ifdef KERN_DRIVERS
while ((ch = getopt(argc, argv, "lrRF:g:m:u:")) != -1) {
#else
while ((ch = getopt_r(argc, argv, "rRF:g:m:u:", &getopt_reent)) != -1) {
#endif
switch (ch) {
#ifdef KERN_DRIVERS
case 'l':
l_flag = 1;
break;
#endif
case 'r':
r_flag = 1;
break;
case 'R':
r_flag = 2;
break;
case 'F':
pack = pack_find(getopt_reent.optarg);
if (pack == NULL)
errx(exit_jump, 1, "invalid format: %s", getopt_reent.optarg);
hasformat++;
break;
case 'g':
if (getopt_reent.optarg[0] == '#') {
gid = strtol(getopt_reent.optarg + 1, &p, 10);
if (*p == 0)
break;
}
if (gid_name(getopt_reent.optarg, &gid) == 0)
break;
gid = strtol(getopt_reent.optarg, &p, 10);
if (*p == 0)
break;
errx(exit_jump, 1, "%s: invalid group name", getopt_reent.optarg);
case 'm':
#if RTEMS_REMOVED
modes = setmode(getopt_reent.optarg);
if (modes == NULL)
#endif
err(exit_jump, 1, "Cannot set file mode `%s'", getopt_reent.optarg);
break;
case 'u':
if (getopt_reent.optarg[0] == '#') {
uid = strtol(getopt_reent.optarg + 1, &p, 10);
if (*p == 0)
break;
}
#if RTEMS_REMOVED
if (uid_from_user(getopt_reent.optarg, &uid) == 0)
break;
#endif
uid = strtol(getopt_reent.optarg, &p, 10);
if (*p == 0)
break;
errx(exit_jump, 1, "%s: invalid user name", getopt_reent.optarg);
default:
case '?':
usage(globals);
}
}
argc -= getopt_reent.optind;
argv += getopt_reent.optind;
#ifdef KERN_DRIVERS
if (l_flag) {
print_device_info(argv);
return 0;
}
#endif
if (argc < 2 || argc > 10)
usage(globals);
name = *argv;
argc--;
argv++;
umask(mode = umask(0));
mode = (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) & ~mode;
if (argv[0][1] != '\0')
goto badtype;
switch (*argv[0]) {
case 'c':
mode |= S_IFCHR;
break;
case 'b':
mode |= S_IFBLK;
break;
case 'p':
if (hasformat)
errx(exit_jump, 1, "format is meaningless for fifos");
mode |= S_IFIFO;
fifo = 1;
break;
default:
badtype:
errx(exit_jump, 1, "node type must be 'b', 'c' or 'p'.");
}
argc--;
argv++;
if (fifo) {
if (argc != 0)
usage(globals);
} else {
if (argc < 1 || argc > MAXARGS)
usage(globals);
}
for (n = 0; n < argc; n++) {
errno = 0;
numbers[n] = strtoul(argv[n], &p, 0);
if (*p == 0 && errno == 0)
continue;
#ifdef KERN_DRIVERS
if (n == 0) {
major = major_from_name(argv[0], mode);
if (major != -1) {
numbers[0] = major;
continue;
}
if (!isdigit(*(unsigned char *)argv[0]))
errx(1, "unknown driver: %s", argv[0]);
}
#endif
errx(exit_jump, 1, "invalid number: %s", argv[n]);
}
switch (argc) {
case 0:
dev = 0;
break;
case 1:
dev = numbers[0];
break;
default:
dev = callPack(globals, pack, argc, numbers);
break;
}
#if RTEMS_REMOVED
if (modes != NULL)
mode = getmode(modes, mode);
#endif
umask(0);
rval = fifo ? mkfifo(name, mode) : mknod(name, mode, dev);
if (rval < 0 && errno == EEXIST && r_flag) {
struct stat sb;
if (lstat(name, &sb) != 0 || (!fifo && sb.st_rdev != dev))
sb.st_mode = 0;
if ((sb.st_mode & S_IFMT) == (mode & S_IFMT)) {
if (r_flag == 1)
/* Ignore permissions and user/group */
return 0;
if (sb.st_mode != mode)
rval = chmod(name, mode);
else
rval = 0;
} else {
unlink(name);
rval = fifo ? mkfifo(name, mode)
: mknod(name, mode, dev);
}
}
if (rval < 0)
err(exit_jump, 1, "%s", name);
if ((uid != (uid_t)-1 || gid != (uid_t)-1) && chown(name, uid, gid) == -1)
/* XXX Should we unlink the files here? */
warn("%s: uid/gid not changed", name);
return 0;
}
static void
usage(rtems_shell_mknod_globals* globals)
{
const char *progname = getprogname();
(void)fprintf(stderr,
"usage: %s [-rR] [-F format] [-m mode] [-u user] [-g group]\n",
progname);
(void)fprintf(stderr,
#ifdef KERN_DRIVERS
" [ name [b | c] [major | driver] minor\n"
#else
" [ name [b | c] major minor\n"
#endif
" | name [b | c] major unit subunit\n"
" | name [b | c] number\n"
" | name p ]\n");
#ifdef KERN_DRIVERS
(void)fprintf(stderr, " %s -l [driver] ...\n", progname);
#endif
exit(1);
}
static int
gid_name(const char *name, gid_t *gid)
{
struct group *g;
g = getgrnam(name);
if (!g)
return -1;
*gid = g->gr_gid;
return 0;
}
static portdev_t
callPack(rtems_shell_mknod_globals* globals, pack_t *f, int n, u_long *numbers)
{
portdev_t d;
const char *error = NULL;
d = (*f)(n, numbers, &error);
if (error != NULL)
errx(exit_jump, 1, "%s", error);
return d;
}
#ifdef KERN_DRIVERS
static void
get_device_info(void)
{
static int mib[2] = {CTL_KERN, KERN_DRIVERS};
size_t len;
if (sysctl(mib, 2, NULL, &len, NULL, 0) != 0)
err(1, "kern.drivers" );
kern_drivers = malloc(len);
if (kern_drivers == NULL)
err(1, "malloc");
if (sysctl(mib, 2, kern_drivers, &len, NULL, 0) != 0)
err(1, "kern.drivers" );
num_drivers = len / sizeof *kern_drivers;
}
static void
print_device_info(char **names)
{
int i;
struct kinfo_drivers *kd;
if (kern_drivers == NULL)
get_device_info();
do {
kd = kern_drivers;
for (i = 0; i < num_drivers; kd++, i++) {
if (*names && strcmp(*names, kd->d_name))
continue;
printf("%s", kd->d_name);
if (kd->d_cmajor != -1)
printf(" character major %d", kd->d_cmajor);
if (kd->d_bmajor != -1)
printf(" block major %d", kd->d_bmajor);
printf("\n");
}
} while (*names && *++names);
}
static int
major_from_name(const char *name, mode_t mode)
{
int i;
struct kinfo_drivers *kd;
if (kern_drivers == NULL)
get_device_info();
kd = kern_drivers;
for (i = 0; i < num_drivers; kd++, i++) {
if (strcmp(name, kd->d_name))
continue;
if (S_ISCHR(mode))
return kd->d_cmajor;
return kd->d_bmajor;
}
return -1;
}
#endif
rtems_shell_cmd_t rtems_shell_MKNOD_Command = {
"mknod", /* name */
"mknod mknod [-rR] [-F fmt] [-m mode] name [c | b] minor", /* usage */
"files", /* topic */
rtems_shell_main_mknod, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -128,6 +128,14 @@ int rtems_shell_main_mount(
for (a = rtems_shell_Mount_filesystems; *a; a++)
if (*a)
fprintf (stderr, "%s ", (*a)->name);
if (!rtems_chain_is_empty(&filesystems)) {
rtems_chain_node* node = filesystems.first;
while (!rtems_chain_is_tail (&filesystems, node)) {
rtems_shell_filesystems_t* f = (rtems_shell_filesystems_t*)node;
fprintf (stderr, "%s ", f->name);
node = node->next;
}
}
fprintf (stderr, "\n");
return 1;
} else {

View File

@@ -0,0 +1,296 @@
/* $NetBSD: pack_dev.c,v 1.10 2009/02/13 01:37:23 lukem Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION 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 HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#if 0
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: pack_dev.c,v 1.10 2009/02/13 01:37:23 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "pack_dev.h"
#endif
static pack_t pack_netbsd;
static pack_t pack_freebsd;
static pack_t pack_8_8;
static pack_t pack_12_20;
static pack_t pack_14_18;
static pack_t pack_8_24;
static pack_t pack_bsdos;
static int compare_format(const void *, const void *);
static const char iMajorError[] = "invalid major number";
static const char iMinorError[] = "invalid minor number";
static const char tooManyFields[] = "too many fields for format";
#define makedev(x,y) rtems_filesystem_make_dev_t(x,y)
#define major(d) rtems_filesystem_dev_major_t(d)
#define minor(d) rtems_filesystem_dev_minor_t(d)
/* exported */
portdev_t
pack_native(int n, u_long numbers[], const char **error)
{
portdev_t dev = 0;
if (n == 2) {
dev = makedev(numbers[0], numbers[1]);
if ((u_long)major(dev) != numbers[0])
*error = iMajorError;
else if ((u_long)minor(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
static portdev_t
pack_netbsd(int n, u_long numbers[], const char **error)
{
portdev_t dev = 0;
if (n == 2) {
dev = makedev_netbsd(numbers[0], numbers[1]);
if ((u_long)major_netbsd(dev) != numbers[0])
*error = iMajorError;
else if ((u_long)minor_netbsd(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_freebsd(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
#define minor_freebsd(x) ((int32_t)(((x) & 0xffff00ff) >> 0))
#define makedev_freebsd(x,y) ((portdev_t)((((x) << 8) & 0x0000ff00) | \
(((y) << 0) & 0xffff00ff)))
static portdev_t
pack_freebsd(int n, u_long numbers[], const char **error)
{
portdev_t dev = 0;
if (n == 2) {
dev = makedev_freebsd(numbers[0], numbers[1]);
if ((u_long)major_freebsd(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_freebsd(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_8_8(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
#define minor_8_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
#define makedev_8_8(x,y) ((portdev_t)((((x) << 8) & 0x0000ff00) | \
(((y) << 0) & 0x000000ff)))
static portdev_t
pack_8_8(int n, u_long numbers[], const char **error)
{
portdev_t dev = 0;
if (n == 2) {
dev = makedev_8_8(numbers[0], numbers[1]);
if ((u_long)major_8_8(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_8_8(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_12_20(x) ((int32_t)(((x) & 0xfff00000) >> 20))
#define minor_12_20(x) ((int32_t)(((x) & 0x000fffff) >> 0))
#define makedev_12_20(x,y) ((portdev_t)((((x) << 20) & 0xfff00000) | \
(((y) << 0) & 0x000fffff)))
static portdev_t
pack_12_20(int n, u_long numbers[], const char **error)
{
portdev_t dev = 0;
if (n == 2) {
dev = makedev_12_20(numbers[0], numbers[1]);
if ((u_long)major_12_20(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_12_20(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_14_18(x) ((int32_t)(((x) & 0xfffc0000) >> 18))
#define minor_14_18(x) ((int32_t)(((x) & 0x0003ffff) >> 0))
#define makedev_14_18(x,y) ((portdev_t)((((x) << 18) & 0xfffc0000) | \
(((y) << 0) & 0x0003ffff)))
static portdev_t
pack_14_18(int n, u_long numbers[], const char **error)
{
portdev_t dev = 0;
if (n == 2) {
dev = makedev_14_18(numbers[0], numbers[1]);
if ((u_long)major_14_18(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_14_18(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_8_24(x) ((int32_t)(((x) & 0xff000000) >> 24))
#define minor_8_24(x) ((int32_t)(((x) & 0x00ffffff) >> 0))
#define makedev_8_24(x,y) ((portdev_t)((((x) << 24) & 0xff000000) | \
(((y) << 0) & 0x00ffffff)))
static portdev_t
pack_8_24(int n, u_long numbers[], const char **error)
{
portdev_t dev = 0;
if (n == 2) {
dev = makedev_8_24(numbers[0], numbers[1]);
if ((u_long)major_8_24(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_8_24(dev) != numbers[1])
*error = iMinorError;
} else
*error = tooManyFields;
return (dev);
}
#define major_12_12_8(x) ((int32_t)(((x) & 0xfff00000) >> 20))
#define unit_12_12_8(x) ((int32_t)(((x) & 0x000fff00) >> 8))
#define subunit_12_12_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
#define makedev_12_12_8(x,y,z) ((portdev_t)((((x) << 20) & 0xfff00000) | \
(((y) << 8) & 0x000fff00) | \
(((z) << 0) & 0x000000ff)))
static portdev_t
pack_bsdos(int n, u_long numbers[], const char **error)
{
portdev_t dev = 0;
if (n == 2) {
dev = makedev_12_20(numbers[0], numbers[1]);
if ((u_long)major_12_20(dev) != numbers[0])
*error = iMajorError;
if ((u_long)minor_12_20(dev) != numbers[1])
*error = iMinorError;
} else if (n == 3) {
dev = makedev_12_12_8(numbers[0], numbers[1], numbers[2]);
if ((u_long)major_12_12_8(dev) != numbers[0])
*error = iMajorError;
if ((u_long)unit_12_12_8(dev) != numbers[1])
*error = "invalid unit number";
if ((u_long)subunit_12_12_8(dev) != numbers[2])
*error = "invalid subunit number";
} else
*error = tooManyFields;
return (dev);
}
/* list of formats and pack functions */
/* this list must be sorted lexically */
struct format {
const char *name;
pack_t *pack;
} formats[] = {
{"386bsd", pack_8_8},
{"4bsd", pack_8_8},
{"bsdos", pack_bsdos},
{"freebsd", pack_freebsd},
{"hpux", pack_8_24},
{"isc", pack_8_8},
{"linux", pack_8_8},
{"native", pack_native},
{"netbsd", pack_netbsd},
{"osf1", pack_12_20},
{"sco", pack_8_8},
{"solaris", pack_14_18},
{"sunos", pack_8_8},
{"svr3", pack_8_8},
{"svr4", pack_14_18},
{"ultrix", pack_8_8},
};
static int
compare_format(const void *key, const void *element)
{
const char *name;
const struct format *format;
name = key;
format = element;
return (strcmp(name, format->name));
}
pack_t *
pack_find(const char *name)
{
struct format *format;
format = bsearch(name, formats,
sizeof(formats)/sizeof(formats[0]),
sizeof(formats[0]), compare_format);
if (format == 0)
return (NULL);
return (format->pack);
}

View File

@@ -0,0 +1,52 @@
/* $NetBSD: pack_dev.h,v 1.7 2008/04/28 20:23:09 martin Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION 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.
*/
#ifndef _PACK_DEV_H
#define _PACK_DEV_H
#ifdef __CYGWIN__
typedef __dev32_t portdev_t;
#else
typedef dev_t portdev_t;
#endif
typedef portdev_t pack_t(int, u_long [], const char **);
static pack_t *pack_find(const char *);
static pack_t pack_native;
#define major_netbsd(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
#define minor_netbsd(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
(((x) & 0x000000ff) >> 0)))
#define makedev_netbsd(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
(((y) << 12) & 0xfff00000) | \
(((y) << 0) & 0x000000ff)))
#endif /* _PACK_DEV_H */

View File

@@ -50,6 +50,8 @@ extern rtems_shell_cmd_t rtems_shell_CAT_Command;
extern rtems_shell_cmd_t rtems_shell_MSDOSFMT_Command;
extern rtems_shell_cmd_t rtems_shell_MV_Command;
extern rtems_shell_cmd_t rtems_shell_RM_Command;
extern rtems_shell_cmd_t rtems_shell_LN_Command;
extern rtems_shell_cmd_t rtems_shell_MKNOD_Command;
extern rtems_shell_cmd_t rtems_shell_UMASK_Command;
extern rtems_shell_cmd_t rtems_shell_MOUNT_Command;
extern rtems_shell_cmd_t rtems_shell_UNMOUNT_Command;
@@ -286,6 +288,16 @@ extern rtems_shell_filesystems_t *rtems_shell_Mount_filesystems[];
defined(CONFIGURE_SHELL_COMMAND_RM)
&rtems_shell_RM_Command,
#endif
#if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
!defined(CONFIGURE_SHELL_NO_COMMAND_LN)) || \
defined(CONFIGURE_SHELL_COMMAND_LN)
&rtems_shell_LN_Command,
#endif
#if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
!defined(CONFIGURE_SHELL_NO_COMMAND_MKNOD)) || \
defined(CONFIGURE_SHELL_COMMAND_MKNOD)
&rtems_shell_MKNOD_Command,
#endif
#if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
!defined(CONFIGURE_SHELL_NO_COMMAND_UMASK)) || \
defined(CONFIGURE_SHELL_COMMAND_UMASK)

View File

@@ -69,9 +69,6 @@ __RCSID("$NetBSD: utils.c,v 1.29 2005/10/15 18:22:18 christos Exp $");
#define cp_pct(x, y) ((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
/* original was MAXBSIZE which results in 64K on the stack */
#define MAX_READ 1024
int
set_utimes(const char *file, struct stat *fs)
{
@@ -90,7 +87,9 @@ set_utimes(const char *file, struct stat *fs)
int
copy_file(rtems_shell_cp_globals* cp_globals __attribute__((unused)), FTSENT *entp, int dne)
{
static char buf[MAX_READ];
#define MAX_READ max_read
int max_read;
char* buf;
struct stat *fs;
ssize_t wcount;
size_t wresid;
@@ -101,13 +100,24 @@ copy_file(rtems_shell_cp_globals* cp_globals __attribute__((unused)), FTSENT *en
char *p;
#endif
fs = entp->fts_statp;
max_read = fs->st_blksize;
if (max_read < (8 * 1024))
max_read = 8 * 1024;
buf = malloc (max_read);
if (!buf)
{
warn("no memory");
return (1);
}
if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
warn("%s", entp->fts_path);
(void)free(buf);
return (1);
}
fs = entp->fts_statp;
/*
* If the file exists and we're interactive, verify with the user.
* If the file DNE, set the mode to be the from file, minus setuid
@@ -122,6 +132,7 @@ copy_file(rtems_shell_cp_globals* cp_globals __attribute__((unused)), FTSENT *en
if (vflag)
printf("%s not overwritten\n", to.p_path);
(void)close(from_fd);
(void)free(buf);
return (0);
} else if (iflag) {
(void)fprintf(stderr, "overwrite %s? %s",
@@ -131,6 +142,7 @@ copy_file(rtems_shell_cp_globals* cp_globals __attribute__((unused)), FTSENT *en
ch = getchar();
if (checkch != 'y' && checkch != 'Y') {
(void)close(from_fd);
(void)free(buf);
(void)fprintf(stderr, "not overwritten\n");
return (1);
}
@@ -157,6 +169,7 @@ copy_file(rtems_shell_cp_globals* cp_globals __attribute__((unused)), FTSENT *en
if (to_fd == -1) {
warn("%s", to.p_path);
(void)close(from_fd);
(void)free(buf);
return (1);
}
@@ -261,6 +274,7 @@ copy_file(rtems_shell_cp_globals* cp_globals __attribute__((unused)), FTSENT *en
rval = 1;
}
}
(void)free(buf);
return (rval);
}