/* * Closes srcHandle if it's not -1. * Closes dstHandle if it's not -1. * Removes unlinkpath from the unlinkHandle dir if it's not NULL. * Frees 'buf' if not NULL. * Always returns -1. * errno is what was before the call. */ static int copyError(uio_Handle *srcHandle, uio_Handle *dstHandle, uio_DirHandle *unlinkHandle, const char *unlinkPath, uint8 *buf) { int savedErrno; savedErrno = errno; log_add (log_Debug, "Error while copying: %s", strerror (errno)); if (srcHandle != NULL) uio_close (srcHandle); if (dstHandle != NULL) uio_close (dstHandle); if (unlinkPath != NULL) uio_unlink (unlinkHandle, unlinkPath); if (buf != NULL) HFree(buf); errno = savedErrno; return -1; }
/* * Closes srcHandle if it's not -1. * Closes dstHandle if it's not -1. * Removes unlinkpath from the unlinkHandle dir if it's not NULL. * Frees 'buf' if not NULL. * Always returns -1. * errno is what was before the call. */ static int uio_copyError(uio_Handle *srcHandle, uio_Handle *dstHandle, uio_DirHandle *unlinkHandle, const char *unlinkPath, uio_uint8 *buf) { int savedErrno; savedErrno = errno; #ifdef DEBUG fprintf(stderr, "Error while copying: %s\n", strerror(errno)); #endif if (srcHandle != NULL) uio_close(srcHandle); if (dstHandle != NULL) uio_close(dstHandle); if (unlinkPath != NULL) uio_unlink(unlinkHandle, unlinkPath); if (buf != NULL) uio_free(buf); errno = savedErrno; return -1; }
static int debugCmdCat(DebugContext *debugContext, int argc, char *argv[]) { uio_Handle *handle; #define READBUFSIZE 0x10000 char readBuf[READBUFSIZE]; char *bufPtr; ssize_t numInBuf, numWritten; size_t totalWritten; if (argc != 2) { fprintf(debugContext->err, "Invalid number of arguments.\n"); return 1; } handle = uio_open(debugContext->cwd, argv[1], O_RDONLY #ifdef WIN32 | O_BINARY #endif , 0); if (handle == NULL) { fprintf(debugContext->err, "Could not open file: %s\n", strerror(errno)); return 1; } totalWritten = 0; while (1) { numInBuf = uio_read(handle, readBuf, READBUFSIZE); if (numInBuf == -1) { if (errno == EINTR) continue; fprintf(debugContext->err, "Could not read from file: %s\n", strerror(errno)); uio_close(handle); return 1; } if (numInBuf == 0) break; bufPtr = readBuf; do { numWritten = write(fileno(debugContext->out), bufPtr, numInBuf); if (numWritten == -1) { if (errno == EINTR) continue; fprintf(debugContext->err, "Could not read from file: %s\n", strerror(errno)); uio_close(handle); } numInBuf -= numWritten; bufPtr += numWritten; totalWritten += numWritten; } while (numInBuf > 0); } fprintf(debugContext->out, "[%u bytes]\n", (unsigned int) totalWritten); uio_close(handle); return 0; }
static int debugCmdWriteTest(DebugContext *debugContext, int argc, char *argv[]) { uio_Handle *handle; const char testString[] = "Hello world!\n"; if (argc != 2) { fprintf(debugContext->err, "Invalid number of arguments.\n"); return 1; } handle = uio_open(debugContext->cwd, argv[1], O_WRONLY | O_CREAT | O_EXCL #ifdef WIN32 | O_BINARY #endif , 0644); if (handle == NULL) { fprintf(debugContext->err, "Could not open file: %s\n", strerror(errno)); return 1; } if (uio_write(handle, testString, sizeof testString) == -1) { fprintf(debugContext->err, "Write failed: %s\n", strerror(errno)); return 1; } uio_close(handle); return 0; }
int main (int argc, char **argv) { struct uio_info_t *uio; unsigned long offset; uint32_t val; int i, ret; if (argc < 3) { usage (argv [0]); return -1; } textdomain (PACKAGE); uio = uio_find_by_uio_name (argv [1]); if (!uio) { printf (_("could not find UIO device >%s<.\n"), argv [1]); return -1; } ret = uio_open (uio); if (ret) { printf (_("could not open UIO device >%s<: %s\n"), argv [1], strerror (errno)); return -1; } for (i = 2; i < argc; i++) { offset = strtoul (argv [i], NULL, 0); ret = uio_read32 (uio, 0, offset, &val); if (ret) { printf (_("could not read at offset %ld: %s\n"), offset, strerror (errno)); } else printf ("%ld: %d\n", offset, val); } uio_close (uio); return 0; }
/* * If \a state is non-NULL: * Initialize the owners table, ie. pointers from * shared_state->owners[i] to the start of the allocation * table for block i. * If \a state is NULL: * skip the initialization and just calculate the size of the owners table, * ie. the sum of the sizes of the allocation tables for each block. * \returns The total size in bytes of the owners table. */ static size_t init_owners_table (struct uiomux_state * state) { struct uio * uio; const char * name = NULL; int i; size_t nr_pages = 0, n; long pagesize; char * o = NULL; pid_t * owners = NULL; pagesize = sysconf (_SC_PAGESIZE); if (state != NULL) { o = (char *)state + sizeof (struct uiomux_state); owners = (pid_t *)o; } for (i = 0; i < UIOMUX_BLOCK_MAX; i++) { if ((name = uiomux_name (1<<i)) != NULL) { if ((uio = uio_open (name)) != NULL) { n = (uio->mem.size / pagesize) + 1; if (state != NULL) { state->owners[i] = owners; #ifdef DEBUG fprintf (stderr, "%s: Tabling %d pages for block %d at %p ...\n", __func__, n, i, owners); #endif owners += n; #ifdef DEBUG } else { fprintf (stderr, "%s: Counting %d pages for block %d ...\n", __func__, n, i); #endif } nr_pages += n; uio_close (uio); } } else if (state != NULL) { state->owners[i] = NULL; } } return nr_pages * sizeof(pid_t); }
/* * Copy a file with path srcName to a file with name newName. * If the destination already exists, the operation fails. * Links are followed. * Special files (fifos, char devices, block devices, etc) will be * read as long as there is data available and the destination will be * a regular file with that data. * The new file will have the same permissions as the old. * If an error occurs during copying, an attempt will be made to * remove the copy. */ int copyFile (uio_DirHandle *srcDir, const char *srcName, uio_DirHandle *dstDir, const char *newName) { uio_Handle *src, *dst; struct stat sb; #define BUFSIZE 65536 uint8 *buf, *bufPtr; ssize_t numInBuf, numWritten; src = uio_open (srcDir, srcName, O_RDONLY #ifdef WIN32 | O_BINARY #endif , 0); if (src == NULL) return -1; if (uio_fstat (src, &sb) == -1) return copyError (src, NULL, NULL, NULL, NULL); dst = uio_open (dstDir, newName, O_WRONLY | O_CREAT | O_EXCL #ifdef WIN32 | O_BINARY #endif , sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)); if (dst == NULL) return copyError (src, NULL, NULL, NULL, NULL); buf = HMalloc(BUFSIZE); // This was originally a statically allocated buffer, // but as this function might be run from a thread with // a small Stack, this is better. while (1) { numInBuf = uio_read (src, buf, BUFSIZE); if (numInBuf == -1) { if (errno == EINTR) continue; return copyError (src, dst, dstDir, newName, buf); } if (numInBuf == 0) break; bufPtr = buf; do { numWritten = uio_write (dst, bufPtr, numInBuf); if (numWritten == -1) { if (errno == EINTR) continue; return copyError (src, dst, dstDir, newName, buf); } numInBuf -= numWritten; bufPtr += numWritten; } while (numInBuf > 0); } HFree (buf); uio_close (src); uio_close (dst); errno = 0; return 0; }
/* * Function name: uio_mountDir * Description: Grafts a directory from inside a physical fileSystem * into the locical filesystem, at a specified directory. * Arguments: destRep - the repository where the newly mounted dir * is to be grafted. * mountPoint - the path to the directory where the dir * is to be grafted. * fsType - the file system type of physical fileSystem * pointed to by sourcePath. * sourceDir - the directory to which 'sourcePath' is to * be taken relative. * sourcePath - a path relative to sourceDir, which contains * the file/directory to be mounted. * If sourceDir and sourcePath are NULL, the file * system of the operating system will be used. * inPath - the location relative to the root of the newly * mounted fileSystem, pointing to the directory * that is to be grafted. * Note: If fsType is uio_FSTYPE_STDIO, inPath is * relative to the root of the filesystem, NOT to * the current working dir. * autoMount - array of automount options in function * in this mountPoint. * flags - one of uio_MOUNT_TOP, uio_MOUNT_BOTTOM, * uio_MOUNT_BELOW, uio_MOUNT_ABOVE, specifying * the precedence of this mount, OR'ed with * one or more of the following flags: * uio_MOUNT_RDONLY (no writing is allowed) * relative - If 'flags' includes uio_MOUNT_BELOW or * uio_MOUNT_ABOVE, this is the mount handle * where the new mount is relative to. * Otherwise, it should be NULL. * Returns: a handle suitable for uio_unmountDir() * NULL if an error occured. In this case 'errno' is set. */ uio_MountHandle * uio_mountDir(uio_Repository *destRep, const char *mountPoint, uio_FileSystemID fsType, uio_DirHandle *sourceDir, const char *sourcePath, const char *inPath, uio_AutoMount **autoMount, int flags, uio_MountHandle *relative) { uio_PRoot *pRoot; uio_Handle *handle; uio_FileSystemHandler *handler; uio_MountInfo *relativeInfo; switch (flags & uio_MOUNT_LOCATION_MASK) { case uio_MOUNT_TOP: case uio_MOUNT_BOTTOM: if (relative != NULL) { errno = EINVAL; return NULL; } relativeInfo = NULL; break; case uio_MOUNT_BELOW: case uio_MOUNT_ABOVE: if (relative == NULL) { errno = EINVAL; return NULL; } relativeInfo = relative->mountInfo; break; default: abort(); } if (mountPoint[0] == '/') mountPoint++; if (!validPathName(mountPoint, strlen(mountPoint))) { errno = EINVAL; return NULL; } // TODO: check if the filesystem is already mounted, and if so, reuse it. // A RO filedescriptor will need to be replaced though if the // filesystem needs to be remounted RW now. if (sourceDir == NULL) { if (sourcePath != NULL) { // bad: sourceDir is NULL, but sourcePath isn't errno = EINVAL; return NULL; } handle = NULL; } else { if (sourcePath == NULL) { // bad: sourcePath is NULL, but sourceDir isn't errno = EINVAL; return NULL; } handle = uio_open(sourceDir, sourcePath, ((flags & uio_MOUNT_RDONLY) == uio_MOUNT_RDONLY ? O_RDONLY : O_RDWR) #ifdef WIN32 | O_BINARY #endif , 0); if (handle == NULL) { // errno is set return NULL; } } handler = uio_getFileSystemHandler(fsType); if (handler == NULL) { if (handle) uio_close(handle); errno = ENODEV; return NULL; } assert(handler->mount != NULL); pRoot = (handler->mount)(handle, flags); if (pRoot == NULL) { int savedErrno; savedErrno = errno; if (handle) uio_close(handle); errno = savedErrno; return NULL; } if (handle) { // Close this reference to handle. // The physical layer may store the link in pRoot, in which it // will be cleaned up from uio_unmount(). uio_close(handle); } // The new file system is ready, now we need to find the specified // dir inside it and put it in its place in the mountTree. { uio_PDirHandle *endDirHandle; const char *endInPath; char *dirName; uio_MountInfo *mountInfo; uio_MountTree *mountTree; uio_PDirHandle *pRootHandle; #ifdef BACKSLASH_IS_PATH_SEPARATOR char *unixPath; unixPath = dosToUnixPath(inPath); inPath = unixPath; #endif /* BACKSLASH_IS_PATH_SEPARATOR */ if (inPath[0] == '/') inPath++; pRootHandle = uio_PRoot_getRootDirHandle(pRoot); uio_walkPhysicalPath(pRootHandle, inPath, strlen(inPath), &endDirHandle, &endInPath); if (*endInPath != '\0') { // Path inside the filesystem to mount does not exist. #ifdef BACKSLASH_IS_PATH_SEPARATOR uio_free(unixPath); #endif /* BACKSLASH_IS_PATH_SEPARATOR */ uio_PDirHandle_unref(endDirHandle); uio_PRoot_unrefMount(pRoot); errno = ENOENT; return NULL; } dirName = uio_malloc(endInPath - inPath + 1); memcpy(dirName, inPath, endInPath - inPath); dirName[endInPath - inPath] = '\0'; #ifdef BACKSLASH_IS_PATH_SEPARATOR // InPath is a copy with the paths fixed. uio_free(unixPath); #endif /* BACKSLASH_IS_PATH_SEPARATOR */ mountInfo = uio_MountInfo_new(fsType, NULL, endDirHandle, dirName, autoMount, NULL, flags); uio_repositoryAddMount(destRep, mountInfo, flags & uio_MOUNT_LOCATION_MASK, relativeInfo); mountTree = uio_mountTreeAddMountInfo(destRep, destRep->mountTree, mountInfo, mountPoint, flags & uio_MOUNT_LOCATION_MASK, relativeInfo); // mountTree is the node in destRep->mountTree where mountInfo // leads to. mountInfo->mountTree = mountTree; mountInfo->mountHandle = uio_MountHandle_new(destRep, mountInfo); return mountInfo->mountHandle; } }
int main(){ uio_mem_t cmem_dsc; struct pdparam_slave sp; unsigned long vad; long i, dt, *p, sz, err; printf(" ____________________________________________________________ \r\n"); printf("| |\r\n"); printf("| PokeA32slave 1.2 |\r\n"); printf("| |\r\n"); printf("| Writing numbers 0, 1, 2,... 65535 into A32 |\r\n"); printf("| slave memory of the RTPC 8067. It is required, |\r\n"); printf("| that the ram of the RTPC is static mapped. |\r\n"); printf("| (Based on the speek, spoke, vmem and cmem functions) |\r\n"); printf("| |\r\n"); printf("| E-mail : [email protected] |\r\n"); printf("| Created : 04-09-1998 |\r\n"); printf("| Modified: 26-09-1998 13-07-99 |\r\n"); printf("|____________________________________________________________|\r\n"); printf(" \r\n"); printf("This program can be run to check if A32 slave memory works. \r\n"); printf("Type CR to write 64 kwords into memory. The RTPC may crash, \r\n"); printf("so - if you are not sure - type CTRL C to exit now... \r\n"); fflush(stdout); getchar(); sz = 4 * MAXBUF; if(err=uio_open()) { uio_perror("uio_open",err); exit(0); } /* * prepare page descriptor options */ sp.rdpref = 0; /* read prefetch (before = 3, magne)*/ sp.wrpost = 0; /* write posting (before = 1, magne)*/ sp.wrprotect = 0; /* enable writing */ sp.swap = SINGLE_AUTO_SWAP; /* auto-swapping */ sp.pcispace = PCI_MEM_CES; /* PCI memory space */ printf("Allocating 0x%x (%d) bytes ...\n",sz,sz); if (err=uio_calloc(&cmem_dsc,sz)) { uio_perror("uio_calloc",err); exit(0); }else{ printf("Kernel virtual address: 0x%08x\n",cmem_dsc.kaddr); printf("User virtual address: 0x%08x\n",cmem_dsc.uaddr); printf("Physical address : 0x%08x\n",cmem_dsc.paddr); printf("Size : %d (0x%x) bytes\n",cmem_dsc.size, cmem_dsc.size); } /* * map to VME */ vad = vme_slave_map(PHYS_2_PCI(cmem_dsc.paddr),sz,&sp); if (vad == -1) { fprintf(stderr,"mapping to VME failed -terminating\n"); uio_cfree(&cmem_dsc); exit(0); }else{ printf("Mapped 0x%x (%d) bytes at PCI 0x%08x to VME 0x%08x\n", sz,sz,PHYS_2_PCI(cmem_dsc.paddr),vad); } printf("<CR> to continue"); fflush(stdout); getchar(); p = (u_long *)cmem_dsc.uaddr; for( i = 0; i < MAXBUF; i++){ *(p+i) = i; dt = *(p+i); if((int)(i/10000.)*10000. == i){ printf("log AD=0x%08x (%ld): data write/read: %ld\n",p+i,i,dt); } } printf("log AD=0x%08x (%ld): data write/read: %ld\n",p+i-1,i-1,dt); printf("Congratulation, it worked! You may now see if you can read \r\n"); printf("the same numbers from lynx (Sun SparcStation) via bit3 with: \r\n"); printf("/usr/local/944/v1.1/src/readram -t BT_AXSRR -a 0x08xxxxxx \r\n"); printf("Here, the xxxxxx's is the physical address to start from. \r\n"); printf("(The first data start at physical address:0x%08x)\n",cmem_dsc.paddr); printf("After this, you may type CR to remove the allocated buffer \r\n"); printf("from the RTPC A32 slave space. Good luck, and have a nice day!\r\n"); fflush(stdout); getchar(); /* * release memory, unmap VME */ if (err=uio_cfree(&cmem_dsc)) { uio_perror("uio_cfree",err); exit(0); } err=vme_slave_unmap(vad,sz); if (err == -1) { fprintf(stderr,"unmapping from VME failed\n"); exit(0); } uio_close(); return 0; }