1 /*
2  * Copyright (C) 2021 Red Hat, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 
20 #ifndef META_DEVICE_POOL_H
21 #define META_DEVICE_POOL_H
22 
23 #include <glib-object.h>
24 #include <stdint.h>
25 
26 typedef enum _MetaDeviceFileFlags
27 {
28   META_DEVICE_FILE_FLAG_NONE = 0,
29   META_DEVICE_FILE_FLAG_TAKE_CONTROL = 1 << 0,
30   META_DEVICE_FILE_FLAG_READ_ONLY = 1 << 1,
31 } MetaDeviceFileFlags;
32 
33 typedef enum _MetaDeviceFileTags
34 {
35   META_DEVICE_FILE_TAG_KMS,
36 
37   META_DEVICE_FILE_N_TAGS,
38 } MetaDeviceFileTags;
39 
40 typedef struct _MetaDeviceFile MetaDeviceFile;
41 typedef struct _MetaDevicePool MetaDevicePool;
42 
43 int meta_device_file_get_fd (MetaDeviceFile *device_file);
44 
45 const char * meta_device_file_get_path (MetaDeviceFile *device_file);
46 
47 void meta_device_file_tag (MetaDeviceFile     *device_file,
48                            MetaDeviceFileTags  tag,
49                            uint32_t            value);
50 
51 uint32_t meta_device_file_has_tag (MetaDeviceFile     *device_file,
52                                    MetaDeviceFileTags  tag,
53                                    uint32_t            value);
54 
55 MetaDeviceFile * meta_device_file_acquire (MetaDeviceFile *file);
56 
57 void meta_device_file_release (MetaDeviceFile *device_file);
58 
59 MetaDevicePool * meta_device_file_get_pool (MetaDeviceFile *device_file);
60 
61 MetaDeviceFile * meta_device_pool_open (MetaDevicePool       *pool,
62                                         const char           *path,
63                                         MetaDeviceFileFlags   flags,
64                                         GError              **error);
65 
66 G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaDeviceFile, meta_device_file_release)
67 
68 #endif /* META_DEVICE_FILE_POOL_H */
69