cmd/xfsprogs/libdm/dmapi_tests/README 1.1 Renamed to cmd/xfstests/dmapi/README
[xfstests-dev.git] / dmapi / src / suite1 / cmd / punch_hole.c
diff --git a/dmapi/src/suite1/cmd/punch_hole.c b/dmapi/src/suite1/cmd/punch_hole.c
new file mode 100644 (file)
index 0000000..e1137ed
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * 
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * 
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like.  Any license provided herein, whether implied or
+ * otherwise, applies only to this software file.  Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ * 
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA  94043, or:
+ * 
+ * http://www.sgi.com 
+ * 
+ * For further information regarding this notice, see: 
+ * 
+ * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ */
+
+#include <lib/hsm.h>
+
+#ifdef linux
+#include <string.h>
+#endif
+
+/*---------------------------------------------------------------------------
+
+Test program used to test the DMAPI function dm_punch_hole().  The
+command line is:
+
+       punch_hole [-o offset] [-l length] [-s sid] pathname
+
+where pathname is the name of a file, offset is the offset of the start of
+the punch, and length is the length of the punch.  sid is the
+session ID whose events you you are interested in.
+
+----------------------------------------------------------------------------*/
+
+#ifndef linux
+extern char    *sys_errlist[];
+#endif
+extern  int     optind;
+extern  char    *optarg;
+
+
+char   *Progname;
+
+
+static void
+usage(void)
+{
+       int     i;
+
+       fprintf(stderr, "usage:\t%s [-o offset] [-l length] "
+               "[-s sid] pathname\n", Progname);
+       exit(1);
+}
+
+
+int
+main(
+       int     argc, 
+       char    **argv)
+{
+       dm_sessid_t     sid = DM_NO_SESSION;
+       char            *pathname = NULL;
+       dm_off_t        offset = 0;
+       dm_size_t       length = 0;
+       void            *hanp;
+       size_t          hlen;
+       char            *name;
+       int             opt;
+       int             i;
+
+       if (Progname = strrchr(argv[0], '/')) {
+               Progname++;
+       } else {
+               Progname = argv[0];
+       }
+
+       /* Crack and validate the command line options. */
+
+       while ((opt = getopt(argc, argv, "o:l:s:")) != EOF) {
+               switch (opt) {
+               case 'o':
+                       offset = atol(optarg);
+                       break;
+               case 'l':
+                       length = atol(optarg);
+                       break;
+               case 's':
+                       sid = atol(optarg);
+                       break;
+               case '?':
+                       usage();
+               }
+       }
+       if (optind + 1 != argc)
+               usage();
+       pathname = argv[optind];
+
+       if (dm_init_service(&name) == -1)  {
+               fprintf(stderr, "Can't inititalize the DMAPI\n");
+               exit(1);
+       }
+       if (sid == DM_NO_SESSION)
+               find_test_session(&sid);
+
+       /* Get the file's handle. */
+
+       if (dm_path_to_handle(pathname, &hanp, &hlen)) {
+               fprintf(stderr, "can't get handle for file %s\n", pathname);
+               exit(1);
+       }
+
+       if (dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, offset, length)) {
+               fprintf(stderr, "dm_punch_hole failed, %s\n",
+                       strerror(errno));
+               exit(1);
+       }
+       dm_handle_free(hanp, hlen);
+       exit(0);
+}