mksnap_ffs.c revision 111725
173050Smsmith/* 273050Smsmith * Copyright (c) 2003 Networks Associates Technology, Inc. 373050Smsmith * All rights reserved. 473050Smsmith * 573050Smsmith * This software was developed for the FreeBSD Project by Marshall 673050Smsmith * Kirk McKusick and Network Associates Laboratories, the Security 773050Smsmith * Research Division of Network Associates, Inc. under DARPA/SPAWAR 873050Smsmith * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS 973050Smsmith * research program. 1073050Smsmith * 1173050Smsmith * Redistribution and use in source and binary forms, with or without 1273050Smsmith * modification, are permitted provided that the following conditions 1373050Smsmith * are met: 1473050Smsmith * 1. Redistributions of source code must retain the above copyright 1573050Smsmith * notice, this list of conditions and the following disclaimer. 1673050Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1773050Smsmith * notice, this list of conditions and the following disclaimer in the 1873050Smsmith * documentation and/or other materials provided with the distribution. 1973050Smsmith * 3. The names of the authors may not be used to endorse or promote 2073050Smsmith * products derived from this software without specific prior written 2173050Smsmith * permission. 2273050Smsmith * 2373050Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2473050Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2573050Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2673050Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2773050Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2873050Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2973050Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3073050Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3173050Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3273050Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3373050Smsmith * SUCH DAMAGE. 3473050Smsmith * 3573050Smsmith * $FreeBSD: head/sbin/mksnap_ffs/mksnap_ffs.c 111725 2003-03-02 08:07:57Z mckusick $ 3673050Smsmith */ 3773050Smsmith 3873050Smsmith#include <sys/param.h> 3973050Smsmith#include <sys/mount.h> 4073050Smsmith#include <sys/stat.h> 4173050Smsmith#include <ufs/ufs/ufsmount.h> 4273050Smsmith#include <err.h> 4373050Smsmith#include <errno.h> 4473050Smsmith#include <fcntl.h> 4573050Smsmith#include <grp.h> 4673050Smsmith#include <stdio.h> 4773050Smsmith#include <stdlib.h> 4873050Smsmith#include <string.h> 4973050Smsmith#include <sysexits.h> 5073050Smsmith#include <unistd.h> 5173050Smsmith 5273050Smsmithvoid 5373050Smsmithusage() 5473050Smsmith{ 5573050Smsmith 5673050Smsmith fprintf(stderr, "usage: mksnap_ffs mountpoint file\n"); 5773050Smsmith exit(EX_USAGE); 5873050Smsmith} 5973050Smsmith 6073050Smsmithint 6173050Smsmithmain(int argc, char **argv) 6279695Smsmith{ 6379695Smsmith const char *dir; 6479695Smsmith struct ufs_args args; 6573050Smsmith struct group *grp; 6673050Smsmith struct stat stbuf; 6773050Smsmith int fd; 6873050Smsmith 6973050Smsmith if (argc != 3) 7073050Smsmith usage(); 71 72 dir = argv[1]; 73 args.fspec = argv[2]; 74 75 if ((grp = getgrnam("operator")) == NULL) 76 errx(1, "Cannot retrieve operator gid"); 77 if (mount("ffs", dir, MNT_UPDATE | MNT_SNAPSHOT, &args) < 0) 78 err(1, "Cannot create %s", args.fspec); 79 if ((fd = open(args.fspec, O_RDONLY)) < 0) 80 err(1, "Cannot open %s", args.fspec); 81 if (fstat(fd, &stbuf) != 0) 82 err(1, "Cannot stat %s", args.fspec); 83 if ((stbuf.st_flags & SF_SNAPSHOT) == 0) 84 errx(1, "File %s is not a snapshot", args.fspec); 85 if (fchown(fd, -1, grp->gr_gid) != 0) 86 err(1, "Cannot chown %s", args.fspec); 87 if (fchmod(fd, S_IRUSR | S_IRGRP) != 0) 88 err(1, "Cannot chmod %s", args.fspec); 89 90 exit(EXIT_SUCCESS); 91} 92