[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    flash_islock applet
From:       Micha Nelissen <micha () neli ! hopto ! org>
Date:       2015-07-30 11:05:21
Message-ID: 55BA04F1.5070005 () neli ! hopto ! org
[Download RAW message or body]

Hi all,

I have added a 'flash_islock' applet to query the lock status of a given 
mtd. It is integrated into flash_lock_unlock so that much of the code 
there is reused for this functionality.

See attached patch. Might be useful for someone else too.

Regards,

Micha Nelissen

["busybox-0100-add-flash-islock.patch" (text/x-patch)]

diff -u -ru busybox-1.22.1-orig/include/applets.src.h \
                busybox-1.22.1/include/applets.src.h
--- busybox-1.22.1-orig/include/applets.src.h	2014-01-09 19:15:44.000000000 +0100
+++ busybox-1.22.1/include/applets.src.h	2015-07-29 22:16:19.723787174 +0200
@@ -147,6 +147,7 @@
 /* Benefits from suid root: better access to /dev/BLOCKDEVs: */
 IF_FINDFS(APPLET(findfs, BB_DIR_SBIN, BB_SUID_MAYBE))
 IF_FLASH_ERASEALL(APPLET(flash_eraseall, BB_DIR_USR_SBIN, BB_SUID_DROP))
+IF_FLASH_ISLOCK(APPLET_ODDNAME(flash_islock, flash_lock_unlock, BB_DIR_USR_SBIN, \
BB_SUID_DROP, flash_islock))  IF_FLASH_LOCK(APPLET_ODDNAME(flash_lock, \
flash_lock_unlock, BB_DIR_USR_SBIN, BB_SUID_DROP, flash_lock))  \
IF_FLASH_UNLOCK(APPLET_ODDNAME(flash_unlock, flash_lock_unlock, BB_DIR_USR_SBIN, \
BB_SUID_DROP, flash_unlock))  IF_FLASHCP(APPLET(flashcp, BB_DIR_USR_SBIN, \
                BB_SUID_DROP))
diff -u -ru busybox-1.22.1-orig/miscutils/Config.src \
                busybox-1.22.1/miscutils/Config.src
--- busybox-1.22.1-orig/miscutils/Config.src	2014-01-09 19:15:44.000000000 +0100
+++ busybox-1.22.1/miscutils/Config.src	2015-07-29 21:58:53.320373489 +0200
@@ -306,6 +306,12 @@
 	  The flash_lock binary from mtd-utils as of git head 5ec0c10d0. This
 	  utility locks part or all of the flash device.
 
+config FLASH_ISLOCK
+	bool "flash_islock"
+	default n  # doesn't build on Ubuntu 8.04
+	help
+	  This utility shows lock status of given sectors of a flash device.
+
 config FLASH_UNLOCK
 	bool "flash_unlock"
 	default n  # doesn't build on Ubuntu 8.04
diff -u -ru busybox-1.22.1-orig/miscutils/flash_lock_unlock.c \
                busybox-1.22.1/miscutils/flash_lock_unlock.c
--- busybox-1.22.1-orig/miscutils/flash_lock_unlock.c	2014-01-09 19:15:44.000000000 \
                +0100
+++ busybox-1.22.1/miscutils/flash_lock_unlock.c	2015-07-29 22:19:26.796614842 +0200
@@ -4,6 +4,12 @@
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
 
+//usage:#define flash_islock_trivial_usage
+//usage:       "MTD_DEVICE OFFSET SECTORS"
+//usage:#define flash_islock_full_usage "\n\n"
+//usage:       "Show lock status of part or all of an MTD device. If SECTORS is \
-1,\n" +//usage:       "then status of all sectors is shown, regardless of the value \
of OFFSET" +//usage:
 //usage:#define flash_lock_trivial_usage
 //usage:       "MTD_DEVICE OFFSET SECTORS"
 //usage:#define flash_lock_full_usage "\n\n"
@@ -31,6 +37,7 @@
 	int fd;
 
 #define do_lock (ENABLE_FLASH_LOCK && (!ENABLE_FLASH_UNLOCK || (applet_name[6] == \
'l'))) +#define is_lock (applet_name[6] == 'i')
 
 	if (!argv[1])
 		bb_show_usage();
@@ -38,7 +45,7 @@
 	/* parse offset and number of sectors to lock */
 	offset = 0;
 	sectors = -1;
-	if (do_lock) {
+	if (do_lock || is_lock) {
 		if (!argv[2] || !argv[3])
 			bb_show_usage();
 		offset = xstrtoul(argv[2], 0);
@@ -51,7 +58,7 @@
 
 	lock.start = 0;
 	lock.length = info.size;
-	if (do_lock) {
+	if (do_lock || is_lock) {
 		unsigned long size = info.size - info.erasesize;
 		if (offset > size) {
 			bb_error_msg_and_die("%lx is beyond device size %lx\n",
@@ -72,8 +79,18 @@
 
 		lock.start = offset;
 		lock.length = sectors * info.erasesize;
-		xioctl(fd, MEMLOCK, &lock);
-	} else {
+		if (is_lock) {
+		  const char *str;
+		  switch (xioctl(fd, MEMISLOCKED, &lock)) {
+		  case 0: str = "unlocked"; break;
+		  case 1: str = "locked"; break;
+		  case 2: str = "partially locked"; break;
+		  default: str = "unknown"; break;
+		  }
+		  puts(str);
+		} else
+		  xioctl(fd, MEMLOCK, &lock);
+    } else {
 		xioctl(fd, MEMUNLOCK, &lock);
 	}
 
diff -u -ru busybox-1.22.1-orig/miscutils/Kbuild.src \
                busybox-1.22.1/miscutils/Kbuild.src
--- busybox-1.22.1-orig/miscutils/Kbuild.src	2014-01-09 19:15:44.000000000 +0100
+++ busybox-1.22.1/miscutils/Kbuild.src	2015-07-29 21:57:45.412265105 +0200
@@ -21,6 +21,7 @@
 lib-$(CONFIG_FBSPLASH)    += fbsplash.o
 lib-$(CONFIG_FLASHCP)     += flashcp.o
 lib-$(CONFIG_FLASH_ERASEALL) += flash_eraseall.o
+lib-$(CONFIG_FLASH_ISLOCK)   += flash_lock_unlock.o
 lib-$(CONFIG_FLASH_LOCK)     += flash_lock_unlock.o
 lib-$(CONFIG_FLASH_UNLOCK)   += flash_lock_unlock.o
 lib-$(CONFIG_IONICE)      += ionice.o



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic