mksnap_ffs.c revision 121707
1111716Smckusick/* 2111716Smckusick * Copyright (c) 2003 Networks Associates Technology, Inc. 3111716Smckusick * All rights reserved. 4111716Smckusick * 5111716Smckusick * This software was developed for the FreeBSD Project by Marshall 6111716Smckusick * Kirk McKusick and Network Associates Laboratories, the Security 7111716Smckusick * Research Division of Network Associates, Inc. under DARPA/SPAWAR 8111716Smckusick * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS 9111716Smckusick * research program. 10111716Smckusick * 11111716Smckusick * Redistribution and use in source and binary forms, with or without 12111716Smckusick * modification, are permitted provided that the following conditions 13111716Smckusick * are met: 14111716Smckusick * 1. Redistributions of source code must retain the above copyright 15111716Smckusick * notice, this list of conditions and the following disclaimer. 16111716Smckusick * 2. Redistributions in binary form must reproduce the above copyright 17111716Smckusick * notice, this list of conditions and the following disclaimer in the 18111716Smckusick * documentation and/or other materials provided with the distribution. 19111716Smckusick * 3. The names of the authors may not be used to endorse or promote 20111716Smckusick * products derived from this software without specific prior written 21111716Smckusick * permission. 22111716Smckusick * 23111716Smckusick * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24111716Smckusick * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25111716Smckusick * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26111716Smckusick * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27111716Smckusick * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28111716Smckusick * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29111716Smckusick * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30111716Smckusick * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31111716Smckusick * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32111716Smckusick * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33111716Smckusick * SUCH DAMAGE. 34111716Smckusick * 35111716Smckusick * $FreeBSD: head/sbin/mksnap_ffs/mksnap_ffs.c 121707 2003-10-29 21:23:44Z trhodes $ 36111716Smckusick */ 37111716Smckusick 38111716Smckusick#include <sys/param.h> 39111716Smckusick#include <sys/mount.h> 40111716Smckusick#include <sys/stat.h> 41111716Smckusick#include <ufs/ufs/ufsmount.h> 42111716Smckusick#include <err.h> 43111716Smckusick#include <errno.h> 44111725Smckusick#include <fcntl.h> 45111716Smckusick#include <grp.h> 46111716Smckusick#include <stdio.h> 47111716Smckusick#include <stdlib.h> 48111716Smckusick#include <string.h> 49111716Smckusick#include <sysexits.h> 50111716Smckusick#include <unistd.h> 51111716Smckusick 52121706Strhodesvoid usage(void); 53121706Strhodes 54111716Smckusickint 55111716Smckusickmain(int argc, char **argv) 56111716Smckusick{ 57111716Smckusick const char *dir; 58111716Smckusick struct ufs_args args; 59111716Smckusick struct group *grp; 60111725Smckusick struct stat stbuf; 61111725Smckusick int fd; 62111716Smckusick 63111716Smckusick if (argc != 3) 64111716Smckusick usage(); 65111716Smckusick 66111716Smckusick dir = argv[1]; 67111716Smckusick args.fspec = argv[2]; 68111716Smckusick 69111716Smckusick if ((grp = getgrnam("operator")) == NULL) 70111716Smckusick errx(1, "Cannot retrieve operator gid"); 71111716Smckusick if (mount("ffs", dir, MNT_UPDATE | MNT_SNAPSHOT, &args) < 0) 72111716Smckusick err(1, "Cannot create %s", args.fspec); 73111725Smckusick if ((fd = open(args.fspec, O_RDONLY)) < 0) 74111725Smckusick err(1, "Cannot open %s", args.fspec); 75111725Smckusick if (fstat(fd, &stbuf) != 0) 76111725Smckusick err(1, "Cannot stat %s", args.fspec); 77111725Smckusick if ((stbuf.st_flags & SF_SNAPSHOT) == 0) 78111725Smckusick errx(1, "File %s is not a snapshot", args.fspec); 79111725Smckusick if (fchown(fd, -1, grp->gr_gid) != 0) 80111716Smckusick err(1, "Cannot chown %s", args.fspec); 81111725Smckusick if (fchmod(fd, S_IRUSR | S_IRGRP) != 0) 82111716Smckusick err(1, "Cannot chmod %s", args.fspec); 83111716Smckusick 84111716Smckusick exit(EXIT_SUCCESS); 85111716Smckusick} 86121707Strhodes 87121707Strhodesvoid 88121707Strhodesusage() 89121707Strhodes{ 90121707Strhodes 91121707Strhodes fprintf(stderr, "usage: mksnap_ffs mountpoint snapshot_name\n"); 92121707Strhodes exit(EX_USAGE); 93121707Strhodes} 94