home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / code_examples / cmanual_456 / amigados / amigados.doc < prev    next >
Text File  |  1991-01-27  |  45KB  |  1,420 lines

  1. 11    AMIGADOS
  2.  
  3. 11.1  INTRODUCTION
  4.  
  5. In this chapter are we going to discuss how to read and write
  6. files from/to different devices (disk drivers etc). How to
  7. protect your data from being corrupted by other tasks working
  8. with the same file, and how to attach comments to files, how
  9. to rename them etc...
  10.  
  11. However, before we start it is best to look at how AmigaDOS
  12. works, and explain some commonly used words. If you are familiar
  13. with AmigaDOS and CLI you can skip the following chapters and
  14. immediately start on chapter 11.2 (OPEN AND CLOSE FILES).
  15.  
  16.  
  17.  
  18. 11.1.1  PHYSICAL DEVICES
  19.  
  20. Physical devices are parts of the Amiga to which files can be
  21. read from and sent to. The most commonly used physical device
  22. is undoubtedly the internal disk drive (DF0:). 
  23.  
  24. Here is the list of the standard AmigaDOS devices:
  25. -------------------------------------------------------------
  26. DF0: Diskdrive 0.      File/Directory access
  27. DF1: Diskdrive 1.      File/Directory access
  28. DF2: Diskdrive 2.      File/Directory access
  29. DF3: Diskdrive 3.      File/Directory access
  30. RAM: RAMdisk,          File/Directory access
  31.  
  32. SER: Serial port,      Input/Output
  33. PAR: Parallel port,    Input/Output
  34. PRT: Printerdevice,    Output to printer (trough Preferences)
  35.  
  36. CON: Console, (window) Input/Output
  37. RAW: RAW, (window)     Input/Output
  38. NIL: Nothing,          Output to nothing
  39. -------------------------------------------------------------
  40.  
  41. (Note that all device-names end with a colon.)
  42.  
  43. If you want to copy a file called "program.c" from the internal
  44. disk drive (DF0:) to the second disk drive (DF1:) you write:
  45.  
  46.   copy from DF0:program.c to DF1:
  47.  
  48. If you want to copy a file called "program.c" from the internal
  49. disk drive (DF0:) to the parallel port (PAR:) you write:
  50.  
  51.   copy from DF0:program.c to PAR:
  52.  
  53. If a printer was connected to the parallel port the file
  54. "program.c" would be printed out with the printers default
  55. mode. If the printer was connected to the serial port (SER:)
  56. you write: 
  57.  
  58.   copy from DF0:program.c to SER:
  59.  
  60. However, if you want to copy a file to the printer, and you
  61. want to use the printer mode you have chosen with Preferences,
  62. you use the printer device (PRT:). (With Preferences you can
  63. decide which device you want to use (PAR: or SER:), and if the
  64. text should be printed with letter quality or in draft mode
  65. etc.)
  66.  
  67.   copy from DF0:program.c to PRT:
  68.  
  69.  
  70. AmigaDOS allows you even to use special windows (CON:) for
  71. input/output. The only thing you need to remember is to tell
  72. AmigaDOS what size and position of the window you want. The
  73. syntax is:
  74.  
  75.   CON:x/y/width/height/(title)
  76.  
  77. Remember to include all four slashes! (The window title is
  78. optional.) To copy the file "program.c" to a special window
  79. you write:
  80.  
  81.   copy from DF0:program.c to CON:10/20/320/100/Text
  82.  
  83. This will print the file program.c to a window positioned at
  84. x position 10, y position 20, width 320, height 100, with the
  85. title "Text". If you want to use spaces in the title you need
  86. to put quotes around the whole expression:
  87.  
  88.   copy from DF0:program.c to "CON:10/20/320/100/Spacy Window"
  89.  
  90.  
  91.  
  92. 11.1.2  VOLUMES
  93.  
  94. To access a disk you can either use the physical device name of
  95. the drive in which the disk is, or use the volume name of the
  96. disk. If you want to copy a file from the RAMdisk called
  97. "program.c", to a disk called "DOCUMENTS", and the disk is in
  98. the second disk drive, you can either write:
  99.  
  100.   copy from RAM:program.c to DF1:
  101.  
  102. or
  103.  
  104.   copy from RAM:program.c to DOCUMENTS:
  105.  
  106. (Note the colon after the volume name!) The advantage with the
  107. last example is that you do not need to bother in which drive
  108. the DOCUMENTS disk is in. Furthermore, if the right disk was not
  109. in any drive, AmigaDOS will ask you to insert it, and you
  110. do not need to worry about writing to the wrong disk.
  111.  
  112.  
  113.  
  114. 11.1.3  DIRECTORIES/SUBDIRECTORIES/FILES
  115.  
  116. On a disk there exist directories/subdirectories and files. A
  117. subdirectory is a directory inside another directory. (There
  118. may be subdirectories inside other subdirectories and so on.)
  119. See picture:
  120.  
  121.                       DEVICE/VOLUME
  122.                             |
  123.       /---------------------+---------------------\
  124.       |                     |                     |
  125.     FILES               DIRECTORY             DIRECTORY
  126.                             |                     |
  127.                           FILES             SUBDIRECTORIES
  128.                                                   |
  129.                                                 FILES
  130.  
  131. How to gain access to files:
  132.  
  133. Left of the colon    Right of the colon    Right of a slash
  134. ------------------------------------------------------------
  135. Device name          Directory name        Subdirectory name
  136.     or                     or                     or
  137. Volume name             Filename               Filename
  138. ------------------------------------------------------------
  139.  
  140.  
  141. For example. Here is a disk named "CPrograms" on which there is
  142. a program called "Example" and two directories named "Games"
  143. and "Utilities". In the Utilities directory there is a program
  144. called FileWindow, and in the Games directory there are two
  145. games called Car and MiniBlast. There exist also a subdirectory
  146. called "SourceCode" which contains two files "Car.c" and
  147. "MiniBlast.c". See drawing:
  148.  
  149.                          CPrograms
  150.                              |
  151.       /----------------------+--------------------------\
  152.       |                      |                          |
  153.    Example                 Games                    Utilities
  154.                              |                          |
  155.                /-------------+-------------\        FileWindow
  156.                |             |             |
  157.               Car        MiniBlast     SourceCode
  158.                                            |
  159.                                     /-------------\
  160.                                     |              |
  161.                                   Car.c        MiniBlast.c
  162.  
  163.  
  164. Here is how to access all the files:
  165.  
  166. CPrograms:Example
  167. CPrograms:Utilities/FileWindow
  168. CPrograms:Games/Car
  169. CPrograms:Games/MiniBlast
  170. CPrograms:Games/SourceCode/Car.c
  171. CPrograms:Games/SourceCode/MiniBlast.c
  172.  
  173.  
  174.  
  175. 11.1.4  LOGICAL DEVICES
  176.  
  177. Logical devices is a simple way to find files, regardless of
  178. where the file actually is. For example: If you have all your
  179. C programs on a disk called "Programs", placed i directory
  180. named "Examples", and you want to run the program "test1" you
  181. need to write:
  182.  
  183.   Programs:Examples/test1
  184.  
  185. If you often want to access files in that directory you can
  186. assign a logical device to it. You then only need to write the
  187. logical device name and the filename, and AmigaDOS will
  188. automatically look on the right disk and directory.
  189.  
  190. You assign logical devices by using the CLI command "Assign"
  191. which is called like this:
  192.  
  193.   Assign [logical device name]: [device/(directory/subdirectory)]
  194.  
  195. For example:
  196.  
  197.   Assign EX: Programs:Examples
  198.  
  199. To gain access to the file "test1" you then only need to write:
  200.  
  201.   EX:test1
  202.  
  203.  
  204. When you boot up the computer it will automatically create some
  205. commonly used logical devices. A good example is the logical
  206. device "FONTS:". It is automatically assigned to the system
  207. disk's "fonts" directory. Here is the list of some of the most
  208. commonly used logical devices:
  209.  
  210.   Logical device  Description
  211.   ---------------------------
  212.   SYS:            system disk
  213.   C:              CLI commands
  214.   FONTS:          fonts
  215.   L:              handlers
  216.   LIBS:           libraries              
  217.   S:              sequence library
  218.   DEVS:           devices
  219.  
  220. The logical device "C:" is assigned to the system disk's "c"
  221. directory, where all CLI commands are. If you have copied some
  222. CLI commands to the RAMdisk, and you want AmigaDOS to look
  223. there instead of looking on the system disk's c directory you
  224. simply reassign the C: device. For example:
  225.  
  226.   Assign C: RAM:
  227.  
  228.  
  229. If you call Assign without any parameters, it will list all
  230. logical devices, and their assignments. If you have booted up
  231. the system with the Lattice C Compiler disk, the following
  232. logical devices are assigned: 
  233.  
  234.   Automatically assigned:
  235.   --------------------------------------
  236.   S              Lattice_C_5.0.1:s
  237.   L              Lattice_C_5.0.1:l
  238.   C              Lattice_C_5.0.1:c
  239.   FONTS          Lattice_C_5.0.1:fonts
  240.   DEVS           Lattice_C_5.0.1:devs
  241.   LIBS           Lattice_C_5.0.1:libs
  242.   SYS            Lattice_C_5.0.1:
  243.  
  244.   Specially assigned: (Lattice C)
  245.   --------------------------------------
  246.   LIB            Volume: Lattice_C_5.0.2
  247.   INCLUDE        Volume: Lattice_C_5.0.2
  248.   LC             Lattice_C_5.0.1:c
  249.   QUAD           RAM DISK:
  250.   ENV            RAM DISK:env
  251.   CLIPS          RAM DISK:clipboards
  252.  
  253.  
  254.  
  255. 11.2  OPEN AND CLOSE FILES
  256.  
  257. Before you can do anything with a file you have to ask the
  258. operating system to "open it". This is because AmigaDOS needs
  259. to know what you are going to do with the file. Are you going
  260. to create a new file or are you going to work with an already
  261. opened file. You open a file by calling the function Open():
  262.  
  263. Synopsis:    file_handle = Open( file_name, mode );
  264.  
  265. file_handle: (BPTR) Actually a pointer to a FileHandle
  266.              structure. If the system could not open the file
  267.              with our requirements Open() returns NULL.
  268.  
  269. file_name:   (char *) Pointer to a text string which contains
  270.              the file name including any necessary device/
  271.              directory names.
  272.  
  273. mode:        (long) When you open a file you need to tell the
  274.              system what you are going to do with it. This
  275.              field should therefore contain one of the
  276.              following flags:
  277.  
  278.              MODE_OLDFILE:   Opens an existing file for reading
  279.                              and writing.
  280.  
  281.              MODE_NEWFILE:   Opens a new file for writing.
  282.  
  283.              MODE_READWRITE: Opens an old file with an
  284.                              exclusive lock. (Explained later
  285.                              in this chapter.)
  286.  
  287.              MODE_READONLY:  Same as MODE_OLDFILE.
  288.  
  289. For example, if you want to create a new file called
  290. "Highscore.dat" you write:
  291.  
  292. /* Try to open the file: */
  293. file_handle = Open( "Highscore.dat", MODE_NEWFILE );
  294.  
  295. /* Check if we have opened the file: */
  296. if( file_handle == NULL )
  297.   /* Could NOT open file! */
  298.  
  299.  
  300. Once you have finished reading/writing the file you need to
  301. close it. You do it by calling the function Close():
  302.  
  303. Synopsis:    Close( file_handle );
  304.  
  305. file_handle: (BPTR) Actually a pointer to a FileHandle
  306.              structure which has been initialized by a previous
  307.              Open() call.
  308.  
  309. Remember to close ALL files you have opened!
  310.  
  311.  
  312.  
  313. 11.3  READ AND WRITE FILES
  314.  
  315. Once you have successfully opened a file you can start to
  316. read/write. AmigaDOS consider files to be a stream of bytes,
  317. and when you read/write something you need to specify how many
  318. bytes you want to read/write.
  319.  
  320.  
  321.  
  322. 11.3.1  READ()
  323.  
  324. You read data by calling the function Read():
  325.  
  326. Synopsis:    bytes_read = Read( file_handle, buffer, size );
  327.  
  328. bytes_read:  (long) Number of bytes actually read. Even if you
  329.              tell AmigaDOS that you want to read x number of
  330.              bytes, it is not certain that you actually can
  331.              do it. The file is maybe corrupted, not as big as
  332.              you thought etc.
  333.  
  334. file_handle: (BPTR) Actually a pointer to a FileHandle
  335.              structure which has been initialized by a previous
  336.              Open() call.
  337.  
  338. buffer:      (char *) Pointer to the data buffer you want to
  339.              read the data into.
  340.  
  341. size:        (long) Number of bytes you want to read.
  342.  
  343. For example, if you want to read a file which contains an array
  344. (highscore) of ten integers, you write: (the file has already
  345. been opened.)
  346.  
  347. bytes_read = Read( file_handle, highscore, sizeof( highscore ) );
  348.  
  349. if( bytes_read != sizeof( highscore ) )
  350.   /* ERROR while reading! */
  351.  
  352.  
  353.  
  354. 11.3.2  WRITE()
  355.  
  356. When you what to write to a file you use the function Write():
  357.  
  358. Synopsis:       bytes_written = Write( file_handle, buffer, size );
  359.  
  360. bytes_writtten: (long) Number of bytes actually written. Even
  361.                 if you tell AmigaDOS that you want to write x
  362.                 number of bytes, it is not certain that you
  363.                 actually can do it. Maybe the disk was full,
  364.                 writeprotected etc.
  365.  
  366. file_handle:    (BPTR) Actually a pointer to a FileHandle
  367.                 structure which has been initialized by a
  368.                 previous Open() call.
  369.  
  370. buffer:         (char *) Pointer to the data buffer which you
  371.                 want to write.
  372.  
  373. size:           (long) Number of bytes you want to write.
  374.  
  375. For example, if you want to save an array (highscore) of
  376. ten integers to a file, you simply write: (the file has
  377. already been opened.)
  378.  
  379. bytes_written = Write( file_handle, highscore, sizeof( highscore ) );
  380.  
  381. if( bytes_written != sizeof( highscore ) )
  382.   /* ERROR while writing! */
  383.  
  384.  
  385.  
  386. 11.4  MOVE INSIDE FILES
  387.  
  388. If you write something to a disk the "file cursor" will be
  389. positioned where you stopped writing. So if you start writing
  390. again, the new data will be placed after the first data. If
  391. you on the other hand wanted to write over the old data you
  392. need to move the file cursor to beginning of the data before
  393. you start writing. You move the file cursor by calling the
  394. function Seek():
  395.  
  396. Synopsis:    old_pos = Seek( file_handle, new_pos, mode );
  397.  
  398. old_pos:     (long) Previous position in the file, or -1 if
  399.              an error occurred.
  400.  
  401. file_handle: (BPTR) Actually a pointer to a FileHandle
  402.              structure which has been initialized by a 
  403.              previous Open() call.
  404.  
  405. new_pos:     (long) New position relative to the "mode".
  406.  
  407. mode:        (long) The new_pos can be relative to:
  408.                OFFSET_BEGINNING: Beginning of the file.
  409.                OFFSET_CURRENT:   Current position.
  410.                OFFSET_END:       The end of the file.
  411.  
  412. So if you want to move the cursor to the beginning of the file
  413. you set mode to OFFSET_BEGINNING, and new_pos to 0. (When you
  414. open a file by calling the function Open(), the file cursor is
  415. automatically placed at the beginning of the file.)
  416.  
  417. If you on the other hand want to move the cursor to the end of
  418. the file you set mode to OFFSET_END, and new_pos still to 0.
  419.  
  420. To move 10 bytes forward from the current position you set mode
  421. to OFFSET_CURRENT, and new_pos to 10. To move 10 bytes
  422. backwards you set new_pos to -10.
  423.  
  424.  
  425.  
  426. 11.5  FILES AND MULTITASKING
  427.  
  428. Since the Amiga can have several tasks running at the same time
  429. it can happen that more than one task work with the same file.
  430. This can be very dangerous since one process may destroy some
  431. data another process has created.
  432.  
  433. Imagine two tasks, one will read a file and multiply a value
  434. with two, while the other tasks should add 3. Since the two
  435. tasks can run at the same time it could happen that they would
  436. update the file at the same time:
  437.  
  438.                             FILE:
  439.                        ---------------
  440. Process A reads the <- | number = 10 | -> Process B reads also
  441. value. (number=10)     ---------------    the value. (number=10) 
  442.  
  443.         |                                           |
  444.         V                                           |
  445.                                                     |
  446. Process A changes                                   |
  447. the value to 20,       ---------------              |
  448. and writes the new  -> | number = 20 |              |
  449. value to the file.     ---------------              V
  450. (10 * 2 = 20)
  451.                        ---------------    Process B adds 3 to
  452.                        | number = 13 | <- the number and writes
  453.                        ---------------    the new value to the
  454.                                           file. (10 + 3 = 13)
  455.  
  456.  
  457. As you can see, the number that was updated by process A, has
  458. been lost. What should have happen was that process A should
  459. have "locked" the file so no other tasks could work with it.
  460. Process B would then have been forced to wait for Process A
  461. to "unlock" the file before it could read the value.
  462.  
  463. On large mainframe computers there exist different "locks"
  464. with different priorities, but on the Amiga there exist only
  465. two different types of lock. You can lock a file so other
  466. processes may read it but not change it (SHARED_LOCK), or if
  467. you do not want any other tasks to even read the file you set
  468. an EXCLUSIVE_LOCK. Call the function Lock() to set a lock:
  469.  
  470. Synopsis:  lock = Lock( file_name, mode );
  471.  
  472. lock:      (BPTR) Actually a pointer to a FileLock structure.
  473.  
  474. file_name: (char *) Pointer to a text string which contains
  475.            the file name including any necessary devices/
  476.            directories.
  477.  
  478. mode:      (long) Accessmode:
  479.              SHARED_LOCK:     Other processes may read the file.
  480.              ACCESS_READ:                 - " -
  481.              EXCLUSIVE_LOCK:  No other processes may use this f.
  482.              ACCESS_WRITE:                - " -
  483.  
  484. Here is an example how to lock a file so no other processes
  485. may use the file:
  486.  
  487. struct FileLock *lock;
  488.  
  489. lock = Lock( "HighScore.dat", EXCLUSIVE_LOCK );
  490.  
  491. if( lock == NULL )
  492.   /* ERROR Could NOT create lock! */
  493.  
  494.  
  495. When you do not need the file any more you must "unlock" it.
  496. You do it by calling the function UnLock():
  497.  
  498. Synopsis: UnLock( lock );
  499.  
  500. lock:     (BPTR) Actually a pointer to FileLock structure
  501.           which has been initialized by a previous Lock()
  502.           call.
  503.  
  504. Remember to unlock ALL files you have locked!
  505.  
  506.  
  507.  
  508. 11.6  OTHER USEFUL FUNCTIONS
  509.  
  510. Here is a list of some other useful functions that you probably
  511. want to use. AmigaDOS allows you to rename and delete files,
  512. attach comments to them, set protection bits etc. All these
  513. things can be done with help of the functions listed below:
  514.  
  515.  
  516.  
  517. 11.6.1  CREATE DIRECTORIES
  518.  
  519. If you want to create a directory you use the function
  520. CreateDir(). You only need to give the function a pointer to
  521. the name of the directory you want to create, and it will
  522. either return a pointer to a Lock (the new directory is
  523. automatically given an EXCLUSIVE Lock), or NULL if something
  524. went wrong.
  525.  
  526. Remember to unlock the new directory before your program
  527. determinates.
  528.  
  529. If there already exist a directory with the same name, it is
  530. simply locked and your program will not notice any difference.
  531.  
  532.  
  533. Synopsis: lock = CreateDir( name );
  534.  
  535. lock:     (BPTR) Actually a pointer to a FileLock structure.
  536.           If lock is equal to NULL, AmigaDOS have not been
  537.           able to create the new directory.
  538.  
  539. name:     (char *) Pointer to a string containing the name
  540.           of the new directory.
  541.  
  542.  
  543. Here is a short example:
  544.  
  545. struct FileLock *lock;
  546.  
  547. lock = CreateDir( "RAM:MyDirectory" );
  548.  
  549. if( lock == NULL )
  550.   exit( ERROR );
  551.  
  552. ...
  553.  
  554. UnLock( lock );
  555.  
  556.  
  557.  
  558. 11.6.2  DELETE FILES AND DIRECTORIES
  559.  
  560. If you want to delete a file you call the function
  561. DeleteFile(). You only need to give it a file/directory name
  562. and it will either return TRUE (file was deleted) or FALSE
  563. (file could not be deleted). Remember that you can only delete
  564. a directory if it is empty.
  565.  
  566. Synopsis: ok = DeleteFile( name );
  567.  
  568. ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  569.           could delete the file/directory, else FALSE which
  570.           means something went wrong. (Eg. disk write-
  571.           protected, directory not empty etc.)
  572.  
  573. name:     (char *) Pointer to a string containing the name of
  574.           the file/directory you want to delete. 
  575.  
  576.  
  577.  
  578. 11.6.3  RENAME FILES AND DIRECTORIES
  579.  
  580. When you want to rename a file/directory you use the function
  581. Rename(). You can even move a file between directories by
  582. renaming it. For example:
  583.  
  584.   Rename( "df0:Documents/Sale.doc", "df0:Letters/Sale.doc" );
  585.  
  586. will move the file Sale.doc from the directory "Documents" to
  587. directory "Letters". Note! You can not rename a file from one
  588. volume to another.
  589.  
  590. Synopsis: ok = Rename( old_name, new_name );
  591.   
  592. ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  593.           could rename the file/directory, else FALSE which
  594.           means something went wrong. (Eg. disk write-
  595.      protected.)
  596.  
  597. old_name: (char *) Pointer to a string containing the old
  598.           file/directory name.
  599.  
  600. new_name: (char *) Pointer to a string containing the new
  601.           file/directory name.
  602.  
  603.  
  604.  
  605. 11.6.4  ATTACH COMMENTS TO FILES AND DIRECTORIES
  606.  
  607. AmigaDOS allows you to set a comment on a file or directory.
  608. The comment can give a brief description of what the file is,
  609. and is very handy to use when you want to give some extra
  610. information about the file etc. The comment can be up to 80
  611. characters long.
  612.  
  613. A program can set a comment to a file/directory by using the
  614. function SetComment(). 
  615.  
  616. Synopsis: ok = SetComment( name, comment );
  617.  
  618. ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  619.           could attach the new comment, else FALSE which
  620.           means something went wrong. (Eg. disk write-
  621.           protected.)
  622.  
  623. name:     (char *) Pointer to a string containing the name
  624.           of the file/directory you want to attach the
  625.           comment to.
  626.  
  627. comment:  (char *) Pointer to a string containing the
  628.           comment. (A comment may be up to 80 characters
  629.           long.)
  630.  
  631.  
  632. Here is a short example:
  633.  
  634. if( SetComment( "Letter.doc", "Letter to Mr Smith" ) == FALSE )
  635.   printf("ERROR! Could not attach the comment to the file!\n");
  636.  
  637.  
  638.  
  639. 11.6.5  PROTECT FILES AND DIRECTORIES
  640.  
  641. You can protect files and directory from being accidentally
  642. deleted or changed. You do it by calling the function
  643. SetProtection() which will alter the protection bits as
  644. desired. Here are a list of the protection bits (flags) you
  645. can change:
  646.   
  647.   FIBF_DELETE  : the file/directory can not be deleted.
  648.   FIBF_EXECUTE : the file can not be executed.
  649.   FIBF_WRITE   : you can not write to the file.
  650.   FIBF_READ    : you can not read the file.
  651.   FIBF_ARCHIVE : Archive bit.
  652.   FIBF_PURE    : Pure bit.
  653.   FIBF_SCRIPT  : Script bit.
  654.  
  655. Note! All of the flags are for the moment not working!
  656.   
  657. Synopsis: ok = SetProtection( name, mask );
  658.   
  659. ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  660.           could alter the protection bits, else FALSE which
  661.           means something went wrong. (Eg. disk write-
  662.           protected.)
  663.  
  664. name:     (char *) Pointer to a string containing the name of
  665.           the file/directory you want to change the protection
  666.           bits.
  667.  
  668. mask:     (long) The protection bits. (For example, if you
  669.           want to make the file/directory not deletable, and
  670.           that it can not be executed you should set the
  671.           protection bits: FIBF_DELETE | FIBF_EXECUTE.)
  672.  
  673.  
  674.  
  675. 11.7  EXAMINE FILES AND DIRECTORIES
  676.  
  677. You can examine a file or directory with the function
  678. Examine(). You give the function a pointer to a "lock" on
  679. the file/directory you want to examine, and it will initializes
  680. a FileInfoBlock structure for you. The FileInfoBlock structure
  681. contains several interesting fields which you then can look at.
  682.  
  683.  
  684.  
  685. 11.7.1  FILEINFOBLOCK AND DATESTAMP STRUCTURE
  686.  
  687. The FileInfoBlock look like this:
  688.  
  689. struct FileInfoBlock
  690. {
  691.   LONG fib_DiskKey;
  692.   LONG fib_DirEntryType;
  693.   char fib_FileName[108];
  694.   LONG fib_Protection;
  695.   LONG fib_EntryType;
  696.   LONG fib_Size;
  697.   LONG fib_NumBlocks;
  698.   struct DateStamp fib_Date;
  699.   char fib_Comment[80];
  700.   char fib_Reserved[36];
  701. };
  702.  
  703. fib_DiskKey:      Key number for the disk. Usually of no
  704.                   interest for us.
  705.  
  706. fib_DirEntryType: If the number is smaller than zero it is a
  707.                   file. On the other hand, if the number is
  708.                   larger than zero it is a directory.
  709.  
  710. fib_FileName:     Null terminated string containing the file-
  711.                   name. (Do not use longer filenames than 30
  712.                   characters.)
  713.  
  714. fib_Protection:   Field containing the protection flags:
  715.  
  716.                   FIBF_DELETE  : the file/directory can not be
  717.                                  deleted.
  718.                   FIBF_EXECUTE : the file can not be executed.
  719.                   FIBF_WRITE   : you can not write to the file.
  720.                   FIBF_READ    : you can not read the file.
  721.                   FIBF_ARCHIVE : Archive bit.
  722.                   FIBF_PURE    : Pure bit.
  723.                   FIBF_SCRIPT  : Script bit.
  724.  
  725.                   (Note! All of the flags are for the moment
  726.                   not working!)
  727.  
  728. fib_EntryType:   File/Directory entry type number. Usually of no
  729.                  interest for us.
  730.  
  731. fib_Size:        Size of the file (in bytes).
  732.  
  733. fib_NumBlocks:   Number of blocks in the file.
  734.  
  735. fib_Date:        Structure containing the date when the file
  736.                  was latest updated/created.
  737.  
  738. fib_Comment:     Null terminated string containing the file
  739.                  comment. (Max 80 characters including the NULL
  740.                  sign.)
  741.  
  742. fib_Reserved:    This field is for the moment reserved, and may
  743.                  therefore not be used.
  744.  
  745.  
  746. The DateStamp structure look like this:
  747.  
  748. struct DateStamp
  749. {
  750.   LONG ds_Days;
  751.   LONG ds_Minute;
  752.   LONG ds_Tick;
  753. };
  754.  
  755. ds_Days:   Number of days since 01-Jan-1978.
  756.  
  757. ds_Minute: Number of minutes past midnight.
  758.  
  759. ds_Tick:   Number of ticks past the last minute. There are 50
  760.            ticks / second. (50 * 60 = 3000 ticks / minute.)
  761.  
  762.  
  763.  
  764. 11.7.2  EXAMINE()
  765.  
  766. The Examine() function is called like this:
  767.  
  768. Synopsis: ok = Examine( lock, fib_ptr );
  769.  
  770. ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  771.           could get information about the file/directory, else
  772.           FALSE which means something went wrong.
  773.  
  774. lock:     (BPTR) Actually a pointer to a FileLock structure.
  775.  
  776. fib_ptr:  (struct FileInfoBlock *) Pointer to a FileInfoBlock
  777.           structure which will be initialized with some
  778.           information about the file/directory. IMPORTANT! the
  779.           structure must be on a 4 byte boundary. (See below
  780.           for more information.)
  781.  
  782.  
  783.  
  784. 11.7.3  4 BYTE BOUNDARY
  785.  
  786. There is one problem left. (Who said it should be easy?)
  787. AmigaDOS was not, as everything else on the Amiga, written in
  788. C. They used the BCPL programming language which is the
  789. predecessor of C. The problem is that BCPL only uses one data
  790. type - longword (LONG). ALL data which is handled by AmigaDOS
  791. must therefore be on a "4 byte boundary". (Are you with me?) To
  792. make sure that a structure starts on a 4 byte boundary you
  793. need to allocate the memory by using the function AllocMem().
  794. (Remember to deallocate the memory once you do not need it any
  795. more!)
  796.  
  797. So instead of writing:
  798.  
  799. --------------------------------------------------------------
  800. struct FileInfoBlock fib; /* Declare a FileInfoBlock called */
  801.                           /* fib. This structure may NOT    */
  802.                           /* necessary start on a 4 byte    */
  803.                           /* boundary!                      */
  804. --------------------------------------------------------------
  805.  
  806. You write:
  807.  
  808. --------------------------------------------------------------
  809. struct FileInfoBlock *fib_ptr; /* Declare a FileInfoBlock */
  810.                                /* pointer called fib_ptr. */
  811.  
  812. /* Allocate enough memory for a FileInfoBlock structure: */
  813. /* This memory WILL be on a 4 byte boundary!             */
  814. fib_ptr = AllocMem( sizeof( struct FileInfoBlock ),
  815.                     MEMF_PUBLIC | MEMF_CLEAR )
  816.  
  817. /* Check if we have allocated the memory successfully: */
  818. if( fib_ptr == NULL )
  819.   exit(); /* NOT ENOUGH MEMORY! */
  820.  
  821.  
  822. ... your program ...
  823.  
  824.  
  825. /* Deallocate the memory we have allocated for the fib. struct: */
  826. FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
  827.  
  828. --------------------------------------------------------------
  829.  
  830.  
  831.  
  832. 11.7.4  EXAMPLE
  833.  
  834. Here is an example which shows how to use the Examine()
  835. function: (Remember to deallocate all allocated memory and to
  836. unlock all locked files when your program terminates!)
  837.  
  838. #include <libraries/dos.h>
  839. #include <exec/memory.h>
  840.  
  841. main()
  842. {
  843.   struct FileLock *lock;
  844.   struct FileInfoBlock *fib_ptr; /* Declare a FileInfoBlock */
  845.                                  /* pointer called fib_ptr. */
  846.  
  847.  
  848.   /* 1. Allocate enough memory for a FileInfoBlock structure: */
  849.   fib_ptr = AllocMem( sizeof( struct FileInfoBlock ),
  850.                       MEMF_PUBLIC | MEMF_CLEAR )
  851.  
  852.   /* Check if we have allocated the memory successfully: */
  853.   if( fib_ptr == NULL )
  854.     exit(); /* NOT ENOUGH MEMORY! */
  855.  
  856.   
  857.   /* 2. Try to lock the file: */
  858.   lock = Lock( "highscore.dat", SHARED_LOCK )
  859.   
  860.   /* Could we lock the file? */
  861.   if( lock == NULL )
  862.   {
  863.     /* Deallocate the memory we have allocated: */
  864.     FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
  865.  
  866.     exit();
  867.   }
  868.  
  869.  
  870.   /* 3. Try to get some information about the file: */
  871.   if( Examine( lock, fib_ptr ) == NULL )
  872.   {
  873.     /* Deallocate the memory we have allocated: */
  874.     FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
  875.     
  876.     /* Unlock the file: */
  877.     UnLock( lock );  
  878.     
  879.     exit();
  880.   }
  881.  
  882.  
  883.   /* 4. You may now examine the FileInfoBlock structure! */
  884.  
  885.  
  886.   /* 5. Unlock the file: */
  887.   UnLock( lock );  
  888.  
  889.  
  890.   /* 6. Deallocate the memory we have allocated: */
  891.   FreeMem( fib_ptr, sizeof( struct FileInfoBlock ) );
  892. }
  893.  
  894.  
  895.  
  896. 11.7.5  EXAMINE FILES/SUBDIRECTORIES IN A DIRECTORY/DEVICE
  897.  
  898. A directory/device can contain several files plus several
  899. (sub)directories. If you want to examine not only a file/
  900. directory, but all files/directories in a directory/device the
  901. Examine() function is not enough. You need to use the function
  902. ExNext(), which works together with the Examine function.
  903.  
  904. To examine a directory/device you first need to call the
  905. function Examine() as normal. If it was a directory/device you
  906. start calling the function ExNext(), and continue calling it
  907. until you receive an error message. The error message is
  908. normally an "end of directory" message, which means that you
  909. have examined everything in the directory/device. It can also
  910. be some other error message which indicates that something
  911. went wrong while reading.
  912.  
  913.  
  914.  
  915. 11.7.5.1  EXNEXT()
  916.  
  917. The ExNext() function is very similar to Examine(). It is
  918. called like this:
  919.  
  920. Synopsis: ok = ExNext( lock, fib_ptr );
  921.  
  922. ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  923.           could get information about a file/directory in the
  924.           directory/device, else FALSE which means something
  925.           went wrong.
  926.  
  927. lock:     (BPTR) Actually a pointer to a FileLock structure.
  928.  
  929. fib_ptr:  (struct FileInfoBlock *) Pointer to a FileInfoBlock
  930.           structure which will be initialized with some
  931.           information about the file/directory. IMPORTANT! the
  932.           structure must be on a 4 byte boundary. (See above
  933.           for more information.)
  934.  
  935. Remember that you first need to call the function Examine(),
  936. and if it was a directory/device (fib_DirEntryType > 0), you
  937. may call the function ExNext() until you receive an error
  938. message.
  939.  
  940.  
  941.  
  942. 11.7.5.2  ERROR MESSAGES
  943.  
  944. When you have used an AmigaDOS function, and you have received
  945. an error message, you can call the function IoErr() to find out
  946. what went wrong. You do not send IoErr() any parameters, it
  947. only returns a flag (value) which tells your program what went
  948. wrong.
  949.  
  950. Here is the complete (V1.3) error list: (The header file
  951. "libraries/dos.h" contains the definitions.) I do not think I
  952. need to explain what they mean.
  953.  
  954.   ERROR_NO_FREE_STORE
  955.   ERROR_TASK_TABLE_FULL
  956.   ERROR_LINE_TOO_LONG
  957.   ERROR_FILE_NOT_OBJECT
  958.   ERROR_INVALID_RESIDENT_LIBRARY
  959.   ERROR_NO_DEFAULT_DIR
  960.   ERROR_OBJECT_IN_USE
  961.   ERROR_OBJECT_EXISTS
  962.   ERROR_DIR_NOT_FOUND
  963.   ERROR_OBJECT_NOT_FOUND
  964.   ERROR_BAD_STREAM_NAME
  965.   ERROR_OBJECT_TOO_LARGE
  966.   ERROR_ACTION_NOT_KNOWN
  967.   ERROR_INVALID_COMPONENT_NAME
  968.   ERROR_INVALID_LOCK
  969.   ERROR_OBJECT_WRONG_TYPE
  970.   ERROR_DISK_NOT_VALIDATED
  971.   ERROR_DISK_WRITE_PROTECTED
  972.   ERROR_RENAME_ACROSS_DEVICES
  973.   ERROR_DIRECTORY_NOT_EMPTY
  974.   ERROR_TOO_MANY_LEVELS
  975.   ERROR_DEVICE_NOT_MOUNTED
  976.   ERROR_SEEK_ERROR
  977.   ERROR_COMMENT_TOO_BIG
  978.   ERROR_DISK_FULL
  979.   ERROR_DELETE_PROTECTED
  980.   ERROR_WRITE_PROTECTED
  981.   ERROR_READ_PROTECTED
  982.   ERROR_NOT_A_DOS_DISK
  983.   ERROR_NO_DISK
  984.   ERROR_NO_MORE_ENTRIES
  985.  
  986.  
  987.   The IoErr() function is called like this:
  988.     
  989.   Synopsis: error = IoErr();
  990.   
  991.   error:    (long) This field contains one of the above
  992.             mentioned flags.
  993.  
  994.  
  995.   So when you use the function ExNext(), and you receive and
  996.   error message, you should call the function IoErr to check
  997.   what went wrong. If it was not ERROR_NO_MORE_ENTRIES (you
  998.   have checked everything in the directory), something terrible
  999.   went wrong (error while reading). 
  1000.  
  1001.  
  1002.  
  1003. 11.7.5.3  EXAMPLE
  1004.  
  1005. Here is parts of a program that examines everything inside a
  1006. directory/device, and prints out the filenames:
  1007.  
  1008. if( Examine( lock, fib_ptr ) )
  1009. {
  1010.   if( fib_ptr->fib_DirEntryType > 0 )
  1011.   {
  1012.     printf("Directory name: %s\n", fib_ptr->fib_FileName );
  1013.  
  1014.     while( ExNext( lock, fib_ptr ) )
  1015.     {
  1016.       printf("name: %s\n", fib_ptr->fib_FileName );
  1017.     }
  1018.     
  1019.     if( IoErr() == ERROR_NO_MORE_ENTRIES )
  1020.       printf("End of directory!\n");
  1021.     else
  1022.       printf("ERROR WHILE READING!!!\n");
  1023.   }
  1024.   else
  1025.     printf("This is a file!\n");
  1026. }
  1027. else
  1028.   printf("Could not examine the directory/device!\n");
  1029.  
  1030.  
  1031.  
  1032. 11.8  FUNCTIONS
  1033.  
  1034. Here is a list of commonly used functions:
  1035.  
  1036. Open()
  1037.  
  1038.   This function opens a file. Remember, before you can read/
  1039.   write files you have to open them. 
  1040.  
  1041.   Synopsis:    file_handle = Open( file_name, mode );
  1042.  
  1043.   file_handle: (BPTR) Actually a pointer to a FileHandle
  1044.                structure. If the system could not open the file
  1045.                with our requirements Open() returns NULL.
  1046.  
  1047.   file_name:   (char *) Pointer to a text string which contains
  1048.                the file name including any necessary devices/
  1049.                directories.
  1050.  
  1051.   mode:        (long) When you open a file you need to tell the
  1052.                system what you are going to do with it. This
  1053.                field should therefore contain one of the
  1054.                following flags:
  1055.  
  1056.                MODE_OLDFILE:   Opens an existing file for
  1057.                                reading and writing.
  1058.  
  1059.                MODE_NEWFILE:   Opens a new file for writing.
  1060.                                (If the file already exist it
  1061.                                is deleted.)
  1062.  
  1063.                MODE_READWRITE: Opens an old file with an
  1064.                                exclusive lock. (The file is
  1065.                                automatically locked with an
  1066.                                EXCLUSIVE_LOCK.)
  1067.  
  1068.                MODE_READONLY:  Same as MODE_OLDFILE.
  1069.  
  1070.  
  1071. Close()
  1072.  
  1073.   This function closes an already opened file. Remember to
  1074.   close ALL files you have opened!
  1075.  
  1076.   Synopsis:    Close( file_handle );
  1077.  
  1078.   file_handle: (BPTR) Actually a pointer to a FileHandle
  1079.                structure which has been initialized by a
  1080.                previous Open() call.
  1081.  
  1082.  
  1083. Read()
  1084.  
  1085.   This function reads a specified number of bytes from a file.
  1086.  
  1087.   Synopsis:    bytes_read = Read( file_handle, buffer, size );
  1088.  
  1089.   bytes_read:  (long) Number of bytes actually read. Even if
  1090.                you tell AmigaDOS that you want to read x
  1091.                number of bytes, it is not certain that you
  1092.                actually can do it. The file is maybe corrupted,
  1093.                not as big as you thought etc.
  1094.  
  1095.   file_handle: (BPTR) Actually a pointer to a FileHandle
  1096.                structure which has been initialized by a
  1097.                previous Open() call.
  1098.  
  1099.   buffer:      (char *) Pointer to the data buffer you want to
  1100.                read the data into.
  1101.  
  1102.   size:        (long) Number of bytes you want to read.
  1103.  
  1104.  
  1105. Write()
  1106.  
  1107.   This function writes a specified number of bytes to a file.
  1108.  
  1109.   Synopsis:  bytes_wr = Write( file_handle, buffer, size );
  1110.  
  1111.   bytes_wr:    (long) Number of bytes actually written. Even if
  1112.                you tell AmigaDOS that you want to write x number
  1113.                of bytes, it is not certain that you actually
  1114.                can do it. Maybe the disk was full, write-
  1115.                protected etc.
  1116.  
  1117.   file_handle: (BPTR) Actually a pointer to a FileHandle
  1118.                structure which has been initialized by a
  1119.                previous Open() call.
  1120.  
  1121.   buffer:      (char *) Pointer to the data buffer which you
  1122.                want to write.
  1123.  
  1124.   size:        (long) Number of bytes you want to write.
  1125.  
  1126.  
  1127. Seek()
  1128.  
  1129.   This function moves the "file cursor" inside a file:
  1130.  
  1131.   Synopsis:    old_pos = Seek( file_handle, new_pos, mode );
  1132.  
  1133.   old_pos:     (long) Previous position in the file, or -1 if
  1134.                an error occurred.
  1135.  
  1136.   file_handle: (BPTR) Actually a pointer to a FileHandle
  1137.                structure which has been initialized by a
  1138.                previous Open() call.
  1139.  
  1140.   new_pos:     (long) New position relative to the "mode".
  1141.  
  1142.   mode:        (long) The new_pos can be relative to:
  1143.                  OFFSET_BEGINNING: Beginning of the file.
  1144.                  OFFSET_CURRENT:   Current position.
  1145.                  OFFSET_END:       The end of the file.
  1146.  
  1147.  
  1148. Lock()
  1149.  
  1150.   This function "locks" a file so no other processes may alter
  1151.   the contents (SHARED_LOCK). You can even prevent other
  1152.   processes to read the file (EXCLUSIVE_LOCK).
  1153.  
  1154.   Synopsis: lock = Lock( name, mode );
  1155.  
  1156.   lock:     (BPTR) Actually a pointer to a FileLock structure.
  1157.  
  1158.   name:     (char *) Pointer to a text string which contains
  1159.             the file/directory name.
  1160.  
  1161.   mode:     (long) Accessmode:
  1162.               SHARED_LOCK:     Other tasks may read the file.
  1163.               ACCESS_READ:                 - " -
  1164.               EXCLUSIVE_LOCK:  No other tasks may use this f.
  1165.               ACCESS_WRITE:                - " -
  1166.  
  1167.  
  1168. UnLock()
  1169.  
  1170.   This function unlocks a previously locked file: (Remember to
  1171.   unlock ALL files you have locked!)
  1172.  
  1173.   Synopsis: Unlock( lock );
  1174.  
  1175.   lock:     (BPTR) Actually a pointer to FileLock structure
  1176.             which has been initialized by a previous Lock()
  1177.             call.
  1178.  
  1179.  
  1180. Rename()
  1181.  
  1182.   This function renames a file or directory. You can even
  1183.   move a file between directories by renaming it. (For example,
  1184.   Rename( "df0:Documents/Sale.doc", "df0:Letters/Sale.doc" );
  1185.   will move the file Sale.doc from the directory "Documents"
  1186.   to directory "Letters". Note! You can not rename a file from
  1187.   one volume to another.)
  1188.   
  1189.   Synopsis: ok = Rename( old_name, new_name );
  1190.   
  1191.   ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  1192.             could rename the file/directory, else FALSE which
  1193.             means something went wrong. (Eg. disk write
  1194.             -protected.)
  1195.  
  1196.   old_name: (char *) Pointer to a string containing the old
  1197.             file/directory name.
  1198.  
  1199.   new_name: (char *) Pointer to a string containing the new
  1200.             file/directory name.
  1201.  
  1202.  
  1203. SetComment
  1204.  
  1205.   This function attach a comment to a file or directory.
  1206.  
  1207.   Synopsis: ok = SetComment( name, comment );
  1208.  
  1209.   ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  1210.             could attach the new comment, else FALSE which
  1211.             means something went wrong. (Eg. disk write-
  1212.             protected.)
  1213.  
  1214.   name:     (char *) Pointer to a string containing the name
  1215.             of the file/directory you want to attach the
  1216.             comment to.
  1217.  
  1218.   comment:  (char *) Pointer to a string containing the
  1219.             comment. (A comment may be up to 80 characters
  1220.             long.)
  1221.  
  1222.  
  1223. SetProtection()
  1224.  
  1225.   This function alters the protection bits of a file.
  1226.   You can set following flags:
  1227.   
  1228.   FIBF_DELETE  : the file/directory can not be deleted.
  1229.   FIBF_EXECUTE : the file can not be executed.
  1230.   FIBF_WRITE   : you can not write to the file.
  1231.   FIBF_READ    : you can not read the file.
  1232.   FIBF_ARCHIVE : Archive bit.
  1233.   FIBF_PURE    : Pure bit.
  1234.   FIBF_SCRIPT  : Script bit.
  1235.  
  1236.   (Note! All of the flags are for the moment not working!)
  1237.   
  1238.   Synopsis: ok = SetProtection( name, mask );
  1239.   
  1240.   ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  1241.             could alter the protection bits, else FALSE which
  1242.             means something went wrong. (Eg. disk write-
  1243.             protected.)
  1244.  
  1245.   name:     (char *) Pointer to a string containing the name
  1246.             of the file/directory you want to change the
  1247.             protection bits.
  1248.  
  1249.   mask:     (long) The protection bits. (For example, if you
  1250.             want to make the file/directory not deletable,
  1251.             and that it can not be executed you should set the
  1252.             protection bits: FIBF_DELETE | FIBF_EXECUTE.)
  1253.  
  1254.  
  1255. DeleteFile()
  1256.  
  1257.   This function deletes a file or directory. Remember that
  1258.   a directory must be empty before it can be deleted.
  1259.  
  1260.   Synopsis: ok = DeleteFile( name );
  1261.  
  1262.   ok:       (long) Actually a Boolean. It is TRUE if AmigaDOS
  1263.             could delete the file/directory, else FALSE which
  1264.             means something went wrong. (Eg. disk write-
  1265.             protected, directory not empty etc.)
  1266.  
  1267.   name:     (char *) Pointer to a string containing the name
  1268.             of the file/directory you want to delete. 
  1269.  
  1270.  
  1271. CreateDir()
  1272.  
  1273.   This function creates a new directory, AND "locks" is
  1274.   automatically. (Remember to unlock the directory later on.)
  1275.  
  1276.   Synopsis: lock = CreateDir( name );
  1277.  
  1278.   lock:     (BPTR) Actually a pointer to a FileLock structure.
  1279.             If lock is equal to NULL, AmigaDOS have not been
  1280.             able to create the new directory.
  1281.  
  1282.   name:     (char *) Pointer to a string containing the name
  1283.             of the new directory.
  1284.  
  1285.  
  1286. CurrentDir()
  1287.  
  1288.   This function makes a specified directory "current
  1289.   directory". You need to lock the new directory (new_lock)
  1290.   before you can make it the current directory. The function
  1291.   returns the old current directories lock so you can unlock
  1292.   it if necessary.
  1293.   
  1294.   Synopsis: old_lock = CurrentDir( new_lock );
  1295.   
  1296.   old_lock: (BPTR) Actually a pointer to a FileLock structure.
  1297.             It is the old current directory lock.
  1298.   
  1299.   new_lock: (BPTR) Actually a pointer to a FileLock structure.
  1300.             The new current directory lock.
  1301.  
  1302.  
  1303. Info()
  1304.  
  1305.   This function returns information about a specified disk. You
  1306.   specify which disk by either lock that disk, or a file/
  1307.   directory on that disk.
  1308.  
  1309.   Synopsis:  ok = Info( lock, info_data );
  1310.   
  1311.   ok:        (long) Actually a Boolean. It is TRUE if AmigaDOS
  1312.              could get information about the disk, else FALSE
  1313.              which means something went wrong.
  1314.  
  1315.   lock:      (BPTR) Actually a pointer to a FileLock structure.
  1316.  
  1317.   info_data: (struct InfoData *) Pointer to an InfoData
  1318.              structure which will be initialized by the Info()
  1319.              function. The problem with this structure is that
  1320.              it must be on a four byte boundary, so you need
  1321.              to use the function AllocMem() to get the right
  1322.              type of memory for the structure. (See Example.)
  1323.  
  1324.  
  1325. IoErr()
  1326.  
  1327.   This function can be used to get more information about an
  1328.   error message. Whenever you have used an AmigaDOS function
  1329.   which did not work properly (you have received an error
  1330.   message), you call this function and it will return an
  1331.   explanation.
  1332.   
  1333.   Synopsis: error = IoErr();
  1334.   
  1335.   error:    (long) This field contains a flag returned by
  1336.             IoErr() which can be: (I do not think I need
  1337.             to explain what they mean.)
  1338.  
  1339.             ERROR_NO_FREE_STORE
  1340.             ERROR_TASK_TABLE_FULL
  1341.             ERROR_LINE_TOO_LONG
  1342.             ERROR_FILE_NOT_OBJECT
  1343.             ERROR_INVALID_RESIDENT_LIBRARY
  1344.             ERROR_NO_DEFAULT_DIR
  1345.             ERROR_OBJECT_IN_USE
  1346.             ERROR_OBJECT_EXISTS
  1347.             ERROR_DIR_NOT_FOUND
  1348.             ERROR_OBJECT_NOT_FOUND
  1349.             ERROR_BAD_STREAM_NAME
  1350.             ERROR_OBJECT_TOO_LARGE
  1351.             ERROR_ACTION_NOT_KNOWN
  1352.             ERROR_INVALID_COMPONENT_NAME
  1353.             ERROR_INVALID_LOCK
  1354.             ERROR_OBJECT_WRONG_TYPE
  1355.             ERROR_DISK_NOT_VALIDATED
  1356.             ERROR_DISK_WRITE_PROTECTED
  1357.             ERROR_RENAME_ACROSS_DEVICES
  1358.             ERROR_DIRECTORY_NOT_EMPTY
  1359.             ERROR_TOO_MANY_LEVELS
  1360.             ERROR_DEVICE_NOT_MOUNTED
  1361.             ERROR_SEEK_ERROR
  1362.             ERROR_COMMENT_TOO_BIG
  1363.             ERROR_DISK_FULL
  1364.             ERROR_DELETE_PROTECTED
  1365.             ERROR_WRITE_PROTECTED
  1366.             ERROR_READ_PROTECTED
  1367.             ERROR_NOT_A_DOS_DISK
  1368.             ERROR_NO_DISK
  1369.             ERROR_NO_MORE_ENTRIES
  1370.  
  1371.  
  1372.  
  1373. 11.9  EXAMPLES
  1374.  
  1375. Example1
  1376.   This program collects ten integer values from the user, and
  1377.   saves them in a file ("HighScore.dat") on the RAM disk. The
  1378.   memory is then cleared, and the file cursor is moved to the
  1379.   beginning of the file. The file is then loaded into the
  1380.   memory again, and printed out.
  1381.  
  1382. Example2
  1383.   This example demonstrates how to create a directory called
  1384.   "MyDirectory" on the RAM disk.
  1385.  
  1386. Example3
  1387.   This example demonstrates how to rename files and directories.
  1388.   It will rename the file Example 1 created (called
  1389.   "HighScore.dat") to "Numbers.dat". It will also rename the
  1390.   directory Example 2 created ("MyDirectory") to "NewDirectory".
  1391.  
  1392. Example4
  1393.   This example demonstrates how to delete files and directories.
  1394.   It will delete the file Example 1 and directory Example 2
  1395.   created. (The file and directory are supposed to have been
  1396.   renamed by Example 3.)
  1397.  
  1398. Example5
  1399.   This example demonstrates how to attach a short comment to a
  1400.   file. A short file called "Letter.doc" will be created, and a
  1401.   short comment will be attached. To see the comment use the
  1402.   CLI command "List".
  1403.  
  1404. Example6
  1405.   This example demonstrates how to protect and unprotect files.
  1406.   The file Example 5 created ("Letter.doc") will be protected,
  1407.   and we will then try to delete it (unsuccessfully). We will
  1408.   then unprotect the file and then try to delete it
  1409.   (successfully).
  1410.  
  1411. Example7
  1412.   This program takes a file/directory/device name as
  1413.   parameter, and prints out some interesting information about
  1414.   it.
  1415.  
  1416. Example8
  1417.   This program takes a directory/device name as parameter,
  1418.   and prints out all the file/directory-names inside it. This
  1419.   example describes how to use Examine() and ExNext().
  1420.