PRIMECLUSTER Global File Services 説明書 4.1 (Linux版)
目次 索引 前ページ次ページ

付録D バージョンごとの非互換> D.1 4.1A40 と 4.1A30 の非互換項目

D.1.1 sendfile(2) のサポート中止

■非互換内容

sendfile(2) を GFS 共用ファイルシステムに対して発行した場合の動作を変更しました。

移行前:正常終了
移行後:異常終了(復帰値:-1、errno:EINVAL)

■対処方法

 sendfile(2) を使用している箇所は、read 処理(*1)と write 処理(*2)を組み合わせることで代替可能です。

 *1: read(2), readv(2), pread(2)

 *2: write(2), writev(2), pwrite(2)

 具体的な例を以下に示します。

 なお、以下に示すプログラムは、あるファイルの先頭から最後までの内容を、512バイトの転送サイズで、他のファイルに複写するプログラムです。

<修正前>

#include <sys/sendfile.h>
    :
int
func(void)
{
        int out_fd = 0, in_fd = 0;
        off_t offset = 0;
            :
        while (1) {
                ssize_t write_size;

                write_size = sendfile(out_fd, in_fd, &offset, 512);
                if (write_size == -1) {
                            :
                        return -1;
                }
                if (write_size == 0) {
                        break;
                }
        }
           :
        return 0;
}

<修正後>

#include <unistd.h>
    :
int
func(void)
{
        int out_fd = 0, in_fd = 0;
        char buf[512];
            :
        while (1) {
                ssize_t read_size, write_size;

                read_size = read(in_fd, buf, 512);
                if (read_size == -1) {
                            :
                        return -1;
                }
                if (read_size == 0) {
                        break;
                }

                write_size = write(out_fd, buf, read_size);
                if (write_size == -1) {
                            :
                        return -1;
                }
        }
            :
        return 0;
}

目次 索引 前ページ次ページ

All Rights Reserved, Copyright(C) 富士通株式会社 2006