File: igt_dir.h

package info (click to toggle)
intel-gpu-tools 2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 63,368 kB
  • sloc: xml: 781,458; ansic: 360,567; python: 8,336; yacc: 2,781; perl: 1,196; sh: 1,177; lex: 487; asm: 227; lisp: 35; makefile: 30
file content (62 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* SPDX-License-Identifier: MIT
 * Copyright © 2025 Intel Corporation
 */

#ifndef IGT_DIR_H
#define IGT_DIR_H

#include "igt_list.h"

/**
 * Callback function type for processing files
 * The callback is blocking, meaning traversal waits for it to return
 * before proceeding to the next file
 * @filename: Path to the file
 * @callback_data: Optional pointer to user-defined data passed to the callback
 *
 * Returns:
 * 0 on success, a negative error code on failure.
 */
typedef int (*igt_dir_file_callback)(const char *filename,
				     void *callback_data);

/**
 * igt_dir_file_list_t: List of files with a relative path
 * @relative_path: path to a file, relative to the root directory
 * @match: a boolean used to filter the list of files. When match=true the
 *	   file is processed, otherwise it is skipped
 * @link: list head for linking files in the list
 */
typedef struct {
	char *relative_path;
	bool match;
	struct igt_list_head link;
} igt_dir_file_list_t;

/**
 * igt_dir_t: Main struct for igt_dir
 * @dirfd: file descriptor of the root directory
 * @root_path: string of the root path, for example:
 *	       /sys/kernel/debug/dri/0000:00:02.0/
 * @file_list_head: head of the list of files
 * @callback: Callback function for file operations. If NULL, defaults
 *	      to reading and discarding file contents
 */
typedef struct {
	int dirfd;
	char *root_path;
	struct igt_list_head file_list_head;
	igt_dir_file_callback callback;
} igt_dir_t;

int igt_dir_get_fd_path(int fd, char *path, size_t path_len);
int igt_dir_callback_read_discard(const char *filename,
				  void *callback_data);
igt_dir_t *igt_dir_create(int dirfd);
int igt_dir_scan_dirfd(igt_dir_t *config, int scan_maxdepth);
int igt_dir_process_files(igt_dir_t *config,
			  igt_dir_file_callback callback,
			  void *callback_data);
void igt_dir_destroy(igt_dir_t *config);
int igt_dir_process_files_simple(int dirfd);
#endif /* IGT_DIR_H */