{"id":1666,"date":"2012-04-23T05:37:13","date_gmt":"2012-04-22T20:37:13","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=1666"},"modified":"2012-04-23T05:37:13","modified_gmt":"2012-04-22T20:37:13","slug":"xv6-66-chapter-5-file-system-file-descriptor-layer","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/1666","title":{"rendered":"[xv6 #66] Chapter 5 &#8211; File system &#8211; File descriptor layer"},"content":{"rendered":"<p>\u30c6\u30ad\u30b9\u30c8\u306e74\u30da\u30fc\u30b8<\/p>\n<p>\u672c\u6587<br \/>\nUnix\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u306e\u4e00\u3064\u306e\u30af\u30fc\u30eb\u306a\u5074\u9762\u306f\u3001\u591a\u304f\u306e\u30ea\u30bd\u30fc\u30b9\uff08\u30b3\u30f3\u30bd\u30fc\u30eb\u306e\u3088\u3046\u306a\u30c7\u30d0\u30a4\u30b9\u3084\u30d1\u30a4\u30d7\u3084\u3082\u3061\u308d\u3093\u5b9f\u969b\u306e\u30d5\u30a1\u30a4\u30eb\u3082\uff09\u3092\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u8868\u73fe\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3042\u308b\u3002<br \/>\n\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u306e\u5c64\u306f\u3001\u3053\u306e\u7279\u5fb4\u3092\u9054\u6210\u3059\u308b\u305f\u3081\u306e\u5c64\u3067\u3042\u308b\u3002<\/p>\n<p>xv6\u306f\u3001\u7b2c0\u7ae0\u3067\u898b\u305f\u3088\u3046\u306b\u3001\u5404\u30d7\u30ed\u30bb\u30b9\u304c\u958b\u3044\u3066\u308b\u30d5\u30a1\u30a4\u30eb\uff08\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\uff09\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u5404\u30d7\u30ed\u30bb\u30b9\u3054\u3068\u306b\u4e0e\u3048\u308b\u3002<br \/>\n\u958b\u3044\u3066\u3044\u308b\u305d\u308c\u305e\u308c\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u3001inode\u3084\u30d1\u30a4\u30d7\u3001\u305d\u308c\u306bI\/O\u30aa\u30d5\u30bb\u30c3\u30c8\u3092\u52a0\u3048\u3001\u305d\u308c\u3089\u3092\u30e9\u30c3\u30d7\u3059\u308bfile\u69cb\u9020\u4f53\u3068\u3057\u3066\u8868\u73fe\u3055\u308c\u308b\u3002<br \/>\n1\u56de\u306eopen\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u306e\u547c\u3073\u51fa\u3057\u3054\u3068\u306b\u3001\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\uff08\u65b0\u3057\u3044file\u69cb\u9020\u4f53\uff09\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\n\u8907\u6570\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u540c\u3058\u30d5\u30a1\u30a4\u30eb\u3092\u304a\u4e92\u3044\u7121\u95a2\u4fc2\u306b\u958b\u3044\u305f\u5834\u5408\u3001\u305d\u308c\u305e\u308c\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306f\u9055\u3046I\/O\u30aa\u30d5\u30bb\u30c3\u30c8\u3092\u6301\u3064\u3060\u308d\u3046\u3002<br \/>\n\u4e00\u65b9\u3001\u4e00\u3064\u306e\u958b\u3044\u3066\u3044\u308b\u30d5\u30a1\u30a4\u30eb\uff08file\u69cb\u9020\u4f53\uff09\u306f\u3001\u3042\u308b\u30d7\u30ed\u30bb\u30b9\u306e\u30d5\u30a1\u30a4\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u8907\u6570\u56de\u73fe\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u3001\u307e\u305f\u3001\u8907\u6570\u306e\u30d7\u30ed\u30bb\u30b9\u306b\u6e21\u3063\u3066\u3082\u540c\u3058\u3053\u3068\u304c\u8d77\u304d\u308b\u53ef\u80fd\u6027\u304c\u5f53\u7136\u3042\u308b\u3002<br \/>\n\u3042\u308b\u30d7\u30ed\u30bb\u30b9\u304copen\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3092\u547c\u3073\u51fa\u3057\u305f\u3089\u3001dup\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u30a8\u30a4\u30ea\u30a2\u30b9\u304c\u4f5c\u6210\u3055\u308c\u308b\u304b\u3001\u3082\u3057\u304f\u306ffork\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u5b50\u30d7\u30ed\u30bb\u30b9\u306b\u5171\u6709\u3055\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u8d77\u3053\u308b\u3060\u308d\u3046\u3002<br \/>\n\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u30ab\u30a6\u30f3\u30c8ref\u306b\u3088\u3063\u3066\u3001\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u304c\u500b\u5225\u306b\u958b\u304b\u308c\u3066\u3044\u308b\u56de\u6570\u304c\u8ffd\u8de1\u3055\u308c\u308b\u3002<br \/>\n\u4e00\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u3001\u8aad\u307f\u8fbc\u307f\u3082\u3057\u304f\u306f\u66f8\u304d\u8fbc\u307f\u3001\u307e\u305f\u306f\u305d\u306e\u4e21\u65b9\u306e\u305f\u3081\u306b\u958b\u304f\u3053\u3068\u304c\u51fa\u6765\u308b\u3002<br \/>\nreadable\u30d5\u30a3\u30fc\u30eb\u30c9\u3068writable\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u3053\u308c\u3092\u8ffd\u8de1\u3059\u308b\u3002<\/p>\n<p>file.h<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">struct file {\r\n  enum { FD_NONE, FD_PIPE, FD_INODE } type;\r\n  int ref; \/\/ reference count\r\n  char readable;\r\n  char writable;\r\n  struct pipe *pipe;\r\n  struct inode *ip;\r\n  uint off;\r\n};\r\n\r\n\r\n\/\/ in-core file system types\r\n\r\nstruct inode {\r\n  uint dev;           \/\/ Device number\r\n  uint inum;          \/\/ Inode number\r\n  int ref;            \/\/ Reference count\r\n  int flags;          \/\/ I_BUSY, I_VALID\r\n\r\n  short type;         \/\/ copy of disk inode\r\n  short major;\r\n  short minor;\r\n  short nlink;\r\n  uint size;\r\n  uint addrs&#x5B;NDIRECT+1];\r\n};\r\n\r\n#define I_BUSY 0x1\r\n#define I_VALID 0x2\r\n\r\n\/\/ device implementations\r\n\r\nstruct devsw {\r\n  int (*read)(struct inode*, char*, int);\r\n  int (*write)(struct inode*, char*, int);\r\n};\r\n\r\nextern struct devsw devsw&#x5B;];\r\n\r\n#define CONSOLE 1<\/pre>\n<p>\u30b7\u30b9\u30c6\u30e0\u5185\u3067\u958b\u304b\u308c\u3066\u3044\u308b\u5168\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u306a\u30d5\u30a1\u30a4\u30eb\u30c6\u30fc\u30d6\u30eb\u3067\u3042\u308bftable\u306b\u4fdd\u6301\u3055\u308c\u308b\u3002<br \/>\n\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u30c6\u30fc\u30d6\u30eb\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u5272\u308a\u5f53\u3066\u308b\u305f\u3081\u306e\u95a2\u6570\uff08filealloc\uff09\u3084\u3001\u53c2\u7167\u306e\u8907\u88fd\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\uff08filedup\uff09\u3084\u3001\u53c2\u7167\u3092\u89e3\u653e\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\uff08fileclose\uff09\u3084\u3001\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u66f8\u304d\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\uff08fileread, filewrite\uff09\u3092\u6301\u3064\u3002<\/p>\n<p>file.c<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &quot;types.h&quot;\r\n#include &quot;defs.h&quot;\r\n#include &quot;param.h&quot;\r\n#include &quot;fs.h&quot;\r\n#include &quot;file.h&quot;\r\n#include &quot;spinlock.h&quot;\r\n\r\nstruct devsw devsw&#x5B;NDEV];\r\nstruct {\r\n  struct spinlock lock;\r\n  struct file file&#x5B;NFILE];\r\n} ftable;\r\n\r\nvoid\r\nfileinit(void)\r\n{\r\n  initlock(&amp;ftable.lock, &quot;ftable&quot;);\r\n}\r\n\r\n\/\/ Allocate a file structure.\r\nstruct file*\r\nfilealloc(void)\r\n{\r\n  struct file *f;\r\n\r\n  acquire(&amp;ftable.lock);\r\n  for(f = ftable.file; f &lt; ftable.file + NFILE; f++){\r\n    if(f-&gt;ref == 0){\r\n      f-&gt;ref = 1;\r\n      release(&amp;ftable.lock);\r\n      return f;\r\n    }\r\n  }\r\n  release(&amp;ftable.lock);\r\n  return 0;\r\n}\r\n\r\n\/\/ Increment ref count for file f.\r\nstruct file*\r\nfiledup(struct file *f)\r\n{\r\n  acquire(&amp;ftable.lock);\r\n  if(f-&gt;ref &lt; 1)\r\n    panic(&quot;filedup&quot;);\r\n  f-&gt;ref++;\r\n  release(&amp;ftable.lock);\r\n  return f;\r\n}\r\n\r\n\/\/ Close file f.  (Decrement ref count, close when reaches 0.)\r\nvoid\r\nfileclose(struct file *f)\r\n{\r\n  struct file ff;\r\n\r\n  acquire(&amp;ftable.lock);\r\n  if(f-&gt;ref &lt; 1)\r\n    panic(&quot;fileclose&quot;);\r\n  if(--f-&gt;ref &gt; 0){\r\n    release(&amp;ftable.lock);\r\n    return;\r\n  }\r\n  ff = *f;\r\n  f-&gt;ref = 0;\r\n  f-&gt;type = FD_NONE;\r\n  release(&amp;ftable.lock);\r\n  \r\n  if(ff.type == FD_PIPE)\r\n    pipeclose(ff.pipe, ff.writable);\r\n  else if(ff.type == FD_INODE){\r\n    begin_trans();\r\n    iput(ff.ip);\r\n    commit_trans();\r\n  }\r\n}\r\n\r\n\/\/ Get metadata about file f.\r\nint\r\nfilestat(struct file *f, struct stat *st)\r\n{\r\n  if(f-&gt;type == FD_INODE){\r\n    ilock(f-&gt;ip);\r\n    stati(f-&gt;ip, st);\r\n    iunlock(f-&gt;ip);\r\n    return 0;\r\n  }\r\n  return -1;\r\n}\r\n\r\n\/\/ Read from file f.  Addr is kernel address.\r\nint\r\nfileread(struct file *f, char *addr, int n)\r\n{\r\n  int r;\r\n\r\n  if(f-&gt;readable == 0)\r\n    return -1;\r\n  if(f-&gt;type == FD_PIPE)\r\n    return piperead(f-&gt;pipe, addr, n);\r\n  if(f-&gt;type == FD_INODE){\r\n    ilock(f-&gt;ip);\r\n    if((r = readi(f-&gt;ip, addr, f-&gt;off, n)) &gt; 0)\r\n      f-&gt;off += r;\r\n    iunlock(f-&gt;ip);\r\n    return r;\r\n  }\r\n  panic(&quot;fileread&quot;);\r\n}\r\n\r\n\/\/PAGEBREAK!\r\n\/\/ Write to file f.  Addr is kernel address.\r\nint\r\nfilewrite(struct file *f, char *addr, int n)\r\n{\r\n  int r;\r\n\r\n  if(f-&gt;writable == 0)\r\n    return -1;\r\n  if(f-&gt;type == FD_PIPE)\r\n    return pipewrite(f-&gt;pipe, addr, n);\r\n  if(f-&gt;type == FD_INODE){\r\n    \/\/ write a few blocks at a time to avoid exceeding\r\n    \/\/ the maximum log transaction size, including\r\n    \/\/ i-node, indirect block, allocation blocks,\r\n    \/\/ and 2 blocks of slop for non-aligned writes.\r\n    \/\/ this really belongs lower down, since writei()\r\n    \/\/ might be writing a device like the console.\r\n    int max = ((LOGSIZE-1-1-2) \/ 2) * 512;\r\n    int i = 0;\r\n    while(i &lt; n){\r\n      int n1 = n - i;\r\n      if(n1 &gt; max)\r\n        n1 = max;\r\n\r\n      begin_trans();\r\n      ilock(f-&gt;ip);\r\n      if ((r = writei(f-&gt;ip, addr + i, f-&gt;off, n1)) &gt; 0)\r\n        f-&gt;off += r;\r\n      iunlock(f-&gt;ip);\r\n      commit_trans();\r\n\r\n      if(r &lt; 0)\r\n        break;\r\n      if(r != n1)\r\n        panic(&quot;short filewrite&quot;);\r\n      i += r;\r\n    }\r\n    return i == n ? n : -1;\r\n  }\r\n  panic(&quot;filewrite&quot;);\r\n}<\/pre>\n<p>\u6700\u521d\u306e3\u3064\u306f\u3001\u304a\u306a\u3058\u307f\u306e\u624b\u9806\u306b\u5f93\u3046\u3002<br \/>\nfilealloc\u95a2\u6570\u306f\u3001\u53c2\u7167\u3055\u308c\u3066\u3044\u306a\u3044\u30d5\u30a1\u30a4\u30eb\uff08f-&gt;ref == 0\uff09\u3092\u635c\u3059\u305f\u3081\u306b\u30d5\u30a1\u30a4\u30eb\u30c6\u30fc\u30d6\u30eb\u3092\u30b9\u30ad\u30e3\u30f3\u3057\u3001\u65b0\u3057\u3044\u53c2\u7167\u3092\u8fd4\u3059\u3002<br \/>\nfiledup\u95a2\u6570\u306f\u3001\u53c2\u7167\u30ab\u30a6\u30f3\u30c8\u3092\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3059\u308b\u3002<br \/>\nfileclose\u95a2\u6570\u306f\u3001\u53c2\u7167\u30ab\u30a6\u30f3\u30c8\u3092\u30c7\u30af\u30ea\u30e1\u30f3\u30c8\u3059\u308b\u3002<br \/>\n\u30d5\u30a1\u30a4\u30eb\u306e\u53c2\u7167\u30ab\u30a6\u30f3\u30c8\u304c\u30bc\u30ed\u306b\u9054\u3057\u305f\u3089\u3001fileclose\u95a2\u6570\u306f\u3001file\u69cb\u9020\u4f53\u306e\u88cf\u306b\u3042\u308b\u30d1\u30a4\u30d7\u3084inode\u3092\u89e3\u653e\u3059\u308b\u3002<br \/>\n\u3069\u3061\u3089\u3092\u89e3\u653e\u3059\u308b\u304b\u306ffile\u69cb\u9020\u4f53\u306etype\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u306b\u5f93\u3046\u3002<\/p>\n<p>filestat, fileread, filewrite\u95a2\u6570\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3059\u308bstat, read, write\u306e\u5b9f\u88c5\u3067\u3042\u308b\u3002<br \/>\nfilestat\u95a2\u6570\u306f\u3001inode\u306b\u5bfe\u3057\u3066\u306e\u307f\u6a5f\u80fd\u3057\u3001stati\u95a2\u6570\u3092\u547c\u3076\u3002<br \/>\nfileread, filewrite\u95a2\u6570\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u958b\u304b\u308c\u305f\u3068\u304d\u306e\u30e2\u30fc\u30c9\u306b\u305d\u306e\u64cd\u4f5c\u304c\u8a31\u53ef\u3055\u308c\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af\u3057\u3001\u305d\u308c\u304b\u3089\u30d1\u30a4\u30d7\u3084inode\u306e\u5b9f\u88c5\u3092\u547c\u3073\u51fa\u3059\u3002<br \/>\n\u3082\u3057\u3001\u30d5\u30a1\u30a4\u30eb\u304cinode\u3092\u8868\u73fe\u3057\u3066\u3044\u305f\u3089\u3001fileread\u3068filewrite\u306f\u3001I\/O\u30aa\u30d5\u30bb\u30c3\u30c8\u306e\u5024\u3092\u3001\u64cd\u4f5c\u306e\u305f\u3081\u306e\u30aa\u30d5\u30bb\u30c3\u30c8\u3068\u3057\u3066\u4f7f\u3044\u3001\u305d\u306e\u30aa\u30d5\u30bb\u30c3\u30c8\u5024\u3092\u8aad\u307f\u66f8\u304d\u3057\u305f\u5206\u3060\u3051\u9032\u3081\u308b\u3002<br \/>\n\u30d1\u30a4\u30d7\u306b\u306f\u30aa\u30d5\u30bb\u30c3\u30c8\u306e\u6982\u5ff5\u306f\u306a\u3044\u3002<br \/>\ninode\u306e\u95a2\u6570\u306f\u3001\u305d\u306e\u547c\u3073\u51fa\u3057\u5074\u306b\u3088\u308b\u30ed\u30c3\u30af\u306e\u5236\u5fa1\u3092\u8981\u6c42\u3059\u308b\u3053\u3068\u3092\u601d\u3044\u51fa\u305b\u3002\uff08filestat\u95a2\u6570\u306a\u3069\u306eilock, iunlock\u306e\u547c\u3073\u51fa\u3057\u90e8\u5206\uff09<br \/>\ninode\u3092\u30ed\u30c3\u30af\u3059\u308b\u3053\u3068\u306f\u3001\u8aad\u307f\u8fbc\u307f\u3084\u66f8\u304d\u8fbc\u307f\u306e\u30aa\u30d5\u30bb\u30c3\u30c8\u5024\u306e\u66f4\u65b0\u304c\u30a2\u30c8\u30df\u30c3\u30af\u306b\u884c\u308f\u308c\u308b\u3068\u3044\u3046\u4fbf\u5229\u306a\u526f\u4f5c\u7528\u3082\u3082\u305f\u3089\u3059\u3002<br \/>\n\u306a\u306e\u3067\u3001\u540c\u3058\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057\u3066\u540c\u6642\u306b\u8907\u6570\u306e\u66f8\u304d\u8fbc\u307f\u304c\u767a\u751f\u3057\u3066\u3082\u3001\u304a\u4e92\u3044\u306e\u30c7\u30fc\u30bf\u304c\u4e0a\u66f8\u304d\u3055\u308c\u308b\u3053\u3068\u306f\u306a\u3044\u3002<br \/>\n\u304c\u3001\u6700\u7d42\u7684\u306b\u306f\u305d\u306e\u66f8\u304d\u8fbc\u307f\u306f\u3054\u3061\u3083\u6df7\u305c\u306b\u306a\u308b\u3060\u308d\u3046\u3002<\/p>\n<h3>\u611f\u60f3<\/h3>\n<p>\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u306e\u5b9f\u88c5\u306b\u3064\u3044\u3066\u3067\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u3067\u306f\u3001\u30d1\u30a4\u30d7\u3068inode\u304c\u7d71\u5408\u3055\u308c\u308b\u3068\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\ninode\u306e\u5c64\u3067\u5b9f\u969b\u306e\u30d5\u30a1\u30a4\u30eb\u3068\u30c7\u30d0\u30a4\u30b9\u304c\u7d71\u5408\u3055\u308c\u308b\u306e\u3067\u3001\u6700\u7d42\u7684\u306b\u5b9f\u969b\u306e\u30d5\u30a1\u30a4\u30eb\u3001\u30c7\u30d0\u30a4\u30b9\u3001\u30d1\u30a4\u30d7\u304c&#8221;\u30d5\u30a1\u30a4\u30eb&#8221;\u3068\u3057\u3066\u6271\u308f\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u81ea\u4f53\u306f\u3001\u4eca\u307e\u3067\u898b\u3066\u304d\u305f\u30b3\u30fc\u30c9\u3068\u540c\u3058\u3088\u3046\u306a\u611f\u3058\u3067\u3001\u6ce8\u610f\u6df1\u304f\u8aad\u307e\u306a\u3044\u3068\u52d8\u9055\u3044\u3059\u308b\u3088\u3046\u306a\u90e8\u5206\u306f\u7279\u306b\u306a\u3055\u3052\u3067\u3059\u3002<br \/>\n\u305d\u308c\u3060\u304b\u3089\u304b\u3001\u3053\u306e\u7bc0\u306f\u4e00\u3064\u4e00\u3064\u306e\u95a2\u6570\u306f\u30b5\u30e9\u30c3\u3068\u8aac\u660e\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30bf\u30a4\u30c8\u30eb\u306b\u3082&#8221;Code: &#8220;\u304c\u5165\u3063\u3066\u306a\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u6b21\u306e\u7bc0\u3067\u3001xv6\u81ea\u4f53\u306e\u8aac\u660e\u306f\u7d42\u308f\u308a\u3067\u3059\u3002<br \/>\n\uff08\u305d\u306e\u5f8c\u3001Real world\u306e\u7bc0\u3068Exercises\u306e\u7bc0\u304c\u3042\u308a\u307e\u3059\u3051\u3069\u306d\uff09<\/p>\n<p>\u3055\u3089\u306b\u4ed8\u9332A, B\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u4ee5\u524d\u8aad\u3080\u304b\u3069\u3046\u304b\u306f\u672a\u5b9a\u3068\u66f8\u3044\u305f\u899a\u3048\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u30b6\u30c3\u3068\u76ee\u3092\u901a\u3057\u305f\u3068\u3053\u308d\u3001\u6559\u80b2\u7528OS\u306e\u67a0\u5185\u306b\u3068\u3069\u307e\u3089\u306a\u3044\u5b9f\u969b\u306e\u4e16\u754c\u306e\u8a71\u3082\u66f8\u304b\u308c\u3066\u308b\u307f\u305f\u3044\u3067\u3001\u306a\u304b\u306a\u304b\u9762\u767d\u305d\u3046\u306a\u306e\u3067\u8aad\u3093\u3067\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c6\u30ad\u30b9\u30c8\u306e74\u30da\u30fc\u30b8<\/p>\n<p>\u672c\u6587<br \/>\nUnix\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u306e\u4e00\u3064\u306e\u30af\u30fc\u30eb\u306a\u5074\u9762\u306f\u3001\u591a\u304f\u306e\u30ea\u30bd\u30fc\u30b9\uff08\u30b3\u30f3\u30bd\u30fc\u30eb\u306e\u3088\u3046\u306a\u30c7\u30d0\u30a4\u30b9\u3084\u30d1\u30a4\u30d7\u3084\u3082\u3061\u308d\u3093\u5b9f\u969b\u306e\u30d5\u30a1\u30a4\u30eb\u3082\uff09\u3092\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u8868\u73fe\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3042\u308b\u3002<br \/>\n\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u306e\u5c64\u306f\u3001\u3053\u306e\u7279\u5fb4\u3092\u9054\u6210\u3059\u308b\u305f\u3081\u306e\u5c64\u3067\u3042\u308b\u3002<\/p>\n<p>xv6\u306f\u3001\u7b2c0\u7ae0\u3067\u898b\u305f\u3088\u3046\u306b\u3001\u5404\u30d7\u30ed\u30bb\u30b9\u304c\u958b\u3044\u3066\u308b\u30d5\u30a1\u30a4\u30eb\uff08\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\uff09\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u5404\u30d7\u30ed\u30bb\u30b9\u3054\u3068\u306b\u4e0e\u3048\u308b\u3002<br \/>\n\u958b\u3044\u3066\u3044\u308b\u305d\u308c\u305e\u308c\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u3001inode\u3084\u30d1\u30a4\u30d7\u3001\u305d\u308c\u306bI\/O\u30aa\u30d5\u30bb\u30c3\u30c8\u3092\u52a0\u3048\u3001\u305d\u308c\u3089\u3092\u30e9\u30c3\u30d7\u3059\u308bfile\u69cb\u9020\u4f53\u3068\u3057\u3066\u8868\u73fe\u3055\u308c\u308b\u3002<br \/>\n1\u56de\u306eopen\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u306e\u547c\u3073\u51fa\u3057\u3054\u3068\u306b\u3001\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\uff08\u65b0\u3057\u3044file\u69cb\u9020\u4f53\uff09\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\n\u8907\u6570\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u540c\u3058\u30d5\u30a1\u30a4\u30eb\u3092\u304a\u4e92\u3044\u7121\u95a2\u4fc2\u306b\u958b\u3044\u305f\u5834\u5408\u3001\u305d\u308c\u305e\u308c\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306f\u9055\u3046I\/O\u30aa\u30d5\u30bb\u30c3\u30c8\u3092\u6301\u3064\u3060\u308d\u3046\u3002<br \/>\n\u4e00\u65b9\u3001\u4e00\u3064\u306e\u958b\u3044\u3066\u3044\u308b\u30d5\u30a1\u30a4\u30eb\uff08file\u69cb\u9020\u4f53\uff09\u306f\u3001\u3042\u308b\u30d7\u30ed\u30bb\u30b9\u306e\u30d5\u30a1\u30a4\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u8907\u6570\u56de\u73fe\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u3001\u307e\u305f\u3001\u8907\u6570\u306e\u30d7\u30ed\u30bb\u30b9\u306b\u6e21\u3063\u3066\u3082\u540c\u3058\u3053\u3068\u304c\u8d77\u304d\u308b\u53ef\u80fd\u6027\u304c\u5f53\u7136\u3042\u308b\u3002<br \/>\n\u3042\u308b\u30d7\u30ed\u30bb\u30b9\u304copen\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3092\u547c\u3073\u51fa\u3057\u305f\u3089\u3001dup\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u30a8\u30a4\u30ea\u30a2\u30b9\u304c\u4f5c\u6210\u3055\u308c\u308b\u304b\u3001\u3082\u3057\u304f\u306ffork\u30b7\u30b9\u30c6\u30e0\u30b3\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u5b50\u30d7\u30ed\u30bb\u30b9\u306b\u5171\u6709\u3055\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u8d77\u3053\u308b\u3060\u308d\u3046\u3002<br \/>\n\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u30ab\u30a6\u30f3\u30c8ref\u306b\u3088\u3063\u3066\u3001\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u304c\u500b\u5225\u306b\u958b\u304b\u308c\u3066\u3044\u308b\u56de\u6570\u304c\u8ffd\u8de1\u3055\u308c\u308b\u3002<br \/>\n\u4e00\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u3001\u8aad\u307f\u8fbc\u307f\u3082\u3057\u304f\u306f\u66f8\u304d\u8fbc\u307f\u3001\u307e\u305f\u306f\u305d\u306e\u4e21\u65b9\u306e\u305f\u3081\u306b\u958b\u304f\u3053\u3068\u304c\u51fa\u6765\u308b\u3002<br \/>\nreadable\u30d5\u30a3\u30fc\u30eb\u30c9\u3068writable\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u3053\u308c\u3092\u8ffd\u8de1\u3059\u308b\u3002<\/p>\n<p>file.h<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">struct file {\r\n  enum { FD_NONE, FD_PIPE, FD_INODE } type;\r\n  int ref; \/\/ reference count\r\n  char readable;\r\n  char writable;\r\n  struct pipe *pipe;\r\n  struct inode *ip;\r\n  uint off;\r\n};\r\n\r\n\r\n\/\/ in-core file system types\r\n\r\nstruct inode {\r\n  uint dev;           \/\/ Device number\r\n  uint inum;          \/\/ Inode number\r\n  int ref;            \/\/ Reference count\r\n  int flags;          \/\/ I_BUSY, I_VALID\r\n\r\n  short type;         \/\/ copy of disk inode\r\n  short major;\r\n  short minor;\r\n  short nlink;\r\n  uint size;\r\n  uint addrs&#x5B;NDIRECT+1];\r\n};\r\n\r\n#define I_BUSY 0x1\r\n#define I_VALID 0x2\r\n\r\n\/\/ device implementations\r\n\r\nstruct devsw {\r\n  int (*read)(struct inode*, char*, int);\r\n  int (*write)(struct inode*, char*, int);\r\n};\r\n\r\nextern struct devsw devsw&#x5B;];\r\n\r\n#define CONSOLE 1<\/pre>\n<p>\u30b7\u30b9\u30c6\u30e0\u5185\u3067\u958b\u304b\u308c\u3066\u3044\u308b\u5168\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u306a\u30d5\u30a1\u30a4\u30eb\u30c6\u30fc\u30d6\u30eb\u3067\u3042\u308bftable\u306b\u4fdd\u6301\u3055\u308c\u308b\u3002<br \/>\n\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u30c6\u30fc\u30d6\u30eb\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u5272\u308a\u5f53\u3066\u308b\u305f\u3081\u306e\u95a2\u6570\uff08filealloc\uff09\u3084\u3001\u53c2\u7167\u306e\u8907\u88fd\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\uff08filedup\uff09\u3084\u3001\u53c2\u7167\u3092\u89e3\u653e\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\uff08fileclose\uff09\u3084\u3001\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u66f8\u304d\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\uff08fileread, filewrite\uff09\u3092\u6301\u3064\u3002<\/p>\n<p>file.c<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &quot;types.h&quot;\r\n#include &quot;defs.h&quot;\r\n#include &quot;param.h&quot;\r\n#include &quot;fs.h&quot;\r\n#include &quot;file.h&quot;\r\n#include &quot;spinlock.h&quot;\r\n\r\nstruct devsw devsw&#x5B;NDEV];\r\nstruct {\r\n  struct spinlock lock;\r\n  struct file file&#x5B;NFILE];\r\n} ftable;\r\n\r\nvoid\r\nfileinit(void)\r\n{\r\n  initlock(&amp;ftable.lock, &quot;ftable&quot;);\r\n}\r\n\r\n\/\/ Allocate a file structure.\r\nstruct file*\r\nfilealloc(void)\r\n{\r\n  struct file *f;\r\n\r\n  acquire(&amp;ftable.lock);\r\n  for(f = ftable.file; f &lt; ftable.file + NFILE; f++){\r\n    if(f-&gt;ref == 0){\r\n      f-&gt;ref = 1;\r\n      release(&amp;ftable.lock);\r\n      return f;\r\n    }\r\n  }\r\n  release(&amp;ftable.lock);\r\n  return 0;\r\n}\r\n\r\n\/\/ Increment ref count for file f.\r\nstruct file*\r\nfiledup(struct file *f)\r\n{\r\n  acquire(&amp;ftable.lock);\r\n  if(f-&gt;ref &lt; 1)\r\n    panic(&quot;filedup&quot;);\r\n  f-&gt;ref++;\r\n  release(&amp;ftable.lock);\r\n  return f;\r\n}\r\n\r\n\/\/ Close file f.  (Decrement ref count, close when reaches 0.)\r\nvoid\r\nfileclose(struct file *f)\r\n{\r\n  struct file ff;\r\n\r\n  acquire(&amp;ftable.lock);\r\n  if(f-&gt;ref &lt; 1)\r\n    panic(&quot;fileclose&quot;);\r\n  if(--f-&gt;ref &gt; 0){\r\n    release(&amp;ftable.lock);\r\n    return;\r\n  }\r\n  ff = *f;\r\n  f-&gt;ref = 0;\r\n  f-&gt;type = FD_NONE;\r\n  release(&amp;ftable.lock);\r\n  \r\n  if(ff.type == FD_PIPE)\r\n    pipeclose(ff.pipe, ff.writable);\r\n  else if(ff.type == FD_INODE){\r\n    begin_trans();\r\n    iput(ff.ip);\r\n    commit_trans();\r\n  }\r\n}\r\n\r\n\/\/ Get metadata about file f.\r\nint\r\nfilestat(struct file *f, struct stat *st)\r\n{\r\n  if(f-&gt;type == FD_INODE){\r\n    ilock(f-&gt;ip);\r\n    stati(f-&gt;ip, st);\r\n    iunlock(f-&gt;ip);\r\n    return 0;\r\n  }\r\n  return -1;\r\n}\r\n\r\n\/\/ Read from file f.  Addr is kernel address.\r\nint\r\nfileread(struct file *f, char *addr, int n)\r\n{\r\n  int r;\r\n\r\n  if(f-&gt;readable == 0)\r\n    return -1;\r\n  if(f-&gt;type == FD_PIPE)\r\n    return piperead(f-&gt;pipe, addr, n);\r\n  if(f-&gt;type == FD_INODE){\r\n    ilock(f-&gt;ip);\r\n    if((r = readi(f-&gt;ip, addr, f-&gt;off, n)) &gt; 0)\r\n      f-&gt;off += r;\r\n    iunlock(f-&gt;ip);\r\n    return r;\r\n  }\r\n  panic(&quot;fileread&quot;);\r\n}\r\n\r\n\/\/PAGEBREAK!\r\n\/\/ Write to file f.  Addr is kernel address.\r\nint\r\nfilewrite(struct file *f, char *addr, int n)\r\n{\r\n  int r;\r\n\r\n  if(f-&gt;writable == 0)\r\n    return -1;\r\n  if(f-&gt;type == FD_PIPE)\r\n    return pipewrite(f-&gt;pipe, addr, n);\r\n  if(f-&gt;type == FD_INODE){\r\n    \/\/ write a few blocks at a time to avoid exceeding\r\n    \/\/ the maximum log transaction size, including\r\n    \/\/ i-node, indirect block, allocation blocks,\r\n    \/\/ and 2 blocks of slop for non-aligned writes.\r\n    \/\/ this really belongs lower down, since writei()\r\n    \/\/ might be writing a device like the console.\r\n    int max = ((LOGSIZE-1-1-2) \/ 2) * 512;\r\n    int i = 0;\r\n    while(i &lt; n){\r\n      int n1 = n - i;\r\n      if(n1 &gt; max)\r\n        n1 = max;\r\n\r\n      begin_trans();\r\n      ilock(f-&gt;ip);\r\n      if ((r = writei(f-&gt;ip, addr + i, f-&gt;off, n1)) &gt; 0)\r\n        f-&gt;off += r;\r\n      iunlock(f-&gt;ip);\r\n      commit_trans();\r\n\r\n      if(r &lt; 0)\r\n        break;\r\n      if(r != n1)\r\n        panic(&quot;short filewrite&quot;);\r\n      i += r;\r\n    }\r\n    return i == n ? n : -1;\r\n  }\r\n  panic(&quot;filewrite&quot;);\r\n}<\/pre>\n<p>\u6700\u521d\u306e3\u3064\u306f\u3001\u304a\u306a\u3058\u307f\u306e\u624b\u9806\u306b\u5f93\u3046\u3002<br \/>\nfilealloc\u95a2\u6570\u306f\u3001\u53c2\u7167\u3055\u308c\u3066\u3044\u306a\u3044\u30d5\u30a1\u30a4\u30eb\uff08f-&gt;ref == 0\uff09\u3092\u635c\u3059\u305f\u3081\u306b\u30d5\u30a1\u30a4\u30eb\u30c6\u30fc\u30d6\u30eb\u3092\u30b9\u30ad\u30e3\u30f3\u3057\u3001\u65b0\u3057\u3044\u53c2\u7167\u3092\u8fd4\u3059\u3002<br \/>\nfiledup\u95a2\u6570\u306f\u3001\u53c2\u7167\u30ab\u30a6\u30f3\u30c8\u3092\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3059\u308b\u3002<br \/>\nfileclose\u95a2\u6570\u306f\u3001\u53c2\u7167\u30ab\u30a6\u30f3\u30c8\u3092\u30c7\u30af\u30ea\u30e1\u30f3\u30c8\u3059\u308b\u3002<br \/>\n\u30d5\u30a1\u30a4\u30eb\u306e\u53c2\u7167\u30ab\u30a6\u30f3\u30c8\u304c\u30bc\u30ed\u306b\u9054\u3057\u305f\u3089\u3001fileclose\u95a2\u6570\u306f\u3001file\u69cb\u9020\u4f53\u306e\u88cf\u306b\u3042\u308b\u30d1\u30a4\u30d7\u3084inode\u3092\u89e3\u653e\u3059\u308b\u3002<br \/>\n\u3069\u3061\u3089\u3092\u89e3\u653e\u3059\u308b\u304b\u306ffile\u69cb\u9020\u4f53\u306etype\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u306b\u5f93\u3046\u3002<\/p>\n<p>filestat, fileread, filewrite\u95a2\u6570\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3059\u308bstat, read, write\u306e\u5b9f\u88c5\u3067\u3042\u308b\u3002<br \/>\nfilestat\u95a2\u6570\u306f\u3001inode\u306b\u5bfe\u3057\u3066\u306e\u307f\u6a5f\u80fd\u3057\u3001stati\u95a2\u6570\u3092\u547c\u3076\u3002<br \/>\nfileread, filewrite\u95a2\u6570\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u958b\u304b\u308c\u305f\u3068\u304d\u306e\u30e2\u30fc\u30c9\u306b\u305d\u306e\u64cd\u4f5c\u304c\u8a31\u53ef\u3055\u308c\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af\u3057\u3001\u305d\u308c\u304b\u3089\u30d1\u30a4\u30d7\u3084inode\u306e\u5b9f\u88c5\u3092\u547c\u3073\u51fa\u3059\u3002<br \/>\n\u3082\u3057\u3001\u30d5\u30a1\u30a4\u30eb\u304cinode\u3092\u8868\u73fe\u3057\u3066\u3044\u305f\u3089\u3001fileread\u3068filewrite\u306f\u3001I\/O\u30aa\u30d5\u30bb\u30c3\u30c8\u306e\u5024\u3092\u3001\u64cd\u4f5c\u306e\u305f\u3081\u306e\u30aa\u30d5\u30bb\u30c3\u30c8\u3068\u3057\u3066\u4f7f\u3044\u3001\u305d\u306e\u30aa\u30d5\u30bb\u30c3\u30c8\u5024\u3092\u8aad\u307f\u66f8\u304d\u3057\u305f\u5206\u3060\u3051\u9032\u3081\u308b\u3002<br \/>\n\u30d1\u30a4\u30d7\u306b\u306f\u30aa\u30d5\u30bb\u30c3\u30c8\u306e\u6982\u5ff5\u306f\u306a\u3044\u3002<br \/>\ninode\u306e\u95a2\u6570\u306f\u3001\u305d\u306e\u547c\u3073\u51fa\u3057\u5074\u306b\u3088\u308b\u30ed\u30c3\u30af\u306e\u5236\u5fa1\u3092\u8981\u6c42\u3059\u308b\u3053\u3068\u3092\u601d\u3044\u51fa\u305b\u3002\uff08filestat\u95a2\u6570\u306a\u3069\u306eilock, iunlock\u306e\u547c\u3073\u51fa\u3057\u90e8\u5206\uff09<br \/>\ninode\u3092\u30ed\u30c3\u30af\u3059\u308b\u3053\u3068\u306f\u3001\u8aad\u307f\u8fbc\u307f\u3084\u66f8\u304d\u8fbc\u307f\u306e\u30aa\u30d5\u30bb\u30c3\u30c8\u5024\u306e\u66f4\u65b0\u304c\u30a2\u30c8\u30df\u30c3\u30af\u306b\u884c\u308f\u308c\u308b\u3068\u3044\u3046\u4fbf\u5229\u306a\u526f\u4f5c\u7528\u3082\u3082\u305f\u3089\u3059\u3002<br \/>\n\u306a\u306e\u3067\u3001\u540c\u3058\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057\u3066\u540c\u6642\u306b\u8907\u6570\u306e\u66f8\u304d\u8fbc\u307f\u304c\u767a\u751f\u3057\u3066\u3082\u3001\u304a\u4e92\u3044\u306e\u30c7\u30fc\u30bf\u304c\u4e0a\u66f8\u304d\u3055\u308c\u308b\u3053\u3068\u306f\u306a\u3044\u3002<br \/>\n\u304c\u3001\u6700\u7d42\u7684\u306b\u306f\u305d\u306e\u66f8\u304d\u8fbc\u307f\u306f\u3054\u3061\u3083\u6df7\u305c\u306b\u306a\u308b\u3060\u308d\u3046\u3002<\/p>\n<h3>\u611f\u60f3<\/h3>\n<p>\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u306e\u5b9f\u88c5\u306b\u3064\u3044\u3066\u3067\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u3067\u306f\u3001\u30d1\u30a4\u30d7\u3068inode\u304c\u7d71\u5408\u3055\u308c\u308b\u3068\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\ninode\u306e\u5c64\u3067\u5b9f\u969b\u306e\u30d5\u30a1\u30a4\u30eb\u3068\u30c7\u30d0\u30a4\u30b9\u304c\u7d71\u5408\u3055\u308c\u308b\u306e\u3067\u3001\u6700\u7d42\u7684\u306b\u5b9f\u969b\u306e\u30d5\u30a1\u30a4\u30eb\u3001\u30c7\u30d0\u30a4\u30b9\u3001\u30d1\u30a4\u30d7\u304c&#8221;\u30d5\u30a1\u30a4\u30eb&#8221;\u3068\u3057\u3066\u6271\u308f\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u81ea\u4f53\u306f\u3001\u4eca\u307e\u3067\u898b\u3066\u304d\u305f\u30b3\u30fc\u30c9\u3068\u540c\u3058\u3088\u3046\u306a\u611f\u3058\u3067\u3001\u6ce8\u610f\u6df1\u304f\u8aad\u307e\u306a\u3044\u3068\u52d8\u9055\u3044\u3059\u308b\u3088\u3046\u306a\u90e8\u5206\u306f\u7279\u306b\u306a\u3055\u3052\u3067\u3059\u3002<br \/>\n\u305d\u308c\u3060\u304b\u3089\u304b\u3001\u3053\u306e\u7bc0\u306f\u4e00\u3064\u4e00\u3064\u306e\u95a2\u6570\u306f\u30b5\u30e9\u30c3\u3068\u8aac\u660e\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30bf\u30a4\u30c8\u30eb\u306b\u3082&#8221;Code: &#8220;\u304c\u5165\u3063\u3066\u306a\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\u6b21\u306e\u7bc0\u3067\u3001xv6\u81ea\u4f53\u306e\u8aac\u660e\u306f\u7d42\u308f\u308a\u3067\u3059\u3002<br \/>\n\uff08\u305d\u306e\u5f8c\u3001Real world\u306e\u7bc0\u3068Exercises\u306e\u7bc0\u304c\u3042\u308a\u307e\u3059\u3051\u3069\u306d\uff09<\/p>\n<p>\u3055\u3089\u306b\u4ed8\u9332A, B\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u4ee5\u524d\u8aad\u3080\u304b\u3069\u3046\u304b\u306f\u672a\u5b9a\u3068\u66f8\u3044\u305f\u899a\u3048\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u30b6\u30c3\u3068\u76ee\u3092\u901a\u3057\u305f\u3068\u3053\u308d\u3001\u6559\u80b2\u7528OS\u306e\u67a0\u5185\u306b\u3068\u3069\u307e\u3089\u306a\u3044\u5b9f\u969b\u306e\u4e16\u754c\u306e\u8a71\u3082\u66f8\u304b\u308c\u3066\u308b\u307f\u305f\u3044\u3067\u3001\u306a\u304b\u306a\u304b\u9762\u767d\u305d\u3046\u306a\u306e\u3067\u8aad\u3093\u3067\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[405],"class_list":["post-1666","post","type-post","status-publish","format-standard","hentry","category-tech","tag-xv6"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=1666"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/1666\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=1666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=1666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=1666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}