[PATCH rtems 12/14] Add IOCTL to get the active partition idx

berndmoessner80 at gmail.com berndmoessner80 at gmail.com
Tue Jan 2 20:45:33 UTC 2024


From: Bernd Moessner <berndmoessner80 at gmail.com>

---
 cpukit/dev/flash/flashdev.c         | 24 ++++++++++++++++++++++++
 cpukit/include/dev/flash/flashdev.h |  9 +++++++++
 2 files changed, 33 insertions(+)

diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c
index b06e7d0c2f..ee01b8b447 100644
--- a/cpukit/dev/flash/flashdev.c
+++ b/cpukit/dev/flash/flashdev.c
@@ -98,6 +98,12 @@ static int rtems_flashdev_ioctl_deactivate_partition(
   void *arg
 );
 
+static int rtems_flashdev_ioctl_get_active_partition(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop,
+  void *arg
+);
+
 static uint32_t rtems_flashdev_ioctl_get_flash_type(
   rtems_flashdev *flash,
   void *arg
@@ -603,6 +609,9 @@ static int rtems_flashdev_ioctl(
     case RTEMS_FLASHDEV_IOCTL_DEACTIVATE_PARTITION:
       err = rtems_flashdev_ioctl_deactivate_partition( flash, iop, arg );
       break;
+    case RTEMS_FLASHDEV_IOCTL_GET_ACTIVATE_PARTITION_IDX:
+      err = rtems_flashdev_ioctl_get_active_partition( flash, iop, arg );
+      break;
     case RTEMS_FLASHDEV_IOCTL_GET_TYPE:
       err = rtems_flashdev_ioctl_get_flash_type( flash, arg );
       break;
@@ -1062,6 +1071,21 @@ static int rtems_flashdev_ioctl_deactivate_partition(
   return rtems_flashdev_deactivate_partition(iop, *partition_idx);
 }
 
+static int rtems_flashdev_ioctl_get_active_partition(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop,
+  void *arg
+)
+{
+  int32_t * partition_idx = (int32_t *) arg;
+  *partition_idx = -1;
+  if (rtems_flashdev_is_a_partition_active( iop ))
+  {
+    *partition_idx = rtems_flashdev_get_active_partition_index( iop );
+  }
+
+}
+
 static uint32_t rtems_flashdev_ioctl_get_flash_type(
   rtems_flashdev *flash,
   void *arg
diff --git a/cpukit/include/dev/flash/flashdev.h b/cpukit/include/dev/flash/flashdev.h
index fcb3bbf865..d1ffd30583 100644
--- a/cpukit/include/dev/flash/flashdev.h
+++ b/cpukit/include/dev/flash/flashdev.h
@@ -136,6 +136,15 @@ typedef enum {
    */
   RTEMS_FLASHDEV_IOCTL_DEACTIVATE_PARTITION,
 
+  /**
+   * @brief Get active partition idx
+   *
+   * @param[out] partition_idx Integer containing the partition index
+   * or -1 if no partition is active
+   *
+   */
+  RTEMS_FLASHDEV_IOCTL_GET_ACTIVATE_PARTITION_IDX,
+
   /**
    * @brief Returns the type of flash device (e.g. NOR or NAND).
    *
-- 
2.34.1



More information about the devel mailing list