int os_process_parent(int pid) { char stat[STAT_PATH_LEN]; char data[256]; int parent, n, fd; if(pid == -1) return(-1); snprintf(stat, sizeof(stat), "/proc/%d/stat", pid); fd = os_open_file(stat, of_read(OPENFLAGS()), 0); if(fd < 0){ printk("Couldn't open '%s', err = %d\n", stat, -fd); return(FAILURE_PID); } n = os_read_file(fd, data, sizeof(data)); os_close_file(fd); if(n < 0){ printk("Couldn't read '%s', err = %d\n", stat, -n); return(FAILURE_PID); } parent = FAILURE_PID; n = sscanf(data, "%*d " COMM_SCANF " %*c %d", &parent); if(n != 1) printk("Failed to scan '%s'\n", data); return(parent); }
unsigned long os_process_pc(int pid) { char proc_stat[STAT_PATH_LEN], buf[256]; unsigned long pc; int fd, err; sprintf(proc_stat, "/proc/%d/stat", pid); fd = os_open_file(proc_stat, of_read(OPENFLAGS()), 0); if(fd < 0){ printk("os_process_pc - couldn't open '%s', err = %d\n", proc_stat, -fd); return(ARBITRARY_ADDR); } err = os_read_file(fd, buf, sizeof(buf)); if(err < 0){ printk("os_process_pc - couldn't read '%s', err = %d\n", proc_stat, -err); os_close_file(fd); return(ARBITRARY_ADDR); } os_close_file(fd); pc = ARBITRARY_ADDR; if(sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d " "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d " "%*d %*d %*d %*d %*d %lu", &pc) != 1){ printk("os_process_pc - couldn't find pc in '%s'\n", buf); } return(pc); }
static int file_removed(struct dentry *dentry, const char *file) { char *host_file; int extra, fd; extra = 0; if(file != NULL) extra += strlen(file) + 1; host_file = dentry_name(dentry, extra + strlen("/remove")); if(host_file == NULL){ printk("file_removed : allocation failed\n"); return(-ENOMEM); } if(file != NULL){ strcat(host_file, "/"); strcat(host_file, file); } strcat(host_file, "/remove"); fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); kfree(host_file); if(fd >= 0){ os_close_file(fd); return(1); } return(0); }
ssize_t ConsoleHandle::ReadAt(void */*cookie*/, off_t /*pos*/, void *buffer, size_t bufferSize) { // don't seek in character devices return of_read(fHandle, buffer, bufferSize); }
ssize_t Handle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) { if (pos == -1 || of_seek(fHandle, pos) != OF_FAILED) return of_read(fHandle, buffer, bufferSize); return B_ERROR; }
static int cimod_read(char *buffer, int len) { int ret; ret = of_read(myself, buffer, len); dprintf("cimod read returned: %i!\n", ret); return ret; }
int os_file_mode(char *file, struct openflags *mode_out) { *mode_out = OPENFLAGS(); if(!access(file, W_OK)) *mode_out = of_write(*mode_out); else if(errno != EACCES) return(-errno); if(!access(file, R_OK)) *mode_out = of_read(*mode_out); else if(errno != EACCES) return(-errno); return(0); }
int load_initrd(char *filename, void *buf, int size) { int fd, n; if((fd = os_open_file(filename, of_read(OPENFLAGS()), 0)) < 0){ printk("Opening '%s' failed - errno = %d\n", filename, errno); return(-1); } if((n = read(fd, buf, size)) != size){ printk("Read of %d bytes from '%s' returned %d, errno = %d\n", size, filename, n, errno); return(-1); } return(0); }
snk_module_t * cimod_check_and_install(void) { uint8_t tmpbuf[8]; dprintf("entered cimod_check_and_install!\n"); myself = of_interpret_1("my-parent", tmpbuf); dprintf("cimod: myself=%lx\n", myself); /* Check whether "read" and "write" functions are provided by the * device tree node: */ if (of_read(myself, tmpbuf, 0) == -1 || of_write(myself, tmpbuf, 0) == -1) { dprintf("cimod: missing read or write!\n"); return NULL; } return &ci_module; }
static int load_initrd(char *filename, void *buf, int size) { int fd, n; fd = os_open_file(filename, of_read(OPENFLAGS()), 0); if (fd < 0) { printk(KERN_ERR "Opening '%s' failed - err = %d\n", filename, -fd); return -1; } n = os_read_file(fd, buf, size); if (n != size) { printk(KERN_ERR "Read of %d bytes from '%s' failed, " "err = %d\n", size, filename, -n); return -1; } os_close_file(fd); return 0; }
int not_dead_yet(char *dir) { char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; char pid[sizeof("nnnnn\0")], *end; int dead, fd, p, n; sprintf(file, "%s/pid", dir); dead = 0; fd = os_open_file(file, of_read(OPENFLAGS()), 0); if(fd < 0){ if(fd != -ENOENT){ printk("not_dead_yet : couldn't open pid file '%s', " "err = %d\n", file, -fd); return(1); } dead = 1; } if(fd > 0){ n = os_read_file(fd, pid, sizeof(pid)); if(n < 0){ printk("not_dead_yet : couldn't read pid file '%s', " "err = %d\n", file, -n); return(1); } p = strtoul(pid, &end, 0); if(end == pid){ printk("not_dead_yet : couldn't parse pid file '%s', " "errno = %d\n", file, errno); dead = 1; } if(((kill(p, 0) < 0) && (errno == ESRCH)) || (p == CHOOSE_MODE(tracing_pid, os_getpid()))) dead = 1; } if(!dead) return(1); return(actually_do_remove(dir)); }