Skip to content

Commit

Permalink
Update non regression code to handle big minor numbers
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
  • Loading branch information
sysstat committed Jul 24, 2020
1 parent 071314d commit 9c8e5ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ioconf.c
Expand Up @@ -489,8 +489,8 @@ char *transform_devmapname(unsigned int major, unsigned int minor)
if (__stat(filen, &aux) == 0) {
/* Get its minor and major numbers */

dm_major = major(aux.st_rdev);
dm_minor = minor(aux.st_rdev);
dm_major = __major(aux.st_rdev);
dm_minor = __minor(aux.st_rdev);

if ((dm_minor == minor) && (dm_major == major)) {
strncpy(name, dp->d_name, sizeof(name));
Expand Down
4 changes: 2 additions & 2 deletions iostat.c
Expand Up @@ -318,8 +318,8 @@ int get_major_minor_nr(char filename[], int *major, int *minor)
if (__stat(dfile, &statbuf) < 0)
return -1;

*major = major(statbuf.st_rdev);
*minor = minor(statbuf.st_rdev);
*major = __major(statbuf.st_rdev);
*minor = __minor(statbuf.st_rdev);

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions systest.c
Expand Up @@ -195,7 +195,7 @@ int virtual_stat(const char *name, struct stat *statbuf)
int major, minor;

if (!strcmp(name, VIRTUALHD)) {
statbuf->st_rdev = (253 << 8) + 2;
statbuf->st_rdev = (253 << MINORBITS) + 2;
return 0;
}

Expand All @@ -206,7 +206,7 @@ int virtual_stat(const char *name, struct stat *statbuf)

if (fgets(line, sizeof(line), fp) != NULL) {
sscanf(line, "%d %d", &major, &minor);
statbuf->st_rdev = (major << 8) + minor;
statbuf->st_rdev = (major << MINORBITS) + minor;
}

fclose(fp);
Expand Down
10 changes: 10 additions & 0 deletions systest.h
Expand Up @@ -12,6 +12,12 @@
#include <sys/statvfs.h>
#include <sys/stat.h>

#ifndef MINORBITS
#define MINORBITS 20
#endif
#define S_MAXMINOR ((1U << MINORBITS) - 1)
#define S_MAXMAJOR ((1U << (32 - MINORBITS)) - 1)

/* Test mode: Use alternate files and syscalls */
#ifdef TEST

Expand All @@ -30,6 +36,8 @@
#define __gettimeofday(m,n) get_day_time(m)
#define __getpwuid(m) get_usrname(m)
#define __fork(m) get_known_pid(m)
#define __major(m) (m >> MINORBITS)
#define __minor(m) (m & S_MAXMINOR)

#define ROOTDIR "./tests/root"
#define ROOTFILE "root"
Expand All @@ -55,6 +63,8 @@
#define __gettimeofday(m,n) gettimeofday(m,n)
#define __getpwuid(m) getpwuid(m)
#define __fork(m) fork(m)
#define __major(m) major(m)
#define __minor(m) minor(m)

#endif

Expand Down

0 comments on commit 9c8e5ca

Please sign in to comment.