summaryrefslogtreecommitdiff
path: root/nvidia-installer.h
blob: c90e785b101d88de9a58892a84223611e6a6f767 (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/*
 * nvidia-installer: A tool for installing NVIDIA software packages on
 * Unix and Linux systems.
 *
 * Copyright (C) 2003-2009 NVIDIA Corporation
 *
 * This program 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 2 of the
 * License, or (at your option) any later version.
 * 
 * This program 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 this program; if not, write to the:
 *
 *      Free Software Foundation, Inc.
 *      59 Temple Place - Suite 330
 *      Boston, MA 02111-1307, USA
 *
 *
 * nvidia-installer.h
 */

#ifndef __NVIDIA_INSTALLER_H__
#define __NVIDIA_INSTALLER_H__

#include <sys/types.h>
#include <stdint.h>


/*
 * Enumerated type, listing each of the system utilities we'll need.
 * Keep this enum in sync with the needed_utils string array in
 * misc.c:find_system_utils().
 */

typedef enum {
    LDCONFIG = 0,
    LDD,
    LD,
    OBJCOPY,
    GREP,
    DMESG,
    TAIL,
    CUT,
    TR,
    SED,
    MAX_SYSTEM_UTILS
} SystemUtils;

typedef enum {
    CHCON = MAX_SYSTEM_UTILS,
    SELINUX_ENABLED,
    GETENFORCE,
    EXECSTACK,
    PKG_CONFIG,
    XSERVER,
    MAX_SYSTEM_OPTIONAL_UTILS
} SystemOptionalUtils;

/*
 * Enumerated type, listing each of the module utilities we'll need.
 * Keep this enum in sync with the needed_utils string array in
 * misc.c:find_module_utils().
 */

typedef enum {
    INSMOD = MAX_SYSTEM_OPTIONAL_UTILS,
    MODPROBE,
    RMMOD,
    LSMOD,
    DEPMOD,
    MAX_UTILS
} ModuleUtils;

/*
 * Enumerated type of distributions; this isn't an exhaustive list of
 * supported distributions... just distributions that have asked for
 * special behavior.
 */

typedef enum {
    SUSE,
    UNITED_LINUX,
    DEBIAN,
    UBUNTU,
    GENTOO,
    OTHER
} Distribution;


typedef uint32_t uint32;
typedef uint16_t uint16;
typedef uint8_t uint8;



/*
 * Options structure; malloced by and initialized by
 * parse_commandline() and used by all the other functions in the
 * installer.
 */


typedef struct __options {

    int accept_license;
    int update;
    int expert;
    int uninstall;
    int driver_info;
    int debug;
    int logging;
    int no_precompiled_interface;
    int no_ncurses_color;
    int latest;
    int force_update;
    int opengl_headers;
    int no_questions;
    int silent;
    int which_tls;
    int which_tls_compat32;
    int sanity;
    int add_this_kernel;
    int no_runlevel_check;
    int no_backup;
    int no_network;
    int kernel_module_only;
    int no_kernel_module;
    int no_abi_note;
    int no_rpms;
    int no_recursion;
    int run_nvidia_xconfig;
    int selinux_option;
    int selinux_enabled;
    int sigwinch_workaround;
    int no_x_check;
    int no_nvidia_xconfig_question;
    int run_distro_scripts;

    char *opengl_prefix;
    char *opengl_libdir;
    char *opengl_incdir;

    char *x_prefix;
    char *x_libdir;
    char *x_moddir;
    char *x_module_path;
    char *x_library_path;

    char *compat32_chroot;
    char *compat32_prefix;
    char *compat32_libdir;

    char *utility_prefix;
    char *utility_libdir;
    char *utility_bindir;
    char *installer_prefix;

    char *dot_desktopdir;

    char *documentation_prefix;
    char *documentation_docdir;
    char *documentation_mandir;

    int modular_xorg;

    char *kernel_source_path;
    char *kernel_output_path;
    char *kernel_include_path;
    char *kernel_module_installation_path;
    char *utils[MAX_UTILS];
    
    char *proc_mount_point;
    char *ui_str;
    char *log_file_name;

    char *ftp_site;

    char *tmpdir;
    char *update_arguments;
    char *kernel_name;
    char *rpm_file_list;
    char *precompiled_kernel_interfaces_path;
    char *precompiled_kernel_interfaces_url;
    const char *selinux_chcon_type;

    Distribution distro;

    void *ui_priv; /* for use by the ui's */

    int ignore_cc_version_check;

} Options;


typedef struct __package_entry {
    
    char *file;     /*
                     * filename in the package, relative to cwd of the
                     * .manifest file.
                     */
    
    char *path;     /*
                     * 
                     */

    
    char *name;     /*
                     * filename without any leading directory
                     * components; this is just a pointer into the
                     * 'file' field.
                     */

    char *target;   /*
                     * For Package entries that are symbolic links,
                     * the target indicates the target of the link;
                     * NULL for non-symbolic link Package entries.
                     */
    
    char *dst;      /*
                     * The fully-qualified filename of the destination
                     * location of the Package entry; NULL for entries
                     * that are not installed on the filesystem.  This
                     * field is assigned by the set_destinations()
                     * function.
                     */

    uint64_t flags;
    mode_t mode;

    ino_t inode;
    dev_t device;   /*
                     * inode of the file after extraction from the
                     * package; this is needed to compare against the
                     * files on the user's system that we consider for
                     * removal, so that symlink loops don't confuse us
                     * into deleting the files from the package.
                     */
} PackageEntry;


typedef struct __package {

    char *description;
    char *version;
    char *kernel_module_filename;
    char *kernel_interface_filename;
    char *kernel_module_name;
    char **bad_modules;
    char **bad_module_filenames;
    char *kernel_module_build_directory;
    char *precompiled_kernel_interface_directory;
    
    PackageEntry *entries; /* array of filename/checksum/bytesize entries */
    int num_entries;

} Package;



typedef struct {
    char **t; /* the text rows */
    int n;    /* number of rows */
    int m;    /* maximum row length */
} TextRows;




/* define boolean values TRUE and FALSE */

#ifndef TRUE
#define TRUE 1
#endif /* TRUE */
  
#ifndef FALSE
#define FALSE 0
#endif /* FALSE */


/* flags for passing into install_from_cwd() */

#define ADJUST_CWD  0x01


/* default line length for strings */

#define NV_LINE_LEN 1024
#define NV_MIN_LINE_LEN 256

/* file types */

#define FILE_TYPE_MASK                          0x00000000ffffffffULL

#define FILE_TYPE_KERNEL_MODULE_SRC             0x0000000000000001ULL
#define FILE_TYPE_KERNEL_MODULE_CMD             0x0000000000000002ULL
#define FILE_TYPE_OPENGL_HEADER                 0x0000000000000004ULL
#define FILE_TYPE_OPENGL_LIB                    0x0000000000000008ULL
#define FILE_TYPE_XLIB_STATIC_LIB               0x0000000000000010ULL
#define FILE_TYPE_XLIB_SHARED_LIB               0x0000000000000020ULL
#define FILE_TYPE_DOCUMENTATION                 0x0000000000000040ULL
#define FILE_TYPE_OPENGL_SYMLINK                0x0000000000000080ULL
#define FILE_TYPE_XLIB_SYMLINK                  0x0000000000000100ULL
#define FILE_TYPE_KERNEL_MODULE                 0x0000000000000200ULL
#define FILE_TYPE_INSTALLER_BINARY              0x0000000000000400ULL
#define FILE_TYPE_UTILITY_BINARY                0x0000000000000800ULL
#define FILE_TYPE_LIBGL_LA                      0x0000000000001000ULL
#define FILE_TYPE_TLS_LIB                       0x0000000000002000ULL
#define FILE_TYPE_TLS_SYMLINK                   0x0000000000004000ULL
#define FILE_TYPE_UTILITY_LIB                   0x0000000000008000ULL
#define FILE_TYPE_DOT_DESKTOP                   0x0000000000010000ULL
#define FILE_TYPE_UTILITY_LIB_SYMLINK           0x0000000000020000ULL
#define FILE_TYPE_XMODULE_SHARED_LIB            0x0000000000040000ULL
#define FILE_TYPE_XMODULE_SYMLINK               0x0000000000080000ULL
/* Create a symlink only if the file doesn't exist */
#define FILE_TYPE_XMODULE_NEWSYM                0x0000000000100000ULL
#define FILE_TYPE_MANPAGE                       0x0000000000200000ULL
#define FILE_TYPE_CUDA_HEADER                   0x0000000000400000ULL
#define FILE_TYPE_CUDA_LIB                      0x0000000000800000ULL
#define FILE_TYPE_CUDA_SYMLINK                  0x0000000001000000ULL
#define FILE_TYPE_VDPAU_LIB                     0x0000000002000000ULL
#define FILE_TYPE_VDPAU_SYMLINK                 0x0000000004000000ULL
#define FILE_TYPE_VDPAU_HEADER                  0x0000000008000000ULL
#define FILE_TYPE_UTILITY_BIN_SYMLINK           0x0000000010000000ULL

/* file class: this is used to distinguish OpenGL libraries */

#define FILE_CLASS_MASK                         0xf000000000000000ULL

#define FILE_CLASS_NEW_TLS                      0x1000000000000000ULL
#define FILE_CLASS_CLASSIC_TLS                  0x2000000000000000ULL
#define FILE_CLASS_NATIVE                       0x4000000000000000ULL
#define FILE_CLASS_COMPAT32                     0x8000000000000000ULL

#define FILE_TYPE_XLIB_LIB         (FILE_TYPE_XLIB_STATIC_LIB | \
                                    FILE_TYPE_XLIB_SHARED_LIB)

#define FILE_TYPE_XMODULE_LIB      (FILE_TYPE_XMODULE_SHARED_LIB)

#define FILE_TYPE_INSTALLABLE_FILE (FILE_TYPE_OPENGL_LIB         | \
                                    FILE_TYPE_CUDA_LIB           | \
                                    FILE_TYPE_XLIB_LIB           | \
                                    FILE_TYPE_TLS_LIB            | \
                                    FILE_TYPE_UTILITY_LIB        | \
                                    FILE_TYPE_DOCUMENTATION      | \
                                    FILE_TYPE_MANPAGE            | \
                                    FILE_TYPE_OPENGL_HEADER      | \
                                    FILE_TYPE_CUDA_HEADER        | \
                                    FILE_TYPE_KERNEL_MODULE      | \
                                    FILE_TYPE_INSTALLER_BINARY   | \
                                    FILE_TYPE_UTILITY_BINARY     | \
                                    FILE_TYPE_LIBGL_LA           | \
                                    FILE_TYPE_XMODULE_LIB        | \
                                    FILE_TYPE_DOT_DESKTOP        | \
                                    FILE_TYPE_VDPAU_LIB          | \
                                    FILE_TYPE_VDPAU_HEADER)

#define FILE_TYPE_HAVE_PATH        (FILE_TYPE_XMODULE_LIB        | \
                                    FILE_TYPE_XMODULE_SYMLINK    | \
                                    FILE_TYPE_XMODULE_NEWSYM     | \
                                    FILE_TYPE_MANPAGE            | \
                                    FILE_TYPE_OPENGL_HEADER      | \
                                    FILE_TYPE_CUDA_LIB           | \
                                    FILE_TYPE_CUDA_SYMLINK       | \
                                    FILE_TYPE_CUDA_HEADER        | \
                                    FILE_TYPE_TLS_LIB            | \
                                    FILE_TYPE_TLS_SYMLINK        | \
                                    FILE_TYPE_DOT_DESKTOP        | \
                                    FILE_TYPE_DOCUMENTATION      | \
                                    FILE_TYPE_VDPAU_SYMLINK      | \
                                    FILE_TYPE_VDPAU_LIB          | \
                                    FILE_TYPE_VDPAU_HEADER)

#define FILE_TYPE_HAVE_ARCH        (FILE_TYPE_OPENGL_LIB         | \
                                    FILE_TYPE_CUDA_LIB           | \
                                    FILE_TYPE_OPENGL_SYMLINK     | \
                                    FILE_TYPE_CUDA_SYMLINK       | \
                                    FILE_TYPE_LIBGL_LA           | \
                                    FILE_TYPE_TLS_LIB            | \
                                    FILE_TYPE_TLS_SYMLINK        | \
                                    FILE_TYPE_VDPAU_SYMLINK      | \
                                    FILE_TYPE_VDPAU_LIB)

#define FILE_TYPE_HAVE_CLASS       (FILE_TYPE_TLS_LIB            | \
                                    FILE_TYPE_TLS_SYMLINK)

#define FILE_TYPE_SYMLINK          (FILE_TYPE_OPENGL_SYMLINK     | \
                                    FILE_TYPE_CUDA_SYMLINK       | \
                                    FILE_TYPE_XLIB_SYMLINK       | \
                                    FILE_TYPE_TLS_SYMLINK        | \
                                    FILE_TYPE_XMODULE_SYMLINK    | \
                                    FILE_TYPE_UTILITY_LIB_SYMLINK| \
                                    FILE_TYPE_UTILITY_BIN_SYMLINK| \
                                    FILE_TYPE_VDPAU_SYMLINK)

#define FILE_TYPE_NEWSYM           (FILE_TYPE_XMODULE_NEWSYM)

#define FILE_TYPE_HAVE_TARGET      (FILE_TYPE_SYMLINK            | \
                                    FILE_TYPE_NEWSYM)

#define FILE_TYPE_RTLD_CHECKED     (FILE_TYPE_OPENGL_LIB         | \
                                    FILE_TYPE_TLS_LIB)

#define FILE_TYPE_SHARED_LIB       (FILE_TYPE_OPENGL_LIB         | \
                                    FILE_TYPE_CUDA_LIB           | \
                                    FILE_TYPE_XLIB_SHARED_LIB    | \
                                    FILE_TYPE_TLS_LIB            | \
                                    FILE_TYPE_XMODULE_SHARED_LIB | \
                                    FILE_TYPE_UTILITY_LIB        | \
                                    FILE_TYPE_VDPAU_LIB)

#define TLS_LIB_TYPE_FORCED         0x0001
#define TLS_LIB_NEW_TLS             0x0002
#define TLS_LIB_CLASSIC_TLS         0x0004

#define SELINUX_DEFAULT             0x0000
#define SELINUX_FORCE_YES           0x0001
#define SELINUX_FORCE_NO            0x0002

#define FORCE_CLASSIC_TLS          (TLS_LIB_CLASSIC_TLS | TLS_LIB_TYPE_FORCED)
#define FORCE_NEW_TLS              (TLS_LIB_NEW_TLS | TLS_LIB_TYPE_FORCED)

#define PERM_MASK (S_IRWXU|S_IRWXG|S_IRWXO)

#define PRECOMPILED_KERNEL_INTERFACE_FILENAME "precompiled-nv-linux.o"


/*
 * These are the default installation prefixes and the default
 * paths relative to the prefixes. Some of the defaults are
 * overriden on some distributions or when the new modular Xorg
 * is detected, all prefixes/paths can be overriden from the
 * command line.
 */
#define DEFAULT_OPENGL_PREFIX           "/usr"
#define DEFAULT_X_PREFIX                "/usr/X11R6"
#define DEFAULT_UTILITY_PREFIX          "/usr"
#define DEFAULT_DOCUMENTATION_PREFIX    "/usr"

#define DEFAULT_LIBDIR                  "lib"
#define DEFAULT_64BIT_LIBDIR            "lib64"
#define DEFAULT_BINDIR                  "bin"
#define DEFAULT_INCDIR                  "include"
#define DEFAULT_X_MODULEDIR             "modules"
#define DEFAULT_DOT_DESKTOPDIR          "share/applications"
#define DEFAULT_DOCDIR                  "share/doc"
#define DEFAULT_MANDIR                  "share/man"

/*
 * As of Xorg 7.x, X components need not be installed relative
 * to a special top-level directory, they can be integrated
 * more tightly with the rest of the system. The system must be
 * queried for the installation paths, but in the event that
 * this fails, the fallbacks below are chosen.
 */
#define XORG7_DEFAULT_X_PREFIX          "/usr"
#define XORG7_DEFAULT_X_MODULEDIR       "xorg/modules"

/*
 * Debian GNU/Linux for x86-64 installs 32-bit compatibility
 * libraries relative to a chroot-like top-level directory; the
 * prefix below is prepended to the full paths.
 */
#define DEBIAN_DEFAULT_COMPAT32_CHROOT  "/emul/ia32-linux"

/*
 * Debian GNU/Linux and Ubuntu do not follow the lib64 library
 * path naming convention used by other distributors. 64-bit
 * libraries are placed under ../lib.
 */
#define DEBIAN_DEFAULT_64BIT_LIBDIR     "lib"

/*
 * Ubuntu GNU/Linux and Gentoo Linux do not follow the "lib"
 * library path naming convention used for 32-bit compatibility
 * libraries by other distributors. These libraries are
 * placed under ../lib32.
 */
#define UBUNTU_DEFAULT_COMPAT32_LIBDIR  "lib32"


#define DEFAULT_PROC_MOUNT_POINT "/proc"

#define DEFAULT_FTP_SITE "ftp://download.nvidia.com"

#define LICENSE_FILE "LICENSE"

#define DEFAULT_LOG_FILE_NAME "/var/log/nvidia-installer.log"

#define NUM_TIMES_QUESTIONS_ASKED 3

#define LD_OPTIONS "-d -r"
#define NVIDIA_VERSION_PROC_FILE "/proc/driver/nvidia/version"

#define NV_BULLET_STR "-> "
#define NV_CMD_OUT_PREFIX "   "

/* useful macros */

#define NV_MIN(x,y) ((x) < (y) ? (x) : (y))
#define NV_MAX(x,y) ((x) > (y) ? (x) : (y))

#define TAB "  "
#define BIGTAB "      "

/* prototypes of functions used throughout the installer */

void log_init(Options *op);
void log_printf(Options *op, const int wb,
                const char *prefix, const char *fmt, ...);

int  install_from_cwd(Options *op);
int  add_this_kernel(Options *op);

void add_package_entry(Package *p,
                       char *file,
                       char *path,
                       char *name,
                       char *target,
                       char *dst,
                       uint64_t flags,
                       mode_t mode);
/* XXX */

typedef TextRows *(*FormatTextRows)(const char*, const char*, int, int);


#endif /* __NVIDIA_INSTALLER_H__ */