-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuDevice.pas
144 lines (114 loc) · 5.51 KB
/
uDevice.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{
Copyright (c) 2019,2021 Daniel T. Borelli <[email protected]>
This file is part of ArchIsoMyDrive.
ArchIsoMyDrive is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ArchIsoMyDrive is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ArchIsoMyDrive. If not, see <http://www.gnu.org/licenses/>.
}
{
Representa la envoltura del archivo c_in/device.c
}
unit uDevice;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, CTypes, uResources;
const
E_NO = 0;
E_DEV_R = 1;
E_DEV_W = 2;
E_DEV_OR = 3;
E_DEV_OW = 4;
E_ISO_R = 5;
E_ISO_W = 6;
E_ISO_OR = 7;
E_ISO_OW = 8;
type
{$PACKRECORDS C}
PDeviceProperty = ^TDeviceProperty;
TDeviceProperty = record
node_path : array[0..40] of char;
id_vendor : array[0..40] of char;
id_product : array[0..40] of char;
product : array[0..40] of char;
manufacturer : array[0..40] of char;
serial : array[0..40] of char;
version : array[0..40] of char;
max_power : array[0..40] of char;
bus : array[0..40] of char;
size: array[0..40] of char;
totalbytes: cuint64;
readahead: cuint64;
end;
function Device_ProcessError(eid : cint): string;
type TListDevicesCallback = procedure; cdecl;
procedure CFree(P: pointer) ;cdecl;
procedure Device_Initialize; cdecl;
procedure Device_Unitialize; cdecl;
function Device_GetMonitorEvent : ctypes.cint32; cdecl;
function Device_ReceiveEvents : ctypes.cint32; cdecl;
procedure Device_ListOfDevices(cb : TListDevicesCallback); cdecl;
function Device_GetAttribute(attr : PChar) : PChar; cdecl;
function Device_GetProperty : PDeviceProperty; cdecl;
function Device_GetFileSize(path : PChar) : cuint64; cdecl;
function Device_GetFileSizeStr(size : cuint64) : PChar; cdecl;
function Device_CopyIsoToDevice(iso: PChar; isosize: cuint64; prop: PDeviceProperty): cint; cdecl;
function Device_ContinueCopyIsoToDevice: cint; cdecl;
function Device_CopyDeviceToIso(prop: PDeviceProperty; iso: PChar): cint; cdecl;
function Device_ContinueCopyDeviceToIso: cint; cdecl;
procedure Device_StopCopy; cdecl;
function Device_GetLenCopy: cuint64; cdecl;
function Device_GetStrPercentCopy: PChar; cdecl;
function Device_GetPercentCopy: cfloat; cdecl;
function Device_GetPercentTotalCopy: cfloat; cdecl;
function Device_GetError: PChar; cdecl;
function Device_GetDevicePath: PChar; cdecl;
implementation
{$linklib c} { implica libc }
{$linklib udev} { implica libudev }
{$link c_device.o} { linker only }
procedure CFree(P: pointer) ;cdecl; external name 'free';
procedure Device_Initialize; cdecl; external;
procedure Device_Unitialize; cdecl; external;
function Device_GetMonitorEvent : cint32; cdecl; external;
function Device_ReceiveEvents : cint32; cdecl; external;
procedure Device_ListOfDevices(cb : TListDevicesCallback); cdecl; external;
function Device_GetAttribute(attr : PChar) : PChar; cdecl; external;
function Device_GetProperty : PDeviceProperty; cdecl; external;
function Device_GetFileSize(path : PChar) : cuint64; cdecl; external;
function Device_GetFileSizeStr(size : cuint64) : PChar; cdecl; external;
function Device_CopyIsoToDevice(iso: PChar; isosize: cuint64; prop: PDeviceProperty): cint; cdecl ; external;
function Device_ContinueCopyIsoToDevice: cint; cdecl; external;
function Device_CopyDeviceToIso(prop: PDeviceProperty; iso: PChar): cint; cdecl; external;
function Device_ContinueCopyDeviceToIso: cint; cdecl; external;
procedure Device_StopCopy; cdecl; external;
function Device_GetLenCopy: cuint64; cdecl; external;
function Device_GetStrPercentCopy: PChar; cdecl; external;
function Device_GetPercentCopy: cfloat; cdecl; external;
function Device_GetPercentTotalCopy: cfloat; cdecl; external;
function Device_GetError: PChar; cdecl; external;
function Device_GetDevicePath: PChar; cdecl; external;
function Device_ProcessError(eid : cint): string;
var
error : PChar;
begin
error := Device_GetError;
case eid of
E_DEV_R: Result := rsE_DEV_R + error;
E_DEV_W: Result := rsE_DEV_W + error;
E_DEV_OR: Result := rsE_DEV_OR + error;
E_DEV_OW: Result := rsE_DEV_OW + error;
E_ISO_R: Result := rsE_ISO_R + error;
E_ISO_W: Result := rsE_ISO_W + error;
E_ISO_OR: Result := rsE_ISO_OR + error;
E_ISO_OW: Result := rsE_ISO_OW + error;
end;
end;
end.