다른 방법으로 마운트되거나 사용되지 않는 드라이브에 스핀 다운이 필요한 프로그램이 있습니다.파일 디스크립터가 닫힌 후 SCSI 드라이브 스핀 업
필자가 filedescriptor를 닫은 후에 자동으로 드라이브가 회전하는 것으로 나타났습니다.
왜 이런 정보를 발견하지 못 했습니까? 이것을 비활성화하는 방법이 있습니까?
다음은 직접 테스트하는 간단한 프로그램입니다. 모든 도움이나 조언을 부탁드립니다
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <scsi/sg.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
sg_io_hdr_t io_hdr;
const unsigned char stopcmdblk[6] = { 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00 };
int fd = open(argv[1], O_RDWR);
if (fd == -1) {
perror("couldn't open device");
exit(1);
}
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
io_hdr.interface_id = 'S';
io_hdr.cmd_len = 6;
io_hdr.mx_sb_len = 32;
io_hdr.dxfer_direction = SG_DXFER_NONE;
io_hdr.dxfer_len = 0;
io_hdr.dxferp = NULL;
io_hdr.cmdp = malloc(6);
io_hdr.sbp = calloc(32, 1);
memcpy(io_hdr.cmdp, stopcmdblk, 6);
errno = 0;
int ret = ioctl(fd, SG_IO, &io_hdr);
if (ret < 0) {
perror("ioctl error");
exit(1);
}
if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK) {
printf("SCSI err\n");
exit(1);
}
printf("finished spindown\n");
sleep(30);
printf("close file now\n");
close(fd);
printf("file closed\n");
exit(0);
}
파일 시스템이 파일 잠금 (숨겨진 잠금 파일 또는 유사)에 대한 정보를 디스크에 유지할 수 있습니까? R/W 파일을 열어야 잠겨 야합니다. 디스크에 액세스하는 네트워크의 다른 Linux 노드는이 정보를 읽고 안전하게 파일에 액세스 할 수 있는지 여부를 판별 할 수 있습니다. 그런 다음 파일을 닫으면 스핀 업 (spin-up)되어 디스크에서 잠금을 제거 할 수 있습니다. –
파일을 닫은 후에 강제로 잠금을 설정할 수 있습니까? 스핀 다운이 끝나면 디스크에 아무 것도 쓰지 않기 때문에 드라이브가 제거 될 것입니다. –