int sys_write(int fp, off_t off, char *buf, size_t count) { struct file *f = get_file_pointer((task_t *)current_task, fp); if(!f) return -EBADF; return do_sys_write(f, off, buf, count); }
int sys_posix_fsstat(int fd, struct posix_statfs *sb) { struct file *f = get_file_pointer((task_t *)current_task, fd); if(!f) return -EBADF; struct inode *i = f->inode; fput((task_t *)current_task, fd, 0); if(!i) return -EBADF; return vfs_callback_fsstat(i, sb); }
int sys_getpath(int f, char *b, int len) { if(!b) return -EINVAL; struct file *file = get_file_pointer((task_t *) current_task, f); if(!file) return -EBADF; int ret = get_path_string(file->inode, b, len); fput((task_t *)current_task, f, 0); return ret; }
int sys_fstat(int fp, struct stat *sb) { if(!sb) return -EINVAL; struct file *f = get_file_pointer((task_t *)current_task, fp); if(!f) return -EBADF; do_stat(f->inode, sb); fput((task_t *)current_task, fp, 0); return 0; }
int sys_readpos(int fp, char *buf, size_t count) { if(!buf) return -EINVAL; struct file *f = get_file_pointer((task_t *)current_task, fp); if(!f) return -EBADF; if(!(f->flags & _FREAD)) return -EACCES; return do_sys_read(f, f->pos, buf, count); }
int sys_isatty(int f) { struct file *file = get_file_pointer((task_t *) current_task, f); if(!file) return -EBADF; struct inode *inode = file->inode; if(S_ISCHR(inode->mode) && (MAJOR(inode->dev) == 3 || MAJOR(inode->dev) == 4)) { fput((task_t *)current_task, f, 0); return 1; } fput((task_t *)current_task, f, 0); return 0; }
int sys_writepos(int fp, char *buf, size_t count) { struct file *f = get_file_pointer((task_t *)current_task, fp); if(!f) return -EBADF; if(!count || !buf) return -EINVAL; if(!(f->flags & _FWRITE)) return -EACCES; assert(f->inode); int ret=do_sys_write(f, f->flags & _FAPPEND ? f->inode->len : f->pos, buf, count); if(ret > 0) f->pos += ret; return ret; }
int sys_dirstat_fd(int fd, unsigned num, char *namebuf, struct stat *statbuf) { if(!namebuf || !statbuf) return -EINVAL; struct file *f = get_file_pointer((task_t *)current_task, fd); if(!f) return -EBADF; struct inode *i = read_idir(f->inode, num); fput((task_t *)current_task, fd, 0); if(!i) return -ESRCH; do_stat(i, statbuf); strncpy(namebuf, i->name, 128); if(i->dynamic) { rwlock_acquire(&i->rwl, RWL_WRITER); free_inode(i, 0); } return 0; }
static int write2emmc(int pkg_fd, int img_count, int retry_count, enum swan_image_type *skip_types, size_t skip_img_count) { int ret; int img_fd; u32 tmp_crc32; struct swan_image_info img_info; while (img_count) { int retry; ret = read_image_info(pkg_fd, &img_info); if (ret < 0) { pr_err_info("read_image_info"); return ret; } if (array_has_element(img_info.type, (int *) skip_types, skip_img_count)) { ret = lseek(pkg_fd, img_info.length, SEEK_CUR); if (ret < 0) { pr_err_info("lseek"); return ret; } pr_warn_info("skipping image \"%s\" ...", swan_image_type_tostring(img_info.type)); continue; } img_fd = open_dest_device(&img_info); if (img_fd < 0) { pr_err_info("open_dest_device"); return ret; } retry = retry_count; while (retry--) { off_t pkg_pointer_bak; ret = get_file_pointer(pkg_fd, &pkg_pointer_bak); if (ret < 0) { pr_err_info("can't backup file pointer"); goto out_close_img; } ret = read_simple_image(pkg_fd, img_fd, img_info.length, img_info.offset); if (ret < 0) { pr_err_info("get_image"); goto out_close_img; } ret = lseek(img_fd, img_info.offset, SEEK_SET); if (ret < 0) { pr_err_info("lseek"); goto out_close_img; } fsync(img_fd); println("check image crc32 checksum"); tmp_crc32 = 0; ret = ffile_ncrc32(img_fd, img_info.length, &tmp_crc32); if (ret < 0) { pr_err_info("ffile_ncrc32"); goto out_close_img; } println("img_crc32 = 0x%08x, tmp_crc32 = 0x%08x", img_info.crc32, tmp_crc32); if (img_info.crc32 ^ tmp_crc32) { pr_err_info("image crc32 checksum is not match, retry = %d", retry); } else { pr_green_info("image crc32 checksum is match"); break; } ret = lseek(pkg_fd, pkg_pointer_bak, SEEK_SET); if (ret < 0) { pr_err_info("recovery package file pointer"); goto out_close_img; } } if (retry < 0) { ret = -EIO; goto out_close_img; } close(img_fd); img_count--; } return 0; out_close_img: close(img_fd); return ret; }
void c_read_ints(const char* filename, int64_t& position, int64_t* vector, int64_t& length){ FILE* fp = get_file_pointer(filename); fseek(fp, (position-1)*length*sizeof(int64_t), SEEK_SET); size_t count = fread(vector, sizeof(int64_t), length, fp); error_processing(fp, filename, "reading", count, length, position); }
void c_write_vector(const char* filename, int64_t& position, double* vector, int64_t& length){ FILE* fp = get_file_pointer(filename); fseek(fp, (position-1)*length*sizeof(double), SEEK_SET); size_t count = fwrite(vector, sizeof(double), length , fp); error_processing(fp, filename, "writing", count, length, position); }
int sys_read(int fp, off_t off, char *buf, size_t count) { return do_sys_read(get_file_pointer((task_t *)current_task, fp), off, buf, count); }