sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// PosixFilesystem class
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "SYSIF.H"
|
sl@0
|
19 |
#include "FDESC.H"
|
sl@0
|
20 |
#include "LTIME.H"
|
sl@0
|
21 |
#include "LPOSIX.H"
|
sl@0
|
22 |
#include <fcntl.h>
|
sl@0
|
23 |
#include <sys/errno.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
wchar_t * PosixFilesystem::getcwd (RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno)
|
sl@0
|
26 |
{
|
sl@0
|
27 |
TFullName name;
|
sl@0
|
28 |
TInt err = aFs.SessionPath(name);
|
sl@0
|
29 |
if (!err)
|
sl@0
|
30 |
{
|
sl@0
|
31 |
TPtr16 pathdes((TText16 *)buf, len);
|
sl@0
|
32 |
if (pathdes.MaxLength() >= (name.Length() + 1)) //+1 to allow for the null terminator
|
sl@0
|
33 |
{
|
sl@0
|
34 |
pathdes.Copy(name);
|
sl@0
|
35 |
pathdes.ZeroTerminate();
|
sl@0
|
36 |
return buf;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
else
|
sl@0
|
39 |
err = ERANGE; //out of range
|
sl@0
|
40 |
}
|
sl@0
|
41 |
MapError(err, anErrno);
|
sl@0
|
42 |
return 0;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
int PosixFilesystem::chdir (RFs& aFs, const wchar_t* aPath, int& anErrno)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
TParse name;
|
sl@0
|
48 |
TInt err=GetFullPath(name, (const TText16 *)aPath, aFs, NULL);
|
sl@0
|
49 |
if (!err)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
TPtrC path=name.DriveAndPath();
|
sl@0
|
52 |
TUint att=0;
|
sl@0
|
53 |
if (path.Length()==3) // Problem in F32 - the root directory has no attributes
|
sl@0
|
54 |
att=KEntryAttDir;
|
sl@0
|
55 |
else
|
sl@0
|
56 |
err=aFs.Att(path, att);
|
sl@0
|
57 |
if (!err)
|
sl@0
|
58 |
if (att&KEntryAttDir)
|
sl@0
|
59 |
err=aFs.SetSessionPath(path);
|
sl@0
|
60 |
else
|
sl@0
|
61 |
err=ENOTDIR;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
return MapError(err,anErrno);
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
int PosixFilesystem::rmdir (RFs& aFs, const wchar_t* aPath, int& anErrno)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
TParse name;
|
sl@0
|
69 |
TInt err=GetFullPath(name,(const TText16 *)aPath,aFs,NULL);
|
sl@0
|
70 |
if (!err)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
TPtrC path=name.DriveAndPath();
|
sl@0
|
73 |
TUint att=0;
|
sl@0
|
74 |
if (path.Length()==3)
|
sl@0
|
75 |
err=EPERM; // no, you may not remove the root directory
|
sl@0
|
76 |
else
|
sl@0
|
77 |
err=aFs.Att(path, att);
|
sl@0
|
78 |
if (!err)
|
sl@0
|
79 |
if (att&KEntryAttDir)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
err=aFs.RmDir(path);
|
sl@0
|
82 |
if (err==KErrInUse)
|
sl@0
|
83 |
err=EEXIST; // i.e. directory not empty
|
sl@0
|
84 |
}
|
sl@0
|
85 |
else
|
sl@0
|
86 |
err=ENOTDIR;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
return MapError(err,anErrno);
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
|
sl@0
|
92 |
|
sl@0
|
93 |
int PosixFilesystem::mkdir (RFs& aFs, const wchar_t* aPath, int perms, int& anErrno)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
TParse name;
|
sl@0
|
96 |
TInt err=GetFullPath(name,(const TText16 *)aPath,aFs,NULL);
|
sl@0
|
97 |
if (!err)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
TPtrC path=name.DriveAndPath();
|
sl@0
|
100 |
err=aFs.MkDir(path);
|
sl@0
|
101 |
if (!err)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
if ((perms&S_IWUSR)==0)
|
sl@0
|
104 |
err=aFs.SetAtt(path,KEntryAttReadOnly,0);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
}
|
sl@0
|
107 |
return MapError(err,anErrno);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
int PosixFilesystem::stat (RFs& aFs, const wchar_t* name, struct stat *st, int& anErrno)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
TFullName fullName;
|
sl@0
|
113 |
TInt err=GetFullFile(fullName,(const TText16*)name,aFs);
|
sl@0
|
114 |
if (!err)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
TEntry entry;
|
sl@0
|
117 |
if (fullName.Length()==3)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
entry.iAtt=KEntryAttDir;
|
sl@0
|
120 |
entry.iModified==TTime(0);
|
sl@0
|
121 |
}
|
sl@0
|
122 |
else
|
sl@0
|
123 |
err=aFs.Entry(fullName,entry);
|
sl@0
|
124 |
if (!err)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
st->st_size = entry.iSize;
|
sl@0
|
127 |
st->st_dev = st->st_rdev = (dev_t)TDriveUnit(fullName);
|
sl@0
|
128 |
CFileDesc::MapStat(*st, entry.iModified, entry.iAtt);
|
sl@0
|
129 |
return 0;
|
sl@0
|
130 |
}
|
sl@0
|
131 |
}
|
sl@0
|
132 |
return MapError(err, anErrno);
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
int PosixFilesystem::chmod (RFs& aFs, const wchar_t* name, int perms, int& anErrno)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
TFullName fullName;
|
sl@0
|
138 |
TInt err=GetFullFile(fullName,(const TText16*)name,aFs);
|
sl@0
|
139 |
if (!err)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
if ((perms&S_IWUSR)==0)
|
sl@0
|
142 |
err=aFs.SetAtt(fullName,KEntryAttReadOnly,0);
|
sl@0
|
143 |
else
|
sl@0
|
144 |
err=aFs.SetAtt(fullName,0,KEntryAttReadOnly);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
return MapError(err, anErrno);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
int PosixFilesystem::unlink (RFs& aFs, const wchar_t* name, int& anErrno)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
TFullName fullName;
|
sl@0
|
152 |
TInt err=GetFullFile(fullName, (TText16*)name, aFs);
|
sl@0
|
153 |
if (!err)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
TUint att=0;
|
sl@0
|
156 |
err=aFs.Att(fullName, att);
|
sl@0
|
157 |
if (!err)
|
sl@0
|
158 |
if (att&KEntryAttDir)
|
sl@0
|
159 |
err=EPERM;
|
sl@0
|
160 |
else
|
sl@0
|
161 |
err=aFs.Delete(fullName);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
return MapError(err, anErrno);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
int PosixFilesystem::rename (RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
TFileName oldFullName;
|
sl@0
|
169 |
TInt err = GetFullFile(oldFullName,(const TText16 *)oldname,aFs);
|
sl@0
|
170 |
if (!err)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
TFileName newFullName;
|
sl@0
|
173 |
err = GetFullFile(newFullName,(const TText16 *)newname,aFs);
|
sl@0
|
174 |
if (!err)
|
sl@0
|
175 |
{
|
sl@0
|
176 |
// ANSI doesn't require specific handling when newname exists,
|
sl@0
|
177 |
// so we can just use the EPOC32 semantics and insist that
|
sl@0
|
178 |
// newname doesn't currently exist.
|
sl@0
|
179 |
err=aFs.Rename(oldFullName,newFullName);
|
sl@0
|
180 |
}
|
sl@0
|
181 |
}
|
sl@0
|
182 |
return MapError(err, anErrno);
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
|
sl@0
|
186 |
TInt PosixFilesystem::ResolvePath (RFs& aFs, TParse& aResult, const wchar_t* path, TDes* aFilename)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
return GetFullPath(aResult,(const TText16*)path,aFs,aFilename);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
|
sl@0
|
192 |
#ifdef __WINS__
|
sl@0
|
193 |
TInt PosixFilesystem::SetDefaultDir (RFs& /*aFs*/)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
// NB. don't do this on WINS because the executable is
|
sl@0
|
196 |
// something like w:\epoc32\release\wins\deb\mytest.exe (or just mytest.exe or
|
sl@0
|
197 |
// even ./mytest !!)
|
sl@0
|
198 |
return KErrNone;
|
sl@0
|
199 |
}
|
sl@0
|
200 |
#else
|
sl@0
|
201 |
TInt PosixFilesystem::SetDefaultDir (RFs& aFs)
|
sl@0
|
202 |
{
|
sl@0
|
203 |
TParse parse;
|
sl@0
|
204 |
parse.Set(RProcess().FileName(), NULL, NULL);
|
sl@0
|
205 |
#ifdef __SECURE_DATA__
|
sl@0
|
206 |
return aFs.SetSessionToPrivate(TDriveUnit(parse.Drive()));
|
sl@0
|
207 |
#else
|
sl@0
|
208 |
return aFs.SetSessionPath(parse.DriveAndPath());
|
sl@0
|
209 |
#endif
|
sl@0
|
210 |
}
|
sl@0
|
211 |
#endif
|