Home | History | Annotate | Download | only in fs_get_stats
      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <string.h>
      4 #include <unistd.h>
      5 
      6 #include <private/android_filesystem_config.h>
      7 
      8 #define DO_DEBUG 1
      9 
     10 #define ERROR(fmt,args...) \
     11 	do { \
     12 		fprintf(stderr, "%s:%d: ERROR: " fmt,  \
     13 		        __FILE__, __LINE__, ##args);    \
     14 	} while (0)
     15 
     16 #if DO_DEBUG
     17 #define DEBUG(fmt,args...) \
     18 	do { fprintf(stderr, "DEBUG: " fmt, ##args); } while(0)
     19 #else
     20 #define DEBUG(x...)               do {} while(0)
     21 #endif
     22 
     23 void
     24 print_help(void)
     25 {
     26 	fprintf(stderr, "fs_get_stats: retrieve the target file stats "
     27 	        "for the specified file\n");
     28 	fprintf(stderr, "usage: fs_get_stats cur_perms is_dir filename targetout\n");
     29 	fprintf(stderr, "\tcur_perms - The current permissions of "
     30 	        "the file\n");
     31 	fprintf(stderr, "\tis_dir    - Is filename is a dir, 1. Otherwise, 0.\n");
     32 	fprintf(stderr, "\tfilename  - The filename to lookup\n");
     33 	fprintf(stderr, "\ttargetout - The target out path to query device specific FS configs\n");
     34 	fprintf(stderr, "\n");
     35 }
     36 
     37 int
     38 main(int argc, const char *argv[])
     39 {
     40 	char *endptr;
     41 	char is_dir = 0;
     42 	unsigned perms = 0;
     43 	unsigned uid = (unsigned)-1;
     44 	unsigned gid = (unsigned)-1;
     45 
     46 	if (argc < 5) {
     47 		ERROR("Invalid arguments\n");
     48 		print_help();
     49 		exit(-1);
     50 	}
     51 
     52 	perms = (unsigned)strtoul(argv[1], &endptr, 0);
     53 	if (!endptr || (endptr == argv[1]) || (*endptr != '\0')) {
     54 		ERROR("current permissions must be a number. Got '%s'.\n", argv[1]);
     55 		exit(-1);
     56 	}
     57 
     58 	if (!strcmp(argv[2], "1"))
     59 		is_dir = 1;
     60 
     61 	uint64_t capabilities;
     62 	fs_config(argv[3], is_dir, argv[4], &uid, &gid, &perms, &capabilities);
     63 	fprintf(stdout, "%d %d 0%o\n", uid, gid, perms);
     64 
     65 	return 0;
     66 }
     67