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

Allow configuring partition offset and size for linux file device. #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 22 additions & 2 deletions blockdev/linux/file_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
/**@brief Default filename.*/
static const char *fname = "ext2";

/**@brief Default partition offset.*/
static uint64_t part_offset = 0;

/**@brief Default partition. Zero means the rest of the file.*/
static uint64_t part_size = 0;

/**@brief Image block size.*/
#define EXT4_FILEDEV_BSIZE 512

Expand Down Expand Up @@ -73,8 +79,12 @@ static int file_dev_open(struct ext4_blockdev *bdev)
if (fseeko(dev_file, 0, SEEK_END))
return EFAULT;

file_dev.part_offset = 0;
file_dev.part_size = ftello(dev_file);
file_dev.part_offset = part_offset;
if (part_size) {
file_dev.part_size = part_size;
} else {
file_dev.part_size = ftello(dev_file) - part_offset;
}
file_dev.bdif->ph_bcnt = file_dev.part_size / file_dev.bdif->ph_bsize;

return EOK;
Expand Down Expand Up @@ -140,3 +150,13 @@ void file_dev_name_set(const char *n)
fname = n;
}
/******************************************************************************/
void file_dev_part_offset_set(const uint64_t n)
{
part_offset = n;
}
/******************************************************************************/
void file_dev_part_size_set(const uint64_t n)
{
part_size = n;
}
/******************************************************************************/
6 changes: 6 additions & 0 deletions blockdev/linux/file_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ struct ext4_blockdev *file_dev_get(void);
/**@brief Set filename to open.*/
void file_dev_name_set(const char *n);

/**@brief Set partition offset .*/
void file_dev_part_offset_set(const uint64_t n);

/**@brief Set partition size .*/
void file_dev_part_size_set(const uint64_t n);

#endif /* FILE_DEV_H_ */