10 #include <sys/mount.h>
12 #include <talloc/talloc.h>
13 #include <list/list.h>
15 #include <types/types.h>
16 #include <system/system.h>
17 #include <process/process.h>
19 #include <i18n/i18n.h>
21 #include <sys/types.h>
22 #include <sys/socket.h>
24 #include <arpa/inet.h>
26 #include "device-handler.h"
27 #include "discover-server.h"
28 #include "user-event.h"
39 struct device_handler {
40 struct discover_server *server;
44 struct network *network;
45 struct user_event *user_event;
47 struct discover_device **devices;
48 unsigned int n_devices;
50 struct waitset *waitset;
51 struct waiter *timeout_waiter;
52 bool autoboot_enabled;
53 unsigned int sec_to_boot;
55 struct discover_boot_option *default_boot_option;
56 struct list unresolved_boot_options;
58 struct boot_task *pending_boot;
59 bool pending_boot_is_default;
62 static int mount_device(struct discover_device *dev);
63 static int umount_device(struct discover_device *dev);
65 static int device_handler_init_sources(struct device_handler *handler);
66 static void device_handler_reinit_sources(struct device_handler *handler);
68 static void device_handler_update_lang(const char *lang);
70 void discover_context_add_boot_option(struct discover_context *ctx,
71 struct discover_boot_option *boot_option)
73 boot_option->source = ctx->parser;
74 list_add_tail(&ctx->boot_options, &boot_option->list);
75 talloc_steal(ctx, boot_option);
79 * device_handler_get_device_count - Get the count of current handler devices.
82 int device_handler_get_device_count(const struct device_handler *handler)
84 return handler->n_devices;
88 * device_handler_get_device - Get a handler device by index.
91 const struct discover_device *device_handler_get_device(
92 const struct device_handler *handler, unsigned int index)
94 if (index >= handler->n_devices) {
95 assert(0 && "bad index");
99 return handler->devices[index];
102 struct discover_boot_option *discover_boot_option_create(
103 struct discover_context *ctx,
104 struct discover_device *device)
106 struct discover_boot_option *opt;
108 opt = talloc_zero(ctx, struct discover_boot_option);
109 opt->option = talloc_zero(opt, struct boot_option);
110 opt->device = device;
115 static int device_match_uuid(struct discover_device *dev, const char *uuid)
117 return dev->uuid && !strcmp(dev->uuid, uuid);
120 static int device_match_label(struct discover_device *dev, const char *label)
122 return dev->label && !strcmp(dev->label, label);
125 static int device_match_id(struct discover_device *dev, const char *id)
127 return !strcmp(dev->device->id, id);
130 static int device_match_serial(struct discover_device *dev, const char *serial)
132 const char *val = discover_device_get_param(dev, "ID_SERIAL");
133 return val && !strcmp(val, serial);
136 static struct discover_device *device_lookup(
137 struct device_handler *device_handler,
138 int (match_fn)(struct discover_device *, const char *),
141 struct discover_device *dev;
147 for (i = 0; i < device_handler->n_devices; i++) {
148 dev = device_handler->devices[i];
150 if (match_fn(dev, str))
157 struct discover_device *device_lookup_by_name(struct device_handler *handler,
160 if (!strncmp(name, "/dev/", strlen("/dev/")))
161 name += strlen("/dev/");
163 return device_lookup_by_id(handler, name);
166 struct discover_device *device_lookup_by_uuid(
167 struct device_handler *device_handler,
170 return device_lookup(device_handler, device_match_uuid, uuid);
173 struct discover_device *device_lookup_by_label(
174 struct device_handler *device_handler,
177 return device_lookup(device_handler, device_match_label, label);
180 struct discover_device *device_lookup_by_id(
181 struct device_handler *device_handler,
184 return device_lookup(device_handler, device_match_id, id);
187 struct discover_device *device_lookup_by_serial(
188 struct device_handler *device_handler,
191 return device_lookup(device_handler, device_match_serial, serial);
194 void device_handler_destroy(struct device_handler *handler)
196 talloc_free(handler);
199 static int destroy_device(void *arg)
201 struct discover_device *dev = arg;
208 struct discover_device *discover_device_create(struct device_handler *handler,
211 struct discover_device *dev;
213 dev = device_lookup_by_id(handler, id);
217 dev = talloc_zero(handler, struct discover_device);
218 dev->device = talloc_zero(dev, struct device);
219 dev->device->id = talloc_strdup(dev->device, id);
220 list_init(&dev->params);
221 list_init(&dev->boot_options);
223 talloc_set_destructor(dev, destroy_device);
228 struct discover_device_param {
231 struct list_item list;
234 void discover_device_set_param(struct discover_device *device,
235 const char *name, const char *value)
237 struct discover_device_param *param;
240 list_for_each_entry(&device->params, param, list) {
241 if (!strcmp(param->name, name)) {
250 param = talloc(device, struct discover_device_param);
251 param->name = talloc_strdup(param, name);
252 list_add(&device->params, ¶m->list);
255 list_remove(¶m->list);
259 talloc_free(param->value);
262 param->value = talloc_strdup(param, value);
265 const char *discover_device_get_param(struct discover_device *device,
268 struct discover_device_param *param;
270 list_for_each_entry(&device->params, param, list) {
271 if (!strcmp(param->name, name))
277 struct device_handler *device_handler_init(struct discover_server *server,
278 struct waitset *waitset, int dry_run)
280 struct device_handler *handler;
283 handler = talloc_zero(NULL, struct device_handler);
284 handler->server = server;
285 handler->waitset = waitset;
286 handler->dry_run = dry_run;
287 handler->autoboot_enabled = config_get()->autoboot_enabled;
289 list_init(&handler->unresolved_boot_options);
291 /* set up our mount point base */
292 pb_mkdir_recursive(mount_base());
296 if (config_get()->safe_mode)
299 rc = device_handler_init_sources(handler);
301 talloc_free(handler);
308 void device_handler_reinit(struct device_handler *handler)
310 struct discover_boot_option *opt, *tmp;
313 device_handler_cancel_default(handler);
315 /* free unresolved boot options */
316 list_for_each_entry_safe(&handler->unresolved_boot_options,
319 list_init(&handler->unresolved_boot_options);
321 /* drop all devices */
322 for (i = 0; i < handler->n_devices; i++)
323 discover_server_notify_device_remove(handler->server,
324 handler->devices[i]->device);
326 talloc_free(handler->devices);
327 handler->devices = NULL;
328 handler->n_devices = 0;
330 device_handler_reinit_sources(handler);
333 void device_handler_remove(struct device_handler *handler,
334 struct discover_device *device)
336 struct discover_boot_option *opt, *tmp;
339 for (i = 0; i < handler->n_devices; i++)
340 if (handler->devices[i] == device)
343 if (i == handler->n_devices) {
348 /* Free any unresolved options, as they're currently allocated
349 * against the handler */
350 list_for_each_entry_safe(&handler->unresolved_boot_options,
352 if (opt->device != device)
354 list_remove(&opt->list);
358 /* if this is a network device, we have to unregister it from the
360 if (device->device->type == DEVICE_TYPE_NETWORK)
361 network_unregister_device(handler->network, device);
363 handler->n_devices--;
364 memmove(&handler->devices[i], &handler->devices[i + 1],
365 (handler->n_devices - i) * sizeof(handler->devices[0]));
366 handler->devices = talloc_realloc(handler, handler->devices,
367 struct discover_device *, handler->n_devices);
369 if (device->notified)
370 discover_server_notify_device_remove(handler->server,
376 static void boot_status(void *arg, struct boot_status *status)
378 struct device_handler *handler = arg;
380 discover_server_notify_boot_status(handler->server, status);
383 static void countdown_status(struct device_handler *handler,
384 struct discover_boot_option *opt, unsigned int sec)
386 struct boot_status status;
388 status.type = BOOT_STATUS_INFO;
389 status.progress = -1;
390 status.detail = NULL;
391 status.message = talloc_asprintf(handler,
392 _("Booting in %d sec: %s"), sec, opt->option->name);
394 discover_server_notify_boot_status(handler->server, &status);
396 talloc_free(status.message);
399 static int default_timeout(void *arg)
401 struct device_handler *handler = arg;
402 struct discover_boot_option *opt;
404 if (!handler->default_boot_option)
407 if (handler->pending_boot)
410 opt = handler->default_boot_option;
412 if (handler->sec_to_boot) {
413 countdown_status(handler, opt, handler->sec_to_boot);
414 handler->sec_to_boot--;
415 handler->timeout_waiter = waiter_register_timeout(
416 handler->waitset, 1000,
417 default_timeout, handler);
421 handler->timeout_waiter = NULL;
423 pb_log("Timeout expired, booting default option %s\n", opt->option->id);
425 handler->pending_boot = boot(handler, handler->default_boot_option,
426 NULL, handler->dry_run, boot_status, handler);
427 handler->pending_boot_is_default = true;
431 static bool priority_match(struct boot_priority *prio,
432 struct discover_boot_option *opt)
434 return prio->type == opt->device->device->type ||
435 prio->type == DEVICE_TYPE_ANY;
438 static int default_option_priority(struct discover_boot_option *opt)
440 const struct config *config;
441 struct boot_priority *prio;
444 config = config_get();
446 for (i = 0; i < config->n_boot_priorities; i++) {
447 prio = &config->boot_priorities[i];
448 if (priority_match(prio, opt))
449 return prio->priority;
455 static bool device_allows_default(struct discover_device *dev)
459 dev_str = config_get()->boot_device;
461 if (!dev_str || !strlen(dev_str))
464 /* default devices are specified by UUIDs at present */
465 if (strcmp(dev->uuid, dev_str))
471 static void set_default(struct device_handler *handler,
472 struct discover_boot_option *opt)
476 if (!handler->autoboot_enabled)
479 /* do we allow default-booting from this device? */
480 if (!device_allows_default(opt->device))
483 new_prio = default_option_priority(opt);
485 /* A negative priority indicates that we don't want to boot this device
490 /* Resolve any conflicts: if we have a new default option, it only
491 * replaces the current if it has a higher priority. */
492 if (handler->default_boot_option) {
495 cur_prio = default_option_priority(
496 handler->default_boot_option);
498 if (new_prio > cur_prio) {
499 handler->default_boot_option = opt;
500 /* extend the timeout a little, so the user sees some
501 * indication of the change */
502 handler->sec_to_boot += 2;
508 handler->sec_to_boot = config_get()->autoboot_timeout_sec;
509 handler->default_boot_option = opt;
511 pb_log("Boot option %s set as default, timeout %u sec.\n",
512 opt->option->id, handler->sec_to_boot);
514 default_timeout(handler);
517 static bool resource_is_resolved(struct resource *res)
519 return !res || res->resolved;
522 /* We only use this in an assert, which will disappear if we're compiling
523 * with NDEBUG, so we need the 'used' attribute for these builds */
524 static bool __attribute__((used)) boot_option_is_resolved(
525 struct discover_boot_option *opt)
527 return resource_is_resolved(opt->boot_image) &&
528 resource_is_resolved(opt->initrd) &&
529 resource_is_resolved(opt->dtb) &&
530 resource_is_resolved(opt->icon);
533 static bool resource_resolve(struct resource *res, const char *name,
534 struct discover_boot_option *opt,
535 struct device_handler *handler)
537 struct parser *parser = opt->source;
539 if (resource_is_resolved(res))
542 pb_debug("Attempting to resolve resource %s->%s with parser %s\n",
543 opt->option->id, name, parser->name);
544 parser->resolve_resource(handler, res);
546 return res->resolved;
549 static bool boot_option_resolve(struct discover_boot_option *opt,
550 struct device_handler *handler)
552 return resource_resolve(opt->boot_image, "boot_image", opt, handler) &&
553 resource_resolve(opt->initrd, "initrd", opt, handler) &&
554 resource_resolve(opt->dtb, "dtb", opt, handler) &&
555 resource_resolve(opt->icon, "icon", opt, handler);
558 static void boot_option_finalise(struct device_handler *handler,
559 struct discover_boot_option *opt)
561 assert(boot_option_is_resolved(opt));
563 /* check that the parsers haven't set any of the final data */
564 assert(!opt->option->boot_image_file);
565 assert(!opt->option->initrd_file);
566 assert(!opt->option->dtb_file);
567 assert(!opt->option->icon_file);
568 assert(!opt->option->device_id);
571 opt->option->boot_image_file = opt->boot_image->url->full;
573 opt->option->initrd_file = opt->initrd->url->full;
575 opt->option->dtb_file = opt->dtb->url->full;
577 opt->option->icon_file = opt->icon->url->full;
579 opt->option->device_id = opt->device->device->id;
581 if (opt->option->is_default)
582 set_default(handler, opt);
585 static void notify_boot_option(struct device_handler *handler,
586 struct discover_boot_option *opt)
588 struct discover_device *dev = opt->device;
591 discover_server_notify_device_add(handler->server,
592 opt->device->device);
593 dev->notified = true;
594 discover_server_notify_boot_option_add(handler->server, opt->option);
597 static void process_boot_option_queue(struct device_handler *handler)
599 struct discover_boot_option *opt, *tmp;
601 list_for_each_entry_safe(&handler->unresolved_boot_options,
604 pb_debug("queue: attempting resolution for %s\n",
607 if (!boot_option_resolve(opt, handler))
610 pb_debug("\tresolved!\n");
612 list_remove(&opt->list);
613 list_add_tail(&opt->device->boot_options, &opt->list);
614 talloc_steal(opt->device, opt);
615 boot_option_finalise(handler, opt);
616 notify_boot_option(handler, opt);
620 struct discover_context *device_handler_discover_context_create(
621 struct device_handler *handler,
622 struct discover_device *device)
624 struct discover_context *ctx;
626 ctx = talloc_zero(handler, struct discover_context);
627 ctx->device = device;
628 list_init(&ctx->boot_options);
634 * context_commit - Commit a temporary discovery context to the handler,
635 * and notify the clients about any new options / devices
637 void device_handler_discover_context_commit(struct device_handler *handler,
638 struct discover_context *ctx)
640 struct discover_device *dev = ctx->device;
641 struct discover_boot_option *opt, *tmp;
643 if (!device_lookup_by_id(handler, dev->device->id))
644 device_handler_add_device(handler, dev);
646 /* move boot options from the context to the device */
647 list_for_each_entry_safe(&ctx->boot_options, opt, tmp, list) {
648 list_remove(&opt->list);
650 if (boot_option_resolve(opt, handler)) {
651 pb_log("boot option %s is resolved, "
652 "sending to clients\n",
654 list_add_tail(&dev->boot_options, &opt->list);
655 talloc_steal(dev, opt);
656 boot_option_finalise(handler, opt);
657 notify_boot_option(handler, opt);
659 if (!opt->source->resolve_resource) {
660 pb_log("parser %s gave us an unresolved "
661 "resource (%s), but no way to "
663 opt->source->name, opt->option->id);
666 pb_log("boot option %s is unresolved, "
669 list_add(&handler->unresolved_boot_options,
671 talloc_steal(handler, opt);
677 void device_handler_add_device(struct device_handler *handler,
678 struct discover_device *device)
680 handler->n_devices++;
681 handler->devices = talloc_realloc(handler, handler->devices,
682 struct discover_device *, handler->n_devices);
683 handler->devices[handler->n_devices - 1] = device;
685 if (device->device->type == DEVICE_TYPE_NETWORK)
686 network_register_device(handler->network, device);
689 /* Start discovery on a hotplugged device. The device will be in our devices
690 * array, but has only just been initialised by the hotplug source.
692 int device_handler_discover(struct device_handler *handler,
693 struct discover_device *dev)
695 struct discover_context *ctx;
698 process_boot_option_queue(handler);
700 /* create our context */
701 ctx = device_handler_discover_context_create(handler, dev);
703 rc = mount_device(dev);
707 /* add this device to our system info */
708 system_info_register_blockdev(dev->device->id, dev->uuid,
711 /* run the parsers. This will populate the ctx's boot_option list. */
712 iterate_parsers(ctx);
714 /* add discovered stuff to the handler */
715 device_handler_discover_context_commit(handler, ctx);
723 /* Incoming dhcp event */
724 int device_handler_dhcp(struct device_handler *handler,
725 struct discover_device *dev, struct event *event)
727 struct discover_context *ctx;
729 /* create our context */
730 ctx = device_handler_discover_context_create(handler, dev);
733 iterate_parsers(ctx);
735 device_handler_discover_context_commit(handler, ctx);
742 /* incoming conf event */
743 int device_handler_conf(struct device_handler *handler,
744 struct discover_device *dev, struct pb_url *url)
746 struct discover_context *ctx;
748 /* create our context */
749 ctx = device_handler_discover_context_create(handler, dev);
752 iterate_parsers(ctx);
754 device_handler_discover_context_commit(handler, ctx);
761 static struct discover_boot_option *find_boot_option_by_id(
762 struct device_handler *handler, const char *id)
766 for (i = 0; i < handler->n_devices; i++) {
767 struct discover_device *dev = handler->devices[i];
768 struct discover_boot_option *opt;
770 list_for_each_entry(&dev->boot_options, opt, list)
771 if (!strcmp(opt->option->id, id))
778 void device_handler_boot(struct device_handler *handler,
779 struct boot_command *cmd)
781 struct discover_boot_option *opt = NULL;
783 if (cmd->option_id && strlen(cmd->option_id))
784 opt = find_boot_option_by_id(handler, cmd->option_id);
786 if (handler->pending_boot)
787 boot_cancel(handler->pending_boot);
788 handler->pending_boot = boot(handler, opt, cmd, handler->dry_run,
789 boot_status, handler);
790 handler->pending_boot_is_default = false;
793 void device_handler_cancel_default(struct device_handler *handler)
795 struct boot_status status;
797 if (handler->timeout_waiter)
798 waiter_remove(handler->timeout_waiter);
800 handler->timeout_waiter = NULL;
801 handler->autoboot_enabled = false;
803 /* we only send status if we had a default boot option queued */
804 if (!handler->default_boot_option)
807 pb_log("Cancelling default boot option\n");
809 if (handler->pending_boot && handler->pending_boot_is_default) {
810 boot_cancel(handler->pending_boot);
811 handler->pending_boot = NULL;
812 handler->pending_boot_is_default = false;
815 handler->default_boot_option = NULL;
817 status.type = BOOT_STATUS_INFO;
818 status.progress = -1;
819 status.detail = NULL;
820 status.message = _("Default boot cancelled");
822 discover_server_notify_boot_status(handler->server, &status);
825 void device_handler_update_config(struct device_handler *handler,
826 struct config *config)
830 rc = config_set(config);
834 discover_server_notify_config(handler->server, config);
835 device_handler_update_lang(config->lang);
836 device_handler_reinit(handler);
839 static char *device_from_addr(void *ctx, struct pb_url *url)
841 char *ipaddr, *buf, *tok, *dev = NULL;
842 const char *delim = " ";
843 struct sockaddr_in *ip;
844 struct sockaddr_in si;
845 struct addrinfo *res;
849 /* Note: IPv4 only */
850 rc = inet_pton(AF_INET, url->host, &(si.sin_addr));
854 /* need to turn hostname into a valid IP */
855 rc = getaddrinfo(url->host, NULL, NULL, &res);
857 pb_debug("%s: Invalid URL\n",__func__);
860 ipaddr = talloc_array(ctx,char,INET_ADDRSTRLEN);
861 ip = (struct sockaddr_in *) res->ai_addr;
862 inet_ntop(AF_INET, &(ip->sin_addr), ipaddr, INET_ADDRSTRLEN);
866 const char *argv[] = {
868 "route", "show", "to", "match",
873 p = process_create(ctx);
875 p->path = pb_system_apps.ip;
877 p->keep_stdout = true;
879 rc = process_run_sync(p);
882 /* ip has complained for some reason; most likely
883 * there is no route to the host - bail out */
884 pb_debug("%s: No route to %s\n",__func__,url->host);
889 /* If a route is found, ip-route output will be of the form
890 * "... dev DEVNAME ... " */
891 tok = strtok(buf, delim);
893 if (!strcmp(tok, "dev")) {
894 tok = strtok(NULL, delim);
895 dev = talloc_strdup(ctx, tok);
898 tok = strtok(NULL, delim);
903 pb_debug("%s: Found interface '%s'\n", __func__,dev);
908 void device_handler_process_url(struct device_handler *handler,
911 struct discover_context *ctx;
912 struct discover_device *dev;
913 struct boot_status *status;
914 struct pb_url *pb_url;
918 status = talloc(handler, struct boot_status);
920 status->type = BOOT_STATUS_ERROR;
921 status->progress = 0;
922 status->detail = talloc_asprintf(status,
923 _("Received config URL %s"), url);
925 event = talloc(handler, struct event);
926 event->type = EVENT_TYPE_USER;
927 event->action = EVENT_ACTION_CONF;
929 event->params = talloc_array(event, struct param, 1);
930 param = &event->params[0];
931 param->name = talloc_strdup(event, "pxeconffile");
932 param->value = talloc_strdup(event, url);
935 pb_url = pb_url_parse(event, event->params->value);
936 if (!pb_url || !pb_url->host) {
937 status->message = talloc_asprintf(handler,
938 _("Invalid config URL!"));
942 event->device = device_from_addr(event, pb_url);
943 if (!event->device) {
944 status->message = talloc_asprintf(status,
945 _("Unable to route to host %s"),
950 dev = discover_device_create(handler, event->device);
951 ctx = device_handler_discover_context_create(handler, dev);
954 iterate_parsers(ctx);
956 device_handler_discover_context_commit(handler, ctx);
960 status->type = BOOT_STATUS_INFO;
961 status->message = talloc_asprintf(status, _("Config file %s parsed"),
964 boot_status(handler, status);
968 #ifndef PETITBOOT_TEST
970 static void device_handler_update_lang(const char *lang)
972 const char *cur_lang;
977 cur_lang = setlocale(LC_ALL, NULL);
978 if (cur_lang && !strcmp(cur_lang, lang))
981 setlocale(LC_ALL, lang);
984 static int device_handler_init_sources(struct device_handler *handler)
986 /* init our device sources: udev, network and user events */
987 handler->udev = udev_init(handler, handler->waitset);
991 handler->network = network_init(handler, handler->waitset,
993 if (!handler->network)
996 handler->user_event = user_event_init(handler, handler->waitset);
997 if (!handler->user_event)
1003 static void device_handler_reinit_sources(struct device_handler *handler)
1005 /* if we haven't initialised sources previously (becuase we started in
1006 * safe mode), then init once here. */
1007 if (!(handler->udev || handler->network || handler->user_event)) {
1008 device_handler_init_sources(handler);
1012 udev_reinit(handler->udev);
1014 network_shutdown(handler->network);
1015 handler->network = network_init(handler, handler->waitset,
1019 static bool check_existing_mount(struct discover_device *dev)
1021 struct stat devstat, mntstat;
1026 rc = stat(dev->device_path, &devstat);
1028 pb_debug("%s: stat failed: %s\n", __func__, strerror(errno));
1032 if (!S_ISBLK(devstat.st_mode)) {
1033 pb_debug("%s: %s isn't a block device?\n", __func__,
1038 fp = fopen("/proc/self/mounts", "r");
1041 mnt = getmntent(fp);
1045 if (!mnt->mnt_fsname || mnt->mnt_fsname[0] != '/')
1048 rc = stat(mnt->mnt_fsname, &mntstat);
1052 if (!S_ISBLK(mntstat.st_mode))
1055 if (mntstat.st_rdev == devstat.st_rdev) {
1056 dev->mount_path = talloc_strdup(dev, mnt->mnt_dir);
1057 dev->mounted_rw = !!hasmntopt(mnt, "rw");
1058 dev->mounted = true;
1059 dev->unmount = false;
1061 pb_debug("%s: %s is already mounted (r%c) at %s\n",
1062 __func__, dev->device_path,
1063 dev->mounted_rw ? 'w' : 'o',
1074 static int mount_device(struct discover_device *dev)
1079 if (!dev->device_path)
1085 if (check_existing_mount(dev))
1088 fstype = discover_device_get_param(dev, "ID_FS_TYPE");
1092 dev->mount_path = join_paths(dev, mount_base(),
1095 if (pb_mkdir_recursive(dev->mount_path)) {
1096 pb_log("couldn't create mount directory %s: %s\n",
1097 dev->mount_path, strerror(errno));
1101 pb_log("mounting device %s read-only\n", dev->device_path);
1103 rc = mount(dev->device_path, dev->mount_path, fstype,
1104 MS_RDONLY | MS_SILENT, "");
1106 dev->mounted = true;
1107 dev->mounted_rw = false;
1108 dev->unmount = true;
1112 pb_log("couldn't mount device %s: mount failed: %s\n",
1113 dev->device_path, strerror(errno));
1115 pb_rmdir_recursive(mount_base(), dev->mount_path);
1117 talloc_free(dev->mount_path);
1118 dev->mount_path = NULL;
1122 static int umount_device(struct discover_device *dev)
1126 if (!dev->mounted || !dev->unmount)
1129 pb_log("unmounting device %s\n", dev->device_path);
1130 rc = umount(dev->mount_path);
1134 dev->mounted = false;
1136 pb_rmdir_recursive(mount_base(), dev->mount_path);
1138 talloc_free(dev->mount_path);
1139 dev->mount_path = NULL;
1144 int device_request_write(struct discover_device *dev, bool *release)
1153 if (dev->mounted_rw)
1156 pb_log("remounting device %s read-write\n", dev->device_path);
1157 rc = mount(dev->device_path, dev->mount_path, "",
1158 MS_REMOUNT | MS_SILENT, "");
1162 dev->mounted_rw = true;
1167 void device_release_write(struct discover_device *dev, bool release)
1172 pb_log("remounting device %s read-only\n", dev->device_path);
1173 mount(dev->device_path, dev->mount_path, "",
1174 MS_REMOUNT | MS_RDONLY | MS_SILENT, "");
1175 dev->mounted_rw = false;
1180 static void device_handler_update_lang(const char *lang __attribute__((unused)))
1184 static int device_handler_init_sources(
1185 struct device_handler *handler __attribute__((unused)))
1190 static void device_handler_reinit_sources(
1191 struct device_handler *handler __attribute__((unused)))
1195 static int umount_device(struct discover_device *dev __attribute__((unused)))
1200 static int __attribute__((unused)) mount_device(
1201 struct discover_device *dev __attribute__((unused)))
1206 int device_request_write(struct discover_device *dev __attribute__((unused)),
1213 void device_release_write(struct discover_device *dev __attribute__((unused)),
1214 bool release __attribute__((unused)))