modules/batt_health/nvm.c
static bool nvm_file_read(int fd, bhd_state_t *state)
{
	bool is_success = false;
	ssize_t r;
	nvm_file_hdr_t hdr;

	/* Read the standard header first */
	r = read(fd, &hdr, sizeof(hdr));
	if (r != sizeof(hdr))
		ALOGE("NVM Read - Failed to read file header, r = %lu, errno = %d (%s)",
			r, errno, strerror(errno));
	else if (strncmp(hdr.text, NVM_HDR_TEXT, sizeof(hdr.text)))
		ALOGE("NVM Read - Invalid header");
	else {
		ALOGD("NVM Read - Read header, version = %d, file write count = %llu, "
			"time = %s", hdr.version, hdr.file_write_count,
			ctime(&hdr.timestamp));

		/* Read rest of file depending on format version */
		switch (hdr.version) {
		case NVM_FILE_HEADER_VERSION_1:
			is_success = nvm_file_ver_0_read(fd, state);
			break;

		default:
			ALOGE("NVM Read - Unknown version %d", hdr.version);
			break;
		}

		if (is_success)
			state->file_write_count = hdr.file_write_count;
	}

	return is_success;
}
/* Reads battery health file from NVM */
Reads battery health file from NVM
Reads battery health file from NVM
static bool nvm_file_read(int fd, bhd_state_t *state)
{
	bool is_success = false;
	ssize_t r;
	nvm_file_hdr_t hdr;
	r = read(fd, &hdr, sizeof(hdr));
	if (r != sizeof(hdr))
		ALOGE("NVM Read - Failed to read file header, r = %lu, errno = %d (%s)",
			r, errno, strerror(errno));
	else if (strncmp(hdr.text, NVM_HDR_TEXT, sizeof(hdr.text)))
		ALOGE("NVM Read - Invalid header");
	else {
		ALOGD("NVM Read - Read header, version = %d, file write count = %llu, "
			"time = %s", hdr.version, hdr.file_write_count,
			ctime(&hdr.timestamp));
		switch (hdr.version) {
		case NVM_FILE_HEADER_VERSION_1:
			is_success = nvm_file_ver_0_read(fd, state);
			break;
		default:
			ALOGE("NVM Read - Unknown version %d", hdr.version);
			break;
		}
		if (is_success)
			state->file_write_count = hdr.file_write_count;
	}
	return is_success;
}
static bool nvm_file_read ( int fd , bhd_state_t * state ) { bool is_success = false ; ssize_t r ; nvm_file_hdr_t hdr ; r = read ( fd , & hdr , sizeof ( hdr ) ) ; if ( r != sizeof ( hdr ) ) ALOGE ( " " , r , errno , strerror ( errno ) ) ; else if ( strncmp ( hdr . text , NVM_HDR_TEXT , sizeof ( hdr . text ) ) ) ALOGE ( " " ) ; else { ALOGD ( " " " " , hdr . version , hdr . file_write_count , ctime ( & hdr . timestamp ) ) ; switch ( hdr . version ) { case NVM_FILE_HEADER_VERSION_1 : is_success = nvm_file_ver_0_read ( fd , state ) ; break ; default : ALOGE ( " " , hdr . version ) ; break ; } if ( is_success ) state -> file_write_count = hdr . file_write_count ; } return is_success ; }
Reads battery health file from NVM
Reads battery health file from NVM
/* Read the standard header first */ /* Read rest of file depending on format version */