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