/*
- * udev_db.c
- *
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
*
*
* 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.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <string.h>
#include <errno.h>
#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include "udev.h"
-static int devpath_to_db_path(const char *devpath, char *filename, size_t len)
+static size_t devpath_to_db_path(const char *devpath, char *filename, size_t len)
{
- size_t start, end, i;
+ size_t start;
/* add location of db files */
strlcpy(filename, udev_root, len);
start = strlcat(filename, "/"DB_DIR, len);
- end = strlcat(filename, devpath, len);
- if (end > len)
- end = len;
-
- /* replace '/' to transform path into a filename */
- for (i = start+1; i < end; i++)
- if (filename[i] == '/')
- filename[i] = PATH_TO_NAME_CHAR;
-
- return 0;
+ strlcat(filename, devpath, len);
+ return path_encode(&filename[start+1], len - (start+1));
}
static int db_file_to_devpath(const char *filename, char *devpath, size_t len)
{
- size_t end, i;
-
strlcpy(devpath, "/", len);
- end = strlcat(devpath, filename, len);
-
- /* replace PATH_TO_NAME_CHAR to transform name into devpath */
- for (i = 1; i < end; i++)
- if (devpath[i] == PATH_TO_NAME_CHAR)
- devpath[i] = '/';
-
- return 0;
+ strlcat(devpath, filename, len);
+ return path_decode(devpath);
}
int udev_db_add_device(struct udevice *udev)
* create only a symlink with the name as the target
* if we don't have any interesting data to remember
*/
- if (strcmp(udev->name, udev->dev->kernel) == 0 &&
- list_empty(&udev->symlink_list) && list_empty(&udev->env_list) &&
+ if (list_empty(&udev->symlink_list) && list_empty(&udev->env_list) &&
!udev->partitions && !udev->ignore_remove) {
dbg("nothing interesting to store, create symlink");
unlink(filename);
struct name_entry *name_loop;
FILE *f;
+ unlink(filename);
f = fopen(filename, "w");
if (f == NULL) {
err("unable to create db file '%s': %s", filename, strerror(errno));
struct stat stats;
char filename[PATH_SIZE];
char line[PATH_SIZE];
- unsigned int major, minor;
+ unsigned int maj, min;
char *bufline;
char *buf;
size_t bufsize;
count = sizeof(line);
memcpy(line, &bufline[2], count-2);
line[count-2] = '\0';
- sscanf(line, "%u:%u", &major, &minor);
- udev->devt = makedev(major, minor);
+ sscanf(line, "%u:%u", &maj, &min);
+ udev->devt = makedev(maj, min);
break;
case 'S':
if (count > sizeof(line))
while (1) {
struct dirent *ent;
- char filename[PATH_SIZE] = "/";
- size_t end, i;
+ char device[PATH_SIZE];
ent = readdir(dir);
if (ent == NULL || ent->d_name[0] == '\0')
if (ent->d_name[0] == '.')
continue;
- end = strlcat(filename, ent->d_name, sizeof(filename));
- for (i = 1; i < end; i++)
- if (filename[i] == PATH_TO_NAME_CHAR)
- filename[i] = '/';
- name_list_add(name_list, filename, 1);
- dbg("added '%s'", filename);
+ db_file_to_devpath(ent->d_name, device, sizeof(device));
+ name_list_add(name_list, device, 1);
+ dbg("added '%s'", device);
}
closedir(dir);