device-file: Add tags

Tags are meant to make it possible for a device file opener to tag a
file if it has affected the state the file descriptor is in; e.g. if it
has enabled a DRM capability.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1828>
This commit is contained in:
Jonas Ådahl 2021-04-11 02:18:57 +02:00
parent ceff2a93ca
commit 5502f956f5
2 changed files with 30 additions and 0 deletions

View File

@ -43,6 +43,7 @@ struct _MetaDeviceFile
int minor;
int fd;
MetaDeviceFileFlags flags;
uint32_t tags[META_DEVICE_FILE_N_TAGS];
};
struct _MetaDevicePool
@ -107,6 +108,22 @@ meta_device_file_get_path (MetaDeviceFile *device_file)
return device_file->path;
}
void
meta_device_file_tag (MetaDeviceFile *device_file,
MetaDeviceFileTags tag,
uint32_t value)
{
device_file->tags[tag] |= value;
}
uint32_t
meta_device_file_has_tag (MetaDeviceFile *device_file,
MetaDeviceFileTags tag,
uint32_t value)
{
return (device_file->tags[tag] & value) == value;
}
static MetaDeviceFile *
meta_device_file_acquire_locked (MetaDeviceFile *file)
{

View File

@ -30,6 +30,11 @@ typedef enum _MetaDeviceFileFlags
META_DEVICE_FILE_FLAG_READ_ONLY = 1 << 1,
} MetaDeviceFileFlags;
typedef enum _MetaDeviceFileTags
{
META_DEVICE_FILE_N_TAGS,
} MetaDeviceFileTags;
typedef struct _MetaDeviceFile MetaDeviceFile;
typedef struct _MetaDevicePool MetaDevicePool;
@ -37,6 +42,14 @@ int meta_device_file_get_fd (MetaDeviceFile *device_file);
const char * meta_device_file_get_path (MetaDeviceFile *device_file);
void meta_device_file_tag (MetaDeviceFile *device_file,
MetaDeviceFileTags tag,
uint32_t value);
uint32_t meta_device_file_has_tag (MetaDeviceFile *device_file,
MetaDeviceFileTags tag,
uint32_t value);
MetaDeviceFile * meta_device_file_acquire (MetaDeviceFile *file);
void meta_device_file_release (MetaDeviceFile *device_file);