diff options
author | Paulo Alcantara <paulo.alcantara@openbossa.org> | 2012-07-27 16:43:13 -0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2012-07-29 20:04:56 +0200 |
commit | 5def8e37a88dc47bb9ce6084fff10f2f1f320aae (patch) | |
tree | 8c67fbbc52b645b77bc68a3c6c2f93e25493dd23 /src/storage.c | |
parent | be5fd633a6976358e9c91f7bec87bccb05faafd2 (diff) |
storage: Store address type in "aliases" file
Diffstat (limited to 'src/storage.c')
-rw-r--r-- | src/storage.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/storage.c b/src/storage.c index 7a3010d9..df876b47 100644 --- a/src/storage.c +++ b/src/storage.c @@ -62,17 +62,29 @@ static inline int create_filename(char *buf, size_t size, return create_name(buf, size, STORAGEDIR, addr, name); } -int read_device_alias(const char *src, const char *dst, char *alias, size_t size) +int read_device_alias(const char *src, const char *dst, uint8_t dst_type, + char *alias, size_t size) { char filename[PATH_MAX + 1], *tmp; + char key[20]; int err; create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases"); - tmp = textfile_get(filename, dst); - if (!tmp) + snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type); + + tmp = textfile_get(filename, key); + if (tmp != NULL) + goto done; + + /* Try old format (address only) */ + key[17] = '\0'; + + tmp = textfile_get(filename, key); + if (tmp == NULL) return -ENXIO; +done: err = snprintf(alias, size, "%s", tmp); free(tmp); @@ -80,15 +92,19 @@ int read_device_alias(const char *src, const char *dst, char *alias, size_t size return err < 0 ? -EIO : 0; } -int write_device_alias(const char *src, const char *dst, const char *alias) +int write_device_alias(const char *src, const char *dst, uint8_t dst_type, + const char *alias) { char filename[PATH_MAX + 1]; + char key[20]; create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases"); create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - return textfile_put(filename, dst, alias); + snprintf(key, sizeof(key), "%17s#%hhu", dst, dst_type); + + return textfile_put(filename, key, alias); } int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout) |