[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[FDclone-users:00666] Re: Linux 2.6.18 で dosdisk.c コンパイルエラー (_syscall5 マクロ)



濱崎です。

>>  _FILE_OFFSET_BITS が「定義されていること」と「有効であるこ
>> と」とは別の話です。

なるほど。

>>  別解としては man page にあるという syscall(2) を使うという
>> 手なんでしょうが、その記述ではどういう手順で使うことになって
>> いますか?

man llseek(2) の中に

    _syscall5(int, _llseek, unsigned int, fd, unsigned long, hi,
       unsigned long, lo, loff_t *, res, unsigned int, wh)
      /* Using syscall(2) may be preferable; see intro(2) */

とあり、 syscall(2) では

  書式
     #include <sys/syscall.h>
     #include <unistd.h>
     int syscall(int number, ...)

  説明
     syscall() は number で指定されたアセンブリ言語インターフェースのシステム
     コールを、指定された引き数をつけて実行する。システムコールのシンボル定数
     はヘッダファイル <sys/syscall.h> に書かれている。

とありましたので、#include を辿って
<sys/syscall.h>  →  <asm/unistd.h>  →  <asm-i486/unistd.h>
の順に見ていくと

#define __NR__llseek        140

がありました。syscall の引数の先頭に __NR__llseek を渡せばいいようです。

_syscall5の定義が __KERNEL__ に囲まれているかどうかに応じて使い分けるとすると、
以下のようになると思います。
__KERNEL__を定義するのに比べると、少し煩わしいですね。

-*-*- -*-*- -*-*- -*-*- -*-*- -*-*- ここから
#include <unistd.h>
#include <linux/unistd.h>
#include <linux/types.h>
#include <stdio.h>

typedef long long   l_off_t;

#ifdef _syscall5
    static _syscall5(int, _llseek,
        u_int, fd,
        u_long, ofs_h,
        u_long, ofs_l,
        l_off_t *, result,
        u_int, whence);
#else
#endif

int main() {
    u_int  fd;
    u_long ofs_h;
    u_long ofs_l;
    l_off_t * result;
    u_int whence;

#ifdef _syscall5
    printf ("syscall5 is defined");
    _llseek(fd, ofs_h, ofs_l, result, whence);
#else

    printf ("syscall5 is NOT defined");
    syscall(__NR__llseek, fd, ofs_h, ofs_l, result, whence);
#endif
}
-*-*- -*-*- -*-*- -*-*- -*-*- -*-*- ここまで

--------------------------------------------------
    濱崎 健 E-mail: hma@syd.odn.ne.jp