• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <stdio.h>
18 #include <sys/stat.h>
19 #include <errno.h>
20 #include <unistd.h>
21 #include <string.h>
22 
23 #include "private/android_filesystem_config.h"
24 
25 // This program takes a list of files and directories (indicated by a
26 // trailing slash) on the stdin, and prints to stdout each input
27 // filename along with its desired uid, gid, and mode (in octal).
28 // The leading slash should be stripped from the input.
29 //
30 // Example input:
31 //
32 //    system/etc/dbus.conf
33 //    data/app/
34 //
35 // Output:
36 //
37 //    system/etc/dbus.conf 1002 1002 440
38 //    data/app 1000 1000 771
39 //
40 // Note that the output will omit the trailing slash from
41 // directories.
42 
main(int argc,char ** argv)43 int main(int argc, char** argv) {
44   char buffer[1024];
45 
46   while (fgets(buffer, 1023, stdin) != NULL) {
47     int is_dir = 0;
48     int i;
49     for (i = 0; i < 1024 && buffer[i]; ++i) {
50       switch (buffer[i]) {
51         case '\n':
52           buffer[i-is_dir] = '\0';
53           i = 1025;
54           break;
55         case '/':
56           is_dir = 1;
57           break;
58         default:
59           is_dir = 0;
60           break;
61       }
62     }
63 
64     unsigned uid = 0, gid = 0, mode = 0;
65     fs_config(buffer, is_dir, &uid, &gid, &mode);
66     printf("%s %d %d %o\n", buffer, uid, gid, mode);
67   }
68   return 0;
69 }
70