An answer from 7 years later:
Currently (2023.4), you'd better to use a library libi2c to alleviate I2C development, instead of fully using ioctls and linux/i2c.h. Actually it is a shallow API wrapper for the I2C/SMBus declaration in linux kernel.
Edit:
You even don't need any libraries, it is actually integrated inside the Linux I2C driver if your device conforms to the SMBus behavior. What you need is only:
- Open the i2c file device by
open("/dev/i2c-X", O_RDWR ).
- Set the current using slave address by
fcntl(fd, I2C_SLAVE, YOUR_SLAVE_ADDRESS). The macro I2C_SLAVE is defined in linux/i2c-dev.h.
- Perform simple
read and write on the file descriptor. Corresponding SMBus transaction is automatically performed by underlying Linux I2C driver.
These operations are enough for operating all functions of BH1750 ambient light sensor.