Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read and write syscalls may read less bytes than requested #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions lfs_fuse_bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,24 @@ int lfs_fuse_bd_read(const struct lfs_config *cfg, lfs_block_t block,
assert(block < cfg->block_count);

// go to block
off_t err = lseek(fd, (off_t)block*cfg->block_size + (off_t)off, SEEK_SET);
off_t offrq = (off_t)block*cfg->block_size + (off_t)off;
off_t err = lseek(fd,offrq, SEEK_SET);
if (err < 0) {
return -errno;
} else if( err != offrq ) {
return LFS_ERR_IO;
}

// read block
ssize_t res = read(fd, buffer, (size_t)size);
if (res < 0) {
return -errno;
}

char* rdb = buffer;
do {
// read block
ssize_t res = read(fd, rdb, (size_t)size);
if (res <= 0) {
return (res==0)?(LFS_ERR_IO):(-errno);
} else {
rdb += res;
size -= res;
}
} while( size > 0 );
return 0;
}

Expand All @@ -93,16 +100,25 @@ int lfs_fuse_bd_prog(const struct lfs_config *cfg, lfs_block_t block,
assert(block < cfg->block_count);

// go to block
off_t err = lseek(fd, (off_t)block*cfg->block_size + (off_t)off, SEEK_SET);
off_t offrq = (off_t)block*cfg->block_size + (off_t)off;
off_t err = lseek(fd,offrq, SEEK_SET);
if (err < 0) {
return -errno;
} else if(err != offrq )
{
return LFS_ERR_IO;
}

// write block
ssize_t res = write(fd, buffer, (size_t)size);
if (res < 0) {
return -errno;
}
const char* wrb = buffer;
do {
// write block
ssize_t res = write(fd, wrb, (size_t)size);
if (res <= 0) {
return (res==0)?(LFS_ERR_IO):(-errno);
} else {
wrb += res;
size -= res;
}
} while(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something, but why does this do/while loop have 0 as a condition?


return 0;
}
Expand All @@ -119,7 +135,6 @@ int lfs_fuse_bd_sync(const struct lfs_config *cfg) {
if (err) {
return -errno;
}

return 0;
}