Implement guestfish -f option to allow guestfish scripts.
[libguestfs.git] / fish / fish.c
1 /* guestfish - the filesystem interactive shell
2  * Copyright (C) 2009 Red Hat Inc. 
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <config.h>
20
21 #define _GNU_SOURCE // for strchrnul
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #include <getopt.h>
29 #include <signal.h>
30 #include <assert.h>
31 #include <ctype.h>
32
33 #ifdef HAVE_LIBREADLINE
34 #include <readline/readline.h>
35 #include <readline/history.h>
36 #endif
37
38 #include <guestfs.h>
39
40 #include "fish.h"
41
42 struct mp {
43   struct mp *next;
44   char *device;
45   char *mountpoint;
46 };
47
48 struct drv {
49   struct drv *next;
50   char *filename;
51 };
52
53 static void add_drives (struct drv *drv);
54 static void mount_mps (struct mp *mp);
55 static void interactive (void);
56 static void shell_script (void);
57 static void script (int prompt);
58 static void cmdline (char *argv[], int optind, int argc);
59 static void initialize_readline (void);
60 static void cleanup_readline (void);
61 static void add_history_line (const char *);
62
63 /* Currently open libguestfs handle. */
64 guestfs_h *g;
65
66 int read_only = 0;
67 int quit = 0;
68 int verbose = 0;
69
70 int
71 launch (guestfs_h *_g)
72 {
73   assert (_g == g);
74
75   if (guestfs_is_config (g)) {
76     if (guestfs_launch (g) == -1)
77       return -1;
78     if (guestfs_wait_ready (g) == -1)
79       return -1;
80   }
81   return 0;
82 }
83
84 static void
85 usage (void)
86 {
87   fprintf (stderr,
88            _("guestfish: guest filesystem shell\n"
89              "guestfish lets you edit virtual machine filesystems\n"
90              "Copyright (C) 2009 Red Hat Inc.\n"
91              "Usage:\n"
92              "  guestfish [--options] cmd [: cmd : cmd ...]\n"
93              "or for interactive use:\n"
94              "  guestfish\n"
95              "or from a shell script:\n"
96              "  guestfish <<EOF\n"
97              "  cmd\n"
98              "  ...\n"
99              "  EOF\n"
100              "Options:\n"
101              "  -h|--cmd-help        List available commands\n"
102              "  -h|--cmd-help cmd    Display detailed help on 'cmd'\n"
103              "  -a|--add image       Add image\n"
104              "  -D|--no-dest-paths   Don't tab-complete paths from guest fs\n"
105              "  -f|--file file       Read commands from file\n"
106              "  -m|--mount dev[:mnt] Mount dev on mnt (if omitted, /)\n"
107              "  -n|--no-sync         Don't autosync\n"
108              "  -r|--ro              Mount read-only\n"
109              "  -v|--verbose         Verbose messages\n"
110              "  -V|--version         Display version and exit\n"
111              "For more information,  see the manpage guestfish(1).\n"));
112 }
113
114 int
115 main (int argc, char *argv[])
116 {
117   static const char *options = "a:f:h::m:nrv?V";
118   static struct option long_options[] = {
119     { "add", 1, 0, 'a' },
120     { "cmd-help", 2, 0, 'h' },
121     { "file", 1, 0, 'f' },
122     { "help", 0, 0, '?' },
123     { "mount", 1, 0, 'm' },
124     { "no-dest-paths", 0, 0, 'D' },
125     { "no-sync", 0, 0, 'n' },
126     { "ro", 0, 0, 'r' },
127     { "verbose", 0, 0, 'v' },
128     { "version", 0, 0, 'V' },
129     { 0, 0, 0, 0 }
130   };
131   struct drv *drvs = NULL;
132   struct drv *drv;
133   struct mp *mps = NULL;
134   struct mp *mp;
135   char *p, *file = NULL;
136   int c;
137
138   initialize_readline ();
139
140   /* guestfs_create is meant to be a lightweight operation, so
141    * it's OK to do it early here.
142    */
143   g = guestfs_create ();
144   if (g == NULL) {
145     fprintf (stderr, _("guestfs_create: failed to create handle\n"));
146     exit (1);
147   }
148
149   guestfs_set_autosync (g, 1);
150
151   /* If developing, add ./appliance to the path.  Note that libtools
152    * interferes with this because uninstalled guestfish is a shell
153    * script that runs the real program with an absolute path.  Detect
154    * that too.
155    *
156    * BUT if LIBGUESTFS_PATH environment variable is already set by
157    * the user, then don't override it.
158    */
159   if (getenv ("LIBGUESTFS_PATH") == NULL &&
160       argv[0] &&
161       (argv[0][0] != '/' || strstr (argv[0], "/.libs/lt-") != NULL))
162     guestfs_set_path (g, "appliance:" GUESTFS_DEFAULT_PATH);
163
164   for (;;) {
165     c = getopt_long (argc, argv, options, long_options, NULL);
166     if (c == -1) break;
167
168     switch (c) {
169     case 'a':
170       if (access (optarg, R_OK) != 0) {
171         perror (optarg);
172         exit (1);
173       }
174       drv = malloc (sizeof (struct drv));
175       if (!drv) {
176         perror ("malloc");
177         exit (1);
178       }
179       drv->filename = optarg;
180       drv->next = drvs;
181       drvs = drv;
182       break;
183
184     case 'D':
185       complete_dest_paths = 0;
186       break;
187
188     case 'f':
189       if (file) {
190         fprintf (stderr, _("guestfish: only one -f parameter can be given\n"));
191         exit (1);
192       }
193       file = optarg;
194       break;
195
196     case 'h':
197       if (optarg)
198         display_command (optarg);
199       else if (argv[optind] && argv[optind][0] != '-')
200         display_command (argv[optind++]);
201       else
202         list_commands ();
203       exit (0);
204
205     case 'm':
206       mp = malloc (sizeof (struct mp));
207       if (!mp) {
208         perror ("malloc");
209         exit (1);
210       }
211       p = strchr (optarg, ':');
212       if (p) {
213         *p = '\0';
214         mp->mountpoint = p+1;
215       } else
216         mp->mountpoint = "/";
217       mp->device = optarg;
218       mp->next = mps;
219       mps = mp;
220       break;
221
222     case 'n':
223       guestfs_set_autosync (g, 0);
224       break;
225
226     case 'r':
227       read_only = 1;
228       break;
229
230     case 'v':
231       verbose++;
232       guestfs_set_verbose (g, verbose);
233       break;
234
235     case 'V':
236       printf ("guestfish %s\n", PACKAGE_VERSION);
237       exit (0);
238
239     case '?':
240       usage ();
241       exit (0);
242
243     default:
244       fprintf (stderr, _("guestfish: unexpected command line option 0x%x\n"),
245                c);
246       exit (1);
247     }
248   }
249
250   /* If we've got drives to add, add them now. */
251   add_drives (drvs);
252
253   /* If we've got mountpoints, we must launch the guest and mount them. */
254   if (mps != NULL) {
255     if (launch (g) == -1) exit (1);
256     mount_mps (mps);
257   }
258
259   /* -f (file) parameter? */
260   if (file) {
261     close (0);
262     if (open (file, O_RDONLY) == -1) {
263       perror (file);
264       exit (1);
265     }
266   }
267
268   /* Interactive, shell script, or command(s) on the command line? */
269   if (optind >= argc) {
270     if (isatty (0))
271       interactive ();
272     else
273       shell_script ();
274   }
275   else
276     cmdline (argv, optind, argc);
277
278   cleanup_readline ();
279
280   exit (0);
281 }
282
283 void
284 pod2text (const char *heading, const char *str)
285 {
286   FILE *fp;
287
288   fp = popen ("pod2text", "w");
289   if (fp == NULL) {
290     /* pod2text failed, maybe not found, so let's just print the
291      * source instead, since that's better than doing nothing.
292      */
293     printf ("%s\n\n%s\n", heading, str);
294     return;
295   }
296   fputs ("=head1 ", fp);
297   fputs (heading, fp);
298   fputs ("\n\n", fp);
299   fputs (str, fp);
300   pclose (fp);
301 }
302
303 /* List is built in reverse order, so mount them in reverse order. */
304 static void
305 mount_mps (struct mp *mp)
306 {
307   int r;
308
309   if (mp) {
310     mount_mps (mp->next);
311     if (!read_only)
312       r = guestfs_mount (g, mp->device, mp->mountpoint);
313     else
314       r = guestfs_mount_ro (g, mp->device, mp->mountpoint);
315     if (r == -1)
316       exit (1);
317   }
318 }
319
320 static void
321 add_drives (struct drv *drv)
322 {
323   int r;
324
325   if (drv) {
326     add_drives (drv->next);
327     if (!read_only)
328       r = guestfs_add_drive (g, drv->filename);
329     else
330       r = guestfs_add_drive_ro (g, drv->filename);
331     if (r == -1)
332       exit (1);
333   }
334 }
335
336 static void
337 interactive (void)
338 {
339   script (1);
340 }
341
342 static void
343 shell_script (void)
344 {
345   script (0);
346 }
347
348 #define FISH "><fs> "
349
350 static char *line_read = NULL;
351
352 static char *
353 rl_gets (int prompt)
354 {
355 #ifdef HAVE_LIBREADLINE
356
357   if (prompt) {
358     if (line_read) {
359       free (line_read);
360       line_read = NULL;
361     }
362
363     line_read = readline (prompt ? FISH : "");
364
365     if (line_read && *line_read)
366       add_history_line (line_read);
367
368     return line_read;
369   }
370
371 #endif /* HAVE_LIBREADLINE */
372
373   static char buf[8192];
374   int len;
375
376   if (prompt) printf (FISH);
377   line_read = fgets (buf, sizeof buf, stdin);
378
379   if (line_read) {
380     len = strlen (line_read);
381     if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0';
382   }
383
384   return line_read;
385 }
386
387 static void
388 script (int prompt)
389 {
390   char *buf;
391   char *cmd;
392   char *p, *pend;
393   char *argv[64];
394   int i, len;
395   int global_exit_on_error = !prompt;
396   int exit_on_error;
397
398   if (prompt)
399     printf (_("\n"
400               "Welcome to guestfish, the libguestfs filesystem interactive shell for\n"
401               "editing virtual machine filesystems.\n"
402               "\n"
403               "Type: 'help' for help with commands\n"
404               "      'quit' to quit the shell\n"
405               "\n"));
406
407   while (!quit) {
408     exit_on_error = global_exit_on_error;
409
410     buf = rl_gets (prompt);
411     if (!buf) {
412       quit = 1;
413       break;
414     }
415
416     /* Skip any initial whitespace before the command. */
417   again:
418     while (*buf && isspace (*buf))
419       buf++;
420
421     if (!*buf) continue;
422
423     /* If the next character is '#' then this is a comment. */
424     if (*buf == '#') continue;
425
426     /* If the next character is '!' then pass the whole lot to system(3). */
427     if (*buf == '!') {
428       int r;
429
430       r = system (buf+1);
431       if (exit_on_error) {
432         if (r == -1 ||
433             (WIFSIGNALED (r) &&
434              (WTERMSIG (r) == SIGINT || WTERMSIG (r) == SIGQUIT)) ||
435             WEXITSTATUS (r) != 0)
436           exit (1);
437       }
438       continue;
439     }
440
441     /* If the next character is '-' allow the command to fail without
442      * exiting on error (just for this one command though).
443      */
444     if (*buf == '-') {
445       exit_on_error = 0;
446       buf++;
447       goto again;
448     }
449
450     /* Get the command (cannot be quoted). */
451     len = strcspn (buf, " \t");
452
453     if (len == 0) continue;
454
455     cmd = buf;
456     i = 0;
457     if (buf[len] == '\0') {
458       argv[0] = NULL;
459       goto got_command;
460     }
461
462     buf[len] = '\0';
463     p = &buf[len+1];
464     p += strspn (p, " \t");
465
466     /* Get the parameters. */
467     while (*p && i < sizeof argv / sizeof argv[0]) {
468       /* Parameters which start with quotes or square brackets
469        * are treated specially.  Bare parameters are delimited
470        * by whitespace.
471        */
472       if (*p == '"') {
473         p++;
474         len = strcspn (p, "\"");
475         if (p[len] == '\0') {
476           fprintf (stderr, _("guestfish: unterminated double quote\n"));
477           if (exit_on_error) exit (1);
478           goto next_command;
479         }
480         if (p[len+1] && (p[len+1] != ' ' && p[len+1] != '\t')) {
481           fprintf (stderr, _("guestfish: command arguments not separated by whitespace\n"));
482           if (exit_on_error) exit (1);
483           goto next_command;
484         }
485         p[len] = '\0';
486         pend = p[len+1] ? &p[len+2] : &p[len+1];
487       } else if (*p == '\'') {
488         p++;
489         len = strcspn (p, "'");
490         if (p[len] == '\0') {
491           fprintf (stderr, _("guestfish: unterminated single quote\n"));
492           if (exit_on_error) exit (1);
493           goto next_command;
494         }
495         if (p[len+1] && (p[len+1] != ' ' && p[len+1] != '\t')) {
496           fprintf (stderr, _("guestfish: command arguments not separated by whitespace\n"));
497           if (exit_on_error) exit (1);
498           goto next_command;
499         }
500         p[len] = '\0';
501         pend = p[len+1] ? &p[len+2] : &p[len+1];
502         /*
503       } else if (*p == '[') {
504         int c = 1;
505         p++;
506         pend = p;
507         while (*pend && c != 0) {
508           if (*pend == '[') c++;
509           else if (*pend == ']') c--;
510           pend++;
511         }
512         if (c != 0) {
513           fprintf (stderr, _("guestfish: unterminated \"[...]\" sequence\n"));
514           if (exit_on_error) exit (1);
515           goto next_command;
516         }
517         if (*pend && (*pend != ' ' && *pend != '\t')) {
518           fprintf (stderr, _("guestfish: command arguments not separated by whitespace\n"));
519           if (exit_on_error) exit (1);
520           goto next_command;
521         }
522         *(pend-1) = '\0';
523         */
524       } else if (*p != ' ' && *p != '\t') {
525         len = strcspn (p, " \t");
526         if (p[len]) {
527           p[len] = '\0';
528           pend = &p[len+1];
529         } else
530           pend = &p[len];
531       } else {
532         fprintf (stderr, _("guestfish: internal error parsing string at '%s'\n"),
533                  p);
534         abort ();
535       }
536
537       argv[i++] = p;
538       p = pend;
539
540       if (*p)
541         p += strspn (p, " \t");
542     }
543
544     if (i == sizeof argv / sizeof argv[0]) {
545       fprintf (stderr, _("guestfish: too many arguments\n"));
546       if (exit_on_error) exit (1);
547       goto next_command;
548     }
549
550     argv[i] = NULL;
551
552   got_command:
553     if (issue_command (cmd, argv) == -1) {
554       if (exit_on_error) exit (1);
555     }
556
557   next_command:;
558   }
559   if (prompt) printf ("\n");
560 }
561
562 static void
563 cmdline (char *argv[], int optind, int argc)
564 {
565   const char *cmd;
566   char **params;
567
568   if (optind >= argc) return;
569
570   cmd = argv[optind++];
571   if (strcmp (cmd, ":") == 0) {
572     fprintf (stderr, _("guestfish: empty command on command line\n"));
573     exit (1);
574   }
575   params = &argv[optind];
576
577   /* Search for end of command list or ":" ... */
578   while (optind < argc && strcmp (argv[optind], ":") != 0)
579     optind++;
580
581   if (optind == argc) {
582     if (issue_command (cmd, params) == -1) exit (1);
583   } else {
584     argv[optind] = NULL;
585     if (issue_command (cmd, params) == -1) exit (1);
586     cmdline (argv, optind+1, argc);
587   }
588 }
589
590 int
591 issue_command (const char *cmd, char *argv[])
592 {
593   int argc;
594
595   for (argc = 0; argv[argc] != NULL; ++argc)
596     ;
597
598   if (strcasecmp (cmd, "help") == 0) {
599     if (argc == 0)
600       list_commands ();
601     else
602       display_command (argv[0]);
603     return 0;
604   }
605   else if (strcasecmp (cmd, "quit") == 0 ||
606            strcasecmp (cmd, "exit") == 0 ||
607            strcasecmp (cmd, "q") == 0) {
608     quit = 1;
609     return 0;
610   }
611   else if (strcasecmp (cmd, "alloc") == 0 ||
612            strcasecmp (cmd, "allocate") == 0)
613     return do_alloc (cmd, argc, argv);
614   else if (strcasecmp (cmd, "echo") == 0)
615     return do_echo (cmd, argc, argv);
616   else if (strcasecmp (cmd, "edit") == 0 ||
617            strcasecmp (cmd, "vi") == 0 ||
618            strcasecmp (cmd, "emacs") == 0)
619     return do_edit (cmd, argc, argv);
620   else if (strcasecmp (cmd, "lcd") == 0)
621     return do_lcd (cmd, argc, argv);
622   else if (strcasecmp (cmd, "glob") == 0)
623     return do_glob (cmd, argc, argv);
624   else
625     return run_action (cmd, argc, argv);
626 }
627
628 void
629 list_builtin_commands (void)
630 {
631   /* help and quit should appear at the top */
632   printf ("%-20s %s\n",
633           "help", _("display a list of commands or help on a command"));
634   printf ("%-20s %s\n",
635           "quit", _("quit guestfish"));
636
637   printf ("%-20s %s\n",
638           "alloc", _("allocate an image"));
639   printf ("%-20s %s\n",
640           "echo", _("display a line of text"));
641   printf ("%-20s %s\n",
642           "edit", _("edit a file in the image"));
643   printf ("%-20s %s\n",
644           "lcd", _("local change directory"));
645   printf ("%-20s %s\n",
646           "glob", _("expand wildcards in command"));
647
648   /* actions are printed after this (see list_commands) */
649 }
650
651 void
652 display_builtin_command (const char *cmd)
653 {
654   /* help for actions is auto-generated, see display_command */
655
656   if (strcasecmp (cmd, "alloc") == 0 ||
657       strcasecmp (cmd, "allocate") == 0)
658     printf (_("alloc - allocate an image\n"
659               "     alloc <filename> <size>\n"
660               "\n"
661               "    This creates an empty (zeroed) file of the given size,\n"
662               "    and then adds so it can be further examined.\n"
663               "\n"
664               "    For more advanced image creation, see qemu-img utility.\n"
665               "\n"
666               "    Size can be specified (where <nn> means a number):\n"
667               "    <nn>             number of kilobytes\n"
668               "      eg: 1440       standard 3.5\" floppy\n"
669               "    <nn>K or <nn>KB  number of kilobytes\n"
670               "    <nn>M or <nn>MB  number of megabytes\n"
671               "    <nn>G or <nn>GB  number of gigabytes\n"
672               "    <nn>sects        number of 512 byte sectors\n"));
673   else if (strcasecmp (cmd, "echo") == 0)
674     printf (_("echo - display a line of text\n"
675               "     echo [<params> ...]\n"
676               "\n"
677               "    This echos the parameters to the terminal.\n"));
678   else if (strcasecmp (cmd, "edit") == 0 ||
679            strcasecmp (cmd, "vi") == 0 ||
680            strcasecmp (cmd, "emacs") == 0)
681     printf (_("edit - edit a file in the image\n"
682               "     edit <filename>\n"
683               "\n"
684               "    This is used to edit a file.\n"
685               "\n"
686               "    It is the equivalent of (and is implemented by)\n"
687               "    running \"cat\", editing locally, and then \"write-file\".\n"
688               "\n"
689               "    Normally it uses $EDITOR, but if you use the aliases\n"
690               "    \"vi\" or \"emacs\" you will get those editors.\n"
691               "\n"
692               "    NOTE: This will not work reliably for large files\n"
693               "    (> 2 MB) or binary files containing \\0 bytes.\n"));
694   else if (strcasecmp (cmd, "lcd") == 0)
695     printf (_("lcd - local change directory\n"
696               "    lcd <directory>\n"
697               "\n"
698               "    Change guestfish's current directory. This command is\n"
699               "    useful if you want to download files to a particular\n"
700               "    place.\n"));
701   else if (strcasecmp (cmd, "glob") == 0)
702     printf (_("glob - expand wildcards in command\n"
703               "    glob <command> [<args> ...]\n"
704               "\n"
705               "    Glob runs <command> with wildcards expanded in any\n"
706               "    command args.  Note that the command is run repeatedly\n"
707               "    once for each expanded argument.\n"));
708   else if (strcasecmp (cmd, "help") == 0)
709     printf (_("help - display a list of commands or help on a command\n"
710               "     help cmd\n"
711               "     help\n"));
712   else if (strcasecmp (cmd, "quit") == 0 ||
713            strcasecmp (cmd, "exit") == 0 ||
714            strcasecmp (cmd, "q") == 0)
715     printf (_("quit - quit guestfish\n"
716               "     quit\n"));
717   else
718     fprintf (stderr, _("%s: command not known, use -h to list all commands\n"),
719              cmd);
720 }
721
722 void
723 free_strings (char **argv)
724 {
725   int argc;
726
727   for (argc = 0; argv[argc] != NULL; ++argc)
728     free (argv[argc]);
729   free (argv);
730 }
731
732 int
733 count_strings (char * const * const argv)
734 {
735   int c;
736
737   for (c = 0; argv[c]; ++c)
738     ;
739   return c;
740 }
741
742 void
743 print_strings (char * const * const argv)
744 {
745   int argc;
746
747   for (argc = 0; argv[argc] != NULL; ++argc)
748     printf ("%s\n", argv[argc]);
749 }
750
751 void
752 print_table (char * const * const argv)
753 {
754   int i;
755
756   for (i = 0; argv[i] != NULL; i += 2)
757     printf ("%s: %s\n", argv[i], argv[i+1]);
758 }
759
760 int
761 is_true (const char *str)
762 {
763   return
764     strcasecmp (str, "0") != 0 &&
765     strcasecmp (str, "f") != 0 &&
766     strcasecmp (str, "false") != 0 &&
767     strcasecmp (str, "n") != 0 &&
768     strcasecmp (str, "no") != 0;
769 }
770
771 /* XXX We could improve list parsing. */
772 char **
773 parse_string_list (const char *str)
774 {
775   char **argv;
776   const char *p, *pend;
777   int argc, i;
778
779   argc = 1;
780   for (i = 0; str[i]; ++i)
781     if (str[i] == ' ') argc++;
782
783   argv = malloc (sizeof (char *) * (argc+1));
784   if (argv == NULL) { perror ("malloc"); exit (1); }
785
786   p = str;
787   i = 0;
788   while (*p) {
789     pend = strchrnul (p, ' ');
790     argv[i] = strndup (p, pend-p);
791     i++;
792     p = *pend == ' ' ? pend+1 : pend;
793   }
794   argv[i] = NULL;
795
796   return argv;
797 }
798
799 #ifdef HAVE_LIBREADLINE
800 static char histfile[1024];
801 static int nr_history_lines = 0;
802 #endif
803
804 static void
805 initialize_readline (void)
806 {
807 #ifdef HAVE_LIBREADLINE
808   const char *home;
809
810   home = getenv ("HOME");
811   if (home) {
812     snprintf (histfile, sizeof histfile, "%s/.guestfish", home);
813     using_history ();
814     (void) read_history (histfile);
815   }
816
817   rl_readline_name = "guestfish";
818   rl_attempted_completion_function = do_completion;
819 #endif
820 }
821
822 static void
823 cleanup_readline (void)
824 {
825 #ifdef HAVE_LIBREADLINE
826   int fd;
827
828   if (histfile[0] != '\0') {
829     fd = open (histfile, O_WRONLY|O_CREAT, 0644);
830     if (fd == -1) {
831       perror (histfile);
832       return;
833     }
834     close (fd);
835
836     (void) append_history (nr_history_lines, histfile);
837   }
838 #endif
839 }
840
841 static void
842 add_history_line (const char *line)
843 {
844 #ifdef HAVE_LIBREADLINE
845   add_history (line);
846   nr_history_lines++;
847 #endif
848 }