{"id":810,"date":"2010-08-11T01:28:27","date_gmt":"2010-08-11T04:28:27","guid":{"rendered":"http:\/\/wordpress.matbra.com\/?p=810"},"modified":"2010-08-11T01:36:26","modified_gmt":"2010-08-11T04:36:26","slug":"adicionando-metodo-ao-servidor-vfs-no-minix","status":"publish","type":"post","link":"https:\/\/wordpress.matbra.com\/en\/2010\/08\/11\/adicionando-metodo-ao-servidor-vfs-no-minix\/","title":{"rendered":"Add method to VFS in Minix."},"content":{"rendered":"<p>Good Night,<\/p>\n<p>First of all, what is VFS? VFS means Virtual File System. It is a layer that exists in a lot of OS and in Minix too, this layer takes care of the communication with the File System. It is a Master&#8217;s thesis in Computer Science from Bal\u00e1zs Ger\u00f3fi and the name is &#8220;<a href=\"http:\/\/www.minix3.org\/doc\/gerofi_thesis.pdf\" target=\"_blank\">Design and implementation of the MINIX Virtual File system<\/a>&#8220;. <\/p>\n<p><!--more--><\/p>\n<p>But why to communicate with VFS server? Or why to add something on it? If you want to some tasks you need to do a SYSCALL to it. But sometimes the VFS server don&#8217;t do what you want. So you must add and change it to do it. <\/p>\n<p>How to do this?<\/p>\n<p>Edit &#8220;\/usr\/src\/include\/minix\/callnr.h&#8221;. After this line &#8220;#define GETPGRP\t\t  63&#8243; add this:<br \/>\n[code lang=&#8221;c&#8221;]<br \/>\n#define TESTCALL\t  64<br \/>\n[\/code]<\/p>\n<p>Then you need to change the VFS server and add what you want to do when it is called. Edit &#8220;\/usr\/src\/servers\/vfs\/table.c&#8221;. You should replace the line &#8220;no_sys,\t\/* 64 = unused\t*\/&#8221; with:<br \/>\n[code lang=&#8221;c&#8221;]<br \/>\ndo_TESTCALL,\t\/* 64 = unused\t*\/<br \/>\n[\/code]<\/p>\n<p>What happens? The method do_TESTCALL will be called when a syscall with number 64 is done.<\/p>\n<p>Change the &#8220;\/usr\/src\/servers\/vfs\/proto.h&#8221;. Add this:<br \/>\n[code lang=&#8221;c&#8221;]<br \/>\n\/* do_TESTCALL EXAMPLE  *\/<br \/>\n_PROTOTYPE( int do_TESTCALL, (void)\t\t\t\t\t);<br \/>\n[\/code]<\/p>\n<p>Now you have to create the method in &#8220;\/usr\/src\/servers\/vfs\/read.c&#8221; (I did in this file and it worked). Add this: <\/p>\n<p>[code lang=&#8221;c&#8221;]<br \/>\n\/*===========================================================================*<br \/>\n *Trabalho:\t\t\tdo_ver_contig\t\t\t\t     *<br \/>\n *===========================================================================*\/<br \/>\nPUBLIC int do_TESTCALL() {<br \/>\n  message m;<br \/>\n  printf(&#8220;Number received %d&#8221;, m_in.fd);<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>But how to execute? How this works? How to compile?<br \/>\nAcess &#8220;\/usr\/src\/tools\/&#8221; and execute: <\/p>\n<blockquote><p>\n$ make libraries\n<\/p><\/blockquote>\n<p>(This process can take a long time) <\/p>\n<p>In &#8220;\/usr\/src\/tools&#8221; execute:<\/p>\n<blockquote><p>\n$ make hdboot\n<\/p><\/blockquote>\n<p>Reboot.<\/p>\n<p>How to test and see if it is working? Create in your &#8220;\/root&#8221; a file with this:<br \/>\n[code lang=&#8221;c&#8221;]<br \/>\n#include <stdio.h><br \/>\n#include <unistd.h><br \/>\n#include <lib.h>\n#include <fcntl.h><\/p>\n<p>int main(int argc, char *argv[]) {<br \/>\n  int fd = 2;<br \/>\n  message m;<br \/>\n  m.m1_i1 = fd;<br \/>\n  printf(&#8220;Number: %d&#8221;, fd);<br \/>\n  _syscall(FS, 64, &#038;m);<br \/>\n}<br \/>\n[\/code] <\/p>\n<p>Compile it, execute it and done! <\/p>\n<p>This file do a _syscall to FS saying to execute method 64 and send by message the number 2. So the do_TESTCALL receive the parameter and show it on screen. Yes it is simple, but it is just an example about how to work with VFS server. <\/p>\n<p><a href='http:\/\/wordpress.matbra.com\/wp-content\/uploads\/vfs-call.tar.gz'>Example of code changed\/add to VFS server<\/a><\/p>\n<p><a href=\"http:\/\/wordpress.matbra.com\/en\/2010\/07\/26\/criando-uma-biblioteca-do-sistema-no-minix\/\">Creating a system library in Minix.<\/a><\/p>\n<p>Best Regards,<br \/>\nMatheus<\/p>\n<p>PS: It is a silly example, but it just show how to add some method to VFS Server. Probably in the next days I will show a real example.<\/p>","protected":false},"excerpt":{"rendered":"<p>Good Night, First of all, what is VFS? VFS means Virtual File System. It is a layer that exists in a lot of OS and<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/wordpress.matbra.com\/en\/2010\/08\/11\/adicionando-metodo-ao-servidor-vfs-no-minix\/\">Continue reading<span class=\"screen-reader-text\">Add method to VFS in Minix.<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,34],"tags":[172,182,181],"class_list":["post-810","post","type-post","status-publish","format-standard","hentry","category-c","category-linux","tag-minix","tag-syscall","tag-vfs","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/psjGE-d4","_links":{"self":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/comments?post=810"}],"version-history":[{"count":3,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/810\/revisions"}],"predecessor-version":[{"id":813,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/810\/revisions\/813"}],"wp:attachment":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/media?parent=810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/categories?post=810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/tags?post=810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}