Skip to content

Commit ec78559

Browse files
wjtrelan
authored andcommitted
attrib: qualify device with an option.
I learned that the in-kernel FAT implementation in Linux supports two ioctls, FAT_IOCTL_GET_ATTRIBUTES and FAT_IOCTL_SET_ATTRIBUTES, to get and set file attributes on a mounted file system. If this FUSE exFAT implementation (and/or the new in-kernel implementation on Linux) were to implement such an ioctl in future, it would be nice to be able to adjust this tool to support that usage without breaking its command-line arguments in a backwards-incompatible way. To future-proof against that, require a '-d' option to specify the target device. This would also allow the command to accept more that one path, like chmod.
1 parent 41fd196 commit ec78559

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

attrib/exfatattrib.8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
|
2424
.B \-A
2525
]
26+
.B \-d
2627
.I device
2728
.I file
2829
.SH DESCRIPTION
@@ -44,6 +45,10 @@ error to set and clear the same flag.
4445
.SH COMMAND LINE OPTIONS
4546
Command line options available:
4647

48+
.TP
49+
.BI \-d " device"
50+
The path to an unmounted disk partition or disk image file containing an exFAT
51+
file system. This option is required.
4752
.TP
4853
.BI -r
4954
Set read\-only flag

attrib/main.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ static void usage(const char* prog)
2929
{
3030
fprintf(stderr,
3131
"Display current attributes:\n"
32-
" %1$s <device> <file>\n"
32+
" %1$s -d <device> <file>\n"
3333
"\n"
3434
"Set attributes:\n"
35-
" %1$s [FLAGS] <device> <file>\n"
35+
" %1$s [FLAGS] -d <device> <file>\n"
3636
"\n"
3737
"Flags:\n"
3838
" -r Set read-only flag\n"
@@ -111,7 +111,7 @@ int main(int argc, char* argv[])
111111
uint16_t add_flags = 0;
112112
uint16_t clear_flags = 0;
113113

114-
while ((opt = getopt(argc, argv, "rRiIsSaAhV")) != -1)
114+
while ((opt = getopt(argc, argv, "d:rRiIsSaAhV")) != -1)
115115
{
116116
switch (opt)
117117
{
@@ -120,6 +120,15 @@ int main(int argc, char* argv[])
120120
puts("Copyright (C) 2011-2018 Andrew Nayenko");
121121
puts("Copyright (C) 2020 Endless OS Foundation LLC");
122122
return 0;
123+
/*
124+
The path to the unmounted exFAT partition is a (mandatory) named
125+
option rather than a positional parameter. If the FUSE file system
126+
ever gains an ioctl to get and set attributes, this option could be
127+
made optional, and this tool taught to use the ioctl.
128+
*/
129+
case 'd':
130+
spec = optarg;
131+
break;
123132
case 'r':
124133
add_flags |= EXFAT_ATTRIB_RO;
125134
break;
@@ -157,11 +166,10 @@ int main(int argc, char* argv[])
157166
return 1;
158167
}
159168

160-
if (argc - optind != 2)
169+
if (spec == NULL || argc - optind != 1)
161170
usage(argv[0]);
162171

163-
spec = argv[optind];
164-
file_path = argv[optind + 1];
172+
file_path = argv[optind];
165173

166174
if ((add_flags | clear_flags) == 0)
167175
options = "ro";

0 commit comments

Comments
 (0)