Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=02135cc56b2fc89dc760d42b34bcc6aed3b7c592

commit 02135cc56b2fc89dc760d42b34bcc6aed3b7c592
Author: James Buren <[email protected]>
Date:   Mon Aug 13 15:04:06 2012 -0500

implement writing DOS label back to original device

diff --git a/fwsetup.h b/fwsetup.h
index 45ffff3..694b9bc 100644
--- a/fwsetup.h
+++ b/fwsetup.h
@@ -13,7 +13,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/major.h>
-#include <stdint.h>
+#include <limits.h>
#include <blkid.h>

#define _(S) S
@@ -83,18 +83,18 @@ struct partition
{
struct partition *prev;
struct partition *next;
-  uint64_t num;
+  unsigned long long num;
char *name;
char *uuid;
-  uint64_t start;
-  uint64_t end;
-  uint64_t sectors;
+  unsigned long long start;
+  unsigned long long end;
+  unsigned long long sectors;
union
{
-    uint8_t type_n;
+    unsigned char type_n;
char *type_s;
};
-  uint64_t flags;
+  unsigned long long flags;
bool primary;
bool extended;
bool logical;
@@ -105,7 +105,7 @@ struct device
struct device *prev;
struct device *next;
char *path;
-  uint64_t sector_size;
+  unsigned long long sector_size;
enum devicetype type;
char *label;
struct partition *partitions;
@@ -119,6 +119,7 @@ extern void *list_find_end(void *list);
extern void list_free(void *list,void (*cb) (void *));
extern void string_free(void *string);
extern struct device *read_device_data(const char *path);
+extern bool write_device_data(const struct device *device);
extern void free_device(struct device *device);
extern int main(void);
extern struct module begin_module;
diff --git a/utility.c b/utility.c
index 3833c11..eff89d5 100644
--- a/utility.c
+++ b/utility.c
@@ -209,7 +209,7 @@ extern struct device *read_device_data(const char *path)
int fd = -1;
blkid_probe probe = 0;
blkid_topology topology = 0;
-  uint64_t sector_size = 0;
+  unsigned long long sector_size = 0;
struct stat st;
enum devicetype type = 0;
struct device *device = 0;
@@ -375,6 +375,46 @@ bail:
return device;
}

+extern bool write_device_data(const struct device *device)
+{
+  assert(device != 0);
+  assert(device->label != 0);
+
+  char cmd[LINE_MAX] = {0};
+  const struct partition *part = 0;
+  size_t len = 0;
+  int n = 0;
+
+  if(strcmp(device->label,"dos") == 0)
+  {
+    part = device->partitions;
+
+    n = snprintf(cmd+len,sizeof(cmd)-len,"echo -n -e '");
+
+    if(n > 0)
+      len += n;
+
+    while(part != 0)
+    {
+      n = snprintf(cmd+len,sizeof(cmd)-len,"%llu %llu 0x%hhx 
%c\\n",part->start,part->sectors,part->type_n,(part->flags == 0x80) ? '*' : 
'-');
+
+      if(n > 0)
+        len += n;
+
+      part = part->next;
+    }
+
+    n = snprintf(cmd+len,sizeof(cmd)-len,"' | sfdisk -u S -L %s",device->path);
+
+    if(n > 0)
+      len += n;
+
+    return true;
+  }
+
+  return true;
+}
+
extern void free_device(struct device *device)
{
if(device == 0)
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to