tag: Add blank tag format support
authorEyal Reizer <eyalr@ti.com>
Wed, 27 Jun 2012 08:11:39 +0000 (11:11 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 27 Jun 2012 09:52:49 +0000 (11:52 +0200)
* Add a new near_tag_driver op (format) used for formatting blank tags.
* In case an un-formatted tag is being written __near_tag_write()
  first format the tag and if that succeeds it proceeds to writing
  the data.

include/tag.h
src/tag.c

index e2ebb73..2b39440 100644 (file)
@@ -70,6 +70,8 @@ struct near_tag_driver {
                                        near_tag_io_cb cb);
        int (*check_presence)(uint32_t adapter_idx, uint32_t target_idx,
                                                near_tag_io_cb cb);
+       int (*format)(uint32_t adapter_idx, uint32_t target_idx,
+                                       near_tag_io_cb cb);
 };
 
 struct near_tag;
index 1059784..f980764 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -870,6 +870,7 @@ int __near_tag_write(struct near_tag *tag,
                                near_tag_io_cb cb)
 {
        GSList *list;
+       int err;
 
        DBG("type 0x%x", tag->type);
 
@@ -878,9 +879,20 @@ int __near_tag_write(struct near_tag *tag,
 
                DBG("driver type 0x%x", driver->type);
 
-               if (driver->type == tag->type)
+               if (driver->type == tag->type) {
+                       if (tag->blank == TRUE && driver->format != NULL) {
+                               DBG("Blank tag detected, formatting");
+                               err = driver->format(tag->adapter_idx,
+                                               tag->target_idx, NULL);
+
+                               if (err < 0)
+                                       return err;
+
+                       }
+
                        return driver->write(tag->adapter_idx, tag->target_idx,
                                                                ndef, cb);
+               }
        }
 
        return 0;