Register_filesystem and unregister_filesystem of Kernel File System APIs,
Register_filesystem and unregister_filesystem of Kernel File System APIs
Int register_filesystem (struct file_system_type * fs) is used to register a new file system. The source code analysis is as follows: int register_filesystem (struct file_system_type * fs) {int res = 0; struct file_system_type * p; # The file system name cannot contain '. 'bug _ ON (strchr (fs-> name ,'. '); # fs-> next is not null, busyif (fs-> next) return-EBUSY; # the file system is in a list, write_lock (& file_systems_lock); # Check whether the file system of the parameter has been registered. If it has been registered, busy is returned, responsible for modifying the file system p = find_filesystem (fs-> name, st Rlen (fs-> name); if (* p) res =-EBUSY; else * p = fs; write_unlock (& file_systems_lock); return res ;} from the find_filesystem function, we can know that all registered file systems are in the file_systems linked list. It mainly uses name to match whether the file system has registered static struct file_system_type ** find_filesystem (const char * name, unsigned len) {struct file_system_type ** p; for (p = & file_systems; * p; p = & (* p)-> next) # traverse the list of registered file systems and use name to match if (strncmp (* p)-> name, name, len) = 0 &&! (* P)-> name [len]) break; return p;} corresponds to unregister_filesystem, which cancels a file system int unregister_filesystem (struct file_system_type * fs) {struct file_system_type ** tmp; write_lock (& file_systems_lock); # Use the tmp variable to point to the linked list tmp = & file_systems; while (* tmp) of the total file system) {# When the comparison pointer is released and equal, delete this node from file_systems if (fs = * tmp) {* tmp = fs-> next; fs-> next = NULL; write_unlock (& file_systems_lock); synchronize_rcu (); return 0;} tmp = & (* tmp)-> next;} write_unlock (& file_systems_lock ); return-EINVAL ;}