VirtualBox

source: vbox/trunk/include/iprt/linux/sysfs.h@ 15399

Last change on this file since 15399 was 15399, checked in by vboxsync, 16 years ago

iprt: new Linux sysfs APIs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: sysfs.h 15399 2008-12-12 22:02:14Z vboxsync $ */
2/** @file
3 * IPRT - Linux sysfs access.
4 */
5
6/*
7 * Copyright (C) 2008 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___iprt_linux_sysfs_h
32#define ___iprt_linux_sysfs_h
33
34#include <iprt/cdefs.h>
35#include <iprt/types.h>
36
37#include <stdarg.h>
38
39__BEGIN_DECLS
40
41/** @defgroup grp_rt_mp RTLinuxSysfs - Linux sysfs
42 * @ingroup grp_rt
43 * @{
44 */
45
46/**
47 * Checks if a sysfs file (or directory, device, symlink, whatever) exists.
48 *
49 * @returns true / false, errno is preserved.
50 * @param pszFormat The name format, either absolute or relative to "/sys/".
51 * @param va The format args.
52 */
53RTDECL(bool) RTLinuxSysFsExistsV(const char *pszFormat, va_list va);
54
55/**
56 * Checks if a sysfs file (or directory, device, symlink, whatever) exists.
57 *
58 * @returns true / false, errno is preserved.
59 * @param pszFormat The name format, either absolute or relative to "/sys/".
60 * @param ... The format args.
61 */
62RTDECL(bool) RTLinuxSysFsExists(const char *pszFormat, ...);
63
64/**
65 * Opens a sysfs file.
66 *
67 * @returns The file descriptor. -1 and errno on failure.
68 * @param pszFormat The name format, either absolute or relative to "/sys/".
69 * @param va The format args.
70 */
71RTDECL(int) RTLinuxSysFsOpenV(const char *pszFormat, va_list va);
72
73/**
74 * Opens a sysfs file.
75 *
76 * @returns The file descriptor. -1 and errno on failure.
77 * @param pszFormat The name format, either absolute or relative to "/sys/".
78 * @param ... The format args.
79 */
80RTDECL(int) RTLinuxSysFsOpen(const char *pszFormat, ...);
81
82/**
83 * Closes a file opened with RTLinuxSysFsOpen or RTLinuxSysFsOpenV.
84 *
85 * @param fd
86 */
87RTDECL(void) RTLinuxSysFsClose(int fd);
88
89/**
90 * Reads a string from a file opened with RTLinuxSysFsOpen or RTLinuxSysFsOpenV.
91 *
92 * @returns The number of bytes read. -1 and errno on failure.
93 * @param fd The file descriptor returned by RTLinuxSysFsOpen or RTLinuxSysFsOpenV.
94 * @param pszBuf Where to store the string.
95 * @param cchBuf The size of the buffer. Must be at least 2 bytes.
96 */
97RTDECL(ssize_t) RTLinuxSysFsReadStr(int fd, char *pszBuf, size_t cchBuf);
98
99/**
100 * Reads a number from a sysfs file.
101 *
102 * @returns 64-bit signed value on success, -1 and errno on failure.
103 * @param uBase The number base, 0 for autodetect.
104 * @param pszFormat The filename format, either absolute or relative to "/sys/".
105 * @param va Format args.
106 */
107RTDECL(int64_t) RTLinuxSysFsReadIntFileV(unsigned uBase, const char *pszFormat, va_list va);
108
109/**
110 * Reads a number from a sysfs file.
111 *
112 * @returns 64-bit signed value on success, -1 and errno on failure.
113 * @param uBase The number base, 0 for autodetect.
114 * @param pszFormat The filename format, either absolute or relative to "/sys/".
115 * @param ... Format args.
116 */
117RTDECL(int64_t) RTLinuxSysFsReadIntFile(unsigned uBase, const char *pszFormat, ...);
118
119/**
120 * Reads a string from a sysfs file. If the file contains a newline, we only
121 * return the text up until there.
122 *
123 * @returns number of characters read on success, -1 and errno on failure.
124 * @param pszBuf Where to store the path element. Must be at least two
125 * characters, but a longer buffer would be advisable.
126 * @param cchBuf The size of the buffer pointed to by @a pszBuf.
127 * @param pszFormat The filename format, either absolute or relative to "/sys/".
128 * @param va Format args.
129 */
130RTDECL(ssize_t) RTLinuxSysFsReadStrFileV(char *pszBuf, size_t cchBuf, const char *pszFormat, va_list va);
131
132/**
133 * Reads a string from a sysfs file. If the file contains a newline, we only
134 * return the text up until there.
135 *
136 * @returns number of characters read on success, -1 and errno on failure.
137 * @param pszBuf Where to store the path element. Must be at least two
138 * characters, but a longer buffer would be advisable.
139 * @param cchBuf The size of the buffer pointed to by @a pszBuf.
140 * @param pszFormat The filename format, either absolute or relative to "/sys/".
141 * @param ... Format args.
142 */
143RTDECL(ssize_t) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, const char *pszFormat, ...);
144
145/**
146 * Reads the last element of the path of the file pointed to by the symbolic
147 * link specified. This is needed at least to get the name of the driver
148 * associated with a device, where pszFormat should be the "driver" link in the
149 * devices sysfs directory.
150 *
151 * @returns The number of characters written on success, -1 and errno on failure.
152 * @param pszBuf Where to store the path element. Must be at least two
153 * characters, but a longer buffer would be advisable.
154 * @param cchBuf The size of the buffer pointed to by @a pszBuf.
155 * @param pszFormat The filename format, either absolute or relative to "/sys/".
156 * @param ... Format args.
157 */
158RTDECL(int) RTLinuxSysFsGetLinkDest(char *pszBuf, size_t cchBuf, const char *pszFormat, ...);
159
160/** @} */
161
162__END_DECLS
163
164#endif
165
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette