linux
Factor documentation > Factor handbook > The implementation > System interface > Operating system detection
Prev:os ( -- class )
Next:macosx


Vocabulary
system

Definition
IN: system

SINGLETON: linux


Methods
USING: io.monitors io.monitors.linux io.monitors.recursive
kernel system unix.linux.inotify ;

M: linux (monitor)
swap
[ <recursive-monitor> ]
[ check-inotify IN_CHANGE_EVENTS swap add-watch ] if ;


USING: accessors math sequences system system-info
unix.linux.proc ;

M: linux cpu-mhz parse-proc-cpuinfo first cpu-mhz>> 1000000 * ;


USING: kernel system system-info unix.linux.proc ;

M: linux cpus parse-proc-cpuinfo sort-cpus cpu-counts 2drop ;


USING: destructors io.monitors io.monitors.linux namespaces
system ;

M: linux dispose-monitors inotify get dispose ;


USING: accessors combinators io.backend io.files.info
io.files.info.unix io.files.info.unix.linux kernel system ;

M: linux file-system-info
normalize-path [
[ new-file-system-info ] dip
[ file-system-statfs statfs>file-system-info ]
[ file-system-statvfs statvfs>file-system-info ] bi
file-system-calculations
] keep find-mount-point {
[ file-system-name>> >>device-name drop ]
[ mount-point>> >>mount-point drop ]
[ type>> >>type ]
} 2cleave ;


USING: classes.struct io.files.info.unix kernel system unix
unix.statfs.linux ;

M: linux file-system-statfs
\ statfs64 <struct> [ statfs64 io-error ] keep ;


USING: classes.struct io.files.info.unix kernel system unix
unix.statvfs.linux ;

M: linux file-system-statvfs
\ statvfs64 <struct> [ statvfs64 io-error ] keep ;


USING: accessors combinators io.files.info
io.files.info.unix.linux kernel sequences system ;

M: linux file-systems
parse-mtab [
[ mount-point>> file-system-info ] keep {
[ file-system-name>> >>device-name ]
[ mount-point>> >>mount-point ]
[ type>> >>type ]
} cleave
] map ;


USING: alien.c-types alien.data classes.struct
io.directories.unix kernel system unix unix.ffi ;

M: linux find-next-file
dirent <struct> f void* <ref> [
[ readdir64_r ] unix-system-call 0 =
[ (io-error) ] unless
] 2keep void* deref [ drop f ] unless ;


USING: io.backend io.backend.unix.multiplexers
io.backend.unix.multiplexers.epoll namespaces system ;

M: linux init-io <epoll-mx> mx set-global ;


USING: io.monitors io.monitors.linux kernel namespaces system
threads ;

M: linux init-monitors
H{ } clone watches set <inotify> [
[ inotify set ] [
[ inotify-read-thread ] curry
"Linux monitor thread" spawn drop
] bi
] [ "Linux kernel version is too old" throw ] if* ;


USING: assocs io.serial kernel system ;

M: linux lookup-baud
H{
{ 0 0 }
{ 4800 12 }
{ 921600 4103 }
{ 9600 13 }
{ 134 4 }
{ 200 6 }
{ 1800 10 }
{ 19200 14 }
{ 75 2 }
{ 1000000 4104 }
{ 38400 15 }
{ 57600 4097 }
{ 150 5 }
{ 600 8 }
{ 4000000 4111 }
{ 1152000 4105 }
{ 115200 4098 }
{ 2400 11 }
{ 500000 4101 }
{ 1500000 4106 }
{ 230400 4099 }
{ 2500000 4108 }
{ 2000000 4107 }
{ 3500000 4110 }
{ 300 7 }
{ 460800 4100 }
{ 110 3 }
{ 1200 9 }
{ 50 1 }
{ 576000 4102 }
{ 3000000 4109 }
} ?at [ invalid-baud ] unless ;


USING: io.files.info.unix io.files.info.unix.linux kernel
system ;

M: linux new-file-system-info linux-file-system-info new ;


USING: io.launcher kernel sequences system webbrowser ;

M: linux open-file { "xdg-open" } swap suffix try-process ;


USING: system unix unix.ffi ;

M: linux open-file [ open64 ] unix-system-call ;


USING: system system-info system-info.linux ;

M: linux os-version release ;


USING: accessors system system-info unix.linux.proc ;

M: linux physical-mem parse-proc-meminfo mem-total>> ;


USING: io.sockets system ;

M: linux resolve-localhost { T{ ipv4 { host "0.0.0.0" } } } ;


USING: accessors combinators io.files.info.unix system ;

M: linux statfs>file-system-info
{
[ f_type>> >>type ]
[ f_bsize>> >>block-size ]
[ f_blocks>> >>blocks ]
[ f_bfree>> >>blocks-free ]
[ f_bavail>> >>blocks-available ]
[ f_files>> >>files ]
[ f_ffree>> >>files-free ]
[ f_fsid>> >>id ]
[ f_namelen>> >>namelen ]
[ f_frsize>> >>preferred-block-size ]
} cleave ;


USING: accessors combinators io.files.info.unix system ;

M: linux statvfs>file-system-info
{ [ f_flag>> >>flags ] [ f_namemax>> >>name-max ] } cleave
;


USING: game.input.gtk system ;

M: linux x>hid-bit-order
{
0
0
0
0
0
0
0
0
0
41
30
31
32
33
34
35
36
37
38
39
45
46
42
43
20
26
8
21
23
28
24
12
18
19
47
48
40
224
4
22
7
9
10
11
13
14
15
51
52
53
225
49
29
27
6
25
5
17
16
54
55
56
229
85
226
44
57
58
59
60
61
62
63
64
65
66
67
83
71
95
96
97
86
92
93
94
87
91
90
89
98
99
0
0
0
68
69
0
0
~157 more~
} ; inline


USING: game.input.x11 system ;

M: linux x>hid-bit-order
{
0
0
0
0
0
0
0
0
0
41
30
31
32
33
34
35
36
37
38
39
45
46
42
43
20
26
8
21
23
28
24
12
18
19
47
48
40
224
4
22
7
9
10
11
13
14
15
51
52
53
225
49
29
27
6
25
5
17
16
54
55
56
229
85
226
44
57
58
59
60
61
62
63
64
65
66
67
83
71
95
96
97
86
92
93
94
87
91
90
89
98
99
0
0
0
68
69
0
0
~157 more~
} ; inline