14 // f32\sfile\sf_notif.cpp |
14 // f32\sfile\sf_notif.cpp |
15 // |
15 // |
16 // |
16 // |
17 |
17 |
18 #include "sf_std.h" |
18 #include "sf_std.h" |
19 |
19 #include "sf_notifier.h" |
20 |
20 #include "sf_pool.h" |
|
21 |
|
22 #ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
23 #include <f32notification.h> |
|
24 #endif |
21 |
25 |
22 TChangeQue FsNotify::iChangeQues[KMaxNotifyQues]; |
26 TChangeQue FsNotify::iChangeQues[KMaxNotifyQues]; |
23 TDiskSpaceQue FsNotify::iDiskSpaceQues[KMaxDiskQues]; |
27 TDiskSpaceQue FsNotify::iDiskSpaceQues[KMaxDiskQues]; |
24 TDebugQue FsNotify::iDebugQue; |
28 TDebugQue FsNotify::iDebugQue; |
25 TDismountNotifyQue FsNotify::iDismountNotifyQue; |
29 TDismountNotifyQue FsNotify::iDismountNotifyQue; |
|
30 |
|
31 _LIT(KEmptyString,""); |
|
32 |
|
33 CFsNotificationInfoBody::CFsNotificationInfoBody() |
|
34 : iSrc(KEmptyString), |
|
35 iSrcBuf(KEmptyString), |
|
36 iDest(KEmptyString), |
|
37 iDestDriveStored(EFalse), |
|
38 iFunction(KErrNotFound), |
|
39 iData(KErrNotFound), |
|
40 #ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
41 iNotificationType(TFsNotification::EOverflow), |
|
42 #else |
|
43 iNotificationType(KErrNotFound), |
|
44 #endif |
|
45 iUid(TUid::Null()) |
|
46 { |
|
47 } |
|
48 |
|
49 CFsNotificationInfo::CFsNotificationInfo() |
|
50 { |
|
51 } |
|
52 |
|
53 /* |
|
54 * These do not get deleted, they get Freed via CFsNotificationInfo::Free. |
|
55 */ |
|
56 CFsNotificationInfo::~CFsNotificationInfo() |
|
57 { |
|
58 Fault(ENotificationInfoDeletion); |
|
59 } |
|
60 |
|
61 TInt CFsNotificationInfo::Init(TInt aFunction, TInt aDriveNum) |
|
62 { |
|
63 //Clean notification before use |
|
64 CleanNotification(); |
|
65 |
|
66 iBody->iFunction = aFunction; |
|
67 TInt err = SetDriveNumber(aDriveNum); |
|
68 if(err != KErrNone) |
|
69 { |
|
70 return err; |
|
71 } |
|
72 |
|
73 //Set notification type |
|
74 #ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
75 CFsNotificationInfo::NotificationType(iBody->iFunction, iBody->iNotificationType); |
|
76 #else |
|
77 iBody->iNotificationType = KErrNotSupported; |
|
78 #endif |
|
79 return KErrNone; |
|
80 } |
|
81 |
|
82 void CFsNotificationInfo::CleanNotification() |
|
83 { |
|
84 //Clear all variables |
|
85 TParsePtrC empty(KEmptyString); |
|
86 memcpy(&iBody->iSrc,&empty,sizeof(TParsePtrC)); |
|
87 memcpy(&iBody->iDest,&empty,sizeof(TParsePtrC)); |
|
88 iBody->iData = KErrNotFound; |
|
89 iBody->iRequest = NULL; |
|
90 iBody->iDriveNumber = KErrNotFound; |
|
91 iBody->iUid = TUid::Null(); |
|
92 iBody->iDestDriveStored = EFalse; |
|
93 #ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
94 iBody->iNotificationType=TFsNotification::EOverflow; |
|
95 #else |
|
96 iBody->iNotificationType=KErrNotFound; |
|
97 #endif |
|
98 } |
|
99 |
|
100 EXPORT_C CFsNotificationInfo* CFsNotificationInfo::Allocate(const CMountCB& aMount, TInt aFunction) |
|
101 { |
|
102 CFsNotificationInfo* info = NotificationInfoPool->Allocate(); |
|
103 __ASSERT_DEBUG(info,User::Panic(_L("CFsNotificationInfo::Allocate, Could not allocate"),KErrNotFound)); |
|
104 |
|
105 TInt driveNum = aMount.Drive().DriveNumber(); |
|
106 __ASSERT_ALWAYS((driveNum >= EDriveA && driveNum <= EDriveZ), User::Panic(_L("CFsNotificationInfo::Allocate - Invalid Drive Num"),KErrArgument)); |
|
107 TInt err = info->Init(aFunction,driveNum); |
|
108 if(err != KErrNone) |
|
109 { |
|
110 Free(info); |
|
111 return NULL; |
|
112 } |
|
113 return info; |
|
114 } |
|
115 |
|
116 |
|
117 CFsNotificationInfo* CFsNotificationInfo::Allocate(CFsMessageRequest& aRequest) |
|
118 { |
|
119 //Get a notification Info block from the pool. |
|
120 CFsNotificationInfo* notificationInfo = NotificationInfoPool->Allocate(); |
|
121 |
|
122 //Set the function and call Init. |
|
123 TInt function = aRequest.Operation()->Function(); |
|
124 notificationInfo->iBody->iFunction = function; |
|
125 TInt err = notificationInfo->Init(function,aRequest.DriveNumber()); |
|
126 if(err != KErrNone) |
|
127 { |
|
128 CFsNotificationInfo::Free(notificationInfo); |
|
129 return NULL; |
|
130 } |
|
131 |
|
132 //Set request |
|
133 notificationInfo->SetRequest(&aRequest); |
|
134 |
|
135 //Set UID |
|
136 notificationInfo->SetUid(aRequest.Uid()); |
|
137 |
|
138 //Set notification type |
|
139 #ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
140 CFsNotificationInfo::SetData(&aRequest,notificationInfo); |
|
141 #endif |
|
142 |
|
143 CFsClientMessageRequest& msgRequest = (CFsClientMessageRequest&)aRequest; |
|
144 |
|
145 //Get and store Src |
|
146 CFsNotificationInfo::PathName(msgRequest,notificationInfo->Source()); |
|
147 |
|
148 //Get and store NewName/Dest |
|
149 switch(function) |
|
150 { |
|
151 case EFsFileRename: |
|
152 case EFsRename: |
|
153 case EFsReplace: |
|
154 case EFsSetDriveName: |
|
155 case EFsSetVolume: |
|
156 { |
|
157 CFsNotificationInfo::NewPathName((CFsClientMessageRequest&)aRequest,notificationInfo->NewName()); |
|
158 notificationInfo->iBody->iDestDriveStored = ETrue; |
|
159 } |
|
160 default: |
|
161 break; |
|
162 } |
|
163 return notificationInfo; |
|
164 } |
|
165 |
|
166 CFsNotificationInfo* CFsNotificationInfo::Allocate(TInt aFunction, TInt aDrive) |
|
167 { |
|
168 //Get a notification Info block from the pool. |
|
169 CFsNotificationInfo* notificationInfo = NotificationInfoPool->Allocate(); |
|
170 |
|
171 //Set the function and call Init. |
|
172 notificationInfo->iBody->iFunction = aFunction; |
|
173 TInt err = notificationInfo->Init(aFunction,aDrive); |
|
174 if(err != KErrNone) |
|
175 { |
|
176 CFsNotificationInfo::Free(notificationInfo); |
|
177 return NULL; |
|
178 } |
|
179 |
|
180 //Set request (NULL) |
|
181 notificationInfo->SetRequest(NULL); |
|
182 |
|
183 //Set UID (KNullUid) |
|
184 notificationInfo->SetUid(TUid::Null()); |
|
185 return notificationInfo; |
|
186 } |
|
187 |
|
188 EXPORT_C void CFsNotificationInfo::Free(CFsNotificationInfo*& aNotificationInfo) |
|
189 { |
|
190 __ASSERT_DEBUG(aNotificationInfo,User::Panic(_L("CFsNotificationInfo::Free - KErrArgument"), KErrArgument)); |
|
191 NotificationInfoPool->Free(aNotificationInfo); |
|
192 aNotificationInfo = NULL; |
|
193 } |
|
194 |
|
195 |
|
196 TInt CFsNotificationInfo::Initialise() |
|
197 { |
|
198 //Have to trap as sf_main.cpp commonInitialize doesn't. |
|
199 TRAPD(r, NotificationInfoPool = CFsPool<CFsNotificationInfo>::New(KMaxDrives,CFsNotificationInfo::New)); |
|
200 if(r != KErrNone) |
|
201 return r; |
|
202 if(!NotificationInfoPool) |
|
203 return KErrNoMemory; |
|
204 return KErrNone; |
|
205 } |
|
206 |
|
207 CFsNotificationInfo* CFsNotificationInfo::New() |
|
208 { |
|
209 CFsNotificationInfo* info = new CFsNotificationInfo; |
|
210 __ASSERT_ALWAYS(info,Fault(ENotifyPoolCreation)); |
|
211 info->iBody = new CFsNotificationInfoBody(); |
|
212 __ASSERT_ALWAYS(info->iBody,Fault(ENotifyPoolCreation)); |
|
213 return info; |
|
214 } |
|
215 |
|
216 EXPORT_C TInt CFsNotificationInfo::SetSourceName(const TDesC& aSrc) |
|
217 { |
|
218 //Add the aSrc to a TParsePtrC (no copying the filename) |
|
219 TParsePtrC sourceParsePtr(aSrc); |
|
220 |
|
221 if(sourceParsePtr.DrivePresent() || !sourceParsePtr.FullName().Length()) |
|
222 return KErrArgument; |
|
223 |
|
224 switch(iBody->iFunction) |
|
225 { |
|
226 |
|
227 case EFsFileWrite: //EParseSrc | EFileShare |
|
228 case EFsFileSetSize: //EParseSrc | EFileShare |
|
229 case EFsFileSetAtt: //EParseDst | EParseSrc, - should not use these; has share. |
|
230 case EFsFileSet: //EParseSrc | EFileShare |
|
231 case EFsFileSetModified: //EParseSrc | EFileShare - new |
|
232 case EFsFileWriteDirty: //EFileShare |
|
233 case EFsFileCreate: //EParseSrc |
|
234 case EFsFileTemp: //EParseSrc - new |
|
235 case EFsFileRename: //EParseDst | EParseSrc, |
|
236 case EFsFileReplace: //EParseSrc |
|
237 { |
|
238 //Should look like this: \[path\]filename |
|
239 if(!sourceParsePtr.Name().Length()) |
|
240 { |
|
241 return KErrArgument; |
|
242 } |
|
243 break; |
|
244 } |
|
245 case EFsDelete: //EParseSrc |
|
246 case EFsSetEntry: //EParseSrc, |
|
247 case EFsRename: //EParseDst | EParseSrc, |
|
248 case EFsReplace: //EParseDst | EParseSrc, |
|
249 { |
|
250 if(!sourceParsePtr.PathPresent() && !sourceParsePtr.NamePresent()) |
|
251 { |
|
252 return KErrArgument; |
|
253 } |
|
254 break; |
|
255 } |
|
256 case EFsRmDir: //EParseSrc |
|
257 case EFsMkDir: //EParseSrc |
|
258 { |
|
259 if(!sourceParsePtr.PathPresent()) |
|
260 { |
|
261 return KErrArgument; |
|
262 } |
|
263 break; |
|
264 } |
|
265 /*case EFsFormatNext: //EParseSrc |
|
266 case EFsDismountFileSystem: //0 |
|
267 case EFsMountFileSystem: //0 |
|
268 case EFsSetVolume: //0 |
|
269 case EFsSetDriveName: //ESync |
|
270 case EFsRawDiskWrite: //EParseSrc |
|
271 case EFsMountFileSystemScan: */ |
|
272 default: |
|
273 { |
|
274 __ASSERT_DEBUG(EFalse,User::Panic(_L("CFsNotificationInfo::SetSourceName Invalid Operation"),KErrArgument)); |
|
275 return KErrNotSupported; |
|
276 } |
|
277 } |
|
278 memcpy(&iBody->iSrc,&sourceParsePtr,sizeof(TParsePtrC)); |
|
279 return KErrNone; |
|
280 } |
|
281 |
|
282 EXPORT_C TInt CFsNotificationInfo::SetNewName(const TDesC& aDest) |
|
283 { |
|
284 //Add the aSrc to a TParsePtr for some validation without copying the filename |
|
285 TParsePtrC destParsePtr(aDest); |
|
286 |
|
287 if(destParsePtr.DrivePresent() || !destParsePtr.FullName().Length()) |
|
288 return KErrArgument; |
|
289 |
|
290 switch(iBody->iFunction) |
|
291 { |
|
292 case EFsFileRename: //EParseDst | EParseSrc, |
|
293 case EFsRename: //EParseDst | EParseSrc, |
|
294 case EFsReplace: //EParseDst | EParseSrc, |
|
295 { |
|
296 if(!destParsePtr.PathPresent() && !destParsePtr.NamePresent()) |
|
297 { |
|
298 return KErrArgument; |
|
299 } |
|
300 break; |
|
301 } |
|
302 case EFsSetDriveName: |
|
303 case EFsSetVolume: |
|
304 { |
|
305 if(!destParsePtr.NamePresent()) |
|
306 { |
|
307 return KErrArgument; |
|
308 } |
|
309 break; |
|
310 } |
|
311 default: |
|
312 { |
|
313 __ASSERT_DEBUG(ETrue,User::Panic(_L("CFsNotificationInfo::SetNewName Invalid Operation"),KErrArgument)); |
|
314 } |
|
315 } |
|
316 |
|
317 memcpy(&iBody->iDest,&destParsePtr,sizeof(TParsePtrC)); |
|
318 return KErrNone; |
|
319 } |
|
320 |
|
321 EXPORT_C TInt CFsNotificationInfo::SetFilesize(TInt64 aFilesize) |
|
322 { |
|
323 if(aFilesize<0) |
|
324 return KErrArgument; |
|
325 |
|
326 iBody->iData = aFilesize; |
|
327 return KErrNone; |
|
328 } |
|
329 EXPORT_C TInt CFsNotificationInfo::SetAttributes(TUint aSet,TUint aCleared) |
|
330 { |
|
331 iBody->iData = MAKE_TUINT64(aSet,aCleared); |
|
332 return KErrNone; |
|
333 } |
|
334 |
|
335 EXPORT_C TInt CFsNotificationInfo::SetUid(const TUid& aUid) |
|
336 { |
|
337 iBody->iUid = aUid; |
|
338 return KErrNone; |
|
339 } |
|
340 |
|
341 |
|
342 TInt CFsNotificationInfo::SetDriveNumber(TInt aDriveNumber) |
|
343 { |
|
344 if(aDriveNumber >= EDriveA && aDriveNumber <= EDriveZ) |
|
345 { |
|
346 iBody->iDriveNumber = aDriveNumber; |
|
347 return KErrNone; |
|
348 } |
|
349 return KErrArgument; |
|
350 } |
|
351 void CFsNotificationInfo::SetRequest(CFsRequest* aRequest) |
|
352 { |
|
353 iBody->iRequest = aRequest; |
|
354 } |
|
355 TInt CFsNotificationInfo::Function() |
|
356 { return iBody->iFunction; } |
|
357 TInt CFsNotificationInfo::DriveNumber() |
|
358 { return iBody->iDriveNumber; } |
|
359 TParsePtrC& CFsNotificationInfo::Source() |
|
360 { |
|
361 switch(iBody->iFunction) |
|
362 { |
|
363 case EFsFormatNext: //EParseSrc |
|
364 case EFsDismountFileSystem: //0 |
|
365 case EFsMountFileSystem: //0 |
|
366 case EFsSetVolume: //0 |
|
367 case EFsSetDriveName: //ESync |
|
368 case EFsRawDiskWrite: //EParseSrc |
|
369 case EFsMountFileSystemScan: |
|
370 { |
|
371 _LIT(KFormatDrive,"?:"); |
|
372 iBody->iSrcBuf = KFormatDrive; |
|
373 iBody->iSrcBuf[0] = TText(DriveNumber() + 'A'); |
|
374 TParsePtrC parse(iBody->iSrcBuf); |
|
375 memcpy(&iBody->iSrc,&parse,sizeof(TParsePtrC)); |
|
376 } |
|
377 } |
|
378 return iBody->iSrc; |
|
379 } |
|
380 TParsePtrC& CFsNotificationInfo::NewName() |
|
381 { return iBody->iDest; } |
|
382 CFsRequest* CFsNotificationInfo::Request() |
|
383 { return iBody->iRequest; } |
|
384 TInt64* CFsNotificationInfo::Data() |
|
385 { return &iBody->iData; } |
|
386 TUid& CFsNotificationInfo::Uid() |
|
387 { return iBody->iUid; } |
|
388 TNotificationType& CFsNotificationInfo::NotificationType() |
|
389 { return iBody->iNotificationType; } |
|
390 TBool CFsNotificationInfo::DestDriveIsSet() |
|
391 { return iBody->iDestDriveStored; } |
|
392 TInt CFsNotificationInfo::SourceSize() |
|
393 { |
|
394 TInt size = Source().FullName().Size(); |
|
395 if(NotificationType()!=TFsNotification::EMediaChange && |
|
396 NotificationType()!=TFsNotification::EDriveName && |
|
397 NotificationType()!=TFsNotification::EVolumeName) |
|
398 { |
|
399 size += sizeof(TText)*2; |
|
400 } |
|
401 return size; |
|
402 } |
|
403 TInt CFsNotificationInfo::NewNameSize() |
|
404 { |
|
405 TInt size = NewName().FullName().Size(); |
|
406 if(!DestDriveIsSet()) |
|
407 size += sizeof(TText)*2; |
|
408 return size; |
|
409 } |
|
410 |
|
411 //Get the path of the file, folder or drive name based on the TFsMessage function |
|
412 void CFsNotificationInfo::PathName(CFsClientMessageRequest& aRequest, TParsePtrC& aPath) |
|
413 { |
|
414 __PRINT(_L("CFsNotificationInfo::PathName")); |
|
415 //Get the notification type |
|
416 TInt function = aRequest.Operation()->Function(); |
|
417 |
|
418 //Get the filename(s) |
|
419 switch(function) |
|
420 { |
|
421 case EFsFileWrite: //EParseSrc | EFileShare |
|
422 case EFsFileSetSize: //EParseSrc | EFileShare |
|
423 case EFsFileSetAtt: //EParseDst | EParseSrc, - should not use these; has share. |
|
424 case EFsFileSet: //EParseSrc | EFileShare |
|
425 case EFsFileSetModified: //EParseSrc | EFileShare - new |
|
426 case EFsFileWriteDirty: //EFileShare |
|
427 { |
|
428 CFileShare* share = NULL; |
|
429 CFileCB* file = NULL; |
|
430 GetFileFromScratch(&aRequest,share,file); |
|
431 TParsePtrC ptrC(file->iFileName->Des()); |
|
432 memcpy(&aPath,&ptrC,sizeof(TParsePtrC)); |
|
433 break; |
|
434 } |
|
435 case EFsFileCreate: //EParseSrc |
|
436 case EFsFileTemp: //EParseSrc - new |
|
437 case EFsDelete: //EParseSrc |
|
438 case EFsSetEntry: //EParseSrc, |
|
439 case EFsFileRename: //EParseDst | EParseSrc, |
|
440 case EFsRename: //EParseDst | EParseSrc, |
|
441 case EFsReplace: //EParseDst | EParseSrc, |
|
442 case EFsFileReplace: //EParseSrc |
|
443 { |
|
444 TParsePtrC parsePtrC(aRequest.Src().FullName().Mid(2)); //Don't want drive letter |
|
445 memcpy(&aPath,&parsePtrC,sizeof(TParsePtrC)); |
|
446 break; |
|
447 } |
|
448 case EFsRmDir: //EParseSrc |
|
449 case EFsMkDir: //EParseSrc |
|
450 { |
|
451 TParsePtrC parsePtrC(aRequest.Src().Path()); |
|
452 memcpy(&aPath,&parsePtrC,sizeof(TParsePtrC)); |
|
453 break; |
|
454 |
|
455 //aPath.Set(aRequest.Src().DriveAndPath(),NULL,NULL); |
|
456 //break; |
|
457 } |
|
458 case EFsFormatNext: //EParseSrc |
|
459 case EFsDismountFileSystem: //0 |
|
460 case EFsMountFileSystem: //0 |
|
461 case EFsSetVolume: //0 |
|
462 case EFsSetDriveName: //ESync |
|
463 case EFsRawDiskWrite: //EParseSrc |
|
464 case EFsLockDrive: |
|
465 case EFsUnlockDrive: |
|
466 case EFsReserveDriveSpace: |
|
467 case EFsMountFileSystemScan: |
|
468 { |
|
469 break; |
|
470 } |
|
471 default: |
|
472 ASSERT(0); |
|
473 break; |
|
474 } |
|
475 } |
|
476 |
|
477 //Get the new path of the file, folder or drive name based on the TFsMessage function |
|
478 void CFsNotificationInfo::NewPathName(CFsClientMessageRequest& aRequest, TParsePtrC& aNewPath) |
|
479 { |
|
480 __PRINT(_L("CFsNotificationInfo::NewPathName")); |
|
481 //Get the notification type |
|
482 TInt function = aRequest.Operation()->Function(); |
|
483 |
|
484 //Get the filename(s) |
|
485 switch(function) |
|
486 { |
|
487 case EFsFileRename: //EParseDst | EParseSrc, |
|
488 case EFsRename: //EParseDst | EParseSrc, |
|
489 case EFsReplace: //EParseDst | EParseSrc, |
|
490 { |
|
491 //We must provide the drive letter too as in the case |
|
492 //of the file being monitored being renamed to a |
|
493 //different drive. |
|
494 //In that case we need to provide the new drive letter to the client. |
|
495 TParsePtrC ptrC(aRequest.Dest().FullName()); |
|
496 memcpy(&aNewPath,&ptrC,sizeof(TParsePtrC)); |
|
497 break; |
|
498 } |
|
499 case EFsSetVolume: //EParseDst |
|
500 case EFsSetDriveName: //ESync | EParseDst |
|
501 { |
|
502 TParsePtrC ptrC(aRequest.Dest().FullName()); |
|
503 memcpy(&aNewPath,&ptrC,sizeof(TParsePtrC)); |
|
504 break; |
|
505 } |
|
506 default: |
|
507 { |
|
508 ASSERT(0); |
|
509 } |
|
510 } |
|
511 } |
|
512 |
|
513 //Get the size of the notification based on its type |
|
514 TInt CFsNotificationInfo::NotificationSize(CFsNotificationInfo& aRequest) |
|
515 { |
|
516 __PRINT(_L("CFsNotificationInfo::NotificationSize")); |
|
517 |
|
518 /* |
|
519 * If there are no new names, the order of the data in the buffer is: |
|
520 * Word1 : NotificationSize (2 bytes) , PathSize (2 bytes) |
|
521 * Word2 : NotificationType (Lower 2 bytes) |
|
522 * Word3 : UID |
|
523 * Word(s) : Path (TText8) , [Any sub-class members] |
|
524 * |
|
525 * Else for notification types ERename, EVolumeName and EDriveName the order is: |
|
526 * Word1 : NotificationSize (2 bytes) , PathSize (2 bytes) |
|
527 * Word2 : NewNameSize (2 bytes) , NotificationType (2 bytes) |
|
528 * Word3 : UID |
|
529 * Word(s) : Path (TText8) , NewName (TText8) |
|
530 * |
|
531 * EOverflow size: KNotificationHeaderSize |
|
532 */ |
|
533 |
|
534 //Size of the filename +(with '<drive>:') |
|
535 TInt size = KNotificationHeaderSize + Align4(aRequest.SourceSize()); |
|
536 |
|
537 switch(aRequest.NotificationType()) |
|
538 { |
|
539 //NewName |
|
540 case TFsNotification::ERename: |
|
541 case TFsNotification::EVolumeName: |
|
542 case TFsNotification::EDriveName: |
|
543 { |
|
544 if(!aRequest.NewName().FullName().Length()) |
|
545 __ASSERT_ALWAYS(false,User::Panic(_L("CFsNotificationInfo::NotificationSize"),KErrArgument)); |
|
546 |
|
547 size += Align4(aRequest.NewNameSize()); |
|
548 break; |
|
549 } |
|
550 case TFsNotification::EFileChange: |
|
551 { |
|
552 size += sizeof(TInt64); |
|
553 break; |
|
554 } |
|
555 case TFsNotification::EAttribute: |
|
556 { |
|
557 size += sizeof(TUint64); |
|
558 break; |
|
559 } |
|
560 case TFsNotification::ECreate: |
|
561 case TFsNotification::EDelete: |
|
562 case TFsNotification::EMediaChange: |
|
563 { |
|
564 break; |
|
565 } |
|
566 default: |
|
567 { |
|
568 ASSERT(0); |
|
569 break; |
|
570 } |
|
571 } |
|
572 return (TUint16) size; |
|
573 } |
|
574 |
|
575 |
|
576 TNotificationType CFsNotificationInfo::NotificationType(TInt& aIndex) |
|
577 { |
|
578 __PRINT(_L("CFsNotificationInfo::NotificationType(TInt)")); |
|
579 __ASSERT_DEBUG(aIndex < KNumRegisterableFilters, Fault(ENotificationFault)); |
|
580 |
|
581 switch(aIndex) //No break statements here on purpose |
|
582 { |
|
583 case 7 : return TFsNotification::EMediaChange; |
|
584 case 6 : return TFsNotification::EDriveName; |
|
585 case 5 : return TFsNotification::EVolumeName; |
|
586 case 4 : return TFsNotification::EDelete; |
|
587 case 3 : return TFsNotification::EAttribute; |
|
588 case 2 : return TFsNotification::ECreate; |
|
589 case 1 : return TFsNotification::ERename; |
|
590 case 0 : return TFsNotification::EFileChange; |
|
591 default: ASSERT(0); return (TFsNotification::TFsNotificationType) 0; |
|
592 } |
|
593 } |
|
594 |
|
595 //Get the array index of the notification based on its type |
|
596 TInt CFsNotificationInfo::TypeToIndex(TNotificationType aType) |
|
597 { |
|
598 __PRINT(_L("CFsNotificationInfo::ArrayIndex")); |
|
599 |
|
600 TInt index = 0; |
|
601 switch(aType) //No break statements here on purpose |
|
602 { |
|
603 case TFsNotification::EMediaChange: index++; |
|
604 case TFsNotification::EDriveName: index++; |
|
605 case TFsNotification::EVolumeName: index++; |
|
606 case TFsNotification::EDelete: index++; |
|
607 case TFsNotification::EAttribute: index++; |
|
608 case TFsNotification::ECreate: index++; |
|
609 case TFsNotification::ERename: index++; |
|
610 case TFsNotification::EFileChange: // skip; |
|
611 default: break; |
|
612 } |
|
613 __ASSERT_DEBUG(index < KNumRegisterableFilters, Fault(ENotificationFault)); |
|
614 return index; |
|
615 } |
|
616 |
|
617 TInt CFsNotificationInfo::DriveNumber(const TPtrC& aPath) |
|
618 { |
|
619 if(aPath.Length() >= 1) |
|
620 { |
|
621 TInt drive; |
|
622 TInt r = RFs::CharToDrive(aPath[0],drive); |
|
623 if(r!=KErrNone) |
|
624 return KErrNotFound; |
|
625 return drive; |
|
626 } |
|
627 return KErrNotFound; |
|
628 } |
|
629 |
|
630 //Get the attributes set and cleared |
|
631 void CFsNotificationInfo::Attributes(CFsMessageRequest& aRequest, TUint& aSet, TUint& aClear) |
|
632 { |
|
633 __PRINT(_L("CFsNotificationInfo::Attributes")); |
|
634 |
|
635 TInt function = aRequest.Operation()->Function(); |
|
636 const RMessage2& msg = aRequest.Message(); |
|
637 |
|
638 //Client notification |
|
639 switch(function) |
|
640 { |
|
641 case EFsFileSet: |
|
642 { |
|
643 aSet = msg.Int1(); |
|
644 aClear = msg.Int2(); |
|
645 break; |
|
646 } |
|
647 case EFsFileSetAtt: |
|
648 { |
|
649 aSet = msg.Int0(); |
|
650 aClear = msg.Int1(); |
|
651 break; |
|
652 } |
|
653 case EFsSetEntry: |
|
654 { |
|
655 aSet = msg.Int2(); |
|
656 aClear = msg.Int3(); |
|
657 break; |
|
658 } |
|
659 default: |
|
660 { |
|
661 ASSERT(0); |
|
662 break; |
|
663 } |
|
664 } |
|
665 } |
|
666 |
|
667 TInt64 CFsNotificationInfo::FileSize(CFsMessageRequest& aRequest) |
|
668 { |
|
669 CFileShare* share = NULL; |
|
670 CFileCB* file = NULL; |
|
671 GetFileFromScratch(&aRequest, share, file); |
|
672 TInt64 size = file->CachedSize64(); |
|
673 return size; |
|
674 } |
|
675 |
|
676 |
|
677 void CFsNotificationInfo::SetData(CFsMessageRequest* aRequest, CFsNotificationInfo* aNotificationInfo) |
|
678 { |
|
679 TInt function = aRequest->Operation()->Function(); |
|
680 |
|
681 switch(function) |
|
682 { |
|
683 case EFsFileWrite: |
|
684 case EFsFileWriteDirty: |
|
685 case EFsFileSetSize: |
|
686 { |
|
687 aNotificationInfo->SetFilesize(FileSize(*aRequest)); |
|
688 break; |
|
689 } |
|
690 case EFsSetEntry: |
|
691 case EFsFileSetAtt: |
|
692 case EFsFileSet: |
|
693 { |
|
694 TUint set = 0; |
|
695 TUint clear = 0; |
|
696 Attributes(*aRequest,set,clear); |
|
697 *(aNotificationInfo->Data())= MAKE_TUINT64(set,clear); |
|
698 break; |
|
699 } |
|
700 default: |
|
701 { |
|
702 return; |
|
703 } |
|
704 } |
|
705 } |
|
706 |
|
707 TInt CFsNotificationInfo::ValidateNotification(CFsNotificationInfo& aNotificationInfo) |
|
708 { |
|
709 //Validate UID |
|
710 if(aNotificationInfo.Uid() == TUid::Null()) |
|
711 { |
|
712 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Uid not set"),KErrArgument)); |
|
713 return KErrArgument; |
|
714 } |
|
715 |
|
716 switch(aNotificationInfo.Function()) |
|
717 { |
|
718 case EFsFileWrite: |
|
719 case EFsFileWriteDirty: |
|
720 case EFsFileSetSize: |
|
721 { |
|
722 if(*aNotificationInfo.Data() == -1) |
|
723 { |
|
724 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - File size not set"),KErrArgument)); |
|
725 return KErrArgument; |
|
726 } |
|
727 if(!aNotificationInfo.Source().FullName().Length()) |
|
728 { |
|
729 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Source Name not set"),KErrArgument)); |
|
730 return KErrArgument; |
|
731 } |
|
732 if(aNotificationInfo.NewName().FullName().Length()) |
|
733 { |
|
734 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - New Name set in err"),KErrArgument)); |
|
735 return KErrArgument; |
|
736 } |
|
737 break; |
|
738 } |
|
739 case EFsRename: |
|
740 case EFsFileRename: |
|
741 case EFsReplace: |
|
742 case EFsSetVolume: |
|
743 case EFsSetDriveName: |
|
744 { |
|
745 if(!aNotificationInfo.Source().FullName().Length()) |
|
746 { |
|
747 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Source Name not set"),KErrArgument)); |
|
748 return KErrArgument; |
|
749 } |
|
750 if(!aNotificationInfo.NewName().FullName().Length()) |
|
751 { |
|
752 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - New Name not set"),KErrArgument)); |
|
753 return KErrArgument; |
|
754 } |
|
755 if(*aNotificationInfo.Data() != -1) |
|
756 { |
|
757 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Data set in err"),KErrArgument)); |
|
758 return KErrArgument; |
|
759 } |
|
760 break; |
|
761 } |
|
762 case EFsMkDir: |
|
763 case EFsFileCreate: |
|
764 case EFsFileReplace: |
|
765 case EFsDelete: |
|
766 case EFsRmDir: |
|
767 { |
|
768 if(!aNotificationInfo.Source().FullName().Length()) |
|
769 { |
|
770 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Source Name not set"),KErrArgument)); |
|
771 return KErrArgument; |
|
772 } |
|
773 if(aNotificationInfo.NewName().FullName().Length()) |
|
774 { |
|
775 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - New Name set in err"),KErrArgument)); |
|
776 return KErrArgument; |
|
777 } |
|
778 if(*aNotificationInfo.Data() != -1) |
|
779 { |
|
780 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Data set in err"),KErrArgument)); |
|
781 return KErrArgument; |
|
782 } |
|
783 break; |
|
784 } |
|
785 case EFsFileSetAtt: |
|
786 case EFsFileSet: |
|
787 case EFsSetEntry: |
|
788 { |
|
789 if(!aNotificationInfo.Source().FullName().Length()) |
|
790 { |
|
791 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Source Name not set"),KErrArgument)); |
|
792 return KErrArgument; |
|
793 } |
|
794 if(*aNotificationInfo.Data() == -1) |
|
795 { |
|
796 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Attributes not set"),KErrArgument)); |
|
797 return KErrArgument; |
|
798 } |
|
799 if(aNotificationInfo.NewName().FullName().Length()) |
|
800 { |
|
801 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - New Name set in err"),KErrArgument)); |
|
802 return KErrArgument; |
|
803 } |
|
804 break; |
|
805 } |
|
806 case EFsDismountFileSystem: |
|
807 case EFsMountFileSystem: |
|
808 case EFsFormatNext: |
|
809 case EFsRawDiskWrite: |
|
810 case EFsMountFileSystemScan: |
|
811 { |
|
812 if(aNotificationInfo.NewName().FullName().Length()) |
|
813 { |
|
814 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - New Name set in err"),KErrArgument)); |
|
815 return KErrArgument; |
|
816 } |
|
817 if(aNotificationInfo.Source().FullName().Length()) |
|
818 { |
|
819 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Source Name set in err"),KErrArgument)); |
|
820 return KErrArgument; |
|
821 } |
|
822 if(*aNotificationInfo.Data() != -1) |
|
823 { |
|
824 __ASSERT_DEBUG(false,User::Panic(_L("::ValidateNotification - Data set in err"),KErrArgument)); |
|
825 return KErrArgument; |
|
826 } |
|
827 break; |
|
828 } |
|
829 default: |
|
830 { |
|
831 break; |
|
832 } |
|
833 } |
|
834 return KErrNone; |
|
835 } |
|
836 |
|
837 TUint CFsNotificationInfo::NotifyType(TInt aFunction) |
|
838 // |
|
839 // Convert aFunction that caused the notification to a |
|
840 // value corresponding to the correct TNotifyType enum |
|
841 // |
|
842 { |
|
843 switch (aFunction) |
|
844 { |
|
845 case EFsFileCreate: |
|
846 case EFsFileReplace: |
|
847 case EFsDelete: |
|
848 case EFsReplace: |
|
849 case EFsFileRename: |
|
850 return(ENotifyFile|ENotifyEntry); |
|
851 case EFsMkDir: |
|
852 case EFsRmDir: |
|
853 return(ENotifyDir|ENotifyEntry); |
|
854 case EFsRename: |
|
855 return(ENotifyDir|ENotifyFile|ENotifyEntry); |
|
856 case EFsSetVolume: |
|
857 return(ENotifyDisk|ENotifyEntry); |
|
858 case EFsFileSet: |
|
859 case EFsFileSetAtt: |
|
860 case EFsFileSetModified: |
|
861 case EFsFileSetSize: |
|
862 case EFsSetEntry: |
|
863 return(ENotifyAttributes); |
|
864 case EFsFileWrite: |
|
865 case EFsFileWriteDirty: |
|
866 return(ENotifyWrite); |
|
867 case EFsRawDiskWrite: |
|
868 case EFsLockDrive: |
|
869 case EFsUnlockDrive: |
|
870 return(ENotifyDisk); |
|
871 case EFsFileTemp: |
|
872 case EFsSetDriveName: |
|
873 return(ENotifyAll); |
|
874 default: |
|
875 return(0); |
|
876 } |
|
877 } |
26 |
878 |
27 void CNotifyInfo::Initialise(TInfoType aType,TRequestStatus* aStatus,const RMessagePtr2& aMessage,CSessionFs* aSession) |
879 void CNotifyInfo::Initialise(TInfoType aType,TRequestStatus* aStatus,const RMessagePtr2& aMessage,CSessionFs* aSession) |
28 // |
880 // |
29 // |
881 // |
30 // |
882 // |