11 #include <sys/mount.h>
13 #include <talloc/talloc.h>
14 #include <list/list.h>
16 #include <types/types.h>
17 #include <system/system.h>
18 #include <process/process.h>
20 #include <i18n/i18n.h>
22 #include <sys/types.h>
23 #include <sys/socket.h>
25 #include <arpa/inet.h>
27 #include "device-handler.h"
28 #include "discover-server.h"
29 #include "user-event.h"
40 struct device_handler {
41 struct discover_server *server;
45 struct network *network;
46 struct user_event *user_event;
48 struct discover_device **devices;
49 unsigned int n_devices;
51 struct waitset *waitset;
52 struct waiter *timeout_waiter;
53 bool autoboot_enabled;
54 unsigned int sec_to_boot;
56 struct discover_boot_option *default_boot_option;
57 struct list unresolved_boot_options;
59 struct boot_task *pending_boot;
60 bool pending_boot_is_default;
63 static int mount_device(struct discover_device *dev);
64 static int umount_device(struct discover_device *dev);
66 static int device_handler_init_sources(struct device_handler *handler);
67 static void device_handler_reinit_sources(struct device_handler *handler);
69 static void device_handler_update_lang(const char *lang);
71 void discover_context_add_boot_option(struct discover_context *ctx,
72 struct discover_boot_option *boot_option)
74 boot_option->source = ctx->parser;
75 list_add_tail(&ctx->boot_options, &boot_option->list);
76 talloc_steal(ctx, boot_option);
80 * device_handler_get_device_count - Get the count of current handler devices.
83 int device_handler_get_device_count(const struct device_handler *handler)
85 return handler->n_devices;
89 * device_handler_get_device - Get a handler device by index.
92 const struct discover_device *device_handler_get_device(
93 const struct device_handler *handler, unsigned int index)
95 if (index >= handler->n_devices) {
96 assert(0 && "bad index");
100 return handler->devices[index];
103 struct discover_boot_option *discover_boot_option_create(
104 struct discover_context *ctx,
105 struct discover_device *device)
107 struct discover_boot_option *opt;
109 opt = talloc_zero(ctx, struct discover_boot_option);
110 opt->option = talloc_zero(opt, struct boot_option);
111 opt->device = device;
116 static int device_match_uuid(struct discover_device *dev, const char *uuid)
118 return dev->uuid && !strcmp(dev->uuid, uuid);
121 static int device_match_label(struct discover_device *dev, const char *label)
123 return dev->label && !strcmp(dev->label, label);
126 static int device_match_id(struct discover_device *dev, const char *id)
128 return !strcmp(dev->device->id, id);
131 static int device_match_serial(struct discover_device *dev, const char *serial)
133 const char *val = discover_device_get_param(dev, "ID_SERIAL");
134 return val && !strcmp(val, serial);
137 static struct discover_device *device_lookup(
138 struct device_handler *device_handler,
139 int (match_fn)(struct discover_device *, const char *),
142 struct discover_device *dev;
148 for (i = 0; i < device_handler->n_devices; i++) {
149 dev = device_handler->devices[i];
151 if (match_fn(dev, str))
158 struct discover_device *device_lookup_by_name(struct device_handler *handler,
161 if (!strncmp(name, "/dev/", strlen("/dev/")))
162 name += strlen("/dev/");
164 return device_lookup_by_id(handler, name);
167 struct discover_device *device_lookup_by_uuid(
168 struct device_handler *device_handler,
171 return device_lookup(device_handler, device_match_uuid, uuid);
174 struct discover_device *device_lookup_by_label(
175 struct device_handler *device_handler,
178 return device_lookup(device_handler, device_match_label, label);
181 struct discover_device *device_lookup_by_id(
182 struct device_handler *device_handler,
185 return device_lookup(device_handler, device_match_id, id);
188 struct discover_device *device_lookup_by_serial(
189 struct device_handler *device_handler,
192 return device_lookup(device_handler, device_match_serial, serial);
195 void device_handler_destroy(struct device_handler *handler)
197 talloc_free(handler);
200 static int destroy_device(void *arg)
202 struct discover_device *dev = arg;
209 struct discover_device *discover_device_create(struct device_handler *handler,
212 struct discover_device *dev;
214 dev = device_lookup_by_id(handler, id);
218 dev = talloc_zero(handler, struct discover_device);
219 dev->device = talloc_zero(dev, struct device);
220 dev->device->id = talloc_strdup(dev->device, id);
221 list_init(&dev->params);
222 list_init(&dev->boot_options);
224 talloc_set_destructor(dev, destroy_device);
229 struct discover_device_param {
232 struct list_item list;
235 void discover_device_set_param(struct discover_device *device,
236 const char *name, const char *value)
238 struct discover_device_param *param;
241 list_for_each_entry(&device->params, param, list) {
242 if (!strcmp(param->name, name)) {
251 param = talloc(device, struct discover_device_param);
252 param->name = talloc_strdup(param, name);
253 list_add(&device->params, ¶m->list);
256 list_remove(¶m->list);
260 talloc_free(param->value);
263 param->value = talloc_strdup(param, value);
266 const char *discover_device_get_param(struct discover_device *device,
269 struct discover_device_param *param;
271 list_for_each_entry(&device->params, param, list) {
272 if (!strcmp(param->name, name))
278 struct device_handler *device_handler_init(struct discover_server *server,
279 struct waitset *waitset, int dry_run)
281 struct device_handler *handler;
284 handler = talloc_zero(NULL, struct device_handler);
285 handler->server = server;
286 handler->waitset = waitset;
287 handler->dry_run = dry_run;
288 handler->autoboot_enabled = config_get()->autoboot_enabled;
290 list_init(&handler->unresolved_boot_options);
292 /* set up our mount point base */
293 pb_mkdir_recursive(mount_base());
297 if (config_get()->safe_mode)
300 rc = device_handler_init_sources(handler);
302 talloc_free(handler);
309 void device_handler_reinit(struct device_handler *handler)
311 struct discover_boot_option *opt, *tmp;
314 device_handler_cancel_default(handler);
316 /* free unresolved boot options */
317 list_for_each_entry_safe(&handler->unresolved_boot_options,
320 list_init(&handler->unresolved_boot_options);
322 /* drop all devices */
323 for (i = 0; i < handler->n_devices; i++)
324 discover_server_notify_device_remove(handler->server,
325 handler->devices[i]->device);
327 talloc_free(handler->devices);
328 handler->devices = NULL;
329 handler->n_devices = 0;
331 device_handler_reinit_sources(handler);
334 void device_handler_remove(struct device_handler *handler,
335 struct discover_device *device)
337 struct discover_boot_option *opt, *tmp;
340 for (i = 0; i < handler->n_devices; i++)
341 if (handler->devices[i] == device)
344 if (i == handler->n_devices) {
349 /* Free any unresolved options, as they're currently allocated
350 * against the handler */
351 list_for_each_entry_safe(&handler->unresolved_boot_options,
353 if (opt->device != device)
355 list_remove(&opt->list);
359 /* if this is a network device, we have to unregister it from the
361 if (device->device->type == DEVICE_TYPE_NETWORK)
362 network_unregister_device(handler->network, device);
364 handler->n_devices--;
365 memmove(&handler->devices[i], &handler->devices[i + 1],
366 (handler->n_devices - i) * sizeof(handler->devices[0]));
367 handler->devices = talloc_realloc(handler, handler->devices,
368 struct discover_device *, handler->n_devices);
370 if (device->notified)
371 discover_server_notify_device_remove(handler->server,
377 static void boot_status(void *arg, struct boot_status *status)
379 struct device_handler *handler = arg;
381 discover_server_notify_boot_status(handler->server, status);
384 static void countdown_status(struct device_handler *handler,
385 struct discover_boot_option *opt, unsigned int sec)
387 struct boot_status status;
389 status.type = BOOT_STATUS_INFO;
390 status.progress = -1;
391 status.detail = NULL;
392 status.message = talloc_asprintf(handler,
393 _("Booting in %d sec: %s"), sec, opt->option->name);
395 discover_server_notify_boot_status(handler->server, &status);
397 talloc_free(status.message);
400 static int default_timeout(void *arg)
402 struct device_handler *handler = arg;
403 struct discover_boot_option *opt;
405 if (!handler->default_boot_option)
408 if (handler->pending_boot)
411 opt = handler->default_boot_option;
413 if (handler->sec_to_boot) {
414 countdown_status(handler, opt, handler->sec_to_boot);
415 handler->sec_to_boot--;
416 handler->timeout_waiter = waiter_register_timeout(
417 handler->waitset, 1000,
418 default_timeout, handler);
422 handler->timeout_waiter = NULL;
424 pb_log("Timeout expired, booting default option %s\n", opt->option->id);
426 handler->pending_boot = boot(handler, handler->default_boot_option,
427 NULL, handler->dry_run, boot_status, handler);
428 handler->pending_boot_is_default = true;
432 static bool priority_match(struct boot_priority *prio,
433 struct discover_boot_option *opt)
435 return prio->type == opt->device->device->type ||
436 prio->type == DEVICE_TYPE_ANY;
439 static int default_option_priority(struct discover_boot_option *opt)
441 const struct config *config;
442 struct boot_priority *prio;
445 config = config_get();
447 for (i = 0; i < config->n_boot_priorities; i++) {
448 prio = &config->boot_priorities[i];
449 if (priority_match(prio, opt))
450 return prio->priority;
456 static bool device_allows_default(struct discover_device *dev)
460 dev_str = config_get()->boot_device;
462 if (!dev_str || !strlen(dev_str))
465 /* default devices are specified by UUIDs at present */
466 if (strcmp(dev->uuid, dev_str))
472 static void set_default(struct device_handler *handler,
473 struct discover_boot_option *opt)
477 if (!handler->autoboot_enabled)
480 /* do we allow default-booting from this device? */
481 if (!device_allows_default(opt->device))
484 new_prio = default_option_priority(opt);
486 /* A negative priority indicates that we don't want to boot this device
491 /* Resolve any conflicts: if we have a new default option, it only
492 * replaces the current if it has a higher priority. */
493 if (handler->default_boot_option) {
496 cur_prio = default_option_priority(
497 handler->default_boot_option);
499 if (new_prio > cur_prio) {
500 handler->default_boot_option = opt;
501 /* extend the timeout a little, so the user sees some
502 * indication of the change */
503 handler->sec_to_boot += 2;
509 handler->sec_to_boot = config_get()->autoboot_timeout_sec;
510 handler->default_boot_option = opt;
512 pb_log("Boot option %s set as default, timeout %u sec.\n",
513 opt->option->id, handler->sec_to_boot);
515 default_timeout(handler);
518 static bool resource_is_resolved(struct resource *res)
520 return !res || res->resolved;
523 /* We only use this in an assert, which will disappear if we're compiling
524 * with NDEBUG, so we need the 'used' attribute for these builds */
525 static bool __attribute__((used)) boot_option_is_resolved(
526 struct discover_boot_option *opt)
528 return resource_is_resolved(opt->boot_image) &&
529 resource_is_resolved(opt->initrd) &&
530 resource_is_resolved(opt->dtb) &&
531 resource_is_resolved(opt->icon);
534 static bool resource_resolve(struct resource *res, const char *name,
535 struct discover_boot_option *opt,
536 struct device_handler *handler)
538 struct parser *parser = opt->source;
540 if (resource_is_resolved(res))
543 pb_debug("Attempting to resolve resource %s->%s with parser %s\n",
544 opt->option->id, name, parser->name);
545 parser->resolve_resource(handler, res);
547 return res->resolved;
550 static bool boot_option_resolve(struct discover_boot_option *opt,
551 struct device_handler *handler)
553 return resource_resolve(opt->boot_image, "boot_image", opt, handler) &&
554 resource_resolve(opt->initrd, "initrd", opt, handler) &&
555 resource_resolve(opt->dtb, "dtb", opt, handler) &&
556 resource_resolve(opt->icon, "icon", opt, handler);
559 static void boot_option_finalise(struct device_handler *handler,
560 struct discover_boot_option *opt)
562 assert(boot_option_is_resolved(opt));
564 /* check that the parsers haven't set any of the final data */
565 assert(!opt->option->boot_image_file);
566 assert(!opt->option->initrd_file);
567 assert(!opt->option->dtb_file);
568 assert(!opt->option->icon_file);
569 assert(!opt->option->device_id);
572 opt->option->boot_image_file = opt->boot_image->url->full;
574 opt->option->initrd_file = opt->initrd->url->full;
576 opt->option->dtb_file = opt->dtb->url->full;
578 opt->option->icon_file = opt->icon->url->full;
580 opt->option->device_id = opt->device->device->id;
582 if (opt->option->is_default)
583 set_default(handler, opt);
586 static void notify_boot_option(struct device_handler *handler,
587 struct discover_boot_option *opt)
589 struct discover_device *dev = opt->device;
592 discover_server_notify_device_add(handler->server,
593 opt->device->device);
594 dev->notified = true;
595 discover_server_notify_boot_option_add(handler->server, opt->option);
598 static void process_boot_option_queue(struct device_handler *handler)
600 struct discover_boot_option *opt, *tmp;
602 list_for_each_entry_safe(&handler->unresolved_boot_options,
605 pb_debug("queue: attempting resolution for %s\n",
608 if (!boot_option_resolve(opt, handler))
611 pb_debug("\tresolved!\n");
613 list_remove(&opt->list);
614 list_add_tail(&opt->device->boot_options, &opt->list);
615 talloc_steal(opt->device, opt);
616 boot_option_finalise(handler, opt);
617 notify_boot_option(handler, opt);
621 struct discover_context *device_handler_discover_context_create(
622 struct device_handler *handler,
623 struct discover_device *device)
625 struct discover_context *ctx;
627 ctx = talloc_zero(handler, struct discover_context);
628 ctx->device = device;
629 ctx->network = handler->network;
630 list_init(&ctx->boot_options);
636 * context_commit - Commit a temporary discovery context to the handler,
637 * and notify the clients about any new options / devices
639 void device_handler_discover_context_commit(struct device_handler *handler,
640 struct discover_context *ctx)
642 struct discover_device *dev = ctx->device;
643 struct discover_boot_option *opt, *tmp;
645 if (!device_lookup_by_id(handler, dev->device->id))
646 device_handler_add_device(handler, dev);
648 /* move boot options from the context to the device */
649 list_for_each_entry_safe(&ctx->boot_options, opt, tmp, list) {
650 list_remove(&opt->list);
652 if (boot_option_resolve(opt, handler)) {
653 pb_log("boot option %s is resolved, "
654 "sending to clients\n",
656 list_add_tail(&dev->boot_options, &opt->list);
657 talloc_steal(dev, opt);
658 boot_option_finalise(handler, opt);
659 notify_boot_option(handler, opt);
661 if (!opt->source->resolve_resource) {
662 pb_log("parser %s gave us an unresolved "
663 "resource (%s), but no way to "
665 opt->source->name, opt->option->id);
668 pb_log("boot option %s is unresolved, "
671 list_add(&handler->unresolved_boot_options,
673 talloc_steal(handler, opt);
679 void device_handler_add_device(struct device_handler *handler,
680 struct discover_device *device)
682 handler->n_devices++;
683 handler->devices = talloc_realloc(handler, handler->devices,
684 struct discover_device *, handler->n_devices);
685 handler->devices[handler->n_devices - 1] = device;
687 if (device->device->type == DEVICE_TYPE_NETWORK)
688 network_register_device(handler->network, device);
691 /* Start discovery on a hotplugged device. The device will be in our devices
692 * array, but has only just been initialised by the hotplug source.
694 int device_handler_discover(struct device_handler *handler,
695 struct discover_device *dev)
697 struct discover_context *ctx;
700 process_boot_option_queue(handler);
702 /* create our context */
703 ctx = device_handler_discover_context_create(handler, dev);
705 rc = mount_device(dev);
709 /* add this device to our system info */
710 system_info_register_blockdev(dev->device->id, dev->uuid,
713 /* run the parsers. This will populate the ctx's boot_option list. */
714 iterate_parsers(ctx);
716 /* add discovered stuff to the handler */
717 device_handler_discover_context_commit(handler, ctx);
725 /* Incoming dhcp event */
726 int device_handler_dhcp(struct device_handler *handler,
727 struct discover_device *dev, struct event *event)
729 struct discover_context *ctx;
731 /* create our context */
732 ctx = device_handler_discover_context_create(handler, dev);
735 iterate_parsers(ctx);
737 device_handler_discover_context_commit(handler, ctx);
744 /* incoming conf event */
745 int device_handler_conf(struct device_handler *handler,
746 struct discover_device *dev, struct pb_url *url)
748 struct discover_context *ctx;
750 /* create our context */
751 ctx = device_handler_discover_context_create(handler, dev);
754 iterate_parsers(ctx);
756 device_handler_discover_context_commit(handler, ctx);
763 static struct discover_boot_option *find_boot_option_by_id(
764 struct device_handler *handler, const char *id)
768 for (i = 0; i < handler->n_devices; i++) {
769 struct discover_device *dev = handler->devices[i];
770 struct discover_boot_option *opt;
772 list_for_each_entry(&dev->boot_options, opt, list)
773 if (!strcmp(opt->option->id, id))
780 void device_handler_boot(struct device_handler *handler,
781 struct boot_command *cmd)
783 struct discover_boot_option *opt = NULL;
785 if (cmd->option_id && strlen(cmd->option_id))
786 opt = find_boot_option_by_id(handler, cmd->option_id);
788 if (handler->pending_boot)
789 boot_cancel(handler->pending_boot);
791 platform_finalise_config();
793 handler->pending_boot = boot(handler, opt, cmd, handler->dry_run,
794 boot_status, handler);
795 handler->pending_boot_is_default = false;
798 void device_handler_cancel_default(struct device_handler *handler)
800 struct boot_status status;
802 if (handler->timeout_waiter)
803 waiter_remove(handler->timeout_waiter);
805 handler->timeout_waiter = NULL;
806 handler->autoboot_enabled = false;
808 /* we only send status if we had a default boot option queued */
809 if (!handler->default_boot_option)
812 pb_log("Cancelling default boot option\n");
814 if (handler->pending_boot && handler->pending_boot_is_default) {
815 boot_cancel(handler->pending_boot);
816 handler->pending_boot = NULL;
817 handler->pending_boot_is_default = false;
820 handler->default_boot_option = NULL;
822 status.type = BOOT_STATUS_INFO;
823 status.progress = -1;
824 status.detail = NULL;
825 status.message = _("Default boot cancelled");
827 discover_server_notify_boot_status(handler->server, &status);
830 void device_handler_update_config(struct device_handler *handler,
831 struct config *config)
835 rc = config_set(config);
839 discover_server_notify_config(handler->server, config);
840 device_handler_update_lang(config->lang);
841 device_handler_reinit(handler);
844 static char *device_from_addr(void *ctx, struct pb_url *url)
846 char *ipaddr, *buf, *tok, *dev = NULL;
847 const char *delim = " ";
848 struct sockaddr_in *ip;
849 struct sockaddr_in si;
850 struct addrinfo *res;
854 /* Note: IPv4 only */
855 rc = inet_pton(AF_INET, url->host, &(si.sin_addr));
859 /* need to turn hostname into a valid IP */
860 rc = getaddrinfo(url->host, NULL, NULL, &res);
862 pb_debug("%s: Invalid URL\n",__func__);
865 ipaddr = talloc_array(ctx,char,INET_ADDRSTRLEN);
866 ip = (struct sockaddr_in *) res->ai_addr;
867 inet_ntop(AF_INET, &(ip->sin_addr), ipaddr, INET_ADDRSTRLEN);
871 const char *argv[] = {
873 "route", "show", "to", "match",
878 p = process_create(ctx);
880 p->path = pb_system_apps.ip;
882 p->keep_stdout = true;
884 rc = process_run_sync(p);
887 /* ip has complained for some reason; most likely
888 * there is no route to the host - bail out */
889 pb_debug("%s: No route to %s\n",__func__,url->host);
894 /* If a route is found, ip-route output will be of the form
895 * "... dev DEVNAME ... " */
896 tok = strtok(buf, delim);
898 if (!strcmp(tok, "dev")) {
899 tok = strtok(NULL, delim);
900 dev = talloc_strdup(ctx, tok);
903 tok = strtok(NULL, delim);
908 pb_debug("%s: Found interface '%s'\n", __func__,dev);
913 void device_handler_process_url(struct device_handler *handler,
916 struct discover_context *ctx;
917 struct discover_device *dev;
918 struct boot_status *status;
919 struct pb_url *pb_url;
923 status = talloc(handler, struct boot_status);
925 status->type = BOOT_STATUS_ERROR;
926 status->progress = 0;
927 status->detail = talloc_asprintf(status,
928 _("Received config URL %s"), url);
930 if (!handler->network) {
931 status->message = talloc_asprintf(handler,
932 _("No network configured"));
936 event = talloc(handler, struct event);
937 event->type = EVENT_TYPE_USER;
938 event->action = EVENT_ACTION_CONF;
940 event->params = talloc_array(event, struct param, 1);
941 param = &event->params[0];
942 param->name = talloc_strdup(event, "pxeconffile");
943 param->value = talloc_strdup(event, url);
946 pb_url = pb_url_parse(event, event->params->value);
947 if (!pb_url || !pb_url->host) {
948 status->message = talloc_asprintf(handler,
949 _("Invalid config URL!"));
953 event->device = device_from_addr(event, pb_url);
954 if (!event->device) {
955 status->message = talloc_asprintf(status,
956 _("Unable to route to host %s"),
961 dev = discover_device_create(handler, event->device);
962 ctx = device_handler_discover_context_create(handler, dev);
965 iterate_parsers(ctx);
967 device_handler_discover_context_commit(handler, ctx);
971 status->type = BOOT_STATUS_INFO;
972 status->message = talloc_asprintf(status, _("Config file %s parsed"),
975 boot_status(handler, status);
979 #ifndef PETITBOOT_TEST
981 static void device_handler_update_lang(const char *lang)
983 const char *cur_lang;
988 cur_lang = setlocale(LC_ALL, NULL);
989 if (cur_lang && !strcmp(cur_lang, lang))
992 setlocale(LC_ALL, lang);
995 static int device_handler_init_sources(struct device_handler *handler)
997 /* init our device sources: udev, network and user events */
998 handler->udev = udev_init(handler, handler->waitset);
1002 handler->network = network_init(handler, handler->waitset,
1004 if (!handler->network)
1007 handler->user_event = user_event_init(handler, handler->waitset);
1008 if (!handler->user_event)
1014 static void device_handler_reinit_sources(struct device_handler *handler)
1016 /* if we haven't initialised sources previously (becuase we started in
1017 * safe mode), then init once here. */
1018 if (!(handler->udev || handler->network || handler->user_event)) {
1019 device_handler_init_sources(handler);
1023 udev_reinit(handler->udev);
1025 network_shutdown(handler->network);
1026 handler->network = network_init(handler, handler->waitset,
1030 static bool check_existing_mount(struct discover_device *dev)
1032 struct stat devstat, mntstat;
1037 rc = stat(dev->device_path, &devstat);
1039 pb_debug("%s: stat failed: %s\n", __func__, strerror(errno));
1043 if (!S_ISBLK(devstat.st_mode)) {
1044 pb_debug("%s: %s isn't a block device?\n", __func__,
1049 fp = fopen("/proc/self/mounts", "r");
1052 mnt = getmntent(fp);
1056 if (!mnt->mnt_fsname || mnt->mnt_fsname[0] != '/')
1059 rc = stat(mnt->mnt_fsname, &mntstat);
1063 if (!S_ISBLK(mntstat.st_mode))
1066 if (mntstat.st_rdev == devstat.st_rdev) {
1067 dev->mount_path = talloc_strdup(dev, mnt->mnt_dir);
1068 dev->mounted_rw = !!hasmntopt(mnt, "rw");
1069 dev->mounted = true;
1070 dev->unmount = false;
1072 pb_debug("%s: %s is already mounted (r%c) at %s\n",
1073 __func__, dev->device_path,
1074 dev->mounted_rw ? 'w' : 'o',
1085 static int mount_device(struct discover_device *dev)
1090 if (!dev->device_path)
1096 if (check_existing_mount(dev))
1099 fstype = discover_device_get_param(dev, "ID_FS_TYPE");
1103 dev->mount_path = join_paths(dev, mount_base(),
1106 if (pb_mkdir_recursive(dev->mount_path)) {
1107 pb_log("couldn't create mount directory %s: %s\n",
1108 dev->mount_path, strerror(errno));
1112 pb_log("mounting device %s read-only\n", dev->device_path);
1114 rc = mount(dev->device_path, dev->mount_path, fstype,
1115 MS_RDONLY | MS_SILENT, "");
1117 dev->mounted = true;
1118 dev->mounted_rw = false;
1119 dev->unmount = true;
1123 pb_log("couldn't mount device %s: mount failed: %s\n",
1124 dev->device_path, strerror(errno));
1126 pb_rmdir_recursive(mount_base(), dev->mount_path);
1128 talloc_free(dev->mount_path);
1129 dev->mount_path = NULL;
1133 static int umount_device(struct discover_device *dev)
1137 if (!dev->mounted || !dev->unmount)
1140 pb_log("unmounting device %s\n", dev->device_path);
1141 rc = umount(dev->mount_path);
1145 dev->mounted = false;
1147 pb_rmdir_recursive(mount_base(), dev->mount_path);
1149 talloc_free(dev->mount_path);
1150 dev->mount_path = NULL;
1155 int device_request_write(struct discover_device *dev, bool *release)
1164 if (dev->mounted_rw)
1167 pb_log("remounting device %s read-write\n", dev->device_path);
1168 rc = mount(dev->device_path, dev->mount_path, "",
1169 MS_REMOUNT | MS_SILENT, "");
1173 dev->mounted_rw = true;
1178 void device_release_write(struct discover_device *dev, bool release)
1183 pb_log("remounting device %s read-only\n", dev->device_path);
1184 mount(dev->device_path, dev->mount_path, "",
1185 MS_REMOUNT | MS_RDONLY | MS_SILENT, "");
1186 dev->mounted_rw = false;
1191 static void device_handler_update_lang(const char *lang __attribute__((unused)))
1195 static int device_handler_init_sources(
1196 struct device_handler *handler __attribute__((unused)))
1201 static void device_handler_reinit_sources(
1202 struct device_handler *handler __attribute__((unused)))
1206 static int umount_device(struct discover_device *dev __attribute__((unused)))
1211 static int __attribute__((unused)) mount_device(
1212 struct discover_device *dev __attribute__((unused)))
1217 int device_request_write(struct discover_device *dev __attribute__((unused)),
1224 void device_release_write(struct discover_device *dev __attribute__((unused)),
1225 bool release __attribute__((unused)))