xref: /OK3568_Linux_fs/kernel/tools/lib/api/fs/fs.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef __API_FS__
3*4882a593Smuzhiyun #define __API_FS__
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <stdbool.h>
6*4882a593Smuzhiyun #include <unistd.h>
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun /*
9*4882a593Smuzhiyun  * On most systems <limits.h> would have given us this, but  not on some systems
10*4882a593Smuzhiyun  * (e.g. GNU/Hurd).
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun #ifndef PATH_MAX
13*4882a593Smuzhiyun #define PATH_MAX 4096
14*4882a593Smuzhiyun #endif
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #define FS(name)				\
17*4882a593Smuzhiyun 	const char *name##__mountpoint(void);	\
18*4882a593Smuzhiyun 	const char *name##__mount(void);	\
19*4882a593Smuzhiyun 	bool name##__configured(void);		\
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /*
22*4882a593Smuzhiyun  * The xxxx__mountpoint() entry points find the first match mount point for each
23*4882a593Smuzhiyun  * filesystems listed below, where xxxx is the filesystem type.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * The interface is as follows:
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  * - If a mount point is found on first call, it is cached and used for all
28*4882a593Smuzhiyun  *   subsequent calls.
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * - If a mount point is not found, NULL is returned on first call and all
31*4882a593Smuzhiyun  *   subsequent calls.
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun FS(sysfs)
34*4882a593Smuzhiyun FS(procfs)
35*4882a593Smuzhiyun FS(debugfs)
36*4882a593Smuzhiyun FS(tracefs)
37*4882a593Smuzhiyun FS(hugetlbfs)
38*4882a593Smuzhiyun FS(bpf_fs)
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun #undef FS
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys);
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun int filename__read_int(const char *filename, int *value);
46*4882a593Smuzhiyun int filename__read_ull(const char *filename, unsigned long long *value);
47*4882a593Smuzhiyun int filename__read_xll(const char *filename, unsigned long long *value);
48*4882a593Smuzhiyun int filename__read_str(const char *filename, char **buf, size_t *sizep);
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun int filename__write_int(const char *filename, int value);
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun int procfs__read_str(const char *entry, char **buf, size_t *sizep);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun int sysctl__read_int(const char *sysctl, int *value);
55*4882a593Smuzhiyun int sysfs__read_int(const char *entry, int *value);
56*4882a593Smuzhiyun int sysfs__read_ull(const char *entry, unsigned long long *value);
57*4882a593Smuzhiyun int sysfs__read_xll(const char *entry, unsigned long long *value);
58*4882a593Smuzhiyun int sysfs__read_str(const char *entry, char **buf, size_t *sizep);
59*4882a593Smuzhiyun int sysfs__read_bool(const char *entry, bool *value);
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun int sysfs__write_int(const char *entry, int value);
62*4882a593Smuzhiyun #endif /* __API_FS__ */
63