Message ID | 20241125134820.560648-1-rickard.andersson@axis.com |
---|---|
State | Superseded |
Headers | show |
Series | [1/2] ubi: Expose interface for detailed erase counters | expand |
----- Ursprüngliche Mail ----- > Von: "Rickard X Andersson" <rickard.andersson@axis.com> > +/** > + * struct ubi_ecinfo_req - a data structure used in UBI device erase count > + * information requests and responses. > + * > + * @start_ec_req: first erase counter block in range to read > + * @end_ec_req: last erase counter block in the half-open range > + * @end_ec_res: last erase counter block that was actually read > + * @erase_counters: array of erase counter values > + * @padding: reserved for future, not used, has to be zeroed > + * > + * Erase counters are read in range @start_ec_req to @end_ec_req. Range is > half-open > + * i.e erase counter of end_ec_req is not actually included. > + * The read erase counters are placed in @erase_counters. If a block is bad or > if the > + * erase counter is unknown the value of the block will be set to -1. > + */ > +struct ubi_ecinfo_req { > + __s32 start_ec_req; > + __s32 end_ec_req; > + __s32 end_ec_res; > + __s32 erase_counters[1000]; There is no need to have a limited number. Just use a flexible array. If userspace asks for more entries than the provided buffer can hold, __put_user() will fail anyways. Have a look at fibmap, I think you can the model the API the same way. Thanks, //richard
----- Ursprüngliche Mail ----- > Von: "richard" <richard@nod.at> > An: "Rickard X Andersson" <rickard.andersson@axis.com> > CC: "chengzhihao1" <chengzhihao1@huawei.com>, "linux-mtd" <linux-mtd@lists.infradead.org>, "rickard314 andersson" > <rickard314.andersson@gmail.com>, "kernel" <kernel@axis.com> > Gesendet: Montag, 25. November 2024 16:44:54 > Betreff: Re: [PATCH 1/2] ubi: Expose interface for detailed erase counters > ----- Ursprüngliche Mail ----- >> Von: "Rickard X Andersson" <rickard.andersson@axis.com> >> +/** >> + * struct ubi_ecinfo_req - a data structure used in UBI device erase count >> + * information requests and responses. >> + * >> + * @start_ec_req: first erase counter block in range to read >> + * @end_ec_req: last erase counter block in the half-open range >> + * @end_ec_res: last erase counter block that was actually read >> + * @erase_counters: array of erase counter values >> + * @padding: reserved for future, not used, has to be zeroed >> + * >> + * Erase counters are read in range @start_ec_req to @end_ec_req. Range is >> half-open >> + * i.e erase counter of end_ec_req is not actually included. >> + * The read erase counters are placed in @erase_counters. If a block is bad or >> if the >> + * erase counter is unknown the value of the block will be set to -1. >> + */ >> +struct ubi_ecinfo_req { >> + __s32 start_ec_req; >> + __s32 end_ec_req; >> + __s32 end_ec_res; >> + __s32 erase_counters[1000]; > > There is no need to have a limited number. Just use a flexible array. > If userspace asks for more entries than the provided buffer can hold, > __put_user() > will fail anyways. > > Have a look at fibmap, I think you can the model the API the same way. *fiemap Thanks, //richard
在 2024/11/25 21:48, Rickard Andersson 写道: > Using the ioctl command 'UBI_IOCECNFO' user space can obtain > detailed erase counter information of all blocks of a device. > > Signed-off-by: Rickard Andersson <rickard.andersson@axis.com> > --- > include/uapi/mtd/ubi-user.h | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/include/uapi/mtd/ubi-user.h b/include/uapi/mtd/ubi-user.h > index e1571603175e..667680e44ed4 100644 > --- a/include/uapi/mtd/ubi-user.h > +++ b/include/uapi/mtd/ubi-user.h > @@ -175,6 +175,8 @@ > #define UBI_IOCRPEB _IOW(UBI_IOC_MAGIC, 4, __s32) > /* Force scrubbing on the specified PEB */ > #define UBI_IOCSPEB _IOW(UBI_IOC_MAGIC, 5, __s32) > +/* Read detailed device erase counter information */ > +#define UBI_IOCECNFO _IOWR(UBI_IOC_MAGIC, 6, struct ubi_ecinfo_req) > > /* ioctl commands of the UBI control character device */ > > @@ -470,4 +472,27 @@ struct ubi_blkcreate_req { > __s8 padding[128]; > } __packed; > > +/** > + * struct ubi_ecinfo_req - a data structure used in UBI device erase count > + * information requests and responses. > + * > + * @start_ec_req: first erase counter block in range to read > + * @end_ec_req: last erase counter block in the half-open range > + * @end_ec_res: last erase counter block that was actually read > + * @erase_counters: array of erase counter values > + * @padding: reserved for future, not used, has to be zeroed > + * > + * Erase counters are read in range @start_ec_req to @end_ec_req. Range is half-open > + * i.e erase counter of end_ec_req is not actually included. > + * The read erase counters are placed in @erase_counters. If a block is bad or if the > + * erase counter is unknown the value of the block will be set to -1. > + */ > +struct ubi_ecinfo_req { > + __s32 start_ec_req; > + __s32 end_ec_req; > + __s32 end_ec_res; > + __s32 erase_counters[1000]; > + __s8 padding[84]; > +} __packed; > + Hi Rickard, please move the definition of 'ubi_ecinfo_req' between 'ubi_rnvol_req' and 'ubi_leb_change_req'. The last part in 'include/uapi/mtd/ubi-user.h' defines all structures for the ubi volume ioctl. > #endif /* __UBI_USER_H__ */ >
diff --git a/include/uapi/mtd/ubi-user.h b/include/uapi/mtd/ubi-user.h index e1571603175e..667680e44ed4 100644 --- a/include/uapi/mtd/ubi-user.h +++ b/include/uapi/mtd/ubi-user.h @@ -175,6 +175,8 @@ #define UBI_IOCRPEB _IOW(UBI_IOC_MAGIC, 4, __s32) /* Force scrubbing on the specified PEB */ #define UBI_IOCSPEB _IOW(UBI_IOC_MAGIC, 5, __s32) +/* Read detailed device erase counter information */ +#define UBI_IOCECNFO _IOWR(UBI_IOC_MAGIC, 6, struct ubi_ecinfo_req) /* ioctl commands of the UBI control character device */ @@ -470,4 +472,27 @@ struct ubi_blkcreate_req { __s8 padding[128]; } __packed; +/** + * struct ubi_ecinfo_req - a data structure used in UBI device erase count + * information requests and responses. + * + * @start_ec_req: first erase counter block in range to read + * @end_ec_req: last erase counter block in the half-open range + * @end_ec_res: last erase counter block that was actually read + * @erase_counters: array of erase counter values + * @padding: reserved for future, not used, has to be zeroed + * + * Erase counters are read in range @start_ec_req to @end_ec_req. Range is half-open + * i.e erase counter of end_ec_req is not actually included. + * The read erase counters are placed in @erase_counters. If a block is bad or if the + * erase counter is unknown the value of the block will be set to -1. + */ +struct ubi_ecinfo_req { + __s32 start_ec_req; + __s32 end_ec_req; + __s32 end_ec_res; + __s32 erase_counters[1000]; + __s8 padding[84]; +} __packed; + #endif /* __UBI_USER_H__ */
Using the ioctl command 'UBI_IOCECNFO' user space can obtain detailed erase counter information of all blocks of a device. Signed-off-by: Rickard Andersson <rickard.andersson@axis.com> --- include/uapi/mtd/ubi-user.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)