Beispiel #1
0
static int sys_ioctl(int fd, int request, void * argp) {
    if (FD_CHECK(fd)) {
        PTR_VALIDATE(argp);
        return ioctl_fs(FD_ENTRY(fd), request, argp);
    }
    return -1;
}
Beispiel #2
0
static int sys_stat(int fd, uintptr_t st) {
    PTR_VALIDATE(st);
    if (FD_CHECK(fd)) {
        return stat_node(FD_ENTRY(fd), st);
    }
    return -1;
}
Beispiel #3
0
static int sys_close(int fd) {
    if (FD_CHECK(fd)) {
        close_fs(FD_ENTRY(fd));
        FD_ENTRY(fd) = NULL;
        return 0;
    }
    return -1;
}
Beispiel #4
0
static int sys_write(int fd, char * ptr, int len) {
    if (FD_CHECK(fd)) {
        PTR_VALIDATE(ptr);
        fs_node_t * node = FD_ENTRY(fd);
        uint32_t out = write_fs(node, node->offset, len, (uint8_t *)ptr);
        node->offset += out;
        return out;
    }
    return -1;
}
Beispiel #5
0
static int sys_readdir(int fd, int index, struct dirent * entry) {
    if (FD_CHECK(fd)) {
        PTR_VALIDATE(entry);
        struct dirent * kentry = readdir_fs(FD_ENTRY(fd), (uint32_t)index);
        if (kentry) {
            memcpy(entry, kentry, sizeof *entry);
            free(kentry);
            return 0;
        } else {
            return 1;
        }
    }
    return -1;
}
Beispiel #6
0
static int sys_write(int fd, char * ptr, int len) {
	if (FD_CHECK(fd)) {
		PTR_VALIDATE(ptr);
		fs_node_t * node = FD_ENTRY(fd);
		if (!has_permission(node, 02)) {
			debug_print(WARNING, "access denied (write, fd=%d)", fd);
			return -EACCES;
		}
		uint32_t out = write_fs(node, node->offset, len, (uint8_t *)ptr);
		node->offset += out;
		return out;
	}
	return -1;
}
Beispiel #7
0
static int sys_write(int fd, char * ptr, int len) {
	if (FD_CHECK(fd)) {
		PTR_VALIDATE(ptr);
		fs_node_t * node = FD_ENTRY(fd);
		if (!(FD_MODE(fd) & 02)) {
			debug_print(WARNING, "access denied (write, fd=%d)", fd);
			return -EACCES;
		}
		uint32_t out = write_fs(node, FD_OFFSET(fd), len, (uint8_t *)ptr);
		FD_OFFSET(fd) += out;
		return out;
	}
	return -EBADF;
}
Beispiel #8
0
static int sys_read(int fd, char * ptr, int len) {
	if (FD_CHECK(fd)) {
		PTR_VALIDATE(ptr);

		fs_node_t * node = FD_ENTRY(fd);
		if (!(FD_MODE(fd) & 01)) {
			debug_print(WARNING, "access denied (read, fd=%d, mode=%d, %s, %s)", fd, FD_MODE(fd), node->name, current_process->name);
			return -EACCES;
		}
		uint32_t out = read_fs(node, FD_OFFSET(fd), len, (uint8_t *)ptr);
		FD_OFFSET(fd) += out;
		return (int)out;
	}
	return -EBADF;
}
Beispiel #9
0
static int sys_seek(int fd, int offset, int whence) {
    if (FD_CHECK(fd)) {
        if (fd < 3)
            return 0;

        switch (whence) {
        case 0:
            FD_ENTRY(fd)->offset = offset;
            break;
        case 1:
            FD_ENTRY(fd)->offset += offset;
            break;
        case 2:
            FD_ENTRY(fd)->offset = FD_ENTRY(fd)->length + offset;
            break;
        }
        return FD_ENTRY(fd)->offset;
    }
    return -1;
}
Beispiel #10
0
static int sys_seek(int fd, int offset, int whence) {
	if (FD_CHECK(fd)) {
		if (fd < 3) {
			return 0;
		}
		switch (whence) {
			case 0:
				FD_OFFSET(fd) = offset;
				break;
			case 1:
				FD_OFFSET(fd) += offset;
				break;
			case 2:
				FD_OFFSET(fd) = FD_ENTRY(fd)->length + offset;
				break;
		}
		return FD_OFFSET(fd);
	}
	return -EBADF;
}