2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 #include <app_storage.h>
28 #include <app_storage_private.h>
34 #define LOG_TAG "TIZEN_N_STORAGE"
36 #define USBHOST_PATH "/opt/storage/usb"
38 static int storage_usbhost_get_state()
40 int usbhost_state = 0;
42 vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhost_state);
44 switch (usbhost_state)
46 case VCONFKEY_SYSMEN_USB_HOST_DISCONNECTED:
47 return STORAGE_STATE_REMOVED;
49 case VCONFKEY_SYSMEN_USB_HOST_CONNECTED:
50 return STORAGE_STATE_MOUNTED;
53 return STORAGE_STATE_REMOVED;
57 static void storage_usbhost_state_cb_broker(keynode_t* key, void* data)
59 storage_state_e state;
61 state = storage_usbhost_get_state();
63 storage_dispatch_state_event(state, data);
66 static int storage_usbhost_set_state_cb(void *data)
68 vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS, storage_usbhost_state_cb_broker, data);
72 static void storage_usbhost_unset_state_cb()
74 vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS, storage_usbhost_state_cb_broker);
78 static int storage_usbhost_get_space(unsigned long long *total, unsigned long long *available)
80 storage_state_e state;
81 state = storage_usbhost_get_state();
83 if (state < STORAGE_STATE_MOUNTED)
90 if (available != NULL)
99 return storage_statfs(USBHOST_PATH, total, available);
104 storage_device_h storage_usbhost_device()
106 storage_device_h device;
108 device = calloc(1, sizeof(struct storage_device_s));
112 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, STORAGE_ERROR_OUT_OF_MEMORY);
116 device->type = STORAGE_TYPE_EXTERNAL;
117 device->path = USBHOST_PATH;
118 device->get_state = storage_usbhost_get_state;
119 device->set_state_cb = storage_usbhost_set_state_cb;
120 device->unset_state_cb = storage_usbhost_unset_state_cb;
121 device->get_space = storage_usbhost_get_space;