혹시 o_direct flag 써서 file open해보신 분 있으세요?

너부리의 이미지

o_direct flag로 파일을 열어야할 일이 생겨서 test를 하는데 잘 안되네요

혹시 해보셨던 분 있으면 도움 좀 주세요.

아래는 제가 작성한 코드.

#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <asm/page.h>
#define O_DIRECT 040000
#define Chunk (8192)
#define IntSize (4)

void main()
{
unsigned int fd;
int len;

char *buf;

buf = memalign(getpagesize(), getpagesize());

fd = open("xz.txt", O_RDWR|O_DIRECT);
printf("page size:%d\n", getpagesize());

if(fd<0){
printf("huk!, %ld\n",errno);
}
else{
printf("fd:%ld\n");

len = read( fd, buf, getpagesize());
if( len<0 ){
perror("read");
printf(" %d, %d\n", len, errno);
}
else{
printf("%s\n", buf);
}
}

close(fd);
}

또 아래는 위 프로그램의 결과입니다.
page size:4096
fd:134520832
read: Invalid argument <-- 즉, read가 제대로 안되고 있는거죠.
-1, 22

kernel 버젼은 2.2(redhat 6.2)에서 2.4.18로 업그레이드한거고요.

ext2 파일 시스템 사용 중입니다.

아.. 정말 에러 못 잡겠네요.

경험 있으신 분이 꼭 답좀 -.ㅠ

mach의 이미지

$ cat > xz.txt
test data
^D
$ ./test
page size:4096
fd:4096
test data

$_

------------------ P.S. --------------
지식은 오픈해서 검증받아야 산지식이된다고 동네 아저씨가 그러더라.

mach의 이미지

mach wrote:
$ cat > xz.txt
test data
^D
$ ./test
page size:4096
fd:4096
test data

$_


참고로, 위의 테스트는 질문하신분이 게시하신 소스를 그대로 사용하였습니다.
제 개발 환경은 레드햇9.0입니다.
특이 사항은 xz.txt 데이터 파일을 미리 생성해준것입니다.
아니면, O_CREAT 플래그를 추가해주던가 하면 돌기야 돌겠습니다.

위 프로그램에서 소개된 플래그 'O_DIRECT'는 전형적인 유닉스의 IO를 변경시킨 것이더군요.
유닉스의 block device의 IO는 반드시 커널내부의 buffer cache를 거쳐서
이뤄져야 하는데, 이를 버퍼캐시를 거치지 않고 직접 디스크와 같은
block device로 IO를 수행할 수 있는 옵션이더군요.
프로그래머가 커널 버퍼캐시의 장단점을 무시하고, 새로운 메카니즘을 구현할 수
있다는 장점도 있겠지만, 다수 서버등이 동작하는 환경에서는 전체적인
시스템의 performance에는 별로 좋을게 없어 보입니다.
특정 서버 프로그램만 수행하는 전용서버로써, 디스크등 블럭디바이스
입출력이 빈번한 응용을 위한, 버퍼캐시알고리즘보다 나은(?????) 대안을 만들어
볼수있다? 외에는요. 하여간 오픈시스템으로 가는 리눅스 멋지군요.
sun에도 이와 유사한 것이 있긴 한것 같던데요.

------------------ P.S. --------------
지식은 오픈해서 검증받아야 산지식이된다고 동네 아저씨가 그러더라.

서지훈의 이미지

이건 xz.txt file의 유뮤가 문제가 아닌것 같군요...
O_DIRECT falg를 open이 지원을 해주는냐의 문제가 아닌가 생각이 드네요...
xz.txt 존재 유무가 문제라면...
open에서 먼저 error가 나야 이론상 맞을 듯 하네요...-_-ㅋ

그리고 프비에선 man 2 open에 O_DIRECT 있지만...
Debian에선 아무런 언급도 없네요...
그리고 프비에선 잘 돌아가고...
Debian에선 같은 에러가...

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.