/* * sgtblsz.c - Look up max number of scatter-gather table entries on * an SG device * * Copyright (C) 2006 Oracle Corporation * Written by Martin K. Petersen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include int die (const char *fmt, ...) { va_list val; va_start(val, fmt); vfprintf(stderr, fmt, val); if (errno != 0) fprintf(stderr, ": %s", strerror(errno)); fprintf(stderr, "\n"); va_end(val); exit(EXIT_FAILURE); } int main (int argc, char *argv[]) { int fd; struct stat st; unsigned long num; if (argc < 2) die("Must specify sg device to query"); if ((fd = open(argv[1], O_RDONLY)) < 0) die("Can't open %s", argv[1]); if (stat(argv[1], &st) < 0) die("Can't stat device %s", argv[1]); if (!S_ISCHR(st.st_mode)) die("Argument must be an sg device"); if (ioctl(fd, SG_GET_VERSION_NUM, &num) < 0) die("%s is not an sg device", argv[1]); if (ioctl(fd, SG_GET_SG_TABLESIZE, &num) < 0) die("Can't get table size from sg device"); printf("Max sgl entries for %s = %ld\n", argv[1], num); exit(EXIT_SUCCESS); }