Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Angelo Compagnucci <angelo.compagnucci@gmail.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 1/2] package/makedevs: add recursive option
Date: Fri, 13 Mar 2015 11:50:04 +0100	[thread overview]
Message-ID: <1426243805-8317-2-git-send-email-angelo.compagnucci@gmail.com> (raw)
In-Reply-To: <1426243805-8317-1-git-send-email-angelo.compagnucci@gmail.com>

This patch adds the possibilty to change owner/permission
of a folder recursively.

Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
---
 package/makedevs/makedevs.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/package/makedevs/makedevs.c b/package/makedevs/makedevs.c
index ab90b93..e575427 100644
--- a/package/makedevs/makedevs.c
+++ b/package/makedevs/makedevs.c
@@ -34,6 +34,8 @@
 #ifndef __APPLE__
 #include <sys/sysmacros.h>     /* major() and minor() */
 #endif
+#include <ftw.h>
+
 
 const char *bb_applet_name;
 
@@ -332,6 +334,7 @@ void bb_show_usage(void)
 	fprintf(stderr, "Where name is the file name,  type can be one of:\n");
 	fprintf(stderr, "      f       A regular file\n");
 	fprintf(stderr, "      d       Directory\n");
+	fprintf(stderr, "      r       Directory recursively\n");
 	fprintf(stderr, "      c       Character special device file\n");
 	fprintf(stderr, "      b       Block special device file\n");
 	fprintf(stderr, "      p       Fifo (named pipe)\n");
@@ -364,6 +367,20 @@ void bb_show_usage(void)
 	exit(1);
 }
 
+bb_recursive(const char *full_name, uid_t uid, gid_t gid, unsigned int mode){
+
+	int chmod_chown(const char *fpath, const struct stat *sb,
+		int tflag, struct FTW *ftwbuf) {
+		if (chown(fpath, uid, gid) == -1) return -1;
+		if ((mode != -1)) {
+			if (chmod(fpath, mode) < 0) return -1;
+		}
+		return 0;
+	}
+
+	return nftw(full_name, chmod_chown, 20, FTW_MOUNT | FTW_PHYS);
+}
+
 int main(int argc, char **argv)
 {
 	int opt;
@@ -474,6 +491,12 @@ int main(int argc, char **argv)
 				ret = EXIT_FAILURE;
 				goto loop;
 			}
+		} else if (type == 'r') {
+			if (bb_recursive(full_name, uid, gid, mode) < 0) {
+				bb_perror_msg("line %d: recursive failed for %s", linenum, full_name);
+				ret = EXIT_FAILURE;
+				goto loop;
+			}
 		} else
 		{
 			dev_t rdev;
-- 
1.9.1

  reply	other threads:[~2015-03-13 10:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-13 10:50 [Buildroot] [PATCH 0/2] Makedevs: add recursive option Angelo Compagnucci
2015-03-13 10:50 ` Angelo Compagnucci [this message]
2015-04-04 23:17   ` [Buildroot] [PATCH 1/2] package/makedevs: " Angelo Compagnucci
2015-04-05  7:12     ` Peter Korsgaard
2015-04-09 21:23   ` Yann E. MORIN
2015-04-10  5:39     ` Angelo Compagnucci
2015-04-10 17:33       ` Yann E. MORIN
2015-04-10 21:41   ` Peter Korsgaard
2015-04-11  7:00     ` Angelo Compagnucci
2015-04-11  8:28       ` Peter Korsgaard
2015-03-13 10:50 ` [Buildroot] [PATCH 2/2] docs/manual: documentation for recursive makedevs syntax Angelo Compagnucci
2015-03-23 10:00 ` [Buildroot] [PATCH 0/2] Makedevs: add recursive option Angelo Compagnucci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426243805-8317-2-git-send-email-angelo.compagnucci@gmail.com \
    --to=angelo.compagnucci@gmail.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox