dasdinfo: Apply project's coding convention

GitHub-ID: #19

Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
Acked-by: Jan Höppner <hoeppner@linux.vnet.ibm.com>
Signed-off-by: Stefan Haberland <sth@linux.vnet.ibm.com>
This commit is contained in:
Rafael Fonseca
2017-12-01 09:59:46 +01:00
committed by Stefan Haberland
parent 2d3774932b
commit 70a7fc3e72

View File

@@ -159,8 +159,7 @@ struct dasd_data
int blksize;
};
static char EBCtoASC[256] =
{
static char EBCtoASC[256] = {
/* 0x00 NUL SOH STX ETX *SEL HT *RNL DEL */
0x00, 0x01, 0x02, 0x03, 0x07, 0x09, 0x07, 0x7F,
/* 0x08 -GE -SPS -RPT VT FF CR SO SI */
@@ -227,12 +226,12 @@ static char EBCtoASC[256] =
0x38, 0x39, 0x07, 0x07, 0x9A, 0x07, 0x07, 0x07
};
static char *dinfo_ebcdic_dec (char *source, char *target, int l)
static char *dinfo_ebcdic_dec(char *source, char *target, int l)
{
int i;
for (i = 0; i < l; i++)
target[i]=EBCtoASC[(unsigned char)(source[i])];
target[i] = EBCtoASC[(unsigned char)(source[i])];
return target;
}
@@ -242,8 +241,8 @@ static int dinfo_read_dasd_uid(char *uidfile, char *readbuf)
return util_file_read_line(readbuf, RD_BUFFER_SIZE, uidfile);
}
static int dinfo_read_dasd_vlabel (char *device, struct volume_label *vlabel,
char *readbuf)
static int dinfo_read_dasd_vlabel(char *device, struct volume_label *vlabel,
char *readbuf)
{
struct dasd_data data;
struct volume_label tmp;
@@ -253,7 +252,8 @@ static int dinfo_read_dasd_vlabel (char *device, struct volume_label *vlabel,
int f;
char *space;
if ((f = open(device, O_RDONLY)) < 0) {
f = open(device, O_RDONLY);
if (f < 0) {
printf("Could not open device node.\n");
goto error;
}
@@ -286,7 +286,7 @@ static int dinfo_read_dasd_vlabel (char *device, struct volume_label *vlabel,
if (data.dasd_info.FBA_layout) {
bzero(&tmp, vlsize);
memcpy(&tmp, vlabel, vlsize);
memcpy(vlabel->vollbl, &tmp, vlsize-4);
memcpy(vlabel->vollbl, &tmp, vlsize - 4);
}
close(f);
@@ -301,12 +301,12 @@ static int dinfo_read_dasd_vlabel (char *device, struct volume_label *vlabel,
(strncmp(vollbl, "CMS1", 4) == 0)) {
strncpy(readbuf, vlabel->volid, 6);
dinfo_ebcdic_dec(readbuf, readbuf, 6);
space = strchr(readbuf,' ');
space = strchr(readbuf, ' ');
if (space)
*space = 0;
} else
} else {
strcpy(readbuf, "");
}
return 0;
error:
@@ -321,7 +321,7 @@ static void *dinfo_malloc(size_t size)
result = malloc(size);
if (result == NULL) {
printf("Could not allocate %lld bytes of memory",
(unsigned long long) size);
(unsigned long long)size);
}
return result;
}
@@ -332,7 +332,7 @@ static char *dinfo_make_path(char *dirname, char *filename)
size_t len;
len = strlen(dirname) + strlen(filename) + 2;
result = (char *) dinfo_malloc(len);
result = (char *)dinfo_malloc(len);
if (result == NULL)
return NULL;
sprintf(result, "%s/%s", dirname, filename);
@@ -342,8 +342,8 @@ static char *dinfo_make_path(char *dirname, char *filename)
static int dinfo_create_devnode(dev_t dev, char **devno)
{
char *result;
char * pathname[] = { "/dev", getenv("TMPDIR"), "/tmp",
getenv("HOME"), "." , "/"};
char *pathname[] = { "/dev", getenv("TMPDIR"), "/tmp",
getenv("HOME"), ".", "/"};
char filename[] = "dasdinfo0000";
mode_t mode;
unsigned int path;
@@ -354,10 +354,10 @@ static int dinfo_create_devnode(dev_t dev, char **devno)
mode = S_IFBLK | S_IRWXU;
/* Try several locations for the temporary device node. */
for (path=0; path < sizeof(pathname) / sizeof(pathname[0]); path++) {
for (path = 0; path < UTIL_ARRAY_SIZE(pathname); path++) {
if (pathname[path] == NULL)
continue;
for (retry=0; retry < TEMP_DEV_MAX_RETRIES; retry++) {
for (retry = 0; retry < TEMP_DEV_MAX_RETRIES; retry++) {
sprintf(filename, "dasdinfo%04d", retry);
result = dinfo_make_path(pathname[path], filename);
if (result == NULL)
@@ -366,7 +366,8 @@ static int dinfo_create_devnode(dev_t dev, char **devno)
if (rc == 0) {
/* Need this test to cover
* 'nodev'-mounted
* filesystems. */
* filesystems.
*/
fd = open(result, O_RDONLY);
if (fd != -1) {
close(fd);
@@ -375,8 +376,9 @@ static int dinfo_create_devnode(dev_t dev, char **devno)
}
remove(result);
retry = TEMP_DEV_MAX_RETRIES;
} else if (errno != EEXIST)
} else if (errno != EEXIST) {
retry = TEMP_DEV_MAX_RETRIES;
}
free(result);
}
}
@@ -400,7 +402,8 @@ static int dinfo_extract_dev(dev_t *dev, char *str)
bzero(tmp, RD_BUFFER_SIZE);
strncpy(tmp, str, RD_BUFFER_SIZE);
if ((p = strchr(tmp, ':')) == NULL) {
p = strchr(tmp, ':');
if (p == NULL) {
printf("Error: unable to extract major/minor\n");
return -1;
}
@@ -439,6 +442,7 @@ dinfo_is_busiddir(const char *fpath, const struct stat *UNUSED(sb),
char *tempdir;
char linkdir[128];
ssize_t i;
if (tflag != FTW_D || (strncmp((fpath + ftwbuf->base), searchbusid,
strlen(searchbusid)) != 0))
return FTW_CONTINUE;
@@ -454,7 +458,7 @@ dinfo_is_busiddir(const char *fpath, const struct stat *UNUSED(sb),
if ((i < 0) || (i >= 128))
return -1;
/* append '\0' because readlink returns non zero terminated string */
tempdir[i+1] = '\0';
tempdir[i + 1] = '\0';
if (strstr(linkdir, "dasd") == NULL)
return FTW_CONTINUE;
free(busiddir);
@@ -470,15 +474,17 @@ dinfo_find_entry(const char *dir, const char *searchstring,
{
DIR *directory = NULL;
struct dirent *dir_entry = NULL;
directory = opendir(dir);
if (directory == NULL)
return -1;
while ((dir_entry = readdir(directory)) != NULL) {
/* compare if the found entry has exactly the same name
and type as searched */
/* compare if the found entry has exactly the same name and type
* as searched
*/
if ((strncmp(dir_entry->d_name, searchstring,
strlen(searchstring)) == 0)
&& (dir_entry->d_type & type)) {
strlen(searchstring)) == 0) &&
(dir_entry->d_type & type)) {
*result = strdup(dir_entry->d_name);
if (*result == NULL)
goto out;
@@ -555,7 +561,8 @@ static int dinfo_get_uid_from_devnode(char **uidfile, char *devnode)
sprintf(stat_dev, "%d:%d", major(stat_buffer.st_rdev),
minor(stat_buffer.st_rdev));
if ((directory = opendir("/sys/block/")) == NULL) {
directory = opendir("/sys/block/");
if (directory == NULL) {
printf("Error: could not open directory /sys/block\n");
return -1;
}
@@ -573,7 +580,7 @@ static int dinfo_get_uid_from_devnode(char **uidfile, char *devnode)
continue;
if (strncmp(stat_dev, readbuf,
MAX(strlen(stat_dev), strlen(readbuf)-1)) == 0) {
MAX(strlen(stat_dev), strlen(readbuf) - 1)) == 0) {
rc = snprintf(*uidfile, RD_BUFFER_SIZE,
"/sys/block/%s/device/uid",
dir_entry->d_name);
@@ -591,7 +598,7 @@ static int dinfo_get_uid_from_devnode(char **uidfile, char *devnode)
return 0;
}
int main(int argc, char * argv[])
int main(int argc, char *argv[])
{
struct utsname uname_buf;
int version, release;
@@ -635,13 +642,13 @@ int main(int argc, char * argv[])
print_vlabel = 1;
break;
case 'i':
busid=strdup(optarg);
busid = strdup(optarg);
break;
case 'b':
blockdev=strdup(optarg);
blockdev = strdup(optarg);
break;
case 'd':
devnode=strdup(optarg);
devnode = strdup(optarg);
break;
case 'e':
export = 1;
@@ -661,11 +668,11 @@ int main(int argc, char * argv[])
}
uname(&uname_buf);
sscanf(uname_buf.release, "%d.%d", &version,&release);
if (strcmp(uname_buf.sysname,"Linux") ||
sscanf(uname_buf.release, "%d.%d", &version, &release);
if (strcmp(uname_buf.sysname, "Linux") ||
version < 2 || (version == 2 && release < 6)) {
printf("%s %d.%d is not supported\n", uname_buf.sysname,
version,release);
version, release);
exit(1);
}
@@ -693,9 +700,9 @@ int main(int argc, char * argv[])
/* try to read the uid attribute */
if (busid) {
sprintf(uidfile,"/sys/bus/ccw/devices/%s/uid", busid);
sprintf(uidfile, "/sys/bus/ccw/devices/%s/uid", busid);
} else if (blockdev) {
sprintf(uidfile,"/sys/block/%s/device/uid", blockdev);
sprintf(uidfile, "/sys/block/%s/device/uid", blockdev);
} else if (devnode) {
if (dinfo_get_uid_from_devnode(&uidfile, devnode) != 0)
goto error;
@@ -715,12 +722,11 @@ int main(int argc, char * argv[])
if (!srchuid)
break;
}
if (srchuid) {
if (srchuid)
srchuid[0] = '\0';
}
if (export) {
if (export)
printf("ID_UID=%s\n", readbuf);
} else
else
printf("%s\n", readbuf);
if (!print_vlabel && !print_extended_uid)
goto out;
@@ -729,9 +735,9 @@ int main(int argc, char * argv[])
if (print_extended_uid) {
if (dinfo_read_dasd_uid(uidfile, readbuf) == 0) {
if (export) {
if (export)
printf("ID_XUID=%s\n", readbuf);
} else
else
printf("%s\n", readbuf);
if (!print_vlabel)
goto out;
@@ -768,9 +774,9 @@ int main(int argc, char * argv[])
}
if (dinfo_read_dasd_vlabel(device, &vlabel, readbuf) == 0) {
if (export) {
printf("ID_SERIAL=%s\n",readbuf);
} else
if (export)
printf("ID_SERIAL=%s\n", readbuf);
else
printf("%s\n", readbuf);
goto out;
}