[インデックス 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): 複数のプロセスが同時に同じファイルにアクセスする際に、データの整合性を保つために使用されるメカニズムです。
flock
やfcntl
システムコールを通じて実現されます。flock
: ファイル全体に対するアドバイザリロック(協調ロック)を提供します。ロックの種類には共有ロック(LOCK_SH
)と排他ロック(LOCK_EX
)があります。fcntl
ロック: ファイルの特定範囲に対するロック(レコードロック)をサポートし、強制ロック(mandatory locking)も可能です。より粒度の細かい制御が可能です。
Flock_t
構造体:fcntl
システムコールでファイルロックを操作する際に使用される構造体です。ロックの種類(共有、排他、アンロック)、ロックの開始オフセット、長さ、プロセスIDなどの情報を含みます。OSによって構造体の定義が異なる場合があります。Termios
構造体: Unix系システムでターミナル(シリアルポートやコンソール)のI/O設定を制御するための構造体です。ボーレート、パリティ、フロー制御、エコー、カノニカルモードなどの設定が含まれます。tcgetattr
やtcsetattr
といった関数を通じてこの構造体を操作します。- クロスプラットフォーム開発: Go言語はクロスプラットフォームを強く意識して設計されていますが、低レベルなシステムコールはOSによって大きく異なります。
syscall
パッケージは、これらのOS固有の差異を吸収しつつ、各プラットフォームのネイティブ機能へのアクセスを提供します。このコミットのように、特定のOS(Linux, Darwin, FreeBSD, NetBSD, OpenBSDなど)向けのAPIが追加されるのは、そのOSでしか利用できない、あるいはそのOSで特に重要な機能への対応を強化するためです。 api/next.txt
: Goプロジェクトにおいて、次期リリースで追加される予定の公開APIを記録するファイルです。このファイルに記載されたAPIは、Goの互換性ガイドラインに従い、将来のバージョンでも維持されることが期待されます。
技術的詳細
このコミットは、Goのsyscall
パッケージが提供するOS固有の機能セットを拡張しています。
-
Flock_t
構造体とFcntlFlock
関数の追加:FcntlFlock
は、Unix系システムにおけるfcntl(fd, cmd, &flock_t)
システムコールに対応するGoの関数です。これにより、Goプログラムからファイルのセグメントロック(レコードロック)をかけることが可能になります。これは、複数のプロセスが同じファイルの一部を同時に読み書きする際に、競合状態を防ぐために非常に重要です。Flock_t
構造体は、ロックの種類(読み取りロック、書き込みロック、アンロック)、ロックをかけるファイルのオフセット、ロックの長さ、そしてロックを保持しているプロセスのIDなどの情報を含みます。この構造体は、OSやアーキテクチャ(例:linux-amd64
,linux-386
)によって内部的なパディングやフィールドの順序が異なる場合があるため、Goのsyscall
パッケージではそれぞれの環境に合わせて正確な定義を提供する必要があります。コミット内容を見ると、Pad_cgo_0
やPad_cgo_1
といったフィールドが追加されており、これはCgoを介してOSの構造体とGoの構造体を正確にマッピングするために必要なパディングを示しています。- この機能は、特にデータベースシステムや、複数のアプリケーションが共有ファイルにアクセスするような環境で、データの整合性を保証するために不可欠です。
-
BSD系システムにおける
Termios
関連の追加:Termios
構造体は、Unix系OSにおけるターミナルデバイスの属性を制御するために使用されます。これには、入力モード、出力モード、制御モード、ローカルモード、特殊文字の設定などが含まれます。- このコミットでは、
freebsd
,netbsd
,openbsd
の各アーキテクチャ(386
,amd64
,arm
など)に対して、Termios
構造体の定義とそのフィールド(Cc
,Cflag
,Iflag
,Ispeed
,Lflag
,Oflag
,Ospeed
など)が追加されています。 - これにより、Goプログラムは、シリアルポート通信を行うアプリケーションや、カスタムシェル、ターミナルエミュレータなどを開発する際に、より細かくターミナルの挙動を制御できるようになります。例えば、エコーの無効化、カノニカルモードの切り替え、ボーレートの設定などが可能になります。
-
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つのカテゴリに分けられます。
-
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
はファイル記述子を表し、int
はfcntl
コマンド(例:F_SETLK
,F_SETLKW
,F_GETLK
)を表します。*Flock_t
はロック情報を格納する構造体へのポインタです。
- これは、Unix系OS(Darwin, FreeBSD, Linux, NetBSD, OpenBSD)の様々なアーキテクチャ(386, amd64, arm)に対して、
-
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-amd64
のFlock_t
にはPad_cgo_0
とPad_cgo_1
というパディングフィールドが含まれており、これはC言語の構造体とのメモリレイアウトの互換性を保つためにGoコンパイラが自動的に挿入するものです。
- Linuxの各アーキテクチャ(386, amd64, arm)に対して、
-
pkg syscall (OS-ARCH), type Termios struct
およびそのフィールド:- FreeBSD, NetBSD, OpenBSDの各アーキテクチャに対して、
Termios
構造体とそのフィールド(Cc
,Cflag
,Iflag
,Ispeed
,Lflag
,Oflag
,Ospeed
など)が追加されています。 Termios
は、ターミナルデバイスのI/O設定を制御するための構造体です。これらのフィールドは、ターミナルの挙動(例: 入力処理、出力処理、制御文字、ボーレート)を細かく設定するために使用されます。
- FreeBSD, NetBSD, OpenBSDの各アーキテクチャに対して、
これらのAPIがapi/next.txt
に追加されたことで、Go開発者はこれらの低レベルなOS機能に、Goの型安全なインターフェースを通じてアクセスできるようになります。これにより、Goでより高度なシステムプログラミングや、特定のOS機能に依存するアプリケーションの開発が可能になります。
関連リンク
- Go言語の
syscall
パッケージのドキュメント: https://pkg.go.dev/syscall fcntl
システムコール (Linux man page): https://man7.org/linux/man-pages/man2/fcntl.2.htmltermios
(Linux man page): https://man7.org/linux/man-pages/man3/termios.3.html- Go言語のAPI互換性ガイドライン: https://go.dev/doc/go1compat
参考にした情報源リンク
- 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")