-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fdtable: fix longstanding layering violations #75348
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,13 @@ struct flashdisk_data { | |
struct disk_info info; | ||
struct k_mutex lock; | ||
const unsigned int area_id; | ||
const off_t offset; | ||
const k_off_t offset; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure whether using I think that we need separate types for storage/external devices, with long addresses, independent from whatever kernel is running on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using It might be better to retype this field in a separate PR. |
||
uint8_t *const cache; | ||
const size_t cache_size; | ||
const size_t size; | ||
const size_t sector_size; | ||
size_t page_size; | ||
off_t cached_addr; | ||
k_off_t cached_addr; | ||
bool cache_valid; | ||
bool cache_dirty; | ||
bool erase_required; | ||
|
@@ -89,7 +89,7 @@ static int flashdisk_init_runtime(struct flashdisk_data *ctx, | |
{ | ||
int rc; | ||
struct flash_pages_info page; | ||
off_t offset; | ||
k_off_t offset; | ||
|
||
flashdisk_probe_erase(ctx); | ||
|
||
|
@@ -126,7 +126,8 @@ static int flashdisk_init_runtime(struct flashdisk_data *ctx, | |
while (offset < ctx->offset + ctx->size) { | ||
rc = flash_get_page_info_by_offs(ctx->info.dev, offset, &page); | ||
if (rc < 0) { | ||
LOG_ERR("Error %d getting page info at offset %lx", rc, offset); | ||
LOG_ERR("Error %d getting page info at offset %lx", rc, | ||
(long)offset); | ||
return rc; | ||
} | ||
if (page.size != ctx->page_size) { | ||
|
@@ -200,7 +201,7 @@ static int disk_flash_access_read(struct disk_info *disk, uint8_t *buff, | |
uint32_t start_sector, uint32_t sector_count) | ||
{ | ||
struct flashdisk_data *ctx; | ||
off_t fl_addr; | ||
k_off_t fl_addr; | ||
uint32_t remaining; | ||
uint32_t offset; | ||
uint32_t len; | ||
|
@@ -272,7 +273,7 @@ static int flashdisk_cache_commit(struct flashdisk_data *ctx) | |
return 0; | ||
} | ||
|
||
static int flashdisk_cache_load(struct flashdisk_data *ctx, off_t fl_addr) | ||
static int flashdisk_cache_load(struct flashdisk_data *ctx, k_off_t fl_addr) | ||
{ | ||
int rc; | ||
|
||
|
@@ -308,11 +309,11 @@ static int flashdisk_cache_load(struct flashdisk_data *ctx, off_t fl_addr) | |
/* input size is either less or equal to a block size (ctx->page_size) | ||
* and write data never spans across adjacent blocks. | ||
*/ | ||
static int flashdisk_cache_write(struct flashdisk_data *ctx, off_t start_addr, | ||
uint32_t size, const void *buff) | ||
static int flashdisk_cache_write(struct flashdisk_data *ctx, k_off_t start_addr, uint32_t size, | ||
const void *buff) | ||
{ | ||
int rc; | ||
off_t fl_addr; | ||
k_off_t fl_addr; | ||
uint32_t offset; | ||
|
||
/* adjust offset if starting address is not erase-aligned address */ | ||
|
@@ -347,7 +348,7 @@ static int disk_flash_access_write(struct disk_info *disk, const uint8_t *buff, | |
uint32_t start_sector, uint32_t sector_count) | ||
{ | ||
struct flashdisk_data *ctx; | ||
off_t fl_addr; | ||
k_off_t fl_addr; | ||
uint32_t remaining; | ||
uint32_t size; | ||
int rc = 0; | ||
|
@@ -369,7 +370,7 @@ static int disk_flash_access_write(struct disk_info *disk, const uint8_t *buff, | |
|
||
/* check if start address is erased-aligned address */ | ||
if (fl_addr & (ctx->page_size - 1)) { | ||
off_t block_bnd; | ||
k_off_t block_bnd; | ||
|
||
/* not aligned */ | ||
/* check if the size goes over flash block boundary */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really correct? This driver is for native_sim, and some 10 lines later the return value from the host libc's
read()
is assigned to it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The definitions should be identical (as far as the underlying type goes). Otherwise, there would be warnings / errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't doubt that. I was mainly wondering where a
native_sim
driver like this conceptually sits in the software stack. It's calling the host OS APIs (likeread()
) so in that sense it could be seen to be above POSIX (in which casessize_t
would be more appropriate), however the driver also accesses Zephyr kernel APIs. Anyway, this isn't necessarily that critical (as you say, the types should be the same), which is why I didn't want to block this PR by requesting changes, but I do think it would be good to understand wherenative_sim
driver code sits in the software stack.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, it's kind of a recursion. I would still say those drivers sit below (Zephyr's) POSIX API.
The namespace issue is kind of an unfortunate side-effect (not without solutions, ofc)