Skip to content
Snippets Groups Projects
Commit bf32ff32 authored by Julian Oes's avatar Julian Oes Committed by Daniel Agar
Browse files

dataman: make _file_write more readable

This should not be any functional change. The only difference are the
variable scopes, and early return versus nested ifs.
parent dc3341db
No related branches found
No related tags found
No related merge requests found
...@@ -495,11 +495,9 @@ static ssize_t ...@@ -495,11 +495,9 @@ static ssize_t
_file_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf, size_t count) _file_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf, size_t count)
{ {
unsigned char buffer[g_per_item_size[item]]; unsigned char buffer[g_per_item_size[item]];
size_t len;
int offset;
/* Get the offset for this item */ /* Get the offset for this item */
offset = calculate_offset(item, index); const int offset = calculate_offset(item, index);
/* If item type or index out of range, return error */ /* If item type or index out of range, return error */
if (offset < 0) { if (offset < 0) {
...@@ -523,20 +521,17 @@ _file_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const v ...@@ -523,20 +521,17 @@ _file_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const v
count += DM_SECTOR_HDR_SIZE; count += DM_SECTOR_HDR_SIZE;
len = -1; if (lseek(dm_operations_data.file.fd, offset, SEEK_SET) != offset) {
return -1;
/* Seek to the right spot in the data manager file and write the data item */
if (lseek(dm_operations_data.file.fd, offset, SEEK_SET) == offset) {
if ((len = write(dm_operations_data.file.fd, buffer, count)) == count) {
fsync(dm_operations_data.file.fd); /* Make sure data is written to physical media */
}
} }
/* Make sure the write succeeded */ if ((write(dm_operations_data.file.fd, buffer, count)) != (ssize_t)count) {
if (len != count) {
return -1; return -1;
} }
/* Make sure data is written to physical media */
fsync(dm_operations_data.file.fd);
/* All is well... return the number of user data written */ /* All is well... return the number of user data written */
return count - DM_SECTOR_HDR_SIZE; return count - DM_SECTOR_HDR_SIZE;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment