├── .gitignore ├── Doxyfile ├── Makefile ├── README ├── doc └── mainpage.c ├── include ├── openfat.h └── openfat │ ├── blockdev.h │ ├── leaccess.h │ ├── mbr.h │ └── unixlike.h ├── src ├── Makefile ├── bpb.h ├── direntry.c ├── direntry.h ├── fat_core.c ├── fat_core.h ├── mbr.c ├── unixlike.c └── write.c ├── stm32 ├── Makefile ├── example.c ├── mmc.c ├── mmc.h └── stm32.ld └── unix ├── Makefile ├── autopsy.c ├── blockdev_file.c └── fattest.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.d 3 | *.a 4 | *.img 5 | .*.swp 6 | tags 7 | 8 | -------------------------------------------------------------------------------- /Doxyfile: -------------------------------------------------------------------------------- 1 | # Doxyfile 1.7.1 2 | 3 | # This file describes the settings to be used by the documentation system 4 | # doxygen (www.doxygen.org) for a project 5 | # 6 | # All text after a hash (#) is considered a comment and will be ignored 7 | # The format is: 8 | # TAG = value [value, ...] 9 | # For lists items can also be appended using: 10 | # TAG += value [value, ...] 11 | # Values that contain spaces should be placed between quotes (" ") 12 | 13 | #--------------------------------------------------------------------------- 14 | # Project related configuration options 15 | #--------------------------------------------------------------------------- 16 | 17 | # This tag specifies the encoding used for all characters in the config file 18 | # that follow. The default is UTF-8 which is also the encoding used for all 19 | # text before the first occurrence of this tag. Doxygen uses libiconv (or the 20 | # iconv built into libc) for the transcoding. See 21 | # http://www.gnu.org/software/libiconv for the list of possible encodings. 22 | 23 | DOXYFILE_ENCODING = UTF-8 24 | 25 | # The PROJECT_NAME tag is a single word (or a sequence of words surrounded 26 | # by quotes) that should identify the project. 27 | 28 | PROJECT_NAME = OpenFAT 29 | 30 | # The PROJECT_NUMBER tag can be used to enter a project or revision number. 31 | # This could be handy for archiving the generated documentation or 32 | # if some version control system is used. 33 | 34 | PROJECT_NUMBER = 35 | 36 | # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 37 | # base path where the generated documentation will be put. 38 | # If a relative path is entered, it will be relative to the location 39 | # where doxygen was started. If left blank the current directory will be used. 40 | 41 | OUTPUT_DIRECTORY = doc 42 | 43 | # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 44 | # 4096 sub-directories (in 2 levels) under the output directory of each output 45 | # format and will distribute the generated files over these directories. 46 | # Enabling this option can be useful when feeding doxygen a huge amount of 47 | # source files, where putting all generated files in the same directory would 48 | # otherwise cause performance problems for the file system. 49 | 50 | CREATE_SUBDIRS = NO 51 | 52 | # The OUTPUT_LANGUAGE tag is used to specify the language in which all 53 | # documentation generated by doxygen is written. Doxygen will use this 54 | # information to generate all constant output in the proper language. 55 | # The default language is English, other supported languages are: 56 | # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, 57 | # Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, 58 | # Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English 59 | # messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, 60 | # Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, 61 | # Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. 62 | 63 | OUTPUT_LANGUAGE = English 64 | 65 | # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will 66 | # include brief member descriptions after the members that are listed in 67 | # the file and class documentation (similar to JavaDoc). 68 | # Set to NO to disable this. 69 | 70 | BRIEF_MEMBER_DESC = YES 71 | 72 | # If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend 73 | # the brief description of a member or function before the detailed description. 74 | # Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the 75 | # brief descriptions will be completely suppressed. 76 | 77 | REPEAT_BRIEF = YES 78 | 79 | # This tag implements a quasi-intelligent brief description abbreviator 80 | # that is used to form the text in various listings. Each string 81 | # in this list, if found as the leading text of the brief description, will be 82 | # stripped from the text and the result after processing the whole list, is 83 | # used as the annotated text. Otherwise, the brief description is used as-is. 84 | # If left blank, the following values are used ("$name" is automatically 85 | # replaced with the name of the entity): "The $name class" "The $name widget" 86 | # "The $name file" "is" "provides" "specifies" "contains" 87 | # "represents" "a" "an" "the" 88 | 89 | ABBREVIATE_BRIEF = 90 | 91 | # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then 92 | # Doxygen will generate a detailed section even if there is only a brief 93 | # description. 94 | 95 | ALWAYS_DETAILED_SEC = NO 96 | 97 | # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all 98 | # inherited members of a class in the documentation of that class as if those 99 | # members were ordinary class members. Constructors, destructors and assignment 100 | # operators of the base classes will not be shown. 101 | 102 | INLINE_INHERITED_MEMB = NO 103 | 104 | # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full 105 | # path before files name in the file list and in the header files. If set 106 | # to NO the shortest path that makes the file name unique will be used. 107 | 108 | FULL_PATH_NAMES = YES 109 | 110 | # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag 111 | # can be used to strip a user-defined part of the path. Stripping is 112 | # only done if one of the specified strings matches the left-hand part of 113 | # the path. The tag can be used to show relative paths in the file list. 114 | # If left blank the directory from which doxygen is run is used as the 115 | # path to strip. 116 | 117 | STRIP_FROM_PATH = 118 | 119 | # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of 120 | # the path mentioned in the documentation of a class, which tells 121 | # the reader which header file to include in order to use a class. 122 | # If left blank only the name of the header file containing the class 123 | # definition is used. Otherwise one should specify the include paths that 124 | # are normally passed to the compiler using the -I flag. 125 | 126 | STRIP_FROM_INC_PATH = 127 | 128 | # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter 129 | # (but less readable) file names. This can be useful is your file systems 130 | # doesn't support long names like on DOS, Mac, or CD-ROM. 131 | 132 | SHORT_NAMES = NO 133 | 134 | # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen 135 | # will interpret the first line (until the first dot) of a JavaDoc-style 136 | # comment as the brief description. If set to NO, the JavaDoc 137 | # comments will behave just like regular Qt-style comments 138 | # (thus requiring an explicit @brief command for a brief description.) 139 | 140 | JAVADOC_AUTOBRIEF = YES 141 | 142 | # If the QT_AUTOBRIEF tag is set to YES then Doxygen will 143 | # interpret the first line (until the first dot) of a Qt-style 144 | # comment as the brief description. If set to NO, the comments 145 | # will behave just like regular Qt-style comments (thus requiring 146 | # an explicit \brief command for a brief description.) 147 | 148 | QT_AUTOBRIEF = NO 149 | 150 | # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen 151 | # treat a multi-line C++ special comment block (i.e. a block of //! or /// 152 | # comments) as a brief description. This used to be the default behaviour. 153 | # The new default is to treat a multi-line C++ comment block as a detailed 154 | # description. Set this tag to YES if you prefer the old behaviour instead. 155 | 156 | MULTILINE_CPP_IS_BRIEF = NO 157 | 158 | # If the INHERIT_DOCS tag is set to YES (the default) then an undocumented 159 | # member inherits the documentation from any documented member that it 160 | # re-implements. 161 | 162 | INHERIT_DOCS = YES 163 | 164 | # If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce 165 | # a new page for each member. If set to NO, the documentation of a member will 166 | # be part of the file/class/namespace that contains it. 167 | 168 | SEPARATE_MEMBER_PAGES = NO 169 | 170 | # The TAB_SIZE tag can be used to set the number of spaces in a tab. 171 | # Doxygen uses this value to replace tabs by spaces in code fragments. 172 | 173 | TAB_SIZE = 8 174 | 175 | # This tag can be used to specify a number of aliases that acts 176 | # as commands in the documentation. An alias has the form "name=value". 177 | # For example adding "sideeffect=\par Side Effects:\n" will allow you to 178 | # put the command \sideeffect (or @sideeffect) in the documentation, which 179 | # will result in a user-defined paragraph with heading "Side Effects:". 180 | # You can put \n's in the value part of an alias to insert newlines. 181 | 182 | ALIASES = 183 | 184 | # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C 185 | # sources only. Doxygen will then generate output that is more tailored for C. 186 | # For instance, some of the names that are used will be different. The list 187 | # of all members will be omitted, etc. 188 | 189 | OPTIMIZE_OUTPUT_FOR_C = YES 190 | 191 | # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java 192 | # sources only. Doxygen will then generate output that is more tailored for 193 | # Java. For instance, namespaces will be presented as packages, qualified 194 | # scopes will look different, etc. 195 | 196 | OPTIMIZE_OUTPUT_JAVA = NO 197 | 198 | # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran 199 | # sources only. Doxygen will then generate output that is more tailored for 200 | # Fortran. 201 | 202 | OPTIMIZE_FOR_FORTRAN = NO 203 | 204 | # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL 205 | # sources. Doxygen will then generate output that is tailored for 206 | # VHDL. 207 | 208 | OPTIMIZE_OUTPUT_VHDL = NO 209 | 210 | # Doxygen selects the parser to use depending on the extension of the files it 211 | # parses. With this tag you can assign which parser to use for a given extension. 212 | # Doxygen has a built-in mapping, but you can override or extend it using this 213 | # tag. The format is ext=language, where ext is a file extension, and language 214 | # is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, 215 | # C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make 216 | # doxygen treat .inc files as Fortran files (default is PHP), and .f files as C 217 | # (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions 218 | # you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. 219 | 220 | EXTENSION_MAPPING = 221 | 222 | # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want 223 | # to include (a tag file for) the STL sources as input, then you should 224 | # set this tag to YES in order to let doxygen match functions declarations and 225 | # definitions whose arguments contain STL classes (e.g. func(std::string); v.s. 226 | # func(std::string) {}). This also make the inheritance and collaboration 227 | # diagrams that involve STL classes more complete and accurate. 228 | 229 | BUILTIN_STL_SUPPORT = NO 230 | 231 | # If you use Microsoft's C++/CLI language, you should set this option to YES to 232 | # enable parsing support. 233 | 234 | CPP_CLI_SUPPORT = NO 235 | 236 | # Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. 237 | # Doxygen will parse them like normal C++ but will assume all classes use public 238 | # instead of private inheritance when no explicit protection keyword is present. 239 | 240 | SIP_SUPPORT = NO 241 | 242 | # For Microsoft's IDL there are propget and propput attributes to indicate getter 243 | # and setter methods for a property. Setting this option to YES (the default) 244 | # will make doxygen to replace the get and set methods by a property in the 245 | # documentation. This will only work if the methods are indeed getting or 246 | # setting a simple type. If this is not the case, or you want to show the 247 | # methods anyway, you should set this option to NO. 248 | 249 | IDL_PROPERTY_SUPPORT = YES 250 | 251 | # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC 252 | # tag is set to YES, then doxygen will reuse the documentation of the first 253 | # member in the group (if any) for the other members of the group. By default 254 | # all members of a group must be documented explicitly. 255 | 256 | DISTRIBUTE_GROUP_DOC = NO 257 | 258 | # Set the SUBGROUPING tag to YES (the default) to allow class member groups of 259 | # the same type (for instance a group of public functions) to be put as a 260 | # subgroup of that type (e.g. under the Public Functions section). Set it to 261 | # NO to prevent subgrouping. Alternatively, this can be done per class using 262 | # the \nosubgrouping command. 263 | 264 | SUBGROUPING = YES 265 | 266 | # When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum 267 | # is documented as struct, union, or enum with the name of the typedef. So 268 | # typedef struct TypeS {} TypeT, will appear in the documentation as a struct 269 | # with name TypeT. When disabled the typedef will appear as a member of a file, 270 | # namespace, or class. And the struct will be named TypeS. This can typically 271 | # be useful for C code in case the coding convention dictates that all compound 272 | # types are typedef'ed and only the typedef is referenced, never the tag name. 273 | 274 | TYPEDEF_HIDES_STRUCT = NO 275 | 276 | # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to 277 | # determine which symbols to keep in memory and which to flush to disk. 278 | # When the cache is full, less often used symbols will be written to disk. 279 | # For small to medium size projects (<1000 input files) the default value is 280 | # probably good enough. For larger projects a too small cache size can cause 281 | # doxygen to be busy swapping symbols to and from disk most of the time 282 | # causing a significant performance penality. 283 | # If the system has enough physical memory increasing the cache will improve the 284 | # performance by keeping more symbols in memory. Note that the value works on 285 | # a logarithmic scale so increasing the size by one will rougly double the 286 | # memory usage. The cache size is given by this formula: 287 | # 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, 288 | # corresponding to a cache size of 2^16 = 65536 symbols 289 | 290 | SYMBOL_CACHE_SIZE = 0 291 | 292 | #--------------------------------------------------------------------------- 293 | # Build related configuration options 294 | #--------------------------------------------------------------------------- 295 | 296 | # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in 297 | # documentation are documented, even if no documentation was available. 298 | # Private class members and static file members will be hidden unless 299 | # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES 300 | 301 | EXTRACT_ALL = NO 302 | 303 | # If the EXTRACT_PRIVATE tag is set to YES all private members of a class 304 | # will be included in the documentation. 305 | 306 | EXTRACT_PRIVATE = NO 307 | 308 | # If the EXTRACT_STATIC tag is set to YES all static members of a file 309 | # will be included in the documentation. 310 | 311 | EXTRACT_STATIC = NO 312 | 313 | # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) 314 | # defined locally in source files will be included in the documentation. 315 | # If set to NO only classes defined in header files are included. 316 | 317 | EXTRACT_LOCAL_CLASSES = YES 318 | 319 | # This flag is only useful for Objective-C code. When set to YES local 320 | # methods, which are defined in the implementation section but not in 321 | # the interface are included in the documentation. 322 | # If set to NO (the default) only methods in the interface are included. 323 | 324 | EXTRACT_LOCAL_METHODS = NO 325 | 326 | # If this flag is set to YES, the members of anonymous namespaces will be 327 | # extracted and appear in the documentation as a namespace called 328 | # 'anonymous_namespace{file}', where file will be replaced with the base 329 | # name of the file that contains the anonymous namespace. By default 330 | # anonymous namespace are hidden. 331 | 332 | EXTRACT_ANON_NSPACES = NO 333 | 334 | # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all 335 | # undocumented members of documented classes, files or namespaces. 336 | # If set to NO (the default) these members will be included in the 337 | # various overviews, but no documentation section is generated. 338 | # This option has no effect if EXTRACT_ALL is enabled. 339 | 340 | HIDE_UNDOC_MEMBERS = YES 341 | 342 | # If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all 343 | # undocumented classes that are normally visible in the class hierarchy. 344 | # If set to NO (the default) these classes will be included in the various 345 | # overviews. This option has no effect if EXTRACT_ALL is enabled. 346 | 347 | HIDE_UNDOC_CLASSES = YES 348 | 349 | # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all 350 | # friend (class|struct|union) declarations. 351 | # If set to NO (the default) these declarations will be included in the 352 | # documentation. 353 | 354 | HIDE_FRIEND_COMPOUNDS = NO 355 | 356 | # If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any 357 | # documentation blocks found inside the body of a function. 358 | # If set to NO (the default) these blocks will be appended to the 359 | # function's detailed documentation block. 360 | 361 | HIDE_IN_BODY_DOCS = NO 362 | 363 | # The INTERNAL_DOCS tag determines if documentation 364 | # that is typed after a \internal command is included. If the tag is set 365 | # to NO (the default) then the documentation will be excluded. 366 | # Set it to YES to include the internal documentation. 367 | 368 | INTERNAL_DOCS = NO 369 | 370 | # If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate 371 | # file names in lower-case letters. If set to YES upper-case letters are also 372 | # allowed. This is useful if you have classes or files whose names only differ 373 | # in case and if your file system supports case sensitive file names. Windows 374 | # and Mac users are advised to set this option to NO. 375 | 376 | CASE_SENSE_NAMES = YES 377 | 378 | # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen 379 | # will show members with their full class and namespace scopes in the 380 | # documentation. If set to YES the scope will be hidden. 381 | 382 | HIDE_SCOPE_NAMES = NO 383 | 384 | # If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen 385 | # will put a list of the files that are included by a file in the documentation 386 | # of that file. 387 | 388 | SHOW_INCLUDE_FILES = NO 389 | 390 | # If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen 391 | # will list include files with double quotes in the documentation 392 | # rather than with sharp brackets. 393 | 394 | FORCE_LOCAL_INCLUDES = NO 395 | 396 | # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] 397 | # is inserted in the documentation for inline members. 398 | 399 | INLINE_INFO = YES 400 | 401 | # If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen 402 | # will sort the (detailed) documentation of file and class members 403 | # alphabetically by member name. If set to NO the members will appear in 404 | # declaration order. 405 | 406 | SORT_MEMBER_DOCS = YES 407 | 408 | # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the 409 | # brief documentation of file, namespace and class members alphabetically 410 | # by member name. If set to NO (the default) the members will appear in 411 | # declaration order. 412 | 413 | SORT_BRIEF_DOCS = NO 414 | 415 | # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen 416 | # will sort the (brief and detailed) documentation of class members so that 417 | # constructors and destructors are listed first. If set to NO (the default) 418 | # the constructors will appear in the respective orders defined by 419 | # SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. 420 | # This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO 421 | # and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. 422 | 423 | SORT_MEMBERS_CTORS_1ST = NO 424 | 425 | # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the 426 | # hierarchy of group names into alphabetical order. If set to NO (the default) 427 | # the group names will appear in their defined order. 428 | 429 | SORT_GROUP_NAMES = NO 430 | 431 | # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be 432 | # sorted by fully-qualified names, including namespaces. If set to 433 | # NO (the default), the class list will be sorted only by class name, 434 | # not including the namespace part. 435 | # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. 436 | # Note: This option applies only to the class list, not to the 437 | # alphabetical list. 438 | 439 | SORT_BY_SCOPE_NAME = NO 440 | 441 | # The GENERATE_TODOLIST tag can be used to enable (YES) or 442 | # disable (NO) the todo list. This list is created by putting \todo 443 | # commands in the documentation. 444 | 445 | GENERATE_TODOLIST = YES 446 | 447 | # The GENERATE_TESTLIST tag can be used to enable (YES) or 448 | # disable (NO) the test list. This list is created by putting \test 449 | # commands in the documentation. 450 | 451 | GENERATE_TESTLIST = YES 452 | 453 | # The GENERATE_BUGLIST tag can be used to enable (YES) or 454 | # disable (NO) the bug list. This list is created by putting \bug 455 | # commands in the documentation. 456 | 457 | GENERATE_BUGLIST = YES 458 | 459 | # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or 460 | # disable (NO) the deprecated list. This list is created by putting 461 | # \deprecated commands in the documentation. 462 | 463 | GENERATE_DEPRECATEDLIST= YES 464 | 465 | # The ENABLED_SECTIONS tag can be used to enable conditional 466 | # documentation sections, marked by \if sectionname ... \endif. 467 | 468 | ENABLED_SECTIONS = 469 | 470 | # The MAX_INITIALIZER_LINES tag determines the maximum number of lines 471 | # the initial value of a variable or define consists of for it to appear in 472 | # the documentation. If the initializer consists of more lines than specified 473 | # here it will be hidden. Use a value of 0 to hide initializers completely. 474 | # The appearance of the initializer of individual variables and defines in the 475 | # documentation can be controlled using \showinitializer or \hideinitializer 476 | # command in the documentation regardless of this setting. 477 | 478 | MAX_INITIALIZER_LINES = 30 479 | 480 | # Set the SHOW_USED_FILES tag to NO to disable the list of files generated 481 | # at the bottom of the documentation of classes and structs. If set to YES the 482 | # list will mention the files that were used to generate the documentation. 483 | 484 | SHOW_USED_FILES = YES 485 | 486 | # If the sources in your project are distributed over multiple directories 487 | # then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy 488 | # in the documentation. The default is NO. 489 | 490 | SHOW_DIRECTORIES = NO 491 | 492 | # Set the SHOW_FILES tag to NO to disable the generation of the Files page. 493 | # This will remove the Files entry from the Quick Index and from the 494 | # Folder Tree View (if specified). The default is YES. 495 | 496 | SHOW_FILES = YES 497 | 498 | # Set the SHOW_NAMESPACES tag to NO to disable the generation of the 499 | # Namespaces page. 500 | # This will remove the Namespaces entry from the Quick Index 501 | # and from the Folder Tree View (if specified). The default is YES. 502 | 503 | SHOW_NAMESPACES = YES 504 | 505 | # The FILE_VERSION_FILTER tag can be used to specify a program or script that 506 | # doxygen should invoke to get the current version for each file (typically from 507 | # the version control system). Doxygen will invoke the program by executing (via 508 | # popen()) the command , where is the value of 509 | # the FILE_VERSION_FILTER tag, and is the name of an input file 510 | # provided by doxygen. Whatever the program writes to standard output 511 | # is used as the file version. See the manual for examples. 512 | 513 | FILE_VERSION_FILTER = 514 | 515 | # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed 516 | # by doxygen. The layout file controls the global structure of the generated 517 | # output files in an output format independent way. The create the layout file 518 | # that represents doxygen's defaults, run doxygen with the -l option. 519 | # You can optionally specify a file name after the option, if omitted 520 | # DoxygenLayout.xml will be used as the name of the layout file. 521 | 522 | LAYOUT_FILE = 523 | 524 | #--------------------------------------------------------------------------- 525 | # configuration options related to warning and progress messages 526 | #--------------------------------------------------------------------------- 527 | 528 | # The QUIET tag can be used to turn on/off the messages that are generated 529 | # by doxygen. Possible values are YES and NO. If left blank NO is used. 530 | 531 | QUIET = NO 532 | 533 | # The WARNINGS tag can be used to turn on/off the warning messages that are 534 | # generated by doxygen. Possible values are YES and NO. If left blank 535 | # NO is used. 536 | 537 | WARNINGS = YES 538 | 539 | # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings 540 | # for undocumented members. If EXTRACT_ALL is set to YES then this flag will 541 | # automatically be disabled. 542 | 543 | WARN_IF_UNDOCUMENTED = YES 544 | 545 | # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for 546 | # potential errors in the documentation, such as not documenting some 547 | # parameters in a documented function, or documenting parameters that 548 | # don't exist or using markup commands wrongly. 549 | 550 | WARN_IF_DOC_ERROR = YES 551 | 552 | # This WARN_NO_PARAMDOC option can be abled to get warnings for 553 | # functions that are documented, but have no documentation for their parameters 554 | # or return value. If set to NO (the default) doxygen will only warn about 555 | # wrong or incomplete parameter documentation, but not about the absence of 556 | # documentation. 557 | 558 | WARN_NO_PARAMDOC = NO 559 | 560 | # The WARN_FORMAT tag determines the format of the warning messages that 561 | # doxygen can produce. The string should contain the $file, $line, and $text 562 | # tags, which will be replaced by the file and line number from which the 563 | # warning originated and the warning text. Optionally the format may contain 564 | # $version, which will be replaced by the version of the file (if it could 565 | # be obtained via FILE_VERSION_FILTER) 566 | 567 | WARN_FORMAT = "$file:$line: $text" 568 | 569 | # The WARN_LOGFILE tag can be used to specify a file to which warning 570 | # and error messages should be written. If left blank the output is written 571 | # to stderr. 572 | 573 | WARN_LOGFILE = 574 | 575 | #--------------------------------------------------------------------------- 576 | # configuration options related to the input files 577 | #--------------------------------------------------------------------------- 578 | 579 | # The INPUT tag can be used to specify the files and/or directories that contain 580 | # documented source files. You may enter file names like "myfile.cpp" or 581 | # directories like "/usr/src/myproject". Separate the files or directories 582 | # with spaces. 583 | 584 | INPUT = include doc/mainpage.c 585 | 586 | # This tag can be used to specify the character encoding of the source files 587 | # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is 588 | # also the default input encoding. Doxygen uses libiconv (or the iconv built 589 | # into libc) for the transcoding. See http://www.gnu.org/software/libiconv for 590 | # the list of possible encodings. 591 | 592 | INPUT_ENCODING = UTF-8 593 | 594 | # If the value of the INPUT tag contains directories, you can use the 595 | # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 596 | # and *.h) to filter out the source-files in the directories. If left 597 | # blank the following patterns are tested: 598 | # *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx 599 | # *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 600 | 601 | FILE_PATTERNS = *.c *.h 602 | 603 | # The RECURSIVE tag can be used to turn specify whether or not subdirectories 604 | # should be searched for input files as well. Possible values are YES and NO. 605 | # If left blank NO is used. 606 | 607 | RECURSIVE = YES 608 | 609 | # The EXCLUDE tag can be used to specify files and/or directories that should 610 | # excluded from the INPUT source files. This way you can easily exclude a 611 | # subdirectory from a directory tree whose root is specified with the INPUT tag. 612 | 613 | EXCLUDE = include/openfat/leaccess.h include/openfat/unixlike.h 614 | 615 | # The EXCLUDE_SYMLINKS tag can be used select whether or not files or 616 | # directories that are symbolic links (a Unix filesystem feature) are excluded 617 | # from the input. 618 | 619 | EXCLUDE_SYMLINKS = NO 620 | 621 | # If the value of the INPUT tag contains directories, you can use the 622 | # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude 623 | # certain files from those directories. Note that the wildcards are matched 624 | # against the file with absolute path, so to exclude all test directories 625 | # for example use the pattern */test/* 626 | 627 | EXCLUDE_PATTERNS = 628 | 629 | # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names 630 | # (namespaces, classes, functions, etc.) that should be excluded from the 631 | # output. The symbol name can be a fully qualified name, a word, or if the 632 | # wildcard * is used, a substring. Examples: ANamespace, AClass, 633 | # AClass::ANamespace, ANamespace::*Test 634 | 635 | EXCLUDE_SYMBOLS = 636 | 637 | # The EXAMPLE_PATH tag can be used to specify one or more files or 638 | # directories that contain example code fragments that are included (see 639 | # the \include command). 640 | 641 | EXAMPLE_PATH = 642 | 643 | # If the value of the EXAMPLE_PATH tag contains directories, you can use the 644 | # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 645 | # and *.h) to filter out the source-files in the directories. If left 646 | # blank all files are included. 647 | 648 | EXAMPLE_PATTERNS = 649 | 650 | # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be 651 | # searched for input files to be used with the \include or \dontinclude 652 | # commands irrespective of the value of the RECURSIVE tag. 653 | # Possible values are YES and NO. If left blank NO is used. 654 | 655 | EXAMPLE_RECURSIVE = NO 656 | 657 | # The IMAGE_PATH tag can be used to specify one or more files or 658 | # directories that contain image that are included in the documentation (see 659 | # the \image command). 660 | 661 | IMAGE_PATH = 662 | 663 | # The INPUT_FILTER tag can be used to specify a program that doxygen should 664 | # invoke to filter for each input file. Doxygen will invoke the filter program 665 | # by executing (via popen()) the command , where 666 | # is the value of the INPUT_FILTER tag, and is the name of an 667 | # input file. Doxygen will then use the output that the filter program writes 668 | # to standard output. 669 | # If FILTER_PATTERNS is specified, this tag will be 670 | # ignored. 671 | 672 | INPUT_FILTER = 673 | 674 | # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern 675 | # basis. 676 | # Doxygen will compare the file name with each pattern and apply the 677 | # filter if there is a match. 678 | # The filters are a list of the form: 679 | # pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further 680 | # info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER 681 | # is applied to all files. 682 | 683 | FILTER_PATTERNS = 684 | 685 | # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using 686 | # INPUT_FILTER) will be used to filter the input files when producing source 687 | # files to browse (i.e. when SOURCE_BROWSER is set to YES). 688 | 689 | FILTER_SOURCE_FILES = NO 690 | 691 | #--------------------------------------------------------------------------- 692 | # configuration options related to source browsing 693 | #--------------------------------------------------------------------------- 694 | 695 | # If the SOURCE_BROWSER tag is set to YES then a list of source files will 696 | # be generated. Documented entities will be cross-referenced with these sources. 697 | # Note: To get rid of all source code in the generated output, make sure also 698 | # VERBATIM_HEADERS is set to NO. 699 | 700 | SOURCE_BROWSER = NO 701 | 702 | # Setting the INLINE_SOURCES tag to YES will include the body 703 | # of functions and classes directly in the documentation. 704 | 705 | INLINE_SOURCES = NO 706 | 707 | # Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct 708 | # doxygen to hide any special comment blocks from generated source code 709 | # fragments. Normal C and C++ comments will always remain visible. 710 | 711 | STRIP_CODE_COMMENTS = YES 712 | 713 | # If the REFERENCED_BY_RELATION tag is set to YES 714 | # then for each documented function all documented 715 | # functions referencing it will be listed. 716 | 717 | REFERENCED_BY_RELATION = NO 718 | 719 | # If the REFERENCES_RELATION tag is set to YES 720 | # then for each documented function all documented entities 721 | # called/used by that function will be listed. 722 | 723 | REFERENCES_RELATION = NO 724 | 725 | # If the REFERENCES_LINK_SOURCE tag is set to YES (the default) 726 | # and SOURCE_BROWSER tag is set to YES, then the hyperlinks from 727 | # functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will 728 | # link to the source code. 729 | # Otherwise they will link to the documentation. 730 | 731 | REFERENCES_LINK_SOURCE = YES 732 | 733 | # If the USE_HTAGS tag is set to YES then the references to source code 734 | # will point to the HTML generated by the htags(1) tool instead of doxygen 735 | # built-in source browser. The htags tool is part of GNU's global source 736 | # tagging system (see http://www.gnu.org/software/global/global.html). You 737 | # will need version 4.8.6 or higher. 738 | 739 | USE_HTAGS = NO 740 | 741 | # If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen 742 | # will generate a verbatim copy of the header file for each class for 743 | # which an include is specified. Set to NO to disable this. 744 | 745 | VERBATIM_HEADERS = YES 746 | 747 | #--------------------------------------------------------------------------- 748 | # configuration options related to the alphabetical class index 749 | #--------------------------------------------------------------------------- 750 | 751 | # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index 752 | # of all compounds will be generated. Enable this if the project 753 | # contains a lot of classes, structs, unions or interfaces. 754 | 755 | ALPHABETICAL_INDEX = YES 756 | 757 | # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then 758 | # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns 759 | # in which this list will be split (can be a number in the range [1..20]) 760 | 761 | COLS_IN_ALPHA_INDEX = 5 762 | 763 | # In case all classes in a project start with a common prefix, all 764 | # classes will be put under the same header in the alphabetical index. 765 | # The IGNORE_PREFIX tag can be used to specify one or more prefixes that 766 | # should be ignored while generating the index headers. 767 | 768 | IGNORE_PREFIX = 769 | 770 | #--------------------------------------------------------------------------- 771 | # configuration options related to the HTML output 772 | #--------------------------------------------------------------------------- 773 | 774 | # If the GENERATE_HTML tag is set to YES (the default) Doxygen will 775 | # generate HTML output. 776 | 777 | GENERATE_HTML = YES 778 | 779 | # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. 780 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 781 | # put in front of it. If left blank `html' will be used as the default path. 782 | 783 | HTML_OUTPUT = html 784 | 785 | # The HTML_FILE_EXTENSION tag can be used to specify the file extension for 786 | # each generated HTML page (for example: .htm,.php,.asp). If it is left blank 787 | # doxygen will generate files with .html extension. 788 | 789 | HTML_FILE_EXTENSION = .html 790 | 791 | # The HTML_HEADER tag can be used to specify a personal HTML header for 792 | # each generated HTML page. If it is left blank doxygen will generate a 793 | # standard header. 794 | 795 | HTML_HEADER = 796 | 797 | # The HTML_FOOTER tag can be used to specify a personal HTML footer for 798 | # each generated HTML page. If it is left blank doxygen will generate a 799 | # standard footer. 800 | 801 | HTML_FOOTER = 802 | 803 | # The HTML_STYLESHEET tag can be used to specify a user-defined cascading 804 | # style sheet that is used by each HTML page. It can be used to 805 | # fine-tune the look of the HTML output. If the tag is left blank doxygen 806 | # will generate a default style sheet. Note that doxygen will try to copy 807 | # the style sheet file to the HTML output directory, so don't put your own 808 | # stylesheet in the HTML output directory as well, or it will be erased! 809 | 810 | HTML_STYLESHEET = 811 | 812 | # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. 813 | # Doxygen will adjust the colors in the stylesheet and background images 814 | # according to this color. Hue is specified as an angle on a colorwheel, 815 | # see http://en.wikipedia.org/wiki/Hue for more information. 816 | # For instance the value 0 represents red, 60 is yellow, 120 is green, 817 | # 180 is cyan, 240 is blue, 300 purple, and 360 is red again. 818 | # The allowed range is 0 to 359. 819 | 820 | HTML_COLORSTYLE_HUE = 220 821 | 822 | # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of 823 | # the colors in the HTML output. For a value of 0 the output will use 824 | # grayscales only. A value of 255 will produce the most vivid colors. 825 | 826 | HTML_COLORSTYLE_SAT = 100 827 | 828 | # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to 829 | # the luminance component of the colors in the HTML output. Values below 830 | # 100 gradually make the output lighter, whereas values above 100 make 831 | # the output darker. The value divided by 100 is the actual gamma applied, 832 | # so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, 833 | # and 100 does not change the gamma. 834 | 835 | HTML_COLORSTYLE_GAMMA = 80 836 | 837 | # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML 838 | # page will contain the date and time when the page was generated. Setting 839 | # this to NO can help when comparing the output of multiple runs. 840 | 841 | HTML_TIMESTAMP = YES 842 | 843 | # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, 844 | # files or namespaces will be aligned in HTML using tables. If set to 845 | # NO a bullet list will be used. 846 | 847 | HTML_ALIGN_MEMBERS = YES 848 | 849 | # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML 850 | # documentation will contain sections that can be hidden and shown after the 851 | # page has loaded. For this to work a browser that supports 852 | # JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox 853 | # Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). 854 | 855 | HTML_DYNAMIC_SECTIONS = NO 856 | 857 | # If the GENERATE_DOCSET tag is set to YES, additional index files 858 | # will be generated that can be used as input for Apple's Xcode 3 859 | # integrated development environment, introduced with OSX 10.5 (Leopard). 860 | # To create a documentation set, doxygen will generate a Makefile in the 861 | # HTML output directory. Running make will produce the docset in that 862 | # directory and running "make install" will install the docset in 863 | # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find 864 | # it at startup. 865 | # See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html 866 | # for more information. 867 | 868 | GENERATE_DOCSET = NO 869 | 870 | # When GENERATE_DOCSET tag is set to YES, this tag determines the name of the 871 | # feed. A documentation feed provides an umbrella under which multiple 872 | # documentation sets from a single provider (such as a company or product suite) 873 | # can be grouped. 874 | 875 | DOCSET_FEEDNAME = "Doxygen generated docs" 876 | 877 | # When GENERATE_DOCSET tag is set to YES, this tag specifies a string that 878 | # should uniquely identify the documentation set bundle. This should be a 879 | # reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen 880 | # will append .docset to the name. 881 | 882 | DOCSET_BUNDLE_ID = org.doxygen.Project 883 | 884 | # When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify 885 | # the documentation publisher. This should be a reverse domain-name style 886 | # string, e.g. com.mycompany.MyDocSet.documentation. 887 | 888 | DOCSET_PUBLISHER_ID = org.doxygen.Publisher 889 | 890 | # The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. 891 | 892 | DOCSET_PUBLISHER_NAME = Publisher 893 | 894 | # If the GENERATE_HTMLHELP tag is set to YES, additional index files 895 | # will be generated that can be used as input for tools like the 896 | # Microsoft HTML help workshop to generate a compiled HTML help file (.chm) 897 | # of the generated HTML documentation. 898 | 899 | GENERATE_HTMLHELP = NO 900 | 901 | # If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can 902 | # be used to specify the file name of the resulting .chm file. You 903 | # can add a path in front of the file if the result should not be 904 | # written to the html output directory. 905 | 906 | CHM_FILE = 907 | 908 | # If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can 909 | # be used to specify the location (absolute path including file name) of 910 | # the HTML help compiler (hhc.exe). If non-empty doxygen will try to run 911 | # the HTML help compiler on the generated index.hhp. 912 | 913 | HHC_LOCATION = 914 | 915 | # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag 916 | # controls if a separate .chi index file is generated (YES) or that 917 | # it should be included in the master .chm file (NO). 918 | 919 | GENERATE_CHI = NO 920 | 921 | # If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING 922 | # is used to encode HtmlHelp index (hhk), content (hhc) and project file 923 | # content. 924 | 925 | CHM_INDEX_ENCODING = 926 | 927 | # If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag 928 | # controls whether a binary table of contents is generated (YES) or a 929 | # normal table of contents (NO) in the .chm file. 930 | 931 | BINARY_TOC = NO 932 | 933 | # The TOC_EXPAND flag can be set to YES to add extra items for group members 934 | # to the contents of the HTML help documentation and to the tree view. 935 | 936 | TOC_EXPAND = NO 937 | 938 | # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and 939 | # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated 940 | # that can be used as input for Qt's qhelpgenerator to generate a 941 | # Qt Compressed Help (.qch) of the generated HTML documentation. 942 | 943 | GENERATE_QHP = NO 944 | 945 | # If the QHG_LOCATION tag is specified, the QCH_FILE tag can 946 | # be used to specify the file name of the resulting .qch file. 947 | # The path specified is relative to the HTML output folder. 948 | 949 | QCH_FILE = 950 | 951 | # The QHP_NAMESPACE tag specifies the namespace to use when generating 952 | # Qt Help Project output. For more information please see 953 | # http://doc.trolltech.com/qthelpproject.html#namespace 954 | 955 | QHP_NAMESPACE = org.doxygen.Project 956 | 957 | # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating 958 | # Qt Help Project output. For more information please see 959 | # http://doc.trolltech.com/qthelpproject.html#virtual-folders 960 | 961 | QHP_VIRTUAL_FOLDER = doc 962 | 963 | # If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to 964 | # add. For more information please see 965 | # http://doc.trolltech.com/qthelpproject.html#custom-filters 966 | 967 | QHP_CUST_FILTER_NAME = 968 | 969 | # The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the 970 | # custom filter to add. For more information please see 971 | # 972 | # Qt Help Project / Custom Filters. 973 | 974 | QHP_CUST_FILTER_ATTRS = 975 | 976 | # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this 977 | # project's 978 | # filter section matches. 979 | # 980 | # Qt Help Project / Filter Attributes. 981 | 982 | QHP_SECT_FILTER_ATTRS = 983 | 984 | # If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can 985 | # be used to specify the location of Qt's qhelpgenerator. 986 | # If non-empty doxygen will try to run qhelpgenerator on the generated 987 | # .qhp file. 988 | 989 | QHG_LOCATION = 990 | 991 | # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files 992 | # will be generated, which together with the HTML files, form an Eclipse help 993 | # plugin. To install this plugin and make it available under the help contents 994 | # menu in Eclipse, the contents of the directory containing the HTML and XML 995 | # files needs to be copied into the plugins directory of eclipse. The name of 996 | # the directory within the plugins directory should be the same as 997 | # the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before 998 | # the help appears. 999 | 1000 | GENERATE_ECLIPSEHELP = NO 1001 | 1002 | # A unique identifier for the eclipse help plugin. When installing the plugin 1003 | # the directory name containing the HTML and XML files should also have 1004 | # this name. 1005 | 1006 | ECLIPSE_DOC_ID = org.doxygen.Project 1007 | 1008 | # The DISABLE_INDEX tag can be used to turn on/off the condensed index at 1009 | # top of each HTML page. The value NO (the default) enables the index and 1010 | # the value YES disables it. 1011 | 1012 | DISABLE_INDEX = NO 1013 | 1014 | # This tag can be used to set the number of enum values (range [1..20]) 1015 | # that doxygen will group on one line in the generated HTML documentation. 1016 | 1017 | ENUM_VALUES_PER_LINE = 4 1018 | 1019 | # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index 1020 | # structure should be generated to display hierarchical information. 1021 | # If the tag value is set to YES, a side panel will be generated 1022 | # containing a tree-like index structure (just like the one that 1023 | # is generated for HTML Help). For this to work a browser that supports 1024 | # JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). 1025 | # Windows users are probably better off using the HTML help feature. 1026 | 1027 | GENERATE_TREEVIEW = NO 1028 | 1029 | # By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, 1030 | # and Class Hierarchy pages using a tree view instead of an ordered list. 1031 | 1032 | USE_INLINE_TREES = NO 1033 | 1034 | # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be 1035 | # used to set the initial width (in pixels) of the frame in which the tree 1036 | # is shown. 1037 | 1038 | TREEVIEW_WIDTH = 250 1039 | 1040 | # When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open 1041 | # links to external symbols imported via tag files in a separate window. 1042 | 1043 | EXT_LINKS_IN_WINDOW = NO 1044 | 1045 | # Use this tag to change the font size of Latex formulas included 1046 | # as images in the HTML documentation. The default is 10. Note that 1047 | # when you change the font size after a successful doxygen run you need 1048 | # to manually remove any form_*.png images from the HTML output directory 1049 | # to force them to be regenerated. 1050 | 1051 | FORMULA_FONTSIZE = 10 1052 | 1053 | # Use the FORMULA_TRANPARENT tag to determine whether or not the images 1054 | # generated for formulas are transparent PNGs. Transparent PNGs are 1055 | # not supported properly for IE 6.0, but are supported on all modern browsers. 1056 | # Note that when changing this option you need to delete any form_*.png files 1057 | # in the HTML output before the changes have effect. 1058 | 1059 | FORMULA_TRANSPARENT = YES 1060 | 1061 | # When the SEARCHENGINE tag is enabled doxygen will generate a search box 1062 | # for the HTML output. The underlying search engine uses javascript 1063 | # and DHTML and should work on any modern browser. Note that when using 1064 | # HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets 1065 | # (GENERATE_DOCSET) there is already a search function so this one should 1066 | # typically be disabled. For large projects the javascript based search engine 1067 | # can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. 1068 | 1069 | SEARCHENGINE = YES 1070 | 1071 | # When the SERVER_BASED_SEARCH tag is enabled the search engine will be 1072 | # implemented using a PHP enabled web server instead of at the web client 1073 | # using Javascript. Doxygen will generate the search PHP script and index 1074 | # file to put on the web server. The advantage of the server 1075 | # based approach is that it scales better to large projects and allows 1076 | # full text search. The disadvances is that it is more difficult to setup 1077 | # and does not have live searching capabilities. 1078 | 1079 | SERVER_BASED_SEARCH = NO 1080 | 1081 | #--------------------------------------------------------------------------- 1082 | # configuration options related to the LaTeX output 1083 | #--------------------------------------------------------------------------- 1084 | 1085 | # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 1086 | # generate Latex output. 1087 | 1088 | GENERATE_LATEX = NO 1089 | 1090 | # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 1091 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 1092 | # put in front of it. If left blank `latex' will be used as the default path. 1093 | 1094 | LATEX_OUTPUT = latex 1095 | 1096 | # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be 1097 | # invoked. If left blank `latex' will be used as the default command name. 1098 | # Note that when enabling USE_PDFLATEX this option is only used for 1099 | # generating bitmaps for formulas in the HTML output, but not in the 1100 | # Makefile that is written to the output directory. 1101 | 1102 | LATEX_CMD_NAME = latex 1103 | 1104 | # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to 1105 | # generate index for LaTeX. If left blank `makeindex' will be used as the 1106 | # default command name. 1107 | 1108 | MAKEINDEX_CMD_NAME = makeindex 1109 | 1110 | # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact 1111 | # LaTeX documents. This may be useful for small projects and may help to 1112 | # save some trees in general. 1113 | 1114 | COMPACT_LATEX = NO 1115 | 1116 | # The PAPER_TYPE tag can be used to set the paper type that is used 1117 | # by the printer. Possible values are: a4, a4wide, letter, legal and 1118 | # executive. If left blank a4wide will be used. 1119 | 1120 | PAPER_TYPE = a4wide 1121 | 1122 | # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX 1123 | # packages that should be included in the LaTeX output. 1124 | 1125 | EXTRA_PACKAGES = 1126 | 1127 | # The LATEX_HEADER tag can be used to specify a personal LaTeX header for 1128 | # the generated latex document. The header should contain everything until 1129 | # the first chapter. If it is left blank doxygen will generate a 1130 | # standard header. Notice: only use this tag if you know what you are doing! 1131 | 1132 | LATEX_HEADER = 1133 | 1134 | # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated 1135 | # is prepared for conversion to pdf (using ps2pdf). The pdf file will 1136 | # contain links (just like the HTML output) instead of page references 1137 | # This makes the output suitable for online browsing using a pdf viewer. 1138 | 1139 | PDF_HYPERLINKS = YES 1140 | 1141 | # If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of 1142 | # plain latex in the generated Makefile. Set this option to YES to get a 1143 | # higher quality PDF documentation. 1144 | 1145 | USE_PDFLATEX = YES 1146 | 1147 | # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. 1148 | # command to the generated LaTeX files. This will instruct LaTeX to keep 1149 | # running if errors occur, instead of asking the user for help. 1150 | # This option is also used when generating formulas in HTML. 1151 | 1152 | LATEX_BATCHMODE = NO 1153 | 1154 | # If LATEX_HIDE_INDICES is set to YES then doxygen will not 1155 | # include the index chapters (such as File Index, Compound Index, etc.) 1156 | # in the output. 1157 | 1158 | LATEX_HIDE_INDICES = NO 1159 | 1160 | # If LATEX_SOURCE_CODE is set to YES then doxygen will include 1161 | # source code with syntax highlighting in the LaTeX output. 1162 | # Note that which sources are shown also depends on other settings 1163 | # such as SOURCE_BROWSER. 1164 | 1165 | LATEX_SOURCE_CODE = NO 1166 | 1167 | #--------------------------------------------------------------------------- 1168 | # configuration options related to the RTF output 1169 | #--------------------------------------------------------------------------- 1170 | 1171 | # If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output 1172 | # The RTF output is optimized for Word 97 and may not look very pretty with 1173 | # other RTF readers or editors. 1174 | 1175 | GENERATE_RTF = NO 1176 | 1177 | # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. 1178 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 1179 | # put in front of it. If left blank `rtf' will be used as the default path. 1180 | 1181 | RTF_OUTPUT = rtf 1182 | 1183 | # If the COMPACT_RTF tag is set to YES Doxygen generates more compact 1184 | # RTF documents. This may be useful for small projects and may help to 1185 | # save some trees in general. 1186 | 1187 | COMPACT_RTF = NO 1188 | 1189 | # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated 1190 | # will contain hyperlink fields. The RTF file will 1191 | # contain links (just like the HTML output) instead of page references. 1192 | # This makes the output suitable for online browsing using WORD or other 1193 | # programs which support those fields. 1194 | # Note: wordpad (write) and others do not support links. 1195 | 1196 | RTF_HYPERLINKS = NO 1197 | 1198 | # Load stylesheet definitions from file. Syntax is similar to doxygen's 1199 | # config file, i.e. a series of assignments. You only have to provide 1200 | # replacements, missing definitions are set to their default value. 1201 | 1202 | RTF_STYLESHEET_FILE = 1203 | 1204 | # Set optional variables used in the generation of an rtf document. 1205 | # Syntax is similar to doxygen's config file. 1206 | 1207 | RTF_EXTENSIONS_FILE = 1208 | 1209 | #--------------------------------------------------------------------------- 1210 | # configuration options related to the man page output 1211 | #--------------------------------------------------------------------------- 1212 | 1213 | # If the GENERATE_MAN tag is set to YES (the default) Doxygen will 1214 | # generate man pages 1215 | 1216 | GENERATE_MAN = NO 1217 | 1218 | # The MAN_OUTPUT tag is used to specify where the man pages will be put. 1219 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 1220 | # put in front of it. If left blank `man' will be used as the default path. 1221 | 1222 | MAN_OUTPUT = man 1223 | 1224 | # The MAN_EXTENSION tag determines the extension that is added to 1225 | # the generated man pages (default is the subroutine's section .3) 1226 | 1227 | MAN_EXTENSION = .3 1228 | 1229 | # If the MAN_LINKS tag is set to YES and Doxygen generates man output, 1230 | # then it will generate one additional man file for each entity 1231 | # documented in the real man page(s). These additional files 1232 | # only source the real man page, but without them the man command 1233 | # would be unable to find the correct page. The default is NO. 1234 | 1235 | MAN_LINKS = NO 1236 | 1237 | #--------------------------------------------------------------------------- 1238 | # configuration options related to the XML output 1239 | #--------------------------------------------------------------------------- 1240 | 1241 | # If the GENERATE_XML tag is set to YES Doxygen will 1242 | # generate an XML file that captures the structure of 1243 | # the code including all documentation. 1244 | 1245 | GENERATE_XML = NO 1246 | 1247 | # The XML_OUTPUT tag is used to specify where the XML pages will be put. 1248 | # If a relative path is entered the value of OUTPUT_DIRECTORY will be 1249 | # put in front of it. If left blank `xml' will be used as the default path. 1250 | 1251 | XML_OUTPUT = xml 1252 | 1253 | # The XML_SCHEMA tag can be used to specify an XML schema, 1254 | # which can be used by a validating XML parser to check the 1255 | # syntax of the XML files. 1256 | 1257 | XML_SCHEMA = 1258 | 1259 | # The XML_DTD tag can be used to specify an XML DTD, 1260 | # which can be used by a validating XML parser to check the 1261 | # syntax of the XML files. 1262 | 1263 | XML_DTD = 1264 | 1265 | # If the XML_PROGRAMLISTING tag is set to YES Doxygen will 1266 | # dump the program listings (including syntax highlighting 1267 | # and cross-referencing information) to the XML output. Note that 1268 | # enabling this will significantly increase the size of the XML output. 1269 | 1270 | XML_PROGRAMLISTING = YES 1271 | 1272 | #--------------------------------------------------------------------------- 1273 | # configuration options for the AutoGen Definitions output 1274 | #--------------------------------------------------------------------------- 1275 | 1276 | # If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will 1277 | # generate an AutoGen Definitions (see autogen.sf.net) file 1278 | # that captures the structure of the code including all 1279 | # documentation. Note that this feature is still experimental 1280 | # and incomplete at the moment. 1281 | 1282 | GENERATE_AUTOGEN_DEF = NO 1283 | 1284 | #--------------------------------------------------------------------------- 1285 | # configuration options related to the Perl module output 1286 | #--------------------------------------------------------------------------- 1287 | 1288 | # If the GENERATE_PERLMOD tag is set to YES Doxygen will 1289 | # generate a Perl module file that captures the structure of 1290 | # the code including all documentation. Note that this 1291 | # feature is still experimental and incomplete at the 1292 | # moment. 1293 | 1294 | GENERATE_PERLMOD = NO 1295 | 1296 | # If the PERLMOD_LATEX tag is set to YES Doxygen will generate 1297 | # the necessary Makefile rules, Perl scripts and LaTeX code to be able 1298 | # to generate PDF and DVI output from the Perl module output. 1299 | 1300 | PERLMOD_LATEX = NO 1301 | 1302 | # If the PERLMOD_PRETTY tag is set to YES the Perl module output will be 1303 | # nicely formatted so it can be parsed by a human reader. 1304 | # This is useful 1305 | # if you want to understand what is going on. 1306 | # On the other hand, if this 1307 | # tag is set to NO the size of the Perl module output will be much smaller 1308 | # and Perl will parse it just the same. 1309 | 1310 | PERLMOD_PRETTY = YES 1311 | 1312 | # The names of the make variables in the generated doxyrules.make file 1313 | # are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. 1314 | # This is useful so different doxyrules.make files included by the same 1315 | # Makefile don't overwrite each other's variables. 1316 | 1317 | PERLMOD_MAKEVAR_PREFIX = 1318 | 1319 | #--------------------------------------------------------------------------- 1320 | # Configuration options related to the preprocessor 1321 | #--------------------------------------------------------------------------- 1322 | 1323 | # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will 1324 | # evaluate all C-preprocessor directives found in the sources and include 1325 | # files. 1326 | 1327 | ENABLE_PREPROCESSING = YES 1328 | 1329 | # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro 1330 | # names in the source code. If set to NO (the default) only conditional 1331 | # compilation will be performed. Macro expansion can be done in a controlled 1332 | # way by setting EXPAND_ONLY_PREDEF to YES. 1333 | 1334 | MACRO_EXPANSION = YES 1335 | 1336 | # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES 1337 | # then the macro expansion is limited to the macros specified with the 1338 | # PREDEFINED and EXPAND_AS_DEFINED tags. 1339 | 1340 | EXPAND_ONLY_PREDEF = YES 1341 | 1342 | # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files 1343 | # in the INCLUDE_PATH (see below) will be search if a #include is found. 1344 | 1345 | SEARCH_INCLUDES = YES 1346 | 1347 | # The INCLUDE_PATH tag can be used to specify one or more directories that 1348 | # contain include files that are not input files but should be processed by 1349 | # the preprocessor. 1350 | 1351 | INCLUDE_PATH = 1352 | 1353 | # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard 1354 | # patterns (like *.h and *.hpp) to filter out the header-files in the 1355 | # directories. If left blank, the patterns specified with FILE_PATTERNS will 1356 | # be used. 1357 | 1358 | INCLUDE_FILE_PATTERNS = 1359 | 1360 | # The PREDEFINED tag can be used to specify one or more macro names that 1361 | # are defined before the preprocessor is started (similar to the -D option of 1362 | # gcc). The argument of the tag is a list of macros of the form: name 1363 | # or name=definition (no spaces). If the definition and the = are 1364 | # omitted =1 is assumed. To prevent a macro definition from being 1365 | # undefined via #undef or recursively expanded use the := operator 1366 | # instead of the = operator. 1367 | 1368 | PREDEFINED = __attribute__()= 1369 | 1370 | # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then 1371 | # this tag can be used to specify a list of macro names that should be expanded. 1372 | # The macro definition that is found in the sources will be used. 1373 | # Use the PREDEFINED tag if you want to use a different macro definition. 1374 | 1375 | EXPAND_AS_DEFINED = 1376 | 1377 | # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then 1378 | # doxygen's preprocessor will remove all function-like macros that are alone 1379 | # on a line, have an all uppercase name, and do not end with a semicolon. Such 1380 | # function macros are typically used for boiler-plate code, and will confuse 1381 | # the parser if not removed. 1382 | 1383 | SKIP_FUNCTION_MACROS = YES 1384 | 1385 | #--------------------------------------------------------------------------- 1386 | # Configuration::additions related to external references 1387 | #--------------------------------------------------------------------------- 1388 | 1389 | # The TAGFILES option can be used to specify one or more tagfiles. 1390 | # Optionally an initial location of the external documentation 1391 | # can be added for each tagfile. The format of a tag file without 1392 | # this location is as follows: 1393 | # 1394 | # TAGFILES = file1 file2 ... 1395 | # Adding location for the tag files is done as follows: 1396 | # 1397 | # TAGFILES = file1=loc1 "file2 = loc2" ... 1398 | # where "loc1" and "loc2" can be relative or absolute paths or 1399 | # URLs. If a location is present for each tag, the installdox tool 1400 | # does not have to be run to correct the links. 1401 | # Note that each tag file must have a unique name 1402 | # (where the name does NOT include the path) 1403 | # If a tag file is not located in the directory in which doxygen 1404 | # is run, you must also specify the path to the tagfile here. 1405 | 1406 | TAGFILES = 1407 | 1408 | # When a file name is specified after GENERATE_TAGFILE, doxygen will create 1409 | # a tag file that is based on the input files it reads. 1410 | 1411 | GENERATE_TAGFILE = 1412 | 1413 | # If the ALLEXTERNALS tag is set to YES all external classes will be listed 1414 | # in the class index. If set to NO only the inherited external classes 1415 | # will be listed. 1416 | 1417 | ALLEXTERNALS = NO 1418 | 1419 | # If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed 1420 | # in the modules index. If set to NO, only the current project's groups will 1421 | # be listed. 1422 | 1423 | EXTERNAL_GROUPS = YES 1424 | 1425 | # The PERL_PATH should be the absolute path and name of the perl script 1426 | # interpreter (i.e. the result of `which perl'). 1427 | 1428 | PERL_PATH = /usr/bin/perl 1429 | 1430 | #--------------------------------------------------------------------------- 1431 | # Configuration options related to the dot tool 1432 | #--------------------------------------------------------------------------- 1433 | 1434 | # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will 1435 | # generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base 1436 | # or super classes. Setting the tag to NO turns the diagrams off. Note that 1437 | # this option is superseded by the HAVE_DOT option below. This is only a 1438 | # fallback. It is recommended to install and use dot, since it yields more 1439 | # powerful graphs. 1440 | 1441 | CLASS_DIAGRAMS = YES 1442 | 1443 | # You can define message sequence charts within doxygen comments using the \msc 1444 | # command. Doxygen will then run the mscgen tool (see 1445 | # http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the 1446 | # documentation. The MSCGEN_PATH tag allows you to specify the directory where 1447 | # the mscgen tool resides. If left empty the tool is assumed to be found in the 1448 | # default search path. 1449 | 1450 | MSCGEN_PATH = 1451 | 1452 | # If set to YES, the inheritance and collaboration graphs will hide 1453 | # inheritance and usage relations if the target is undocumented 1454 | # or is not a class. 1455 | 1456 | HIDE_UNDOC_RELATIONS = YES 1457 | 1458 | # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is 1459 | # available from the path. This tool is part of Graphviz, a graph visualization 1460 | # toolkit from AT&T and Lucent Bell Labs. The other options in this section 1461 | # have no effect if this option is set to NO (the default) 1462 | 1463 | HAVE_DOT = NO 1464 | 1465 | # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is 1466 | # allowed to run in parallel. When set to 0 (the default) doxygen will 1467 | # base this on the number of processors available in the system. You can set it 1468 | # explicitly to a value larger than 0 to get control over the balance 1469 | # between CPU load and processing speed. 1470 | 1471 | DOT_NUM_THREADS = 0 1472 | 1473 | # By default doxygen will write a font called FreeSans.ttf to the output 1474 | # directory and reference it in all dot files that doxygen generates. This 1475 | # font does not include all possible unicode characters however, so when you need 1476 | # these (or just want a differently looking font) you can specify the font name 1477 | # using DOT_FONTNAME. You need need to make sure dot is able to find the font, 1478 | # which can be done by putting it in a standard location or by setting the 1479 | # DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory 1480 | # containing the font. 1481 | 1482 | DOT_FONTNAME = FreeSans.ttf 1483 | 1484 | # The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. 1485 | # The default size is 10pt. 1486 | 1487 | DOT_FONTSIZE = 10 1488 | 1489 | # By default doxygen will tell dot to use the output directory to look for the 1490 | # FreeSans.ttf font (which doxygen will put there itself). If you specify a 1491 | # different font using DOT_FONTNAME you can set the path where dot 1492 | # can find it using this tag. 1493 | 1494 | DOT_FONTPATH = 1495 | 1496 | # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen 1497 | # will generate a graph for each documented class showing the direct and 1498 | # indirect inheritance relations. Setting this tag to YES will force the 1499 | # the CLASS_DIAGRAMS tag to NO. 1500 | 1501 | CLASS_GRAPH = YES 1502 | 1503 | # If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen 1504 | # will generate a graph for each documented class showing the direct and 1505 | # indirect implementation dependencies (inheritance, containment, and 1506 | # class references variables) of the class with other documented classes. 1507 | 1508 | COLLABORATION_GRAPH = YES 1509 | 1510 | # If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen 1511 | # will generate a graph for groups, showing the direct groups dependencies 1512 | 1513 | GROUP_GRAPHS = YES 1514 | 1515 | # If the UML_LOOK tag is set to YES doxygen will generate inheritance and 1516 | # collaboration diagrams in a style similar to the OMG's Unified Modeling 1517 | # Language. 1518 | 1519 | UML_LOOK = NO 1520 | 1521 | # If set to YES, the inheritance and collaboration graphs will show the 1522 | # relations between templates and their instances. 1523 | 1524 | TEMPLATE_RELATIONS = NO 1525 | 1526 | # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT 1527 | # tags are set to YES then doxygen will generate a graph for each documented 1528 | # file showing the direct and indirect include dependencies of the file with 1529 | # other documented files. 1530 | 1531 | INCLUDE_GRAPH = YES 1532 | 1533 | # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and 1534 | # HAVE_DOT tags are set to YES then doxygen will generate a graph for each 1535 | # documented header file showing the documented files that directly or 1536 | # indirectly include this file. 1537 | 1538 | INCLUDED_BY_GRAPH = YES 1539 | 1540 | # If the CALL_GRAPH and HAVE_DOT options are set to YES then 1541 | # doxygen will generate a call dependency graph for every global function 1542 | # or class method. Note that enabling this option will significantly increase 1543 | # the time of a run. So in most cases it will be better to enable call graphs 1544 | # for selected functions only using the \callgraph command. 1545 | 1546 | CALL_GRAPH = NO 1547 | 1548 | # If the CALLER_GRAPH and HAVE_DOT tags are set to YES then 1549 | # doxygen will generate a caller dependency graph for every global function 1550 | # or class method. Note that enabling this option will significantly increase 1551 | # the time of a run. So in most cases it will be better to enable caller 1552 | # graphs for selected functions only using the \callergraph command. 1553 | 1554 | CALLER_GRAPH = NO 1555 | 1556 | # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen 1557 | # will graphical hierarchy of all classes instead of a textual one. 1558 | 1559 | GRAPHICAL_HIERARCHY = YES 1560 | 1561 | # If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES 1562 | # then doxygen will show the dependencies a directory has on other directories 1563 | # in a graphical way. The dependency relations are determined by the #include 1564 | # relations between the files in the directories. 1565 | 1566 | DIRECTORY_GRAPH = YES 1567 | 1568 | # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images 1569 | # generated by dot. Possible values are png, jpg, or gif 1570 | # If left blank png will be used. 1571 | 1572 | DOT_IMAGE_FORMAT = png 1573 | 1574 | # The tag DOT_PATH can be used to specify the path where the dot tool can be 1575 | # found. If left blank, it is assumed the dot tool can be found in the path. 1576 | 1577 | DOT_PATH = 1578 | 1579 | # The DOTFILE_DIRS tag can be used to specify one or more directories that 1580 | # contain dot files that are included in the documentation (see the 1581 | # \dotfile command). 1582 | 1583 | DOTFILE_DIRS = 1584 | 1585 | # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of 1586 | # nodes that will be shown in the graph. If the number of nodes in a graph 1587 | # becomes larger than this value, doxygen will truncate the graph, which is 1588 | # visualized by representing a node as a red box. Note that doxygen if the 1589 | # number of direct children of the root node in a graph is already larger than 1590 | # DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note 1591 | # that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. 1592 | 1593 | DOT_GRAPH_MAX_NODES = 50 1594 | 1595 | # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the 1596 | # graphs generated by dot. A depth value of 3 means that only nodes reachable 1597 | # from the root by following a path via at most 3 edges will be shown. Nodes 1598 | # that lay further from the root node will be omitted. Note that setting this 1599 | # option to 1 or 2 may greatly reduce the computation time needed for large 1600 | # code bases. Also note that the size of a graph can be further restricted by 1601 | # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. 1602 | 1603 | MAX_DOT_GRAPH_DEPTH = 0 1604 | 1605 | # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent 1606 | # background. This is disabled by default, because dot on Windows does not 1607 | # seem to support this out of the box. Warning: Depending on the platform used, 1608 | # enabling this option may lead to badly anti-aliased labels on the edges of 1609 | # a graph (i.e. they become hard to read). 1610 | 1611 | DOT_TRANSPARENT = NO 1612 | 1613 | # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output 1614 | # files in one run (i.e. multiple -o and -T options on the command line). This 1615 | # makes dot run faster, but since only newer versions of dot (>1.8.10) 1616 | # support this, this feature is disabled by default. 1617 | 1618 | DOT_MULTI_TARGETS = YES 1619 | 1620 | # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will 1621 | # generate a legend page explaining the meaning of the various boxes and 1622 | # arrows in the dot generated graphs. 1623 | 1624 | GENERATE_LEGEND = YES 1625 | 1626 | # If the DOT_CLEANUP tag is set to YES (the default) Doxygen will 1627 | # remove the intermediate dot files that are used to generate 1628 | # the various graphs. 1629 | 1630 | DOT_CLEANUP = YES 1631 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ifndef HOST 2 | HOST = unix 3 | endif 4 | 5 | ifeq ($(HOST),stm32) 6 | PREFIX ?= arm-none-eabi 7 | CFLAGS += -mcpu=cortex-m3 -mthumb 8 | LDFLAGS += -mcpu=cortex-m3 -mthumb -march=armv7 -mfix-cortex-m3-ldrd -msoft-float 9 | endif 10 | 11 | export PREFIX 12 | export CFLAGS 13 | export LDFLAGS 14 | 15 | .PHONY: all doc FORCE 16 | 17 | all: 18 | $(MAKE) -C src 19 | $(MAKE) -C $(HOST) 20 | 21 | doc: 22 | doxygen Doxyfile 23 | 24 | %: FORCE 25 | $(MAKE) -C src $@ 26 | $(MAKE) -C $(HOST) $@ 27 | 28 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | OpenFAT is a FAT filesystem implementation for embedded processors. 2 | 3 | See the Doxygen documentation for more information. 4 | To generate the docs type: 5 | $ make doc 6 | And then look at doc/html/index.html 7 | 8 | The directories in this repostory are as follows: 9 | include/ - OpenFAT public interface header files. 10 | src/ - Openfat library code 11 | unix/ - Examples for a Unix host 12 | stm32/ - Examples for an STM32 host using libopenstm32 13 | doc/ - Generated documentation. 14 | 15 | -------------------------------------------------------------------------------- /doc/mainpage.c: -------------------------------------------------------------------------------- 1 | /*! \mainpage OpenFAT Documentation 2 | 3 | \section intro_sec Introduction 4 | 5 | OpenFAT is a FAT filesystem for embedded processors, created by the 6 | Electronics Research Group at the University of Otago, and supported by a 7 | grant from the New Zealand Ministry of Science and Innovation. 8 | 9 | \section req_sec Requirements 10 | 11 | OpenFAT is written entirely in C using C99 and GNU extentions. It is 12 | intended for use in microcontrollers, but is written to be portable and 13 | an example using a FAT image in a POSIX file is included with the source. 14 | It should build with GCC for any target architecture. 15 | 16 | We are currently using OpenFAT with the STM32 family of ARM Cortex-M3 17 | microcontrollers from ST Microelectronics, using 18 | summon-arm-toolchain and 19 | libopenstm32. 20 | 21 | \section install_sec Installation 22 | 23 | If building for a Unix host: 24 | \verbatim 25 | make 26 | make install 27 | \endverbatim 28 | 29 | If building for STM32 with summon-arm-toolchain: 30 | \verbatim 31 | make HOST=stm32 32 | make HOST=stm32 DESTDIR=~/sat install 33 | \endverbatim 34 | 35 | \section usage_sec Using the OpenFAT library. 36 | The public interface is defined in openfat.h. A concrete implementation of 37 | the abstract ::block_device must be provided by the application. 38 | 39 | \code 40 | #include 41 | 42 | int main(void) 43 | { 44 | struct block_device *bldev; 45 | FatVol vol; 46 | FatFile file; 47 | char buffer[128]; 48 | 49 | bldev = block_device_new(); // Must be provided by the application. 50 | fat_vol_init(bldev, &vol); 51 | 52 | fat_open(&vol, "file.dat", O_RDONLY, &file); 53 | fat_read(&file, buffer, sizeof(buffer)); 54 | 55 | // Do something with buffer... 56 | 57 | return 0; 58 | } 59 | \endcode 60 | 61 | Only low-level access functions fat_read() and fat_write() are provided by 62 | OpenFAT. If higher level functions such as fprintf() or fgets() are needed by 63 | the application, Newlib provides 64 | an stdio implementation that may easily be wrapped around the OpenFAT low-level 65 | functions. 66 | 67 | \section link_sec Linking to the OpenFAT library. 68 | The library will be installed as libopenfat.a, so pass the option '-lopenfat' 69 | to GCC at the linker stage. 70 | \verbatim 71 | gcc fat_example.c -o fat_example -lopenfat 72 | \endverbatim 73 | 74 | */ 75 | 76 | -------------------------------------------------------------------------------- /include/openfat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /** \file openfat.h 22 | * \brief FAT Filesystem implementation, public interface. 23 | */ 24 | 25 | #ifndef __OPENFAT_H 26 | #define __OPENFAT_H 27 | 28 | #include 29 | 30 | #include 31 | 32 | #include "openfat/blockdev.h" 33 | 34 | /* Forward declarations of private structures. */ 35 | 36 | /** \brief Structure used internally for FAT volume state. 37 | * Do not access directly. Structure has no public fields. 38 | */ 39 | typedef struct fat_vol_handle FatVol; 40 | 41 | /** \brief Structure used internally for FAT file state. 42 | * Do not access directly. Structure has no public fields. 43 | */ 44 | typedef struct fat_file_handle FatFile; 45 | 46 | /** \brief Mount a FAT volume. 47 | * 48 | * Initialise a handle for access to a FAT filesystem on the specified 49 | * block device. 50 | * \param dev Pointer to block device to mount. 51 | * \param vol Pointer to filesystem handle to initialise. 52 | * \return 0 on success. 53 | */ 54 | int __attribute__((warn_unused_result)) 55 | fat_vol_init(const struct block_device *dev, FatVol *vol); 56 | 57 | /** \brief Change current working directory. 58 | * \param vol Pointer to FAT volume handle. 59 | * \param name Directory name to change to. Relative to the current dir. 60 | * \return 0 on success. 61 | */ 62 | int fat_chdir(FatVol *vol, const char *name); 63 | /** \brief Create a new directory. 64 | * \param vol Pointer to FAT volume handle. 65 | * \param name Directory name to create. 66 | * \return 0 on success. 67 | */ 68 | int fat_mkdir(FatVol *vol, const char *name); 69 | /** \brief Remove an empty directory. 70 | * \param vol Pointer to FAT volume handle. 71 | * \param name Directory name to remove. 72 | * \return 0 on success. 73 | */ 74 | int fat_rmdir(FatVol *vol, const char *name); /* TODO */ 75 | 76 | /** \brief Open an existing file. 77 | * The option O_ASYNC may be passed in flags to surpress the automatic 78 | * updating of the files directory entry on writes. fat_file_sync() must be 79 | * called explicitly to update it in this case. 80 | * 81 | * This function uses a ::dirent on the stack for iterating over the directory. 82 | * This is a fairly large structure. 83 | * 84 | * \param vol Pointer to FAT volume handle. 85 | * \param name File name in current directory to open. 86 | * \param flags O_RDONLY, O_WRONLY, or O_RDWR. (currently not implemented) 87 | * \param file Pointer to file handle to initialise. 88 | * \return 0 on success. 89 | */ 90 | int __attribute__((warn_unused_result)) 91 | fat_open(FatVol *vol, const char *name, int flags, FatFile *file); 92 | 93 | /** \brief Create a new file. 94 | * \see fat_open() 95 | * 96 | * \param vol Pointer to FAT volume handle. 97 | * \param name File name in current directory to create. 98 | * \param flags O_RDONLY, O_WRONLY, or O_RDWR. (currently not implemented) 99 | * \param file Pointer to file handle to initialise. 100 | * \return 0 on success. 101 | */ 102 | int __attribute__((warn_unused_result)) 103 | fat_create(FatVol *vol, const char *name, int flags, FatFile *file); 104 | 105 | #define O_ASYNC 020000 106 | /** \brief Update an open file's directory entry. 107 | * This must be called explicitly if a file is opened with the flag O_ASYNC. 108 | * In this case, updates to the directory entry are surpressed on writes to 109 | * improve performance. 110 | * \param file Pointer to file handle from which to read. 111 | * \return 0 on success. 112 | */ 113 | int fat_file_sync(FatFile *h); 114 | 115 | /** \brief Read from an open file. 116 | * \param file Pointer to file handle from which to read. 117 | * \param buf Buffer into which to read. 118 | * \param size Number of bytes to read. 119 | * \return Number of bytes read on success, negative on error. 120 | */ 121 | int __attribute__((warn_unused_result)) 122 | fat_read(FatFile *file, void *buf, int size); 123 | 124 | /** \brief Write to an open file. 125 | * \param file Pointer to file handle into which to write. 126 | * \param buf Buffer from which to write. 127 | * \param size Number of bytes to write. 128 | * \return Number of bytes written on success, negative on error. 129 | */ 130 | int __attribute__((warn_unused_result)) 131 | fat_write(FatFile *file, const void *buf, int size); 132 | 133 | /** \brief Sets the position in an open file. 134 | * \param file Pointer to file handle to change. 135 | * \param offset Offset into target file. 136 | * \param whence One of SEEK_SET, SEEK_CUR, SEEK_END. See Unix documentation. 137 | * \return New file position on success, negative on error. 138 | */ 139 | off_t fat_lseek(FatFile *file, off_t offset, int whence); 140 | 141 | /** \brief Unlink/delete a file. 142 | * \param vol Pointer to FAT volume handle. 143 | * \param name Name of file in current directory to unlink. 144 | * \return 0 on success. 145 | */ 146 | int fat_unlink(FatVol *vol, const char *name); 147 | 148 | #define FAT_ATTR_READ_ONLY 0x01 149 | #define FAT_ATTR_HIDDEN 0x02 150 | #define FAT_ATTR_SYSTEM 0x04 151 | #define FAT_ATTR_VOLUME_ID 0x08 152 | #define FAT_ATTR_DIRECTORY 0x10 153 | #define FAT_ATTR_ARCHIVE 0x20 154 | #define FAT_ATTR_LONG_NAME 0x0F 155 | 156 | /** \brief Public directory entry structure, returned by fat_readdir() */ 157 | struct dirent { 158 | char d_name[256]; /**< Long file name, POSIX standard. */ 159 | /* Non-standard */ 160 | uint8_t fat_attr; /**< FAT file attributes, non-standard */ 161 | char fat_sname[11]; /**< DOS short filename, non-standard */ 162 | }; 163 | 164 | /** \brief Read a directory entry. 165 | * The dirent structure is filled in with the details of the next file in 166 | * the directory stream pointed to by dir. 167 | * \param dir Pointer to file handle for the directory to be read. 168 | * \param ent Pointer to dirent structure for the read entry. 169 | * \return 0 on success. 170 | */ 171 | int fat_readdir(FatFile *dir, struct dirent *ent); 172 | 173 | 174 | /* Everything below is private. Applications should not direcly access 175 | * anything here. 176 | */ 177 | 178 | struct fat_file_handle { 179 | struct fat_vol_handle *fat; 180 | /* Fields from dir entry */ 181 | uint32_t size; 182 | uint32_t first_cluster; 183 | /* Internal state information */ 184 | uint32_t position; 185 | uint32_t cur_cluster; /* This is used for sector on FAT12/16 root */ 186 | uint8_t root_flag; /* Flag to mark root directory on FAT12/16 */ 187 | int flags; 188 | /* Reference to dirent */ 189 | uint32_t dirent_sector; 190 | uint16_t dirent_offset; 191 | }; 192 | 193 | struct fat_vol_handle { 194 | const struct block_device *dev; 195 | /* FAT type: 12, 16 or 32 */ 196 | int type; 197 | /* Useful fields from BPB */ 198 | uint16_t bytes_per_sector; 199 | uint8_t sectors_per_cluster; 200 | uint16_t reserved_sector_count; 201 | uint8_t num_fats; 202 | /* Fields calcuated from BPB */ 203 | uint32_t first_data_sector; 204 | uint32_t cluster_count; 205 | uint32_t fat_size; 206 | union { 207 | struct { 208 | uint32_t root_cluster; 209 | } fat32; 210 | struct { 211 | uint16_t root_sector_count; 212 | uint16_t root_first_sector; 213 | } fat12_16; 214 | }; 215 | /* Internal state */ 216 | uint32_t last_cluster_alloc; 217 | struct fat_file_handle cwd; 218 | }; 219 | 220 | #endif 221 | -------------------------------------------------------------------------------- /include/openfat/blockdev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /** \file blockdev.h 22 | * \brief Block device abstraction. 23 | * Must be implemented by application for a physical device. 24 | */ 25 | 26 | #ifndef __BLOCKDEV_H 27 | #define __BLOCKDEV_H 28 | 29 | #include 30 | 31 | /** \brief Structure representing an abstract block device. 32 | * This abstraction must be provided by the application. 33 | */ 34 | struct block_device { 35 | /* Info about the device */ 36 | /** \brief Method to get sector size. */ 37 | uint16_t (*get_sector_size)(const struct block_device *dev); 38 | /* ... more to be added as needed ... */ 39 | 40 | /* Actions on the device */ 41 | /** \brief Method to read sectors. */ 42 | int (*read_sectors)(const struct block_device *dev, 43 | uint32_t sector, uint32_t count, void *buf); 44 | /** \brief Method to write sectors. */ 45 | int (*write_sectors)(const struct block_device *dev, 46 | uint32_t sector, uint32_t count, const void *buf); 47 | /* ... more to be added as needed ... */ 48 | 49 | /* May be private fields here ... */ 50 | }; 51 | 52 | /* Convenient wrapper functions */ 53 | static inline uint16_t 54 | block_get_sector_size(const struct block_device *dev) 55 | { 56 | return dev->get_sector_size(dev); 57 | } 58 | 59 | /* Returns the number of sectors read or negative on error */ 60 | static inline int __attribute__((warn_unused_result)) 61 | block_read_sectors(const struct block_device *dev, 62 | uint32_t sector, uint32_t count, void *buf) 63 | { 64 | return dev->read_sectors(dev, sector, count, buf); 65 | } 66 | 67 | /* Returns the number of sectors written or negative on error */ 68 | static inline int __attribute__((warn_unused_result)) 69 | block_write_sectors(const struct block_device *dev, 70 | uint32_t sector, uint32_t count, const void *buf) 71 | { 72 | return dev->write_sectors(dev, sector, count, buf); 73 | } 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /include/openfat/leaccess.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* Macros for structure access. Host system may be little or big endian, 22 | * and may not be capable of misaligned access. Always use these for 23 | * access to the on-disk FAT structures. 24 | */ 25 | 26 | #ifndef __LEACCESS_H 27 | #define __LEACCESS_H 28 | 29 | #include 30 | 31 | static inline uint16_t __get_le16(const uint16_t *p) 32 | { 33 | return *(uint8_t *)p + (*((uint8_t *)p + 1) << 8); 34 | } 35 | 36 | static inline void __put_le16(uint16_t *p, uint16_t v) 37 | { 38 | *(uint8_t *)p = v & 0xff; 39 | *((uint8_t *)p + 1) = v >> 8; 40 | } 41 | 42 | static inline uint32_t __get_le32(const uint32_t *p) 43 | { 44 | return __get_le16((uint16_t *)p) + 45 | (uint32_t)(__get_le16((const uint16_t *)p + 1) << 16); 46 | } 47 | 48 | static inline void __put_le32(uint32_t *p, uint32_t v) 49 | { 50 | __put_le16((uint16_t *)p, v & 0xffff); 51 | __put_le16((uint16_t *)p + 1, v >> 16); 52 | } 53 | 54 | #ifdef __TEST__ 55 | #include 56 | #include 57 | int main(void) 58 | { 59 | const char testdata[] = "\x01\x23\x45\x67"; 60 | printf("%08X\n", __get_le32((uint32_t *)testdata)); 61 | assert(__get_le32((uint32_t *)testdata) == 0x67452301); 62 | return 0; 63 | } 64 | #endif 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /include/openfat/mbr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /** \file mbr.h 22 | * \brief PC Disk Partition Table implementation. 23 | * This module provides interpretation of the PC Master Boot Record 24 | * partition table, and provides a block device implementation for 25 | * partitions given an implementation for the whole disk using wrapper 26 | * functions. 27 | */ 28 | 29 | #ifndef __MBR_H 30 | #define __MBR_H 31 | 32 | #include 33 | 34 | #include "blockdev.h" 35 | 36 | struct mbr_partition { 37 | uint8_t bootable; 38 | uint8_t first_chs[3]; 39 | uint8_t type; 40 | uint8_t last_chs[3]; 41 | uint32_t first_lba; 42 | uint32_t sector_count; 43 | } __attribute__((packed)); 44 | 45 | /** \brief Structure representing block device for a PC disk partition. 46 | * Don't access directly. No public fields. */ 47 | struct block_mbr_partition { 48 | struct block_device bldev; 49 | struct block_device *whole; 50 | uint32_t first_lba; 51 | uint32_t sector_count; 52 | }; 53 | 54 | /** \brief Initialise a partition block device. 55 | * \param part Pointer to partition block device to initialize. 56 | * \param whole Pointer to block device for whole media. 57 | * \param part_index Partition index (0-3). 58 | * \return 0 on success. 59 | */ 60 | int mbr_partition_init(struct block_mbr_partition *part, 61 | struct block_device *whole, uint8_t part_index); 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /include/openfat/unixlike.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* 22 | * Unix-like API for FAT filesystem access. 23 | */ 24 | 25 | #ifndef __UNIXLIKE_H 26 | #define __UNIXLIKE_H 27 | 28 | #include 29 | 30 | #include 31 | 32 | FatVol * ufat_mount(struct block_device *dev); 33 | static inline void ufat_umount(FatVol *vol) { free(vol); } 34 | 35 | FatFile * ufat_open(FatVol *vol, const char *path, int flags); 36 | static inline void ufat_close(FatFile *file) { free(file); } 37 | 38 | int ufat_stat(FatFile *file, struct stat *stat); 39 | 40 | #define ufat_read fat_read 41 | #define ufat_write fat_write 42 | 43 | #define ufat_chdir fat_chdir 44 | #define ufat_mkdir fat_mkdir 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = libopenfat.a 2 | 3 | DESTDIR ?= /usr/local 4 | INCDIR = $(DESTDIR)/$(PREFIX)/include 5 | LIBDIR = $(DESTDIR)/$(PREFIX)/lib 6 | INSTALL = install 7 | 8 | CC = $(PREFIX)-gcc 9 | AR = $(PREFIX)-ar 10 | 11 | CFLAGS += -g3 -MD -Wall -Wextra -std=gnu99 -I../include \ 12 | -Wno-char-subscripts -Werror 13 | 14 | SRC = fat_core.c direntry.c mbr.c write.c unixlike.c 15 | 16 | OBJ = $(SRC:.c=.o) 17 | 18 | $(TARGET): $(OBJ) 19 | $(AR) crv $@ $^ 20 | 21 | .PHONY: clean install 22 | 23 | clean: 24 | -rm -rf *.o *.d $(TARGET) 25 | 26 | install: $(TARGET) 27 | $(INSTALL) -d $(INCDIR) 28 | $(INSTALL) -d $(INCDIR)/openfat 29 | $(INSTALL) -d $(LIBDIR) 30 | $(INSTALL) -m 0644 $(TARGET) $(LIBDIR) 31 | $(INSTALL) -m 0644 ../include/openfat.h $(INCDIR) 32 | $(INSTALL) -m 0644 ../include/openfat/* $(INCDIR)/openfat 33 | 34 | -include *.d 35 | 36 | -------------------------------------------------------------------------------- /src/bpb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* Boot Sector / BIOS Parameter Block definitions. 22 | * Convenience functions for calculations. 23 | */ 24 | 25 | #ifndef __BPB_H 26 | #define __BPB_H 27 | 28 | #include 29 | #include "openfat/leaccess.h" 30 | 31 | /* Boot sector fields common to FAT12/FAT16/FAT32 */ 32 | struct bpb_common { 33 | uint8_t boot_jmp[3]; 34 | char oem_name[8]; 35 | uint16_t bytes_per_sector; 36 | uint8_t sectors_per_cluster; 37 | uint16_t reserved_sector_count; 38 | uint8_t num_fats; 39 | uint16_t root_entry_count; 40 | uint16_t total_sectors_16; 41 | uint8_t media; 42 | uint16_t fat_size_16; 43 | uint16_t sectors_per_track; 44 | uint16_t num_heads; 45 | uint32_t hidden_sectors; 46 | uint32_t total_sectors_32; 47 | } __attribute__((packed)); 48 | 49 | /* Boot sector fields only in FAT12/FAT16 */ 50 | struct bpb_fat12_16 { 51 | struct bpb_common common; 52 | uint8_t drive_num; 53 | uint8_t Reserved1; 54 | uint8_t boot_sig; 55 | uint32_t volume_id; 56 | char volume_label[11]; 57 | char fs_type[8]; 58 | } __attribute__((packed)); 59 | 60 | /* Boot sector fields only in FAT32 */ 61 | struct bpb_fat32 { 62 | struct bpb_common common; 63 | uint32_t fat_size_32; 64 | uint16_t ext_flags; 65 | uint16_t fs_version; 66 | uint32_t root_cluster; 67 | uint16_t fs_info; 68 | uint16_t bk_boot_sec; 69 | uint8_t Reserved[12]; 70 | uint8_t drive_num; 71 | uint8_t Reserved1; 72 | uint8_t boot_sig; 73 | uint32_t volume_id; 74 | char volume_label[11]; 75 | char fs_type[8]; 76 | } __attribute__((packed)); 77 | 78 | 79 | static inline uint32_t 80 | _bpb_root_dir_sectors(struct bpb_common *bpb) 81 | { 82 | return ((__get_le16(&bpb->root_entry_count) * 32) + 83 | (__get_le16(&bpb->bytes_per_sector) - 1)) / 84 | __get_le16(&bpb->bytes_per_sector); 85 | } 86 | 87 | static inline uint32_t 88 | _bpb_fat_size(struct bpb_common *bpb) 89 | { 90 | uint32_t fat_size = __get_le16(&bpb->fat_size_16); 91 | if(fat_size == 0) 92 | fat_size = __get_le32(&((struct bpb_fat32 *)bpb)->fat_size_32); 93 | 94 | return fat_size; 95 | } 96 | 97 | static inline uint32_t 98 | _bpb_first_data_sector(struct bpb_common *bpb) 99 | { 100 | return __get_le16(&bpb->reserved_sector_count) + 101 | (bpb->num_fats * _bpb_fat_size(bpb)) 102 | + _bpb_root_dir_sectors(bpb); 103 | } 104 | 105 | static inline uint32_t 106 | _bpb_first_sector_of_cluster(struct bpb_common *bpb, uint32_t n) 107 | { 108 | return ((n - 2) * bpb->sectors_per_cluster) + 109 | _bpb_first_data_sector(bpb); 110 | } 111 | 112 | enum fat_type { 113 | FAT_TYPE_FAT12 = 12, 114 | FAT_TYPE_FAT16 = 16, 115 | FAT_TYPE_FAT32 = 32, 116 | }; 117 | 118 | static inline uint32_t _bpb_cluster_count(struct bpb_common *bpb) 119 | { 120 | uint32_t tot_sec = __get_le16(&bpb->total_sectors_16); 121 | if(tot_sec == 0) 122 | tot_sec = __get_le32(&bpb->total_sectors_32); 123 | 124 | uint32_t data_sec = tot_sec - 125 | __get_le16(&bpb->reserved_sector_count) - 126 | (bpb->num_fats * _bpb_fat_size(bpb)) - 127 | _bpb_root_dir_sectors(bpb); 128 | 129 | return data_sec / bpb->sectors_per_cluster; 130 | } 131 | 132 | /* FAT type is determined by count of clusters */ 133 | static inline enum fat_type 134 | fat_type(struct bpb_common *bpb) 135 | { 136 | uint32_t cluster_count = _bpb_cluster_count(bpb); 137 | if(cluster_count < 4085) { 138 | return FAT_TYPE_FAT12; 139 | } else if(cluster_count < 65525) { 140 | return FAT_TYPE_FAT16; 141 | } 142 | return FAT_TYPE_FAT32; 143 | } 144 | 145 | #endif 146 | 147 | -------------------------------------------------------------------------------- /src/direntry.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* FAT Directory . 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "openfat.h" 31 | 32 | #include "openfat/leaccess.h" 33 | #include "openfat/blockdev.h" 34 | #include "fat_core.h" 35 | #include "direntry.h" 36 | 37 | #define LONG_NAME_SUPPORT 38 | 39 | #ifdef LONG_NAME_SUPPORT 40 | uint8_t _fat_dirent_chksum(uint8_t *dosname) 41 | { 42 | uint8_t sum = 0; 43 | int i; 44 | 45 | for (i = 0; i < 11; i++) 46 | sum = ((sum & 1) ? 0x80 : 0) + (sum >> 1) + *dosname++; 47 | 48 | return sum; 49 | } 50 | 51 | /* Used to convert W95 UTF-16 filenames to ascii. 52 | * 0 means terminating null reached. 53 | * 1 means converted to end on input. 54 | * 2 means conversion error. 55 | */ 56 | static int ascii_from_utf16(char *ascii, const uint16_t *utf16, int count) 57 | { 58 | uint16_t tmp; 59 | while(count--) { 60 | tmp = __get_le16(utf16++); 61 | if(tmp > 127) 62 | return 2; 63 | *ascii++ = tmp; 64 | if(tmp == 0) 65 | return 0; 66 | } 67 | return 1; 68 | } 69 | #endif 70 | 71 | int fat_readdir(struct fat_file_handle *h, struct dirent *ent) 72 | { 73 | #ifdef LONG_NAME_SUPPORT 74 | uint16_t csum = -1; 75 | #endif 76 | struct fat_sdirent fatent; 77 | int i, j; 78 | 79 | while(fat_read(h, &fatent, sizeof(fatent)) == sizeof(fatent)) { 80 | 81 | if(fatent.name[0] == 0) 82 | return -1; /* Empty entry, end of directory */ 83 | if(fatent.name[0] == (char)0xe5) 84 | continue; /* Deleted entry */ 85 | if(fatent.attr == FAT_ATTR_VOLUME_ID) 86 | continue; /* Ignore volume id entry */ 87 | if(fatent.attr == FAT_ATTR_LONG_NAME) { 88 | #ifdef LONG_NAME_SUPPORT 89 | struct fat_ldirent *ld = (void*)&fatent; 90 | if(ld->ord & FAT_LAST_LONG_ENTRY) { 91 | memset(ent->d_name, 0, sizeof(ent->d_name)); 92 | csum = ld->checksum; 93 | } 94 | if(csum != ld->checksum) /* Abandon orphaned entry */ 95 | csum = -1; 96 | 97 | i = ((ld->ord & 0x3f) - 1) * 13; 98 | 99 | /* If entries can't be converted to ASCII, abandon 100 | * the long filename. DOS 8.3 name will be returned. 101 | * Not pretty... */ 102 | switch(ascii_from_utf16(&ent->d_name[i], ld->name1, 5)) 103 | { case 0: continue; case 2: csum = -1; } 104 | switch(ascii_from_utf16(&ent->d_name[i+5], ld->name2, 6)) 105 | { case 0: continue; case 2: csum = -1; } 106 | switch(ascii_from_utf16(&ent->d_name[i+11], ld->name3, 2)) 107 | { case 0: continue; case 2: csum = -1; } 108 | #endif 109 | continue; 110 | } 111 | #ifdef LONG_NAME_SUPPORT 112 | if(csum != _fat_dirent_chksum((uint8_t*)fatent.name)) 113 | ent->d_name[0] = 0; 114 | 115 | if(ent->d_name[0] == 0) { 116 | #endif 117 | for(i = 0, j = 0; i < 11; i++, j++) { 118 | ent->d_name[j] = tolower(fatent.name[i]); 119 | if(fatent.name[i] == ' ') { 120 | ent->d_name[j] = '.'; 121 | while((fatent.name[++i] == ' ') && (i < 11)); 122 | } 123 | } 124 | if(ent->d_name[j-1] == '.') 125 | ent->d_name[j-1] = 0; 126 | 127 | ent->d_name[j] = 0; 128 | #ifdef LONG_NAME_SUPPORT 129 | } 130 | #endif 131 | /* Non-standard */ 132 | ent->fat_attr = fatent.attr; 133 | memcpy(ent->fat_sname, fatent.name, 11); 134 | 135 | return 0; 136 | } 137 | return -1; 138 | } 139 | 140 | /* Seek to a place in the directory suitable for writing 'entries' new 141 | * directory entries. Called when creating files. */ 142 | int _fat_dir_seek_empty(struct fat_file_handle *dir, int entries) 143 | { 144 | uint32_t pos = 0; 145 | struct fat_sdirent ent; 146 | int i = 0; 147 | 148 | fat_lseek(dir, 0, SEEK_SET); 149 | 150 | while(fat_read(dir, &ent, sizeof(ent)) == sizeof(ent)) { 151 | if(ent.name[0] == 0) /* Empty entry, end of directory */ 152 | break; 153 | if(ent.name[0] == (char)0xe5) { /* Deleted entry */ 154 | i++; 155 | if(i == entries) 156 | break; 157 | continue; 158 | } 159 | i = 0; 160 | pos = dir->position; 161 | } 162 | 163 | fat_lseek(dir, pos, SEEK_SET); 164 | return 0; 165 | } 166 | 167 | static int fat_comparesfn(const char * name, const char *fatname) 168 | { 169 | char canonname[11]; 170 | int i; 171 | 172 | memset(canonname, ' ', sizeof(canonname)); 173 | if(name[0] == '.') { 174 | /* Special case: 175 | * Only legal names are '.' and '..' */ 176 | memcpy(canonname, name, strlen(name)); 177 | name += strlen(name); 178 | } else for(i = 0; (i < 11) && *name && (*name != '/'); i++) { 179 | if(*name == '.') { 180 | if(i < 8) continue; 181 | if(i == 8) name++; 182 | } 183 | canonname[i] = toupper(*name++); 184 | } 185 | return ((*name == 0) || (*name == '/')) && !memcmp(canonname, fatname, 11); 186 | } 187 | 188 | int fat_open(struct fat_vol_handle *vol, const char *name, int flags, 189 | struct fat_file_handle *file) 190 | { 191 | struct fat_file_handle *dir = (struct fat_file_handle*)&vol->cwd; 192 | struct dirent dirent; 193 | 194 | /* FIXME: Implement flags O_RDONLY, O_WRONLY, O_RDWR. */ 195 | 196 | if(strcmp(name, ".") == 0) { 197 | /* Special case needed for root dir with no '.' entry */ 198 | memcpy(file, &vol->cwd, sizeof(*file)); 199 | return 0; 200 | } 201 | 202 | fat_lseek(dir, 0, SEEK_SET); 203 | while(fat_readdir(dir, &dirent) == 0) { 204 | 205 | /* Check for name match */ 206 | if((strcmp(name, dirent.d_name) == 0) || 207 | fat_comparesfn(name, dirent.fat_sname)) { 208 | /* reread on-disk directory entry */ 209 | struct fat_sdirent fatent; 210 | uint32_t sector; 211 | uint16_t offset; 212 | /* Rewind directory one entry */ 213 | fat_lseek(dir, -sizeof(fatent), SEEK_CUR); 214 | _fat_file_sector_offset(dir, §or, &offset); 215 | if(fat_read(dir, &fatent, sizeof(fatent)) != 32) 216 | return -EIO; 217 | 218 | _fat_file_init(dir->fat, &fatent, file); 219 | file->flags = flags; 220 | if(!(fatent.attr & FAT_ATTR_DIRECTORY)) { 221 | file->dirent_sector = sector; 222 | file->dirent_offset = offset; 223 | } else if(!file->first_cluster) { 224 | /* Check for special case of root dir */ 225 | _fat_file_root(dir->fat, file); 226 | } 227 | return 0; 228 | } 229 | } 230 | return -ENOENT; 231 | } 232 | 233 | int fat_chdir(struct fat_vol_handle *vol, const char *name) 234 | { 235 | return fat_open(vol, name, 0, &vol->cwd); 236 | } 237 | 238 | -------------------------------------------------------------------------------- /src/direntry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* FAT Directory entry definitions. 22 | */ 23 | #ifndef __DIRENTRY_H 24 | #define __DIRENTRY_H 25 | 26 | #include 27 | 28 | struct fat_sdirent { 29 | char name[11]; /* DOS file name 8.3 */ 30 | uint8_t attr; 31 | uint8_t Reserved; 32 | uint8_t create_time_fine; 33 | uint16_t create_time; 34 | uint16_t create_date; 35 | uint16_t access_date; 36 | uint16_t cluster_hi; 37 | uint16_t write_time; 38 | uint16_t write_date; 39 | uint16_t cluster_lo; 40 | uint32_t size; 41 | } __attribute__((packed)); 42 | 43 | 44 | #define FAT_LAST_LONG_ENTRY 0x40 45 | 46 | /* W95 long file name entries. Characters are in UTF-16. */ 47 | struct fat_ldirent { 48 | uint8_t ord; 49 | uint16_t name1[5]; 50 | uint8_t attr; 51 | uint8_t type; 52 | uint8_t checksum; 53 | uint16_t name2[6]; 54 | uint16_t cluster_lo; 55 | uint16_t name3[2]; 56 | } __attribute__((packed)); 57 | 58 | uint8_t _fat_dirent_chksum(uint8_t *dosname); 59 | int _fat_dir_seek_empty(struct fat_file_handle *dir, int entries); 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /src/fat_core.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* FAT Filesystem core implementation 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "openfat.h" 30 | 31 | #include "openfat/blockdev.h" 32 | #include "openfat/leaccess.h" 33 | #include "bpb.h" 34 | #include "fat_core.h" 35 | 36 | /* Build time configuration */ 37 | #define MAX_SECTOR_SIZE 512 38 | 39 | uint8_t _fat_sector_buf[MAX_SECTOR_SIZE]; 40 | struct _fat_cache _fat_cache; 41 | 42 | int fat_vol_init(const struct block_device *dev, struct fat_vol_handle *h) 43 | { 44 | struct bpb_common *bpb = (void *)&_fat_sector_buf; 45 | 46 | memset(h, 0, sizeof(*h)); 47 | h->dev = dev; 48 | 49 | FAT_GET_SECTOR(h, 0); 50 | 51 | h->type = fat_type(bpb); 52 | h->cluster_count = _bpb_cluster_count(bpb); 53 | h->bytes_per_sector = __get_le16(&bpb->bytes_per_sector); 54 | h->sectors_per_cluster = bpb->sectors_per_cluster; 55 | h->first_data_sector = _bpb_first_data_sector(bpb); 56 | h->reserved_sector_count = __get_le16(&bpb->reserved_sector_count); 57 | h->num_fats = bpb->num_fats; 58 | h->fat_size = _bpb_fat_size(bpb); 59 | h->last_cluster_alloc = 2; 60 | if(h->type == FAT_TYPE_FAT32) { 61 | struct bpb_fat32 *bpb32 = (void *)&_fat_sector_buf; 62 | h->fat32.root_cluster = __get_le32(&bpb32->root_cluster); 63 | } else { 64 | h->fat12_16.root_sector_count = _bpb_root_dir_sectors(bpb); 65 | h->fat12_16.root_first_sector = _bpb_first_data_sector(bpb) - 66 | h->fat12_16.root_sector_count; 67 | } 68 | _fat_file_root(h, &h->cwd); 69 | 70 | return 0; 71 | } 72 | 73 | uint32_t _fat_get_next_cluster(const struct fat_vol_handle *h, uint32_t cluster) 74 | { 75 | uint32_t offset; 76 | uint32_t sector; 77 | 78 | if(h->type == FAT_TYPE_FAT12) 79 | offset = cluster + (cluster / 2); 80 | else if(h->type == FAT_TYPE_FAT16) 81 | offset = cluster * 2; 82 | else if(h->type == FAT_TYPE_FAT32) 83 | offset = cluster * 4; 84 | 85 | sector = h->reserved_sector_count + (offset / h->bytes_per_sector); 86 | offset %= h->bytes_per_sector; 87 | 88 | FAT_GET_SECTOR(h, sector); 89 | 90 | if(h->type == FAT_TYPE_FAT12) { 91 | uint32_t next; 92 | if(offset == (uint32_t)h->bytes_per_sector - 1) { 93 | /* Fat entry is over sector boundary */ 94 | next = _fat_sector_buf[offset]; 95 | FAT_GET_SECTOR(h, sector + 1); 96 | next += _fat_sector_buf[0] << 8; 97 | } else { 98 | next = __get_le16((uint16_t*)(_fat_sector_buf + offset)); 99 | } 100 | if(cluster & 1) 101 | return next >> 4; 102 | else 103 | return next & 0xFFF; 104 | } else if(h->type == FAT_TYPE_FAT16) { 105 | return __get_le16((uint16_t*)(_fat_sector_buf + offset)); 106 | } else if(h->type == FAT_TYPE_FAT32) { 107 | return __get_le32((uint32_t*)(_fat_sector_buf + offset)) & 0x0FFFFFFF; 108 | } 109 | /* We shouldn't get here... */ 110 | return 0; 111 | } 112 | 113 | void _fat_file_root(struct fat_vol_handle *fat, 114 | struct fat_file_handle *h) 115 | { 116 | memset(h, 0, sizeof(*h)); 117 | h->fat = fat; 118 | 119 | if(fat->type == FAT_TYPE_FAT32) { 120 | h->first_cluster = fat->fat32.root_cluster; 121 | } else { 122 | /* FAT12/FAT16 root directory */ 123 | h->root_flag = 1; 124 | h->first_cluster = fat->fat12_16.root_first_sector; 125 | h->size = h->fat->fat12_16.root_sector_count * h->fat->bytes_per_sector; 126 | } 127 | h->cur_cluster = h->first_cluster; 128 | } 129 | 130 | void _fat_file_init(struct fat_vol_handle *fat, 131 | const struct fat_sdirent *dirent, 132 | struct fat_file_handle *h) 133 | { 134 | memset(h, 0, sizeof(*h)); 135 | h->fat = fat; 136 | h->first_cluster = ((uint32_t)__get_le16(&dirent->cluster_hi) << 16) | 137 | __get_le16(&dirent->cluster_lo); 138 | h->size = __get_le32(&dirent->size); 139 | h->cur_cluster = h->first_cluster; 140 | } 141 | 142 | off_t fat_lseek(struct fat_file_handle *h, off_t offset, int whence) 143 | { 144 | h->cur_cluster = h->first_cluster; 145 | 146 | switch(whence) { 147 | case SEEK_SET: 148 | break; 149 | case SEEK_CUR: 150 | offset += h->position; 151 | break; 152 | case SEEK_END: 153 | offset += h->size; 154 | break; 155 | default: 156 | return -1; 157 | } 158 | 159 | if(h->size && ((uint32_t)offset > h->size)) 160 | offset = h->size; 161 | 162 | h->position = offset; 163 | 164 | if(h->root_flag) { /* FAT12/16 root dir isn't a cluster chain */ 165 | return h->position; 166 | } 167 | 168 | /* Iterate over cluster chain to find cluster */ 169 | while(offset >= (h->fat->sectors_per_cluster * h->fat->bytes_per_sector)) { 170 | h->cur_cluster = _fat_get_next_cluster(h->fat, h->cur_cluster); 171 | offset -= h->fat->sectors_per_cluster * h->fat->bytes_per_sector; 172 | } 173 | 174 | return h->position; 175 | } 176 | 177 | void _fat_file_sector_offset(struct fat_file_handle *h, uint32_t *sector, 178 | uint16_t *offset) 179 | { 180 | if(h->root_flag) { 181 | /* FAT12/FAT16 root directory */ 182 | *sector = h->cur_cluster + 183 | (h->position / h->fat->bytes_per_sector); 184 | } else { 185 | *sector = fat_first_sector_of_cluster(h->fat, h->cur_cluster); 186 | *sector += (h->position / h->fat->bytes_per_sector) % 187 | h->fat->sectors_per_cluster; 188 | } 189 | *offset = h->position % h->fat->bytes_per_sector; 190 | } 191 | 192 | #define MIN(x, y) (((x) < (y))?(x):(y)) 193 | int fat_read(struct fat_file_handle *h, void *buf, int size) 194 | { 195 | int i; 196 | uint32_t sector; 197 | uint16_t offset; 198 | 199 | _fat_file_sector_offset(h, §or, &offset); 200 | 201 | /* Don't read past end of file */ 202 | if(h->size && ((h->position + size) > h->size)) 203 | size = h->size - h->position; 204 | 205 | for(i = 0; i < size; ) { 206 | uint16_t chunk = MIN(h->fat->bytes_per_sector - offset, size - i); 207 | FAT_GET_SECTOR(h->fat, sector); 208 | memcpy(buf + i, _fat_sector_buf + offset, chunk); 209 | h->position += chunk; 210 | i += chunk; 211 | if((h->position % h->fat->bytes_per_sector) != 0) 212 | /* we didn't read until the end of the sector... */ 213 | break; 214 | offset = 0; 215 | sector++; 216 | if(h->root_flag) /* FAT12/16 isn't a cluster chain */ 217 | continue; 218 | if((sector % h->fat->sectors_per_cluster) == 0) { 219 | /* Go to next cluster... */ 220 | h->cur_cluster = _fat_get_next_cluster(h->fat, 221 | h->cur_cluster); 222 | if(h->cur_cluster == fat_eoc(h->fat)) 223 | return i; 224 | sector = fat_first_sector_of_cluster(h->fat, 225 | h->cur_cluster); 226 | } 227 | } 228 | 229 | return i; 230 | } 231 | 232 | -------------------------------------------------------------------------------- /src/fat_core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* FAT Filesystem core implementation, private interface 22 | */ 23 | #ifndef __FAT_CORE_H 24 | #define __FAT_CORE_H 25 | 26 | #include "bpb.h" 27 | #include "direntry.h" 28 | 29 | extern uint8_t _fat_sector_buf[]; 30 | 31 | extern struct _fat_cache { 32 | /* Working sector buffer, use _fat_sector_buf by default. */ 33 | uint8_t *buf; 34 | 35 | /* Sector and block device for current contents of buf. */ 36 | const void *bldev; 37 | uint32_t sector; 38 | 39 | /* Non-zero if buffer is out-of-sync with the physical medium. */ 40 | uint8_t dirty; 41 | } _fat_cache; 42 | 43 | static inline uint32_t 44 | fat_eoc(const struct fat_vol_handle *fat) 45 | { 46 | switch (fat->type) { 47 | case FAT_TYPE_FAT12: 48 | return 0x0FF8; 49 | case FAT_TYPE_FAT16: 50 | return 0xFFF8; 51 | case FAT_TYPE_FAT32: 52 | return 0x0FFFFFF8; 53 | } 54 | return -1; 55 | } 56 | 57 | static inline uint32_t 58 | fat_first_sector_of_cluster(const struct fat_vol_handle *fat, uint32_t n) 59 | { 60 | return ((n - 2) * fat->sectors_per_cluster) + fat->first_data_sector; 61 | } 62 | 63 | uint32_t 64 | _fat_get_next_cluster(const struct fat_vol_handle *h, uint32_t cluster); 65 | 66 | void _fat_file_root(struct fat_vol_handle *fat, struct fat_file_handle *h); 67 | void _fat_file_init(struct fat_vol_handle *fat, const struct fat_sdirent *, 68 | struct fat_file_handle *h); 69 | 70 | void _fat_file_sector_offset(struct fat_file_handle *h, uint32_t *sector, 71 | uint16_t *offset); 72 | 73 | int _fat_dir_create_file(struct fat_vol_handle *vol, const char *name, 74 | uint8_t attr, struct fat_file_handle *file); 75 | 76 | #define FAT_FLUSH_SECTOR() do {\ 77 | if(_fat_cache.dirty) \ 78 | if(block_write_sectors(_fat_cache.bldev, _fat_cache.sector, \ 79 | 1, _fat_sector_buf) != 1) \ 80 | return -EIO; \ 81 | _fat_cache.dirty = 0; \ 82 | } while(0) 83 | 84 | #define FAT_GET_SECTOR(fat, sectorn) do {\ 85 | if((_fat_cache.bldev==(fat)->dev) && (_fat_cache.sector==(sectorn)))\ 86 | break; \ 87 | \ 88 | FAT_FLUSH_SECTOR(); \ 89 | \ 90 | _fat_cache.bldev = (fat)->dev; \ 91 | _fat_cache.sector = (sectorn); \ 92 | \ 93 | if(block_read_sectors((fat)->dev, (sectorn), 1, _fat_sector_buf) != 1)\ 94 | return -EIO; \ 95 | } while(0) 96 | 97 | #define FAT_PUT_SECTOR(fat, sectorn) do {\ 98 | if((_fat_cache.bldev!=(fat)->dev) || (_fat_cache.sector!=(sectorn)))\ 99 | FAT_FLUSH_SECTOR(); \ 100 | \ 101 | _fat_cache.bldev = (fat)->dev; \ 102 | _fat_cache.sector = (sectorn); \ 103 | _fat_cache.dirty = 1; \ 104 | } while(0) 105 | 106 | 107 | #endif 108 | 109 | -------------------------------------------------------------------------------- /src/mbr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* Master boot record. 22 | */ 23 | 24 | #include 25 | 26 | #include "openfat/leaccess.h" 27 | #include "openfat/blockdev.h" 28 | #include "openfat/mbr.h" 29 | 30 | /* In fat_core.c */ 31 | extern uint8_t _fat_sector_buf[]; 32 | 33 | static int mbr_read_sectors(const struct block_device *dev, 34 | uint32_t sector, uint32_t count, void *buf) 35 | { 36 | struct block_mbr_partition *part = (void*)dev; 37 | 38 | return block_read_sectors(part->whole, 39 | part->first_lba + sector, count, buf); 40 | } 41 | 42 | static int mbr_write_sectors(const struct block_device *dev, 43 | uint32_t sector, uint32_t count, const void *buf) 44 | { 45 | struct block_mbr_partition *part = (void*)dev; 46 | 47 | return block_write_sectors(part->whole, 48 | part->first_lba + sector, count, buf); 49 | } 50 | 51 | int mbr_partition_init(struct block_mbr_partition *part, 52 | struct block_device *whole, uint8_t part_index) 53 | { 54 | struct mbr_partition *part_table = (void*)&_fat_sector_buf[446]; 55 | /* Read MBR from whole device */ 56 | if(block_read_sectors(whole, 0, 1, _fat_sector_buf) != 1) 57 | return -1; 58 | 59 | part->whole = whole; 60 | 61 | part->first_lba = __get_le32(&part_table[part_index].first_lba); 62 | part->sector_count = __get_le32(&part_table[part_index].sector_count); 63 | 64 | part->bldev.get_sector_size = whole->get_sector_size; 65 | part->bldev.read_sectors = mbr_read_sectors; 66 | part->bldev.write_sectors = mbr_write_sectors; 67 | 68 | return 0; 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/unixlike.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "openfat.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "openfat/blockdev.h" 28 | #include "fat_core.h" 29 | #include "direntry.h" 30 | 31 | struct fat_vol_handle * 32 | ufat_mount(struct block_device *dev) 33 | { 34 | struct fat_vol_handle *vol = malloc(sizeof(*vol)); 35 | 36 | if(fat_vol_init(dev, vol)) { 37 | free(vol); 38 | return NULL; 39 | } 40 | 41 | return vol; 42 | } 43 | 44 | struct fat_file_handle * 45 | ufat_open(struct fat_vol_handle *fat, const char *path, int flags) 46 | { 47 | struct fat_file_handle oldcwd; 48 | 49 | if(!path || (path[0] == 0)) 50 | return NULL; 51 | 52 | struct fat_file_handle *h = malloc(sizeof(*h)); 53 | 54 | if(path[0] == '/') { 55 | _fat_file_root(fat, h); 56 | path++; 57 | } else { 58 | memcpy(h, &fat->cwd, sizeof(*h)); 59 | } 60 | 61 | memcpy(&oldcwd, &fat->cwd, sizeof(oldcwd)); 62 | while(path && *path) { 63 | memcpy(&fat->cwd, h, sizeof(*h)); 64 | if(fat_open(fat, path, flags, h)) { 65 | free(h); 66 | memcpy(&fat->cwd, &oldcwd, sizeof(oldcwd)); 67 | return NULL; 68 | } 69 | path = strchr(path, '/'); 70 | if(path) path++; 71 | }; 72 | 73 | memcpy(&fat->cwd, &oldcwd, sizeof(oldcwd)); 74 | 75 | return h; 76 | } 77 | 78 | int ufat_stat(struct fat_file_handle *h, struct stat *st) 79 | { 80 | struct fat_sdirent *fatent; 81 | 82 | memset(st, 0, sizeof(*st)); 83 | 84 | if(h->dirent_sector == 0) { 85 | /* Root directory */ 86 | st->st_mode = S_IFDIR; 87 | return 0; 88 | } 89 | 90 | /* Read direntry sector */ 91 | if(block_read_sectors(h->fat->dev, h->dirent_sector, 1, _fat_sector_buf) != 1) 92 | return -1; 93 | fatent = (void*)&_fat_sector_buf[h->dirent_offset]; 94 | 95 | /* TODO: Fill in timestamps */ 96 | 97 | if(fatent->attr & FAT_ATTR_DIRECTORY) { 98 | st->st_mode = S_IFDIR; 99 | } else { 100 | st->st_size = __get_le32(&fatent->size); 101 | } 102 | 103 | return 0; 104 | } 105 | 106 | -------------------------------------------------------------------------------- /src/write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* FAT Filesystem write support implementation 22 | */ 23 | #include 24 | #include 25 | #include 26 | 27 | #include "openfat.h" 28 | 29 | #include "fat_core.h" 30 | 31 | static uint32_t fat_find_free_cluster(struct fat_vol_handle *h) 32 | { 33 | uint32_t i; 34 | 35 | for(i = h->last_cluster_alloc; i < h->cluster_count; i++) { 36 | if(_fat_get_next_cluster(h, i) == 0) { 37 | h->last_cluster_alloc = i; 38 | return i; 39 | } 40 | } 41 | 42 | for(i = 2; i < h->last_cluster_alloc; i++) { 43 | if(_fat_get_next_cluster(h, i) == 0) { 44 | h->last_cluster_alloc = i; 45 | return i; 46 | } 47 | } 48 | 49 | return 0; /* No free clusters */ 50 | } 51 | 52 | static int 53 | fat32_set_next_cluster(const struct fat_vol_handle *h, uint8_t fat, 54 | uint32_t cluster, uint32_t next) 55 | { 56 | uint32_t offset = cluster * 4; 57 | uint32_t sector; 58 | 59 | sector = h->reserved_sector_count + (fat * h->fat_size) + 60 | (offset / h->bytes_per_sector); 61 | offset %= h->bytes_per_sector; 62 | 63 | FAT_GET_SECTOR(h, sector); 64 | 65 | /* Preserve high nybble */ 66 | next &= 0x0FFFFFFF; 67 | next |= __get_le32((uint32_t*)(_fat_sector_buf + offset)) & 0xF0000000; 68 | __put_le32((uint32_t*)(_fat_sector_buf + offset), next); 69 | 70 | FAT_PUT_SECTOR(h, sector); 71 | 72 | return 0; 73 | } 74 | 75 | static int 76 | fat16_set_next_cluster(const struct fat_vol_handle *h, uint8_t fat, 77 | uint16_t cluster, uint16_t next) 78 | { 79 | uint32_t offset = cluster * 2; 80 | uint32_t sector; 81 | 82 | sector = h->reserved_sector_count + (fat * h->fat_size) + 83 | (offset / h->bytes_per_sector); 84 | offset %= h->bytes_per_sector; 85 | 86 | FAT_GET_SECTOR(h, sector); 87 | __put_le16((uint16_t*)(_fat_sector_buf + offset), next); 88 | FAT_PUT_SECTOR(h, sector); 89 | 90 | return 0; 91 | } 92 | 93 | static int 94 | fat12_set_next_cluster(const struct fat_vol_handle *h, uint8_t fat, 95 | uint16_t cluster, uint16_t next) 96 | { 97 | uint32_t offset = cluster + (cluster / 2); 98 | uint32_t sector; 99 | sector = h->reserved_sector_count + (fat * h->fat_size) + 100 | (offset / h->bytes_per_sector); 101 | offset %= h->bytes_per_sector; 102 | 103 | FAT_GET_SECTOR(h, sector); 104 | if(offset == (uint32_t)h->bytes_per_sector - 1) { 105 | if(cluster & 1) { 106 | next <<= 4; 107 | _fat_sector_buf[offset] &= 0x0F; 108 | _fat_sector_buf[offset] |= next & 0xF0; 109 | FAT_PUT_SECTOR(h, sector); 110 | sector++; 111 | FAT_GET_SECTOR(h, sector); 112 | _fat_sector_buf[0] = next >> 8; 113 | } else { 114 | _fat_sector_buf[offset] = next & 0xFF; 115 | FAT_PUT_SECTOR(h, sector); 116 | sector++; 117 | FAT_GET_SECTOR(h, sector); 118 | _fat_sector_buf[0] &= 0xF0; 119 | _fat_sector_buf[0] |= (next >> 8) & 0x0F; 120 | } 121 | } else { 122 | if(cluster & 1) { 123 | next <<= 4; 124 | next |= __get_le16((uint16_t*)(_fat_sector_buf + offset)) & 0xF; 125 | } else { 126 | next &= 0x0FFF; 127 | next |= __get_le16((uint16_t*)(_fat_sector_buf + offset)) & 0xF000; 128 | } 129 | __put_le16((uint16_t*)(_fat_sector_buf + offset), next); 130 | } 131 | FAT_PUT_SECTOR(h, sector); 132 | 133 | return 0; 134 | } 135 | 136 | static int 137 | fat_set_next_cluster(const struct fat_vol_handle *h, 138 | uint32_t cluster, uint32_t next) 139 | { 140 | int ret = 0; 141 | for(int i = 0; i < h->num_fats; i++) { 142 | switch(h->type) { 143 | case FAT_TYPE_FAT12: 144 | ret |= fat12_set_next_cluster(h, i, cluster, next); 145 | break; 146 | case FAT_TYPE_FAT16: 147 | ret |= fat16_set_next_cluster(h, i, cluster, next); 148 | break; 149 | case FAT_TYPE_FAT32: 150 | ret |= fat32_set_next_cluster(h, i, cluster, next); 151 | break; 152 | } 153 | } 154 | return ret; 155 | } 156 | 157 | static int32_t fat_alloc_next_cluster(struct fat_vol_handle *h, 158 | uint32_t cluster, int clear) 159 | { 160 | /* Return next if already allocated */ 161 | uint32_t next = _fat_get_next_cluster(h, cluster); 162 | 163 | if(next != fat_eoc(h)) 164 | return next; 165 | 166 | /* Find free cluster to link to */ 167 | next = fat_find_free_cluster(h); 168 | 169 | if(!next) /* No more free clusters */ 170 | return 0; 171 | 172 | /* Write end of chain marker in new cluster */ 173 | fat_set_next_cluster(h, next, fat_eoc(h)); 174 | /* Add new cluster to chain */ 175 | fat_set_next_cluster(h, cluster, next); 176 | 177 | if(clear) { 178 | /* Zero new cluster */ 179 | uint32_t sector = fat_first_sector_of_cluster( 180 | h, next); 181 | FAT_FLUSH_SECTOR(); 182 | memset(_fat_sector_buf, 0, h->bytes_per_sector); 183 | for(int i = 0; i < h->sectors_per_cluster; i++) { 184 | /* How do we report failure here? 185 | * The cluster has already been allocated. 186 | */ 187 | int discard = block_write_sectors(h->dev, sector + i, 1, 188 | _fat_sector_buf); 189 | (void)discard; 190 | } 191 | } 192 | 193 | return next; 194 | } 195 | 196 | int fat_file_sync(struct fat_file_handle *h) 197 | { 198 | struct fat_sdirent *dirent; 199 | /* Update directory entry with new size */ 200 | FAT_GET_SECTOR(h->fat, h->dirent_sector); 201 | dirent = (void*)&_fat_sector_buf[h->dirent_offset]; 202 | __put_le32(&dirent->size, h->size); 203 | __put_le16(&dirent->cluster_hi, h->first_cluster >> 16); 204 | __put_le16(&dirent->cluster_lo, h->first_cluster & 0xFFFF); 205 | FAT_PUT_SECTOR(h->fat, h->dirent_sector); 206 | FAT_FLUSH_SECTOR(); 207 | return 0; 208 | } 209 | 210 | #define MIN(x, y) (((x) < (y))?(x):(y)) 211 | int fat_write(struct fat_file_handle *h, const void *buf, int size) 212 | { 213 | int i; 214 | uint32_t sector; 215 | uint16_t offset; 216 | 217 | if(!h->cur_cluster && size) { 218 | /* File was empty, allocate first cluster. */ 219 | h->first_cluster = fat_find_free_cluster(h->fat); 220 | if(!h->first_cluster) 221 | return 0; 222 | h->cur_cluster = h->first_cluster; 223 | /* Write end of chain marker in new cluster */ 224 | fat_set_next_cluster(h->fat, h->cur_cluster, fat_eoc(h->fat)); 225 | /* Directory entry will be updated with size after the 226 | * file write is done. 227 | */ 228 | } 229 | 230 | /* Don't write past end of FAT12/FAT16 root directory! */ 231 | if(h->root_flag && ((h->position + size) > h->size)) 232 | size = h->size - h->position; 233 | 234 | _fat_file_sector_offset(h, §or, &offset); 235 | 236 | for(i = 0; i < size; ) { 237 | uint16_t chunk = MIN(h->fat->bytes_per_sector - offset, 238 | size - i); 239 | if(chunk < h->fat->bytes_per_sector) 240 | FAT_GET_SECTOR(h->fat, sector); 241 | else 242 | FAT_FLUSH_SECTOR(); 243 | 244 | memcpy(_fat_sector_buf + offset, buf + i, chunk); 245 | FAT_PUT_SECTOR(h->fat, sector); 246 | h->position += chunk; 247 | i += chunk; 248 | if((h->position % h->fat->bytes_per_sector) != 0) 249 | /* we didn't write until the end of the sector... */ 250 | break; 251 | offset = 0; 252 | sector++; 253 | if(h->root_flag) /* FAT12/16 isn't a cluster chain */ 254 | continue; 255 | if((sector % h->fat->sectors_per_cluster) == 0) { 256 | /* Go to next cluster... */ 257 | uint32_t next_cluster = fat_alloc_next_cluster(h->fat, 258 | h->cur_cluster, h->size == 0); 259 | if(!next_cluster) 260 | break; 261 | h->cur_cluster = next_cluster; 262 | sector = fat_first_sector_of_cluster(h->fat, 263 | h->cur_cluster); 264 | } 265 | } 266 | 267 | if(h->dirent_sector && (h->position > h->size)) { 268 | /* Update directory entry with new size */ 269 | h->size = h->position; 270 | if(!(h->flags & O_ASYNC)) 271 | fat_file_sync(h); 272 | } 273 | 274 | return i; 275 | } 276 | 277 | static int fat_chain_unlink(const struct fat_vol_handle *vol, uint32_t cluster) 278 | { 279 | int ret = 0; 280 | while(cluster && (cluster != fat_eoc(vol))) { 281 | uint32_t next = _fat_get_next_cluster(vol, cluster); 282 | ret |= fat_set_next_cluster(vol, cluster, 0); 283 | cluster = next; 284 | } 285 | return ret; 286 | } 287 | 288 | int fat_unlink(struct fat_vol_handle *vol, const char *name) 289 | { 290 | struct fat_file_handle h; 291 | int ret; 292 | 293 | ret = fat_open(vol, name, 0, &h); 294 | if(ret) 295 | return ret; 296 | 297 | /* Don't try to unlink directories, use fat_rmdir() instead. */ 298 | if(!h.dirent_sector) 299 | return -EISDIR; 300 | 301 | /* Free up cluster chain */ 302 | fat_chain_unlink(vol, h.first_cluster); 303 | 304 | /* Mark directory entry as deleted */ 305 | FAT_GET_SECTOR(vol, h.dirent_sector); 306 | _fat_sector_buf[h.dirent_offset] = 0xE5; 307 | FAT_PUT_SECTOR(vol, h.dirent_sector); 308 | 309 | /* FIXME: Remove long name entries. */ 310 | 311 | return 0; 312 | } 313 | 314 | /* Build a short name for a long name. n is used if name is too long. */ 315 | static void build_short_name(uint8_t *sname, const char *name, int n) 316 | { 317 | int i, j; 318 | 319 | memset(sname, ' ', 11); 320 | for(i = 0; (i < 8) && name[i] && (name[i] != '.'); i++) 321 | sname[i] = toupper(name[i]); 322 | 323 | char *suffix = strrchr(name, '.'); 324 | if(suffix) for(j = 1; (j < 4) && suffix[j]; j++) 325 | sname[j+7] = toupper(suffix[j]); 326 | 327 | if(((i == 8) && (name[i] != '.')) || 328 | ((suffix - name) != i)) { 329 | if(i > 6) 330 | i = 6; 331 | sname[i] = '~'; 332 | sname[i+1] = '0' + (n % 10); 333 | } 334 | } 335 | 336 | /* Create a new zero-length file */ 337 | int _fat_dir_create_file(struct fat_vol_handle *vol, const char *name, 338 | uint8_t attr, struct fat_file_handle *file) 339 | { 340 | /* Check if file already exists */ 341 | if(!fat_open(vol, name, 0, file)) 342 | return -1; /* File exists */ 343 | 344 | /* Attempt to construct a short name for the file */ 345 | uint8_t sname[12]; 346 | sname[11] = 0; /* fat_open() needs terminating null */ 347 | for(int i = 1; i < 10; i++) { 348 | build_short_name(sname, name, i); 349 | if(fat_open(vol, (char*)sname, 0, file)) 350 | break; /* We have a winner */ 351 | sname[0] = ' '; 352 | } 353 | 354 | if(sname[0] == ' ') 355 | return -1; /* Couldn't find a short name */ 356 | 357 | /* Find usable space in parent directory */ 358 | _fat_dir_seek_empty(&vol->cwd, (strlen(name) / 13) + 2); 359 | 360 | /* Create long name directory entries */ 361 | struct fat_ldirent ld; 362 | int last = 1; 363 | memset(&ld, 0, sizeof(ld)); 364 | ld.attr = FAT_ATTR_LONG_NAME; 365 | for(int i = strlen(name) / 13; i >= 0; i--) { 366 | ld.ord = i + 1; 367 | if(last) { 368 | ld.ord |= FAT_LAST_LONG_ENTRY; 369 | last = 0; 370 | } 371 | int j; 372 | for(j = 0; j < 5; j++) 373 | __put_le16(&ld.name1[j], name[i*13 + j]); 374 | for(j = 0; j < 6; j++) 375 | __put_le16(&ld.name2[j], name[i*13 + j + 5]); 376 | for(j = 0; j < 2; j++) 377 | __put_le16(&ld.name3[j], name[i*13 + j + 11]); 378 | ld.checksum = _fat_dirent_chksum(sname); 379 | if(fat_write(&vol->cwd, &ld, sizeof(ld)) != sizeof(ld)) 380 | return -1; 381 | } 382 | 383 | /* Create short name entry */ 384 | struct fat_sdirent fatent; 385 | memset(&fatent, 0, sizeof(fatent)); 386 | fatent.attr = attr; 387 | memcpy(&fatent.name, sname, 11); 388 | /* TODO: Insert timestamp */ 389 | if(attr == FAT_ATTR_DIRECTORY) { 390 | /* Allocate a cluster for directories */ 391 | uint32_t cluster = fat_find_free_cluster(vol); 392 | if(!cluster) 393 | return -1; 394 | fat_set_next_cluster(vol, cluster, fat_eoc(vol)); 395 | __put_le16(&fatent.cluster_hi, cluster >> 16); 396 | __put_le16(&fatent.cluster_lo, cluster & 0xFFFF); 397 | } 398 | if(fat_write(&vol->cwd, &fatent, sizeof(fatent)) != sizeof(fatent)) 399 | return -1; 400 | 401 | return fat_open(vol, name, 0, file); 402 | } 403 | 404 | int fat_mkdir(struct fat_vol_handle *vol, const char *name) 405 | { 406 | int ret; 407 | struct fat_file_handle dir; 408 | struct fat_sdirent fatent; 409 | ret = _fat_dir_create_file(vol, name, FAT_ATTR_DIRECTORY, &dir); 410 | if(ret) 411 | return ret; 412 | 413 | FAT_FLUSH_SECTOR(); 414 | /* Clear out cluster */ 415 | memset(_fat_sector_buf, 0, vol->bytes_per_sector); 416 | uint32_t sector = fat_first_sector_of_cluster(vol, dir.first_cluster); 417 | for(int i = 0; i < vol->sectors_per_cluster; i++) 418 | FAT_PUT_SECTOR(vol, sector + i); 419 | 420 | memset(&fatent, 0, sizeof(fatent)); 421 | fatent.attr = FAT_ATTR_DIRECTORY; 422 | memset(fatent.name, ' ', 11); 423 | 424 | /* Create '.' entry */ 425 | fatent.name[0] = '.'; 426 | __put_le16(&fatent.cluster_hi, dir.first_cluster >> 16); 427 | __put_le16(&fatent.cluster_lo, dir.first_cluster & 0xFFFF); 428 | ret = fat_write(&dir, &fatent, sizeof(fatent)); 429 | if(ret < 0) 430 | return ret; 431 | 432 | /* Create '..' entry */ 433 | fatent.name[1] = '.'; 434 | if((!vol->cwd.root_flag) && 435 | (vol->fat32.root_cluster != vol->cwd.first_cluster)) { 436 | __put_le16(&fatent.cluster_hi, vol->cwd.first_cluster >> 16); 437 | __put_le16(&fatent.cluster_lo, vol->cwd.first_cluster & 0xFFFF); 438 | } else { 439 | fatent.cluster_hi = 0; 440 | fatent.cluster_lo = 0; 441 | } 442 | ret = fat_write(&dir, &fatent, sizeof(fatent)); 443 | return (ret < 0) ? ret : 0; 444 | } 445 | 446 | int fat_create(struct fat_vol_handle *vol, const char *name, int flags, 447 | struct fat_file_handle *file) 448 | { 449 | int ret = _fat_dir_create_file(vol, name, FAT_ATTR_ARCHIVE, file); 450 | file->flags = flags; 451 | return ret; 452 | } 453 | 454 | -------------------------------------------------------------------------------- /stm32/Makefile: -------------------------------------------------------------------------------- 1 | CROSS_COMPILE ?= arm-none-eabi- 2 | 3 | CC = $(CROSS_COMPILE)gcc 4 | 5 | CFLAGS += -Wall -Wextra -std=gnu99 -g3 -MD -I../include -DSTM32F1 6 | LDFLAGS += -L../src \ 7 | -nostartfiles -Wl,-T,stm32.ld -Wl,--defsym,_stack=0x20005000 8 | LIBS = -lopenfat -lopencm3_stm32f1 -lc -lnosys 9 | 10 | SRC = example.c mmc.c 11 | 12 | OBJ = $(SRC:.c=.o) 13 | 14 | example.elf: $(OBJ) ../src/libopenfat.a 15 | $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) 16 | 17 | .PHONY: clean install 18 | 19 | clean: 20 | -rm -rf *.o *.d example.elf 21 | 22 | -include *.d 23 | 24 | -------------------------------------------------------------------------------- /stm32/example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "openfat.h" 34 | #include "openfat/mbr.h" 35 | 36 | #include "mmc.h" 37 | 38 | static volatile uint32_t time_counter; 39 | 40 | void stm32_setup(void) 41 | { 42 | /* Setup SYSCLK */ 43 | rcc_clock_setup_in_hsi_out_48mhz(); 44 | 45 | /* Enable peripheral clocks for GPIOA, GPIOB, SPI2 */ 46 | rcc_peripheral_enable_clock(&RCC_APB2ENR, 47 | RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN); 48 | 49 | rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_SPI2EN); 50 | 51 | /* Enable power to SD card */ 52 | gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, 53 | GPIO2); 54 | gpio_set(GPIOA, GPIO2); 55 | 56 | /* Force to SPI mode. This should be default after reset! */ 57 | SPI2_I2SCFGR = 0; 58 | 59 | /* Configure SD card i/f SPI2: PB13(SCK), PB14(MISO), PB15(MOSI) */ 60 | gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_10_MHZ, 61 | GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, 62 | GPIO_SPI2_SCK | GPIO_SPI2_MOSI); 63 | gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, 64 | GPIO_SPI2_MISO); 65 | /* SD nCS pin is GPIOA 3 */ 66 | gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, 67 | GPIO3); 68 | 69 | /* Enable Systick for benchmark timing */ 70 | /* 48MHz / 8 => 6000000 counts per second */ 71 | systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); 72 | /* 6000000/6000 = 1000 overflows per second - every 1ms one interrupt */ 73 | systick_set_reload(6000); 74 | systick_interrupt_enable(); 75 | /* start counting */ 76 | systick_counter_enable(); 77 | 78 | /* Enable LED output */ 79 | gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, 80 | GPIO12); 81 | gpio_set(GPIOB, GPIO12); 82 | } 83 | 84 | void print_tree(struct fat_vol_handle *vol, struct fat_file_handle *dir, int nest) 85 | { 86 | struct fat_file_handle subdir; 87 | struct dirent ent; 88 | 89 | while(!fat_readdir(dir, &ent)) { 90 | if((strcmp(ent.d_name, ".") == 0) || 91 | (strcmp(ent.d_name, "..") == 0)) 92 | continue; 93 | 94 | for(int i = 0; i < nest; i++) printf("\t"); 95 | printf("%s\n", ent.d_name); 96 | 97 | if(ent.fat_attr == FAT_ATTR_DIRECTORY) { 98 | fat_chdir(vol, ent.d_name); 99 | assert(fat_open(vol, ".", 0, &subdir) == 0); 100 | print_tree(vol, &subdir, nest + 1); 101 | fat_chdir(vol, ".."); 102 | } 103 | } 104 | 105 | } 106 | 107 | int _write(int fd, char *buf, int len) 108 | { 109 | return len; 110 | } 111 | 112 | int main(void) 113 | { 114 | struct mmc_port spi2; 115 | struct block_mbr_partition part; 116 | struct fat_vol_handle vol; 117 | struct fat_file_handle file; 118 | 119 | stm32_setup(); 120 | 121 | mmc_init(SPI2, GPIOA, GPIO3, &spi2); 122 | mbr_partition_init(&part, (struct block_device *)&spi2, 0); 123 | 124 | assert(fat_vol_init((struct block_device *)&part, &vol) == 0); 125 | printf("Fat type is FAT%d\n", vol.type); 126 | 127 | time_counter = 0; 128 | char dirname[20]; 129 | char filename[20]; 130 | char buffer[2000]; 131 | for(int i = 0; i < 100; i++) { 132 | sprintf(dirname, "Dir%d", i); 133 | fat_mkdir(&vol, dirname); 134 | assert(fat_chdir(&vol, dirname) == 0); 135 | for(int j = 0; j < 100; j++) { 136 | sprintf(filename, "File%d", j); 137 | assert(fat_create(&vol, filename, O_WRONLY, &file) == 0); 138 | assert(fat_write(&file, buffer, sizeof(buffer)) == sizeof(buffer)); 139 | } 140 | assert(fat_chdir(&vol, "..") == 0); 141 | } 142 | asm("bkpt"); 143 | 144 | assert(fat_open(&vol, ".", 0, &file) == 0); 145 | print_tree(&vol, &file, 0); 146 | 147 | while (1) { 148 | } 149 | 150 | return 0; 151 | } 152 | 153 | void sys_tick_handler() 154 | { 155 | static int temp32; 156 | 157 | temp32++; 158 | time_counter++; 159 | 160 | /* we call this handler every 1ms so 1000ms = 1s on/off */ 161 | if (temp32 == 1000) { 162 | gpio_toggle(GPIOB, GPIO12); /* LED2 on/off */ 163 | temp32 = 0; 164 | } 165 | } 166 | 167 | 168 | -------------------------------------------------------------------------------- /stm32/mmc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* MMC Card interface implementation. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include "mmc.h" 31 | #include "openfat/leaccess.h" 32 | 33 | #define MMC_SECTOR_SIZE 512 34 | 35 | static uint8_t spi_readwrite(uint32_t spi, uint8_t data) 36 | { 37 | while(SPI_SR(spi) & SPI_SR_BSY); 38 | SPI_DR(spi) = data; 39 | while(!(SPI_SR(spi) & SPI_SR_RXNE)); 40 | return SPI_DR(spi); 41 | } 42 | 43 | static void mmc_select(const struct mmc_port *mmc) 44 | { 45 | gpio_clear(mmc->cs_port, mmc->cs_pin); 46 | /* Wait for not busy */ 47 | while(spi_readwrite(mmc->spi, 0xFF) == 0); 48 | } 49 | 50 | static void mmc_release(const struct mmc_port *mmc) 51 | { 52 | gpio_set(mmc->cs_port, mmc->cs_pin); 53 | /* Must cycle clock 8 times after CS is released */ 54 | spi_readwrite(mmc->spi, 0xFF); 55 | } 56 | 57 | static void 58 | mmc_write_buffer(const struct mmc_port *mmc, const uint8_t *buf, int len) 59 | { 60 | while(len--) 61 | spi_readwrite(mmc->spi, *buf++); 62 | } 63 | 64 | static void 65 | mmc_read_buffer(const struct mmc_port *mmc, uint8_t *buf, int len) 66 | { 67 | while(len--) 68 | *buf++ = spi_readwrite(mmc->spi, 0xFF); 69 | } 70 | 71 | #define TOKEN_START_SINGLE_READ 0xFE 72 | #define TOKEN_START_MULTI_READ 0xFE 73 | #define TOKEN_START_SINGLE_WRITE 0xFE 74 | #define TOKEN_START_MULTI_WRITE 0xFD 75 | #define TOKEN_STOP_MULTI_WRITE 0xFC 76 | 77 | static int 78 | mmc_receive_block(const struct mmc_port *mmc, uint8_t *buf, int len) 79 | { 80 | /* wait for token */ 81 | while((*buf = spi_readwrite(mmc->spi, 0xFF)) == 0xFF); 82 | 83 | if(*buf != TOKEN_START_SINGLE_READ) /* Start data token */ 84 | return -1; 85 | 86 | mmc_read_buffer(mmc, buf, len); 87 | 88 | /* Discard CRC bytes */ 89 | spi_readwrite(mmc->spi, 0xFF); 90 | spi_readwrite(mmc->spi, 0xFF); 91 | 92 | return 0; 93 | 94 | } 95 | 96 | static int 97 | mmc_transmit_block(const struct mmc_port *mmc, const uint8_t *buf, int len) 98 | { 99 | /* wait for not busy */ 100 | while(spi_readwrite(mmc->spi, 0xFF) != 0xFF); 101 | 102 | /* Send token */ 103 | spi_readwrite(mmc->spi, TOKEN_START_SINGLE_WRITE); 104 | 105 | /* Sent data frame */ 106 | mmc_write_buffer(mmc, buf, len); 107 | 108 | /* Send dummy CRC bytes */ 109 | spi_readwrite(mmc->spi, 0xFF); 110 | spi_readwrite(mmc->spi, 0xFF); 111 | 112 | /* Return response code, zero on no error */ 113 | return spi_readwrite(mmc->spi, 0xFF); 114 | } 115 | 116 | static uint8_t 117 | mmc_command(const struct mmc_port *mmc, uint8_t cmd, uint32_t arg) 118 | { 119 | uint8_t buf[6]; 120 | uint8_t ret; 121 | 122 | buf[0] = cmd | 0x40; 123 | /* argument is packed big-endian */ 124 | buf[1] = (arg >> 24) & 0xFF; 125 | buf[2] = (arg >> 16) & 0xFF; 126 | buf[3] = (arg >> 8) & 0xFF; 127 | buf[4] = arg & 0xFF; 128 | buf[5] = (cmd == MMC_GO_IDLE_STATE) ? 0x95 : 1; /* CRC here */ 129 | 130 | mmc_select(mmc); 131 | mmc_write_buffer(mmc, buf, sizeof(buf)); 132 | 133 | do { /* Wait for response byte */ 134 | ret = spi_readwrite(mmc->spi, 0xFF); 135 | } while(ret & 0x80); 136 | 137 | return ret; 138 | } 139 | 140 | static uint16_t mmc_get_sector_size(const struct block_device *dev) 141 | { 142 | (void)dev; 143 | return MMC_SECTOR_SIZE; 144 | } 145 | 146 | static int mmc_read_sectors(const struct block_device *bldev, 147 | uint32_t sector, uint32_t count, void *buf) 148 | { 149 | const struct mmc_port *mmc = (void*)bldev; 150 | uint32_t i; 151 | 152 | mmc_select(mmc); 153 | for(i = 0; i < count; i++) { 154 | mmc_command(mmc, MMC_READ_SINGLE_BLOCK, 155 | (sector + i) * MMC_SECTOR_SIZE); 156 | mmc_receive_block(mmc, buf, MMC_SECTOR_SIZE); 157 | buf += MMC_SECTOR_SIZE; 158 | } 159 | mmc_release(mmc); 160 | 161 | return i; 162 | } 163 | 164 | static int mmc_write_sectors(const struct block_device *bldev, 165 | uint32_t sector, uint32_t count, const void *buf) 166 | { 167 | const struct mmc_port *mmc = (void*)bldev; 168 | uint32_t i; 169 | 170 | mmc_select(mmc); 171 | for(i = 0; i < count; i++) { 172 | mmc_command(mmc, MMC_WRITE_BLOCK, 173 | (sector + i) * MMC_SECTOR_SIZE); 174 | mmc_transmit_block(mmc, buf, MMC_SECTOR_SIZE); 175 | buf += MMC_SECTOR_SIZE; 176 | } 177 | mmc_release(mmc); 178 | 179 | return i; 180 | } 181 | 182 | int 183 | mmc_init(uint32_t spi, uint32_t cs_port, uint16_t cs_pin, struct mmc_port *mmc) 184 | { 185 | uint8_t ocr[4]; 186 | 187 | /* Intialise structure */ 188 | memset(mmc, 0, sizeof(*mmc)); 189 | 190 | /* Block device methods */ 191 | mmc->bldev.get_sector_size = mmc_get_sector_size; 192 | mmc->bldev.read_sectors = mmc_read_sectors; 193 | mmc->bldev.write_sectors = mmc_write_sectors; 194 | 195 | mmc->spi = spi; 196 | mmc->cs_port = cs_port; 197 | mmc->cs_pin = cs_pin; 198 | 199 | /* Do hardware init */ 200 | /* Peripheral clocks must already be enabled. 201 | * SPI pins must already be configured. */ 202 | spi_init_master(mmc->spi, 203 | SPI_CR1_BAUDRATE_FPCLK_DIV_2, 204 | SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE, 205 | SPI_CR1_CPHA_CLK_TRANSITION_2, 206 | SPI_CR1_CRCL_8BIT, 207 | SPI_CR1_MSBFIRST); 208 | /* Ignore the stupid NSS pin */ 209 | spi_enable_software_slave_management(mmc->spi); 210 | spi_set_nss_high(mmc->spi); 211 | 212 | spi_enable(mmc->spi); 213 | 214 | /* SD nCS pin init */ 215 | gpio_mode_setup(mmc->cs_port, GPIO_MODE_OUTPUT, 216 | GPIO_PUPD_NONE, mmc->cs_pin); 217 | 218 | /* Do card init ... */ 219 | for(int i = 0 ; i < 80; i++) spi_readwrite(mmc->spi, 0xff); 220 | 221 | if(mmc_command(mmc, MMC_GO_IDLE_STATE, 0) != 1) 222 | return -1; /* Can't reset card? */ 223 | 224 | /* Wait for card to initialize */ 225 | while(mmc_command(mmc, MMC_SEND_OP_COND, 0) != 0); 226 | 227 | if(mmc_command(mmc, MMC_READ_OCR, 0) != 0) 228 | return -1; /* Can't read OCR? */ 229 | 230 | mmc_read_buffer(mmc, ocr, sizeof(ocr)); 231 | /* FIXME: Check OCR for acceptable voltage range... */ 232 | 233 | 234 | /* All cards support 512 byte block access and this is the default 235 | * after reset. If disk size or other info is needed this can 236 | * be read from CSD in future. 237 | */ 238 | if(0) { 239 | uint8_t csd[16]; 240 | if(mmc_command(mmc, MMC_SEND_CSD, 0) != 0) 241 | return -1; /* Can't read CSD? */ 242 | mmc_receive_block(mmc, csd, sizeof(csd)); 243 | 244 | uint32_t read_bl_len = csd[5] & 0x0F; 245 | uint32_t c_size = (csd[8] >> 6) + (csd[7] << 3) + 246 | ((csd[6] & 0x03) << 10); 247 | uint32_t c_size_mult = ((csd[10] & 0x80) >> 7) + 248 | ((csd[9] & 0x03) << 1); 249 | uint32_t blocknr = (c_size + 1) << (c_size_mult + 2 + read_bl_len); 250 | (void)blocknr; 251 | } 252 | 253 | mmc_release(mmc); 254 | 255 | return 0; 256 | } 257 | 258 | -------------------------------------------------------------------------------- /stm32/mmc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* MMC Card interface. 22 | */ 23 | 24 | #ifndef __MMC_H 25 | #define __MMC_H 26 | 27 | #include 28 | 29 | #include "openfat/blockdev.h" 30 | 31 | struct mmc_port { 32 | struct block_device bldev; 33 | /* Physical hardware config */ 34 | uint32_t spi; 35 | uint32_t cs_port; 36 | uint16_t cs_pin; 37 | /* Any state information */ 38 | /* ... to be added ... */ 39 | }; 40 | 41 | /* MMC command mnemonics in SPI mode */ 42 | #define MMC_GO_IDLE_STATE 0 43 | #define MMC_SEND_OP_COND 1 44 | #define MMC_SWITCH 6 45 | #define MMC_SEND_EXT_CSD 8 46 | #define MMC_SEND_CSD 9 47 | #define MMC_SEND_CID 10 48 | #define MMC_STOP_TRANSMISSION 12 49 | #define MMC_SEND_STATUS 13 50 | #define MMC_SET_BLOCKLEN 16 51 | #define MMC_READ_SINGLE_BLOCK 17 52 | #define MMC_READ_MULTIPLE_BLOCK 18 53 | #define MMC_SET_BLOCK_COUNT 23 54 | #define MMC_WRITE_BLOCK 24 55 | #define MMC_WRITE_MULTIPLE_BLOCK 25 56 | #define MMC_PROGRAM_CSD 27 57 | #define MMC_SET_WRITE_PROT 28 58 | #define MMC_CLR_WRITE_PROT 29 59 | #define MMC_SEND_WRITE_PROT 30 60 | #define MMC_ERASE_GROUP_START 35 61 | #define MMC_ERASE_GROUP_END 36 62 | #define MMC_ERASE 38 63 | #define MMC_LOCK_UNLOCK 42 64 | #define MMC_APP_CMD 55 65 | #define MMC_GEN_CMD 56 66 | #define MMC_READ_OCR 58 67 | #define MMC_CRC_ON_OFF 59 68 | 69 | int mmc_init(uint32_t spi, uint32_t cs_port, uint16_t cs_pin, struct mmc_port *mmc); 70 | 71 | #endif 72 | 73 | -------------------------------------------------------------------------------- /stm32/stm32.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2010 Uwe Hermann 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */ 21 | 22 | /* Define memory regions. */ 23 | MEMORY 24 | { 25 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K 26 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 27 | } 28 | 29 | /* Include the common ld script. */ 30 | INCLUDE libopencm3_stm32f1.ld 31 | 32 | -------------------------------------------------------------------------------- /unix/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: images 2 | 3 | CFLAGS = -Wall -Wextra -std=gnu99 -g3 -MD -I../include 4 | LDFLAGS = -L../src 5 | LIBS = -lopenfat 6 | 7 | SRC = fattest.c \ 8 | blockdev_file.c \ 9 | 10 | OBJ = $(SRC:.c=.o) 11 | 12 | fattest: $(OBJ) ../src/libopenfat.a 13 | $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) 14 | 15 | autopsy: autopsy.c blockdev_file.o 16 | $(CC) $(CFLAGS) $(LDFLAGS) autopsy.c blockdev_file.o -o $@ \ 17 | `pkg-config gtk+-2.0 --cflags --libs` -lopenfat 18 | 19 | images: fat12.img fat16.img fat32.img 20 | 21 | fat12.img: 22 | dd if=/dev/zero of=$@ bs=512 count=2048 23 | mkfs -t msdos $@ 24 | 25 | fat16.img: 26 | dd if=/dev/zero of=$@ bs=512 count=20480 27 | mkfs -t msdos $@ 28 | 29 | fat32.img: 30 | dd if=/dev/zero of=$@ bs=512 count=81920 31 | mkfs -t msdos -F 32 $@ 32 | 33 | .PHONY: clean install 34 | 35 | clean: 36 | -rm -rf *.o *.d fattest 37 | 38 | -include *.d 39 | 40 | -------------------------------------------------------------------------------- /unix/autopsy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* This program is an unfinished diagnostic tool for investigating the 22 | * sector level contents of a FAT filesystem. It was written to aid 23 | * debugging during the development of OpenFAT. It is not expected to 24 | * be useful to the user, but is included for completeness, and may be 25 | * of use to future developers. It currently only works with FAT32 26 | * filesystems with 2 fats. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | #include 38 | 39 | #include 40 | 41 | #include 42 | 43 | #include "openfat.h" 44 | #include "openfat/unixlike.h" 45 | 46 | #include "../src/bpb.h" 47 | #include "../src/fat_core.h" 48 | 49 | /* Prototypes for blockdev_file.c functions */ 50 | extern struct block_device * 51 | block_device_file_new(const char *filename, const char *mode); 52 | extern void block_device_file_destroy(struct block_device *bldev); 53 | 54 | void dump_bootsector(struct fat_vol_handle *vol) 55 | { 56 | uint8_t bootsector[512]; 57 | struct bpb_common *bpb = (void*)bootsector; 58 | struct bpb_fat32 *bpb32 = (void*)bootsector; 59 | 60 | block_read_sectors(vol->dev, 0, 1, bootsector); 61 | 62 | fprintf(stdout, "boot_jmp:\t\t %02X %02X %02X\n", 63 | bpb->boot_jmp[0], bpb->boot_jmp[1], bpb->boot_jmp[2]); 64 | fprintf(stdout, "oem_name:\t\t "); 65 | for(int i = 0; i < 8; i++) 66 | fprintf(stdout, "%c", bpb->oem_name[i]); 67 | fprintf(stdout, "\nbytes_per_sector:\t %d\n", 68 | bpb->bytes_per_sector); 69 | fprintf(stdout, "sectors_per_cluster:\t %d\n", 70 | bpb->sectors_per_cluster); 71 | fprintf(stdout, "reserved_sector_count:\t %d\n", 72 | bpb->reserved_sector_count); 73 | fprintf(stdout, "num_fats:\t\t %d\n", 74 | bpb->num_fats); 75 | fprintf(stdout, "root_entry_count:\t %d\n", 76 | bpb->root_entry_count); 77 | fprintf(stdout, "total_sectors_16:\t %d\n", 78 | bpb->total_sectors_16); 79 | fprintf(stdout, "media:\t\t\t 0x%02X\n", 80 | bpb->media); 81 | fprintf(stdout, "fat_size_16:\t\t %d\n", 82 | bpb->fat_size_16); 83 | fprintf(stdout, "sectors_per_track:\t %d\n", 84 | bpb->sectors_per_track); 85 | fprintf(stdout, "num_heads:\t\t %d\n", 86 | bpb->num_heads); 87 | fprintf(stdout, "hidden_sectors:\t\t %d\n", 88 | bpb->hidden_sectors); 89 | fprintf(stdout, "total_sectors_32:\t %d\n", 90 | bpb->total_sectors_32); 91 | switch(vol->type) { 92 | case FAT_TYPE_FAT32: 93 | fprintf(stdout, "fat_size_32:\t\t %d\n", 94 | bpb32->fat_size_32); 95 | fprintf(stdout, "ext_flags:\t\t 0x%02X\n", 96 | bpb32->ext_flags); 97 | fprintf(stdout, "fs_version:\t\t %d\n", 98 | bpb32->fs_version); 99 | fprintf(stdout, "root_cluster:\t\t %d\n", 100 | bpb32->root_cluster); 101 | fprintf(stdout, "fs_info:\t\t %d\n", 102 | bpb32->fs_info); 103 | fprintf(stdout, "bk_boot_sec:\t\t 0x%X\n", 104 | bpb32->bk_boot_sec); 105 | fprintf(stdout, "reserved:\t\t "); 106 | for(int i = 0; i < 12; i++) 107 | fprintf(stdout, "%02X ", bpb32->Reserved[i]); 108 | fprintf(stdout, "\ndrive_num:\t\t %d\n", 109 | bpb32->drive_num); 110 | fprintf(stdout, "boot_sig:\t\t %d\n", 111 | bpb32->boot_sig); 112 | fprintf(stdout, "volume_id:\t\t 0x%X\n", 113 | bpb32->volume_id); 114 | fprintf(stdout, "volume_label:\t\t "); 115 | for(int i = 0; i < 11; i++) 116 | fprintf(stdout, "%c", bpb32->volume_label[i]); 117 | fprintf(stdout, "\nfs_type:\t\t "); 118 | for(int i = 0; i < 8; i++) 119 | fprintf(stdout, "%c", bpb32->fs_type[i]); 120 | fprintf(stdout, "\n\n"); 121 | break; 122 | 123 | } 124 | fprintf(stdout, "first_data_sector:\t %d\n", 125 | vol->first_data_sector); 126 | fprintf(stdout, "cluster_count:\t\t %d\n", 127 | vol->cluster_count); 128 | fprintf(stdout, "fat_size:\t\t %d\n", 129 | vol->fat_size); 130 | fprintf(stdout, "root_cluster:\t\t %d\n", 131 | vol->fat32.root_cluster); 132 | } 133 | 134 | GtkWidget *setup_fat_view(struct fat_vol_handle *vol) 135 | { 136 | GtkWidget *sw, *tv; 137 | GtkListStore *model; 138 | GtkTreeIter iter; 139 | GtkTreeViewColumn *col; 140 | GtkCellRenderer *cell; 141 | 142 | uint32_t sector; 143 | uint32_t cluster = 0; 144 | uint8_t *fat[vol->num_fats]; 145 | int i; 146 | 147 | sw = gtk_scrolled_window_new(NULL, NULL); 148 | model = gtk_list_store_new(3, 149 | G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); 150 | tv = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); 151 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tv), FALSE); 152 | gtk_widget_modify_font(tv, 153 | pango_font_description_from_string("Monospace 8")); 154 | gtk_container_add(GTK_CONTAINER(sw), tv); 155 | 156 | cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new()); 157 | col = gtk_tree_view_column_new_with_attributes(NULL, cell, 158 | "text", 0, NULL); 159 | gtk_tree_view_append_column(GTK_TREE_VIEW(tv), col); 160 | 161 | for(i = 0; i < vol->num_fats; i++) { 162 | fat[i] = alloca(vol->bytes_per_sector); 163 | 164 | cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new()); 165 | col = gtk_tree_view_column_new_with_attributes(NULL, cell, 166 | "text", i + 1, NULL); 167 | gtk_tree_view_append_column(GTK_TREE_VIEW(tv), col); 168 | } 169 | 170 | for(sector = 0; sector < vol->fat_size; sector++) { 171 | for(i = 0; i < vol->num_fats; i++) { 172 | block_read_sectors(vol->dev, 173 | vol->reserved_sector_count + 174 | (vol->fat_size * i) + 175 | sector, 1, fat[i]); 176 | } 177 | for(int j = 0; j < vol->bytes_per_sector; j += 4) { 178 | char str1[20], str2[20], str3[20]; 179 | gtk_list_store_append(model, &iter); 180 | sprintf(str1, "0x%08X", cluster++); 181 | sprintf(str2, "0x%08X",__get_le32((void*)(fat[0] + j))); 182 | sprintf(str3, "0x%08X",__get_le32((void*)(fat[1] + j))); 183 | gtk_list_store_set(model, &iter, 184 | 0, str1, 1, str2, 2, str3, -1); 185 | } 186 | } 187 | 188 | return sw; 189 | } 190 | 191 | 192 | static void gtk_text_view_puts(GtkTextView *tv, const char *buf) 193 | { 194 | GtkTextBuffer *tb = gtk_text_view_get_buffer(tv); 195 | GtkTextIter iter; 196 | 197 | gtk_text_buffer_get_end_iter(tb, &iter); 198 | gtk_text_buffer_insert(tb, &iter, buf, -1); 199 | } 200 | 201 | void cluster_changed_cb(GtkComboBox *clust, GtkComboBox *sector) 202 | { 203 | struct fat_vol_handle *vol = g_object_get_data(G_OBJECT(clust), "vol"); 204 | uint32_t cluster = strtol(gtk_combo_box_get_active_text(clust), 0, 0); 205 | char sect[20]; 206 | int i; 207 | puts(sect); 208 | for(i = 0; i < vol->sectors_per_cluster; i++) 209 | gtk_combo_box_remove_text(sector, 0); 210 | for(i = 0; i < vol->sectors_per_cluster; i++) { 211 | sprintf(sect, "%d", fat_first_sector_of_cluster(vol, cluster)+i); 212 | gtk_combo_box_append_text(sector, sect); 213 | } 214 | gtk_combo_box_set_active(sector, 0); 215 | } 216 | 217 | void sector_changed_cb(GtkComboBox *entry, GtkTextView *tv) 218 | { 219 | struct fat_vol_handle *vol = g_object_get_data(G_OBJECT(entry), "vol"); 220 | uint32_t sector; 221 | char linebuf[80]; 222 | uint8_t *buf = alloca(vol->bytes_per_sector); 223 | int i, j, k; 224 | 225 | sector = strtol(gtk_combo_box_get_active_text(entry), 0, 0); 226 | block_read_sectors(vol->dev, sector, 1, buf); 227 | 228 | gtk_text_buffer_set_text(gtk_text_view_get_buffer(tv), "", 0); 229 | memset(linebuf, ' ', 79); 230 | linebuf[79] = 0; 231 | linebuf[78] = '\n'; 232 | for(i = 0; i < vol->bytes_per_sector;) { 233 | k = 0; 234 | for(j = 0; j < 16; j++, i++) { 235 | k += sprintf(linebuf+k, "%02X ", buf[i]); 236 | linebuf[k] = ' '; 237 | if((j + 1) % 4 == 0) k++; 238 | if(j == 7) k++; 239 | linebuf[54+j] = ((buf[i]<32)||(buf[i]>126))?'.':buf[i]; 240 | } 241 | gtk_text_view_puts(tv, linebuf); 242 | } 243 | } 244 | 245 | GtkWidget *setup_sector_view(struct fat_vol_handle *vol) 246 | { 247 | GtkWidget *vbox, *hbox, *clust, *entry, *sw, *tv; 248 | 249 | vbox = gtk_vbox_new(FALSE, FALSE); 250 | 251 | hbox = gtk_hbox_new(FALSE, FALSE); 252 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); 253 | 254 | clust = gtk_combo_box_entry_new_text(); 255 | g_object_set_data(G_OBJECT(clust), "vol", vol); 256 | gtk_box_pack_start(GTK_BOX(hbox), clust, FALSE, FALSE, 0); 257 | 258 | entry = gtk_combo_box_entry_new_text(); 259 | g_object_set_data(G_OBJECT(entry), "vol", vol); 260 | gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); 261 | 262 | sw = gtk_scrolled_window_new(NULL, NULL); 263 | gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); 264 | 265 | tv = gtk_text_view_new(); 266 | gtk_text_view_set_editable(GTK_TEXT_VIEW(tv), FALSE); 267 | gtk_widget_modify_font(tv, 268 | pango_font_description_from_string("Monospace 8")); 269 | gtk_container_add(GTK_CONTAINER(sw), tv); 270 | 271 | g_signal_connect(clust, "changed", G_CALLBACK(cluster_changed_cb), entry); 272 | g_signal_connect(entry, "changed", G_CALLBACK(sector_changed_cb), tv); 273 | 274 | return vbox; 275 | } 276 | 277 | void setup_ui(struct fat_vol_handle *vol) 278 | { 279 | GtkWidget *window, *paned; 280 | 281 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 282 | gtk_window_set_default_size(GTK_WINDOW(window), 700, 500); 283 | gtk_window_set_title(GTK_WINDOW(window), "Sector Inspector"); 284 | g_signal_connect(window, "destroy", gtk_main_quit, NULL); 285 | 286 | paned = gtk_hpaned_new(); 287 | gtk_paned_pack1(GTK_PANED(paned), setup_fat_view(vol), TRUE, TRUE); 288 | gtk_paned_pack2(GTK_PANED(paned), setup_sector_view(vol), TRUE, TRUE); 289 | gtk_container_add(GTK_CONTAINER(window), paned); 290 | 291 | gtk_widget_show_all(window); 292 | } 293 | 294 | 295 | int main(int argc, char *argv[]) 296 | { 297 | struct block_device *bldev; 298 | struct fat_vol_handle *vol; 299 | struct fat_file_handle *root, *file; 300 | char *rootpath = argc > 2 ? argv[2] : "/"; 301 | 302 | bldev = block_device_file_new(argc > 1 ? argv[1] : "fat32.img", "r+"); 303 | assert(bldev != NULL); 304 | 305 | vol = ufat_mount(bldev); 306 | fprintf(stderr, "Fat type is FAT%d\n", vol->type); 307 | 308 | dump_bootsector(vol); 309 | 310 | if((root = ufat_open(vol, rootpath, 0)) == NULL) { 311 | fprintf(stderr, "Failed to open file: %s\n", rootpath); 312 | return -1; 313 | } 314 | 315 | gtk_init(NULL, NULL); 316 | setup_ui(vol); 317 | gtk_main(); 318 | 319 | ufat_close(root); 320 | ufat_umount(vol); 321 | 322 | block_device_file_destroy(bldev); 323 | } 324 | 325 | -------------------------------------------------------------------------------- /unix/blockdev_file.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* Sample block device implementation: 22 | * Implementation of abstract block device over a Unix file 23 | */ 24 | 25 | #define _FILE_OFFSET_BITS 64 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "openfat/blockdev.h" 32 | 33 | #define FILE_SECTOR_SIZE 512 34 | 35 | struct block_device_file { 36 | struct block_device bldev; 37 | FILE *file; 38 | }; 39 | 40 | uint16_t file_get_sector_size(const struct block_device *dev) 41 | { 42 | (void)dev; 43 | return FILE_SECTOR_SIZE; 44 | } 45 | 46 | static int file_read_sectors(const struct block_device *bldev, 47 | uint32_t sector, uint32_t count, void *buf) 48 | { 49 | const struct block_device_file *dev = (void*)bldev; 50 | 51 | fseeko(dev->file, (uint64_t)sector * FILE_SECTOR_SIZE, SEEK_SET); 52 | return fread(buf, FILE_SECTOR_SIZE, count, dev->file); 53 | } 54 | 55 | static int file_write_sectors(const struct block_device *bldev, 56 | uint32_t sector, uint32_t count, const void *buf) 57 | { 58 | const struct block_device_file *dev = (void*)bldev; 59 | 60 | fseeko(dev->file, (uint64_t)sector * FILE_SECTOR_SIZE, SEEK_SET); 61 | return fwrite(buf, FILE_SECTOR_SIZE, count, dev->file); 62 | } 63 | 64 | struct block_device * block_device_file_new(const char *filename, const char *mode) 65 | { 66 | FILE *f; 67 | struct block_device_file *dev; 68 | struct block_device *bldev; 69 | 70 | f = fopen(filename, mode); 71 | if(f == NULL) 72 | return NULL; 73 | 74 | dev = malloc(sizeof(*dev)); 75 | bldev = (void*)dev; 76 | 77 | bldev->read_sectors = file_read_sectors; 78 | bldev->write_sectors = file_write_sectors; 79 | bldev->get_sector_size = file_get_sector_size; 80 | dev->file = f; 81 | 82 | return (struct block_device*)dev; 83 | } 84 | 85 | void block_device_file_destroy(struct block_device *bldev) 86 | { 87 | struct block_device_file *dev = (void*)bldev; 88 | 89 | fclose(dev->file); 90 | free(dev); 91 | } 92 | 93 | -------------------------------------------------------------------------------- /unix/fattest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the openfat project. 3 | * 4 | * Copyright (C) 2011 Department of Physics, University of Otago 5 | * Written by Gareth McMullin 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | /* Example to list directory structure. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #include 33 | 34 | #include "openfat.h" 35 | 36 | /* Prototypes for blockdev_file.c functions */ 37 | extern struct block_device * 38 | block_device_file_new(const char *filename, const char *mode); 39 | extern void block_device_file_destroy(struct block_device *bldev); 40 | 41 | void print_tree(struct fat_vol_handle *vol, struct fat_file_handle *dir, 42 | const char *path) 43 | { 44 | struct dirent ent; 45 | char tmppath[1024]; 46 | struct fat_file_handle subdir; 47 | 48 | while(!fat_readdir(dir, &ent)) { 49 | if((strcmp(ent.d_name, ".") == 0) || 50 | (strcmp(ent.d_name, "..") == 0)) 51 | continue; 52 | sprintf(tmppath, "%s/%s", path, ent.d_name); 53 | puts(tmppath); 54 | 55 | if(ent.fat_attr == FAT_ATTR_DIRECTORY) { 56 | fat_chdir(vol, ent.d_name); 57 | assert(fat_open(vol, ".", 0, &subdir) == 0); 58 | print_tree(vol, &subdir, tmppath); 59 | fat_chdir(vol, ".."); 60 | } 61 | } 62 | 63 | } 64 | 65 | int main(int argc, char *argv[]) 66 | { 67 | struct block_device *bldev; 68 | FatVol vol; 69 | FatFile file; 70 | char *rootpath = argc > 2 ? argv[2] : "/"; 71 | 72 | bldev = block_device_file_new(argc > 1 ? argv[1] : "fat32.img", "r+"); 73 | assert(bldev != NULL); 74 | 75 | assert(fat_vol_init(bldev, &vol) == 0); 76 | fprintf(stderr, "Fat type is FAT%d\n", vol.type); 77 | 78 | fat_mkdir(&vol, "Directory1"); 79 | fat_mkdir(&vol, "Directory2"); 80 | fat_mkdir(&vol, "Directory3"); 81 | assert(fat_chdir(&vol, "Directory1") == 0); 82 | fat_mkdir(&vol, "Directory1"); 83 | fat_mkdir(&vol, "Directory2"); 84 | fat_mkdir(&vol, "Directory3"); 85 | if(fat_create(&vol, "Message file with a long name.txt", O_WRONLY, &file) == 0) { 86 | for(int i = 0; i < 100; i++) { 87 | char message[80]; 88 | sprintf(message, "Here is a message %d\n", i); 89 | assert(fat_write(&file, message, strlen(message)) == (int)strlen(message)); 90 | } 91 | } 92 | assert(fat_chdir(&vol, "..") == 0); 93 | assert(fat_open(&vol, ".", O_RDONLY, &file) == 0); 94 | print_tree(&vol, &file, rootpath[0] == '/' ? rootpath + 1 : rootpath); 95 | 96 | block_device_file_destroy(bldev); 97 | } 98 | 99 | --------------------------------------------------------------------------------