1*8a272653SPeter Holm#!/bin/sh 2*8a272653SPeter Holm 3*8a272653SPeter Holm# 4*8a272653SPeter Holm# Copyright (c) 2015 EMC Corp. 5*8a272653SPeter Holm# All rights reserved. 6*8a272653SPeter Holm# 7*8a272653SPeter Holm# Redistribution and use in source and binary forms, with or without 8*8a272653SPeter Holm# modification, are permitted provided that the following conditions 9*8a272653SPeter Holm# are met: 10*8a272653SPeter Holm# 1. Redistributions of source code must retain the above copyright 11*8a272653SPeter Holm# notice, this list of conditions and the following disclaimer. 12*8a272653SPeter Holm# 2. Redistributions in binary form must reproduce the above copyright 13*8a272653SPeter Holm# notice, this list of conditions and the following disclaimer in the 14*8a272653SPeter Holm# documentation and/or other materials provided with the distribution. 15*8a272653SPeter Holm# 16*8a272653SPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*8a272653SPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8a272653SPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*8a272653SPeter Holm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*8a272653SPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*8a272653SPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*8a272653SPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*8a272653SPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*8a272653SPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*8a272653SPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*8a272653SPeter Holm# SUCH DAMAGE. 27*8a272653SPeter Holm# 28*8a272653SPeter Holm 29*8a272653SPeter Holm# Verify that mmap access updates mtime and ctime on files located on a 30*8a272653SPeter Holm# tmpfs FS. 31*8a272653SPeter Holm# Fixed by r277828 and r277969. 32*8a272653SPeter Holm 33*8a272653SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 34*8a272653SPeter Holm 35*8a272653SPeter Holm. ../default.cfg 36*8a272653SPeter Holm 37*8a272653SPeter Holmodir=`pwd` 38*8a272653SPeter Holmcd /tmp 39*8a272653SPeter Holmsed '1,/^EOF/d' < $odir/$0 > tmpfs14.c 40*8a272653SPeter Holmrm -f /tmp/tmpfs14 41*8a272653SPeter Holmmycc -o tmpfs14 -Wall -Wextra -g -O2 tmpfs14.c || exit 1 42*8a272653SPeter Holmrm -f tmpfs14.c 43*8a272653SPeter Holmcd $odir 44*8a272653SPeter Holm 45*8a272653SPeter Holmmount | grep -q "$mntpoint " && umount -f $mntpoint 46*8a272653SPeter Holmmount -t tmpfs tmpfs $mntpoint 47*8a272653SPeter Holm 48*8a272653SPeter Holm(cd $mntpoint; /tmp/tmpfs14) & 49*8a272653SPeter Holm 50*8a272653SPeter Holmsleep .5 51*8a272653SPeter Holmset `stat -f "%m %c" $mntpoint/test` 52*8a272653SPeter Holmm1=$1 53*8a272653SPeter Holmc1=$2 54*8a272653SPeter Holmwhile pgrep -q tmpfs14; do 55*8a272653SPeter Holm set `stat -f "%m %c" $mntpoint/test` 56*8a272653SPeter Holm [ "$m1" != "$1" ] && break 57*8a272653SPeter Holm [ "$c1" != "$2" ] && break 58*8a272653SPeter Holm sleep 1 59*8a272653SPeter Holmdone 60*8a272653SPeter Holm[ "$m1" = "$1" -o "$c1" = "$2" ] && 61*8a272653SPeter Holm echo "FAIL Unchanged time $m1 $c1 / $1 $2" 62*8a272653SPeter Holmwait 63*8a272653SPeter Holm 64*8a272653SPeter Holmwhile mount | grep $mntpoint | grep -q tmpfs; do 65*8a272653SPeter Holm umount $mntpoint || sleep 1 66*8a272653SPeter Holmdone 67*8a272653SPeter Holmrm -f /tmp/tmpfs14 68*8a272653SPeter Holmexit 0 69*8a272653SPeter HolmEOF 70*8a272653SPeter Holm 71*8a272653SPeter Holm#include <sys/types.h> 72*8a272653SPeter Holm#include <sys/mman.h> 73*8a272653SPeter Holm 74*8a272653SPeter Holm#include <err.h> 75*8a272653SPeter Holm#include <errno.h> 76*8a272653SPeter Holm#include <stdio.h> 77*8a272653SPeter Holm#include <stdlib.h> 78*8a272653SPeter Holm#include <unistd.h> 79*8a272653SPeter Holm#include <fcntl.h> 80*8a272653SPeter Holm#include <time.h> 81*8a272653SPeter Holm 82*8a272653SPeter Holmchar *file = "test"; 83*8a272653SPeter Holm 84*8a272653SPeter Holmint 85*8a272653SPeter Holmmain(void) 86*8a272653SPeter Holm{ 87*8a272653SPeter Holm char *p; 88*8a272653SPeter Holm size_t len; 89*8a272653SPeter Holm int fd, i; 90*8a272653SPeter Holm 91*8a272653SPeter Holm if ((fd = open(file, O_RDWR | O_CREAT, 0644)) == -1) 92*8a272653SPeter Holm err(1, "open(%s)", file); 93*8a272653SPeter Holm if (write(fd, "abcdef", 7) < 0) 94*8a272653SPeter Holm err(1, "write"); 95*8a272653SPeter Holm close(fd); 96*8a272653SPeter Holm 97*8a272653SPeter Holm len = getpagesize(); 98*8a272653SPeter Holm for (i = 0; i < 10; i++) { 99*8a272653SPeter Holm sleep(1); 100*8a272653SPeter Holm if ((fd = open(file, O_RDWR | O_CREAT, 0644)) == -1) 101*8a272653SPeter Holm err(1, "open(%s)", file); 102*8a272653SPeter Holm 103*8a272653SPeter Holm if ((p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) 104*8a272653SPeter Holm err(1, "mmap"); 105*8a272653SPeter Holm 106*8a272653SPeter Holm p[0] = '0' + i; 107*8a272653SPeter Holm munmap(p, len); 108*8a272653SPeter Holm close(fd); 109*8a272653SPeter Holm } 110*8a272653SPeter Holm 111*8a272653SPeter Holm return 0; 112*8a272653SPeter Holm} 113