diff options
author | Richard Genoud <richard.genoud@gmail.com> | 2012-08-22 18:04:37 +0200 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-08-23 12:48:54 +0300 |
commit | 9d8751b3f5c6358b6167c38899f1e41498d24a45 (patch) | |
tree | db952e5015e6f33a2e93e3cf477227ea5d52dfc9 /ubi-utils/libubi.c | |
parent | 878e06ea555ba5dbfb974b3904d1a86a9a0e20f5 (diff) |
ubiattach: fail if kernel ignores max_beb_per1024
If the kernel doesn't know the max_beb_per1024 parameter in the attach
ioctl, but the call still succeeded ubi_attach and ubi_attach_mtd will
return 1 instead of 0.
In this case, the ubiattach command will detach the device and fail with
an error message.
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'ubi-utils/libubi.c')
-rw-r--r-- | ubi-utils/libubi.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ubi-utils/libubi.c b/ubi-utils/libubi.c index 8e1d3ee..a7463e8 100644 --- a/ubi-utils/libubi.c +++ b/ubi-utils/libubi.c @@ -769,6 +769,35 @@ int ubi_attach(libubi_t desc, const char *node, struct ubi_attach_request *req) r.ubi_num = req->dev_num; r.mtd_num = req->mtd_num; r.vid_hdr_offset = req->vid_hdr_offset; + + if (req->max_beb_per1024) { + /* + * We first have to check if the running kernel supports the + * 'max_beb_per1024' parameter. To do this, we invoke the + * "attach" ioctl 2 times: first with incorrect value %-1 of + * 'max_beb_per1024'. + * + * If the ioctl succeeds, it means that the kernel doesn't + * support the feature and just ignored our 'max_beb_per1024' + * value. + * + * If the ioctl returns -EINVAL, we assume this is because + * 'max_beb_per1024' was set to -1, and we invoke the ioctl for + * the second time with the 'max_beb_per1024' value. + */ + r.max_beb_per1024 = -1; + ret = do_attach(node, &r); + if (ret == 0) { + req->dev_num = r.ubi_num; + /* + * The call succeeded. It means that the kernel ignored + * 'max_beb_per1024' parameter. + */ + return 1; + } else if (errno != EINVAL) + return ret; + } + r.max_beb_per1024 = req->max_beb_per1024; ret = do_attach(node, &r); |