본문 바로가기

File

find and grep on linux shell Sometimes, we want to perform 'grep' command among results of 'find' command.I'll introduce how can we do this easier. The way is very simple - magic keyword is "--include=" Example, below command find "PAGE" word among the files what has ".dts" string in file name. grep -snra --include="*.dts*" "PAGE" 더보기
JAVA 입출력 출처 : JAVA programming참고하면 좋은 곳 : https://m.blog.naver.com/PostView.nhn?blogId=slrkanjsepdi&logNo=90140711064&proxyReferer=https%3A%2F%2Fwww.google.co.kr%2F@ . 1byte 입/출력 자바에서 처리하는 입력과 출력은 스트림(Stream)에 의존다시말해 모든 형태의 입력과 출력은 1byte의 흐름으로 이루어져 있다는것 *. 많이쓰이는 형식 @ . 1byte 출력 1. 콘솔 출력용 FileOutputStream fos = new FileOutputStream(FileDescriptor.out); BufferedOutputStream bos = new BufferedOutputStream(f.. 더보기
SetUID / SetGID Special File Permissions 출처 : http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=10302&docId=128463841&page=1#answer1안녕하세요.. 답변이 될지 모르겠으나 Set UID / Set GID에 대해 설명드리겠습니다. Set UID는 chmod 4000 권한으로 실행되며, Set GID는 chmod 2000 권한으로 실행합니다.둘다 설정하시려면 6000 권한으로 설정 하시면 됩니다.( 여기서 000은 일반 퍼미션 이며, 파일 실행권한은 꼭 가지고 있어야 합니다. ) 파일 퍼미션 설정이 기본적으로 rwx/rwx/rwx 로 이런 식으로 설정이 되나,Set UID설정 시 rws/rwx/rwx로 변경.Set GID설정 시 rwx/rws/rwx로 변경.둘다 설정 시 rws/r.. 더보기
파일의 속성을 check 하는 코드 - fstatat, fstat, stat, lstat 아래는 dirfd 아래에 asecName 이라는 파일이 regular file인지 check 하는 코드 ex) dirfd = "/mnt/secure/asec/" asecName = "1234" 이면 /mnt/secure/asec/1234 라는 regular file 이 있는지 check 해 준다. struct stat sb; bool ret = (fstatat(dirfd, asecName, &sb, AT_SYMLINK_NOFOLLOW) == 0) && S_ISREG(sb.st_mode); http://www.tutorialspoint.com/unix_system_calls/stat.htm The following POSIX macros are defined to check the file type usi.. 더보기
file open 시 fd 번호 부여 방식 하나의 process 에서 한 파일을 연속으로 open 할때 fd number 부여 방식 - 이전에 3 이라는 fd 숫자를 써서 open 하고 close 를 함.- 다음 open 때는 fd 로 3이 부여 된다.- 따라서 file close 이후에는 항상 fd 에 -1 을 저장하는 것이 중요함. test code#include //#include #include #include #include #include #include #include // O_WRONLY#include // strlen() #define BUFF_SIZE 1024 int main(){ char buff_r[BUFF_SIZE], buff_w[BUFF_SIZE]; int fd[10];int rst;int fd_num; for(int i.. 더보기
stdout 출력을 file 로 돌리기 static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; intmain(int argc, char **argv) { time_t start = time(NULL); redirect_stdio(TEMPORARY_LOG_FILE); 더보기
linux stand out 을 file 에 logging 하기 static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; redirect_stdio(TEMPORARY_LOG_FILE); static void redirect_stdio(const char* filename) { // If these fail, there's not really anywhere to complain... freopen(filename, "a", stdout); setbuf(stdout, NULL); freopen(filename, "a", stderr); setbuf(stderr, NULL);} 더보기
ubuntu / windows PC 와 android phone 간 file explorer 파일 관리 - QtADB Ubuntu / windows PC 와 Android 간에 adb interface 를 이용해서 파일을 탐색기 형태로 자유롭게 전송하는 프로그램이다.개발 및 test 에 아주 용이하다. 다운로드 경로https://qtadb.wordpress.com/download/ 아래 apk file 을 Android Phone 에 설치한 후 실행한다.이후 start service 버튼을 눌러준다.아래 프로그램을 Ubuntu 에서 실행 한후, 첫 화면에서 adb 가 설치되어 있는 path 의 경로를 지정해 준다. 이후 아래와 같이 창이 뜨면서 file 을 주고 받을 수 있다. 더보기
wrtie 비교 O_DIRECT and no-delay-alloc mount option - O_DIRCET optionopen 함수에 주는 flag - no-delay-alloc optionfile system mount option : file write 를 보통 지연시켜서 하는데 이기능을 사용하지 않음. umount /cache 일반적인 mount 명령어mount -t ext4 /dev/block/mmcblk0p27 /cache no delay alloc mount 명령어mount -t ext4 -o nodelalloc /dev/block/mmcblk0p27 /cache test source code 하기 파일에서 O_DIRECT 주석을 풀어주면 O_DIRECT 로 동작함.간단히 input file 을 open 하여 내용을 읽고 output 파일에 write 하는 예제임. 결과를 mos.. 더보기
[linux][platform] O_DIRECT file open, read, write example O_DIRECT flag 를 사용한 file open, read, write 예제 입니다. page size 4096 예 맞추어서 read / write 를 해야 합니다. 더보기
File System의 개요 원문 : http://cafe.naver.com/ghson/164 파일시스템을 이해하는데 기초 자료로서 너무나 설명이 잘 되어 있다.자료 보존 차원에서 옮겨 왔다. 파일시스템은 '6.device file의 개요'에서 설명한 바와 같이 섹터로 나누어진 물리적인 디스크를 운영체제가 사용하기 좋게 블럭단위로 나누어 각 블럭에 주소를 부여함으로써 운영체제가 디스크를 관리할 수 있게끔 디스크에 지도를 그리는 작업이라 할 수 있다. 1. 파일시스템의 구조 파일시스템은 루트디스크를 시작으로 디렉토리 트리나 계층구조로 이루어지며, 각 파일시스템은 물리적으로 같은 디스크에 존재할 수도 있고 다른 디스크에 따로 존재할 수 있다. 또한 각 파일시스템안에는 크게 User Data와 Meta Data로 구분되는 구조로 관리되며.. 더보기
linux kernel 에서 사용 할 수 있는 file io functions 원칙적으로, linux kernel layer 에서는 file io 를 다루면 안된다. 여러 이유가 있겠지만, 일단 file descriptor list 를 각 task descriptor 에서 관리하고 있고, file을 linux kernel 단에서 접근하게 되면, 어느 process 에서 지금 kernel code 를 실행하는지 일일이 확인해야 하기 때문이다. 또한, 각 process 가 가진 access(read / write) 권한 문제도 발생하게 된다. 하지만, 이를 모두 감수하고라도, 꼭 써야만 하겠다면 다음 함수를 사용하면 된다. 여기에는 간단하게 동작하는 file operation 을 제공한다. open close size read write 더보기
virtual file system diagram 안녕하세요. 오늘은 말도많고 복잡하기로도 유명한 linux 의 virtual file system 을 보겠습니다. virtual 은 각 file system layer 에의 상위에 위치하며 공통의 interface 를 user 단에 재공하여, user 단에서 사용하고 있는 file system 에 상관없이 구현을 하도록 돕는 역할을 하고 있습니다. =========================================================== ------------------------------- virtual file system ------------------------------- file system (UBI, ext4, nf.. 더보기
register_mtd_user() - partition에 융통성 있는 driver 구현하기 안녕하세요. linux device 를 작성하면서 간혹 특정 mtd partition 에 의존하는 코드를 구현할 필요가 있습니다. 이때 해당 partition num 를 hard coding 한다면, partition table 이 변경될때마다 쫒아다니면서 일일이 수정해야 겠지요. 하지만 지금 소개시켜 드리는 함수를 잘 이용하시면, 시스템 초기화시는 물론 시스템 운용중에 변경되는 partition 에 대해서도 유동적으로 대처할 수 있는 융통성 있는 device 를 구현할 수 있습니다. 일단 man page 정보를 먼저 봅시다. NAMEregister_mtd_user - register a 'user' of MTD devices. SYNOPSIS"SYNOPSIS" void register_mtd_user .. 더보기
flush_dcache_page와 kmap_atomic 원문 : http://barriosstory.blogspot.com/2009/01/flushdcachepage-kmapatomic.html 굉장히 소중한 자료이다. 더불어 글을 쓰는 스타일도 너무나 마음에 든다. 좋은 자료를 공유해준 분께 다시한번 감사 드립니다. 왜 file system code들 중 kmap_atomic과 flush_dcache_page가 있을까? 아는 분의 도움으로 이 문제에 대해서 생각해 볼 기회가 생겼다. 먼저, flush_dcache_page 함수의 용도를 먼저 알아야 한다. David Miller가 작성한 문서에는 다음과 같이 되어 있다. void flush_dcache_page(struct page *page) Any time the kernel writes to a pag.. 더보기
Linux Network proxy setting 방법 Ubuntu 환경에서는 windows 와 다르게 proxy setting 을 여러곳에 각각 해 주어야 하는 번거로움이 있다.크게 3가지 인데 아래에 정리해본다 참고 : http://xmodulo.com/how-to-set-up-proxy-auto-config-on-ubuntu-desktop.html 그래픽 UI 의 setting menu 에서 아래와 같이 설정한다. you have created this PAC file, go to "System Settings" -> "Network" -> "Proxy Settings", and choose "Automatic" method in network proxy. Then type "file://.. 더보기
linux kernel 에서 file 유무 확인하기 여러 방법이 있겠지만, 다음 방법을 사용하였다. int check_exist_file(char* file_path) { int ret = 0; struct file *temp_file; temp_file = filp_open(file_path, O_RDONLY, 0); if (IS_ERR(temp_file)) ret = -1; else { filp_close(temp_file, NULL); ret = 0; } return ret; } 더보기
커널에서 파일 오퍼레이션 하기(File operation in Kernel) 원문 : http://blog.naver.com/netohk?Redirect=Log&logNo=80045492480 커널에서 파일 오퍼레이션 하기... (드라이버에서 펌웨어 로딩시 유용) #include #ifndef __KERNEL_SYSCALLS__ #define __KERNEL_SYSCALLS__ #endif #incude //#include function() { int fp; mm_segment_t fs; fs = get_fs(); set_fs(KERNEL_DS); open("file", O_RDONLY, 0); size = lseek(fd, 0, 2); //END lseek(fd, 0, 0); //START read(..); close(fp); set_fs(fs); } [출처] 커널에서 파일 .. 더보기