
Directory Commands:
$ cd temp
$ mkdir demodir
$ cd demodir
$ pwd
/home/netprog/temp/demodir
$ mkdir oops
$ mkdir b
$ mv b c
$ rmdir oops
$ cd c
$ mkdir d1 d2
$ cd ../..
$ mkdir demodir/a

mkdir [디렉토리]: 디렉토리 생성rmdir [디렉토리]: 디렉토리 삭제mv [src][dest]: 파일 이름 변경 또는 파일 이동cd [디렉토리]: 특정 디렉토리로 이동cd ..: 상위(부모) 디렉토리로 이동pwd: 현재 작업 디렉토리 경로명 출력$ pwd
/home/netprog/workspace_system/ch04


ls 명령어를 이용하여 실제 hard link 보기
-i 옵션: inode 출력
demodir/a/x 파일과 demodir/c/d1/xlink 파일의 inode값은 동일(14028415)


► inode 내에서도 파일정보와 데이터 블록 위치로 크게 둘로 나뉜다


저장이 되면서 파일이름하고 inode number가 매칭이됨
2) inode table의 특정한 위치에 데이터가 저장이 됨
3)
4)
디렉토리는 파일들의 이름 목록을 담고 있는 특별한 종류의 파일

디렉토리 내부 살펴 보기

기 타 등 등
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
ino_t get_inode(char *);
void print_path_to(ino_t);
void inode_to_name(ino_t, char *, int);
int main()
{
print_path_to(get_inode("."));
putchar('\n’);
return 0;
}
void print_path_to(ino_t inode)
{
ino_t my_inode = 0;
char its_name[256];
if (get_inode("..") != inode)
{
chdir("..");
inode_to_name(inode, its_name, 256);
my_inode = get_inode(".");
print_path_to(my_inode);
printf("/%s", its_name);
}
}
void inode_to_name(ino_t inode_to_find, char *namebuf, int buflen)
{
DIR *dir_ptr = NULL;
struct dirent *dirent_ptr = NULL;
if ((dir_ptr = opendir(".")) == NULL)
{
perror(NULL);
exit(-1);
}
while ((dirent_ptr = readdir(dir_ptr)) != NULL)
{
if (dirent_ptr->d_ino == inode_to_find)
{
strncpy(namebuf, dirent_ptr->d_name, buflen);
closedir(dir_ptr);
namebuf[buflen - 1] = '\0’;
return;
}
}
fprintf(stderr, "error looking for inode: %ld\n",
inode_node_to_find);
exit(1);
}
ino_t get_inode(char *filename)
{
struct stat info;
if (stat(filename, &info) == -1)
{
fprintf(stderr, "cannot stat ");
perror(NULL);
exit(-1);
}
return info.st_ino;
}