Hi,
I found some questions on the internet wondering whether chmod tool does
support binary numbers as input.
Even though it doesn't support I downloaded core-utils source and got
started reading chmode code.

Let's to the point: I added binary input support by making changes
into the*/lib/modechanges.c
* file.
PS: (b) prefix is not case sensitive.

*Tests:*
./chmod* b10111* t*    *
    stat t (0027/----*-w-rwx*)
./chmod b t *(Error)*
   ./chmod: invalid mode: `b'
./chmod *b111111* t
    stat t (0077/----*rwxrwx*)

Octal mode fulfills its goal very well, though Binary mode may be an
interesting feature.

Follows the changes:
--- modechange.c~    2012-11-24 00:03:36.000000000 -0200
+++ modechange.c    2012-11-23 23:54:45.000000000 -0200
@@ -137,6 +137,31 @@
   struct mode_change *mc;
   size_t used = 0;

+  if (*mode_string == 'b' || *mode_string == 'B')
+    {
+      unsigned int binary_mode = 0;
+      mode_t mode;
+      mode_t mentioned;
+
+      // Jumps the b character
+      mode_string++;
+      do
+        {
+          binary_mode = (binary_mode << 1) + *mode_string++ - '0';
+          if (ALLM < binary_mode)
+            return NULL;
+        }
+      while ('0' <= *mode_string && *mode_string <= '1');
+
+      if (*mode_string)
+      return NULL;
+
+      // Octal_to_mode function will fit the binary mode.
+      mode = octal_to_mode (binary_mode);
+      mentioned = (mode & (S_ISUID | S_ISGID)) | S_ISVTX | S_IRWXUGO;
+      return make_node_op_equals (mode, mentioned);
+    }
+
   if ('0' <= *mode_string && *mode_string < '8')
     {
       unsigned int octal_mode = 0;


I would like to receive any feedback on the matter.

Regards,*
Raphael S.Carvalho *
Blog: http://raphaelscarvalho.blogspot.com.br/
Github: https://github.com/raphaelsc

Reply via email to