Repository navigation
Expand file tree
/
Copy pathshared_linux.sh
More file actions
executable file
·184 lines (137 loc) · 5.76 KB
/
Copy pathshared_linux.sh
File metadata and controls
executable file
·184 lines (137 loc) · 5.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
#
# Shared functionality for scripts to generate HFS, HFS+ and HFSX test files
EXIT_SUCCESS=0
EXIT_FAILURE=1
# Checks the availability of a binary and exits if not available.
#
# Arguments:
# a string containing the name of the binary
#
assert_availability_binary()
{
local BINARY=$1
which "${BINARY}" > /dev/null 2>&1
if test $? -ne ${EXIT_SUCCESS}
then
echo "Missing binary: ${BINARY}"
echo ""
exit ${EXIT_FAILURE}
fi
}
# Creates test file entries on traditional HFS.
#
# Arguments:
# a string containing the mount point of the image file
#
create_test_file_entries_hfs()
{
MOUNT_POINT=$1
# Create an empty file
touch "${MOUNT_POINT}/emptyfile"
# Create a directory
mkdir "${MOUNT_POINT}/testdir1"
# Create a file that can be stored as inline data
echo "My file" > "${MOUNT_POINT}/testdir1/testfile1"
# Create a file that cannot be stored as inline data
cp LICENSE "${MOUNT_POINT}/testdir1/TestFile2"
# Create a hard link to a file
# ln: failed to create hard link: Operation not permitted
# Create a symbolic link to a file
# ln: failed to create symbolic link: Operation not permitted
# Create a hard link to a directory
# ln: hard link not allowed for directory
# Create a symbolic link to a directory
# ln: failed to create symbolic link: Operation not permitted
# Create a file with an UTF-8 NFC encoded filename
FILE_NAME=$(printf "%s/nfc_t\xc3\xa9stfil\xc3\xa8" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with an UTF-8 NFD encoded filename
FILE_NAME=$(printf "%s/nfd_te\xcc\x81stfile\xcc\x80" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with an UTF-8 NFD encoded filename
FILE_NAME=$(printf "%s/nfd_\xc2\xbe" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with an UTF-8 NFKD encoded filename
FILE_NAME=$(printf "%s/nfkd_3\xe2\x81\x844" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with filename that requires case folding if
# the file system is case-insensitive
FILE_NAME=$(printf "%s/case_folding_\xc2\xb5" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with a forward slash
FILE_NAME=$(printf "%s/forward:slash" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# TODO: Create a file with a resource fork with content
# Create a file with an extended attribute
# setfattr: Operation not supported
# Create a directory with an extended attribute
# setfattr: Operation not supported
# Create a file with an extended attribute that is not stored inline
# setfattr: Operation not supported
# TODO: create file that uses extents (overflow) file.
}
# Creates test file entries on HFS+/HFSX.
#
# Arguments:
# a string containing the mount point of the image file
#
create_test_file_entries()
{
MOUNT_POINT=$1
# Create an empty file
touch "${MOUNT_POINT}/emptyfile"
# Create a directory
mkdir "${MOUNT_POINT}/testdir1"
# Create a file that can be stored as inline data
echo "My file" > "${MOUNT_POINT}/testdir1/testfile1"
# Create a file that cannot be stored as inline data
cp LICENSE "${MOUNT_POINT}/testdir1/TestFile2"
# Create a hard link to a file
ln "${MOUNT_POINT}/testdir1/testfile1" "${MOUNT_POINT}/file_hardlink1"
# Create a symbolic link to a file
ln -s "${MOUNT_POINT}/testdir1/testfile1" "${MOUNT_POINT}/file_symboliclink1"
# Create a hard link to a directory
# ln "${MOUNT_POINT}/testdir1" "${MOUNT_POINT}/directory_hardlink1"
# ln: hard link not allowed for directory
# Create a symbolic link to a directory
ln -s "${MOUNT_POINT}/testdir1" "${MOUNT_POINT}/directory_symboliclink1"
# Create a file with an UTF-8 NFC encoded filename
FILE_NAME=$(printf "%s/nfc_t\xc3\xa9stfil\xc3\xa8" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with an UTF-8 NFD encoded filename
FILE_NAME=$(printf "%s/nfd_te\xcc\x81stfile\xcc\x80" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with an UTF-8 NFD encoded filename
FILE_NAME=$(printf "%s/nfd_\xc2\xbe" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with an UTF-8 NFKD encoded filename
FILE_NAME=$(printf "%s/nfkd_3\xe2\x81\x844" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with filename that requires case folding if
# the file system is case-insensitive
FILE_NAME=$(printf "%s/case_folding_\xc2\xb5" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# Create a file with a forward slash
FILE_NAME=$(printf "%s/forward:slash" "${MOUNT_PATH}")
touch "${FILE_NAME}"
# TODO: Create a file with a resource fork with content
# Create a file with an extended attribute
touch "${MOUNT_POINT}/testdir1/xattr1"
setfattr -n "user.myxattr1" -v "My 1st extended attribute" "${MOUNT_POINT}/testdir1/xattr1"
# Create a directory with an extended attribute
mkdir "${MOUNT_POINT}/testdir1/xattr2"
setfattr -n "user.myxattr2" -v "My 2nd extended attribute" "${MOUNT_POINT}/testdir1/xattr2"
# Create a file with an extended attribute that is not stored inline
# Note that the Linux HFS+ implementation does not support creating extended attributes
# that are not stored inline, this supports up to approximately 3800 bytes of value data.
# TODO: create file that uses extents (overflow) file.
# Create a block device file
# Need to run mknod with sudo otherwise it errors with: Operation not permitted
sudo mknod "${MOUNT_POINT}/testdir1/blockdev1" b 24 57
# Create a character device file
# Need to run mknod with sudo otherwise it errors with: Operation not permitted
sudo mknod "${MOUNT_POINT}/testdir1/chardev1" c 13 68
# Create a pipe (FIFO) file
mknod "${MOUNT_POINT}/testdir1/pipe1" p
}