📄 compat_generic_segment_checks.c
字号:
/* * compat_generic_segment_checks.c * * This code has been copied from mainline linux kernel git commit * e7b34019606ab1dd06196635e931b0c302799228 to allow ocfs2 to build * against older kernels. For license, refer to mm/filemap.c in mainline * linux kernel. * */#include <linux/fs.h>#ifndef NO_LINUX_UACCESS_H#include <linux/uaccess.h>#else#include <asm/uaccess.h>#endif#include <linux/uio.h>/* * Performs necessary checks before doing a write * @iov: io vector request * @nr_segs: number of segments in the iovec * @count: number of bytes to write * @access_flags: type of access: %VERIFY_READ or %VERIFY_WRITE * * Adjust number of segments and amount of bytes to write (nr_segs should be * properly initialized first). Returns appropriate error code that caller * should return or zero in case that write should be allowed. */int generic_segment_checks(const struct iovec *iov, unsigned long *nr_segs, size_t *count, int access_flags){ unsigned long seg; size_t cnt = 0; for (seg = 0; seg < *nr_segs; seg++) { const struct iovec *iv = &iov[seg]; /* * If any segment has a negative length, or the cumulative * length ever wraps negative then return -EINVAL. */ cnt += iv->iov_len; if (unlikely((ssize_t)(cnt|iv->iov_len) < 0)) return -EINVAL; if (access_ok(access_flags, iv->iov_base, iv->iov_len)) continue; if (seg == 0) return -EFAULT; *nr_segs = seg; cnt -= iv->iov_len; /* This segment is no good */ break; } *count = cnt; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -