Add syslinux.changes abd manifest
[external/syslinux.git] / dos / syslinux.c
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 1998-2008 H. Peter Anvin - All Rights Reserved
4  *   Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9  *   Boston MA 02111-1307, USA; either version 2 of the License, or
10  *   (at your option) any later version; incorporated herein by reference.
11  *
12  * ----------------------------------------------------------------------- */
13
14 /*
15  * syslinux.c - Linux installer program for SYSLINUX
16  *
17  * Hacked up for DOS.
18  */
19
20 #include <errno.h>
21 #include <getopt.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include "mystuff.h"
27
28 #include "syslinux.h"
29 #include "libfat.h"
30 #include "setadv.h"
31 #include "sysexits.h"
32 #include "syslxopt.h"
33 #include "syslxint.h"
34
35 char *program = "syslinux.com";         /* Name of program */
36 uint16_t dos_version;
37
38 #ifdef DEBUG
39 # define dprintf printf
40 void pause(void)
41 {
42     uint16_t ax;
43     
44     asm volatile("int $0x16" : "=a" (ax) : "a" (0));
45 }
46 #else
47 # define dprintf(...) ((void)0)
48 # define pause() ((void)0)
49 #endif
50
51 void unlock_device(int);
52
53 void __attribute__ ((noreturn)) die(const char *msg)
54 {
55     unlock_device(0);
56     puts("syslinux: ");
57     puts(msg);
58     putchar('\n');
59     exit(1);
60 }
61
62 void warning(const char *msg)
63 {
64     puts("syslinux: warning: ");
65     puts(msg);
66     putchar('\n');
67 }
68
69 /*
70  * read/write wrapper functions
71  */
72 int creat(const char *filename, int mode)
73 {
74     uint16_t rv;
75     uint8_t err;
76
77     dprintf("creat(\"%s\", 0x%x)\n", filename, mode);
78
79     rv = 0x3C00;
80     asm volatile ("int $0x21 ; setc %0"
81                   : "=bcdm" (err), "+a" (rv)
82                   : "c" (mode), "d" (filename));
83     if (err) {
84         dprintf("rv = %d\n", rv);
85         die("cannot open ldlinux.sys");
86     }
87
88     return rv;
89 }
90
91 void close(int fd)
92 {
93     uint16_t rv = 0x3E00;
94
95     dprintf("close(%d)\n", fd);
96
97     asm volatile ("int $0x21":"+a" (rv)
98                   :"b"(fd));
99
100     /* The only error MS-DOS returns for close is EBADF,
101        and we really don't care... */
102 }
103
104 int rename(const char *oldname, const char *newname)
105 {
106     uint16_t rv = 0x5600;       /* Also support 43FFh? */
107     uint8_t err;
108
109     dprintf("rename(\"%s\", \"%s\")\n", oldname, newname);
110
111     asm volatile ("int $0x21 ; setc %0":"=bcdm" (err), "+a"(rv)
112                   :"d"(oldname), "D"(newname));
113
114     if (err) {
115         dprintf("rv = %d\n", rv);
116         warning("cannot move ldlinux.sys");
117         return rv;
118     }
119
120     return 0;
121 }
122
123 ssize_t write_ldlinux(int fd)
124 {
125     uint16_t ldlinux_seg = ((size_t)syslinux_ldlinux >> 4) + ds();
126     uint32_t offset = 0;
127     uint16_t rv;
128     uint8_t err;
129
130     while (offset < syslinux_ldlinux_len) {
131         uint32_t chunk = syslinux_ldlinux_len - offset;
132         if (chunk > 32768)
133             chunk = 32768;
134         asm volatile ("pushw %%ds ; "
135                       "movw %6,%%ds ; "
136                       "int $0x21 ; "
137                       "popw %%ds ; " "setc %0":"=bcdm" (err), "=a"(rv)
138                       :"a"(0x4000), "b"(fd), "c"(chunk), "d" (offset & 15),
139                       "SD" ((uint16_t)(ldlinux_seg + (offset >> 4))));
140         if (err || rv == 0)
141             die("file write error");
142         offset += rv;
143     }
144
145     return offset;
146 }
147
148 ssize_t write_file(int fd, const void *buf, size_t count)
149 {
150     uint16_t rv;
151     ssize_t done = 0;
152     uint8_t err;
153
154     dprintf("write_file(%d,%p,%u)\n", fd, buf, count);
155
156     while (count) {
157         asm volatile ("int $0x21 ; setc %0":"=bcdm" (err), "=a"(rv)
158                       :"a"(0x4000), "b"(fd), "c"(count), "d"(buf));
159         if (err || rv == 0)
160             die("file write error");
161
162         done += rv;
163         count -= rv;
164     }
165
166     return done;
167 }
168
169 static inline __attribute__ ((const))
170 uint16_t data_segment(void)
171 {
172     uint16_t ds;
173
174     asm("movw %%ds,%0" : "=rm"(ds));
175     return ds;
176 }
177
178 void write_device(int drive, const void *buf, size_t nsecs, unsigned int sector)
179 {
180     uint16_t errnum = 0x0001;
181     struct diskio dio;
182
183     dprintf("write_device(%d,%p,%u,%u)\n", drive, buf, nsecs, sector);
184
185     dio.startsector = sector;
186     dio.sectors = nsecs;
187     dio.bufoffs = (uintptr_t) buf;
188     dio.bufseg = data_segment();
189     
190     if (dos_version >= 0x070a) {
191         /* Try FAT32-aware system call first */
192         asm volatile("int $0x21 ; jc 1f ; xorw %0,%0\n"
193                      "1:"
194                      : "=a" (errnum)
195                      : "a" (0x7305), "b" (&dio), "c" (-1), "d" (drive),
196                        "S" (1), "m" (dio)
197                      : "memory");
198         dprintf(" rv(7305) = %04x", errnum);
199     }
200
201     /* If not supported, try the legacy system call (int2526.S) */
202     if (errnum == 0x0001)
203         errnum = int26_write_sector(drive, &dio);
204
205     if (errnum) {
206         dprintf("rv = %04x\n", errnum);
207         die("sector write error");
208     }
209 }
210
211 void read_device(int drive, void *buf, size_t nsecs, unsigned int sector)
212 {
213     uint16_t errnum = 0x0001;
214     struct diskio dio;
215
216     dprintf("read_device(%d,%p,%u,%u)\n", drive, buf, nsecs, sector);
217
218     dio.startsector = sector;
219     dio.sectors = nsecs;
220     dio.bufoffs = (uintptr_t) buf;
221     dio.bufseg = data_segment();
222     
223     if (dos_version >= 0x070a) {
224         /* Try FAT32-aware system call first */
225         asm volatile("int $0x21 ; jc 1f ; xorw %0,%0\n"
226                      "1:"
227                      : "=a" (errnum)
228                      : "a" (0x7305), "b" (&dio), "c" (-1), "d" (drive),
229                        "S" (0), "m" (dio));
230         dprintf(" rv(7305) = %04x", errnum);
231     }
232
233     /* If not supported, try the legacy system call (int2526.S) */
234     if (errnum == 0x0001)
235         errnum = int25_read_sector(drive, &dio);
236
237     if (errnum) {
238         dprintf("rv = %04x\n", errnum);
239         die("sector read error");
240     }
241 }
242
243 /* Both traditional DOS and FAT32 DOS return this structure, but
244    FAT32 return a lot more data, so make sure we have plenty of space */
245 struct deviceparams {
246     uint8_t specfunc;
247     uint8_t devtype;
248     uint16_t devattr;
249     uint16_t cylinders;
250     uint8_t mediatype;
251     uint16_t bytespersec;
252     uint8_t secperclust;
253     uint16_t ressectors;
254     uint8_t fats;
255     uint16_t rootdirents;
256     uint16_t sectors;
257     uint8_t media;
258     uint16_t fatsecs;
259     uint16_t secpertrack;
260     uint16_t heads;
261     uint32_t hiddensecs;
262     uint32_t hugesectors;
263     uint8_t lotsofpadding[224];
264 } __attribute__ ((packed));
265
266 uint32_t get_partition_offset(int drive)
267 {
268     uint8_t err;
269     uint16_t rv;
270     struct deviceparams dp;
271
272     dp.specfunc = 1;            /* Get current information */
273
274     rv = 0x440d;
275     asm volatile ("int $0x21 ; setc %0"
276                   :"=abcdm" (err), "+a"(rv), "=m"(dp)
277                   :"b" (drive), "c" (0x0860), "d" (&dp));
278
279     if (!err)
280         return dp.hiddensecs;
281
282     rv = 0x440d;
283     asm volatile ("int $0x21 ; setc %0"
284                   : "=abcdm" (err), "+a" (rv), "=m" (dp)
285                   : "b" (drive), "c" (0x4860), "d" (&dp));
286
287     if (!err)
288         return dp.hiddensecs;
289
290     die("could not find partition start offset");
291 }
292
293 struct rwblock {
294     uint8_t special;
295     uint16_t head;
296     uint16_t cylinder;
297     uint16_t firstsector;
298     uint16_t sectors;
299     uint16_t bufferoffset;
300     uint16_t bufferseg;
301 } __attribute__ ((packed));
302
303 static struct rwblock mbr = {
304     .special = 0,
305     .head = 0,
306     .cylinder = 0,
307     .firstsector = 0,           /* MS-DOS, unlike the BIOS, zero-base sectors */
308     .sectors = 1,
309     .bufferoffset = 0,
310     .bufferseg = 0
311 };
312
313 void write_mbr(int drive, const void *buf)
314 {
315     uint16_t rv;
316     uint8_t err;
317
318     dprintf("write_mbr(%d,%p)", drive, buf);
319
320     mbr.bufferoffset = (uintptr_t) buf;
321     mbr.bufferseg = data_segment();
322
323     rv = 0x440d;
324     asm volatile ("int $0x21 ; setc %0" : "=bcdm" (err), "+a"(rv)
325                   :"c"(0x0841), "d"(&mbr), "b"(drive), "m"(mbr));
326
327     dprintf(" rv(0841) = %04x", rv);
328     if (!err) {
329         dprintf("\n");
330         return;
331     }
332
333     rv = 0x440d;
334     asm volatile ("int $0x21 ; setc %0" : "=bcdm" (err), "+a"(rv)
335                   :"c"(0x4841), "d"(&mbr), "b"(drive), "m"(mbr));
336
337     dprintf(" rv(4841) = %04x\n", rv);
338     if (err)
339         die("mbr write error");
340 }
341
342 void read_mbr(int drive, const void *buf)
343 {
344     uint16_t rv;
345     uint8_t err;
346
347     dprintf("read_mbr(%d,%p)", drive, buf);
348
349     mbr.bufferoffset = (uintptr_t) buf;
350     mbr.bufferseg = data_segment();
351
352     rv = 0x440d;
353     asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv)
354                   :"c"(0x0861), "d"(&mbr), "b"(drive), "m"(mbr));
355
356     dprintf(" rv(0861) = %04x", rv);
357     if (!err) {
358         dprintf("\n");
359         return;
360     }
361
362     rv = 0x440d;
363     asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv)
364                   :"c"(0x4861), "d"(&mbr), "b"(drive), "m"(mbr));
365
366     dprintf(" rv(4841) = %04x\n", rv);
367     if (err)
368         die("mbr read error");
369
370     dprintf("Bytes: %02x %02x %02x %02x %02x %02x %02x %02x\n",
371             ((const uint8_t *)buf)[0],
372             ((const uint8_t *)buf)[1],
373             ((const uint8_t *)buf)[2],
374             ((const uint8_t *)buf)[3],
375             ((const uint8_t *)buf)[4],
376             ((const uint8_t *)buf)[5],
377             ((const uint8_t *)buf)[6],
378             ((const uint8_t *)buf)[7]);
379 }
380
381 /* This call can legitimately fail, and we don't care, so ignore error return */
382 void set_attributes(const char *file, int attributes)
383 {
384     uint16_t rv = 0x4301;
385
386     dprintf("set_attributes(\"%s\", 0x%02x)\n", file, attributes);
387
388     asm volatile ("int $0x21":"+a" (rv)
389                   :"c"(attributes), "d"(file));
390 }
391
392 /*
393  * Version of the read_device function suitable for libfat
394  */
395 int libfat_xpread(intptr_t pp, void *buf, size_t secsize,
396                   libfat_sector_t sector)
397 {
398     read_device(pp, buf, 1, sector);
399     return secsize;
400 }
401
402 static inline void get_dos_version(void)
403 {
404     uint16_t ver;
405
406     asm("int $0x21 ; xchgb %%ah,%%al"
407         : "=a" (ver) 
408         : "a" (0x3001)
409         : "ebx", "ecx");
410     dos_version = ver;
411
412     dprintf("DOS version %d.%d\n", (dos_version >> 8), dos_version & 0xff);
413 }
414
415 /* The locking interface relies on static variables.  A massive hack :( */
416 static uint8_t lock_level, lock_drive;
417
418 static inline void set_lock_device(uint8_t device)
419 {
420     lock_level  = 0;
421     lock_drive = device;
422 }
423
424 static int do_lock(uint8_t level)
425 {
426     uint16_t level_arg = lock_drive + (level << 8);
427     uint16_t rv;
428     uint8_t err;
429 #if 0
430     /* DOS 7.10 = Win95 OSR2 = first version with FAT32 */
431     uint16_t lock_call = (dos_version >= 0x070a) ? 0x484A : 0x084A;
432 #else
433     uint16_t lock_call = 0x084A; /* MSDN says this is OK for all filesystems */
434 #endif
435
436     dprintf("Trying lock %04x... ", level_arg);
437     asm volatile ("int $0x21 ; setc %0"
438                   : "=bcdm" (err), "=a" (rv)
439                   : "a" (0x440d), "b" (level_arg),
440                     "c" (lock_call), "d" (0x0001));
441     dprintf("%s %04x\n", err ? "err" : "ok", rv);
442
443     return err ? rv : 0;
444 }
445
446 void lock_device(int level)
447 {
448     static int hard_lock = 0;
449     int err;
450
451     if (dos_version < 0x0700)
452         return;                 /* Win9x/NT only */
453
454     if (!hard_lock) {
455         /* Assume hierarchial "soft" locking supported */
456
457         while (lock_level < level) {
458             int new_level = lock_level + 1;
459             err = do_lock(new_level);
460             if (err) {
461                 if (err == 0x0001) {
462                     /* Try hard locking next */
463                     hard_lock = 1;
464                 }
465                 goto soft_fail;
466             }
467
468             lock_level = new_level;
469         }
470         return;
471     }
472
473 soft_fail:
474     if (hard_lock) {
475         /* Hard locking, only level 4 supported */
476         /* This is needed for Win9x in DOS mode */
477         
478         err = do_lock(4);
479         if (err) {
480             if (err == 0x0001) {
481                 /* Assume locking is not needed */
482                 return;
483             }
484             goto hard_fail;
485         }
486
487         lock_level = 4;
488         return;
489     }
490
491 hard_fail:
492     die("could not lock device");
493 }
494
495 void unlock_device(int level)
496 {
497     uint16_t rv;
498     uint8_t err;
499     uint16_t unlock_call;
500
501     if (dos_version < 0x0700)
502         return;                 /* Win9x/NT only */
503
504 #if 0
505     /* DOS 7.10 = Win95 OSR2 = first version with FAT32 */
506     unlock_call = (dos_version >= 0x070a) ? 0x486A : 0x086A;
507 #else
508     unlock_call = 0x086A;       /* MSDN says this is OK for all filesystems */
509 #endif
510
511     if (lock_level == 4 && level > 0)
512         return;                 /* Only drop the hard lock at the end */
513
514     while (lock_level > level) {
515         uint8_t new_level = (lock_level == 4) ? 0 : lock_level - 1;
516         uint16_t level_arg = (new_level << 8) + lock_drive;
517         rv = 0x440d;
518         dprintf("Trying unlock %04x... ", new_level);
519         asm volatile ("int $0x21 ; setc %0"
520                       : "=bcdm" (err), "+a" (rv)
521                       : "b" (level_arg), "c" (unlock_call));
522         dprintf("%s %04x\n", err ? "err" : "ok", rv);
523         lock_level = new_level;
524     }
525 }
526
527 /*
528  * This function does any desired MBR manipulation; called with the device lock held.
529  */
530 struct mbr_entry {
531     uint8_t active;             /* Active flag */
532     uint8_t bhead;              /* Begin head */
533     uint8_t bsector;            /* Begin sector */
534     uint8_t bcylinder;          /* Begin cylinder */
535     uint8_t filesystem;         /* Filesystem value */
536     uint8_t ehead;              /* End head */
537     uint8_t esector;            /* End sector */
538     uint8_t ecylinder;          /* End cylinder */
539     uint32_t startlba;          /* Start sector LBA */
540     uint32_t sectors;           /* Length in sectors */
541 } __attribute__ ((packed));
542
543 static void adjust_mbr(int device, int writembr, int set_active)
544 {
545     static unsigned char sectbuf[SECTOR_SIZE];
546     int i;
547
548     if (!writembr && !set_active)
549         return;                 /* Nothing to do */
550
551     read_mbr(device, sectbuf);
552
553     if (writembr) {
554         memcpy(sectbuf, syslinux_mbr, syslinux_mbr_len);
555         *(uint16_t *) (sectbuf + 510) = 0xaa55;
556     }
557
558     if (set_active) {
559         uint32_t offset = get_partition_offset(device);
560         struct mbr_entry *me = (struct mbr_entry *)(sectbuf + 446);
561         int found = 0;
562
563         dprintf("Searching for partition offset: %08x\n", offset);
564
565         for (i = 0; i < 4; i++) {
566             if (me->startlba == offset) {
567                 me->active = 0x80;
568                 found++;
569             } else {
570                 me->active = 0;
571             }
572             me++;
573         }
574
575         if (found < 1) {
576             die("partition not found (-a is not implemented for logical partitions)");
577         } else if (found > 1) {
578             die("multiple aliased partitions found");
579         }
580     }
581
582     write_mbr(device, sectbuf);
583 }
584
585 int main(int argc, char *argv[])
586 {
587     static unsigned char sectbuf[SECTOR_SIZE];
588     int dev_fd, fd;
589     static char ldlinux_name[] = "@:\\ldlinux.sys";
590     struct libfat_filesystem *fs;
591     libfat_sector_t s, *secp;
592     libfat_sector_t *sectors;
593     int ldlinux_sectors;
594     int32_t ldlinux_cluster;
595     int nsectors;
596     const char *errmsg;
597     int i;
598     int patch_sectors;
599     unsigned char *dp;
600
601     dprintf("argv = %p\n", argv);
602     for (i = 0; i <= argc; i++)
603         dprintf("argv[%d] = %p = \"%s\"\n", i, argv[i], argv[i]);
604
605     get_dos_version();
606
607     argv[0] = program;
608     parse_options(argc, argv, MODE_SYSLINUX_DOSWIN);
609
610     if (!opt.device)
611         usage(EX_USAGE, MODE_SYSLINUX_DOSWIN);
612     if (opt.sectors || opt.heads || opt.reset_adv || opt.set_once
613         || (opt.update_only > 0) || opt.menu_save || opt.offset) {
614         fprintf(stderr,
615                 "At least one specified option not yet implemented"
616                 " for this installer.\n");
617         exit(1);
618     }
619
620     /*
621      * Create an ADV in memory... this should be smarter.
622      */
623     syslinux_reset_adv(syslinux_adv);
624
625     /*
626      * Figure out which drive we're talking to
627      */
628     dev_fd = (opt.device[0] & ~0x20) - 0x40;
629     if (dev_fd < 1 || dev_fd > 26 || opt.device[1] != ':' || opt.device[2])
630         usage(EX_USAGE, MODE_SYSLINUX_DOSWIN);
631
632     set_lock_device(dev_fd);
633
634     lock_device(2);             /* Make sure we can lock the device */
635     read_device(dev_fd, sectbuf, 1, 0);
636     unlock_device(1);
637
638     /*
639      * Check to see that what we got was indeed an MS-DOS boot sector/superblock
640      */
641     if ((errmsg = syslinux_check_bootsect(sectbuf))) {
642         unlock_device(0);
643         puts(errmsg);
644         putchar('\n');
645         exit(1);
646     }
647
648     ldlinux_name[0] = dev_fd | 0x40;
649
650     set_attributes(ldlinux_name, 0);
651     fd = creat(ldlinux_name, 0);        /* SYSTEM HIDDEN READONLY */
652     write_ldlinux(fd);
653     write_file(fd, syslinux_adv, 2 * ADV_SIZE);
654     close(fd);
655     set_attributes(ldlinux_name, 0x07); /* SYSTEM HIDDEN READONLY */
656
657     /*
658      * Now, use libfat to create a block map.  This probably
659      * should be changed to use ioctl(...,FIBMAP,...) since
660      * this is supposed to be a simple, privileged version
661      * of the installer.
662      */
663     ldlinux_sectors = (syslinux_ldlinux_len + 2 * ADV_SIZE
664                        + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
665     sectors = calloc(ldlinux_sectors, sizeof *sectors);
666     lock_device(2);
667     fs = libfat_open(libfat_xpread, dev_fd);
668     ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
669     secp = sectors;
670     nsectors = 0;
671     s = libfat_clustertosector(fs, ldlinux_cluster);
672     while (s && nsectors < ldlinux_sectors) {
673         *secp++ = s;
674         nsectors++;
675         s = libfat_nextsector(fs, s);
676     }
677     libfat_close(fs);
678
679     /*
680      * If requested, move ldlinux.sys
681      */
682     if (opt.directory) {
683         char new_ldlinux_name[160];
684         char *cp = new_ldlinux_name + 3;
685         const char *sd;
686         int slash = 1;
687
688         new_ldlinux_name[0] = dev_fd | 0x40;
689         new_ldlinux_name[1] = ':';
690         new_ldlinux_name[2] = '\\';
691
692         for (sd = opt.directory; *sd; sd++) {
693             char c = *sd;
694
695             if (c == '/' || c == '\\') {
696                 if (slash)
697                     continue;
698                 c = '\\';
699                 slash = 1;
700             } else {
701                 slash = 0;
702             }
703
704             *cp++ = c;
705         }
706
707         /* Skip if subdirectory == root */
708         if (cp > new_ldlinux_name + 3) {
709             if (!slash)
710                 *cp++ = '\\';
711
712             memcpy(cp, "ldlinux.sys", 12);
713
714             set_attributes(ldlinux_name, 0);
715             if (rename(ldlinux_name, new_ldlinux_name))
716                 set_attributes(ldlinux_name, 0x07);
717             else
718                 set_attributes(new_ldlinux_name, 0x07);
719         }
720     }
721
722     /*
723      * Patch ldlinux.sys and the boot sector
724      */
725     i = syslinux_patch(sectors, nsectors, opt.stupid_mode, opt.raid_mode, opt.directory, NULL);
726     patch_sectors = (i + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
727
728     /*
729      * Overwrite the now-patched ldlinux.sys
730      */
731     /* lock_device(3); -- doesn't seem to be needed */
732     dp = syslinux_ldlinux;
733     for (i = 0; i < patch_sectors; i++) {
734         memcpy_from_sl(sectbuf, dp, SECTOR_SIZE);
735         dp += SECTOR_SIZE;
736         write_device(dev_fd, sectbuf, 1, sectors[i]);
737     }
738
739     /*
740      * Muck with the MBR, if desired, while we hold the lock
741      */
742     adjust_mbr(dev_fd, opt.install_mbr, opt.activate_partition);
743
744     /*
745      * To finish up, write the boot sector
746      */
747
748     /* Read the superblock again since it might have changed while mounted */
749     read_device(dev_fd, sectbuf, 1, 0);
750
751     /* Copy the syslinux code into the boot sector */
752     syslinux_make_bootsect(sectbuf);
753
754     /* Write new boot sector */
755     if (opt.bootsecfile) {
756         unlock_device(0);
757         fd = creat(opt.bootsecfile, 0x20);      /* ARCHIVE */
758         write_file(fd, sectbuf, SECTOR_SIZE);
759         close(fd);
760     } else {
761         write_device(dev_fd, sectbuf, 1, 0);
762         unlock_device(0);
763     }
764
765     /* Done! */
766
767     return 0;
768 }