#define BLOCK_CONF_FILE "/etc/deviced/block.conf"
+#define EXTERNAL_STORAGE_PATH "/run/external-storage"
+#define PATH_LEN 55
+
/* Minimum value of block id */
#define BLOCK_ID_MIN 10
/* For 2.4 Backward Compatibility */
return -ENOENT;
}
+static void remove_file(int id)
+{
+ char file_name[PATH_LEN];
+ int ret;
+
+ if (id < 0)
+ return;
+
+ snprintf(file_name, sizeof(file_name), EXTERNAL_STORAGE_PATH"/%d", id);
+
+ ret = remove(file_name);
+ if (ret < 0)
+ _E("Fail to remove %s. errno: %d", file_name, errno);
+}
+
+static void create_file(int id, char *mount_point)
+{
+ FILE *fp;
+ char file_name[PATH_LEN];
+
+ if (id < 0)
+ return;
+
+ snprintf(file_name, PATH_LEN, EXTERNAL_STORAGE_PATH"/%d", id);
+
+ fp = fopen(file_name, "w+");
+ if (fp) {
+ fprintf(fp, "%s", mount_point);
+ fclose(fp);
+ } else
+ _E("Fail to open %s", file_name);
+}
+
static void signal_device_blocked(struct block_device *bdev)
{
struct block_data *data;
snprintf(str_id, sizeof(str_id), "%d", data->id);
arr[12] = str_id;
-
broadcast_block_edbus_signal(DEVICED_PATH_BLOCK_MANAGER,
DEVICED_INTERFACE_BLOCK_MANAGER,
BLOCK_DEVICE_BLOCKED,
if (thread_id < 0 || thread_id >= THREAD_MAX)
return;
+ /* Remove file for block device /run/external-storage/id */
+ remove_file(bdev->data->id);
+
pthread_mutex_lock(&(th_manager[thread_id].mutex));
th_manager[thread_id].num_dev--;
pthread_mutex_lock(&(th_manager[thread_id].mutex));
th_manager[thread_id].num_dev++;
DD_LIST_APPEND(th_manager[thread_id].block_dev_list, bdev);
+
+ /* Create file for block device /run/external-storage/id */
+ create_file(bdev->data->id, bdev->data->mount_point);
+
pthread_mutex_unlock(&(th_manager[thread_id].mutex));
ret = add_operation(bdev, BLOCK_DEV_INSERT, NULL, (void *)data);
goto out;
}
+ if (bdev->data->state == BLOCK_MOUNT) {
+ _I("%s is already mounted", bdev->data->devnode);
+ ret = -EALREADY;
+ goto out;
+ }
+
/* if requester want to use a specific mount point */
if (mount_point && strncmp(mount_point, "", 1) != 0) {
ret = change_mount_point(bdev, mount_point);
ret = -EPERM;
goto out;
}
+
+ /* Modify /run/external-storage/id file */
+ create_file(bdev->data->id, bdev->data->mount_point);
}
ret = add_operation(bdev, BLOCK_DEV_MOUNT, msg, NULL);
static void block_init(void *data)
{
+ struct stat buf;
int ret;
int i;
pthread_mutex_init(&(th_manager[i].mutex), NULL);
pthread_cond_init(&(th_manager[i].cond), NULL);
}
+
+ ret = stat(EXTERNAL_STORAGE_PATH, &buf);
+ if (ret < 0) {
+ ret = mkdir(EXTERNAL_STORAGE_PATH, 644);
+ if (ret < 0)
+ _E("Failed to make directory: %d", errno);
+ } else if (!S_ISDIR(buf.st_mode)) {
+ remove(EXTERNAL_STORAGE_PATH);
+ ret = mkdir(EXTERNAL_STORAGE_PATH, 644);
+ if (ret < 0)
+ _E("Failed to make directory: %d", errno);
+ } else
+ chmod(EXTERNAL_STORAGE_PATH, 644);
}
static void block_exit(void *data)