Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

[インデックス 18330] ファイルの概要

このコミットは、Go言語のapi/next.txtファイルを更新し、syscallパッケージに新たなAPI要素を追加するものです。具体的には、LinuxにおけるFlock_t構造体、Unix系システムにおけるFcntlFlock関数、そして様々なBSD系システムにおけるTermios関連の定義が追加されています。これは、Goプログラムがこれらの低レベルなシステムコールをより直接的に利用できるようにするための変更です。

コミット

commit 951c84c41b8a83a4bdee09af3321199e09b5c71f
Author: Brad Fitzpatrick <bradfitz@golang.org>
Date:   Wed Jan 22 10:54:51 2014 -0800

    api: update next.txt
    
    Linux Flock_t, Unix FcntlFlock, and various BSD Termios.
    
    R=golang-codereviews, dsymonds
    CC=golang-codereviews
    https://golang.org/cl/55460043

GitHub上でのコミットページへのリンク

https://github.com/golang/go/commit/951c84c41b8a83a4bdee09af3321199e09b5c71f

元コミット内容

api: update next.txt Linux Flock_t, Unix FcntlFlock, and various BSD Termios.

変更の背景

Go言語の標準ライブラリ、特にsyscallパッケージは、Goプログラムが基盤となるオペレーティングシステム(OS)の機能にアクセスするための重要なインターフェースを提供します。このコミットの背景には、Goプログラムがファイルロック(Flock_t, FcntlFlock)やターミナルI/O制御(Termios)といった、より低レベルでOSに依存する機能を利用できるようにする必要があったことが挙げられます。

api/next.txtファイルは、Goの次期リリースで公開される予定のAPI変更を記録するためのものです。このファイルにエントリが追加されるということは、これらの機能がGoの公式APIとして提供され、開発者が利用できるようになることを意味します。これにより、Goプログラムは、特定のOS機能に特化したより高度な操作を実行できるようになり、例えば、データベースファイルへの排他的アクセス制御や、シリアルポート通信の細かな設定などが可能になります。

前提知識の解説

このコミットを理解するためには、以下の概念についての知識が役立ちます。

  • システムコール (System Call): オペレーティングシステムが提供するサービスをプログラムが利用するためのインターフェースです。ファイル操作、プロセス管理、ネットワーク通信など、OSの核となる機能にアクセスするために使用されます。Go言語ではsyscallパッケージを通じてこれらの機能にアクセスします。
  • fcntl (File Control): Unix系システムにおけるファイル記述子を操作するためのシステムコールです。ファイルロック、ファイルの状態フラグの取得/設定、ファイル記述子の複製など、多岐にわたる機能を提供します。
  • ファイルロック (File Locking): 複数のプロセスが同時に同じファイルにアクセスする際に、データの整合性を保つために使用されるメカニズムです。flockfcntlシステムコールを通じて実現されます。
    • flock: ファイル全体に対するアドバイザリロック(協調ロック)を提供します。ロックの種類には共有ロック(LOCK_SH)と排他ロック(LOCK_EX)があります。
    • fcntlロック: ファイルの特定範囲に対するロック(レコードロック)をサポートし、強制ロック(mandatory locking)も可能です。より粒度の細かい制御が可能です。
  • Flock_t構造体: fcntlシステムコールでファイルロックを操作する際に使用される構造体です。ロックの種類(共有、排他、アンロック)、ロックの開始オフセット、長さ、プロセスIDなどの情報を含みます。OSによって構造体の定義が異なる場合があります。
  • Termios構造体: Unix系システムでターミナル(シリアルポートやコンソール)のI/O設定を制御するための構造体です。ボーレート、パリティ、フロー制御、エコー、カノニカルモードなどの設定が含まれます。tcgetattrtcsetattrといった関数を通じてこの構造体を操作します。
  • クロスプラットフォーム開発: Go言語はクロスプラットフォームを強く意識して設計されていますが、低レベルなシステムコールはOSによって大きく異なります。syscallパッケージは、これらのOS固有の差異を吸収しつつ、各プラットフォームのネイティブ機能へのアクセスを提供します。このコミットのように、特定のOS(Linux, Darwin, FreeBSD, NetBSD, OpenBSDなど)向けのAPIが追加されるのは、そのOSでしか利用できない、あるいはそのOSで特に重要な機能への対応を強化するためです。
  • api/next.txt: Goプロジェクトにおいて、次期リリースで追加される予定の公開APIを記録するファイルです。このファイルに記載されたAPIは、Goの互換性ガイドラインに従い、将来のバージョンでも維持されることが期待されます。

技術的詳細

このコミットは、Goのsyscallパッケージが提供するOS固有の機能セットを拡張しています。

  1. Flock_t構造体とFcntlFlock関数の追加:

    • FcntlFlockは、Unix系システムにおけるfcntl(fd, cmd, &flock_t)システムコールに対応するGoの関数です。これにより、Goプログラムからファイルのセグメントロック(レコードロック)をかけることが可能になります。これは、複数のプロセスが同じファイルの一部を同時に読み書きする際に、競合状態を防ぐために非常に重要です。
    • Flock_t構造体は、ロックの種類(読み取りロック、書き込みロック、アンロック)、ロックをかけるファイルのオフセット、ロックの長さ、そしてロックを保持しているプロセスのIDなどの情報を含みます。この構造体は、OSやアーキテクチャ(例: linux-amd64, linux-386)によって内部的なパディングやフィールドの順序が異なる場合があるため、Goのsyscallパッケージではそれぞれの環境に合わせて正確な定義を提供する必要があります。コミット内容を見ると、Pad_cgo_0Pad_cgo_1といったフィールドが追加されており、これはCgoを介してOSの構造体とGoの構造体を正確にマッピングするために必要なパディングを示しています。
    • この機能は、特にデータベースシステムや、複数のアプリケーションが共有ファイルにアクセスするような環境で、データの整合性を保証するために不可欠です。
  2. BSD系システムにおけるTermios関連の追加:

    • Termios構造体は、Unix系OSにおけるターミナルデバイスの属性を制御するために使用されます。これには、入力モード、出力モード、制御モード、ローカルモード、特殊文字の設定などが含まれます。
    • このコミットでは、freebsd, netbsd, openbsdの各アーキテクチャ(386, amd64, armなど)に対して、Termios構造体の定義とそのフィールド(Cc, Cflag, Iflag, Ispeed, Lflag, Oflag, Ospeedなど)が追加されています。
    • これにより、Goプログラムは、シリアルポート通信を行うアプリケーションや、カスタムシェル、ターミナルエミュレータなどを開発する際に、より細かくターミナルの挙動を制御できるようになります。例えば、エコーの無効化、カノニカルモードの切り替え、ボーレートの設定などが可能になります。
  3. Cgoの考慮:

    • コミット内容には、darwin-386-cgo, linux-amd64-cgoのように-cgoが付加されたエントリが多数見られます。これは、Cgo(GoとC言語の相互運用機能)を使用する場合のAPI定義を示しています。Cgoを使用する場合、Goの構造体とCの構造体間でメモリレイアウトの互換性を保つことが重要であり、OS固有の構造体定義に合わせたパディングなどが考慮されています。

これらの追加により、Goはより幅広いシステムプログラミングのユースケースに対応できるようになり、特にOSの低レベルな機能に直接アクセスする必要があるアプリケーションの開発が容易になります。

コアとなるコードの変更箇所

このコミットは、api/next.txtファイルのみを変更しています。このファイルは、Goの次期リリースで公開される予定のAPIのリストを定義するものです。

--- a/api/next.txt
+++ b/api/next.txt
@@ -117,6 +117,11 @@ pkg sync, method (*Pool) Get() interface{}
 pkg sync, method (*Pool) Put(interface{})
 pkg sync, type Pool struct
 pkg sync, type Pool struct, New func() interface{}
+pkg syscall (darwin-386), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (darwin-386-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (darwin-amd64), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (darwin-amd64-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (freebsd-386), func FcntlFlock(uintptr, int, *Flock_t) error
 pkg syscall (freebsd-386), type Termios struct
 pkg syscall (freebsd-386), type Termios struct, Cc [20]uint8
 pkg syscall (freebsd-386), type Termios struct, Cflag uint32
@@ -125,6 +130,7 @@ pkg syscall (freebsd-386), type Termios struct, Ispeed uint32
 pkg syscall (freebsd-386), type Termios struct, Lflag uint32
 pkg syscall (freebsd-386), type Termios struct, Oflag uint32
 pkg syscall (freebsd-386), type Termios struct, Ospeed uint32
+pkg syscall (freebsd-386-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
 pkg syscall (freebsd-386-cgo), type Termios struct
 pkg syscall (freebsd-386-cgo), type Termios struct, Cc [20]uint8
 pkg syscall (freebsd-386-cgo), type Termios struct, Cflag uint32
@@ -133,6 +139,7 @@ pkg syscall (freebsd-386-cgo), type Termios struct, Ispeed uint32
 pkg syscall (freebsd-386-cgo), type Termios struct, Lflag uint32
 pkg syscall (freebsd-386-cgo), type Termios struct, Oflag uint32
 pkg syscall (freebsd-386-cgo), type Termios struct, Ospeed uint32
+pkg syscall (freebsd-amd64), func FcntlFlock(uintptr, int, *Flock_t) error
 pkg syscall (freebsd-amd64), type Termios struct
 pkg syscall (freebsd-amd64), type Termios struct, Cc [20]uint8
 pkg syscall (freebsd-amd64), type Termios struct, Cflag uint32
@@ -141,6 +148,7 @@ pkg syscall (freebsd-amd64), type Termios struct, Ispeed uint32
 pkg syscall (freebsd-amd64), type Termios struct, Lflag uint32
 pkg syscall (freebsd-amd64), type Termios struct, Oflag uint32
 pkg syscall (freebsd-amd64), type Termios struct, Ospeed uint32
+pkg syscall (freebsd-amd64-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
 pkg syscall (freebsd-amd64-cgo), type Termios struct
 pkg syscall (freebsd-amd64-cgo), type Termios struct, Cc [20]uint8
 pkg syscall (freebsd-amd64-cgo), type Termios struct, Cflag uint32
@@ -149,6 +157,56 @@ pkg syscall (freebsd-amd64-cgo), type Termios struct, Ispeed uint32
 pkg syscall (freebsd-amd64-cgo), type Termios struct, Lflag uint32
 pkg syscall (freebsd-amd64-cgo), type Termios struct, Oflag uint32
 pkg syscall (freebsd-amd64-cgo), type Termios struct, Ospeed uint32
+pkg syscall (freebsd-arm), func Fchflags(int, int) error
+pkg syscall (freebsd-arm), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (freebsd-arm-cgo), func Fchflags(int, int) error
+pkg syscall (freebsd-arm-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (linux-386), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (linux-386), type Flock_t struct
+pkg syscall (linux-386), type Flock_t struct, Len int64
+pkg syscall (linux-386), type Flock_t struct, Pid int32
+pkg syscall (linux-386), type Flock_t struct, Start int64
+pkg syscall (linux-386), type Flock_t struct, Type int16
+pkg syscall (linux-386), type Flock_t struct, Whence int16
+pkg syscall (linux-386-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (linux-386-cgo), type Flock_t struct
+pkg syscall (linux-386-cgo), type Flock_t struct, Len int64
+pkg syscall (linux-386-cgo), type Flock_t struct, Pid int32
+pkg syscall (linux-386-cgo), type Flock_t struct, Start int64
+pkg syscall (linux-386-cgo), type Flock_t struct, Type int16
+pkg syscall (linux-386-cgo), type Flock_t struct, Whence int16
+pkg syscall (linux-amd64), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (linux-amd64), type Flock_t struct
+pkg syscall (linux-amd64), type Flock_t struct, Len int64
+pkg syscall (linux-amd64), type Flock_t struct, Pad_cgo_0 [4]uint8
+pkg syscall (linux-amd64), type Flock_t struct, Pad_cgo_1 [4]uint8
+pkg syscall (linux-amd64), type Flock_t struct, Pid int32
+pkg syscall (linux-amd64), type Flock_t struct, Start int64
+pkg syscall (linux-amd64), type Flock_t struct, Type int16
+pkg syscall (linux-amd64), type Flock_t struct, Whence int16
+pkg syscall (linux-amd64-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (linux-amd64-cgo), type Flock_t struct
+pkg syscall (linux-amd64-cgo), type Flock_t struct, Len int64
+pkg syscall (linux-amd64-cgo), type Flock_t struct, Pad_cgo_0 [4]uint8
+pkg syscall (linux-amd64-cgo), type Flock_t struct, Pad_cgo_1 [4]uint8
+pkg syscall (linux-amd64-cgo), type Flock_t struct, Pid int32
+pkg syscall (linux-amd64-cgo), type Flock_t struct, Start int64
+pkg syscall (linux-amd64-cgo), type Flock_t struct, Type int16
+pkg syscall (linux-amd64-cgo), type Flock_t struct, Whence int16
+pkg syscall (linux-arm), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (linux-arm), type Flock_t struct
+pkg syscall (linux-arm), type Flock_t struct, Len int64
+pkg syscall (linux-arm), type Flock_t struct, Pid int32
+pkg syscall (linux-arm), type Flock_t struct, Start int64
+pkg syscall (linux-arm), type Flock_t struct, Type int16
+pkg syscall (linux-arm), type Flock_t struct, Whence int16
+pkg syscall (linux-arm-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (linux-arm-cgo), type Flock_t struct
+pkg syscall (linux-arm-cgo), type Flock_t struct, Len int64
+pkg syscall (linux-arm-cgo), type Flock_t struct, Pid int32
+pkg syscall (linux-arm-cgo), type Flock_t struct, Start int64
+pkg syscall (linux-arm-cgo), type Flock_t struct, Type int16
+pkg syscall (linux-arm-cgo), type Flock_t struct, Whence int16
 pkg syscall (netbsd-386), const CLONE_CSIGNAL = 255
 pkg syscall (netbsd-386), const CLONE_CSIGNAL ideal-int
 pkg syscall (netbsd-386), const CLONE_FILES = 1024
@@ -247,6 +305,15 @@ pkg syscall (netbsd-386), const PROT_READ = 1
 pkg syscall (netbsd-386), const PROT_READ ideal-int
 pkg syscall (netbsd-386), const PROT_WRITE = 2
 pkg syscall (netbsd-386), const PROT_WRITE ideal-int
+pkg syscall (netbsd-386), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (netbsd-386), type Termios struct
+pkg syscall (netbsd-386), type Termios struct, Cc [20]uint8
+pkg syscall (netbsd-386), type Termios struct, Cflag uint32
+pkg syscall (netbsd-386), type Termios struct, Iflag uint32
+pkg syscall (netbsd-386), type Termios struct, Ispeed int32
+pkg syscall (netbsd-386), type Termios struct, Lflag uint32
+pkg syscall (netbsd-386), type Termios struct, Oflag uint32
+pkg syscall (netbsd-386), type Termios struct, Ospeed int32
 pkg syscall (netbsd-386-cgo), const CLONE_CSIGNAL = 255
 pkg syscall (netbsd-386-cgo), const CLONE_CSIGNAL ideal-int
 pkg syscall (netbsd-386-cgo), const CLONE_FILES = 1024
@@ -345,6 +412,15 @@ pkg syscall (netbsd-386-cgo), const PROT_READ = 1
 pkg syscall (netbsd-386-cgo), const PROT_READ ideal-int
 pkg syscall (netbsd-386-cgo), const PROT_WRITE = 2
 pkg syscall (netbsd-386-cgo), const PROT_WRITE ideal-int
+pkg syscall (netbsd-386-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (netbsd-386-cgo), type Termios struct
+pkg syscall (netbsd-386-cgo), type Termios struct, Cc [20]uint8
+pkg syscall (netbsd-386-cgo), type Termios struct, Cflag uint32
+pkg syscall (netbsd-386-cgo), type Termios struct, Iflag uint32
+pkg syscall (netbsd-386-cgo), type Termios struct, Ispeed int32
+pkg syscall (netbsd-386-cgo), type Termios struct, Lflag uint32
+pkg syscall (netbsd-386-cgo), type Termios struct, Oflag uint32
+pkg syscall (netbsd-386-cgo), type Termios struct, Ospeed int32
 pkg syscall (netbsd-amd64), const CLONE_CSIGNAL = 255
 pkg syscall (netbsd-amd64), const CLONE_CSIGNAL ideal-int
 pkg syscall (netbsd-amd64), const CLONE_FILES = 1024
@@ -443,6 +519,15 @@ pkg syscall (netbsd-amd64), const PROT_READ = 1
 pkg syscall (netbsd-amd64), const PROT_READ ideal-int
 pkg syscall (netbsd-amd64), const PROT_WRITE = 2
 pkg syscall (netbsd-amd64), const PROT_WRITE ideal-int
+pkg syscall (netbsd-amd64), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (netbsd-amd64), type Termios struct
+pkg syscall (netbsd-amd64), type Termios struct, Cc [20]uint8
+pkg syscall (netbsd-amd64), type Termios struct, Cflag uint32
+pkg syscall (netbsd-amd64), type Termios struct, Iflag uint32
+pkg syscall (netbsd-amd64), type Termios struct, Ispeed int32
+pkg syscall (netbsd-amd64), type Termios struct, Lflag uint32
+pkg syscall (netbsd-amd64), type Termios struct, Oflag uint32
+pkg syscall (netbsd-amd64), type Termios struct, Ospeed int32
 pkg syscall (netbsd-amd64-cgo), const CLONE_CSIGNAL = 255
 pkg syscall (netbsd-amd64-cgo), const CLONE_CSIGNAL ideal-int
 pkg syscall (netbsd-amd64-cgo), const CLONE_FILES = 1024
@@ -541,6 +626,35 @@ pkg syscall (netbsd-amd64-cgo), const PROT_READ = 1
 pkg syscall (netbsd-amd64-cgo), const PROT_READ ideal-int
 pkg syscall (netbsd-amd64-cgo), const PROT_WRITE = 2
 pkg syscall (netbsd-amd64-cgo), const PROT_WRITE ideal-int
+pkg syscall (netbsd-amd64-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (netbsd-amd64-cgo), type Termios struct
+pkg syscall (netbsd-amd64-cgo), type Termios struct, Cc [20]uint8
+pkg syscall (netbsd-amd64-cgo), type Termios struct, Cflag uint32
+pkg syscall (netbsd-amd64-cgo), type Termios struct, Iflag uint32
+pkg syscall (netbsd-amd64-cgo), type Termios struct, Ispeed int32
+pkg syscall (netbsd-amd64-cgo), type Termios struct, Lflag uint32
+pkg syscall (netbsd-amd64-cgo), type Termios struct, Oflag uint32
+pkg syscall (netbsd-amd64-cgo), type Termios struct, Ospeed int32
+pkg syscall (netbsd-arm), func Fchflags(int, int) error
+pkg syscall (netbsd-arm), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (netbsd-arm), type Termios struct
+pkg syscall (netbsd-arm), type Termios struct, Cc [20]uint8
+pkg syscall (netbsd-arm), type Termios struct, Cflag uint32
+pkg syscall (netbsd-arm), type Termios struct, Iflag uint32
+pkg syscall (netbsd-arm), type Termios struct, Ispeed int32
+pkg syscall (netbsd-arm), type Termios struct, Lflag uint32
+pkg syscall (netbsd-arm), type Termios struct, Oflag uint32
+pkg syscall (netbsd-arm), type Termios struct, Ospeed int32
+pkg syscall (netbsd-arm-cgo), func Fchflags(int, int) error
+pkg syscall (netbsd-arm-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
+pkg syscall (netbsd-arm-cgo), type Termios struct
+pkg syscall (netbsd-arm-cgo), type Termios struct, Cc [20]uint8
+pkg syscall (netbsd-arm-cgo), type Termios struct, Cflag uint32
+pkg syscall (netbsd-arm-cgo), type Termios struct, Iflag uint32
+pkg syscall (netbsd-arm-cgo), type Termios struct, Ispeed int32
+pkg syscall (netbsd-arm-cgo), type Termios struct, Lflag uint32
+pkg syscall (netbsd-arm-cgo), type Termios struct, Oflag uint32
+pkg syscall (netbsd-arm-cgo), type Termios struct, Ospeed int32
 pkg syscall (openbsd-386), const BIOCGRTIMEOUT = 1074545262
 pkg syscall (openbsd-386), const BIOCSRTIMEOUT = 2148287085
 pkg syscall (openbsd-386), const IPPROTO_DIVERT_INIT = 2
@@ -680,6 +794,7 @@ pkg syscall (openbsd-386), const SizeofRtMsghdr = 96
 pkg syscall (openbsd-386), const TCP_NOPUSH = 16
 pkg syscall (openbsd-386), const TCP_NOPUSH ideal-int
 pkg syscall (openbsd-386), const TIOCGTSTAMP = 1074558043
+pkg syscall (openbsd-386), func FcntlFlock(uintptr, int, *Flock_t) error
 pkg syscall (openbsd-386), type Dirent struct, Fileno uint64
 pkg syscall (openbsd-386), type Dirent struct, Off int64
 pkg syscall (openbsd-386), type Dirent struct, X__d_padding [4]uint8
@@ -692,6 +807,14 @@ pkg syscall (openbsd-386), type Stat_t struct, Ino uint64
 pkg syscall (openbsd-386), type Statfs_t struct, F_ctime uint64
 pkg syscall (openbsd-386), type Statfs_t struct, F_mntfromspec [90]int8
 pkg syscall (openbsd-386), type Statfs_t struct, Pad_cgo_0 [2]uint8
+pkg syscall (openbsd-386), type Termios struct
+pkg syscall (openbsd-386), type Termios struct, Cc [20]uint8
+pkg syscall (openbsd-386), type Termios struct, Cflag uint32
+pkg syscall (openbsd-386), type Termios struct, Iflag uint32
+pkg syscall (openbsd-386), type Termios struct, Ispeed int32
+pkg syscall (openbsd-386), type Termios struct, Lflag uint32
+pkg syscall (openbsd-386), type Termios struct, Oflag uint32
+pkg syscall (openbsd-386), type Termios struct, Ospeed int32
 pkg syscall (openbsd-386), type Timespec struct, Sec int64
 pkg syscall (openbsd-386), type Timeval struct, Sec int64
 pkg syscall (openbsd-386-cgo), const BIOCGRTIMEOUT = 1074545262
@@ -833,6 +956,7 @@ pkg syscall (openbsd-386-cgo), const SizeofRtMsghdr = 96
 pkg syscall (openbsd-386-cgo), const TCP_NOPUSH = 16
 pkg syscall (openbsd-386-cgo), const TCP_NOPUSH ideal-int
 pkg syscall (openbsd-386-cgo), const TIOCGTSTAMP = 1074558043
+pkg syscall (openbsd-386-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
 pkg syscall (openbsd-386-cgo), type Dirent struct, Fileno uint64
 pkg syscall (openbsd-386-cgo), type Dirent struct, Off int64
 pkg syscall (openbsd-386-cgo), type Dirent struct, X__d_padding [4]uint8
@@ -845,6 +969,14 @@ pkg syscall (openbsd-386-cgo), type Stat_t struct, Ino uint64
 pkg syscall (openbsd-386-cgo), type Statfs_t struct, F_ctime uint64
 pkg syscall (openbsd-386-cgo), type Statfs_t struct, F_mntfromspec [90]int8
 pkg syscall (openbsd-386-cgo), type Statfs_t struct, Pad_cgo_0 [2]uint8
+pkg syscall (openbsd-386-cgo), type Termios struct
+pkg syscall (openbsd-386-cgo), type Termios struct, Cc [20]uint8
+pkg syscall (openbsd-386-cgo), type Termios struct, Cflag uint32
+pkg syscall (openbsd-386-cgo), type Termios struct, Iflag uint32
+pkg syscall (openbsd-386-cgo), type Termios struct, Ispeed int32
+pkg syscall (openbsd-386-cgo), type Termios struct, Lflag uint32
+pkg syscall (openbsd-386-cgo), type Termios struct, Oflag uint32
+pkg syscall (openbsd-386-cgo), type Termios struct, Ospeed int32
 pkg syscall (openbsd-386-cgo), type Timespec struct, Sec int64
 pkg syscall (openbsd-386-cgo), type Timeval struct, Sec int64
 pkg syscall (openbsd-amd64), const IPPROTO_DIVERT_INIT = 2
@@ -982,6 +1114,7 @@ pkg syscall (openbsd-amd64), const TCP_NOPUSH = 16
 pkg syscall (openbsd-amd64), const TCP_NOPUSH ideal-int
 pkg syscall (openbsd-amd64), const TIOCGSID = 1074033763
 pkg syscall (openbsd-amd64), const TIOCGSID ideal-int
+pkg syscall (openbsd-amd64), func FcntlFlock(uintptr, int, *Flock_t) error
 pkg syscall (openbsd-amd64), type Dirent struct, Fileno uint64
 pkg syscall (openbsd-amd64), type Dirent struct, Off int64
 pkg syscall (openbsd-amd64), type Dirent struct, X__d_padding [4]uint8
@@ -996,6 +1129,14 @@ pkg syscall (openbsd-amd64), type Stat_t struct, Pad_cgo_0 [4]uint8
 pkg syscall (openbsd-amd64), type Statfs_t struct, F_ctime uint64
 pkg syscall (openbsd-amd64), type Statfs_t struct, F_mntfromspec [90]int8
 pkg syscall (openbsd-amd64), type Statfs_t struct, Pad_cgo_1 [2]uint8
+pkg syscall (openbsd-amd64), type Termios struct
+pkg syscall (openbsd-amd64), type Termios struct, Cc [20]uint8
+pkg syscall (openbsd-amd64), type Termios struct, Cflag uint32
+pkg syscall (openbsd-amd64), type Termios struct, Iflag uint32
+pkg syscall (openbsd-amd64), type Termios struct, Ispeed int32
+pkg syscall (openbsd-amd64), type Termios struct, Lflag uint32
+pkg syscall (openbsd-amd64), type Termios struct, Oflag uint32
+pkg syscall (openbsd-amd64), type Termios struct, Ospeed int32
 pkg syscall (openbsd-amd64), type Timespec struct, Sec int64
 pkg syscall (openbsd-amd64-cgo), const IPPROTO_DIVERT_INIT = 2
 pkg syscall (openbsd-amd64-cgo), const IPPROTO_DIVERT_INIT ideal-int
@@ -1132,6 +1273,7 @@ pkg syscall (openbsd-amd64-cgo), const TCP_NOPUSH = 16
 pkg syscall (openbsd-amd64-cgo), const TCP_NOPUSH ideal-int
 pkg syscall (openbsd-amd64-cgo), const TIOCGSID = 1074033763
 pkg syscall (openbsd-amd64-cgo), const TIOCGSID ideal-int
+pkg syscall (openbsd-amd64-cgo), func FcntlFlock(uintptr, int, *Flock_t) error
 pkg syscall (openbsd-amd64-cgo), type Dirent struct, Fileno uint64
 pkg syscall (openbsd-amd64-cgo), type Dirent struct, Off int64
 pkg syscall (openbsd-amd64-cgo), type Dirent struct, X__d_padding [4]uint8
@@ -1146,6 +1288,14 @@ pkg syscall (openbsd-amd64-cgo), type Stat_t struct, Pad_cgo_0 [4]uint8
 pkg syscall (openbsd-amd64-cgo), type Statfs_t struct, F_ctime uint64
 pkg syscall (openbsd-amd64-cgo), type Statfs_t struct, F_mntfromspec [90]int8
 pkg syscall (openbsd-amd64-cgo), type Statfs_t struct, Pad_cgo_1 [2]uint8
+pkg syscall (openbsd-amd64-cgo), type Termios struct
+pkg syscall (openbsd-amd64-cgo), type Termios struct, Cc [20]uint8
+pkg syscall (openbsd-amd64-cgo), type Termios struct, Cflag uint32
+pkg syscall (openbsd-amd64-cgo), type Termios struct, Iflag uint32
+pkg syscall (openbsd-amd64-cgo), type Termios struct, Ispeed int32
+pkg syscall (openbsd-amd64-cgo), type Termios struct, Lflag uint32
+pkg syscall (openbsd-amd64-cgo), type Termios struct, Oflag uint32
+pkg syscall (openbsd-amd64-cgo), type Termios struct, Ospeed int32
 pkg syscall (openbsd-amd64-cgo), type Timespec struct, Sec int64
 pkg syscall (windows-386), const ERROR_NETNAME_DELETED = 64
 pkg syscall (windows-386), const ERROR_NETNAME_DELETED Errno

コアとなるコードの解説

このコミットは、Goのsyscallパッケージが提供するAPIを拡張するために、api/next.txtファイルに新しいエントリを追加しています。このファイルは、Goの将来のバージョンで公開される予定のAPIをリストアップするものであり、実際のコード変更は含まれていません。しかし、このファイルへの追加は、Goの標準ライブラリがこれらの機能を提供する意図があることを明確に示しています。

追加されたエントリは、主に以下の3つのカテゴリに分けられます。

  1. pkg syscall (OS-ARCH), func FcntlFlock(uintptr, int, *Flock_t) error:

    • これは、Unix系OS(Darwin, FreeBSD, Linux, NetBSD, OpenBSD)の様々なアーキテクチャ(386, amd64, arm)に対して、FcntlFlock関数が追加されることを示しています。
    • FcntlFlockは、ファイル記述子、コマンド、Flock_t構造体へのポインタを引数に取り、ファイルロック操作を実行します。これにより、Goプログラムはfcntlシステムコールを介して、ファイルの特定領域に対するロック(レコードロック)を細かく制御できるようになります。
    • uintptrはファイル記述子を表し、intfcntlコマンド(例: F_SETLK, F_SETLKW, F_GETLK)を表します。*Flock_tはロック情報を格納する構造体へのポインタです。
  2. pkg syscall (OS-ARCH), type Flock_t struct およびそのフィールド:

    • Linuxの各アーキテクチャ(386, amd64, arm)に対して、Flock_t構造体とそのフィールド(Len, Pid, Start, Type, Whence)が追加されています。
    • Flock_tは、FcntlFlock関数で使用されるファイルロック情報を定義する構造体です。
      • Type: ロックの種類(F_RDLCK (読み取りロック), F_WRLCK (書き込みロック), F_UNLCK (アンロック))。
      • Whence: ロック範囲の開始オフセットの基準(SEEK_SET, SEEK_CUR, SEEK_END)。
      • Start: ロック範囲の開始オフセット。
      • Len: ロック範囲の長さ。
      • Pid: ロックを保持しているプロセスのID(F_GETLKで取得する場合)。
    • linux-amd64Flock_tにはPad_cgo_0Pad_cgo_1というパディングフィールドが含まれており、これはC言語の構造体とのメモリレイアウトの互換性を保つためにGoコンパイラが自動的に挿入するものです。
  3. pkg syscall (OS-ARCH), type Termios struct およびそのフィールド:

    • FreeBSD, NetBSD, OpenBSDの各アーキテクチャに対して、Termios構造体とそのフィールド(Cc, Cflag, Iflag, Ispeed, Lflag, Oflag, Ospeedなど)が追加されています。
    • Termiosは、ターミナルデバイスのI/O設定を制御するための構造体です。これらのフィールドは、ターミナルの挙動(例: 入力処理、出力処理、制御文字、ボーレート)を細かく設定するために使用されます。

これらのAPIがapi/next.txtに追加されたことで、Go開発者はこれらの低レベルなOS機能に、Goの型安全なインターフェースを通じてアクセスできるようになります。これにより、Goでより高度なシステムプログラミングや、特定のOS機能に依存するアプリケーションの開発が可能になります。

関連リンク

参考にした情報源リンク

  • Go言語のソースコードリポジトリ: https://github.com/golang/go
  • Go Code Review (CL 55460043): https://golang.org/cl/55460043 (コミットメッセージに記載されているGoのコードレビューリンク)
  • Unix/Linuxプログラミングに関する一般的なドキュメントや書籍(例: "UNIX Network Programming", "Advanced Programming in the UNIX Environment")