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.