NFC Tag usage with Linux

Hi all
the example provided is Arduino based, nothing is readily available for Linux. The following info is easy stuff but since it took me a couple of hours I think it’s worth sharing.
From the M24LR64E-R datasheet you can see that to read random EEPROM locations you should:
Select the device
Write the 2 bytes address
Select the device
Read data

To perform such kind of operation you need little bit more of control than the standard read/write syscalls, that is you need to use the IOCTL interface with I2C_RDWR IOCTL. See relevant info in i2c-dev.h and uapi/i2c.h. See an example below:

int i2c_read_registers(int file, unsigned char device_addr, unsigned char* reg, void* outbuf, unsigned int outbuf_length)
    struct i2c_rdwr_ioctl_data packets;
    struct i2c_msg messages[2];

    /* First push out the 2 bytes address */
    messages[0].addr  = device_addr;
    messages[0].flags = 0;
    messages[0].len   = 2;
    messages[0].buf   = (__u8*)reg;

    /* Incoming data here */
    messages[1].addr  = device_addr;
    messages[1].flags = I2C_M_RD;
    messages[1].len   = outbuf_length;
    messages[1].buf   = outbuf;

    /* Write & read "transaction" */
    packets.msgs = messages;
    packets.nmsgs = 2;
    if (ioctl(file, I2C_RDWR, &packets) < 0) {
        perror("Unable to perform EEPROM read transaction");
        return -1;

    return 0;

Thank you so much for sharing the information in the community.