paul@278 | 1 | /* |
paul@278 | 2 | * Make directories in a filesystem. |
paul@278 | 3 | * |
paul@278 | 4 | * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk> |
paul@278 | 5 | * |
paul@278 | 6 | * This program is free software; you can redistribute it and/or |
paul@278 | 7 | * modify it under the terms of the GNU General Public License as |
paul@278 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@278 | 9 | * the License, or (at your option) any later version. |
paul@278 | 10 | * |
paul@278 | 11 | * This program is distributed in the hope that it will be useful, |
paul@278 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@278 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@278 | 14 | * GNU General Public License for more details. |
paul@278 | 15 | * |
paul@278 | 16 | * You should have received a copy of the GNU General Public License |
paul@278 | 17 | * along with this program; if not, write to the Free Software |
paul@278 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@278 | 19 | * Boston, MA 02110-1301, USA |
paul@278 | 20 | */ |
paul@278 | 21 | |
paul@278 | 22 | #include <stdio.h> |
paul@278 | 23 | |
paul@278 | 24 | #include <ext2fs/ext2fs.h> |
paul@278 | 25 | |
paul@278 | 26 | #include "image.h" |
paul@278 | 27 | #include "session.h" |
paul@278 | 28 | |
paul@278 | 29 | |
paul@278 | 30 | |
paul@278 | 31 | /* Alternative metadata set by options. */ |
paul@278 | 32 | |
paul@278 | 33 | extern struct metadata md; |
paul@278 | 34 | |
paul@278 | 35 | |
paul@278 | 36 | |
paul@278 | 37 | /* Make directories in the filesystem image. */ |
paul@278 | 38 | |
paul@278 | 39 | int make_dirs(ext2_filsys fs, int argc, char *argv[]) |
paul@278 | 40 | { |
paul@278 | 41 | int i; |
paul@278 | 42 | const char *path; |
paul@278 | 43 | ext2_ino_t ino; |
paul@278 | 44 | |
paul@278 | 45 | /* Make each directory component in the given pathname. */ |
paul@278 | 46 | |
paul@278 | 47 | for (i = 0; i < argc; i++) |
paul@278 | 48 | { |
paul@278 | 49 | path = argv[i]; |
paul@278 | 50 | |
paul@278 | 51 | /* Search for the remaining components. */ |
paul@278 | 52 | |
paul@278 | 53 | if ((!*path) || !image_resolve_by_path(fs, &path, &ino)) |
paul@278 | 54 | { |
paul@278 | 55 | fprintf(stderr, "Path exists: %s\n", argv[i]); |
paul@278 | 56 | return 1; |
paul@278 | 57 | } |
paul@278 | 58 | |
paul@278 | 59 | /* From the first unrecognised component, make the remaining |
paul@278 | 60 | directories. */ |
paul@278 | 61 | |
paul@278 | 62 | if (image_make_dirs(fs, &path, ino, |
paul@278 | 63 | 0777 & ~md.mask, |
paul@278 | 64 | md.have_uid ? md.uid : 0, |
paul@278 | 65 | md.have_gid ? md.gid : 0)) |
paul@278 | 66 | { |
paul@278 | 67 | fprintf(stderr, "Failed to make directory: %s\n", argv[i]); |
paul@278 | 68 | return 1; |
paul@278 | 69 | } |
paul@278 | 70 | } |
paul@278 | 71 | |
paul@278 | 72 | return 0; |
paul@278 | 73 | } |
paul@278 | 74 | |
paul@278 | 75 | /* vim: tabstop=4 expandtab shiftwidth=4 |
paul@278 | 76 | */ |