summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorwchang kim <wchang.kim@samsung.com>2016-07-28 11:19:09 +0900
committerwchang kim <wchang.kim@samsung.com>2016-07-29 16:32:41 +0900
commit9c46953a0ed423efff156557e93448736d75ea8d (patch)
treee1da82ea87bf8948f14da85f1d666b67ed45f4a0 /src
parent146ddab6213428a7b2865d10311525a1f549957c (diff)
downloadsystem-plugin-9c46953a0ed423efff156557e93448736d75ea8d.tar.gz
system-plugin-9c46953a0ed423efff156557e93448736d75ea8d.tar.bz2
system-plugin-9c46953a0ed423efff156557e93448736d75ea8d.zip
Description : Adding new package of liblazymount and build enviroment for autotools
Adding new pacakge for lazy mount feature. It has the library and path activator service for mounting user patition(/opt/usr). Adding the build environment for autotools. This change need the change of BuildArch for system-plugin. system-plugin-<version>.noarch.rpm --> system-plugin-<version>.<arch>.rpm Change-Id: I107e7610659fcbbcda7b8b27abb645251c069296 Signed-off-by: Woochang Kim <wchang.kim@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/liblazymount/lazy_mount.h75
-rw-r--r--src/liblazymount/lazy_mount_interface.c155
-rw-r--r--src/liblazymount/liblazymount.pc.in17
-rw-r--r--src/liblazymount/test_lazymount.c70
4 files changed, 317 insertions, 0 deletions
diff --git a/src/liblazymount/lazy_mount.h b/src/liblazymount/lazy_mount.h
new file mode 100644
index 0000000..c534b6c
--- /dev/null
+++ b/src/liblazymount/lazy_mount.h
@@ -0,0 +1,75 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * liblazymount
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _LAZY_MOUNT_H_
+#define _LAZY_MOUNT_H_ 1
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Get the check value wheter system need the ui for lazy mount feature.
+ * @return 1 if system should show the ui for lazy mount feature, otherwise 0.
+ * @par Example
+ @code
+ #include <lazy_mount.h>
+
+ int show_ui;
+
+ show_ui = get_need_ui_for_lazy_mount();
+
+ @endcode
+ */
+int get_need_ui_for_lazy_mount();
+
+/**
+ * @brief Create /tmp/.lazy_mount file to mount user partion to /opt/usr.
+ * @return 0 if success to create /tmp/.lazy_mount, otherwise -errno.
+ * @par Example
+ @code
+ #include <lazy_mount.h>
+
+ int result;
+
+ result = do_mount_user();
+
+ @endcode
+ */
+int do_mount_user();
+
+/**
+ * @brief Wait for complete to mount user partion to /opt/usr.
+ * @return 0 if success to mount it, otherwise -errno.
+ * @par Example
+ @code
+ #include <lazy_mount.h>
+
+ int result;
+
+ result = wait_mount_user();
+
+ @endcode
+ */
+int wait_mount_user();
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#endif // _LAZY_MOUNT_H_
diff --git a/src/liblazymount/lazy_mount_interface.c b/src/liblazymount/lazy_mount_interface.c
new file mode 100644
index 0000000..ec35fa6
--- /dev/null
+++ b/src/liblazymount/lazy_mount_interface.c
@@ -0,0 +1,155 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * liblazymount
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <poll.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/inotify.h>
+#include <vconf.h>
+
+#ifndef VCONFKEY_SYSTEM_LAZY_MOUNT_SHOW_UI
+#define VCONFKEY_SYSTEM_LAZY_MOUNT_SHOW_UI "db/system/lazy_mount_show_ui"
+#endif
+#define DEFAULT_VALUE_LAZY_MOUNT_SHOW_UI 1
+
+#define LAZY_MOUNT_FILE "/tmp/.lazy_mount"
+#define LAZY_MOUNT_CHECK_DIR "/run"
+#define UNLOCK_MNT_STR ".unlock_mnt"
+#define LAZY_MOUNT_CHECK_FILE LAZY_MOUNT_CHECK_DIR "/" UNLOCK_MNT_STR
+
+#define EVENT_NAME_MAX 256
+#define EVENT_SIZE ( sizeof (struct inotify_event) )
+#define EVENT_BUF_LEN ( 512 * ( EVENT_SIZE + EVENT_NAME_MAX ) )
+
+/* Enumerate list of FDs to poll */
+enum {
+ FD_POLL_INOTIFY=0,
+ FD_POLL_MAX
+};
+
+int get_need_ui_for_lazy_mount()
+{
+ int sl_result = 0;
+ /* get touchkey light duration setting */
+ if (vconf_get_int(VCONFKEY_SYSTEM_LAZY_MOUNT_SHOW_UI, &sl_result) < 0)
+ {
+ return DEFAULT_VALUE_LAZY_MOUNT_SHOW_UI;
+ }
+
+ if(sl_result != 1 && sl_result != 0)
+ {
+ return DEFAULT_VALUE_LAZY_MOUNT_SHOW_UI;
+ }
+
+ return sl_result;
+}
+
+int do_mount_user()
+{
+ FILE *f = NULL;
+
+ f = fopen(LAZY_MOUNT_FILE, "w");
+ if (!f)
+ {
+ return -errno;
+ }
+
+ fclose(f);
+ return 0;
+}
+
+int wait_mount_user()
+{
+ int fd, wd;
+ char buffer[EVENT_BUF_LEN];
+ int length;
+ struct pollfd fds[FD_POLL_MAX];
+ int i;
+
+ fd = access(LAZY_MOUNT_CHECK_FILE, F_OK);
+
+ if(fd == 0)
+ {
+ return 0;
+ }
+
+ fd = inotify_init();
+
+ if(fd < 0)
+ {
+ return -errno;
+ }
+
+ wd = inotify_add_watch(fd, LAZY_MOUNT_CHECK_DIR, IN_CREATE|IN_MODIFY|IN_ATTRIB);
+
+ fds[FD_POLL_INOTIFY].fd = fd;
+ fds[FD_POLL_INOTIFY].events = POLLIN;
+
+ while(1)
+ {
+ if(poll(fds, FD_POLL_MAX, -1) < 0)
+ {
+ inotify_rm_watch(fd, wd);
+ close(fd);
+ return -errno;
+ }
+ if(fds[FD_POLL_INOTIFY].revents & POLLIN)
+ {
+ length = read(fds[FD_POLL_INOTIFY].fd, buffer, EVENT_BUF_LEN);
+
+ if( length < 0 )
+ {
+ inotify_rm_watch(fd, wd);
+ close(fd);
+ return -errno;
+ }
+
+ i = 0;
+ while ( i < length ) {
+ struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
+ if ( event->len > 0 && event->len < EVENT_NAME_MAX)
+ {
+ if ( event->mask & (IN_CREATE|IN_MODIFY|IN_ATTRIB) )
+ {
+ if (!(event->mask & IN_ISDIR))
+ {
+ if(!strncmp(event->name, UNLOCK_MNT_STR, sizeof(UNLOCK_MNT_STR)))
+ {
+ inotify_rm_watch(fd, wd);
+ close(fd);
+ return 0;
+ }
+ }
+ }
+ }
+ i += EVENT_SIZE + event->len;
+ }
+ }
+ }
+
+ inotify_rm_watch(fd, wd);
+ close(fd);
+
+ return -1;
+}
diff --git a/src/liblazymount/liblazymount.pc.in b/src/liblazymount/liblazymount.pc.in
new file mode 100644
index 0000000..cf9c9cc
--- /dev/null
+++ b/src/liblazymount/liblazymount.pc.in
@@ -0,0 +1,17 @@
+# Package Information for pkg-config
+#
+# Copyright (c) 2016 Samsung Electronics Co., Ltd.
+# All rights reserved.
+#
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: liblazymount
+Description: system utility libraries for lazy-mount
+Version: @PACKAGE_VERSION@
+Requires.private: @LIBLAZYMOUNT_PC_REQUIRES@
+Cflags: @LIBLAZYMOUNT_PC_CFLAGS@
+Libs: @LIBLAZYMOUNT_PC_LIBS@
diff --git a/src/liblazymount/test_lazymount.c b/src/liblazymount/test_lazymount.c
new file mode 100644
index 0000000..41c74b2
--- /dev/null
+++ b/src/liblazymount/test_lazymount.c
@@ -0,0 +1,70 @@
+#include <lazy_mount.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int get_input()
+{
+ int data;
+ int i = 0;
+ char c_data[2];
+ while(1)
+ {
+ data = getchar();
+ if( i < 2 )
+ {
+ c_data[i] = (char)data;
+ }
+ i++;
+ if(data == 10 || data == 13)
+ {
+ break;
+ }
+ }
+ if( i > 2 )
+ {
+ return -1;
+ }
+ c_data[1] = 0;
+ return atoi(c_data);
+}
+
+int main(int argc, char **argv)
+{
+ int data;
+ int sl_ret;
+ while(1)
+ {
+ printf("Test\n");
+ printf("1. get_need_ui_for_lazy_mount()\n");
+ printf("2. do_mount_user()\n");
+ printf("3. wait_mount_user()\n");
+ printf("4. Exit to test.\n");
+ printf("Select test : ");
+ data = get_input();
+
+ switch(data)
+ {
+ case 1:
+ sl_ret = get_need_ui_for_lazy_mount();
+ printf("get_need_ui_for_lazy_mount() returns %d\n", sl_ret);
+ break;
+ case 2:
+ printf("Doing mount user data....\n");
+ sl_ret = do_mount_user();
+ printf("do_mount_user() returns %d\n", sl_ret);
+ break;
+ case 3:
+ printf("Waiting mount user data....\n");
+ sl_ret = wait_mount_user();
+ printf("wait_mount_user() returns %d\n", sl_ret);
+ break;
+ case 4:
+ printf("exit\n");
+ return 0;
+ default:
+ printf("Unknown : %d\n", data);
+ break;
+ }
+ }
+ return 0;
+}