Browse Source

Move the confirmation to a separate function, as is done in i2cget

already.


git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5209 7894878c-1315-0410-8ee3-d5d059ff63e0
tags/v3.0.2
Jean Delvare 18 years ago
parent
commit
8603e2aab2
  1. 1
      CHANGES
  2. 66
      tools/i2cset.c

1
CHANGES

@ -13,6 +13,7 @@ SVN
i2cset: Support i2c bus passed by name
Shorten the usage message
Restrict the chip address to 0x03-0x77
Split the code into several functions for clarity
3.0.1 (2008-04-04)
Drop the trailing .pl from all perl script names

66
tools/i2cset.c

@ -83,6 +83,40 @@ static int check_funcs(int file, int i2cbus, int size, int pec)
return 0;
}
static int confirm(const char *filename, int address, int size, int daddress,
int value, int vmask, int pec)
{
int dont = 0;
fprintf(stderr, "WARNING! This program can confuse your I2C "
"bus, cause data loss and worse!\n");
if (address >= 0x50 && address <= 0x57) {
fprintf(stderr, "DANGEROUS! Writing to a serial "
"EEPROM on a memory DIMM\nmay render your "
"memory USELESS and make your system "
"UNBOOTABLE!\n");
dont++;
}
fprintf(stderr, "I will write to device file %s, chip address "
"0x%02x, data address\n0x%02x, data 0x%02x%s, mode "
"%s.\n", filename, address, daddress, value,
vmask ? " (masked)" : "",
size == I2C_SMBUS_BYTE_DATA ? "byte" : "word");
if (pec)
fprintf(stderr, "PEC checking enabled.\n");
fprintf(stderr, "Continue? [%s] ", dont ? "y/N" : "Y/n");
fflush(stderr);
if (!user_ack(!dont)) {
fprintf(stderr, "Aborting on user request.\n");
return 0;
}
return 1;
}
int main(int argc, char *argv[])
{
char *end;
@ -170,35 +204,9 @@ int main(int argc, char *argv[])
|| set_slave_addr(file, address, force))
exit(1);
if (!yes) {
int dont = 0;
fprintf(stderr, "WARNING! This program can confuse your I2C "
"bus, cause data loss and worse!\n");
if (address >= 0x50 && address <= 0x57) {
fprintf(stderr, "DANGEROUS! Writing to a serial "
"EEPROM on a memory DIMM\nmay render your "
"memory USELESS and make your system "
"UNBOOTABLE!\n");
dont = 1;
}
fprintf(stderr, "I will write to device file %s, chip address "
"0x%02x, data address\n0x%02x, data 0x%02x%s, mode "
"%s.\n", filename, address, daddress, value,
vmask ? " (masked)" : "",
size == I2C_SMBUS_BYTE_DATA ? "byte" : "word");
if (pec)
fprintf(stderr, "PEC checking enabled.\n");
fprintf(stderr, "Continue? [%s] ", dont ? "y/N" : "Y/n");
fflush(stderr);
if (!user_ack(!dont)) {
fprintf(stderr, "Aborting on user request.\n");
exit(0);
}
}
if (!yes && !confirm(filename, address, size, daddress,
value, vmask, pec))
exit(0);
if (vmask) {
int oldvalue;

Loading…
Cancel
Save