miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Toggle main menu visibility
Loading...
Searching...
No Matches
sysfs.h
Go to the documentation of this file.
1
// MIT License
2
//
3
// Copyright (c) 2026 Christian Spoo
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included in all
13
// copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
23
#ifndef _MINIOS_FS_SYSFS_H_
24
#define _MINIOS_FS_SYSFS_H_
25
26
#include <
miniOS/fs/vfs.h
>
27
28
/* Node types */
29
#define SYSFS_NODE_DIR 1
30
#define SYSFS_NODE_FILE 2
31
32
/* Static content buffer size — covers "0xNNNNNNNN\n" (11 bytes) with margin */
33
#define SYSFS_CONTENT_MAX 32
34
35
typedef
struct
sysfs_node
{
36
const
char
*
name
;
/* caller-owned string pointer (not copied) */
37
uint8_t
type
;
/* SYSFS_NODE_DIR or SYSFS_NODE_FILE */
38
struct
sysfs_node
*
first_child
;
/* first child (dirs only) */
39
struct
sysfs_node
*
next_sibling
;
/* next sibling in parent's child list */
40
/* File content — callback takes priority over static buffer */
41
int (*
callback
)(
char
*buf,
uint32_t
bufsiz);
42
char
content
[
SYSFS_CONTENT_MAX
];
43
uint32_t
content_len
;
44
}
sysfs_node_t
;
45
46
/* Global sysfs root node — drivers create children under this */
47
extern
sysfs_node_t
*
g_sysfs_root
;
48
49
void
sysfs_init
(
void
);
50
sysfs_node_t
*
sysfs_create_dir
(
sysfs_node_t
*parent,
const
char
*
name
);
51
sysfs_node_t
*
sysfs_create_file
(
sysfs_node_t
*parent,
const
char
*
name
,
52
const
char
*buf,
uint32_t
len
,
53
int
(*
callback
)(
char
*,
uint32_t
));
54
55
#endif
/* _MINIOS_FS_SYSFS_H_ */
sysfs_node
Definition
sysfs.h:35
sysfs_node::content
char content[SYSFS_CONTENT_MAX]
Definition
sysfs.h:42
sysfs_node::first_child
struct sysfs_node * first_child
Definition
sysfs.h:38
sysfs_node::next_sibling
struct sysfs_node * next_sibling
Definition
sysfs.h:39
sysfs_node::content_len
uint32_t content_len
Definition
sysfs.h:43
sysfs_node::callback
int(*) callback(char *buf, uint32_t bufsiz)
Definition
sysfs.h:41
sysfs_node::type
uint8_t type
Definition
sysfs.h:37
sysfs_node::name
const char * name
Definition
sysfs.h:36
g_sysfs_root
sysfs_node_t * g_sysfs_root
Definition
sysfs.c:52
sysfs_create_dir
sysfs_node_t * sysfs_create_dir(sysfs_node_t *parent, const char *name)
Definition
sysfs.c:82
SYSFS_CONTENT_MAX
#define SYSFS_CONTENT_MAX
Definition
sysfs.h:33
sysfs_init
void sysfs_init(void)
Definition
sysfs.c:270
sysfs_create_file
sysfs_node_t * sysfs_create_file(sysfs_node_t *parent, const char *name, const char *buf, uint32_t len, int(*callback)(char *, uint32_t))
Definition
sysfs.c:98
sysfs_node_t
struct sysfs_node sysfs_node_t
uint32_t
unsigned int uint32_t
Definition
types.h:34
uint8_t
unsigned char uint8_t
Definition
types.h:28
vfs.h
len
uint32_t len
Definition
virtio_net.c:1
include
miniOS
fs
sysfs.h
Generated by
1.18.0