int cavan_sha_update2(struct cavan_sha_context *context, int fd) { while (1) { ssize_t rdlen; char buff[4096]; rdlen = ffile_read(fd, buff, sizeof(buff)); if (rdlen <= 0) { return rdlen; } cavan_sha_update(context, buff, rdlen); } return 0; }
struct buffer *read_lines(const char *file_path) { struct stat st; struct buffer *buff; int ret; int fd; fd = open(file_path, O_RDONLY | O_BINARY); if (fd < 0) { perror("open"); return NULL; } ret = fstat(fd, &st); if (ret < 0) { perror("fstat"); goto out_close_file; } buff = malloc_buffer(st.st_size); if (buff == NULL) { perror("malloc_buffer"); goto out_close_file; } ret = ffile_read(fd, buff->space, buff->size); if (ret < 0) { perror("ffile_read"); goto out_free_buff; } close(fd); return buff; out_free_buff: free_buffer(buff); out_close_file: close(fd); return NULL; }
static int ext2_read_directory_entry(struct ext2_desc *desc, off_t offset, struct ext2_directory_entry *entry) { ssize_t rdlen; rdlen = ffile_readfrom(desc->fd, entry, EXT2_DIR_ENTRY_HEADER_SIZE, offset); if (rdlen < 0) { pr_error_info("read"); return rdlen; } if (entry->inode == 0) { pr_red_info("inode is zero"); return -EINVAL; } if (entry->name_len == 0) { pr_red_info("name length is zero"); return -EINVAL; } if (entry->rec_len < EXT2_DIR_ENTRY_HEADER_SIZE + entry->name_len) { pr_red_info("rec_len = %d", entry->rec_len); return -EINVAL; } rdlen = ffile_read(desc->fd, entry->name, entry->name_len); if (rdlen < 0) { pr_error_info("read"); return rdlen; } entry->name[rdlen] = 0; #if CAVAN_EXT2_DEBUG show_ext2_directory_entry(entry); #endif return 0; }