changeset 279 | 957c583b417b |
parent 254 | 1560c419b176 |
child 291 | 206a6eaaeb71 |
275:2b433474f2ba | 279:957c583b417b |
---|---|
29 #include "u32std.h" |
29 #include "u32std.h" |
30 #include <u32hal.h> |
30 #include <u32hal.h> |
31 #include <nkern/nk_trace.h> |
31 #include <nkern/nk_trace.h> |
32 #include "filesystem_fat.h" |
32 #include "filesystem_fat.h" |
33 |
33 |
34 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
35 #define RFILE RFile64 |
|
36 #else |
|
37 #define RFILE RFile |
|
38 #endif |
|
39 |
|
40 |
|
34 _LIT(KCrNl, "\r\n"); |
41 _LIT(KCrNl, "\r\n"); |
35 _LIT(KNl, "\n"); |
42 _LIT(KNl, "\n"); |
36 |
43 |
37 TPtrC ptrFormatHelp=_L("Drive:[\\] [fat12|fat16|fat32] [spc:X] [rs:Y] [ft:Z] [/Q][/S][/E][/F]\nfat12 or fat16 or fat32 specifies explicit FAT type\nspc:X specifies \"X\" sectors per cluster\nrs:Y specifies \"Y\" reserved sectors\nft:Z specifies \"Z\" FAT tables (1 or 2)\n\n/q - QuickFormat, /s - SpecialFormat, /e - ForcedErase\n/f - force formatting (ignore volume being in use)"); |
44 TPtrC ptrFormatHelp=_L("Drive:[\\] [fat12|fat16|fat32] [spc:X] [rs:Y] [ft:Z] [/Q][/S][/E][/F]\nfat12 or fat16 or fat32 specifies explicit FAT type\nspc:X specifies \"X\" sectors per cluster\nrs:Y specifies \"Y\" reserved sectors\nft:Z specifies \"Z\" FAT tables (1 or 2)\n\n/q - QuickFormat, /s - SpecialFormat, /e - ForcedErase\n/f - force formatting (ignore volume being in use)"); |
38 TPtrC ptrMountHelp=_L("Drive:[\\] <fsy:X> <fs:Y> [pext:Z] [/S][/U][/F][/R]\n'X' *.fsy module name, like elocal.fsy\n'Y' file system name, like 'FAT'\n'Z' optional primary extension module name\n/U - dismount FS from the drive e.g 'mount d: /u' \n/U /F force dismounting the FS even if there are opened files on it \n/F - force mounting with dismounting existing FS \n/S - mount drive as synchronous\n/R - remount the file system "); |
45 TPtrC ptrMountHelp=_L("Drive:[\\] <fsy:X> <fs:Y> [pext:Z] [/S][/U][/F][/R]\n'X' *.fsy module name, like elocal.fsy\n'Y' file system name, like 'FAT'\n'Z' optional primary extension module name\n/U - dismount FS from the drive e.g 'mount d: /u' \n/U /F force dismounting the FS even if there are opened files on it \n/F - force mounting with dismounting existing FS \n/S - mount drive as synchronous\n/R - remount the file system "); |
40 TBool CShell::iDbgPrint = EFalse; |
47 TBool CShell::iDbgPrint = EFalse; |
41 |
48 |
42 // lint -e40,e30 |
49 // lint -e40,e30 |
43 const TShellCommand CShell::iCommand[ENoShellCommands]= |
50 const TShellCommand CShell::iCommand[ENoShellCommands]= |
44 { |
51 { |
52 // TShellCommand(_L("BLANK"),_L("Help"),_L("-?"),TShellCommand::EDSwitch,ShellFunction::BLANK), |
|
45 TShellCommand(_L("ATTRIB"),_L("Displays or changes file attributes"),_L("[drive:][path][filename] [+R | -R] [+H |-H] [+S | -S] [+A | -A] [/p]\n\n /p - Pause after each screen of information"), TShellCommand::EPSwitch, ShellFunction::Attrib), |
53 TShellCommand(_L("ATTRIB"),_L("Displays or changes file attributes"),_L("[drive:][path][filename] [+R | -R] [+H |-H] [+S | -S] [+A | -A] [/p]\n\n /p - Pause after each screen of information"), TShellCommand::EPSwitch, ShellFunction::Attrib), |
46 TShellCommand(_L("CD"),_L("Change the current directory for a drive"),_L("[path] [/d]\n\n /d - Change drive"),TShellCommand::EDSwitch,ShellFunction::Cd), |
54 TShellCommand(_L("CD"),_L("Change the current directory for a drive"),_L("[path] [/d]\n\n /d - Change drive"),TShellCommand::EDSwitch,ShellFunction::Cd), |
47 TShellCommand(_L("CHKDEPS"),_L("Check the dependencies of an executable or a Dll (ARM only)"),_L("[Filename.EXE] or [Filename.DLL]"),0,ShellFunction::ChkDeps), |
55 TShellCommand(_L("CHKDEPS"),_L("Check the dependencies of an executable or a Dll (ARM only)"),_L("[Filename.EXE] or [Filename.DLL]"),0,ShellFunction::ChkDeps), |
48 TShellCommand(_L("CHKDSK"),_L("Check disk for corruption"),_L("[drive:] [/s][/f|/u]\n\n/s - start ScanDrive instead of CheckDisk\n/f - finalise drive\n/u - unfinalise drive"),TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::EUSwitch,ShellFunction::ChkDsk), |
56 TShellCommand(_L("CHKDSK"),_L("Check disk for corruption"),_L("[drive:] [/s][/f|/u]\n\n/s - start ScanDrive instead of CheckDisk\n/f - finalise drive\n/u - unfinalise drive"),TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::EUSwitch,ShellFunction::ChkDsk), |
49 TShellCommand(_L("COPY"),_L("Copy one (or more) file(s), overwriting existing one(s)"),_L("source [destination]"),TShellCommand::ESSwitch,ShellFunction::Copy), |
57 TShellCommand(_L("COPY"),_L("Copy one (or more) file(s), overwriting existing one(s)"),_L("source [destination]"),TShellCommand::ESSwitch,ShellFunction::Copy), |
50 TShellCommand(_L("DEL"),_L("Delete one file"),_L("[drive:][path][filename]"),TShellCommand::ESSwitch,ShellFunction::Del), |
58 TShellCommand(_L("DEL"),_L("Delete one file"),_L("[drive:][path][filename]"),TShellCommand::ESSwitch,ShellFunction::Del), |
51 TShellCommand(_L("DIR"),_L("Show directory contents"),_L("[drive:][path][filename] [/p][/w]\n\n /p - Pause after each screen of information\n /w - Wide format"),TShellCommand::EPSwitch|TShellCommand::EWSwitch|TShellCommand::EASwitch,ShellFunction::Dir), |
59 TShellCommand(_L("DIR"),_L("Show directory contents"),_L("[drive:][path][filename] [/p][/w]\n\n /p - Pause after each screen of information\n /w - Wide format"),TShellCommand::EPSwitch|TShellCommand::EWSwitch|TShellCommand::EASwitch,ShellFunction::Dir), |
60 // TShellCommand(_L("EDLIN"),_L("Edit a text file"),_L("[drive:][path][filename] [/p]\n\n /p - Pause after each screen of information"),TShellCommand::EPSwitch,ShellFunction::Edit), |
|
52 TShellCommand(_L("FORMAT"),_L("Format a disk"),ptrFormatHelp,TShellCommand::EQSwitch|TShellCommand::ESSwitch|TShellCommand::EESwitch|TShellCommand::EFSwitch,ShellFunction::Format), |
61 TShellCommand(_L("FORMAT"),_L("Format a disk"),ptrFormatHelp,TShellCommand::EQSwitch|TShellCommand::ESSwitch|TShellCommand::EESwitch|TShellCommand::EFSwitch,ShellFunction::Format), |
53 TShellCommand(_L("GOBBLE"),_L("Create a file"),_L("[filename] size [/e]\n\n /e - create an empty file, without writing any data"),TShellCommand::EESwitch,ShellFunction::Gobble), |
62 TShellCommand(_L("GOBBLE"),_L("Create a file"),_L("[filename] size [/e]\n\n /e - create an empty file, without writing any data"),TShellCommand::EESwitch,ShellFunction::Gobble), |
54 TShellCommand(_L("HEXDUMP"),_L("Display the contents of a file in hexadecimal"),_L("[drive:][path][filename] [/p]\n\n /p - Pause after each screen of information\n\n Hit escape to exit from hexdump "),TShellCommand::EPSwitch,ShellFunction::Hexdump), |
63 TShellCommand(_L("HEXDUMP"),_L("Display the contents of a file in hexadecimal"),_L("[drive:][path][filename] [/p]\n\n /p - Pause after each screen of information\n\n Hit escape to exit from hexdump "),TShellCommand::EPSwitch,ShellFunction::Hexdump), |
55 TShellCommand(_L("LABEL"),_L("Set or return the volume label"),_L("[newlabel]"),0,ShellFunction::VolumeLabel), |
64 TShellCommand(_L("LABEL"),_L("Set or return the volume label"),_L("[newlabel]"),0,ShellFunction::VolumeLabel), |
56 TShellCommand(_L("MD"),_L("Make a new directory"),_L("name"),0,ShellFunction::Md), |
65 TShellCommand(_L("MD"),_L("Make a new directory"),_L("name"),0,ShellFunction::Md), |
255 aPath.Insert(0,TheShell->currentPath); |
264 aPath.Insert(0,TheShell->currentPath); |
256 else |
265 else |
257 aPath.Insert(0,TheShell->currentPath.Left(2)); |
266 aPath.Insert(0,TheShell->currentPath.Left(2)); |
258 } |
267 } |
259 |
268 |
260 RFile64 file; |
269 RFILE file; |
261 r=file.Open(CShell::TheFs,aPath,EFileStream); |
270 r=file.Open(CShell::TheFs,aPath,EFileStream); |
262 if (r!=KErrNone) // File could not be opened |
271 if (r!=KErrNone) // File could not be opened |
263 { |
272 { |
264 if (appendedExe) // If .EXE was appended earlier |
273 if (appendedExe) // If .EXE was appended earlier |
265 { |
274 { |
747 // |
756 // |
748 { |
757 { |
749 ShellFunction::StripQuotes(aPath); |
758 ShellFunction::StripQuotes(aPath); |
750 |
759 |
751 RDir dir; |
760 RDir dir; |
752 RFile64 file; |
761 RFILE file; |
753 TParse dirParse; |
762 TParse dirParse; |
754 // Parses the given path to give a full path |
763 // Parses the given path to give a full path |
755 GetFullPath(aPath,dirParse); |
764 GetFullPath(aPath,dirParse); |
756 // Sets aPath to a full path name |
765 // Sets aPath to a full path name |
757 aPath=dirParse.FullName(); |
766 aPath=dirParse.FullName(); |
855 |
864 |
856 TParse dirParse; |
865 TParse dirParse; |
857 GetFullPath(aPath,dirParse); |
866 GetFullPath(aPath,dirParse); |
858 aPath=dirParse.FullName(); |
867 aPath=dirParse.FullName(); |
859 |
868 |
860 RFile64 file; |
869 RFILE file; |
861 if (aPath[aPath.Length()-1]==KPathDelimiter) |
870 if (aPath[aPath.Length()-1]==KPathDelimiter) |
862 aPath.Append('*'); |
871 aPath.Append('*'); |
863 else if( (aPath.Locate(KMatchAny)==KErrNotFound) && (aPath.Locate(KMatchOne)==KErrNotFound) ) |
872 else if( (aPath.Locate(KMatchAny)==KErrNotFound) && (aPath.Locate(KMatchOne)==KErrNotFound) ) |
864 { |
873 { |
865 TInt error=file.Open(TheShell->TheFs,aPath,KEntryAttMatchExclude|KEntryAttDir); |
874 TInt error=file.Open(TheShell->TheFs,aPath,KEntryAttMatchExclude|KEntryAttDir); |
2061 { |
2070 { |
2062 ShellFunction::StripQuotes(aPath); |
2071 ShellFunction::StripQuotes(aPath); |
2063 |
2072 |
2064 ParsePath(aPath); |
2073 ParsePath(aPath); |
2065 |
2074 |
2066 RFile64 file; |
2075 RFILE file; |
2067 TInt r=file.Open(TheShell->TheFs,aPath,EFileStream); |
2076 TInt r=file.Open(TheShell->TheFs,aPath,EFileStream); |
2068 if (r!=KErrNone) |
2077 if (r!=KErrNone) |
2069 return(r); |
2078 return(r); |
2070 |
2079 |
2071 const TInt KLineLength = 16; |
2080 const TInt KLineLength = 16; |
2072 TBuf<0x100> buf; |
2081 TBuf<0x100> buf; |
2073 TBuf<KLineLength> asciiBuf; |
2082 TBuf<KLineLength> asciiBuf; |
2074 TBuf8<KLineLength> line; |
2083 TBuf8<KLineLength> line; |
2075 |
2084 |
2076 for (;;) |
2085 for (;;) |
2077 { |
2086 { |
2078 r=file.Read(line); |
2087 r=file.Read(line); |
2079 if (r != KErrNone || line.Length() == 0) |
2088 if (r != KErrNone || line.Length() == 0) |
2162 if (aPath.Length()==0) |
2171 if (aPath.Length()==0) |
2163 aPath=_L("GOBBLE.DAT"); |
2172 aPath=_L("GOBBLE.DAT"); |
2164 |
2173 |
2165 TParse fileName; |
2174 TParse fileName; |
2166 GetFullPath(aPath,fileName); |
2175 GetFullPath(aPath,fileName); |
2167 RFile64 file; |
2176 RFILE file; |
2168 |
2177 |
2169 const TInt KBufSize=65536; //-- buffer size for writing data |
2178 const TInt KBufSize=65536; //-- buffer size for writing data |
2170 const TUint32 K1Megabyte = 1<<20; //-- 1M, 1048576 |
2179 const TUint32 K1Megabyte = 1<<20; //-- 1M, 1048576 |
2171 TInt64 cntBytes = 0; |
2180 TInt64 cntBytes = 0; |
2172 TUint32 cntMegaBytes =0; |
2181 TUint32 cntMegaBytes =0; |
2209 if(r != KErrNone) |
2218 if(r != KErrNone) |
2210 goto fail; |
2219 goto fail; |
2211 |
2220 |
2212 |
2221 |
2213 if(!(aSwitches&TShellCommand::EESwitch)) |
2222 if(!(aSwitches&TShellCommand::EESwitch)) |
2214 {//-- fill created file with random data |
2223 {//-- fill created file with randomn data |
2215 |
2224 |
2216 while(rem) |
2225 while(rem) |
2217 { |
2226 { |
2218 const TInt s=(TInt)Min((TInt64)KBufSize, rem); |
2227 const TInt s=(TInt)Min((TInt64)KBufSize, rem); |
2219 |
2228 |
2282 // Modified to add more helpful error messages and allow spaced filenames |
2291 // Modified to add more helpful error messages and allow spaced filenames |
2283 ShellFunction::StripQuotes(aPath); |
2292 ShellFunction::StripQuotes(aPath); |
2284 |
2293 |
2285 TBuf<KShellMaxCommandLine> newName; |
2294 TBuf<KShellMaxCommandLine> newName; |
2286 TBuf<KShellMaxCommandLine> tempPath=aPath; |
2295 TBuf<KShellMaxCommandLine> tempPath=aPath; |
2287 RFile64 file; |
2296 RFILE file; |
2288 TWord word(aPath); |
2297 TWord word(aPath); |
2289 |
2298 |
2290 TInt r=word.FindNextWord(aPath); |
2299 TInt r=word.FindNextWord(aPath); |
2291 // Check if the word returned is a valid filename. If not, scan the next |
2300 // Check if the word returned is a valid filename. If not, scan the next |
2292 // word too in case the filename contains spaces. If, at the end of the |
2301 // word too in case the filename contains spaces. If, at the end of the |
2948 { |
2957 { |
2949 // Modified December 1997 to allow for filenames containing spaces |
2958 // Modified December 1997 to allow for filenames containing spaces |
2950 |
2959 |
2951 TBuf<KShellMaxCommandLine> newName; |
2960 TBuf<KShellMaxCommandLine> newName; |
2952 TBuf<KShellMaxCommandLine> tempPath=aPath; |
2961 TBuf<KShellMaxCommandLine> tempPath=aPath; |
2953 RFile64 file; |
2962 RFILE file; |
2954 TWord word(aPath); |
2963 TWord word(aPath); |
2955 |
2964 |
2956 TInt r=word.FindNextWord(aPath); |
2965 TInt r=word.FindNextWord(aPath); |
2957 // Check if the word returned is a valid filename. If not, scan the next |
2966 // Check if the word returned is a valid filename. If not, scan the next |
2958 // word too in case the filename contains spaces. If, at the end of the |
2967 // word too in case the filename contains spaces. If, at the end of the |
3235 } |
3244 } |
3236 |
3245 |
3237 TInt ShellFunction::Type(TDes& aPath,TUint aSwitches) |
3246 TInt ShellFunction::Type(TDes& aPath,TUint aSwitches) |
3238 { |
3247 { |
3239 ParsePath(aPath); |
3248 ParsePath(aPath); |
3240 RFile64 file; |
3249 RFILE file; |
3241 TInt r=file.Open(TheShell->TheFs,aPath,EFileStreamText|EFileShareReadersOnly); |
3250 TInt r=file.Open(TheShell->TheFs,aPath,EFileStreamText|EFileShareReadersOnly); |
3242 if (r!=KErrNone) |
3251 if (r!=KErrNone) |
3243 return r; |
3252 return r; |
3244 TBuf8<0x200> tmpbuf; |
3253 TBuf8<0x200> tmpbuf; |
3245 TBuf<0x200> ubuf; |
3254 TBuf<0x200> ubuf; |
3610 return KErrNone; |
3619 return KErrNone; |
3611 } |
3620 } |
3612 |
3621 |
3613 TParse fileName; |
3622 TParse fileName; |
3614 GetFullPath(aPath,fileName); |
3623 GetFullPath(aPath,fileName); |
3615 RFile64 file; |
3624 RFILE file; |
3616 r=file.Open(CShell::TheFs,fileName.FullName(),EFileRead|EFileWrite); |
3625 r=file.Open(CShell::TheFs,fileName.FullName(),EFileRead|EFileWrite); |
3617 if(r==KErrNotFound) |
3626 if(r==KErrNotFound) |
3618 r=file.Create(CShell::TheFs,fileName.FullName(),EFileRead|EFileWrite); |
3627 r=file.Create(CShell::TheFs,fileName.FullName(),EFileRead|EFileWrite); |
3619 if (r==KErrNone) |
3628 if (r==KErrNone) |
3620 { |
3629 { |