chiark / gitweb /
[PATCH] add dbg_parse() to cut down on parse file debugging statements
[elogind.git] / namedev.c
1 /*
2  * namedev.c
3  *
4  * Userspace devfs
5  *
6  * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
7  *
8  *
9  *      This program is free software; you can redistribute it and/or modify it
10  *      under the terms of the GNU General Public License as published by the
11  *      Free Software Foundation version 2 of the License.
12  * 
13  *      This program is distributed in the hope that it will be useful, but
14  *      WITHOUT ANY WARRANTY; without even the implied warranty of
15  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *      General Public License for more details.
17  * 
18  *      You should have received a copy of the GNU General Public License along
19  *      with this program; if not, write to the Free Software Foundation, Inc.,
20  *      675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */
23
24 /* define this to enable parsing debugging */
25 /* #define DEBUG_PARSER */
26
27 #include <stddef.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <fcntl.h>
32 #include <ctype.h>
33 #include <unistd.h>
34 #include <errno.h>
35 #include <sys/wait.h>
36
37 #include "list.h"
38 #include "udev.h"
39 #include "udev_version.h"
40 #include "namedev.h"
41 #include "libsysfs/libsysfs.h"
42
43 #define TYPE_LABEL      "LABEL"
44 #define TYPE_NUMBER     "NUMBER"
45 #define TYPE_TOPOLOGY   "TOPOLOGY"
46 #define TYPE_REPLACE    "REPLACE"
47 #define TYPE_CALLOUT    "CALLOUT"
48
49 static LIST_HEAD(config_device_list);
50
51 static void dump_dev(struct config_device *dev)
52 {
53         switch (dev->type) {
54         case KERNEL_NAME:
55                 dbg_parse("KERNEL name ='%s'"
56                         " owner = '%s', group = '%s', mode = '%#o'",
57                         dev->attr.name, 
58                         dev->attr.owner, dev->attr.group, dev->attr.mode);
59                 break;
60         case LABEL:
61                 dbg_parse("LABEL name = '%s', bus = '%s', sysfs_file = '%s', sysfs_value = '%s'"
62                         " owner = '%s', group = '%s', mode = '%#o'",
63                         dev->attr.name, dev->bus, dev->sysfs_file, dev->sysfs_value,
64                         dev->attr.owner, dev->attr.group, dev->attr.mode);
65                 break;
66         case NUMBER:
67                 dbg_parse("NUMBER name = '%s', bus = '%s', id = '%s'"
68                         " owner = '%s', group = '%s', mode = '%#o'",
69                         dev->attr.name, dev->bus, dev->id,
70                         dev->attr.owner, dev->attr.group, dev->attr.mode);
71                 break;
72         case TOPOLOGY:
73                 dbg_parse("TOPOLOGY name = '%s', bus = '%s', place = '%s'"
74                         " owner = '%s', group = '%s', mode = '%#o'",
75                         dev->attr.name, dev->bus, dev->place,
76                         dev->attr.owner, dev->attr.group, dev->attr.mode);
77                 break;
78         case REPLACE:
79                 dbg_parse("REPLACE name = %s, kernel_name = %s"
80                         " owner = '%s', group = '%s', mode = '%#o'",
81                         dev->attr.name, dev->kernel_name,
82                         dev->attr.owner, dev->attr.group, dev->attr.mode);
83                 break;
84         case CALLOUT:
85                 dbg_parse("CALLOUT name = '%s', program ='%s', bus = '%s', id = '%s'"
86                         " owner = '%s', group = '%s', mode = '%#o'",
87                         dev->attr.name, dev->exec_program, dev->bus, dev->id,
88                         dev->attr.owner, dev->attr.group, dev->attr.mode);
89                 break;
90         default:
91                 dbg_parse("Unknown type of device!");
92         }
93 }
94
95 #define copy_var(a, b, var)             \
96         if (b->var)                     \
97                 a->var = b->var;
98
99 #define copy_string(a, b, var)          \
100         if (strlen(b->var))             \
101                 strcpy(a->var, b->var);
102
103 static int add_dev(struct config_device *new_dev)
104 {
105         struct list_head *tmp;
106         struct config_device *tmp_dev;
107
108         /* loop through the whole list of devices to see if we already have
109          * this one... */
110         list_for_each(tmp, &config_device_list) {
111                 struct config_device *dev = list_entry(tmp, struct config_device, node);
112                 if (strcmp(dev->attr.name, new_dev->attr.name) == 0) {
113                         /* the same, copy the new info into this structure */
114                         copy_var(dev, new_dev, type);
115                         copy_var(dev, new_dev, attr.mode);
116                         copy_string(dev, new_dev, bus);
117                         copy_string(dev, new_dev, sysfs_file);
118                         copy_string(dev, new_dev, sysfs_value);
119                         copy_string(dev, new_dev, id);
120                         copy_string(dev, new_dev, place);
121                         copy_string(dev, new_dev, kernel_name);
122                         copy_string(dev, new_dev, attr.owner);
123                         copy_string(dev, new_dev, attr.group);
124                         return 0;
125                 }
126         }
127
128         /* not found, lets create a new structure, and add it to the list */
129         tmp_dev = malloc(sizeof(*tmp_dev));
130         if (!tmp_dev)
131                 return -ENOMEM;
132         memcpy(tmp_dev, new_dev, sizeof(*tmp_dev));
133         list_add(&tmp_dev->node, &config_device_list);
134         //dump_dev(tmp_dev);
135         return 0;
136 }
137
138 static void dump_dev_list(void)
139 {
140         struct list_head *tmp;
141
142         list_for_each(tmp, &config_device_list) {
143                 struct config_device *dev = list_entry(tmp, struct config_device, node);
144                 dump_dev(dev);
145         }
146 }
147
148 static int get_value(const char *left, char **orig_string, char **ret_string)
149 {
150         char *temp;
151         char *string = *orig_string;
152
153         /* eat any whitespace */
154         while (isspace(*string))
155                 ++string;
156
157         /* split based on '=' */
158         temp = strsep(&string, "=");
159         if (strcasecmp(temp, left) == 0) {
160                 /* got it, now strip off the '"' */
161                 while (isspace(*string))
162                         ++string;
163                 if (*string == '"')
164                         ++string;
165                 temp = strsep(&string, "\"");
166                 *ret_string = temp;
167                 *orig_string = string;
168                 return 0;
169         }
170         return -ENODEV;
171 }
172         
173 static int get_pair(char **orig_string, char **left, char **right)
174 {
175         char *temp;
176         char *string = *orig_string;
177
178         /* eat any whitespace */
179         while (isspace(*string))
180                 ++string;
181
182         /* split based on '=' */
183         temp = strsep(&string, "=");
184         *left = temp;
185
186         /* take the right side and strip off the '"' */
187         while (isspace(*string))
188                 ++string;
189         if (*string == '"')
190                 ++string;
191         temp = strsep(&string, "\"");
192         *right = temp;
193         *orig_string = string;
194         
195         return 0;
196 }
197
198 static int namedev_init_config(void)
199 {
200         char filename[255];
201         char line[255];
202         char *temp;
203         char *temp2;
204         char *temp3;
205         FILE *fd;
206         int retval = 0;
207         struct config_device dev;
208
209         strcpy(filename, UDEV_CONFIG_DIR NAMEDEV_CONFIG_FILE);
210         dbg("opening %s to read as permissions config", filename);
211         fd = fopen(filename, "r");
212         if (fd == NULL) {
213                 dbg("Can't open %s", filename);
214                 return -ENODEV;
215         }
216
217         /* loop through the whole file */
218         while (1) {
219                 /* get a line */
220                 temp = fgets(line, sizeof(line), fd);
221                 if (temp == NULL)
222                         break;
223
224                 dbg_parse("read %s", temp);
225
226                 /* eat the whitespace at the beginning of the line */
227                 while (isspace(*temp))
228                         ++temp;
229
230                 /* no more line? */
231                 if (*temp == 0x00)
232                         continue;
233
234                 /* see if this is a comment */
235                 if (*temp == COMMENT_CHARACTER)
236                         continue;
237
238                 memset(&dev, 0x00, sizeof(struct config_device));
239
240                 /* parse the line */
241                 temp2 = strsep(&temp, ",");
242                 if (strcasecmp(temp2, TYPE_LABEL) == 0) {
243                         /* label type */
244                         dev.type = LABEL;
245
246                         /* BUS="bus" */
247                         retval = get_value("BUS", &temp, &temp3);
248                         if (retval)
249                                 continue;
250                         strcpy(dev.bus, temp3);
251
252                         /* file="value" */
253                         temp2 = strsep(&temp, ",");
254                         retval = get_pair(&temp, &temp2, &temp3);
255                         if (retval)
256                                 continue;
257                         strcpy(dev.sysfs_file, temp2);
258                         strcpy(dev.sysfs_value, temp3);
259
260                         /* NAME="new_name" */
261                         temp2 = strsep(&temp, ",");
262                         retval = get_value("NAME", &temp, &temp3);
263                         if (retval)
264                                 continue;
265                         strcpy(dev.attr.name, temp3);
266
267                         dbg_parse("LABEL name = '%s', bus = '%s', "
268                                 "sysfs_file = '%s', sysfs_value = '%s'", 
269                                 dev.attr.name, dev.bus, dev.sysfs_file, 
270                                 dev.sysfs_value);
271                 }
272
273                 if (strcasecmp(temp2, TYPE_NUMBER) == 0) {
274                         /* number type */
275                         dev.type = NUMBER;
276
277                         /* BUS="bus" */
278                         retval = get_value("BUS", &temp, &temp3);
279                         if (retval)
280                                 continue;
281                         strcpy(dev.bus, temp3);
282
283                         /* ID="id" */
284                         temp2 = strsep(&temp, ",");
285                         retval = get_value("id", &temp, &temp3);
286                         if (retval)
287                                 continue;
288                         strcpy(dev.id, temp3);
289
290                         /* NAME="new_name" */
291                         temp2 = strsep(&temp, ",");
292                         retval = get_value("NAME", &temp, &temp3);
293                         if (retval)
294                                 continue;
295                         strcpy(dev.attr.name, temp3);
296
297                         dbg_parse("NUMBER name = '%s', bus = '%s', id = '%s'",
298                                         dev.attr.name, dev.bus, dev.id);
299                 }
300
301                 if (strcasecmp(temp2, TYPE_TOPOLOGY) == 0) {
302                         /* number type */
303                         dev.type = TOPOLOGY;
304
305                         /* BUS="bus" */
306                         retval = get_value("BUS", &temp, &temp3);
307                         if (retval)
308                                 continue;
309                         strcpy(dev.bus, temp3);
310
311                         /* PLACE="place" */
312                         temp2 = strsep(&temp, ",");
313                         retval = get_value("place", &temp, &temp3);
314                         if (retval)
315                                 continue;
316                         strcpy(dev.place, temp3);
317
318                         /* NAME="new_name" */
319                         temp2 = strsep(&temp, ",");
320                         retval = get_value("NAME", &temp, &temp3);
321                         if (retval)
322                                 continue;
323                         strcpy(dev.attr.name, temp3);
324
325                         dbg_parse("TOPOLOGY name = '%s', bus = '%s', place = '%s'",
326                                         dev.attr.name, dev.bus, dev.place);
327                 }
328
329                 if (strcasecmp(temp2, TYPE_REPLACE) == 0) {
330                         /* number type */
331                         dev.type = REPLACE;
332
333                         /* KERNEL="kernel_name" */
334                         retval = get_value("KERNEL", &temp, &temp3);
335                         if (retval)
336                                 continue;
337                         strcpy(dev.kernel_name, temp3);
338
339                         /* NAME="new_name" */
340                         temp2 = strsep(&temp, ",");
341                         retval = get_value("NAME", &temp, &temp3);
342                         if (retval)
343                                 continue;
344                         strcpy(dev.attr.name, temp3);
345                         dbg_parse("REPLACE name = %s, kernel_name = %s",
346                                         dev.attr.name, dev.kernel_name);
347                 }
348                 if (strcasecmp(temp2, TYPE_CALLOUT) == 0) {
349                         /* number type */
350                         dev.type = CALLOUT;
351
352                         /* PROGRAM="executable" */
353                         retval = get_value("PROGRAM", &temp, &temp3);
354                         if (retval)
355                                 continue;
356                         strcpy(dev.exec_program, temp3);
357
358                         /* BUS="bus" */
359                         temp2 = strsep(&temp, ",");
360                         retval = get_value("BUS", &temp, &temp3);
361                         if (retval)
362                                 continue;
363                         strcpy(dev.bus, temp3);
364
365                         /* ID="id" */
366                         temp2 = strsep(&temp, ",");
367                         retval = get_value("ID", &temp, &temp3);
368                         if (retval)
369                                 continue;
370                         strcpy(dev.id, temp3);
371
372                         /* NAME="new_name" */
373                         temp2 = strsep(&temp, ",");
374                         retval = get_value("NAME", &temp, &temp3);
375                         if (retval)
376                                 continue;
377                         strcpy(dev.attr.name, temp3);
378                         dbg_parse("CALLOUT name = %s, program = %s",
379                                         dev.attr.name, dev.exec_program);
380                 }
381
382                 retval = add_dev(&dev);
383                 if (retval) {
384                         dbg("add_dev returned with error %d", retval);
385                         goto exit;
386                 }
387         }
388
389 exit:
390         fclose(fd);
391         return retval;
392 }       
393
394
395 static int namedev_init_permissions(void)
396 {
397         char filename[255];
398         char line[255];
399         char *temp;
400         char *temp2;
401         FILE *fd;
402         int retval = 0;
403         struct config_device dev;
404
405         strcpy(filename, UDEV_CONFIG_DIR NAMEDEV_CONFIG_PERMISSION_FILE);
406         dbg("opening %s to read as permissions config", filename);
407         fd = fopen(filename, "r");
408         if (fd == NULL) {
409                 dbg("Can't open %s", filename);
410                 return -ENODEV;
411         }
412
413         /* loop through the whole file */
414         while (1) {
415                 /* get a line */
416                 temp = fgets(line, sizeof(line), fd);
417                 if (temp == NULL)
418                         break;
419
420                 dbg_parse("read %s", temp);
421
422                 /* eat the whitespace at the beginning of the line */
423                 while (isspace(*temp))
424                         ++temp;
425
426                 /* no more line? */
427                 if (*temp == 0x00)
428                         continue;
429
430                 /* see if this is a comment */
431                 if (*temp == COMMENT_CHARACTER)
432                         continue;
433
434                 memset(&dev, 0x00, sizeof(dev));
435
436                 /* parse the line */
437                 temp2 = strsep(&temp, ":");
438                 strncpy(dev.attr.name, temp2, sizeof(dev.attr.name));
439
440                 temp2 = strsep(&temp, ":");
441                 strncpy(dev.attr.owner, temp2, sizeof(dev.attr.owner));
442
443                 temp2 = strsep(&temp, ":");
444                 strncpy(dev.attr.group, temp2, sizeof(dev.attr.owner));
445
446                 dev.attr.mode = strtol(temp, NULL, 8);
447
448                 dbg_parse("name = %s, owner = %s, group = %s, mode = %#o",
449                                 dev.attr.name, dev.attr.owner, dev.attr.group, dev.attr.mode);
450                 retval = add_dev(&dev);
451                 if (retval) {
452                         dbg("add_dev returned with error %d", retval);
453                         goto exit;
454                 }
455         }
456
457 exit:
458         fclose(fd);
459         return retval;
460 }       
461
462 static int get_default_mode(struct sysfs_class_device *class_dev)
463 {
464         /* just default everyone to rw for the world! */
465         return 0666;
466 }
467
468
469 static int exec_callout(struct config_device *dev, char *value, int len)
470 {
471         int retval;
472         int res;
473         int status;
474         int fds[2];
475         pid_t pid;
476         int value_set = 0;
477         char buffer[256];
478
479         dbg("callout to %s\n", dev->exec_program);
480         retval = pipe(fds);
481         if (retval != 0) {
482                 dbg("pipe failed");
483                 return -1;
484         }
485         pid = fork();
486         if (pid == -1) {
487                 dbg("fork failed");
488                 return -1;
489         }
490
491         if (pid == 0) {
492                 /*
493                  * child 
494                  */
495                 close(STDOUT_FILENO);
496                 dup(fds[1]);    /* dup write side of pipe to STDOUT */
497                 retval = execve(dev->exec_program, main_argv, main_envp);
498                 if (retval != 0) {
499                         dbg("child execve failed");
500                         exit(1);
501                 }
502                 return -1; /* avoid compiler warning */
503         } else {
504                 /*
505                  * Parent reads from fds[0].
506                  */
507                 close(fds[1]);
508                 retval = 0;
509                 while (1) {
510                         res = read(fds[0], buffer, sizeof(buffer) - 1);
511                         if (res <= 0)
512                                 break;
513                         buffer[res] = '\0';
514                         if (res > len) {
515                                 dbg("callout len %d too short\n", len);
516                                 retval = -1;
517                         }
518                         if (value_set) {
519                                 dbg("callout value already set");
520                                 retval = -1;
521                         } else {
522                                 value_set = 1;
523                                 strncpy(value, buffer, len);
524                         }
525                 }
526                 close(fds[0]);
527                 res = wait(&status);
528                 if (res < 0) {
529                         dbg("wait failed result %d", res);
530                         retval = -1;
531                 }
532
533                 if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
534                         dbg("callout program status 0x%x", status);
535                         retval = -1;
536                 }
537         }
538         return retval;
539 }
540
541 static int get_attr(struct sysfs_class_device *class_dev, struct device_attr *attr)
542 {
543         struct list_head *tmp;
544         int retval = 0;
545         int found;
546
547         attr->mode = -1;
548         if (class_dev->sysdevice) {
549                 dbg_parse("class_dev->sysdevice->directory->path = '%s'", class_dev->sysdevice->directory->path);
550                 dbg_parse("class_dev->sysdevice->bus_id = '%s'", class_dev->sysdevice->bus_id);
551         } else {
552                 dbg_parse("class_dev->name = '%s'", class_dev->name);
553         }
554         list_for_each(tmp, &config_device_list) {
555                 struct config_device *dev = list_entry(tmp, struct config_device, node);
556                 switch (dev->type) {
557                 case LABEL:
558                         {
559                         char *temp;
560
561                         dbg_parse("LABEL: match file '%s' with value '%s'",
562                                         dev->sysfs_file, dev->sysfs_value);
563                         /* try to find the attribute in the class device directory */
564                         temp = sysfs_get_value_from_attributes(class_dev->directory->attributes, dev->sysfs_file);
565                         if (temp)
566                                 goto label_found;
567
568                         /* look in the class device device directory if present */
569                         if (class_dev->sysdevice) {
570                                 temp = sysfs_get_value_from_attributes(class_dev->sysdevice->directory->attributes, dev->sysfs_file);
571                                 if (temp)
572                                         goto label_found;
573                         }
574
575                         /* bah, let's go backwards up a level to see if the device is there,
576                          * as block partitions don't point to the physical device.  Need to fix that
577                          * up in the kernel...
578                          */
579                         if (strstr(class_dev->directory->path, "block")) {
580                                 dbg_parse("looking at block device...");
581                                 if (isdigit(class_dev->directory->path[strlen(class_dev->directory->path)-1])) {
582                                         char path[SYSFS_PATH_MAX];
583                                         struct sysfs_class_device *class_dev_parent;
584
585                                         dbg_parse("really is a partition...");
586                                         strcpy(path, class_dev->directory->path);
587                                         temp = strrchr(path, '/');
588                                         *temp = 0x00;
589                                         dbg_parse("looking for a class device at '%s'", path);
590                                         class_dev_parent = sysfs_open_class_device(path);
591                                         if (class_dev_parent == NULL) {
592                                                 dbg("sysfs_open_class_device at '%s' failed", path);
593                                                 continue;
594                                         }
595                                         dbg_parse("class_dev_parent->name = %s", class_dev_parent->name);
596
597                                         /* try to find the attribute in the class device directory */
598                                         temp = sysfs_get_value_from_attributes(class_dev_parent->directory->attributes, dev->sysfs_file);
599                                         if (temp) {
600                                                 //sysfs_close_class_device(class_dev_parent);
601                                                 goto label_found;
602                                         }
603
604                                         /* look in the class device device directory if present */
605                                         if (class_dev_parent->sysdevice) {
606                                                 temp = sysfs_get_value_from_attributes(class_dev_parent->sysdevice->directory->attributes, dev->sysfs_file);
607                                                 if (temp) {
608                                                         // sysfs_close_class_device(class_dev_parent);
609                                                         goto label_found;
610                                                 }
611                                         }
612                                         
613                                 }
614                         }
615                         continue;
616
617 label_found:
618                         temp[strlen(temp)-1] = 0x00;
619                         dbg_parse("file '%s' found with value '%s' compare with '%s'", dev->sysfs_file, temp, dev->sysfs_value);
620                         if (strcmp(dev->sysfs_value, temp) != 0)
621                                 continue;
622
623                         strcpy(attr->name, dev->attr.name);
624                         if (isdigit(class_dev->directory->path[strlen(class_dev->directory->path)-1])) {
625                                 temp[0] = class_dev->directory->path[strlen(class_dev->directory->path)-1];
626                                 temp[1] = 0x00;
627                                 strcat(attr->name, temp);
628                         }
629                         if (dev->attr.mode != 0) {
630                                 attr->mode = dev->attr.mode;
631                                 strcpy(attr->owner, dev->attr.owner);
632                                 strcpy(attr->group, dev->attr.group);
633                         }
634                         dbg_parse("file '%s' with value '%s' becomes '%s' - owner = %s, group = %s, mode = %#o",
635                                 dev->sysfs_file, dev->sysfs_value, attr->name, 
636                                 dev->attr.owner, dev->attr.group, dev->attr.mode);
637                         goto done;
638                         break;
639                         }
640                 case NUMBER:
641                         {
642                         char path[SYSFS_PATH_MAX];
643                         char *temp;
644
645                         found = 0;
646                         if (!class_dev->sysdevice)
647                                 continue;
648                         strcpy(path, class_dev->sysdevice->directory->path);
649                         temp = strrchr(path, '/');
650                         dbg_parse("NUMBER path = '%s'", path);
651                         dbg_parse("NUMBER temp = '%s' id = '%s'", temp, dev->id);
652                         if (strstr(temp, dev->id) != NULL) {
653                                 found = 1;
654                         } else {
655                                 *temp = 0x00;
656                                 temp = strrchr(path, '/');
657                                 dbg_parse("NUMBERY temp = '%s' id = '%s'", temp, dev->id);
658                                 if (strstr(temp, dev->id) != NULL)
659                                         found = 1;
660                         }
661                         if (!found)
662                                 continue;
663
664                         strcpy(attr->name, dev->attr.name);
665                         if (dev->attr.mode != 0) {
666                                 attr->mode = dev->attr.mode;
667                                 strcpy(attr->owner, dev->attr.owner);
668                                 strcpy(attr->group, dev->attr.group);
669                         }
670                         dbg_parse("device id '%s' becomes '%s' - owner = %s, group = %s, mode = %#o",
671                                 dev->id, attr->name, 
672                                 dev->attr.owner, dev->attr.group, dev->attr.mode);
673                         goto done;
674                         break;
675                         }
676                 case TOPOLOGY:
677                         {
678                         char path[SYSFS_PATH_MAX];
679                         char *temp;
680
681                         if (!class_dev->sysdevice)
682                                 continue;
683                         found = 0;      
684                         strcpy(path, class_dev->sysdevice->directory->path);
685                         temp = strrchr(path, '/');
686                         dbg_parse("TOPOLOGY path = '%s'", path);
687                         dbg_parse("TOPOLOGY temp = '%s' place = '%s'", temp, dev->place);
688                         if (strstr(temp, dev->place) != NULL) {
689                                 found = 1;
690                         } else {
691                                 *temp = 0x00;
692                                 temp = strrchr(path, '/');
693                                 dbg_parse("TOPOLOGY temp = '%s' place = '%s'", temp, dev->place);
694                                 if (strstr(temp, dev->place) != NULL)
695                                         found = 1;
696                         }
697                         if (!found)
698                                 continue;
699
700                         strcpy(attr->name, dev->attr.name);
701                         if (dev->attr.mode != 0) {
702                                 attr->mode = dev->attr.mode;
703                                 strcpy(attr->owner, dev->attr.owner);
704                                 strcpy(attr->group, dev->attr.group);
705                         }
706                         dbg_parse("device at '%s' becomes '%s' - owner = %s, group = %s, mode = %#o",
707                                 dev->place, attr->name, 
708                                 dev->attr.owner, dev->attr.group, dev->attr.mode);
709                         goto done;
710                         break;
711                         }
712                 case CALLOUT:
713                         {
714                         char value[ID_SIZE];
715
716                         if (exec_callout(dev, value, sizeof(value)))
717                                 continue;
718                         if (strncmp(value, dev->id, sizeof(value)) != 0)
719                                 continue;
720                         strcpy(attr->name, dev->attr.name);
721                         if (dev->attr.mode != 0) {
722                                 attr->mode = dev->attr.mode;
723                                 strcpy(attr->owner, dev->attr.owner);
724                                 strcpy(attr->group, dev->attr.group);
725                         }
726                         dbg_parse("device callout '%s' becomes '%s' - owner = %s, group = %s, mode = %#o",
727                                 dev->id, attr->name, 
728                                 dev->attr.owner, dev->attr.group, dev->attr.mode);
729                         goto done;
730                         break;
731                         }
732                 case REPLACE:
733                         if (strcmp(dev->kernel_name, class_dev->name) != 0)
734                                 continue;
735                         strcpy(attr->name, dev->attr.name);
736                         if (dev->attr.mode != 0) {
737                                 attr->mode = dev->attr.mode;
738                                 strcpy(attr->owner, dev->attr.owner);
739                                 strcpy(attr->group, dev->attr.group);
740                         }
741                         dbg_parse("'%s' becomes '%s' - owner = %s, group = %s, mode = %#o",
742                                 dev->kernel_name, attr->name, 
743                                 dev->attr.owner, dev->attr.group, dev->attr.mode);
744                         goto done;
745                         break;
746                 case KERNEL_NAME:
747                         break;
748                 default:
749                         dbg_parse("Unknown type of device '%d'", dev->type);
750                         break;
751                 }       
752         }
753         strcpy(attr->name, class_dev->name);
754         
755 done:
756         if (attr->mode == -1) { 
757                 attr->mode = get_default_mode(class_dev);
758                 attr->owner[0] = 0x00;
759                 attr->group[0] = 0x00;
760         }
761         return retval;
762 }
763
764 int namedev_name_device(struct sysfs_class_device *class_dev, struct device_attr *attr)
765 {
766         int retval;
767
768         retval = get_attr(class_dev, attr);
769         if (retval)
770                 dbg("get_attr failed");
771
772         return retval;
773 }
774
775 int namedev_init(void)
776 {
777         int retval;
778         
779         retval = namedev_init_config();
780         if (retval)
781                 return retval;
782
783         retval = namedev_init_permissions();
784         if (retval)
785                 return retval;
786
787         dump_dev_list();
788         return retval;
789 }
790
791