Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/     Datei vom 5.9.2011 mit Größe 1 kB image not shown  

Quelle  diskid.c   Sprache: C

 
//$ fdisk -cul /dev/sdb
//Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
//255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
//Units = sectors of 1 * 512 = 512 bytes
//Sector size (logical/physical): 512 bytes / 512 bytes
//I/O size (minimum/optimal): 512 bytes / 512 bytes
//Disk identifier: 0x790b1f29
//
//   Device Boot      Start         End      Blocks   Id  System
// /dev/sdb1              63  1953520064   976760001   fd  Linux raid autodetect
//
// $ gcc --std=c99 -o ndi ndi.c
// $ ./ndi /dev/sdb
// $ fdisk -cul /dev/sdb
// Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
// 255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
// Units = sectors of 1 * 512 = 512 bytes
// Sector size (logical/physical): 512 bytes / 512 bytes
// I/O size (minimum/optimal): 512 bytes / 512 bytes
// Disk identifier: 0xdeadbeef
// 
//   Device Boot      Start         End      Blocks   Id  System
// /dev/sdb1              63  1953520064   976760001   fd  Linux raid autodetect

#include <stdio.h>
#define NEW_DISK_IDENT 0xDEADBEEF
#define IDENT_POSITION 0x1B8
#define IDENT_LENGTH 4 

void readDiskIdentifier(FILE* fp)
  {
  fseek(fp, IDENT_LENGTH - 1 + IDENT_POSITION, SEEK_SET);
  for(int i = 0; i < IDENT_LENGTH; i++)
  {
  printf("%0*X", 2, fgetc(fp));
    fseek(fp, -2, SEEK_CUR);
    }
    printf("\n");
}

void writeDiskIdentifier(FILE* fp)
  {
  fseek(fp, IDENT_POSITION, SEEK_SET);
  for(int i = 0; i < IDENT_LENGTH; i++)
  fputc(0xFF & (NEW_DISK_IDENT >> i*8), fp);
  }
  
  int main(int argc, char **argv)
  {
  if (argc > 1)
  {
  printf("%s\n", argv[1]);
    FILE* fp = fopen(argv[1], "r+");
    printf("Current disk identifier: ");
    readDiskIdentifier(fp);
    writeDiskIdentifier(fp);
    printf("New disk identifier: ");
    readDiskIdentifier(fp);
    fclose(fp);
    return 0;
    } else
  printf(" usage: %s file\n Example: %s /dev/sdb\n", argv[0],
  argv[0]);
  return -2;
  
}

70%


¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.