{"id":4171,"date":"2022-12-20T17:39:36","date_gmt":"2022-12-20T20:39:36","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/register_chrdev-man9\/"},"modified":"2022-12-20T17:39:36","modified_gmt":"2022-12-20T20:39:36","slug":"register_chrdev-man9","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/register_chrdev-man9\/","title":{"rendered":"register_chrdev (man9)"},"content":{"rendered":"<h1 align=\"center\">register_chrdev<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#AVAILABILITY\">AVAILABILITY<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#BUGS\">BUGS<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">register_chrdev, unregister_chrdev \u2212 register a driver major number<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <linux\/fs.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int register_chrdev(unsigned int<\/b> <i>major<\/i><b>, const char*<\/b><i>name<\/i><b>, struct file_operations*<\/b><i>ops<\/i><b>); <br \/> int unregister_chrdev(unsigned int<\/b> <i>major<\/i><b>, const char *<\/b><i>name<\/i><b>);<\/b><\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>register_chrdev<\/b> function associates a character major number with set of driver entry points. The file_operations structure contains pointers to functions that the the driver uses to implement the kernel interface to the driver.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The paramter <i>major<\/i> is the character major number assigned to the device driver and to be mapped to the function table. The <i>name<\/i> parameter is a short name for the device and is displayed in the The <i>\/proc\/devices<\/i> list. It also must exactly match the name passed to <b>unregister_chrdev<\/b> function when releasing the functions.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">A device driver module may register as many different major numbers as it supports, though this is not typically done.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>unregister_chrdev<\/b> function releases the major number, and is normally called in the module_cleanup function to remove the driver from the kernel.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">On success, <b>register_chrdev<\/b> returns 0 if <i>major<\/i> is a number other then 0, otherwise Linux will choose a major number and return the chosen value.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If there is an error, one of the following codes is returned instead:<\/p>\n<p style=\"margin-left:22%;\">-EINVAL<\/p>\n<p style=\"margin-left:32%;\">The specified number is not valid (> MAX_CHRDEV)<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"9%\">\n<p>-EBUSY<\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"37%\">\n<p>The major number is busy<\/p>\n<\/td>\n<td width=\"31%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>unregister_chrdev<\/b> function will return 0 if successful, or <b>-EINVAL<\/b> if the major number is not registered with the matching name.<\/p>\n<h2>AVAILABILITY <a name=\"AVAILABILITY\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Linux 1.0+<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>register_blkdev<\/b>(9) <b>mknod<\/b>(2)<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Stephen Williams (steve@icarus.com)<\/p>\n<h2>BUGS <a name=\"BUGS\"><\/a> <\/h2>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  register_chrdev, unregister_chrdev \u2212 register a driver major number <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1222],"tags":[1226,1223,1225,1251],"class_list":["post-4171","post","type-post","status-publish","format-standard","hentry","category-9-rutinas-del-nucleo","tag-1226","tag-kernel","tag-man9","tag-register_chrdev"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4171"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4171\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}