udev_node.c revision 44aff4cd6d74d230e4a97f8d59f780472b7cad6e
/*
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <grp.h>
#include <dirent.h>
#include "udev.h"
#include "udev_rules.h"
#include "udev_selinux.h"
#define TMP_FILE_EXT ".udev-tmp"
int udev_node_mknod(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid)
{
int preserve = 0;
int err = 0;
else
preserve = 1;
} else {
if (err != 0) {
err("mknod(%s, %#o, %u, %u) failed: %s\n",
goto exit;
}
if (err != 0) {
err("rename(%s, %s) failed: %s\n",
}
}
} else {
if (err != 0) {
err("mknod(%s, %#o, (%u,%u) failed: %s\n",
goto exit;
}
}
if (err != 0) {
goto exit;
}
}
if (err != 0) {
goto exit;
}
}
exit:
return err;
}
{
int i = 0;
int tail = 0;
int len;
int retval = 0;
/* use relative link */
if (node[i] == '/')
tail = i+1;
i++;
}
while (slink[i] != '\0') {
if (slink[i] == '/')
i++;
}
/* preserve link with correct target, do not replace node of other device */
} else {
goto exit;
}
}
if (len > 0) {
goto exit;
}
}
}
} else {
if (retval == 0)
goto exit;
}
if (retval != 0) {
goto exit;
}
if (retval != 0) {
goto exit;
}
exit:
return retval;
}
{
struct name_entry *device;
int count;
int priority = 0;
int rc = 0;
/* if we don't have a reference, delete it */
if (count <= 0) {
}
goto out;
}
/* find the device with the highest priority */
/* did we find ourself? we win, if we have the same priority */
info("compare (our own) priority of '%s' %i >= %i\n",
}
continue;
}
/* another device, read priority from database */
udev_db = udev_device_init();
continue;
} else {
info("compare priority of '%s' %i > %i\n",
}
}
}
}
if (target[0] == '\0') {
rc = 1;
goto out;
}
/* create symlink to the target with the highest priority */
}
out:
return rc;
}
{
struct name_entry *name_loop;
}
/* export symlinks to environment */
if (symlinks[0] != '\0')
/* update possible left-over symlinks (device metadata changed) */
struct name_entry *link_loop;
struct name_entry *link_old_loop;
int found;
/* remove current symlinks from old list */
found = 0;
found = 1;
break;
}
}
if (!found) {
/* link does no longer belong to this device */
info("update old symlink '%s' no longer belonging to '%s'\n",
}
}
/*
* if the node name has changed, delete the node,
* or possibly restore a symlink of another device
*/
}
}
{
int i;
int retval = 0;
uid = 0;
else {
char *endptr;
unsigned long id;
if (endptr[0] == '\0')
else
}
gid = 0;
else {
char *endptr;
unsigned long id;
if (endptr[0] == '\0')
else
}
info("creating device node '%s', major=%d, minor=%d, mode=%#o, uid=%d, gid=%d\n",
retval = -1;
goto exit;
}
/* create all_partitions if requested */
if (udev->partitions) {
char partitionname[PATH_SIZE];
char *attr;
int range;
/* take the maximum registered minor range */
if (range > 1)
}
}
}
}
exit:
return retval;
}
{
char partitionname[PATH_SIZE];
int retval = 0;
int num;
return 0;
}
return -1;
}
if (retval)
return retval;
if (num > 0) {
int i;
if (num > 255)
return -1;
for (i = 1; i <= num; i++) {
}
}
return retval;
}