接上篇的setmax.c

/* setmax.c - aeb, 000326 - use on 2.4.0test9 or newer */
/* IBM part thanks to Matan Ziv-Av <matan@svgalib.org> */
/*
 * Results on Maxtor disks:
 * The jumper that clips capacity does not influence the value returned
 * by READ_NATIVE_MAX_ADDRESS, so it is possible to set the jumper
 * and let the kernel, or a utility (like this one) run at boot time
 * restore full capacity.
 * For example, run "setmax -d 0 /dev/hdX" for suitable X.
 * Kernel patches exist that do the same.
 *
 * Results on IBM disks:
 * The jumper that clips capacity is ruthless. You clipped capacity.
 * However, if your BIOS hangs on a large disk, do not use the jumper
 * but find another machine and use a utility (like this one) to
 * clip the non-volatile max address.
 * For example, run "setmax -m 66055248 /dev/hdX" for suitable X.
 * Now go back to your first machine and proceed as with Maxtor drives above.
 */
#include <stdio.h>
#include <fcntl.h>
#include <getopt.h>
#include <linux/hdreg.h>

#ifndef HDIO_DRIVE_CMD_AEB
#define HDIO_DRIVE_CMD_AEB 0x031e
#endif

#define INITIALIZE_DRIVE_PARAMETERS 0x91
#define READ_NATIVE_MAX_ADDRESS 0xf8
#define CHECK_POWER_MODE 0xe5
#define SET_MAX   0xf9

#define LBA 0x40
#define VV 1  /* if set in sectorct then NOT volatile */

struct idecmdin {
 unsigned char cmd;
 unsigned char feature;
 unsigned char nsect;
 unsigned char sect, lcyl, hcyl;
 unsigned char select;
};

struct idecmdout {
 unsigned char status;
 unsigned char error;
 unsigned char nsect;
 unsigned char sect, lcyl, hcyl;
 unsigned char select;
};

unsigned int
tolba(unsigned char *args) {
 return ((args[6] & 0xf) << 24) + (args[5] << 16) + (args[4] << 8) + args[3];
}

void
fromlba(unsigned char *args, unsigned int lba) {
 args[3] = (lba & 0xff);
 lba >>= 8;
 args[4] = (lba & 0xff);
 lba >>= 8;
 args[5] = (lba & 0xff);
 lba >>= 8;
 args[6] = (args[6] & 0xf0) | (lba & 0xf);
}

int
get_identity(int fd) {
 unsigned char args[4+512] = {WIN_IDENTIFY,0,0,1,};
 struct hd_driveid *id = (struct hd_driveid *)&args[4];

 if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
  perror("HDIO_DRIVE_CMD");
  fprintf(stderr,
   "WIN_IDENTIFY failed - trying WIN_PIDENTIFY/n");
  args[0] = WIN_PIDENTIFY;
  if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
   perror("HDIO_DRIVE_CMD");
   fprintf(stderr,
          "WIN_PIDENTIFY also failed - giving up/n");
   exit(1);
  }
 }

 printf("lba capacity: %d sectors (%lld bytes)/n",
        id->lba_capacity,
        (long long) id->lba_capacity * 512);
}

/*
 * result: in LBA mode precisely what is expected
 *         in CHS mode the correct H and S, and C mod 65536.
 */
unsigned int
get_native_max(int fd, int slave) {
 unsigned char args[7];
 int i, max;

 for (i=0; i<7; i++)
  args[i] = 0;
 args[0] = READ_NATIVE_MAX_ADDRESS;
 args[6] = (slave ? 0x10 : 0) | LBA;
 if (ioctl(fd, HDIO_DRIVE_CMD_AEB, &args)) {
  perror("HDIO_DRIVE_CMD_AEB failed READ_NATIVE_MAX_ADDRESS");
  for (i=0; i<7; i++)
   printf("%d = 0x%x/n", args[i], args[i]);
  exit(1);
 }
 return tolba(args);
}

/*
 * SET_MAX_ADDRESS requires immediately preceding READ_NATIVE_MAX_ADDRESS
 *
 * On old Maxtor disk: this fails for delta <= 254, succeeds for delta >= 255.
 * (So, in order to get the last 255*512=130560 bytes back one has to reboot.
 * Side effect: reset to CurCHS=16383/16/63, CurSects=16514064.)
 * On new Maxtor disk: this works.
 * On IBM disk without jumper: this works.
 */
void
set_max_address(int fd, int slave, int delta, int max, int volat) {
 unsigned char args[7];
 int i, nativemax, newmax;

 nativemax = get_native_max(fd, slave);
 printf("nativemax=%d (0x%x)/n", nativemax, nativemax);

 for (i=0; i<7; i++)
  args[i] = 0;
 args[0] = SET_MAX;
 args[1] = 0;
 args[2] = (volat ? 0 : 1);
 if (delta != -1)
  newmax = nativemax-delta;
 else
  newmax = max-1;
 fromlba(args, newmax);
 args[6] |= LBA;

 if (ioctl(fd, HDIO_DRIVE_CMD_AEB, &args)) {
  perror("HDIO_DRIVE_CMD_AEB failed SET_MAX");
  for (i=0; i<7; i++)
   printf("%d = 0x%x/n", args[i], args[i]);
  exit(1);
 }
}

static char short_opts[] = "d:m:";
static const struct option long_opts[] = {
 { "delta", required_argument, NULL, 'd' },
 { "max", required_argument, NULL, 'm' },
        { NULL, 0, NULL, 0 }
};

static char *usage_txt =
"Call: setmax [-d D] [-m M] DEVICE/n"
"/n"
"The call  /"setmax --max M DEVICE/"  will do a SET_MAX command/n"
"to set the non-volatile max number of accessible sectors to M./n"
"/n"
"The call  /"setmax --delta D DEVICE/"  will do a SET_MAX command/n"
"to set the maximum accessible sector number D sectors/n"
"below end-of-disk./n"
"/n"
"The call  /"setmax DEVICE/"  will do a READ_NATIVE_MAX_ADDRESS/n"
"command, and report the maximum accessible sector number./n"
"/n"
"This is IDE-only. Probably DEVICE is /dev/hdx for some x./n/n";

main(int argc, char **argv){
 int fd, c;
 int delta, max, volat;

 /* If you modify device, also update slave, if necessary. */
 /* The kernel already does this for us since 2.4.0test9. */
 /* master: hda, hdc, hde; slave: hdb, hdd, hdf */
 char *device = NULL; /* e.g. "/dev/hda" */
 int slave = 0;

 delta = max = volat = -1;
 while ((c = getopt_long (argc, argv, short_opts, long_opts, NULL)) != -1) {
  switch(c) {
  case 'd':
   delta = atoi(optarg);
   volat = 1;
   break;
  case 'm':
   max = atoi(optarg);
   volat = 0;
   break;
  case '?':
  default:
   fprintf(stderr, "unknown option/n");
   fprintf(stderr, usage_txt);
   exit(1);
  }
 }

 if (optind < argc)
  device = argv[optind];
 if (!device) {
  fprintf(stderr, "no device specified - "
   "use e.g. /"setmax /dev/hdb/"/n");
  fprintf(stderr, usage_txt);
  exit(1);
 }
 printf("Using device %s/n", device);

 fd = open(device, O_RDONLY);
 if (fd == -1) {
  perror("open");
  exit(1);
 }

 if (delta != -1 || max != -1) {
  if (delta != -1)
   printf("setting delta=%d/n", delta);
  else
   printf("setting max=%d/n", max);
  set_max_address(fd, slave, delta, max, volat);
 } else {
  int mad = get_native_max(fd, slave);
  long long bytes = (long long) (mad+1) * 512;
  int hMB = (bytes+50000000)/100000000;

  printf("native max address: %d/n", mad);
  printf("that is %lld bytes, %d.%d GB/n",
         bytes, hMB/10, hMB%10);
 }
 get_identity(fd);

 return 0;
下载方式:https://pan.quark.cn/s/a4b39357ea24 在纺织制造领域中,纱线的品质水平对最终制成品的整体质量具有决定性作用。 鉴于消费者对于产品规格和样式要求的不断变化,纺织制造工艺的执行过程日益呈现为一种更为复杂的操作体系,进而导致对纱线质量进行预测的任务变得更加困难。 在众多预测技术中,传统的预测手段在面对多变量间相互交织的复杂关系时,往往显得力不从心。 因此,智能计算技术在预测纱线质量的应用场景中逐渐占据核心地位,其中人工神经网络凭借其卓越的非线性映射特性以及自适应学习机制,成为了众多预测方法中的一种重要选择。 在智能计算技术的范畴内,粒子群优化算法(PSO)和反向传播神经网络(BP神经网络)是两种被广泛采用的技术方案。 粒子群优化算法是一种基于群体智能理念的优化技术,它通过模拟鸟类的群体觅食行为来寻求最优解,该算法因其操作简便、执行高效以及具备优秀的全局搜索性能,在函数优化、神经网络训练等多个领域得到了普遍应用。 反向传播神经网络则是一种由多层节点构成的前馈神经网络,它通过误差反向传播的机制来实现网络权重和阈值的动态调整,从而达成学习与预测的目标。 在实际操作层面,反向传播神经网络因其架构设计简洁、实现过程便捷,因此被广泛部署于各类预测和分类任务之中。 然而,该方法也存在一些固有的局限性,例如容易陷入局部最优状态、网络收敛过程缓慢等问题。 而粒子群优化算法在参与神经网络优化时,能够显著增强神经网络的全局搜索性能并提升收敛速度,有效规避神经网络陷入局部最优的困境。 将粒子群优化算法与反向传播神经网络相结合形成的PSO-BP神经网络,通过运用粒子群优化算法对反向传播神经网络的权值和阈值进行精细化调整,能够在预测纱线断裂强度方面,显著提升预测结果的...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值