Update contrib.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32\sfile\sf_dir.cpp
20 LOCAL_C CDirCB* GetDirFromHandle(TInt aHandle,CSessionFs* aSession)
22 // Get the dir control block from its handle.
25 return((CDirCB*)(SessionObjectFromHandle(aHandle,Dirs->UniqueID(),aSession)));
28 LOCAL_C TInt DoInitialise(CFsRequest* aRequest)
30 // Determine asynchronicity from dir control block
34 dir=GetDirFromHandle(aRequest->Message().Int3(),aRequest->Session());
36 return(KErrBadHandle);
37 aRequest->SetDrive(&dir->Drive());
38 aRequest->SetScratchValue((TUint)dir);
45 void fsDirReadPacked(TEntry* pE,TEntry* pEnd,volatile TInt& aLen,CDirCB& aDir)
47 // Read packed directory entries.
55 TRACE1(UTF::EBorder, UTraceModuleFileSys::ECDirCBReadL, EF32TraceUidFileSys, &aDir);
57 TRACE5(UTF::EBorder, UTraceModuleFileSys::ECDirCBReadLRet, EF32TraceUidFileSys,
58 KErrNone, e.iAtt, I64LOW(e.iModified.Int64()), I64HIGH(e.iModified.Int64()), e.iSize);
59 TInt len=EntrySize(e, EFalse);
60 TInt rLen=EntrySize(e, ETrue);
61 TEntry* pX=PtrAdd(pE,rLen);
65 TRACE1(UTF::EBorder, UTraceModuleFileSys::ECDirCBStoreLongEntryNameL, EF32TraceUidFileSys, &aDir);
66 aDir.StoreLongEntryNameL(e.iName);
67 TRACE1(UTF::EBorder, UTraceModuleFileSys::ECDirCBStoreLongEntryNameLRet, EF32TraceUidFileSys, KErrNone);
69 aDir.SetPending(ETrue);
76 * Flag the entry with KEntryAttPacked so we can unpack
77 * these fields as required at a later date...
79 pE->iAtt |= KEntryAttPacked;
82 * ...and pack the iSizeHigh and iReserved fields to the end of the name string
84 TUint32* pSizeHighSrc = PtrAdd((TUint32*)&e, sizeof(TEntry) - 2*sizeof(TInt));
85 TUint32* pSizeHighDst = PtrAdd((TUint32*)pE, EntrySize(*pE, EFalse));
87 *pSizeHighDst++ = *pSizeHighSrc++; // Copy length
88 *pSizeHighDst = *pSizeHighSrc; // Copy reserved
94 TInt TFsDirOpen::DoRequestL(CFsRequest* aRequest)
100 __PRINT(_L("TFsDirOpen::DoRequestL(CFsRequest* aRequest)"));
103 TPckgBuf<TUidType> pckgUid;
104 aRequest->ReadL(KMsgPtr2,pckgUid);
106 TInt r=aRequest->Drive()->DirOpen(aRequest->Session(),h,aRequest->Src().FullName().Mid(2),aRequest->Message().Int1(),uidType);
111 //DirRead does not have a filename / src stored, so if there are plugins installed which
112 //wish to intercept dirread1/packed then store the name in CDirCB::iName now.
113 CFsPlugin* plugin = NULL;
114 //Get the next plugin which is mounted on this drive (IsMounted called in NextPlugin)
115 //Do not check whether we're registered for current operation (in case not registered for EFsDirOpen)
116 while(FsPluginManager::NextPlugin(plugin,(CFsMessageRequest*)aRequest,(TBool)ETrue,(TBool)EFalse)==KErrNone && plugin)
118 if(plugin->IsRegistered(EFsDirReadOne) ||
119 plugin->IsRegistered(EFsDirReadPacked) ||
120 plugin->IsRegistered(EFsDirSubClose))
122 CDirCB* dir = GetDirFromHandle(h,aRequest->Session());
123 TPtrC name = aRequest->Src().FullName();
124 r = dir->SetName(&name);
125 CheckForLeaveAfterOpenL(r, aRequest, h);
130 TPtrC8 pH((TUint8*)&h,sizeof(TInt));
131 TRAP(r,aRequest->WriteL(KMsgPtr3,pH))
132 CheckForLeaveAfterOpenL(r, aRequest, h);
133 aRequest->Session()->IncResourceCount();
138 TInt TFsDirOpen::Initialise(CFsRequest* aRequest)
144 TInt r=ParseSubstPtr0(aRequest,aRequest->Src());
147 r=PathCheck(aRequest,aRequest->Src().FullName().Mid(2),&KCapFsSysDirOpen,&KCapFsPriDirOpen, __PLATSEC_DIAGNOSTIC_STRING("Dir Open"));
154 TInt TFsDirReadOne::DoRequestL(CFsRequest* aRequest)
156 // Read one directory entry.
159 __PRINT(_L("TFsDirReadOne::DoRequestL(CFsRequest* aRequest)"));
160 CDirCB* dir=(CDirCB*)aRequest->ScratchValue();
161 TInt r=dir->CheckMount();
166 TRACE1(UTF::EBorder, UTraceModuleFileSys::ECDirCBReadL, EF32TraceUidFileSys, &dir);
167 TRAP(r,dir->ReadL(e))
168 TRACE5(UTF::EBorder, UTraceModuleFileSys::ECDirCBReadLRet, EF32TraceUidFileSys,
169 KErrNone, e.iAtt, I64LOW(e.iModified.Int64()), I64HIGH(e.iModified.Int64()), e.iSize);
174 TPckgC<TEntry> pE(e);
175 aRequest->WriteL(KMsgPtr0,pE);
180 TInt TFsDirReadOne::Initialise(CFsRequest* aRequest)
185 return(DoInitialise(aRequest));
188 TInt TFsDirReadPacked::DoRequestL(CFsRequest* aRequest)
190 // Read packed directory entries.
194 __PRINT(_L("TFsDirReadPacked::DoRequestL(CFsRequest* aRequest)"));
195 CDirCB* dir=(CDirCB*)aRequest->ScratchValue();
196 TInt r=dir->CheckMount();
200 TBuf8<KEntryArraySize> buf;
201 TEntry* pE=(TEntry*)buf.Ptr();
202 TEntry* pEnd=PtrAdd(pE,KEntryArraySize);
204 TRAP(r,fsDirReadPacked(pE,pEnd,len,*(dir)));
206 aRequest->WriteL(KMsgPtr0,buf);
210 TInt TFsDirReadPacked::Initialise(CFsRequest* aRequest)
212 // Call GetDirFromHandle to determine asynchronicity ***
215 return(DoInitialise(aRequest));
224 EXPORT_C CDirCB::CDirCB()
238 Frees resources before destruction of the object.
240 EXPORT_C CDirCB::~CDirCB()
244 RemoveResource(*iMount);
249 TInt CDirCB::CheckMount()
251 // Check that the media is still mounted.
256 TInt r=d.CheckMount();
259 if (&Mount()!=&d.CurrentMount())
260 return(KErrDisMounted);
264 EXPORT_C void CDirCB::InitL(TDrive* aDrive)
269 DoInitL(aDrive->DriveNumber());
271 iMount=&aDrive->CurrentMount();
272 User::LeaveIfError(iMount->Open());
279 Stores a long full entry name, a TEntry::iName value, into a buffer,
280 re-allocating the buffer first, if necessary, to make it large enough.
282 The function should be implemented by a derived class; this implementation
285 This function is called by a file server reading successive entries,
286 when the file server reads an entry for which the full file name is longer than
287 the maximum buffer size. Once this function has been called, the iPending flag
288 is set to true by the file server and, on the next call to ReadL(),
289 the buffer created in this function is used to store the long entry name.
291 The function should leave with an appropriate error code on error detection.
293 @param aName The name to be set to a newly read entry.
295 EXPORT_C void CDirCB::StoreLongEntryNameL(const TDesC& /*aName*/)
299 EXPORT_C TInt CDirCB::GetInterface(TInt /*aInterfaceId*/,TAny*& /*aInterface*/,TAny* /*aInput*/)
301 return(KErrNotSupported);