Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:fs\exec.c Create Date:2022-07-28 20:03:57
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:kernel_read_file

Proto:int kernel_read_file(struct file *file, void **buf, loff_t *size, loff_t max_size, enum kernel_read_file_id id)

Type:int

Parameter:

TypeParameterName
struct file *file
void **buf
loff_t *size
loff_tmax_size
enum kernel_read_file_idid
899  bytes = 0
902  If Not S_ISREG(i_mode) || max_size < 0 Then Return -EINVAL
905  ret = deny_write_access(file)
906  If ret Then Return ret
909  ret = security_kernel_read_file(file, id)
910  If ret Then Go to out
913  i_size = NOTE: in a 32bit arch with a preemptable kernel and* an UP compile the i_size_read/write must be atomic* with respect to the local cpu (unlike with preempt disabled),* but they don't need to be atomic with respect to other cpus like in* true SMP (so they
914  If i_size <= 0 Then
915  ret = -EINVAL
916  Go to out
918  If i_size > SIZE_MAX || max_size > 0 && i_size > max_size Then
919  ret = -EFBIG
920  Go to out
923  If id != READING_FIRMWARE_PREALLOC_BUFFER Then buf = vmalloc - allocate virtually contiguous memory*@size: allocation size* Allocate enough pages to cover @size from the page level* allocator and map them into contiguous kernel virtual space.* For tight control over page level allocator and protection flags
925  If Not buf Then
926  ret = -ENOMEM
927  Go to out
930  pos = 0
931  When pos < i_size cycle
932  bytes = kernel_read(file, * buf + pos, i_size - pos, & pos)
933  If bytes < 0 Then
934  ret = bytes
935  Go to out_free
938  If bytes == 0 Then Break
942  If pos != i_size Then
943  ret = -EIO
944  Go to out_free
947  ret = security_kernel_post_read_file(file, * buf, i_size, id)
948  If Not ret Then size = pos
951  out_free :
952  If ret < 0 Then
954  vfree( * buf)
955  * buf = NULL
959  out :
960  allow_write_access(file)
961  Return ret
Caller
NameDescribe
kernel_read_file_from_path
kernel_read_file_from_fd