1/*
2 * Copyright 2005-2008, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6//!	This file includes some known R5 syscalls
7
8#include <errno.h>
9#include <sys/resource.h>
10#include <sys/stat.h>
11
12#include <SupportDefs.h>
13#include <errno_private.h>
14#include <fs_info.h>
15#include <fs_volume.h>
16
17#include <syscalls.h>
18
19
20int _kset_mon_limit_(int num);
21int _kset_fd_limit_(int num);
22int _klock_node_(int fd);
23int _kunlock_node_(int fd);
24int _kget_cpu_state_(int cpuNum);
25int _kset_cpu_state_(int cpuNum, int state);
26int _kstatfs_(dev_t device, void *whatever, int fd, const char *path, fs_info *info);
27int mount(const char *filesystem, const char *where, const char *device, ulong flags,
28	void *parms, int len);
29int unmount(const char *path);
30
31
32int
33_kset_mon_limit_(int num)
34{
35	struct rlimit rl;
36	if (num < 1)
37		return EINVAL;
38	rl.rlim_cur = num;
39	rl.rlim_max = RLIM_SAVED_MAX;
40	if (setrlimit(RLIMIT_NOVMON, &rl) < 0)
41		return errno;
42	return B_OK;
43}
44
45
46int
47_kset_fd_limit_(int num)
48{
49	struct rlimit rl;
50	if (num < 1)
51		return EINVAL;
52	rl.rlim_cur = num;
53	rl.rlim_max = RLIM_SAVED_MAX;
54	if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
55		return errno;
56	return B_OK;
57}
58
59
60int
61_klock_node_(int fd)
62{
63	return _kern_lock_node(fd);
64}
65
66
67int
68_kunlock_node_(int fd)
69{
70	return _kern_unlock_node(fd);
71}
72
73
74int
75_kget_cpu_state_(int cpuNum)
76{
77	return _kern_cpu_enabled(cpuNum);
78}
79
80
81int
82_kset_cpu_state_(int cpuNum, int state)
83{
84	return _kern_set_cpu_enabled(cpuNum, state != 0);
85}
86
87
88int
89_kstatfs_(dev_t device, void *whatever, int fd, const char *path, fs_info *info)
90{
91	if (device < 0) {
92		if (fd >= 0) {
93			struct stat stat;
94			if (fstat(fd, &stat) < 0)
95				return -1;
96
97			device = stat.st_dev;
98		} else if (path != NULL)
99			device = dev_for_path(path);
100	}
101	if (device < 0)
102		return B_ERROR;
103
104	return fs_stat_dev(device, info);
105}
106
107
108int
109mount(const char *filesystem, const char *where, const char *device, ulong flags,
110	void *parms, int len)
111{
112	status_t err;
113	uint32 mountFlags = 0;
114
115	if (flags & 1)
116		mountFlags |= B_MOUNT_READ_ONLY;
117
118	// we don't support passing (binary) parameters
119	if (parms != NULL || len != 0 || flags & ~1) {
120		__set_errno(B_BAD_VALUE);
121		return -1;
122	}
123
124	err = fs_mount_volume(where, device, filesystem, mountFlags, NULL);
125	if (err < B_OK) {
126		__set_errno(err);
127		return -1;
128	}
129	return 0;
130}
131
132
133int
134unmount(const char *path)
135{
136	status_t err;
137
138	err = fs_unmount_volume(path, 0);
139	if (err < B_OK) {
140		__set_errno(err);
141		return -1;
142	}
143	return 0;
144}
145
146