edd_id.c revision ad29a9f14fa8b1932c0e418bfcf1c10ce6a35a33
/*
* edd_id - naming of BIOS disk devices via EDD
*
* Copyright (C) 2005 John Hull <John_Hull@Dell.com>
* Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <stdint.h>
#include "libudev.h"
#include "libudev-private.h"
{
}
{
int i;
int export = 0;
int disk_fd;
int sysfs_fd;
int rc = 1;
char filename[UTIL_PATH_SIZE];
char match[UTIL_PATH_SIZE];
goto exit;
udev_log_init("edd_id");
for (i = 1 ; i < argc; i++) {
export = 1;
} else
}
goto exit;
}
/* check for kernel support */
rc = 2;
goto exit;
}
if (disk_fd < 0) {
rc = 3;
goto closedir;
}
/* check for valid MBR signature */
rc = 4;
goto close;
}
rc = 5;
goto close;
}
if (mbr_valid != 0xAA55) {
rc=6;
goto close;
}
/* read EDD signature */
rc = 7;
goto close;
}
rc = 8;
goto close;
}
/* all zero is invalid */
if (disk_id == 0) {
rc = 9;
goto close;
}
/* lookup signature in sysfs to determine the name */
match[0] = '\0';
char sysfs_id_buf[256];
continue;
if (sysfs_fd < 0) {
continue;
}
if (size <= 0) {
continue;
}
/* look for matching value, that appears only once */
if (match[0] == '\0') {
/* store id */
} else {
/* error, same signature for another device */
rc = 10;
goto exit;
}
}
}
if (match[0] != '\0') {
if (export)
else
rc = 0;
}
exit:
return rc;
}