diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-07-16 15:32:18 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-07-16 15:32:18 +0000 |
commit | c8d1675626aa25e0a65ff56e9f8b932ebdee0b88 (patch) | |
tree | 42854fd59e6055cf07c2856a16e46fb457d3185e /nfsClientTest | |
parent | 2007-07-12 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | network-demos-c8d1675626aa25e0a65ff56e9f8b932ebdee0b88.tar.bz2 |
2007-07-16 Joel Sherrill <joel.sherrill@oarcorp.com>
Initial add of NFS Client test.
* .cvsignore, Makefile, dirutils.c, init.c, rootfs/rtems_logo.jpg:
New files.
Diffstat (limited to 'nfsClientTest')
-rw-r--r-- | nfsClientTest/.cvsignore | 1 | ||||
-rw-r--r-- | nfsClientTest/Makefile | 79 | ||||
-rw-r--r-- | nfsClientTest/dirutils.c | 357 | ||||
-rw-r--r-- | nfsClientTest/init.c | 147 | ||||
-rw-r--r-- | nfsClientTest/rootfs/rtems_logo.jpg | bin | 0 -> 14586 bytes |
5 files changed, 584 insertions, 0 deletions
diff --git a/nfsClientTest/.cvsignore b/nfsClientTest/.cvsignore new file mode 100644 index 0000000..fecf58a --- /dev/null +++ b/nfsClientTest/.cvsignore @@ -0,0 +1 @@ +o-optimize diff --git a/nfsClientTest/Makefile b/nfsClientTest/Makefile new file mode 100644 index 0000000..782dfab --- /dev/null +++ b/nfsClientTest/Makefile @@ -0,0 +1,79 @@ +# +# $Id$ +# + +SAMPLE=nfsClientTest +PGM=${ARCH}/$(SAMPLE).exe + +MANAGERS=all + +# C source names, if any, go here -- minus the .c +C_PIECES=init dirutils +C_FILES=$(C_PIECES:%=%.c) +C_O_FILES=$(C_PIECES:%=${ARCH}/%.o) + +H_FILES= + +DOCTYPES= +DOCS=$(DOCTYPES:%=$(SAMPLE).%) + +SRCS=$(DOCS) $(C_FILES) $(CC_FILES) $(H_FILES) $(S_FILES) +OBJS=$(C_O_FILES) $(CC_O_FILES) $(S_O_FILES) $(ARCH)/tarfile.o + +PRINT_SRCS=$(DOCS) + +PGM=${ARCH}/$(SAMPLE).exe + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +# +# (OPTIONAL) Add local stuff here using += +# + +DEFINES += +CPPFLAGS += +CFLAGS_LD += # -Wl,--defsym -Wl,HeapSize=0xC0000 +CFLAGS_OPTIMIZE_V += +CFLAGS_DEBUG_V += -v -qrtems_debug + +LD_PATHS += + +OBJDUMP=$(OBJCOPY:copy=dump) + +CFLAGS += +LD_LIBS += -lrtemsNfs + +# +# Add your list of files to delete here. The config files +# already know how to delete some stuff, so you may want +# to just run 'make clean' first to see what gets missed. +# 'make clobber' already includes 'make clean' +# + +CLEAN_ADDITIONS += tarfile obj_format +CLOBBER_ADDITIONS += + +# strip out flags gcc knows but LD doesn't like -- add as needed +LD_CPU_CFLAGS=$(CPU_CFLAGS:-mstrict-align:) + +all: ${ARCH} $(SRCS) $(PGM) + +obj_format: + $(OBJDUMP) -f $(ARCH)/init.o | grep .o: | \ + sed -e 's/^.*format //' >obj_format + +${PGM}: $(OBJS) $(LINK_FILES) + $(make-exe) + +$(ARCH)/tarfile.o: $(ARCH) obj_format + cd rootfs ; tar cf ../$(ARCH)/tarfile --exclude CVS . + cp $(ARCH)/tarfile . + $(OBJCOPY) -I binary -O `cat obj_format` tarfile $(ARCH)/tarfile.o + $(LD) $(LD_CPU_CFLAGS) -r -o $(ARCH)/temp.o $(ARCH)/tarfile.o + +# Install the program(s), appending _g or _p as appropriate. +# for include files, just use $(INSTALL) +install: all + $(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests diff --git a/nfsClientTest/dirutils.c b/nfsClientTest/dirutils.c new file mode 100644 index 0000000..d6c47fe --- /dev/null +++ b/nfsClientTest/dirutils.c @@ -0,0 +1,357 @@ +/* $Id$ */ + +/* very crude and basic fs utilities for testing the NFS */ + +/* Till Straumann, <strauman@slac.stanford.edu>, 10/2002 */ + +/* + * Copyright 2002, Stanford University and + * Till Straumann <strauman@slac.stanford.edu> + * + * Stanford Notice + * *************** + * + * Acknowledgement of sponsorship + * * * * * * * * * * * * * * * * * + * This software was produced by the Stanford Linear Accelerator Center, + * Stanford University, under Contract DE-AC03-76SFO0515 with the Department + * of Energy. + * + * Government disclaimer of liability + * - - - - - - - - - - - - - - - - - + * Neither the United States nor the United States Department of Energy, + * nor any of their employees, makes any warranty, express or implied, + * or assumes any legal liability or responsibility for the accuracy, + * completeness, or usefulness of any data, apparatus, product, or process + * disclosed, or represents that its use would not infringe privately + * owned rights. + * + * Stanford disclaimer of liability + * - - - - - - - - - - - - - - - - - + * Stanford University makes no representations or warranties, express or + * implied, nor assumes any liability for the use of this software. + * + * This product is subject to the EPICS open license + * - - - - - - - - - - - - - - - - - - - - - - - - - + * Consult the LICENSE file or http://www.aps.anl.gov/epics/license/open.php + * for more information. + * + * Maintenance of notice + * - - - - - - - - - - - + * In the interest of clarity regarding the origin and status of this + * software, Stanford University requests that any recipient of it maintain + * this notice affixed to any distribution by the recipient that contains a + * copy or derivative of this software. + */ + +#ifdef __vxworks +#include <vxWorks.h> +#endif +#include <stdio.h> +#include <dirent.h> +#include <unistd.h> +#include <string.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <errno.h> +#include <stdlib.h> + +#ifdef HAVE_CEXP +#include <cexpHelp.h> +#endif + +#ifndef __vxworks +int +pwd(void) +{ +char buf[MAXPATHLEN]; + + if ( !getcwd(buf,MAXPATHLEN)) { + perror("getcwd"); + return -1; + } else { + printf("%s\n",buf); + } + return 0; +} + +static int +ls_r(char *path, char *chpt, char *name, struct stat *buf) +{ +char *t; + sprintf(chpt, "/%s", name); + if (lstat(path,buf)) { + fprintf(stderr,"stat(%s): %s\n", path, strerror(errno)); + return -1; + } + switch ( buf->st_mode & S_IFMT ) { + case S_IFSOCK: + case S_IFIFO: t = "|"; break; + + default: + case S_IFREG: + case S_IFBLK: + case S_IFCHR: + t = ""; break; + case S_IFDIR: + t = "/"; break; + case S_IFLNK: + t = "@"; break; + } + + printf("%10li, %10lib, %5i.%-5i 0%04o %s%s\n", + buf->st_ino, + buf->st_size, + buf->st_uid, + buf->st_gid, + buf->st_mode & ~S_IFMT, + name, + t); + *chpt = 0; + return 0; +} + +int +ls(char *dir, char *opts) +{ +struct dirent *de; +char path[MAXPATHLEN+1]; +char *chpt; +DIR *dp = 0; +int rval = -1; +struct stat buf; + + if ( !dir ) + dir = "."; + + strncpy(path, dir, MAXPATHLEN); + path[MAXPATHLEN] = 0; + chpt = path+strlen(path); + + if ( !(dp=opendir(dir)) ) { + perror("opendir"); + goto cleanup; + } + + while ( (de = readdir(dp)) ) { + ls_r(path, chpt, de->d_name, &buf); + } + + rval = 0; + +cleanup: + if (dp) + closedir(dp); + return rval; +} +#endif + +#if 0 + fprintf(stderr, "usage: cp(""from"",[""to""[,""-f""]]\n"); + fprintf(stderr, " ""to""==NULL -> stdout\n"); + fprintf(stderr, " ""-f"" -> overwrite existing file\n"); +#endif + +int +cp(char *from, char *to, char *opts) +{ +struct stat st; +int rval = -1; +int fd = -1; +FILE *fst = 0; +FILE *tst = 0; +int flags = O_CREAT | O_WRONLY | O_TRUNC | O_EXCL; + + if (from) { + + if ((fd=open(from,O_RDONLY,0)) < 0) { + fprintf(stderr, + "Opening %s for reading: %s\n", + from, + strerror(errno)); + goto cleanup; + } + + if (fstat(fd, &st)) { + fprintf(stderr, + "rstat(%s): %s\n", + from, + strerror(errno)); + goto cleanup; + } + + + if (!S_ISREG(st.st_mode)) { + fprintf(stderr,"Refuse to copy a non-regular file\n"); + errno = EINVAL; + goto cleanup; + } + /* Now create a stream -- I experienced occasional weirdness + * when circumventing the streams attached to fildno(stdin) + * by reading/writing to the underlying fd's directly -> + * for now we always go through buffered I/O... + */ + if ( !(fst=fdopen(fd,"r")) ) { + fprintf(stderr, + "Opening input stream [fdopen()] failed: %s\n", + strerror(errno)); + goto cleanup; + } + /* at this point, we have a stream and don't need 'fd' anymore */ + fd = -1; + + } else { + fst = stdin; + st.st_mode = 0644; + } + + if (opts && strchr(opts,'f')) + flags &= ~ O_EXCL; + + if (to) { + if ( (fd=open(to,flags,st.st_mode)) < 0 ) { + fprintf(stderr, + "Opening %s for writing: %s\n", + to, + strerror(errno)); + goto cleanup; + } + if ( !(tst=fdopen(fd, "w")) ) { + fprintf(stderr, + "Opening output stream [fdopen()] failed: %s\n", + strerror(errno)); + goto cleanup; + } + /* at this point we have a stream and don't need 'fd' anymore */ + fd = -1; + } else { + tst = stdout; + } + + /* clear old errors */ + clearerr(fst); + clearerr(tst); + + /* use macro versions on register vars; stdio is already buffered, + * there's nothing to be gained by reading/writing blocks into + * a secondary buffer... + */ + { + register int ch; + register FILE *f = fst; + register FILE *t = tst; + while ( EOF != (ch = getc(f)) && EOF != putc(ch, t) ) + /* nothing else */; + } + + if ( ferror(fst) ) { + fprintf(stderr,"Read error: %s\n",strerror(errno)); + goto cleanup; + } + if ( ferror(tst) ) { + fprintf(stderr,"Write error: %s\n",strerror(errno)); + goto cleanup; + } + + rval = 0; + +cleanup: + + if ( fd >= 0 ) + close(fd); + + if ( fst ) { + if ( from ) + fclose(fst); + else + clearerr(fst); + } + if ( tst ) { + if ( to ) + fclose(tst); + else { + /* flush stdout */ + fflush(tst); + clearerr(tst); + } + } + + return rval; +} + +int +ln(char *to, char *name, char *opts) +{ + if (!to) { + fprintf(stderr,"ln: need 'to' argument\n"); + return -1; + } + if (!name) { + if ( !(name = strrchr(to,'/')) ) { + fprintf(stderr, + "ln: 'unable to link %s to %s\n", + to,to); + return -1; + } + name++; + } + if (opts || strchr(opts,'s')) { + if (symlink(name,to)) { + fprintf(stderr,"symlink: %s\n",strerror(errno)); + return -1; + } + } else { + if (link(name,to)) { + fprintf(stderr,"hardlink: %s\n",strerror(errno)); + return -1; + } + } + return 0; +} + +int +rm(char *path) +{ + return unlink(path); +} + +int +cd(char *path) +{ + return chdir(path); +} + +#ifdef HAVE_CEXP +static CexpHelpTabRec _cexpHelpTabDirutils[] __attribute__((unused)) = { + HELP( +"copy a file: cp(""from"",[""to""[,""-f""]])\n\ + from = NULL <-- stdin\n\ + to = NULL --> stdout\n\ + option -f: overwrite existing file\n", + int, + cp, (char *from, char *to, char *options) + ), + HELP( +"list a directory: ls([""dir""])\n", + int, + ls, (char *dir) + ), + HELP( +"remove a file\n", + int, + rm, (char *path) + ), + HELP( +"change the working directory\n", + int, + cd, (char *path) + ), + HELP( +"create a link: ln(""to"",""name"",""[-s]""\n\ + -s creates a symlink\n", + int, + ln, (char *to, char *name, char *options) + ), + HELP("",,0,) +}; +#endif diff --git a/nfsClientTest/init.c b/nfsClientTest/init.c new file mode 100644 index 0000000..3211e1a --- /dev/null +++ b/nfsClientTest/init.c @@ -0,0 +1,147 @@ +/* Init + * + * This routine is the initialization task for this test program. + * + * Don't forget to change the IP addresses + */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20 +#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM + +#define CONFIGURE_MEMORY_OVERHEAD 256 +#define CONFIGURE_MESSAGE_BUFFER_MEMORY 32 * 1024 +#define CONFIGURE_MAXIMUM_SEMAPHORES 40 +#define CONFIGURE_MAXIMUM_TASKS 20 +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 20 + +#define CONFIGURE_MICROSECONDS_PER_TICK 1000 + +#define CONFIGURE_INIT_TASK_STACK_SIZE (64*1024) +#define CONFIGURE_INIT_TASK_PRIORITY 120 +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT +#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \ + RTEMS_NO_TIMESLICE | \ + RTEMS_NO_ASR | \ + RTEMS_INTERRUPT_LEVEL(0)) + +#define CONFIGURE_MAXIMUM_DRIVERS 10 +#define CONFIGURE_INIT + +#include <rtems.h> +#include <librtemsNfs.h> + +/* functions */ + +rtems_task Init( + rtems_task_argument argument +); + +/* configuration information */ + +#include <rtems/confdefs.h> +#include <bsp.h> + +#include <errno.h> +#include <time.h> + +#include <rtems/confdefs.h> +#include <stdio.h> +#include <rtems/rtems_bsdnet.h> +#include <rtems/ftpd.h> +#include <rtems/untar.h> + + +#include <rtems/error.h> +#include <rpc/rpc.h> +#include <netinet/in.h> +#include <time.h> + +#include <arpa/inet.h> +#include <sys/socket.h> +#include "../networkconfig.h" + +#include <rtems_webserver.h> + +#define ARGUMENT 0 + +/* + * The tarfile is built automatically externally so we need to account + * for the leading symbol on the names. + */ +#if defined(__sh__) + #define SYM(_x) _x +#else + #define SYM(_x) _ ## _x +#endif + +extern int SYM(binary_tarfile_start); +extern int SYM(binary_tarfile_size); +#define TARFILE_START SYM(binary_tarfile_start) +#define TARFILE_SIZE SYM(binary_tarfile_size) + +rtems_task Init( + rtems_task_argument argument +) +{ + rtems_status_code status; + int int_status; + + printf("\n\n*** NFS Client TEST ***\n\r" ); + + printf( "Free space %d\n", malloc_free_space() ); + /* + * Load filesystem image + */ + printf("=============== Loading filesystem image ===============\n"); + status = Untar_FromMemory((void *)(&TARFILE_START), (size_t)&TARFILE_SIZE); + + printf("============== Look at Local Filesystem ==============\n"); + printf( "PWD: " ); + pwd(); + + printf( "\nls /\n" ); + ls("/"); + + printf( "\nls /etc\n" ); + ls("/etc"); + + printf("============== Initializing Network ==============\n"); + rtems_bsdnet_initialize_network (); + + printf("============== Initializing RPC ==============\n"); + int_status = rpcUdpInit(); + if ( int_status ) + printf( "RPC UDP Initialization failed\n" ); + + printf("============== Initializing NFS Subsystem ==============\n"); + nfsInit( 0, 0 ); + + printf("============== Mounting Remote Filesystem ==============\n"); +#if 0 + int_status = nfsMount("192.168.1.210", "/home", "/home" ); +#else + int_status = mount( + NULL, /* mount_table_entry_pointer */ + &nfs_fs_ops, /* filesystem_operations_table_pointer */ + RTEMS_FILESYSTEM_READ_WRITE, /* options */ + "192.168.1.210:/home", /* device aka remote filesystem */ + "/home" /* mount_point */ + ); + +#endif + + if ( int_status ) + printf( "NFS Mount failed -- %s\n", strerror(errno) ); + + printf("============== Look at Remote Filesystem ==============\n"); + printf( "\nls /home\n" ); + ls("/home"); + + exit(0); + + status = rtems_task_delete( RTEMS_SELF ); +} + diff --git a/nfsClientTest/rootfs/rtems_logo.jpg b/nfsClientTest/rootfs/rtems_logo.jpg Binary files differnew file mode 100644 index 0000000..485b80b --- /dev/null +++ b/nfsClientTest/rootfs/rtems_logo.jpg |