diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2008-01-24 10:04:01 -0500 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2008-01-25 09:41:25 -0500 |
commit | 1b68d0eea5daddc762c54bf02154f4ad607d9ce8 (patch) | |
tree | e918b5d434da7213a7af8cff2b6bd692035f72cf /drivers/mtd/ubi | |
parent | 0411e7353192d7deebd4f50b9ee41974ec3a634c (diff) |
UBI: simplify internal interfaces
Instead of passing vol_id to all functions and then find
struct ubi_volume, pass struct ubi_volume pointer.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r-- | drivers/mtd/ubi/cdev.c | 4 | ||||
-rw-r--r-- | drivers/mtd/ubi/ubi.h | 5 | ||||
-rw-r--r-- | drivers/mtd/ubi/upd.c | 63 |
3 files changed, 36 insertions, 36 deletions
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index d9bd49421cce..0c4044d6cae0 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c | |||
@@ -354,7 +354,7 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf, | |||
354 | if (!vol->updating) | 354 | if (!vol->updating) |
355 | return vol_cdev_direct_write(file, buf, count, offp); | 355 | return vol_cdev_direct_write(file, buf, count, offp); |
356 | 356 | ||
357 | err = ubi_more_update_data(ubi, vol->vol_id, buf, count); | 357 | err = ubi_more_update_data(ubi, vol, buf, count); |
358 | if (err < 0) { | 358 | if (err < 0) { |
359 | ubi_err("cannot write %zd bytes of update data, error %d", | 359 | ubi_err("cannot write %zd bytes of update data, error %d", |
360 | count, err); | 360 | count, err); |
@@ -427,7 +427,7 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file, | |||
427 | if (err < 0) | 427 | if (err < 0) |
428 | break; | 428 | break; |
429 | 429 | ||
430 | err = ubi_start_update(ubi, vol->vol_id, bytes); | 430 | err = ubi_start_update(ubi, vol, bytes); |
431 | if (bytes == 0) | 431 | if (bytes == 0) |
432 | revoke_exclusive(desc, UBI_READWRITE); | 432 | revoke_exclusive(desc, UBI_READWRITE); |
433 | break; | 433 | break; |
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index a8cdbd0364fb..3a88cf1eaaa8 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
@@ -423,8 +423,9 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol); | |||
423 | void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol); | 423 | void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol); |
424 | 424 | ||
425 | /* upd.c */ | 425 | /* upd.c */ |
426 | int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes); | 426 | int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol, |
427 | int ubi_more_update_data(struct ubi_device *ubi, int vol_id, | 427 | long long bytes); |
428 | int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol, | ||
428 | const void __user *buf, int count); | 429 | const void __user *buf, int count); |
429 | 430 | ||
430 | /* misc.c */ | 431 | /* misc.c */ |
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c index 3defa579fab0..59c61ab4f2aa 100644 --- a/drivers/mtd/ubi/upd.c +++ b/drivers/mtd/ubi/upd.c | |||
@@ -45,30 +45,30 @@ | |||
45 | /** | 45 | /** |
46 | * set_update_marker - set update marker. | 46 | * set_update_marker - set update marker. |
47 | * @ubi: UBI device description object | 47 | * @ubi: UBI device description object |
48 | * @vol_id: volume ID | 48 | * @vol: volume description object |
49 | * | 49 | * |
50 | * This function sets the update marker flag for volume @vol_id. Returns zero | 50 | * This function sets the update marker flag for volume @vol. Returns zero |
51 | * in case of success and a negative error code in case of failure. | 51 | * in case of success and a negative error code in case of failure. |
52 | */ | 52 | */ |
53 | static int set_update_marker(struct ubi_device *ubi, int vol_id) | 53 | static int set_update_marker(struct ubi_device *ubi, struct ubi_volume *vol) |
54 | { | 54 | { |
55 | int err; | 55 | int err; |
56 | struct ubi_vtbl_record vtbl_rec; | 56 | struct ubi_vtbl_record vtbl_rec; |
57 | struct ubi_volume *vol = ubi->volumes[vol_id]; | ||
58 | 57 | ||
59 | dbg_msg("set update marker for volume %d", vol_id); | 58 | dbg_msg("set update marker for volume %d", vol->vol_id); |
60 | 59 | ||
61 | if (vol->upd_marker) { | 60 | if (vol->upd_marker) { |
62 | ubi_assert(ubi->vtbl[vol_id].upd_marker); | 61 | ubi_assert(ubi->vtbl[vol->vol_id].upd_marker); |
63 | dbg_msg("already set"); | 62 | dbg_msg("already set"); |
64 | return 0; | 63 | return 0; |
65 | } | 64 | } |
66 | 65 | ||
67 | memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record)); | 66 | memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id], |
67 | sizeof(struct ubi_vtbl_record)); | ||
68 | vtbl_rec.upd_marker = 1; | 68 | vtbl_rec.upd_marker = 1; |
69 | 69 | ||
70 | mutex_lock(&ubi->volumes_mutex); | 70 | mutex_lock(&ubi->volumes_mutex); |
71 | err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); | 71 | err = ubi_change_vtbl_record(ubi, vol->vol_id, &vtbl_rec); |
72 | mutex_unlock(&ubi->volumes_mutex); | 72 | mutex_unlock(&ubi->volumes_mutex); |
73 | vol->upd_marker = 1; | 73 | vol->upd_marker = 1; |
74 | return err; | 74 | return err; |
@@ -77,23 +77,24 @@ static int set_update_marker(struct ubi_device *ubi, int vol_id) | |||
77 | /** | 77 | /** |
78 | * clear_update_marker - clear update marker. | 78 | * clear_update_marker - clear update marker. |
79 | * @ubi: UBI device description object | 79 | * @ubi: UBI device description object |
80 | * @vol_id: volume ID | 80 | * @vol: volume description object |
81 | * @bytes: new data size in bytes | 81 | * @bytes: new data size in bytes |
82 | * | 82 | * |
83 | * This function clears the update marker for volume @vol_id, sets new volume | 83 | * This function clears the update marker for volume @vol, sets new volume |
84 | * data size and clears the "corrupted" flag (static volumes only). Returns | 84 | * data size and clears the "corrupted" flag (static volumes only). Returns |
85 | * zero in case of success and a negative error code in case of failure. | 85 | * zero in case of success and a negative error code in case of failure. |
86 | */ | 86 | */ |
87 | static int clear_update_marker(struct ubi_device *ubi, int vol_id, long long bytes) | 87 | static int clear_update_marker(struct ubi_device *ubi, struct ubi_volume *vol, |
88 | long long bytes) | ||
88 | { | 89 | { |
89 | int err; | 90 | int err; |
90 | uint64_t tmp; | 91 | uint64_t tmp; |
91 | struct ubi_vtbl_record vtbl_rec; | 92 | struct ubi_vtbl_record vtbl_rec; |
92 | struct ubi_volume *vol = ubi->volumes[vol_id]; | ||
93 | 93 | ||
94 | dbg_msg("clear update marker for volume %d", vol_id); | 94 | dbg_msg("clear update marker for volume %d", vol->vol_id); |
95 | 95 | ||
96 | memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record)); | 96 | memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id], |
97 | sizeof(struct ubi_vtbl_record)); | ||
97 | ubi_assert(vol->upd_marker && vtbl_rec.upd_marker); | 98 | ubi_assert(vol->upd_marker && vtbl_rec.upd_marker); |
98 | vtbl_rec.upd_marker = 0; | 99 | vtbl_rec.upd_marker = 0; |
99 | 100 | ||
@@ -109,7 +110,7 @@ static int clear_update_marker(struct ubi_device *ubi, int vol_id, long long byt | |||
109 | } | 110 | } |
110 | 111 | ||
111 | mutex_lock(&ubi->volumes_mutex); | 112 | mutex_lock(&ubi->volumes_mutex); |
112 | err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); | 113 | err = ubi_change_vtbl_record(ubi, vol->vol_id, &vtbl_rec); |
113 | mutex_unlock(&ubi->volumes_mutex); | 114 | mutex_unlock(&ubi->volumes_mutex); |
114 | vol->upd_marker = 0; | 115 | vol->upd_marker = 0; |
115 | return err; | 116 | return err; |
@@ -118,23 +119,23 @@ static int clear_update_marker(struct ubi_device *ubi, int vol_id, long long byt | |||
118 | /** | 119 | /** |
119 | * ubi_start_update - start volume update. | 120 | * ubi_start_update - start volume update. |
120 | * @ubi: UBI device description object | 121 | * @ubi: UBI device description object |
121 | * @vol_id: volume ID | 122 | * @vol: volume description object |
122 | * @bytes: update bytes | 123 | * @bytes: update bytes |
123 | * | 124 | * |
124 | * This function starts volume update operation. If @bytes is zero, the volume | 125 | * This function starts volume update operation. If @bytes is zero, the volume |
125 | * is just wiped out. Returns zero in case of success and a negative error code | 126 | * is just wiped out. Returns zero in case of success and a negative error code |
126 | * in case of failure. | 127 | * in case of failure. |
127 | */ | 128 | */ |
128 | int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes) | 129 | int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol, |
130 | long long bytes) | ||
129 | { | 131 | { |
130 | int i, err; | 132 | int i, err; |
131 | uint64_t tmp; | 133 | uint64_t tmp; |
132 | struct ubi_volume *vol = ubi->volumes[vol_id]; | ||
133 | 134 | ||
134 | dbg_msg("start update of volume %d, %llu bytes", vol_id, bytes); | 135 | dbg_msg("start update of volume %d, %llu bytes", vol->vol_id, bytes); |
135 | vol->updating = 1; | 136 | vol->updating = 1; |
136 | 137 | ||
137 | err = set_update_marker(ubi, vol_id); | 138 | err = set_update_marker(ubi, vol); |
138 | if (err) | 139 | if (err) |
139 | return err; | 140 | return err; |
140 | 141 | ||
@@ -146,7 +147,7 @@ int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes) | |||
146 | } | 147 | } |
147 | 148 | ||
148 | if (bytes == 0) { | 149 | if (bytes == 0) { |
149 | err = clear_update_marker(ubi, vol_id, 0); | 150 | err = clear_update_marker(ubi, vol, 0); |
150 | if (err) | 151 | if (err) |
151 | return err; | 152 | return err; |
152 | err = ubi_wl_flush(ubi); | 153 | err = ubi_wl_flush(ubi); |
@@ -169,7 +170,7 @@ int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes) | |||
169 | /** | 170 | /** |
170 | * write_leb - write update data. | 171 | * write_leb - write update data. |
171 | * @ubi: UBI device description object | 172 | * @ubi: UBI device description object |
172 | * @vol_id: volume ID | 173 | * @vol: volume description object |
173 | * @lnum: logical eraseblock number | 174 | * @lnum: logical eraseblock number |
174 | * @buf: data to write | 175 | * @buf: data to write |
175 | * @len: data size | 176 | * @len: data size |
@@ -195,11 +196,10 @@ int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes) | |||
195 | * This function returns zero in case of success and a negative error code in | 196 | * This function returns zero in case of success and a negative error code in |
196 | * case of failure. | 197 | * case of failure. |
197 | */ | 198 | */ |
198 | static int write_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf, | 199 | static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, |
199 | int len, int used_ebs) | 200 | void *buf, int len, int used_ebs) |
200 | { | 201 | { |
201 | int err, l; | 202 | int err, l; |
202 | struct ubi_volume *vol = ubi->volumes[vol_id]; | ||
203 | 203 | ||
204 | if (vol->vol_type == UBI_DYNAMIC_VOLUME) { | 204 | if (vol->vol_type == UBI_DYNAMIC_VOLUME) { |
205 | l = ALIGN(len, ubi->min_io_size); | 205 | l = ALIGN(len, ubi->min_io_size); |
@@ -244,11 +244,10 @@ static int write_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf, | |||
244 | * the last call if the whole volume update was successfully finished, and a | 244 | * the last call if the whole volume update was successfully finished, and a |
245 | * negative error code in case of failure. | 245 | * negative error code in case of failure. |
246 | */ | 246 | */ |
247 | int ubi_more_update_data(struct ubi_device *ubi, int vol_id, | 247 | int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol, |
248 | const void __user *buf, int count) | 248 | const void __user *buf, int count) |
249 | { | 249 | { |
250 | uint64_t tmp; | 250 | uint64_t tmp; |
251 | struct ubi_volume *vol = ubi->volumes[vol_id]; | ||
252 | int lnum, offs, err = 0, len, to_write = count; | 251 | int lnum, offs, err = 0, len, to_write = count; |
253 | 252 | ||
254 | dbg_msg("write %d of %lld bytes, %lld already passed", | 253 | dbg_msg("write %d of %lld bytes, %lld already passed", |
@@ -293,8 +292,8 @@ int ubi_more_update_data(struct ubi_device *ubi, int vol_id, | |||
293 | * is the last chunk, it's time to flush the buffer. | 292 | * is the last chunk, it's time to flush the buffer. |
294 | */ | 293 | */ |
295 | ubi_assert(flush_len <= vol->usable_leb_size); | 294 | ubi_assert(flush_len <= vol->usable_leb_size); |
296 | err = write_leb(ubi, vol_id, lnum, vol->upd_buf, | 295 | err = write_leb(ubi, vol, lnum, vol->upd_buf, flush_len, |
297 | flush_len, vol->upd_ebs); | 296 | vol->upd_ebs); |
298 | if (err) | 297 | if (err) |
299 | return err; | 298 | return err; |
300 | } | 299 | } |
@@ -321,8 +320,8 @@ int ubi_more_update_data(struct ubi_device *ubi, int vol_id, | |||
321 | 320 | ||
322 | if (len == vol->usable_leb_size || | 321 | if (len == vol->usable_leb_size || |
323 | vol->upd_received + len == vol->upd_bytes) { | 322 | vol->upd_received + len == vol->upd_bytes) { |
324 | err = write_leb(ubi, vol_id, lnum, vol->upd_buf, len, | 323 | err = write_leb(ubi, vol, lnum, vol->upd_buf, |
325 | vol->upd_ebs); | 324 | len, vol->upd_ebs); |
326 | if (err) | 325 | if (err) |
327 | break; | 326 | break; |
328 | } | 327 | } |
@@ -336,7 +335,7 @@ int ubi_more_update_data(struct ubi_device *ubi, int vol_id, | |||
336 | ubi_assert(vol->upd_received <= vol->upd_bytes); | 335 | ubi_assert(vol->upd_received <= vol->upd_bytes); |
337 | if (vol->upd_received == vol->upd_bytes) { | 336 | if (vol->upd_received == vol->upd_bytes) { |
338 | /* The update is finished, clear the update marker */ | 337 | /* The update is finished, clear the update marker */ |
339 | err = clear_update_marker(ubi, vol_id, vol->upd_bytes); | 338 | err = clear_update_marker(ubi, vol, vol->upd_bytes); |
340 | if (err) | 339 | if (err) |
341 | return err; | 340 | return err; |
342 | err = ubi_wl_flush(ubi); | 341 | err = ubi_wl_flush(ubi); |