Assertion on file descriptor write access
This commit is contained in:
parent
804a6b1485
commit
9e96ebaca0
1 changed files with 13 additions and 0 deletions
13
writeimg.c
13
writeimg.c
|
|
@ -74,6 +74,9 @@ int perform_write(write_job_t *job) {
|
|||
int block_fd = open(job->dev_name, O_RDWR);
|
||||
int file_fd = open(job->filename, O_RDONLY);
|
||||
|
||||
assert(block_fd >= 0);
|
||||
assert(file_fd >= 0);
|
||||
|
||||
/* TODO: Checks */
|
||||
assert(job->bufsize >= job->block_size);
|
||||
|
||||
|
|
@ -202,10 +205,20 @@ int main(int argc, char *argv[]) {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Seems to be the cleanest way to check for write perm on a blockdev */
|
||||
int fd = open(wjob.dev_name, O_WRONLY);
|
||||
if (fd < 0) {
|
||||
printf("Cannot write to \"%s\", do you have write permissions?\n", wjob.dev_name);
|
||||
exit(1);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
printf("Writing %s to %s\n", wjob.filename, wjob.dev_name);
|
||||
|
||||
wjob.buffer = malloc(BLOCKSIZE);
|
||||
wjob.buffer2 = malloc(BLOCKSIZE);
|
||||
assert(wjob.buffer);
|
||||
assert(wjob.buffer2);
|
||||
|
||||
wjob.bufsize = BLOCKSIZE;
|
||||
wjob.block_size = BLOCKSIZE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue