|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: LinuxFileSystemUtils |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <errno.h> |
|
20 #include <sys/statvfs.h> |
|
21 #include <sys/stat.h> |
|
22 #include <string> |
|
23 #include <stdlib.h> |
|
24 |
|
25 #include "javajniutils.h" |
|
26 #include "javacommonutils.h" |
|
27 #include "logger.h" |
|
28 |
|
29 #include "fileutilities.h" |
|
30 #include "linuxfilesystemutils.h" |
|
31 |
|
32 using namespace std; |
|
33 using namespace java::fileutils; |
|
34 using namespace java::util; |
|
35 |
|
36 /* |
|
37 * Implementation of LinuxFileSystemUtils.h |
|
38 * |
|
39 */ |
|
40 unsigned long LinuxFileSystemUtils::getAvailableSize(const char* aPath) |
|
41 { |
|
42 JELOG2(EJavaFile); |
|
43 struct statvfs fiData; |
|
44 |
|
45 int result = statvfs(aPath, &fiData); |
|
46 if (result < 0) |
|
47 { |
|
48 ELOG1(EJavaFile, |
|
49 " LinuxFileSystemUtils::GetAvailableSize(): Error %d ", errno); |
|
50 int error = errno; |
|
51 throw error; |
|
52 } |
|
53 return (fiData.f_bfree * fiData.f_bsize); |
|
54 } |
|
55 |
|
56 unsigned long LinuxFileSystemUtils::getUsedSize(const char* aPath) |
|
57 { |
|
58 JELOG2(EJavaFile); |
|
59 struct statvfs fsData; |
|
60 int result = statvfs(aPath, &fsData); |
|
61 if (result < 0) |
|
62 { |
|
63 ELOG1(EJavaFile, " LinuxFileSystemUtils::GetUsedSize(): Error %d ", |
|
64 errno); |
|
65 int error = errno; |
|
66 throw error; |
|
67 } |
|
68 |
|
69 return ((fsData.f_blocks - fsData.f_bfree) * fsData.f_bsize); |
|
70 |
|
71 } |
|
72 |
|
73 unsigned long LinuxFileSystemUtils::getTotalSize(const char* aPath) |
|
74 { |
|
75 JELOG2(EJavaFile); |
|
76 struct statvfs fsData; |
|
77 int result = statvfs(aPath, &fsData); |
|
78 if (result < 0) |
|
79 { |
|
80 ELOG1(EJavaFile, " LinuxFileSystemUtils::GetTotalSize(): Error %d ", |
|
81 errno); |
|
82 int error = errno; |
|
83 throw error; |
|
84 } |
|
85 |
|
86 return (fsData.f_blocks * fsData.f_frsize); |
|
87 } |
|
88 |
|
89 bool LinuxFileSystemUtils::isHidden(const char* aFile) |
|
90 { |
|
91 //Files in Linux are hidden if they have a "." as a prefix. |
|
92 //We need to search for "/." in the file name to confirm. Simple. Or is it? |
|
93 JELOG2(EJavaFile); |
|
94 std::string name(aFile); |
|
95 |
|
96 int lastIndex = name.find_last_of('/') ; |
|
97 if (name.at(lastIndex+1) == '.') |
|
98 { |
|
99 return true; |
|
100 } |
|
101 return false; |
|
102 } |
|
103 |
|
104 int LinuxFileSystemUtils::setHidden(const char* /*aFile*/, const bool /*aHide*/) |
|
105 { |
|
106 return 0; |
|
107 } |
|
108 |
|
109 string LinuxFileSystemUtils::listRoots() |
|
110 { |
|
111 string retValue(getenv("HOME")); |
|
112 return retValue; |
|
113 } |
|
114 |