upload tizen2.0 alpha installmanager source
[sdk/installer/install-manager.git] / InstallManager_java / src / org / tizen / installmanager / lib / linux / LinuxFileSystemInfo.java
1 /*
2 *  InstallManager
3 *
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: 
7 * Wooyoung Cho <wooyoung1.cho@samsung.com>
8 * Shihyun Kim <shihyun.kim@samsung.com>
9 * Taeyoung Son <taeyoung2.son@samsung.com>
10 * Yongsung kim <yongsung1.kim@samsung.com>
11
12  * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 * Contributors:
25 * - S-Core Co., Ltd
26 *
27 */ 
28
29 package org.tizen.installmanager.lib.linux;
30
31 import java.io.BufferedReader;
32 import java.io.File;
33 import java.io.IOException;
34 import java.io.InputStreamReader;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.StringTokenizer;
38
39 import org.tizen.installmanager.lib.IFileSystemInformation;
40 import org.tizen.installmanager.lib.Log;
41
42
43 /**
44  * Provide information of linux file system.
45  * 
46  * @author Taeyoung Son <taeyoung2.son@samsung.com>
47  *
48  */
49 public class LinuxFileSystemInfo implements IFileSystemInformation {
50
51         @Override
52         public List<File> getListMounts() {
53                 List<File> mountList =  new ArrayList<File>();
54                 BufferedReader reader = null;
55                 InputStreamReader ipStream = null;
56                 
57                 try
58                 { 
59                         Process p=Runtime.getRuntime().exec("df -k"); 
60                         p.waitFor(); 
61                         ipStream = new InputStreamReader(p.getInputStream());
62                         reader = new BufferedReader(ipStream); 
63                         
64                         String line = reader.readLine();
65                         String partition = "";
66                         List<String> deviceInfo= new ArrayList<String>();
67                         while(line!=null)
68                         {
69                                 partition="";
70                                 StringTokenizer tokens = new StringTokenizer(line, " ");
71                                 int deviceNameColumn = tokens.countTokens();
72                                 while(tokens.hasMoreTokens()){
73                                         deviceInfo.add(tokens.nextToken());
74                                 }
75                                 for (int i=5; i < deviceNameColumn;i++) {
76                                         partition += deviceInfo.get(i);
77                                         if(i!=(deviceNameColumn-1))
78                                                 partition +=" ";
79                                 }
80                                 mountList.add(new File(partition));
81                                 deviceInfo.clear();
82                                 line=reader.readLine(); 
83                         }
84                         mountList.remove(0);
85
86                 } catch(IOException e1) {
87                         Log.ExceptionLog(e1);
88                 } catch(InterruptedException e2) {
89                         Log.ExceptionLog(e2);
90                 } finally {
91                         if (ipStream != null) {
92                                 try {
93                                         ipStream.close();
94                                 } catch (IOException e) {
95                                         Log.ExceptionLog(e);
96                                 }
97                         }
98                         
99                         if (reader != null) {
100                                 try {
101                                         reader.close();
102                                 } catch (IOException e) {
103                                         Log.ExceptionLog(e);
104                                 }
105                         }
106                 }
107
108                 return mountList;
109         }
110
111         @Override
112         public File[] getListDevices() {
113                 // TODO Auto-generated method stub
114                 return null;
115         }
116
117         @Override
118         public FileSystemType getFileSystemType(File disk) {
119                 // TODO Auto-generated method stub
120                 return FileSystemType.UNKNOWN;
121         }
122
123 }