|
|
@ -23,14 +23,18 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
#include <string.h> |
|
|
|
#include <string.h> |
|
|
|
#include <sys/types.h> |
|
|
|
#include <sys/types.h> |
|
|
|
#include <sys/stat.h> |
|
|
|
#include <sys/stat.h> |
|
|
|
#include <sys/sysmacros.h> |
|
|
|
#include <sys/sysmacros.h> |
|
|
|
#include <unistd.h> |
|
|
|
#include <unistd.h> |
|
|
|
|
|
|
|
#include <limits.h> |
|
|
|
#include "disk.h" |
|
|
|
#include "disk.h" |
|
|
|
#include "util.h" |
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SYS_DEV_BLOCK_PATH "/sys/dev/block/" |
|
|
|
|
|
|
|
|
|
|
|
struct disk_list * |
|
|
|
struct disk_list * |
|
|
|
disk_get_by_name (struct disk_list *head, const char *s) |
|
|
|
disk_get_by_name (struct disk_list *head, const char *s) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -73,15 +77,27 @@ disk_list_free (struct disk_list **head) |
|
|
|
int path_is_disk(const char *path) |
|
|
|
int path_is_disk(const char *path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct stat stbuf = {0}; |
|
|
|
struct stat stbuf = {0}; |
|
|
|
|
|
|
|
char buf[PATH_MAX] = {0}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("%s\n", path); |
|
|
|
if (stat(path, &stbuf) < 0 || !S_ISBLK(stbuf.st_mode)) |
|
|
|
if (stat(path, &stbuf) < 0 || !S_ISBLK(stbuf.st_mode)) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
if (minor(stbuf.st_rdev)) |
|
|
|
|
|
|
|
|
|
|
|
if (snprintf(buf, PATH_MAX, SYS_DEV_BLOCK_PATH "%d:%d", |
|
|
|
|
|
|
|
major(stbuf.st_rdev), minor(stbuf.st_rdev)) >= PATH_MAX) |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
// FIXME: possible race condition here
|
|
|
|
|
|
|
|
snprintf(buf, PATH_MAX, "%s", get_path(buf)); |
|
|
|
|
|
|
|
strcat(buf, "/partition"); |
|
|
|
|
|
|
|
if (file_exists(buf) > 0) |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
else |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* The do-all function */ |
|
|
|
/* The do-all function */ |
|
|
|
int disk_add_disk (struct disk_list *head, const char *path) |
|
|
|
|
|
|
|
|
|
|
|
/*int disk_add_disk (struct disk_list *head, const char *path)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
struct disk_list dt = {0}; |
|
|
|
struct disk_list dt = {0}; |
|
|
|
// verify if it is a disk
|
|
|
|
// verify if it is a disk
|
|
|
@ -96,3 +112,4 @@ int disk_add_disk (struct disk_list *head, const char *path) |
|
|
|
disk_list_add(head, &dt); |
|
|
|
disk_list_add(head, &dt); |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|