info-mtools
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Mtools] small feature -- specify offset with -i option


From: Luigi Rizzo
Subject: [Mtools] small feature -- specify offset with -i option
Date: Wed, 26 Nov 2008 10:11:30 +0100
User-agent: Mutt/1.4.2.3i

Hi,
attached is a patch to implement a small but i believe convenient
feature to specify a file offset as an additional parameter to
the -i flag which now can take the form

        filename@@offset

and you can add a trailing s,k,m,g character (case insensitive)
to specify the offset in sectors, kb, mb or gb.
Clearly the separator @@ can be changed to something else if
appropriate.

It is convenient e.g. when you need to manipulate image files or flash
keys where the FAT partition is not at the beginning.
I think right now you can only specify the offset by
creating an mtools.conf file, which is probably not so
convenient and the reason why the -i flag was introduced.

patch below -- it should be reasonably compatible with the new mtools 4.0.0,

        cheers
        luigi

--- ../../work.orig/mtools-3.9.10/config.c      2008-11-26 08:42:27.000000000 
+0100
+++ config.c    2008-11-26 09:55:09.000000000 +0100
@@ -521,6 +521,35 @@
   devices[cur_dev].heads = 0;
   devices[cur_dev].sectors = 0;
   devices[cur_dev].offset = 0;
+  do { /* check for embedded offset, in the form file@@offset[SKMG] */
+    char s, *ofsp, *endp = NULL;
+    off_t ofs;
+
+    ofsp = strstr(devices[cur_dev].name, "@@");
+    if (ofsp == NULL)
+        break; /* no separator */
+    ofs = strtol(ofsp+2, &endp, 0);
+    if (ofs <= 0)
+       break; /* invalid or missing offset */
+    s = *endp++;
+    if (s) {   /* trailing char, see if it is a size specifier */
+       endp++;
+       if (s == 's' || s == 'S')       /* sector */
+           ofs <<= 9;
+       else if (s == 'k' || s == 'K')  /* kb */
+           ofs <<= 10;
+       else if (s == 'm' || s == 'M')  /* Mb */
+           ofs <<= 20;
+       else if (s == 'g' || s == 'G')  /* Gb */
+           ofs <<= 30;
+       else
+           break;      /* invalid character */
+       if (*endp)
+           break;      /* extra char, invalid */
+    }
+    devices[cur_dev].offset = ofs;             /* set new offset */
+    *ofsp = '\0';                              /* truncate file name */
+  } while (0);
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]