SDK Script mount-media.are

mount-media.are
/* DESC: This script can be used to mount an USB storage stick.
 * Copyright (C) 2012-2016 NetModule AG, Switzerland
 */
 
device = "usb0"; // or storage0
mntpoint = sprintf("/mnt/media/%s", device);
 
printf("Mounting '%s'", device);
ret = nb_media_mount(device);
if (ret == 0) {
    printf("Successfully mounted %s\n", device);
} else {
    printf("Unable to mount %s (rc %d)\n", ret, device);
    exit(1);
}
 
printf("\nMounted media:\n");
mounted = nb_media_getmount();
printf("%s\n", mounted);
 
printf("Files at %s:\n\n", mntpoint);
handle = opendir(mntpoint);
if (handle != -1) {
    while ((entry = readdir(handle))) {
        if (left(entry, 1) == ".") continue;
        printf("%s\n", entry);
    }
    closedir(handle);
} else {
    printf("cannot open directory %s", mntpoint);
}
 
 
printf("Umounting '%s'", device);
nb_media_umount(device);
 
exit(0);