Linux2010. 1. 8. 16:26
# mount -t ntfs-3g

머.. 이런식으로 실행하면 자동으로 mount.ntfs-3g 라는 파일을 찾아서 실행을 한다.
처음에는 오 졸라 신기해!!! 하면서 뻘짓으로 ..

make 과정중에 나온 intall-exec-hook 인줄 알고 파고 들었다가 웬걸 ㄱ-
아무튼 install-exec-hook은 설치후 trigger 식으로 실행해주는 루틴을 의미할 뿐,
execution hook 이랑은 연관이 없다. (젠장 된장 미네랄!)
[링크 : http://wiki.kldp.org/wiki.php/DocbookSgml/Autotools-KLDP]

아무튼, linux kernel utils 를 검색해서 mount.c 를 열어보니 busybox와는 다른 확연한 차이가 있었다.
일단 exec() 패밀리와 fork()를 사용하는 루틴의 존재유무

util-linux-2.12r/mount/mount.c

static int
check_special_mountprog(const char *spec, const char *node, const char *type,
			int flags, char *extra_opts, int *status) {
  char mountprog[120];
  struct stat statbuf;
  int res;

  if (!external_allowed)
      return 0;

  if (type && strlen(type) < 100) {
       sprintf(mountprog, "/sbin/mount.%s", type);
       if (stat(mountprog, &statbuf) == 0) {
	    res = fork();
	    if (res == 0) {
		 const char *oo, *mountargs[10];
		 int i = 0;

		 setuid(getuid());
		 setgid(getgid());
		 oo = fix_opts_string (flags, extra_opts, NULL);
		 mountargs[i++] = mountprog;
		 mountargs[i++] = spec;
		 mountargs[i++] = node;
		 if (nomtab)
		      mountargs[i++] = "-n";
		 if (verbose)
		      mountargs[i++] = "-v";
		 if (oo && *oo) {
		      mountargs[i++] = "-o";
		      mountargs[i++] = oo;
		 }
		 mountargs[i] = NULL;
		 execv(mountprog, (char **) mountargs);
		 exit(1);	/* exec failed */
	    } else if (res != -1) {
		 int st;
		 wait(&st);
		 *status = (WIFEXITED(st) ? WEXITSTATUS(st) : EX_SYSERR);
		 return 1;
	    } else {
	    	 int errsv = errno;
		 error(_("mount: cannot fork: %s"), strerror(errsv));
	    }
       }
  }
  return 0;
}

위에 소스에서 보면

sprintf(mountprog, "/sbin/mount.%s", type);
res = fork();
execv(mountprog, (char **) mountargs);

mount -t ntfs 는 mount.ntfs 로
mount -t cifs 는 mount.cifs 로

-t type 으로 받은 인자를 이용하여 실행을 넘겨준다.



결론 : busybox에서는 mount 소스가 많이 간략화 되어있으므로
         표준 mount 파일에서 지원하는 mount.type 실행치환 기능을 지원하지 않는다.

[링크 : ftp://ftp.kernel.org/pub/linux/utils/util-linux/] 리눅스용 mount.c
[링크 : http://www.koders.com/c/fid840A8124E3B838F1EC7B690C35A7A6F9BF10277B.aspx] busybox용 mount.c

'Linux' 카테고리의 다른 글

linux에 연결된 HDD의 IO 상태보기  (0) 2010.01.11
fork-exec 종료시 리턴값  (0) 2010.01.11
ntfs-3g 크로스 컴파일 하기 (ntfs-3g cross compile)  (0) 2010.01.07
FUSE 넌 머냐?  (0) 2010.01.07
ntfs-3g at Tuxera  (0) 2010.01.06
Posted by 구차니
Linux2008. 12. 26. 16:18
find 라는 명령어는 -exec 라는 옵션을 사용하여 파이프라인을 통해 검색된 결과를 넘겨 줄 수 있다.

윈도우/리눅스를 혼합하여 사용할 경우 의미 없이 용량만 늘리는 Thumbs.db 라는 넘을 삭제 하고 싶은데
일일이 찾아 지우기는 귀찮으니 조금 더 귀차니즘을 발휘하여 find에게 떠밀어 보자

 find [start path] -name Thumbs.db -exec rm {} \;

{} 는 검색된 결과가 넘어 가는 것이고
\; 는 명령어의 끝을 나타낸다. {}는 붙여 써야 하고(치환자)
\;역시 붙여 써야 하되, {} \;는 띄워서 써야 한다.


[참고 : http://kin.naver.com/detail/detail.php?d1id=1&dir_id=10202&eid=uOUzGMEfvG/Z2+VmcTxiS3R/sb6P15T+&qb=ZmluZCBleGVj&pid=fSfZswoi5URssbZwiR4sss--173216&sid=SVSD7S1zVEkAACzVjnk]
Posted by 구차니
Linux2008. 12. 8. 16:20

#include <unistd.h>

int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execle(const char *path, const char *arg,  ..., char * const envp[]);
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);


The  functions  execlp()  and execvp() will duplicate the actions of the shell in searching for an executable file if
the specified filename does not contain a slash (/) character.  The search path is the path specified in the environ-
ment  by the PATH variable.  If this variable isn’t specified, the default path ‘‘:/bin:/usr/bin’’ is used.  In addi-
tion, certain errors are treated specially.

[출처 : man page]

execl의 경우에는 path가 들어 가는데 arg에서 문제가 생긴다.




execl은 잠시 잊고 잠시 C언어로 돌아가서 main()의 프로토 타입을 생각해보자
 int void(int argc, char **argv)
그리고 argv[0] argv[1]의 내용을 떠올려 보자
argv[0]은 실행한 파일의 이름이 argv[1] 부터 인자가 넘어 오지 않았던가!




다시 execl로 돌아와서
int execl(const char *path, const char *arg, ...);
path에서는 파일 이름이 포함 된 경로를 적어주고, arg[0]에는 파일 이름 arg[1] 부터는 인자를 넘겨 주면 된다.


간단한 예를 들자면
 execl("/bin/ls","ls","-al",0);
로 실행을 하면된다.

마지막의 0은 '\0' == NULL 이다.


[참고 : http://kldp.org/node/1548]
Posted by 구차니