miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
pipe.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_PIPE_H_
24#define _MINIOS_FS_PIPE_H_
25
26#include <miniOS/types.h>
27
28/* Forward-declare the ops struct to break the circular include with vfs.h.
29 * vfs.h includes pipe.h (pipe_t in vfs_file_t); pipe.h uses struct vfs_ops *
30 * to avoid needing the full vfs_ops_t typedef. The typedef and full definition
31 * live in vfs.h which callers should include directly. */
32struct vfs_ops;
33
39#define PIPE_SIZE 4096
40
54typedef struct {
56 uint32_t write_pos; /* monotonically increasing; use % PIPE_SIZE to index */
57 uint32_t read_pos; /* monotonically increasing; use % PIPE_SIZE to index */
58 uint32_t ref_count; /* total number of fds (read + write ends) alive */
59 uint8_t write_closed; /* non-zero when all write-end fds have been closed */
60} pipe_t;
61
70pipe_t *pipe_create(void);
71
84int pipe_read(uint32_t ino, uint64_t off, void *buf, uint32_t len);
85
98int pipe_write(uint32_t ino, uint64_t off, const void *buf, uint32_t len);
99
106void pipe_free(pipe_t *p);
107
111extern struct vfs_ops pipe_ops;
112
120int pipe_write_buf(pipe_t *p, const void *buf, uint32_t len);
121int pipe_read_buf(pipe_t *p, void *buf, uint32_t len);
122
123#endif /* _MINIOS_FS_PIPE_H_ */
pipe_t * pipe_create(void)
Definition pipe.c:37
int pipe_write_buf(pipe_t *p, const void *buf, uint32_t len)
Definition pipe.c:89
struct vfs_ops pipe_ops
Definition pipe.c:125
int pipe_read_buf(pipe_t *p, void *buf, uint32_t len)
Definition pipe.c:57
void pipe_free(pipe_t *p)
Definition pipe.c:113
int pipe_read(uint32_t ino, uint64_t off, void *buf, uint32_t len)
Definition pipe.c:71
#define PIPE_SIZE
Definition pipe.h:39
int pipe_write(uint32_t ino, uint64_t off, const void *buf, uint32_t len)
Definition pipe.c:101
Definition pipe.h:54
uint8_t write_closed
Definition pipe.h:59
uint32_t write_pos
Definition pipe.h:56
uint32_t ref_count
Definition pipe.h:58
uint8_t buf[PIPE_SIZE]
Definition pipe.h:55
uint32_t read_pos
Definition pipe.h:57
Definition vfs.h:75
unsigned int uint32_t
Definition types.h:34
unsigned long int uint64_t
Definition types.h:37
unsigned char uint8_t
Definition types.h:28
uint32_t len
Definition virtio_net.c:1