Kernel File System API: unmarsh_fs_struct,
Kernel File System API: unmarsh_fs_struct
Int unshare_fs_struct (void) is used to set a new value with the fs_struct of the current task, so that the source code of the copy is not shared. The source code analysis is as follows: int unshare_fs_struct (void) {struct fs_struct; # apply for a new fs_structstruct fs_struct * new_fs = copy_fs_struct (fs); int kill; # if the newly applied fs_struct is null, exit if (! New_fs) return-ENOMEM; task_lock (current); spin_lock (& fs-> lock); kill =! -- Fs-> users; # Set the newly applied fs_structcurrent-> fs = new_fs; spin_unlock (& fs-> lock); task_unlock (current); if (kill) for the current task) implementation of struct (fs); return 0;} copy_fs_struct is as follows: struct fs_struct * struct (struct fs_struct * old) {# apply for fs_struct * fs = struct (fs_cache, GFP_KERNEL ); /* We don't need to lock fs-think why;-) */# assign the initial value if (fs) {fs-> users = 1 to the newly applied fs_struct; fs-> in_exec = 0; spin_lock_init (& fs-> lock); seqcount_init (& fs-> seq); fs-> umask = old-> umask; spin_lock (& old-> lock); fs-> root = old-> root; path_get (& fs-> root); fs-> pwd = old-> pwd; path_get (& fs-> pwd); spin_unlock (& old-> lock);} return fs ;}