-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose major and minor device numbers
- Loading branch information
1 parent
500eb50
commit e5488bb
Showing
7 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* SPDX-License-Identifier: MIT */ | ||
/* -------------------------------------------------------------------------- */ | ||
|
||
// This test ensures that the major and minor device numbers available through | ||
// struct bdus_ctx match those of the device's block special file. | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
|
||
#include <bdus.h> | ||
|
||
#include <errno.h> | ||
#include <stdbool.h> | ||
#include <sys/stat.h> | ||
#include <sys/sysmacros.h> | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
|
||
static int device_on_device_available(struct bdus_ctx *ctx) | ||
{ | ||
struct stat st; | ||
|
||
if (stat(ctx->path, &st) != 0) | ||
return errno; | ||
|
||
if (ctx->major == major(st.st_rdev) && ctx->minor == minor(st.st_rdev)) | ||
*(bool *)ctx->private_data = true; | ||
|
||
return EIO; | ||
} | ||
|
||
static const struct bdus_ops device_ops = { | ||
.on_device_available = device_on_device_available, | ||
}; | ||
|
||
static const struct bdus_attrs device_attrs = { | ||
.size = 1 << 30, | ||
.logical_block_size = 512, | ||
.dont_daemonize = true, | ||
}; | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
|
||
int main(void) | ||
{ | ||
for (int iteration = 0; iteration < 10; ++iteration) | ||
{ | ||
bool matches = false; | ||
|
||
bdus_run(&device_ops, &device_attrs, &matches); | ||
|
||
if (!matches) | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/* -------------------------------------------------------------------------- */ |