mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
Everywhere: Add serenity_dev_{makedev,major,minor}
Add them in `<Kernel/API/Device.h>` and use these to provides `{makedev,major,minor}` in `<sys/sysmacros.h>`. It aims to be more in line with other Unix implementations and avoid code duplication in user land.
This commit is contained in:
parent
d4484f4de3
commit
69cabb3ead
7 changed files with 43 additions and 17 deletions
30
Kernel/API/Device.h
Normal file
30
Kernel/API/Device.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Platform.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
ALWAYS_INLINE dev_t serenity_dev_makedev(unsigned major, unsigned minor)
|
||||
{
|
||||
return (minor & 0xffu) | (major << 8u) | ((minor & ~0xffu) << 12u);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE unsigned int serenity_dev_major(dev_t dev)
|
||||
{
|
||||
return (dev & 0xfff00u) >> 8u;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE unsigned int serenity_dev_minor(dev_t dev)
|
||||
{
|
||||
return (dev & 0xffu) | ((dev >> 12u) & 0xfff00u);
|
||||
}
|
||||
|
||||
__END_DECLS
|
Loading…
Add table
Add a link
Reference in a new issue