This is Alberts BLKRRPART ioctl() C code

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <setjmp.h>
#include <errno.h>
#include <getopt.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>

#define BLKRRPART    _IO(0x12,95)    /* re-read partition table */
#define BLKGETSIZE   _IO(0x12,96)    /* return device size */
#define BLKFLSBUF    _IO(0x12,97)    /* flush buffer cache */
#define BLKSSZGET    _IO(0x12,104)   /* get block device sector size */
#define BLKGETSIZE64 _IOR(0x12,114,size_t)      /* size in bytes */

int 
main(int argc, char **argv) {
        int fd = 0, error = 0;
        int i;
	char name[] ="/dev/mmc/disc0/disc";
//	char name[] ="/dev/mmcda";
	
	if ((fd = open(name, O_RDWR)) < 0) {
		if ((fd = open(name, O_RDONLY)) < 0) {
			printf("Failed to open %s, error[%d]: %s\n",
				name, error, strerror(error));
			exit(1);
		}
	}


        printf("Calling ioctl() to re-read partition table.\n");
        sync();
        sleep(2);
        if ((i = ioctl(fd, BLKRRPART)) != 0) {
                error = errno;
        } else {
                /* give it another chance */
                sync();
                sleep(2);
                if ((i = ioctl(fd, BLKRRPART)) != 0)
                        error = errno;
        }

        if (i) {
                printf("Re-reading the partition table failed with error %d: %s.\n",
                        error, strerror(error));
        }


        if (fsync(fd) || close(fd)) {
                printf("Error closing %s\n", name);
                exit(1);
        }

	exit(0);
}
This page was last modified 13:49, 21 June 2006. | This page has been accessed 1,023 times. | About OpenSIMpad.org
Designed by Anna Boheim | Powerd by mediawiki