[rtems commit] libblock: Add optional free at delete request

Sebastian Huber sebh at rtems.org
Tue Mar 13 06:31:32 CDT 2012


Module:    rtems
Branch:    master
Commit:    beea58072d893f7ab820a409f494954f10152a3d
Changeset: http://git.rtems.org/rtems/commit/?id=beea58072d893f7ab820a409f494954f10152a3d

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Mar  5 10:01:37 2012 +0100

libblock: Add optional free at delete request

---

 cpukit/libblock/include/rtems/ramdisk.h |   10 ++++++++++
 cpukit/libblock/src/ramdisk-driver.c    |    9 ++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/cpukit/libblock/include/rtems/ramdisk.h b/cpukit/libblock/include/rtems/ramdisk.h
index 71efc9f..a396bd6 100644
--- a/cpukit/libblock/include/rtems/ramdisk.h
+++ b/cpukit/libblock/include/rtems/ramdisk.h
@@ -136,6 +136,11 @@ typedef struct ramdisk {
    * @brief Trace enable.
    */
   bool trace;
+
+  /**
+   * @brief Free the RAM disk at the block device delete request.
+   */
+  bool free_at_delete_request;
 } ramdisk;
 
 extern const rtems_driver_address_table ramdisk_ops;
@@ -213,6 +218,11 @@ ramdisk *ramdisk_allocate(
 
 void ramdisk_free(ramdisk *rd);
 
+static inline void ramdisk_enable_free_at_delete_request(ramdisk *rd)
+{
+  rd->free_at_delete_request = true;
+}
+
 /**
  * @brief Allocates, initializes and registers a RAM disk.
  *
diff --git a/cpukit/libblock/src/ramdisk-driver.c b/cpukit/libblock/src/ramdisk-driver.c
index 2bc8d27..da36d79 100644
--- a/cpukit/libblock/src/ramdisk-driver.c
+++ b/cpukit/libblock/src/ramdisk-driver.c
@@ -102,12 +102,13 @@ ramdisk_write(struct ramdisk *rd, rtems_blkdev_request *req)
 int
 ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
 {
+    struct ramdisk *rd = rtems_disk_get_driver_data(dd);
+
     switch (req)
     {
         case RTEMS_BLKIO_REQUEST:
         {
             rtems_blkdev_request *r = argp;
-            struct ramdisk *rd = rtems_disk_get_driver_data(dd);
 
             switch (r->req)
             {
@@ -124,6 +125,12 @@ ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
             break;
         }
 
+        case RTEMS_BLKIO_DELETED:
+            if (rd->free_at_delete_request) {
+              ramdisk_free(rd);
+            }
+            break;
+
         default:
             return rtems_blkdev_ioctl (dd, req, argp);
             break;



More information about the rtems-vc mailing list