fstest - /* * fstest - filesystem test code * * Writes a...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * fstest - filesystem test code * * Writes a file (in small chunks) and then reads it back again * (also in small chunks) and complains if what it reads back is * not the same. * * The length of SLOGAN is intentionally a prime number and * specifically *not* a power of two. */ #include <types.h> #include <kern/errno.h> #include <kern/unistd.h> #include <lib.h> #include <synch.h> #include <fs.h> #include <vnode.h> #include <vfs.h> #include <uio.h> #include <test.h> #include <thread.h> #define SLOGAN "HODIE MIHI - CRAS TIBI\n" #define FILENAME "fstest.tmp" #define NCHUNKS 720 #define NTHREADS 12 #define NCREATES 32 static struct semaphore *threadsem = NULL; static void init_threadsem(void) { if (threadsem==NULL) { threadsem = sem_create("fstestsem", 0); if (threadsem == NULL) { panic("fstest: sem_create failed\n"); } } } /* * Vary each line of the test file in a way that's predictable but * unlikely to mask bugs in the filesystem. */ static void rotate(char *str, int amt) { int i, ch; amt = (amt+2600)%26; assert(amt>=0); for (i=0; str[i]; i++) { ch = str[i]; if (ch>='A' && ch<='Z') {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ch = ch - 'A'; ch += amt; ch %= 26; ch = ch + 'A'; assert(ch>='A' & ch<='Z'); } str[i] = ch; } } //////////////////////////////////////////////////////////// static void fstest_makename(char *buf, size_t buflen, const char *fs, const char *namesuffix) { snprintf(buf, buflen, "%s:%s%s", fs, FILENAME, namesuffix); assert(strlen(buf) < buflen); } #define MAKENAME() fstest_makename(name, sizeof(name), fs, namesuffix) static int fstest_remove(const char *fs, const char *namesuffix) { char name[32]; char buf[32]; int err; MAKENAME(); strcpy(buf, name); err = vfs_remove(buf); if (err) { kprintf("Could not remove %s: %s\n", name, strerror(err)); return -1; } return 0; } static int fstest_write(const char *fs, const char *namesuffix, int stridesize, int stridepos) { struct vnode *vn; int err; int i; size_t shouldbytes=0; size_t bytes=0; off_t pos=0; char name[32]; char buf[32]; struct uio ku; int flags;
Background image of page 2
assert(sizeof(buf) > strlen(SLOGAN)); MAKENAME(); flags = O_WRONLY|O_CREAT; if (stridesize == 1) { flags |= O_TRUNC; } /* vfs_open destroys the string it's passed */ strcpy(buf, name); err = vfs_open(buf, flags, &vn); if (err) { kprintf("Could not open %s for write: %s\n", name, strerror(err)); return -1; } for (i=0; i<NCHUNKS; i++) { if (i % stridesize != stridepos) { pos += strlen(SLOGAN); continue; } strcpy(buf, SLOGAN); rotate(buf, i); mk_kuio(&ku, buf, strlen(SLOGAN), pos, UIO_WRITE); err = VOP_WRITE(vn, &ku); if (err) { kprintf("%s: Write error: %s\n", name, strerror(err));
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

fstest - /* * fstest - filesystem test code * * Writes a...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online