<< Previous | Next >>

fat_AutoMount

int fat_AutoMount( word flags );

Description

Initializes the drivers in the default drivers configuration list in fat_config.lib and enumerates the devices in the default devices configuration list, then mounts partitions on enumerated devices according to the device's default configuration flags, unless overridden by the specified run time configuration flags. Despite its lengthy description, this function makes initializing multiple devices using the FAT library as easy as possible. The first driver in the configuration list becomes the primary driver in the system, if one is not already set up.

After this routine successfully returns, the application can start calling directory and file functions for the devices' mounted partitions.

If devices and/or partitions are not already formatted, this function can optionally format them according to the device's configuration or run time override flags.

This function may be called multiple times, but will not attempt to remount device partitions that it has already mounted. Once a device partition has been mounted by this function, unmounts and remounts must be handled by the application.

Even though this function may be called multiple times, it is not meant to be used as a polling or status function. For example, if you are using removable media such as an SD card, you should call sdspi_debounceto determine when the card is fully inserted into the socket.

There are two arrays of data structures that are populated by calling fat_AutoMount(). The array named fat_part_mounted[] is an array of pointers to fat_part structures. A fat_part structure holds information about a specific FAT partition. The other array, _fat_device_table[], is composed of pointers to mbr_dev structures. An mbr_dev structure holds information about a specific device. Partition and device structures are needed in many FAT function calls to specify the device and partition to be used.

An example of using fat_part_mounted[] was shown in the sample program fat_create.c. FAT applications will need to scan fat_part_mounted[] to locate valid FAT partitions. A valid FAT partition must be identified before any file and directory operations can be performed. These pointers to FAT partitions may be used directly by indexing into the array or stored in a local pointer. The fat_shell.c sample uses an index into the array, whereas most other sample programs make a copy of the pointer.

An example of using _fat_device_table[] is in the sample program fat_shell.c. This array is used in FAT operations of a lower level than fat_part_mounted[]. Specifically, when the device is being partitioned, formatted and/or enumerated. Calling fat_AutoMount() relieves most applications of the need to directly use fat_device_table[].

Parameters

flags
Run-time device configuration flags to allow overriding the default device configuration flags. If not overriding the default configuration flags, specify FDDF_USE_DEFAULT. To override the default flags, specify the ORed combination of one or more of the following:

· FDDF_MOUNT_PART_0: Mount specified partition
· FDDF_MOUNT_PART_1:
· FDDF_MOUNT_PART_2:
· FDDF_MOUNT_PART_3:
· FDDF_MOUNT_PART_ALL: Mount all partitions
· FDDF_MOUNT_DEV_0: Apply to specified device
· FDDF_MOUNT_DEV_1:
· FDDF_MOUNT_DEV_2:
· FDDF_MOUNT_DEV_3:
· FDDF_MOUNT_DEV_ALL: Apply to all available devices
· FDDF_NO_RECOVERY: Use norecovery if fails first time
· FDDF_COND_DEV_FORMAT: Format device if unformatted
· FDDF_COND_PART_FORMAT: Format partition if unformatted
· FDDF_UNCOND_DEV_FORMAT: Format device unconditionally
· FDDF_UNCOND_PART_FORMAT: Format partition unconditionally
NOTE The FDDF_MOUNT_PART_* flags apply equally to all FDDF_MOUNT_DEV_* devices which are specified. If this is a problem, call this function multiple times with a single DEV flag bit each time.
NOTE Formatting the device creates a single FAT partition covering the entire device. It is recommended that you always set the *_PART_FORMAT flag bit if you set the corresponding *_DEV_FORMAT flag bit.

Return Value

0: success
-EBADPART: partition is not a valid FAT partition
-EIO: Device I/O error
-EINVAL: invalid prtTable
-EUNFORMAT: device is not formatted
-ENOPART: no partitions exist on the device
-EBUSY: For non-blocking mode only, the device is busy. Call this function again to complete the close.

Any other negative value means that an I/O error occurred when updating the directory entry. In this case, the file is forced to close, but its recorded length might not be valid.

Library

FAT.LIB

See Also

fat_EnumDevice, fat_EnumPartition, fat_MountPartition


Dynamic C Functions << Previous | Next >> rabbit.com