Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:Allocate a new files structure and copy contents from the* passed in files structure.* errorp will be valid only when the returned files_struct is NULL.

Proto:struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)

Type:struct files_struct

Parameter:

TypeParameterName
struct files_struct *oldf
int *errorp
279  errorp = -ENOMEM
280  newf = kmem_cache_alloc(SLAB cache for files_struct structures (tsk->files) , GFP_KERNEL)
281  If Not newf Then Go to out
284  atomic_set( & ad mostly part, 1)
286  Process spin lock initialization( & written part on a separate cache line in SMP)
287  resize_in_progress = false
288  init_waitqueue_head( & resize_wait)
289  next_fd = 0
290  new_fdt = fdtab
291  max_fds = The default fd array needs to be at least BITS_PER_LONG,* as this is the granularity returned by copy_fdset().
292  close_on_exec = close_on_exec_init
293  open_fds = open_fds_init
294  full_fds_bits = full_fds_bits_init
295  current fd array = fd_array[0]
297  spin_lock( & written part on a separate cache line in SMP)
298  old_fdt = files_fdtable(oldf)
299  open_files = count_open_files(old_fdt)
304  When Value for the false possibility is greater at compile time(open_files > max_fds) cycle
305  spin_unlock( & written part on a separate cache line in SMP)
307  If new_fdt != fdtab Then __free_fdtable(new_fdt)
310  new_fdt = alloc_fdtable(open_files - 1)
311  If Not new_fdt Then
312  errorp = -ENOMEM
313  Go to out_release
319  errorp = -EMFILE
320  Go to out_release
328  spin_lock( & written part on a separate cache line in SMP)
329  old_fdt = files_fdtable(oldf)
330  open_files = count_open_files(old_fdt)
333  Copy 'count' fd bits from the old table to the new table and clear the extra* space if any. This does not copy the file pointers. Called with the files* spinlock held for write.
335  old_fds = current fd array
336  new_fds = current fd array
338  When i != 0 cycle
339  f = old_fds++
340  If f Then
341  get_file(f)
342  Else
351  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization( * new_fds++, f)
353  spin_unlock( & written part on a separate cache line in SMP)
356  memset(new_fds, 0, (max_fds - open_files) * size of * )
358  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization(fdt, new_fdt)
360  Return newf
362  out_release :
363  kmem_cache_free(SLAB cache for files_struct structures (tsk->files) , newf)
364  out :
365  Return NULL
Caller
NameDescribe
unshare_fdUnshare file descriptor table if it is being shared