struct stat {
    dev_t         st_dev;      /* device */
    ino_t         st_ino;      /* inode */
    mode_t        st_mode;     /* protection */
    nlink_t       st_nlink;    /* number of hard links */
    uid_t         st_uid;      /* user ID of owner */
    gid_t         st_gid;      /* group ID of owner */
    dev_t         st_rdev;     /* device type (if inode device) */
    off_t         st_size;     /* total size, in bytes */
    blksize_t     st_blksize;  /* blocksize for filesystem I/O */
    blkcnt_t      st_blocks;   /* number of blocks allocated */
    time_t        st_atime;    /* time of last access */
    time_t        st_mtime;    /* time of last modification */
    time_t        st_ctime;    /* time of last change */
};




좋은 자료
http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/stat
http://www.opengroup.org/onlinepubs/000095399/functions/stat.html
http://linux.die.net/man/2/stat




<chmod>




http://opengroup.org/onlinepubs/007908775/xsh/sysstat.h.html


<utime>
st_atime, st_mtime, st_ctime 확인
http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/utime

<chown>
chown, fchown, lchown,

<truncate>
truncate
http://docs.hp.com/en/B9106-90009/truncate.2.html

'c or linux' 카테고리의 다른 글

chmod 예제  (0) 2010.10.19
Domain Socket 정리  (0) 2010.10.19
FILE 관련 API  (0) 2010.10.19
read/write/lseek example  (0) 2010.10.19
[리눅스] man (매뉴얼)  (0) 2010.10.18
Posted by '김용환'
,

FILE 관련 API

c or linux 2010. 10. 19. 13:15


<FILE structure>

typedef struct  {
       int             level;      /* fill/empty level of buffer */
       unsigned        flags;      /* File status flags          */
       char            fd;         /* File descriptor            */
       unsigned char   hold;       /* Ungetc char if no buffer   */
       int             bsize;      /* Buffer size                */
  unsigned char   *buffer;    /* Data transfer buffer       */
  unsigned char   *curp;      /* Current active pointer     */
       unsigned        istemp;     /* Temporary file indicator   */
       short           token;      /* Used for validity checking */
}       FILE;   


파일 관련

http://blog.paran.com/isdev8587/4876504

va_list
http://forum.falinux.com/zbxe/?document_srl=406096&mid=gcc
http://legendfinger.com/132

fopen, fdopen, freopen
http://man.kldp.net/wiki/ManPage/fopen.3
http://www.cworldlab.com/CandCplus/clibrary/freopen.htm
http://www.cworldlab.com/CandCplus/clibrary/fdopen.htm

fseek, rewind
http://beej.us/guide/bgc/output/html/multipage/fseek.html
http://www.google.co.kr/url?sa=t&source=web&cd=5&ved=0CEEQFjAE&url=http%3A%2F%2Fwww.eskimo.com%2F~scs%2Fcclass%2Fint%2Fsx2i.html&ei=eBq9TOWPB4rWvQPxq_BB&usg=AFQjCNHHDhCTfXu6KGrc7NKjaG1MuokIBQ

fileno
http://linux.die.net/man/3/fileno

fgetpos/fsetpos
http://itguru.tistory.com/70

clearerr
http://www.opengroup.org/onlinepubs/009695399/functions/clearerr.html

setbuf, setvbuf
http://www.cworldlab.com/CandCplus/clibrary/setbuf.htm
http://www.cworldlab.com/CandCplus/clibrary/setvbuf.htm

fflush
http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/3/fflush

unlink
http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/unlink

unix system call
http://www.softpanorama.org/Internals/unix_system_calls.shtml

--System calls for low level file I/O
creat(name, permissions)
open(name, mode)
close(fd)
unlink(fd)
read(fd, buffer, n_to_read)
write(fd, buffer, n_to_write)
lseek(fd, offest, whence)
--System Calls for process control
fork()
wait()
execl(), execlp(), execv(), execvp()
exit()
signal(sig, handler)
kill(sig, pid)
--System Calls for IPC
pipe(fildes)
dup(fd)


파일 사용 util
http://ttongfly.net/zbxe/?document_srl=45219&mid=linuxprogramming

'c or linux' 카테고리의 다른 글

Domain Socket 정리  (0) 2010.10.19
stat 파일 상태 확인  (0) 2010.10.19
read/write/lseek example  (0) 2010.10.19
[리눅스] man (매뉴얼)  (0) 2010.10.18
Vxworks 분위기  (0) 2010.10.18
Posted by '김용환'
,

read/write/lseek example

c or linux 2010. 10. 19. 11:48

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>

#define NSTRING 5
#define STRSIZE 3

char *string[] = { "aaa", "bbb", "ccc", "ddd", "eee" };

int main(int argc, char **argv) {
    int n, fd;
    char *fname;
    char buf[STRSIZE], answer[8], template[32];
    strcpy(template, "/tmp/seekerXXXXXX");
    fname = mktemp(template);

    fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666);

   printf ("debug) file name is %s\n", fname);

    for (n = 0 ; n < NSTRING ; n++) {
        write(fd, string[n], STRSIZE);
    }

    for ( ; ; ) {
        write(1, "which string ? ", 15);
        n = read(0, answer, sizeof(answer));
        answer[n-1] = '\0';
        n = atoi(answer);

        printf ("debug) n is %d\n", n);
        printf ("debug) fd is %d\n", fd);
        if (n == 0) {
            close(fd);
            return -1;
        }


        if (n < 0 || n > NSTRING) {
            write (2, "out of range\n", 13);
            continue;
        }

        lseek (fd, (n-1) *STRSIZE, SEEK_SET);
        read (fd, buf, STRSIZE);
        write(1, "String", 7);
        write(1, answer, strlen(answer));
        write(1, " = ", 3);
        write(1, buf, STRSIZE);
        write(1, "\n\n", 2);
    }
    return 0;
}


 read/write/lseek system call을 사용한 예제이다. 

fd의 0은 stdin, 1은 stdout, 2는 stderr를 의미. 예약된 번호이다.

'c or linux' 카테고리의 다른 글

stat 파일 상태 확인  (0) 2010.10.19
FILE 관련 API  (0) 2010.10.19
[리눅스] man (매뉴얼)  (0) 2010.10.18
Vxworks 분위기  (0) 2010.10.18
[리눅스] ar, ranlib, ldd, nm, make  (0) 2010.10.18
Posted by '김용환'
,



manual section 주제
$man <section number> <term>


1 : User commands
    http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/1   
2 : System calls (psix 포함)
    http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/Assembly/Documents/article_linux_systemcall_quick_reference
    http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/syscall
3 : Library functions
    http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/3
4 : Special files
5 : File formats
6 : Games
7 : conventions/misc.
8 : Admin and provileged commands


힌트 얻은 곳 
http://yesyo.com/mintbbs/bbs/board.php?bo_table=linux&wr_id=60&page=14


 

'c or linux' 카테고리의 다른 글

FILE 관련 API  (0) 2010.10.19
read/write/lseek example  (0) 2010.10.19
Vxworks 분위기  (0) 2010.10.18
[리눅스] ar, ranlib, ldd, nm, make  (0) 2010.10.18
rz/sz 사용하기 (lrzsz 사용)  (0) 2010.07.09
Posted by '김용환'
,

Vxworks 분위기

c or linux 2010. 10. 18. 16:39

* vxworks ibm 인수
http://cusee.net/2462023
http://en.wikipedia.org/wiki/VxWorks

요즘 기업에서 vxworks에서 support가 적어서.. embedded linux로 갈 모양인듯..
Posted by '김용환'
,


[개발유틸]

[binutils] 정적 라이브러리의 구조 - ar, ranlib
http://studyfoss.egloos.com/5049029

ar, ranlib 이해
http://wiki.kldp.org/KoreanDoc/html/GNU-Make/GNU-Make-7.html

ar, ranlib, nm
http://progh2.tistory.com/220

ldd 명령어
http://netset.tistory.com/tag/ldd
http://www.ceokj.com/entry/ldd-%EB%AA%85%EB%A0%B9%EC%96%B4

make 명령어
http://www.nicklib.com/library/make/Make-2.html
http://wiki.kldp.org/KoreanDoc/html/GNU-Make/GNU-Make-4.html
http://lily.mmu.ac.kr/lecture/08sm/Fedora2/8jang/4.htm
http://lhjgg.com.ne.kr/doc/makefile.ppt
http://www.google.co.kr/url?sa=t&source=web&cd=8&ved=0CEAQFjAH&url=http%3A%2F%2Flhjgg.com.ne.kr%2Fdoc%2Fmakefile.ppt&ei=GOi7TIjYM4eOvQO_pdCwDQ&usg=AFQjCNGKwXOY_-UQvtqqqesWJfV4k9pLnQ



[디버그]
gdb 대안으로 ddd를 사용 (UI)
http://www.gnu.org/software/ddd/

Remote Debugging
JTAG 원리 - http://defree.co.kr/blog/wp-content/uploads/2009/06/jtagec9d98_ec868ceab09c_ebb08f_ec9b90eba6ac.pdf
JATG - http://ko.wikipedia.org/wiki/JTAG
JTAG 상용 제품  - t32,  ice32

[POST]  power on self test
http://flashcafe.org/?mid=server_study&document_srl=12275&page=6

[Tree]
tree 명령어 tree, tree -d
http://apollo89.com/blog/322
구현 원리
http://www.centerkey.com/tree/

[stat]
% touch t1
% stat t1
  File: `t1'
  Size: 0               Blocks: 0          IO Block: 131072 regular empty file
Device: 811h/2065d      Inode: 397683      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1001/ drl)   Gid: ( 1001/ drl)
Access: 2007-05-26 08:39:21.000000000 -0500
Modify: 2007-05-26 08:39:21.000000000 -0500
Change: 2007-05-26 08:39:21.000000000 -0500

unix inode structure
http://www.tux4u.nl/freedocs/unix/draw/inode.pdf

 

Posted by '김용환'
,

wget http://www.ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
tar -zxvf lrzsz-0.12.20.tar.gz
cd lrzsz-0.12.20
./configure --prefix=/usr
make
make install
Posted by '김용환'
,


How to make empty file in linux

저희 Redhat Enterprise Edition 5를 기준으로 볼때,

cp /dev/null {filename}, cat /dev/null > {filename} 의 성능을 보면, cat 쪽이 훨씬 더 빠릅니다. (Strace로 확인)

Cat 의 경우는 Library도 얼마 안쓰고 file open /dev//null 밖에 안하고 바로 stream으로 쏴버리네요.. cpcat보다 수많은 library를 읽고, file이 없으면 create도 하고 하는 open 작업이 하는 등 system call이 상대적이 많습니다. Redirect sign(output)을 사용하는 것이 엄청 빠르게 동작될 수 있다는 것을 알게 되었습니다.

 

cat /dev/null > {filename}

fstat64(1, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0

open("/dev/null", O_RDONLY|O_LARGEFILE) = 3

fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0

read(3, "", 4096)                       = 0

close(3)                                = 0

close(1)                                = 0

exit_group(0)                           = ?

 

cp /dev/null {filename},

geteuid32()                             = 1726

stat64("kkk111.txt", 0xbf8537bc)        = -1 ENOENT (No such file or directory)

stat64("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0

stat64("kkk111.txt", 0xbf853668)        = -1 ENOENT (No such file or directory)

open("/dev/null", O_RDONLY|O_LARGEFILE) = 3

fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0

open("kkk111.txt", O_WRONLY|O_CREAT|O_LARGEFILE, 020666) = 4

fstat64(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0

fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0

read(3, "", 4096)                       = 0

close(4)                                = 0

close(3)                                = 0

close(1)                                = 0

exit_group(0)                           = ?

 

 

그리고, linux에서 file creation할 수 있는 방법을 적어볼께요~

1.     Cat /dev/null > aa.txt

2.     Cp /dev/null aa.txt

3.     touch aa.txt

4.     /bin/bash 에서의 empty file creation (/bin/bash만 됩니다.)

[gw01:/home1/knight] /bin/bash

id: cannot find name for group ID 1728

[knight@gw01 ~]$ > aaa.txt

[knight@gw01 ~]$ ls -al aaa.txt

-rw-r--r-- 1 knight 1728 0  5 27 10:57 aaa.txt

[knight@gw01 ~]$

5.     dd if=/dev/zero of=foo count=0 of=xx.txt

[gw01:/home1/knight] dd if=/dev/zero of=foo count=0 of=xx.txt

0+0 records in

0+0 records out

0 bytes (0 B) copied, 8.819e-06 seconds, 0.0 kB/s

[gw01:/home1/knight] cat xx.txt

[gw01:/home1/knight] ls -al xx.txt

-rw-r--r-- 1 knight 1728 0  5 27 11:00 xx.txt

6.     head -0 > aa.txt

[gw01:/home1/knight] head -0 > x1x1.txt

[gw01:/home1/knight] ls -al x1x1.txt

-rw-r--r-- 1 knight 1728 0  5 27 11:01 x1x1.txt

7.     true > x2x2.txt

[gw01:/home1/knight] true > x2x2.txt

 [gw01:/home1/knight] ls -al x2x2.txt

-rw-r--r-- 1 knight 1728 0  5 27 11:02 x2x2.txt

8.     false > x3x3.txt

[gw01:/home1/knight] false > x3x3.txt

[gw01:/home1/knight] ls -al x3x3.txt

-rw-r--r-- 1 knight 1728 0  5 27 11:03 x3x3.txt

9.     sed –e “” < filename

[gw01:/home1/knight] sed -e "" < filename

 [gw01:/home1/knight] ls -al filename

-rw-r--r-- 1 knight 1728 0  5 27 11:04 filename

 

'c or linux' 카테고리의 다른 글

[리눅스] ar, ranlib, ldd, nm, make  (0) 2010.10.18
rz/sz 사용하기 (lrzsz 사용)  (0) 2010.07.09
Open files 수 늘이기  (0) 2010.03.23
Sendfile 이해도 높이기  (0) 2010.02.08
KQueue, Epoll  (0) 2010.02.08
Posted by '김용환'
,

ulimit -a
open files                      (-n) 1024
=>
open files                      (-n) 16000
open files 수를 늘리고 싶다.




/etc/security/limits.conf 파일 추가
soft nofile 16000
hard nofile 16000

/etc/profile.d/krb5.sh 또는 /etc/profile 추가
ulimit -HSn 16000


Posted by '김용환'
,

Zero-Copy TCP in Solaris
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.3960

ZeroCopy: Techniques, Benefits and Pitfalls
http://kbs.cs.tu-berlin.de/teaching/ws2005/htos/folien/streams-zcpy.pdf

Zero-Copy TCP in Solaris 독후감
http://namhw.springnote.com/pages/956222?print=1

아파치 sendfile 설정 (테스트를 했는데 10% 성능효과가 있었다고 함)
http://httpd.apache.org/docs/2.3/ko/mod/core.html#enablesendfile

TODO 다음 공부
TCP Segment Offloading



Posted by '김용환'
,