Re: [問題] 關於sys call-open() read() write()..

看板LinuxDev作者 ( )時間17年前 (2006/11/17 15:07), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《mayasky ( )》之銘言: : ※ 引述《mayasky ( )》之銘言: : : 標題: [問題] 關於sys call-open() read() write().. : : 時間: Thu Nov 16 00:26:04 2006 : : 由於我需要低階直接存取功能,我不使用C的LIB去做檔案操作 : : 我直接用open與read.write : : 但始終有Illegal seek : : 但是檔案又寫的進去讀得出來(在不同程式) : : -- : : ◆ From: 140.114.71.192 : : → qrtt1:有沒有範例能看 :P 11/16 11:06 : 殘念,由於安全問題,新的KERNEL都不准open配上O_DIRECT了, 抱歉各位,以上那句話需要修正,是可以用的,只是要多加點東西 CODE在試驗中東改西改,有點亂請包涵 =====================read================================ #include <stdio.h>; #include <sys/types.h>; #include <sys/stat.h>; #include <asm/fcntl.h>; #include <unistd.h>; #define _XOPEN_SOURCE 600 #include <stdlib.h>; //int posix_memalign(void **memptr, size_t alignment, size_t size); // #include <fcntl.h> typedef struct _pp { char name[10]; int high; }pp; main() { int fd; int i, r; pp *bp; r = posix_memalign(&bp, 512, sizeof(pp)); //要設定這個才可用O_DIRECT,但我不是很明確知道用法 printf("r = %d\n", r); fd = open("/raid/data", O_CREAT | O_RDWR | O_DIRECT, 0644); //posix_fadvise(fd,0,0,1); printf("fd = %d\n", fd); r = read(fd, bp, 512); printf("name: %s high: %d\n",bp->name,bp->high); close(fd); } ===============================write=========================== 暫時找不到是哪個檔了..眼花XD~稍晚補上 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.71.192

04/12 14:49, , 1F
這個範例 好像沒有 free()
04/12 14:49, 1F
文章代碼(AID): #15NL-wpL (LinuxDev)
文章代碼(AID): #15NL-wpL (LinuxDev)