udev_add.c revision 6a24dc747788b6049ef35607ff252e3965af2ce5
/*
*
* Userspace devfs
*
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
*
*
* 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.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <grp.h>
#include <pwd.h>
#include "libsysfs/sysfs/libsysfs.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_version.h"
#include "logging.h"
#include "namedev.h"
#include "udev_db.h"
#include "udev_selinux.h"
/*
* The number is stored in decimal values in the format: M:m
*/
{
goto error;
goto error;
return 0;
return -1;
}
int udev_make_node(struct udevice *udev, const char *file, int major, int minor, mode_t mode, uid_t uid, gid_t gid)
{
int retval = 0;
goto create;
/* preserve node with already correct numbers, to not change the inode number */
goto perms;
}
else
case 'b':
break;
case 'c':
case 'u':
break;
case 'p':
break;
default:
return -EINVAL;
}
if (retval != 0) {
dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
goto exit;
}
goto exit;
}
dbg("chown(%s, %u, %u) failed with error '%s'",
goto exit;
}
}
exit:
return retval;
}
{
char partitionname[NAME_SIZE];
int tail;
char *pos;
int len;
int i;
/* create parent directories if needed */
char *endptr;
if (endptr[0] == '\0')
else {
else
}
}
char *endptr;
if (endptr[0] == '\0')
else {
else
}
}
goto error;
} else {
info("creating device node '%s', major = '%d', minor = '%d', "
"mode = '%#o', uid = '%d', gid = '%d'", filename,
}
/* create all_partitions if requested */
if (udev->partitions > 0) {
struct sysfs_attribute *attr;
int range;
/* take the maximum registered minor range */
if (attr) {
if (range > 1)
}
strintcat(partitionname, i);
}
}
}
/* create symlink(s) if requested */
char linktarget[NAME_SIZE];
/* optimize relative link */
linktarget[0] = '\0';
i = 0;
tail = 0;
tail = i+1;
i++;
}
while (linkname[i] != '\0') {
if (linkname[i] == '/')
i++;
}
dbg("symlink(%s, %s) failed with error '%s'",
}
}
return 0;
return -1;
}
{
int sk;
int retval;
return 0;
if (sk < 0) {
dbg("error opening socket");
return -1;
}
if (retval != 0)
dbg("error changing net interface name");
return retval;
}
{
char *pos;
int retval = 0;
if (retval != 0) {
dbg("no dev-file found, do nothing");
return 0;
}
}
return 0;
selinux_init();
if (retval != 0)
goto exit;
if (udev_db_add_device(udev) != 0)
dbg("udev_db_add_dev failed, but we create the node anyway, "
"remove might not work for custom names");
/* use full path to the environment */
/* look if we want to change the name of the netif */
if (retval != 0)
goto exit;
/* we've changed the name, now fake the devpath, cause the
* original kernel name sleeps with the fishes and we don't
* get an event from the kernel with the new name
*/
}
/* use netif name for the environment */
}
}
exit:
return retval;
}