Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
HardwareDrivers/mbed/LocalFileSystem.h@4:a19825caaf41, 2014-02-01 (annotated)
- Committer:
- wyunreal
- Date:
- Sat Feb 01 17:29:15 2014 +0000
- Revision:
- 4:a19825caaf41
- Parent:
- mbed/LocalFileSystem.h@3:5dc0023e6284
creating the application model
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wyunreal | 3:5dc0023e6284 | 1 | /* mbed Microcontroller Library - LocalFileSystem |
| wyunreal | 3:5dc0023e6284 | 2 | * Copyright (c) 2008-2009 ARM Limited. All rights reserved. |
| wyunreal | 3:5dc0023e6284 | 3 | * sford |
| wyunreal | 3:5dc0023e6284 | 4 | */ |
| wyunreal | 3:5dc0023e6284 | 5 | |
| wyunreal | 3:5dc0023e6284 | 6 | #ifndef MBED_LOCALFILESYSTEM_H |
| wyunreal | 3:5dc0023e6284 | 7 | #define MBED_LOCALFILESYSTEM_H |
| wyunreal | 3:5dc0023e6284 | 8 | |
| wyunreal | 3:5dc0023e6284 | 9 | #include "FileSystemLike.h" |
| wyunreal | 3:5dc0023e6284 | 10 | |
| wyunreal | 3:5dc0023e6284 | 11 | namespace mbed { |
| wyunreal | 3:5dc0023e6284 | 12 | |
| wyunreal | 3:5dc0023e6284 | 13 | /* Class: LocalFileSystem |
| wyunreal | 3:5dc0023e6284 | 14 | * A filesystem for accessing the local mbed Microcontroller USB disk drive |
| wyunreal | 3:5dc0023e6284 | 15 | * |
| wyunreal | 3:5dc0023e6284 | 16 | * This allows programs to read and write files on the same disk drive that is used to program the |
| wyunreal | 3:5dc0023e6284 | 17 | * mbed Microcontroller. Once created, the standard C file access functions are used to open, |
| wyunreal | 3:5dc0023e6284 | 18 | * read and write files. |
| wyunreal | 3:5dc0023e6284 | 19 | * |
| wyunreal | 3:5dc0023e6284 | 20 | * Example: |
| wyunreal | 3:5dc0023e6284 | 21 | * > #include "mbed.h" |
| wyunreal | 3:5dc0023e6284 | 22 | * > |
| wyunreal | 3:5dc0023e6284 | 23 | * > LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
| wyunreal | 3:5dc0023e6284 | 24 | * > |
| wyunreal | 3:5dc0023e6284 | 25 | * > int main() { |
| wyunreal | 3:5dc0023e6284 | 26 | * > FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing |
| wyunreal | 3:5dc0023e6284 | 27 | * > fprintf(fp, "Hello World!"); |
| wyunreal | 3:5dc0023e6284 | 28 | * > fclose(fp); |
| wyunreal | 3:5dc0023e6284 | 29 | * > remove("/local/out.txt"); // Removes the file "out.txt" from the local file system |
| wyunreal | 3:5dc0023e6284 | 30 | * > |
| wyunreal | 3:5dc0023e6284 | 31 | * > DIR *d = opendir("/local"); // Opens the root directory of the local file system |
| wyunreal | 3:5dc0023e6284 | 32 | * > struct dirent *p; |
| wyunreal | 3:5dc0023e6284 | 33 | * > while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system |
| wyunreal | 3:5dc0023e6284 | 34 | * > printf("%s\n", p->d_name); // to stdout. |
| wyunreal | 3:5dc0023e6284 | 35 | * > } |
| wyunreal | 3:5dc0023e6284 | 36 | * > closedir(d); |
| wyunreal | 3:5dc0023e6284 | 37 | * > } |
| wyunreal | 3:5dc0023e6284 | 38 | * |
| wyunreal | 3:5dc0023e6284 | 39 | * Implementation Notes: |
| wyunreal | 3:5dc0023e6284 | 40 | * If the microcontroller program makes an access to the local drive, it will be marked as "removed" |
| wyunreal | 3:5dc0023e6284 | 41 | * on the Host computer. This means it is no longer accessible from the Host Computer. |
| wyunreal | 3:5dc0023e6284 | 42 | * |
| wyunreal | 3:5dc0023e6284 | 43 | * The drive will only re-appear when the microcontroller program exists. Note that if the program does |
| wyunreal | 3:5dc0023e6284 | 44 | * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again! |
| wyunreal | 3:5dc0023e6284 | 45 | */ |
| wyunreal | 3:5dc0023e6284 | 46 | class LocalFileSystem : public FileSystemLike { |
| wyunreal | 3:5dc0023e6284 | 47 | |
| wyunreal | 3:5dc0023e6284 | 48 | public: |
| wyunreal | 3:5dc0023e6284 | 49 | |
| wyunreal | 3:5dc0023e6284 | 50 | LocalFileSystem(const char* n) : FileSystemLike(n) { |
| wyunreal | 3:5dc0023e6284 | 51 | |
| wyunreal | 3:5dc0023e6284 | 52 | } |
| wyunreal | 3:5dc0023e6284 | 53 | |
| wyunreal | 3:5dc0023e6284 | 54 | virtual FileHandle *open(const char* name, int flags); |
| wyunreal | 3:5dc0023e6284 | 55 | virtual int remove(const char *filename); |
| wyunreal | 3:5dc0023e6284 | 56 | virtual DirHandle *opendir(const char *name); |
| wyunreal | 3:5dc0023e6284 | 57 | }; |
| wyunreal | 3:5dc0023e6284 | 58 | |
| wyunreal | 3:5dc0023e6284 | 59 | } // namespace mbed |
| wyunreal | 3:5dc0023e6284 | 60 | |
| wyunreal | 3:5dc0023e6284 | 61 | #endif |
