1 /* vi: set sw=4 ts=4: */
2 /* Ported to busybox from mtd-utils.
4 * Licensed under GPLv2, see file LICENSE in this tarball for details.
7 #include <mtd/mtd-user.h>
9 int flash_lock_unlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
10 int flash_lock_unlock_main(int argc UNUSED_PARAM, char **argv)
12 /* note: fields in these structs are 32-bits.
13 * apparently we can't win anything by using off_t
14 * or long long's for offset and/or sectors vars. */
15 struct mtd_info_user info;
16 struct erase_info_user lock;
21 #define do_lock (ENABLE_FLASH_LOCK && (!ENABLE_FLASH_UNLOCK || (applet_name[6] == 'l')))
26 /* parse offset and number of sectors to lock */
30 if (!argv[2] || !argv[3])
32 offset = xstrtoul(argv[2], 0);
33 sectors = xstrtol(argv[3], 0);
36 fd = xopen(argv[1], O_RDWR);
38 xioctl(fd, MEMGETINFO, &info);
41 lock.length = info.size;
43 unsigned long size = info.size - info.erasesize;
45 bb_error_msg_and_die("%lx is beyond device size %lx\n",
50 sectors = info.size / info.erasesize;
52 // isn't this useless?
53 unsigned long num = info.size / info.erasesize;
55 bb_error_msg_and_die("%ld are too many "
56 "sectors, device only has "
57 "%ld\n", sectors, num);
62 lock.length = sectors * info.erasesize;
63 xioctl(fd, MEMLOCK, &lock);
65 xioctl(fd, MEMUNLOCK, &lock);