■要求定義
– ファイルやフォルダにリンクを設定する
■lnコマンドの使い方
$ ls -l
total 16
-rw-rw-r– 1 vagrant vagrant    0 May 18 07:09 0516.txt
-rw-rw-r– 1 vagrant vagrant    0 May 18 07:09 0517.txt
-rw-rw-r– 1 vagrant vagrant    0 May 18 07:09 0518.txt
$ ln -s 0518.txt MuseumDay // ln -sでシンボリックリンクを作る
$ ls -l
total 28
-rw-rw-r– 1 vagrant vagrant   11 May 18 08:09 0516.txt
-rw-rw-r– 1 vagrant vagrant   11 May 18 08:09 0517.txt
-rw-rw-r– 1 vagrant vagrant   11 May 18 08:09 0518.txt
lrwxrwxrwx 1 vagrant vagrant    8 May 18 08:11 MuseumDay -> 0518.txt
$ cat MuseumDay  // シンボリックリンクの中身を確認
abcde
12345
$ sudo vi MuseumDay
$ cat 0518.txt // シンボリックリンクを編集すると、ファイルが更新されている
abcde
12345
asdf
■検討
– symlinkでシンボリックリンクを作成する
#include 
int symlink(const char *oldpath, const char *newpath);
#include <stdio.h>
#include <unistd.h>  // standard symbolic constants and types
int main(){
	if(symlink("./0517.txt", "NYSE") == 0){
		printf("シンボリックリンクを作成しました。\n");
	} else {
		printf("失敗しました。\n");
	}
	
	return 0;
}
$ ls -l
-rw-rw-r– 1 vagrant vagrant   11 May 18 08:09 0516.txt
-rw-rw-r– 1 vagrant vagrant   11 May 18 08:09 0517.txt
-rw-rw-r– 1 vagrant vagrant   17 May 18 08:14 0518.txt
lrwxrwxrwx 1 vagrant vagrant    8 May 18 08:11 MuseumDay -> 0518.txt
lrwxrwxrwx 1 vagrant vagrant   10 May 18 08:34 NYSE -> ./0517.txt
シンボリックリンクそのものは、ファイルまでのパスを含んだ小さなファイル
リダイレクトファイルみたいなものか??
—
Symbolic links were already present by 1978 in minicomputer operating systems from DEC and Data General’s RDOS. 
■アルゴリズム
1. check: old_file must exist and new_file not yet exist
2. create new file, change new file to Link type
3. store old file name in newfile’s INODE.i_block [] area
   set file size to length of old_file name
   mark new file’s minode dirty
   input newfile’s minode
4. mark new file parent minode dirty
   input new file’s parent minode
inodeとは 主にUNIX系で使われる、ファイルやディレクトリの属性情報が書いてあるデータ
なるほど、inodeにリンク先の情報が書かれているわけだ。道理で中身を見れないわけだ。
 
					 
